@enerex/template-studio 1.1.29 → 1.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { QueryClient as Se, QueryClientProvider as Ce, useQuery as
|
|
4
|
-
import
|
|
5
|
-
import { Spinner as
|
|
6
|
-
import { Controller as
|
|
7
|
-
import
|
|
8
|
-
const
|
|
1
|
+
import { jsx as i, jsxs as C, Fragment as ve } from "react/jsx-runtime";
|
|
2
|
+
import q, { useContext as oe, useState as S, useRef as xe, useEffect as N } from "react";
|
|
3
|
+
import { QueryClient as Se, QueryClientProvider as Ce, useQuery as H, useMutation as se, useQueryClient as Ee } from "@tanstack/react-query";
|
|
4
|
+
import Y from "axios";
|
|
5
|
+
import { Spinner as Q, Form as P, Card as J, Row as Ie, Col as O, Button as X } from "react-bootstrap";
|
|
6
|
+
import { Controller as _e, useForm as Ne } from "react-hook-form";
|
|
7
|
+
import Z, { components as Pe } from "react-select";
|
|
8
|
+
const M = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
|
|
9
9
|
<html\r
|
|
10
10
|
dir="ltr"\r
|
|
11
11
|
xmlns:o="urn:schemas-microsoft-com:office:office"\r
|
|
@@ -361,67 +361,66 @@ const F = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
|
|
|
361
361
|
</div>\r
|
|
362
362
|
</body>\r
|
|
363
363
|
</html>\r
|
|
364
|
-
`,
|
|
364
|
+
`, ae = q.createContext(
|
|
365
365
|
void 0
|
|
366
366
|
), je = ({
|
|
367
367
|
children: e,
|
|
368
|
-
configs:
|
|
368
|
+
configs: r
|
|
369
369
|
}) => {
|
|
370
|
-
const [
|
|
371
|
-
|
|
372
|
-
), [p,
|
|
373
|
-
t(
|
|
370
|
+
const [o, a] = q.useState(r.clientId), [n, t] = q.useState(r.apiKey), [s, d] = q.useState(
|
|
371
|
+
r.enerexIdentifier
|
|
372
|
+
), [p, T] = q.useState(r.projectId), v = (y) => {
|
|
373
|
+
t(y.apiKey), a(y.clientId), T(y.projectId), d(y.enerexIdentifier);
|
|
374
374
|
};
|
|
375
|
-
return /* @__PURE__ */
|
|
376
|
-
|
|
375
|
+
return /* @__PURE__ */ i(
|
|
376
|
+
ae.Provider,
|
|
377
377
|
{
|
|
378
378
|
value: {
|
|
379
|
-
clientId:
|
|
380
|
-
apiKey:
|
|
381
|
-
setConfiguration:
|
|
382
|
-
enerexIdentifier:
|
|
383
|
-
projectId:
|
|
384
|
-
userName: p
|
|
379
|
+
clientId: o,
|
|
380
|
+
apiKey: n,
|
|
381
|
+
setConfiguration: v,
|
|
382
|
+
enerexIdentifier: s,
|
|
383
|
+
projectId: p
|
|
385
384
|
},
|
|
386
385
|
children: e
|
|
387
386
|
}
|
|
388
387
|
);
|
|
389
388
|
}, E = () => {
|
|
390
|
-
const e = oe(
|
|
389
|
+
const e = oe(ae);
|
|
391
390
|
if (!e)
|
|
392
391
|
throw new Error("widgetConfig must be used within a ConfigProvider");
|
|
393
392
|
return e;
|
|
394
|
-
},
|
|
393
|
+
}, le = (e = "", r) => ({ get: async (n, t) => {
|
|
395
394
|
try {
|
|
396
|
-
const
|
|
397
|
-
`${e}${
|
|
398
|
-
t ??
|
|
395
|
+
const s = await Y.get(
|
|
396
|
+
`${e}${n}`,
|
|
397
|
+
t ?? r
|
|
399
398
|
);
|
|
400
|
-
if (
|
|
401
|
-
return
|
|
402
|
-
} catch (
|
|
403
|
-
throw
|
|
399
|
+
if (s.status === 200)
|
|
400
|
+
return s.data;
|
|
401
|
+
} catch (s) {
|
|
402
|
+
throw s;
|
|
404
403
|
}
|
|
405
|
-
}, post: async (
|
|
404
|
+
}, post: async (n, t, s) => {
|
|
406
405
|
try {
|
|
407
|
-
const d = await
|
|
408
|
-
`${e}${
|
|
406
|
+
const d = await Y.post(
|
|
407
|
+
`${e}${n}`,
|
|
409
408
|
t,
|
|
410
|
-
|
|
409
|
+
s ?? r
|
|
411
410
|
);
|
|
412
411
|
if (d.status === 200)
|
|
413
412
|
return d.data;
|
|
414
413
|
} catch (d) {
|
|
415
414
|
throw d;
|
|
416
415
|
}
|
|
417
|
-
} }),
|
|
416
|
+
} }), F = {
|
|
418
417
|
EDITOR_SCRIPT_URL: "https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",
|
|
419
418
|
EDITOR_PLUGIN_ID: "1afdc3161ec7409a8627a1c8561d45f5",
|
|
420
419
|
EDITOR_SECRET_KEY: "54ba748ed7e94f2e929555783acb03da",
|
|
421
420
|
API_BASE_URL: "https://dev-socket.enerex.com/common/api"
|
|
422
421
|
//API_BASE_URL: "https://localhost:44338/api",
|
|
423
422
|
// more env variables...
|
|
424
|
-
},
|
|
423
|
+
}, de = q.createContext({
|
|
425
424
|
get: () => {
|
|
426
425
|
throw new Error("HttpClientContext.get not implemented");
|
|
427
426
|
},
|
|
@@ -429,29 +428,29 @@ const F = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
|
|
|
429
428
|
throw new Error("HttpClientContext.post not implemented");
|
|
430
429
|
}
|
|
431
430
|
}), Ae = ({ children: e }) => {
|
|
432
|
-
const { clientId:
|
|
431
|
+
const { clientId: r, apiKey: o } = E(), a = {
|
|
433
432
|
headers: {
|
|
434
|
-
client_id:
|
|
435
|
-
"x-api-key":
|
|
433
|
+
client_id: r,
|
|
434
|
+
"x-api-key": o
|
|
436
435
|
}
|
|
437
|
-
}, { get:
|
|
438
|
-
return /* @__PURE__ */
|
|
436
|
+
}, { get: n, post: t } = le(F.API_BASE_URL, a);
|
|
437
|
+
return /* @__PURE__ */ i(de.Provider, { value: { get: n, post: t }, children: e });
|
|
439
438
|
}, Re = ({ children: e }) => {
|
|
440
|
-
const
|
|
441
|
-
return /* @__PURE__ */
|
|
439
|
+
const r = new Se();
|
|
440
|
+
return /* @__PURE__ */ i(Ae, { children: /* @__PURE__ */ i(Ce, { client: r, children: e }) });
|
|
442
441
|
}, Oe = (e) => {
|
|
443
|
-
const
|
|
444
|
-
return
|
|
445
|
-
const
|
|
442
|
+
const r = Array.from(new Set(e.map((a) => a.category))), o = [];
|
|
443
|
+
return r.forEach((a) => {
|
|
444
|
+
const n = e.filter((t) => t.category === a).map((t) => ({
|
|
446
445
|
label: t.label,
|
|
447
446
|
value: t.value,
|
|
448
447
|
hint: t.hint,
|
|
449
448
|
hidden: t.hidden
|
|
450
449
|
}));
|
|
451
|
-
|
|
452
|
-
}),
|
|
450
|
+
o.push({ category: a, entries: n });
|
|
451
|
+
}), o;
|
|
453
452
|
}, D = () => {
|
|
454
|
-
const e = oe(
|
|
453
|
+
const e = oe(de);
|
|
455
454
|
if (e)
|
|
456
455
|
return e;
|
|
457
456
|
throw new Error("useHttpClient must be used within a HttpClientProvider");
|
|
@@ -463,53 +462,53 @@ const F = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
|
|
|
463
462
|
SaveTemplate: "/Template/save-update/",
|
|
464
463
|
TemplateTypes: "/Template/TemplateTypes/"
|
|
465
464
|
}, qe = () => {
|
|
466
|
-
const e = D(), { enerexIdentifier:
|
|
467
|
-
return
|
|
465
|
+
const e = D(), { enerexIdentifier: r, projectId: o } = E();
|
|
466
|
+
return H({
|
|
468
467
|
queryKey: ["getTemplateTags"],
|
|
469
|
-
queryFn: async (
|
|
470
|
-
`${$.MergeTags}${
|
|
468
|
+
queryFn: async (n) => await e.get(
|
|
469
|
+
`${$.MergeTags}${o}/${r}`
|
|
471
470
|
)
|
|
472
471
|
});
|
|
473
472
|
}, De = () => {
|
|
474
|
-
const e = D(), { enerexIdentifier:
|
|
475
|
-
return
|
|
473
|
+
const e = D(), { enerexIdentifier: r, projectId: o } = E();
|
|
474
|
+
return H({
|
|
476
475
|
queryKey: ["getExcludeCategory"],
|
|
477
|
-
queryFn: async (
|
|
478
|
-
`${$.ExcludeCategory}${
|
|
476
|
+
queryFn: async (n) => await e.get(
|
|
477
|
+
`${$.ExcludeCategory}${o}/${r}`
|
|
479
478
|
)
|
|
480
479
|
});
|
|
481
480
|
}, $e = ({
|
|
482
481
|
templateHTML: e,
|
|
483
|
-
className:
|
|
484
|
-
loading:
|
|
482
|
+
className: r = "",
|
|
483
|
+
loading: o = !1
|
|
485
484
|
}) => {
|
|
486
|
-
const { post: a } =
|
|
487
|
-
e ?? { html:
|
|
488
|
-
), { enerexIdentifier: p, projectId:
|
|
489
|
-
|
|
490
|
-
(async () => (await
|
|
491
|
-
}, [
|
|
492
|
-
async function
|
|
493
|
-
window.Zone || await new Promise((
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
const
|
|
497
|
-
|
|
485
|
+
const { post: a } = le(), { data: n } = qe(), { data: t } = De(), [s, d] = S(
|
|
486
|
+
e ?? { html: M, css: "" }
|
|
487
|
+
), { enerexIdentifier: p, projectId: T } = E(), v = xe(null), y = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", x = "https://plugins.stripo.email/api/v1/auth";
|
|
488
|
+
N(() => {
|
|
489
|
+
(async () => (await j(), n && t && await I(F.EDITOR_SCRIPT_URL)))();
|
|
490
|
+
}, [n, t]);
|
|
491
|
+
async function j() {
|
|
492
|
+
window.Zone || await new Promise((g, u) => {
|
|
493
|
+
const f = document.createElement("script");
|
|
494
|
+
f.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
|
|
495
|
+
const b = document.querySelector("script[nonce]")?.nonce;
|
|
496
|
+
b && f.setAttribute("nonce", b), f.onload = () => g(), f.onerror = () => u(new Error("Failed to load zone.js")), document.head.appendChild(f);
|
|
498
497
|
});
|
|
499
498
|
}
|
|
500
|
-
async function
|
|
499
|
+
async function I(g) {
|
|
501
500
|
let u = document.getElementById(
|
|
502
501
|
"UiEditorScript"
|
|
503
502
|
);
|
|
504
|
-
u || (u = document.createElement("script"), u.id = "UiEditorScript", u.src =
|
|
505
|
-
await
|
|
503
|
+
u || (u = document.createElement("script"), u.id = "UiEditorScript", u.src = g, u.onload = async () => {
|
|
504
|
+
await m();
|
|
506
505
|
}, document.body.appendChild(u)), await new Promise(
|
|
507
|
-
(
|
|
506
|
+
(f) => u.addEventListener("load", () => f(), { once: !0 })
|
|
508
507
|
);
|
|
509
508
|
}
|
|
510
|
-
const
|
|
511
|
-
const
|
|
512
|
-
if (!
|
|
509
|
+
const m = async () => {
|
|
510
|
+
const g = v.current;
|
|
511
|
+
if (!g) {
|
|
513
512
|
console.error("Missing #stripoEditorContainer in DOM");
|
|
514
513
|
return;
|
|
515
514
|
}
|
|
@@ -518,44 +517,44 @@ const F = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
|
|
|
518
517
|
return;
|
|
519
518
|
}
|
|
520
519
|
const u = {
|
|
521
|
-
html:
|
|
522
|
-
css:
|
|
520
|
+
html: s.html,
|
|
521
|
+
css: s.css,
|
|
523
522
|
modulesExcludedCategories: t ?? [],
|
|
524
523
|
forceRecreate: !0,
|
|
525
524
|
metadata: {
|
|
526
|
-
emailId: `${
|
|
525
|
+
emailId: `${T}_${p}`,
|
|
527
526
|
userId: "1",
|
|
528
|
-
username:
|
|
529
|
-
avatarUrl:
|
|
527
|
+
// username: userName,
|
|
528
|
+
avatarUrl: y
|
|
530
529
|
},
|
|
531
530
|
locale: "en",
|
|
532
|
-
onTokenRefreshRequest: async (
|
|
533
|
-
const
|
|
534
|
-
pluginId:
|
|
535
|
-
secretKey:
|
|
531
|
+
onTokenRefreshRequest: async (f) => {
|
|
532
|
+
const b = {
|
|
533
|
+
pluginId: F.EDITOR_PLUGIN_ID,
|
|
534
|
+
secretKey: F.EDITOR_SECRET_KEY,
|
|
536
535
|
userId: "12",
|
|
537
536
|
role: "user"
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
|
|
537
|
+
}, A = await a(
|
|
538
|
+
x,
|
|
539
|
+
b
|
|
541
540
|
);
|
|
542
|
-
|
|
541
|
+
A?.token && f(A.token);
|
|
543
542
|
},
|
|
544
|
-
mergeTags: Oe(
|
|
543
|
+
mergeTags: Oe(n ?? [])
|
|
545
544
|
};
|
|
546
|
-
for (const [
|
|
545
|
+
for (const [f, b] of Object.entries({
|
|
547
546
|
codeEditorButtonSelector: "#codeEditor",
|
|
548
547
|
undoButtonSelector: "#undoButton",
|
|
549
548
|
redoButtonSelector: "#redoButton",
|
|
550
549
|
mobileViewButtonSelector: "#mobileViewButton",
|
|
551
550
|
desktopViewButtonSelector: "#desktopViewButton"
|
|
552
551
|
}))
|
|
553
|
-
|
|
554
|
-
await window.UIEditor.initEditor(
|
|
552
|
+
g.ownerDocument && g.getRootNode() instanceof ShadowRoot && g.getRootNode().querySelector(b) && (u[f] = b);
|
|
553
|
+
await window.UIEditor.initEditor(g, u);
|
|
555
554
|
};
|
|
556
|
-
return /* @__PURE__ */
|
|
557
|
-
|
|
558
|
-
|
|
555
|
+
return /* @__PURE__ */ i("div", { className: "position-relative", children: /* @__PURE__ */ C("div", { className: `editor-container ${r}`, children: [
|
|
556
|
+
o && /* @__PURE__ */ i("div", { className: "loading-overlay", children: /* @__PURE__ */ i(
|
|
557
|
+
Q,
|
|
559
558
|
{
|
|
560
559
|
animation: "border",
|
|
561
560
|
style: { width: "11px", height: "11px" },
|
|
@@ -564,87 +563,87 @@ const F = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
|
|
|
564
563
|
className: "me-1"
|
|
565
564
|
}
|
|
566
565
|
) }),
|
|
567
|
-
/* @__PURE__ */
|
|
568
|
-
/* @__PURE__ */
|
|
566
|
+
/* @__PURE__ */ i("div", { id: "externalSystemContainer" }),
|
|
567
|
+
/* @__PURE__ */ i("div", { id: "stripoEditorContainer", ref: v })
|
|
569
568
|
] }) });
|
|
570
|
-
},
|
|
569
|
+
}, ee = ({
|
|
571
570
|
label: e,
|
|
572
|
-
register:
|
|
573
|
-
validation:
|
|
571
|
+
register: r,
|
|
572
|
+
validation: o,
|
|
574
573
|
required: a = !1,
|
|
575
|
-
name:
|
|
574
|
+
name: n,
|
|
576
575
|
error: t,
|
|
577
|
-
className:
|
|
576
|
+
className: s = "",
|
|
578
577
|
...d
|
|
579
|
-
}) => /* @__PURE__ */ C(
|
|
580
|
-
e ? /* @__PURE__ */ C(
|
|
578
|
+
}) => /* @__PURE__ */ C(P.Group, { className: s + " mb-1", children: [
|
|
579
|
+
e ? /* @__PURE__ */ C(P.Label, { className: "mb-3 d-block form-label", children: [
|
|
581
580
|
e,
|
|
582
|
-
a && /* @__PURE__ */
|
|
581
|
+
a && /* @__PURE__ */ i("label", { className: "text-danger", children: "*" })
|
|
583
582
|
] }) : null,
|
|
584
|
-
/* @__PURE__ */
|
|
585
|
-
|
|
583
|
+
/* @__PURE__ */ i(
|
|
584
|
+
P.Control,
|
|
586
585
|
{
|
|
587
|
-
name:
|
|
586
|
+
name: n,
|
|
588
587
|
type: "text",
|
|
589
588
|
...d,
|
|
590
|
-
isInvalid: !!(t && t[
|
|
591
|
-
...
|
|
592
|
-
...
|
|
589
|
+
isInvalid: !!(t && t[n]),
|
|
590
|
+
...r ? r(n, {
|
|
591
|
+
...o
|
|
593
592
|
}) : {},
|
|
594
|
-
className: `react-select__control ${t && t[
|
|
593
|
+
className: `react-select__control ${t && t[n] && "border border-danger"}`
|
|
595
594
|
}
|
|
596
595
|
),
|
|
597
|
-
t && t[
|
|
596
|
+
t && t[n] ? /* @__PURE__ */ i(P.Control.Feedback, { type: "invalid", children: t[n].message }) : null
|
|
598
597
|
] }), Le = () => {
|
|
599
|
-
const e = D(), { enerexIdentifier:
|
|
600
|
-
return
|
|
598
|
+
const e = D(), { enerexIdentifier: r, projectId: o } = E();
|
|
599
|
+
return H({
|
|
601
600
|
queryKey: ["getTemplatesList"],
|
|
602
|
-
queryFn: async (
|
|
603
|
-
`${$.Template_list}${
|
|
601
|
+
queryFn: async (n) => await e.get(
|
|
602
|
+
`${$.Template_list}${o}/${r}`
|
|
604
603
|
)
|
|
605
604
|
});
|
|
606
605
|
};
|
|
607
|
-
function
|
|
608
|
-
return e.sort((
|
|
606
|
+
function z(e) {
|
|
607
|
+
return e.sort((r, o) => r.name.localeCompare(o.name));
|
|
609
608
|
}
|
|
610
609
|
const ke = () => {
|
|
611
|
-
const e = D(), { enerexIdentifier:
|
|
612
|
-
return
|
|
610
|
+
const e = D(), { enerexIdentifier: r, projectId: o } = E();
|
|
611
|
+
return se({
|
|
613
612
|
mutationKey: ["getTemplate"],
|
|
614
|
-
mutationFn: async ({ id:
|
|
615
|
-
if (
|
|
613
|
+
mutationFn: async ({ id: n }) => {
|
|
614
|
+
if (n)
|
|
616
615
|
return await e.get(
|
|
617
|
-
`${$.Template}${
|
|
616
|
+
`${$.Template}${r}/${n}/${o}`
|
|
618
617
|
);
|
|
619
618
|
}
|
|
620
619
|
});
|
|
621
620
|
}, Be = () => {
|
|
622
|
-
const e = D(), { enerexIdentifier:
|
|
623
|
-
return
|
|
621
|
+
const e = D(), { enerexIdentifier: r, projectId: o } = E();
|
|
622
|
+
return H({
|
|
624
623
|
queryKey: ["getTemplateTypes"],
|
|
625
|
-
queryFn: async (
|
|
626
|
-
`${$.TemplateTypes}${
|
|
624
|
+
queryFn: async (n) => await e.get(
|
|
625
|
+
`${$.TemplateTypes}${r}/${o}`
|
|
627
626
|
)
|
|
628
627
|
});
|
|
629
628
|
};
|
|
630
629
|
function Ue(e) {
|
|
631
630
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
632
631
|
}
|
|
633
|
-
var
|
|
632
|
+
var V = { exports: {} };
|
|
634
633
|
/*!
|
|
635
634
|
Copyright (c) 2018 Jed Watson.
|
|
636
635
|
Licensed under the MIT License (MIT), see
|
|
637
636
|
http://jedwatson.github.io/classnames
|
|
638
637
|
*/
|
|
639
|
-
var
|
|
638
|
+
var te;
|
|
640
639
|
function Me() {
|
|
641
|
-
return
|
|
640
|
+
return te || (te = 1, function(e) {
|
|
642
641
|
(function() {
|
|
643
|
-
var
|
|
644
|
-
function
|
|
645
|
-
for (var t = "",
|
|
646
|
-
var d = arguments[
|
|
647
|
-
d && (t =
|
|
642
|
+
var r = {}.hasOwnProperty;
|
|
643
|
+
function o() {
|
|
644
|
+
for (var t = "", s = 0; s < arguments.length; s++) {
|
|
645
|
+
var d = arguments[s];
|
|
646
|
+
d && (t = n(t, a(d)));
|
|
648
647
|
}
|
|
649
648
|
return t;
|
|
650
649
|
}
|
|
@@ -654,23 +653,23 @@ function Me() {
|
|
|
654
653
|
if (typeof t != "object")
|
|
655
654
|
return "";
|
|
656
655
|
if (Array.isArray(t))
|
|
657
|
-
return
|
|
656
|
+
return o.apply(null, t);
|
|
658
657
|
if (t.toString !== Object.prototype.toString && !t.toString.toString().includes("[native code]"))
|
|
659
658
|
return t.toString();
|
|
660
|
-
var
|
|
659
|
+
var s = "";
|
|
661
660
|
for (var d in t)
|
|
662
|
-
|
|
663
|
-
return
|
|
661
|
+
r.call(t, d) && t[d] && (s = n(s, d));
|
|
662
|
+
return s;
|
|
664
663
|
}
|
|
665
|
-
function
|
|
666
|
-
return
|
|
664
|
+
function n(t, s) {
|
|
665
|
+
return s ? t ? t + " " + s : t + s : t;
|
|
667
666
|
}
|
|
668
|
-
e.exports ? (
|
|
667
|
+
e.exports ? (o.default = o, e.exports = o) : window.classNames = o;
|
|
669
668
|
})();
|
|
670
|
-
}(
|
|
669
|
+
}(V)), V.exports;
|
|
671
670
|
}
|
|
672
671
|
var Fe = Me();
|
|
673
|
-
const
|
|
672
|
+
const ne = /* @__PURE__ */ Ue(Fe), re = (e) => e.data.isSeparator ? /* @__PURE__ */ i("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ i(
|
|
674
673
|
"hr",
|
|
675
674
|
{
|
|
676
675
|
style: {
|
|
@@ -680,23 +679,23 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
680
679
|
margin: 0
|
|
681
680
|
}
|
|
682
681
|
}
|
|
683
|
-
) }) : /* @__PURE__ */
|
|
682
|
+
) }) : /* @__PURE__ */ i(Pe.Option, { ...e }), He = ({
|
|
684
683
|
name: e = "",
|
|
685
|
-
control:
|
|
686
|
-
options:
|
|
684
|
+
control: r,
|
|
685
|
+
options: o,
|
|
687
686
|
multiple: a = !1,
|
|
688
|
-
placeholder:
|
|
687
|
+
placeholder: n,
|
|
689
688
|
validation: t,
|
|
690
|
-
labelKey:
|
|
689
|
+
labelKey: s = "name",
|
|
691
690
|
disabled: d,
|
|
692
691
|
isInvalid: p,
|
|
693
|
-
value:
|
|
694
|
-
onChange:
|
|
695
|
-
uncontrolled:
|
|
696
|
-
menuPlacement:
|
|
697
|
-
closeOnSelect:
|
|
692
|
+
value: T,
|
|
693
|
+
onChange: v,
|
|
694
|
+
uncontrolled: y,
|
|
695
|
+
menuPlacement: x = "auto",
|
|
696
|
+
closeOnSelect: j = !0
|
|
698
697
|
}) => {
|
|
699
|
-
const
|
|
698
|
+
const I = {
|
|
700
699
|
control: (m) => ({
|
|
701
700
|
...m,
|
|
702
701
|
minHeight: "33px",
|
|
@@ -734,97 +733,97 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
734
733
|
display: d ? "none" : "block"
|
|
735
734
|
})
|
|
736
735
|
};
|
|
737
|
-
return
|
|
738
|
-
|
|
736
|
+
return y ? /* @__PURE__ */ i(
|
|
737
|
+
Z,
|
|
739
738
|
{
|
|
740
|
-
components: { Option:
|
|
739
|
+
components: { Option: re },
|
|
741
740
|
isOptionDisabled: (m) => !!m.isSeparator,
|
|
742
|
-
className:
|
|
741
|
+
className: ne({
|
|
743
742
|
"is-invalid": p
|
|
744
743
|
}),
|
|
745
|
-
styles:
|
|
744
|
+
styles: I,
|
|
746
745
|
classNamePrefix: "react-select",
|
|
747
746
|
isMulti: a,
|
|
748
|
-
options:
|
|
749
|
-
onChange:
|
|
750
|
-
placeholder:
|
|
747
|
+
options: o,
|
|
748
|
+
onChange: v,
|
|
749
|
+
placeholder: n,
|
|
751
750
|
menuPortalTarget: document.body,
|
|
752
|
-
value:
|
|
753
|
-
getOptionLabel: typeof
|
|
751
|
+
value: T,
|
|
752
|
+
getOptionLabel: typeof s == "string" ? (m) => m[s] : s,
|
|
754
753
|
getOptionValue: (m) => m.id,
|
|
755
754
|
isDisabled: d,
|
|
756
|
-
menuPlacement:
|
|
757
|
-
closeMenuOnSelect:
|
|
755
|
+
menuPlacement: x,
|
|
756
|
+
closeMenuOnSelect: j
|
|
758
757
|
}
|
|
759
|
-
) : /* @__PURE__ */
|
|
760
|
-
|
|
758
|
+
) : /* @__PURE__ */ i(
|
|
759
|
+
_e,
|
|
761
760
|
{
|
|
762
|
-
control:
|
|
761
|
+
control: r,
|
|
763
762
|
name: e,
|
|
764
763
|
rules: t,
|
|
765
|
-
render: ({ field: { onChange: m, value:
|
|
766
|
-
|
|
764
|
+
render: ({ field: { onChange: m, value: g, onBlur: u } }) => /* @__PURE__ */ i(
|
|
765
|
+
Z,
|
|
767
766
|
{
|
|
768
|
-
components: { Option:
|
|
769
|
-
isOptionDisabled: (
|
|
770
|
-
className:
|
|
767
|
+
components: { Option: re },
|
|
768
|
+
isOptionDisabled: (f) => !!f.isSeparator,
|
|
769
|
+
className: ne({
|
|
771
770
|
"is-invalid": p
|
|
772
771
|
}),
|
|
773
|
-
styles:
|
|
772
|
+
styles: I,
|
|
774
773
|
classNamePrefix: "react-select",
|
|
775
774
|
isMulti: a,
|
|
776
|
-
options:
|
|
777
|
-
onBlur:
|
|
775
|
+
options: o,
|
|
776
|
+
onBlur: u,
|
|
778
777
|
onChange: m,
|
|
779
|
-
placeholder:
|
|
778
|
+
placeholder: n,
|
|
780
779
|
menuPortalTarget: document.body,
|
|
781
|
-
value:
|
|
782
|
-
getOptionLabel: typeof
|
|
783
|
-
getOptionValue: (
|
|
780
|
+
value: g,
|
|
781
|
+
getOptionLabel: typeof s == "string" ? (f) => f[s] : s,
|
|
782
|
+
getOptionValue: (f) => f.id,
|
|
784
783
|
isDisabled: d,
|
|
785
|
-
menuPlacement:
|
|
786
|
-
closeMenuOnSelect:
|
|
784
|
+
menuPlacement: x,
|
|
785
|
+
closeMenuOnSelect: j
|
|
787
786
|
},
|
|
788
|
-
|
|
787
|
+
g ? JSON.stringify(g) : "reset"
|
|
789
788
|
)
|
|
790
789
|
}
|
|
791
790
|
);
|
|
792
|
-
},
|
|
791
|
+
}, K = ({
|
|
793
792
|
label: e,
|
|
794
|
-
name:
|
|
795
|
-
validation:
|
|
793
|
+
name: r,
|
|
794
|
+
validation: o,
|
|
796
795
|
control: a,
|
|
797
|
-
error:
|
|
796
|
+
error: n,
|
|
798
797
|
...t
|
|
799
|
-
}) => /* @__PURE__ */ C(
|
|
800
|
-
e && /* @__PURE__ */ C(
|
|
798
|
+
}) => /* @__PURE__ */ C(P.Group, { className: "mb-1", children: [
|
|
799
|
+
e && /* @__PURE__ */ C(P.Label, { className: "mb-3 d-block form-label", children: [
|
|
801
800
|
e,
|
|
802
801
|
" ",
|
|
803
|
-
t.required && /* @__PURE__ */
|
|
802
|
+
t.required && /* @__PURE__ */ i("span", { className: "text-danger", children: "*" })
|
|
804
803
|
] }),
|
|
805
|
-
/* @__PURE__ */
|
|
804
|
+
/* @__PURE__ */ i(
|
|
806
805
|
He,
|
|
807
806
|
{
|
|
808
807
|
control: a,
|
|
809
808
|
options: t.options ?? [],
|
|
810
|
-
validation:
|
|
811
|
-
isInvalid:
|
|
812
|
-
name:
|
|
809
|
+
validation: o,
|
|
810
|
+
isInvalid: n && !!n[r],
|
|
811
|
+
name: r
|
|
813
812
|
}
|
|
814
813
|
),
|
|
815
|
-
|
|
814
|
+
n && n[r] ? /* @__PURE__ */ i(P.Control.Feedback, { type: "invalid", children: n[r].message }) : null
|
|
816
815
|
] }), ze = () => {
|
|
817
816
|
const e = D();
|
|
818
817
|
Ee();
|
|
819
|
-
const { enerexIdentifier:
|
|
820
|
-
return
|
|
818
|
+
const { enerexIdentifier: r, projectId: o } = E();
|
|
819
|
+
return se({
|
|
821
820
|
mutationKey: ["saveTemplate"],
|
|
822
|
-
mutationFn: async (
|
|
821
|
+
mutationFn: async (n) => (n.enerexIdentifier = r ?? "", n.projectId = o ?? "", await e.post(
|
|
823
822
|
`${$.SaveTemplate}`,
|
|
824
|
-
|
|
823
|
+
n
|
|
825
824
|
))
|
|
826
825
|
});
|
|
827
|
-
},
|
|
826
|
+
}, G = {
|
|
828
827
|
id: "",
|
|
829
828
|
name: "New (Blank)"
|
|
830
829
|
}, ie = {
|
|
@@ -833,110 +832,110 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
833
832
|
isSeparator: !0
|
|
834
833
|
}, Ve = ({
|
|
835
834
|
onSelectItem: e,
|
|
836
|
-
templateLoading:
|
|
837
|
-
onReset:
|
|
835
|
+
templateLoading: r,
|
|
836
|
+
onReset: o
|
|
838
837
|
}) => {
|
|
839
838
|
const {
|
|
840
839
|
register: a,
|
|
841
|
-
handleSubmit:
|
|
840
|
+
handleSubmit: n,
|
|
842
841
|
clearErrors: t,
|
|
843
|
-
setValue:
|
|
842
|
+
setValue: s,
|
|
844
843
|
control: d,
|
|
845
844
|
watch: p,
|
|
846
|
-
reset:
|
|
847
|
-
setError:
|
|
848
|
-
formState: { errors:
|
|
849
|
-
} =
|
|
845
|
+
reset: T,
|
|
846
|
+
setError: v,
|
|
847
|
+
formState: { errors: y }
|
|
848
|
+
} = Ne({
|
|
850
849
|
defaultValues: {
|
|
851
850
|
templateName: "",
|
|
852
851
|
subTemplateType: void 0,
|
|
853
852
|
subject: "",
|
|
854
853
|
templateType: void 0,
|
|
855
|
-
template:
|
|
854
|
+
template: G
|
|
856
855
|
},
|
|
857
856
|
mode: "onChange"
|
|
858
857
|
}), {
|
|
859
|
-
data:
|
|
860
|
-
refetch:
|
|
861
|
-
isLoading:
|
|
862
|
-
} = Le(), [m,
|
|
863
|
-
|
|
864
|
-
if (
|
|
865
|
-
let l =
|
|
858
|
+
data: x,
|
|
859
|
+
refetch: j,
|
|
860
|
+
isLoading: I
|
|
861
|
+
} = Le(), [m, g] = S([]), [u, f] = S(), [b, A] = S(), { mutateAsync: ce, isPending: R } = ke(), { mutateAsync: pe, isPending: k } = ze(), { data: B, isLoading: W } = Be(), [me, ue] = S([]), [_, U] = S([]);
|
|
862
|
+
N(() => {
|
|
863
|
+
if (B) {
|
|
864
|
+
let l = B.filter((c) => c.id != null).sort((c, w) => c.name.localeCompare(w.name));
|
|
866
865
|
ue(
|
|
867
|
-
|
|
868
|
-
),
|
|
869
|
-
|
|
866
|
+
z(l.filter((c) => c.parent_id === 0))
|
|
867
|
+
), U(
|
|
868
|
+
z(
|
|
870
869
|
l.filter(
|
|
871
870
|
(c) => c.parent_id.toString() === `${p("templateType")?.id}`
|
|
872
871
|
)
|
|
873
872
|
)
|
|
874
873
|
);
|
|
875
874
|
}
|
|
876
|
-
}, [
|
|
875
|
+
}, [B]);
|
|
877
876
|
const fe = (l, c) => {
|
|
878
877
|
let w = [];
|
|
879
|
-
return l.forEach((
|
|
880
|
-
c.includes(
|
|
878
|
+
return l.forEach((h, L) => {
|
|
879
|
+
c.includes(L) && L !== 0 && w.push(ie), w.push(h);
|
|
881
880
|
}), w;
|
|
882
881
|
};
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
}, [
|
|
886
|
-
|
|
887
|
-
}, [
|
|
882
|
+
N(() => {
|
|
883
|
+
r(!!R);
|
|
884
|
+
}, [R]), N(() => {
|
|
885
|
+
x?.sort((l, c) => l.readonly !== c.readonly ? (l.readonly ? 0 : 1) - (c.readonly ? 0 : 1) : l.name.localeCompare(c.name)), g(x ?? []);
|
|
886
|
+
}, [x]);
|
|
888
887
|
const ge = async (l) => {
|
|
889
|
-
|
|
890
|
-
const c = await
|
|
891
|
-
|
|
888
|
+
f(l), l && !l.readonly ? (s("templateName", l?.name), t()) : (s("templateName", ""), s("subject", ""));
|
|
889
|
+
const c = await ce({ id: l?.id });
|
|
890
|
+
A(c || void 0);
|
|
892
891
|
};
|
|
893
|
-
|
|
894
|
-
if (
|
|
895
|
-
let l =
|
|
896
|
-
|
|
897
|
-
|
|
892
|
+
N(() => {
|
|
893
|
+
if (s("template", G), p("templateType")) {
|
|
894
|
+
let l = B?.filter((c) => c.id !== void 0) ?? [];
|
|
895
|
+
U(
|
|
896
|
+
z(
|
|
898
897
|
l.filter(
|
|
899
898
|
(c) => c.parent_id.toString() === `${p("templateType")?.id}`
|
|
900
899
|
)
|
|
901
900
|
)
|
|
902
|
-
),
|
|
901
|
+
), s("subTemplateType", void 0);
|
|
903
902
|
}
|
|
904
|
-
}, [p("templateType")]),
|
|
903
|
+
}, [p("templateType")]), N(() => {
|
|
905
904
|
let l = m.find((c) => c.id === p("template")?.id);
|
|
906
905
|
ge(l);
|
|
907
|
-
}, [p("template")]),
|
|
908
|
-
|
|
909
|
-
}, [
|
|
906
|
+
}, [p("template")]), N(() => {
|
|
907
|
+
b && u ? (e(b), s("subject", b.subject ?? "")) : e(void 0);
|
|
908
|
+
}, [b, u, e]);
|
|
910
909
|
const ye = () => {
|
|
911
|
-
let l = [
|
|
912
|
-
(
|
|
913
|
-
|
|
914
|
-
)?.id.toString() ||
|
|
915
|
-
), w = fe(c, [c.findIndex((
|
|
910
|
+
let l = [G], c = m.filter(
|
|
911
|
+
(h) => (h.type?.toString() === p(
|
|
912
|
+
_.length > 0 ? "subTemplateType" : "templateType"
|
|
913
|
+
)?.id.toString() || h.type === null) && p(_.length > 0 ? "subTemplateType" : "templateType")?.id != null
|
|
914
|
+
), w = fe(c, [c.findIndex((h) => !h.readonly)]);
|
|
916
915
|
return w.length > 0 && (l.push(ie), l = [
|
|
917
916
|
...l,
|
|
918
|
-
...w.map((
|
|
919
|
-
id:
|
|
920
|
-
name:
|
|
921
|
-
isSeparator:
|
|
917
|
+
...w.map((h) => ({
|
|
918
|
+
id: h.id,
|
|
919
|
+
name: h.name,
|
|
920
|
+
isSeparator: h.isSeparator
|
|
922
921
|
}))
|
|
923
922
|
]), l.length ? l : [];
|
|
924
923
|
}, he = (l) => {
|
|
925
924
|
window.StripoEditorApi.actionsApi.getTemplateData(
|
|
926
925
|
async (c) => {
|
|
927
|
-
let w = l.template.id,
|
|
928
|
-
|
|
929
|
-
let
|
|
926
|
+
let w = l.template.id, h = "";
|
|
927
|
+
u?.readonly && (w = "", h = l.template.id);
|
|
928
|
+
let L = m.find(
|
|
930
929
|
(Te) => Te.name === l.templateName.trim()
|
|
931
930
|
);
|
|
932
|
-
if (
|
|
933
|
-
|
|
931
|
+
if (L && L.id !== w) {
|
|
932
|
+
v("templateName", {
|
|
934
933
|
type: "validate",
|
|
935
934
|
message: "Template name already exists. Please choose a different name."
|
|
936
935
|
});
|
|
937
936
|
return;
|
|
938
937
|
}
|
|
939
|
-
let be = !!(
|
|
938
|
+
let be = !!(_ && _.length > 0);
|
|
940
939
|
const we = {
|
|
941
940
|
enerexIdentifier: "",
|
|
942
941
|
projectId: "",
|
|
@@ -946,19 +945,19 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
946
945
|
html: c.html,
|
|
947
946
|
css: c.css,
|
|
948
947
|
subject: l.templateType.id === "2" ? l?.subject ?? "" : "",
|
|
949
|
-
parent_id:
|
|
948
|
+
parent_id: h
|
|
950
949
|
};
|
|
951
|
-
await pe(we) && (t(),
|
|
950
|
+
await pe(we) && (t(), T(), U([]), j());
|
|
952
951
|
}
|
|
953
952
|
);
|
|
954
953
|
};
|
|
955
|
-
return /* @__PURE__ */
|
|
956
|
-
/* @__PURE__ */
|
|
957
|
-
|
|
954
|
+
return /* @__PURE__ */ i(J, { className: "border border-0 text-start", children: /* @__PURE__ */ i(J.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ i("form", { onSubmit: n(he), children: /* @__PURE__ */ i("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ C(Ie, { children: [
|
|
955
|
+
/* @__PURE__ */ i(O, { children: /* @__PURE__ */ i(
|
|
956
|
+
K,
|
|
958
957
|
{
|
|
959
958
|
label: "Type",
|
|
960
959
|
control: d,
|
|
961
|
-
error:
|
|
960
|
+
error: y,
|
|
962
961
|
options: me,
|
|
963
962
|
required: !0,
|
|
964
963
|
validation: {
|
|
@@ -970,13 +969,13 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
970
969
|
...a("templateType")
|
|
971
970
|
}
|
|
972
971
|
) }),
|
|
973
|
-
|
|
974
|
-
|
|
972
|
+
_ && _.length > 0 && /* @__PURE__ */ i(O, { children: /* @__PURE__ */ i(
|
|
973
|
+
K,
|
|
975
974
|
{
|
|
976
975
|
label: "Sub Type",
|
|
977
976
|
control: d,
|
|
978
|
-
error:
|
|
979
|
-
options:
|
|
977
|
+
error: y,
|
|
978
|
+
options: _,
|
|
980
979
|
required: !0,
|
|
981
980
|
validation: {
|
|
982
981
|
required: {
|
|
@@ -987,23 +986,23 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
987
986
|
...a("subTemplateType")
|
|
988
987
|
}
|
|
989
988
|
) }),
|
|
990
|
-
/* @__PURE__ */
|
|
991
|
-
|
|
989
|
+
/* @__PURE__ */ i(O, { children: /* @__PURE__ */ i(
|
|
990
|
+
K,
|
|
992
991
|
{
|
|
993
992
|
label: "Template",
|
|
994
993
|
control: d,
|
|
995
|
-
error:
|
|
994
|
+
error: y,
|
|
996
995
|
options: ye(),
|
|
997
996
|
required: !1,
|
|
998
997
|
...a("template")
|
|
999
998
|
}
|
|
1000
999
|
) }),
|
|
1001
|
-
/* @__PURE__ */
|
|
1002
|
-
|
|
1000
|
+
/* @__PURE__ */ i(O, { children: /* @__PURE__ */ i(
|
|
1001
|
+
ee,
|
|
1003
1002
|
{
|
|
1004
1003
|
label: "Name",
|
|
1005
1004
|
register: a,
|
|
1006
|
-
error:
|
|
1005
|
+
error: y,
|
|
1007
1006
|
required: !0,
|
|
1008
1007
|
name: "templateName",
|
|
1009
1008
|
validation: {
|
|
@@ -1014,71 +1013,71 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
1014
1013
|
}
|
|
1015
1014
|
}
|
|
1016
1015
|
) }),
|
|
1017
|
-
p("templateType")?.id === "2" && /* @__PURE__ */
|
|
1018
|
-
|
|
1016
|
+
p("templateType")?.id === "2" && /* @__PURE__ */ i(O, { children: /* @__PURE__ */ i(
|
|
1017
|
+
ee,
|
|
1019
1018
|
{
|
|
1020
1019
|
label: "Subject",
|
|
1021
1020
|
register: a,
|
|
1022
|
-
error:
|
|
1021
|
+
error: y,
|
|
1023
1022
|
required: !1,
|
|
1024
1023
|
name: "subject"
|
|
1025
1024
|
}
|
|
1026
1025
|
) }),
|
|
1027
|
-
/* @__PURE__ */ C(
|
|
1028
|
-
/* @__PURE__ */
|
|
1029
|
-
|
|
1026
|
+
/* @__PURE__ */ C(O, { className: "d-flex align-items-end justify-content-end gap-2 mb-3", children: [
|
|
1027
|
+
/* @__PURE__ */ i(
|
|
1028
|
+
X,
|
|
1030
1029
|
{
|
|
1031
1030
|
style: { width: "70px" },
|
|
1032
1031
|
variant: "primary",
|
|
1033
|
-
disabled:
|
|
1032
|
+
disabled: I || R || k || W,
|
|
1034
1033
|
onClick: () => {
|
|
1035
|
-
|
|
1034
|
+
f(void 0), T(), U([]), o();
|
|
1036
1035
|
},
|
|
1037
|
-
children:
|
|
1038
|
-
|
|
1036
|
+
children: R || k ? /* @__PURE__ */ i(
|
|
1037
|
+
Q,
|
|
1039
1038
|
{
|
|
1040
1039
|
animation: "border",
|
|
1041
1040
|
style: { width: "11px", height: "11px" },
|
|
1042
1041
|
size: "sm",
|
|
1043
1042
|
role: "status",
|
|
1044
1043
|
className: "me-1",
|
|
1045
|
-
children: /* @__PURE__ */
|
|
1044
|
+
children: /* @__PURE__ */ i("span", { className: "visually-hidden", children: "Loading..." })
|
|
1046
1045
|
}
|
|
1047
1046
|
) : "Clear"
|
|
1048
1047
|
}
|
|
1049
1048
|
),
|
|
1050
|
-
(p("templateType")?.id.toString() !== "2" || (p("templateType")?.id.toString() === "2" && (
|
|
1051
|
-
|
|
1049
|
+
(p("templateType")?.id.toString() !== "2" || (p("templateType")?.id.toString() === "2" && (u?.id ?? "")) !== "") && /* @__PURE__ */ i(ve, { children: /* @__PURE__ */ i(
|
|
1050
|
+
X,
|
|
1052
1051
|
{
|
|
1053
1052
|
type: "submit",
|
|
1054
1053
|
variant: "primary",
|
|
1055
1054
|
style: { width: "80px" },
|
|
1056
|
-
disabled:
|
|
1057
|
-
children:
|
|
1058
|
-
|
|
1055
|
+
disabled: I || R || k || W,
|
|
1056
|
+
children: R || k ? /* @__PURE__ */ i(
|
|
1057
|
+
Q,
|
|
1059
1058
|
{
|
|
1060
1059
|
animation: "border",
|
|
1061
1060
|
style: { width: "11px", height: "11px" },
|
|
1062
1061
|
size: "sm",
|
|
1063
1062
|
role: "status",
|
|
1064
1063
|
className: "me-1",
|
|
1065
|
-
children: /* @__PURE__ */
|
|
1064
|
+
children: /* @__PURE__ */ i("span", { className: "visually-hidden", children: "Loading..." })
|
|
1066
1065
|
}
|
|
1067
|
-
) :
|
|
1066
|
+
) : u?.readonly ? "Save as" : "Save"
|
|
1068
1067
|
}
|
|
1069
1068
|
) })
|
|
1070
1069
|
] })
|
|
1071
1070
|
] }) }) }) }) });
|
|
1072
1071
|
}, et = ({ config: e }) => {
|
|
1073
|
-
const [
|
|
1074
|
-
return /* @__PURE__ */
|
|
1075
|
-
/* @__PURE__ */
|
|
1072
|
+
const [r, o] = S(), [a, n] = S(!1);
|
|
1073
|
+
return /* @__PURE__ */ i(je, { configs: e, children: /* @__PURE__ */ i(Re, { children: /* @__PURE__ */ C("div", { className: "root-widget", children: [
|
|
1074
|
+
/* @__PURE__ */ i(
|
|
1076
1075
|
Ve,
|
|
1077
1076
|
{
|
|
1078
|
-
templateLoading:
|
|
1077
|
+
templateLoading: n,
|
|
1079
1078
|
onSelectItem: (d) => {
|
|
1080
|
-
if (
|
|
1081
|
-
let p =
|
|
1079
|
+
if (o(d), window.StripoEditorApi && window.StripoEditorApi.actionsApi) {
|
|
1080
|
+
let p = M;
|
|
1082
1081
|
window.StripoEditorApi.actionsApi.updateHtmlAndCss(
|
|
1083
1082
|
d?.html ?? p,
|
|
1084
1083
|
d?.css ?? "",
|
|
@@ -1087,20 +1086,20 @@ const re = /* @__PURE__ */ Ue(Fe), se = (e) => e.data.isSeparator ? /* @__PURE__
|
|
|
1087
1086
|
}
|
|
1088
1087
|
},
|
|
1089
1088
|
onReset: () => {
|
|
1090
|
-
|
|
1091
|
-
|
|
1089
|
+
n(!1), o(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
|
|
1090
|
+
M,
|
|
1092
1091
|
"",
|
|
1093
1092
|
""
|
|
1094
1093
|
);
|
|
1095
1094
|
}
|
|
1096
1095
|
}
|
|
1097
1096
|
),
|
|
1098
|
-
/* @__PURE__ */
|
|
1097
|
+
/* @__PURE__ */ i(
|
|
1099
1098
|
$e,
|
|
1100
1099
|
{
|
|
1101
1100
|
templateHTML: {
|
|
1102
|
-
css:
|
|
1103
|
-
html:
|
|
1101
|
+
css: r?.css ?? "",
|
|
1102
|
+
html: r?.html ?? M
|
|
1104
1103
|
},
|
|
1105
1104
|
loading: !1,
|
|
1106
1105
|
className: "col-span-5"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(w,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("@tanstack/react-query"),require("axios"),require("react-bootstrap"),require("react-hook-form"),require("react-select")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@tanstack/react-query","axios","react-bootstrap","react-hook-form","react-select"],e):(w=typeof globalThis<"u"?globalThis:w||self,e(w.EnerexTemplateEditor={},w.jsxRuntime,w.React,w.reactQuery,w.axios,w.reactBootstrap,w.reactHookForm,w.Select$1))})(this,function(w,e,p,S,W,u,B,H){"use strict";const L=`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
|
|
2
2
|
<html\r
|
|
3
3
|
dir="ltr"\r
|
|
4
4
|
xmlns:o="urn:schemas-microsoft-com:office:office"\r
|
|
@@ -354,8 +354,8 @@
|
|
|
354
354
|
</div>\r
|
|
355
355
|
</body>\r
|
|
356
356
|
</html>\r
|
|
357
|
-
`,
|
|
357
|
+
`,Y=p.createContext(void 0),re=({children:t,configs:s})=>{const[o,l]=p.useState(s.clientId),[r,n]=p.useState(s.apiKey),[i,d]=p.useState(s.enerexIdentifier),[m,E]=p.useState(s.projectId),I=b=>{n(b.apiKey),l(b.clientId),E(b.projectId),d(b.enerexIdentifier)};return e.jsx(Y.Provider,{value:{clientId:o,apiKey:r,setConfiguration:I,enerexIdentifier:i,projectId:m},children:t})},C=()=>{const t=p.useContext(Y);if(!t)throw new Error("widgetConfig must be used within a ConfigProvider");return t},J=(t="",s)=>({get:async(r,n)=>{try{const i=await W.get(`${t}${r}`,n??s);if(i.status===200)return i.data}catch(i){throw i}},post:async(r,n,i)=>{try{const d=await W.post(`${t}${r}`,n,i??s);if(d.status===200)return d.data}catch(d){throw d}}}),$={EDITOR_SCRIPT_URL:"https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",EDITOR_PLUGIN_ID:"1afdc3161ec7409a8627a1c8561d45f5",EDITOR_SECRET_KEY:"54ba748ed7e94f2e929555783acb03da",API_BASE_URL:"https://dev-socket.enerex.com/common/api"},X=p.createContext({get:()=>{throw new Error("HttpClientContext.get not implemented")},post:()=>{throw new Error("HttpClientContext.post not implemented")}}),se=({children:t})=>{const{clientId:s,apiKey:o}=C(),l={headers:{client_id:s,"x-api-key":o}},{get:r,post:n}=J($.API_BASE_URL,l);return e.jsx(X.Provider,{value:{get:r,post:n},children:t})},oe=({children:t})=>{const s=new S.QueryClient;return e.jsx(se,{children:e.jsx(S.QueryClientProvider,{client:s,children:t})})},ie=t=>{const s=Array.from(new Set(t.map(l=>l.category))),o=[];return s.forEach(l=>{const r=t.filter(n=>n.category===l).map(n=>({label:n.label,value:n.value,hint:n.hint,hidden:n.hidden}));o.push({category:l,entries:r})}),o},q=()=>{const t=p.useContext(X);if(t)return t;throw new Error("useHttpClient must be used within a HttpClientProvider")},P={Template_list:"/Template/list/",Template:"/Template/GetTemplate/",MergeTags:"/Template/TemplateMergeTags/",ExcludeCategory:"/Template/GetExcludeCategories/",SaveTemplate:"/Template/save-update/",TemplateTypes:"/Template/TemplateTypes/"},le=()=>{const t=q(),{enerexIdentifier:s,projectId:o}=C();return S.useQuery({queryKey:["getTemplateTags"],queryFn:async r=>await t.get(`${P.MergeTags}${o}/${s}`)})},ae=()=>{const t=q(),{enerexIdentifier:s,projectId:o}=C();return S.useQuery({queryKey:["getExcludeCategory"],queryFn:async r=>await t.get(`${P.ExcludeCategory}${o}/${s}`)})},de=({templateHTML:t,className:s="",loading:o=!1})=>{const{post:l}=J(),{data:r}=le(),{data:n}=ae(),[i,d]=p.useState(t??{html:L,css:""}),{enerexIdentifier:m,projectId:E}=C(),I=p.useRef(null),b="https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png",_="https://plugins.stripo.email/api/v1/auth";p.useEffect(()=>{(async()=>(await A(),r&&n&&await N($.EDITOR_SCRIPT_URL)))()},[r,n]);async function A(){window.Zone||await new Promise((h,g)=>{const y=document.createElement("script");y.src="https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";const v=document.querySelector("script[nonce]")?.nonce;v&&y.setAttribute("nonce",v),y.onload=()=>h(),y.onerror=()=>g(new Error("Failed to load zone.js")),document.head.appendChild(y)})}async function N(h){let g=document.getElementById("UiEditorScript");g||(g=document.createElement("script"),g.id="UiEditorScript",g.src=h,g.onload=async()=>{await f()},document.body.appendChild(g)),await new Promise(y=>g.addEventListener("load",()=>y(),{once:!0}))}const f=async()=>{const h=I.current;if(!h){console.error("Missing #stripoEditorContainer in DOM");return}if(!window.UIEditor||typeof window.UIEditor.initEditor!="function"){console.error("UIEditor script not loaded or not exposing initEditor");return}const g={html:i.html,css:i.css,modulesExcludedCategories:n??[],forceRecreate:!0,metadata:{emailId:`${E}_${m}`,userId:"1",avatarUrl:b},locale:"en",onTokenRefreshRequest:async y=>{const v={pluginId:$.EDITOR_PLUGIN_ID,secretKey:$.EDITOR_SECRET_KEY,userId:"12",role:"user"},O=await l(_,v);O?.token&&y(O.token)},mergeTags:ie(r??[])};for(const[y,v]of Object.entries({codeEditorButtonSelector:"#codeEditor",undoButtonSelector:"#undoButton",redoButtonSelector:"#redoButton",mobileViewButtonSelector:"#mobileViewButton",desktopViewButtonSelector:"#desktopViewButton"}))h.ownerDocument&&h.getRootNode()instanceof ShadowRoot&&h.getRootNode().querySelector(v)&&(g[y]=v);await window.UIEditor.initEditor(h,g)};return e.jsx("div",{className:"position-relative",children:e.jsxs("div",{className:`editor-container ${s}`,children:[o&&e.jsx("div",{className:"loading-overlay",children:e.jsx(u.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1"})}),e.jsx("div",{id:"externalSystemContainer"}),e.jsx("div",{id:"stripoEditorContainer",ref:I})]})})},Z=({label:t,register:s,validation:o,required:l=!1,name:r,error:n,className:i="",...d})=>e.jsxs(u.Form.Group,{className:i+" mb-1",children:[t?e.jsxs(u.Form.Label,{className:"mb-3 d-block form-label",children:[t,l&&e.jsx("label",{className:"text-danger",children:"*"})]}):null,e.jsx(u.Form.Control,{name:r,type:"text",...d,isInvalid:!!(n&&n[r]),...s?s(r,{...o}):{},className:`react-select__control ${n&&n[r]&&"border border-danger"}`}),n&&n[r]?e.jsx(u.Form.Control.Feedback,{type:"invalid",children:n[r].message}):null]}),ce=()=>{const t=q(),{enerexIdentifier:s,projectId:o}=C();return S.useQuery({queryKey:["getTemplatesList"],queryFn:async r=>await t.get(`${P.Template_list}${o}/${s}`)})};function z(t){return t.sort((s,o)=>s.name.localeCompare(o.name))}const pe=()=>{const t=q(),{enerexIdentifier:s,projectId:o}=C();return S.useMutation({mutationKey:["getTemplate"],mutationFn:async({id:r})=>{if(r)return await t.get(`${P.Template}${s}/${r}/${o}`)}})},me=()=>{const t=q(),{enerexIdentifier:s,projectId:o}=C();return S.useQuery({queryKey:["getTemplateTypes"],queryFn:async r=>await t.get(`${P.TemplateTypes}${s}/${o}`)})};function ue(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var V={exports:{}};/*!
|
|
358
358
|
Copyright (c) 2018 Jed Watson.
|
|
359
359
|
Licensed under the MIT License (MIT), see
|
|
360
360
|
http://jedwatson.github.io/classnames
|
|
361
|
-
*/var
|
|
361
|
+
*/var Q;function fe(){return Q||(Q=1,function(t){(function(){var s={}.hasOwnProperty;function o(){for(var n="",i=0;i<arguments.length;i++){var d=arguments[i];d&&(n=r(n,l(d)))}return n}function l(n){if(typeof n=="string"||typeof n=="number")return n;if(typeof n!="object")return"";if(Array.isArray(n))return o.apply(null,n);if(n.toString!==Object.prototype.toString&&!n.toString.toString().includes("[native code]"))return n.toString();var i="";for(var d in n)s.call(n,d)&&n[d]&&(i=r(i,d));return i}function r(n,i){return i?n?n+" "+i:n+i:n}t.exports?(o.default=o,t.exports=o):window.classNames=o})()}(V)),V.exports}var ge=fe();const R=ue(ge),ee=t=>t.data.isSeparator?e.jsx("div",{style:{padding:0,margin:"2px 0"},children:e.jsx("hr",{style:{border:0,borderTop:"1px solid #bdbdbdff",padding:0,margin:0}})}):e.jsx(H.components.Option,{...t}),ye=({name:t="",control:s,options:o,multiple:l=!1,placeholder:r,validation:n,labelKey:i="name",disabled:d,isInvalid:m,value:E,onChange:I,uncontrolled:b,menuPlacement:_="auto",closeOnSelect:A=!0})=>{const N={control:f=>({...f,minHeight:"33px",borderColor:m?"var(--bs-form-invalid-border-color) !important":"var(--ct-input-border-color)",backgroundImage:m?'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",backgroundRepeat:"no-repeat",backgroundPosition:"right calc(0.375em + 0.225rem) center",backgroundSize:"calc(0.75em + 0.45rem) calc(0.75em + 0.45rem)","&:hover":{borderColor:m?"var(--bs-form-invalid-border-color)":"var(--ct-input-border-color)"},"& .react-select__single-value":{color:"var(--ct-input-color) !important"},"& .react-select__placeholder":{color:"var(--ct-input-placeholder-color) !important"},"& .react-select__indicators":{display:"none"}}),menu:f=>({...f,marginTop:0,width:"max-content",minWidth:"100%"}),menuPortal:f=>({...f,zIndex:9999}),multiValueRemove:f=>({...f,display:d?"none":"block"})};return b?e.jsx(H,{components:{Option:ee},isOptionDisabled:f=>!!f.isSeparator,className:R({"is-invalid":m}),styles:N,classNamePrefix:"react-select",isMulti:l,options:o,onChange:I,placeholder:r,menuPortalTarget:document.body,value:E,getOptionLabel:typeof i=="string"?f=>f[i]:i,getOptionValue:f=>f.id,isDisabled:d,menuPlacement:_,closeMenuOnSelect:A}):e.jsx(B.Controller,{control:s,name:t,rules:n,render:({field:{onChange:f,value:h,onBlur:g}})=>e.jsx(H,{components:{Option:ee},isOptionDisabled:y=>!!y.isSeparator,className:R({"is-invalid":m}),styles:N,classNamePrefix:"react-select",isMulti:l,options:o,onBlur:g,onChange:f,placeholder:r,menuPortalTarget:document.body,value:h,getOptionLabel:typeof i=="string"?y=>y[i]:i,getOptionValue:y=>y.id,isDisabled:d,menuPlacement:_,closeMenuOnSelect:A},h?JSON.stringify(h):"reset")})},K=({label:t,name:s,validation:o,control:l,error:r,...n})=>e.jsxs(u.Form.Group,{className:"mb-1",children:[t&&e.jsxs(u.Form.Label,{className:"mb-3 d-block form-label",children:[t," ",n.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ye,{control:l,options:n.options??[],validation:o,isInvalid:r&&!!r[s],name:s}),r&&r[s]?e.jsx(u.Form.Control.Feedback,{type:"invalid",children:r[s].message}):null]}),he=()=>{const t=q();S.useQueryClient();const{enerexIdentifier:s,projectId:o}=C();return S.useMutation({mutationKey:["saveTemplate"],mutationFn:async r=>(r.enerexIdentifier=s??"",r.projectId=o??"",await t.post(`${P.SaveTemplate}`,r))})},G={id:"",name:"New (Blank)"},te={id:"",name:"Separator",isSeparator:!0},be=({onSelectItem:t,templateLoading:s,onReset:o})=>{const{register:l,handleSubmit:r,clearErrors:n,setValue:i,control:d,watch:m,reset:E,setError:I,formState:{errors:b}}=B.useForm({defaultValues:{templateName:"",subTemplateType:void 0,subject:"",templateType:void 0,template:G},mode:"onChange"}),{data:_,refetch:A,isLoading:N}=ce(),[f,h]=p.useState([]),[g,y]=p.useState(),[v,O]=p.useState(),{mutateAsync:Te,isPending:k}=pe(),{mutateAsync:ve,isPending:F}=he(),{data:M,isLoading:ne}=me(),[xe,Se]=p.useState([]),[j,U]=p.useState([]);p.useEffect(()=>{if(M){let a=M.filter(c=>c.id!=null).sort((c,x)=>c.name.localeCompare(x.name));Se(z(a.filter(c=>c.parent_id===0))),U(z(a.filter(c=>c.parent_id.toString()===`${m("templateType")?.id}`)))}},[M]);const Ce=(a,c)=>{let x=[];return a.forEach((T,D)=>{c.includes(D)&&D!==0&&x.push(te),x.push(T)}),x};p.useEffect(()=>{s(!!k)},[k]),p.useEffect(()=>{_?.sort((a,c)=>a.readonly!==c.readonly?(a.readonly?0:1)-(c.readonly?0:1):a.name.localeCompare(c.name)),h(_??[])},[_]);const Ee=async a=>{y(a),a&&!a.readonly?(i("templateName",a?.name),n()):(i("templateName",""),i("subject",""));const c=await Te({id:a?.id});O(c||void 0)};p.useEffect(()=>{if(i("template",G),m("templateType")){let a=M?.filter(c=>c.id!==void 0)??[];U(z(a.filter(c=>c.parent_id.toString()===`${m("templateType")?.id}`))),i("subTemplateType",void 0)}},[m("templateType")]),p.useEffect(()=>{let a=f.find(c=>c.id===m("template")?.id);Ee(a)},[m("template")]),p.useEffect(()=>{v&&g?(t(v),i("subject",v.subject??"")):t(void 0)},[v,g,t]);const Ie=()=>{let a=[G],c=f.filter(T=>(T.type?.toString()===m(j.length>0?"subTemplateType":"templateType")?.id.toString()||T.type===null)&&m(j.length>0?"subTemplateType":"templateType")?.id!=null),x=Ce(c,[c.findIndex(T=>!T.readonly)]);return x.length>0&&(a.push(te),a=[...a,...x.map(T=>({id:T.id,name:T.name,isSeparator:T.isSeparator}))]),a.length?a:[]},_e=a=>{window.StripoEditorApi.actionsApi.getTemplateData(async c=>{let x=a.template.id,T="";g?.readonly&&(x="",T=a.template.id);let D=f.find(qe=>qe.name===a.templateName.trim());if(D&&D.id!==x){I("templateName",{type:"validate",message:"Template name already exists. Please choose a different name."});return}let Ne=!!(j&&j.length>0);const je={enerexIdentifier:"",projectId:"",templateId:x,templateType:Ne?a.subTemplateType.id:a.templateType.id,name:a.templateName.trim(),html:c.html,css:c.css,subject:a.templateType.id==="2"?a?.subject??"":"",parent_id:T};await ve(je)&&(n(),E(),U([]),A())})};return e.jsx(u.Card,{className:"border border-0 text-start",children:e.jsx(u.Card.Body,{className:"pe-0 ps-2",children:e.jsx("form",{onSubmit:r(_e),children:e.jsx("div",{className:"template-list-container gap-3",children:e.jsxs(u.Row,{children:[e.jsx(u.Col,{children:e.jsx(K,{label:"Type",control:d,error:b,options:xe,required:!0,validation:{required:{value:!0,message:"Select a type"}},...l("templateType")})}),j&&j.length>0&&e.jsx(u.Col,{children:e.jsx(K,{label:"Sub Type",control:d,error:b,options:j,required:!0,validation:{required:{value:!0,message:"Select a type"}},...l("subTemplateType")})}),e.jsx(u.Col,{children:e.jsx(K,{label:"Template",control:d,error:b,options:Ie(),required:!1,...l("template")})}),e.jsx(u.Col,{children:e.jsx(Z,{label:"Name",register:l,error:b,required:!0,name:"templateName",validation:{required:{value:!0,message:"Enter a name"}}})}),m("templateType")?.id==="2"&&e.jsx(u.Col,{children:e.jsx(Z,{label:"Subject",register:l,error:b,required:!1,name:"subject"})}),e.jsxs(u.Col,{className:"d-flex align-items-end justify-content-end gap-2 mb-3",children:[e.jsx(u.Button,{style:{width:"70px"},variant:"primary",disabled:N||k||F||ne,onClick:()=>{y(void 0),E(),U([]),o()},children:k||F?e.jsx(u.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:e.jsx("span",{className:"visually-hidden",children:"Loading..."})}):"Clear"}),(m("templateType")?.id.toString()!=="2"||(m("templateType")?.id.toString()==="2"&&(g?.id??""))!=="")&&e.jsx(e.Fragment,{children:e.jsx(u.Button,{type:"submit",variant:"primary",style:{width:"80px"},disabled:N||k||F||ne,children:k||F?e.jsx(u.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:e.jsx("span",{className:"visually-hidden",children:"Loading..."})}):g?.readonly?"Save as":"Save"})})]})]})})})})})},we=({config:t})=>{const[s,o]=p.useState(),[l,r]=p.useState(!1),n=d=>{if(o(d),window.StripoEditorApi&&window.StripoEditorApi.actionsApi){let m=L;window.StripoEditorApi.actionsApi.updateHtmlAndCss(d?.html??m,d?.css??"","")}},i=()=>{r(!1),o(void 0),window.StripoEditorApi&&window.StripoEditorApi.actionsApi&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(L,"","")};return e.jsx(re,{configs:t,children:e.jsx(oe,{children:e.jsxs("div",{className:"root-widget",children:[e.jsx(be,{templateLoading:r,onSelectItem:n,onReset:i}),e.jsx(de,{templateHTML:{css:s?.css??"",html:s?.html??L},loading:!1,className:"col-span-5"})]})})})};w.EditorWidget=we,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|