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