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