@enerex/template-studio 1.1.13 → 1.1.15
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,20 +1,20 @@
|
|
|
1
|
-
import { jsx as s, jsxs as
|
|
2
|
-
import
|
|
1
|
+
import { jsx as s, jsxs as b } from "react/jsx-runtime";
|
|
2
|
+
import $, { useContext as te, useState as x, useEffect as q } from "react";
|
|
3
3
|
import { QueryClient as pe, QueryClientProvider as me, useQuery as j, useMutation as ne, useQueryClient as ue } from "@tanstack/react-query";
|
|
4
|
-
import
|
|
5
|
-
import { Spinner as U, Form as
|
|
4
|
+
import G from "axios";
|
|
5
|
+
import { Spinner as U, Form as I, ListGroup as K, Popover as W, OverlayTrigger as ge, Card as Q, Button as Y, Row as fe, Col as X } from "react-bootstrap";
|
|
6
6
|
import { Controller as ye, useForm as he } from "react-hook-form";
|
|
7
7
|
import J from "react-select";
|
|
8
|
-
const re =
|
|
8
|
+
const re = $.createContext(
|
|
9
9
|
void 0
|
|
10
10
|
), be = ({
|
|
11
11
|
children: t,
|
|
12
12
|
configs: r
|
|
13
13
|
}) => {
|
|
14
|
-
const [i, a] =
|
|
14
|
+
const [i, a] = $.useState(r.clientId), [n, e] = $.useState(r.apiKey), [o, l] = $.useState(
|
|
15
15
|
r.enerexIdentifier
|
|
16
|
-
), [p,
|
|
17
|
-
e(
|
|
16
|
+
), [p, m] = $.useState(r.projectId), u = (h) => {
|
|
17
|
+
e(h.apiKey), a(h.clientId), m(h.projectId), l(h.enerexIdentifier);
|
|
18
18
|
};
|
|
19
19
|
return /* @__PURE__ */ s(
|
|
20
20
|
re.Provider,
|
|
@@ -22,14 +22,14 @@ const re = _.createContext(
|
|
|
22
22
|
value: {
|
|
23
23
|
clientId: i,
|
|
24
24
|
apiKey: n,
|
|
25
|
-
setConfiguration:
|
|
25
|
+
setConfiguration: u,
|
|
26
26
|
enerexIdentifier: o,
|
|
27
27
|
projectId: p
|
|
28
28
|
},
|
|
29
29
|
children: t
|
|
30
30
|
}
|
|
31
31
|
);
|
|
32
|
-
},
|
|
32
|
+
}, w = () => {
|
|
33
33
|
const t = te(re);
|
|
34
34
|
if (!t)
|
|
35
35
|
throw new Error("widgetConfig must be used within a ConfigProvider");
|
|
@@ -392,7 +392,7 @@ const re = _.createContext(
|
|
|
392
392
|
</html>\r
|
|
393
393
|
`, se = (t = "", r) => ({ get: async (n, e) => {
|
|
394
394
|
try {
|
|
395
|
-
const o = await
|
|
395
|
+
const o = await G.get(
|
|
396
396
|
`${t}${n}`,
|
|
397
397
|
e ?? r
|
|
398
398
|
);
|
|
@@ -403,7 +403,7 @@ const re = _.createContext(
|
|
|
403
403
|
}
|
|
404
404
|
}, post: async (n, e, o) => {
|
|
405
405
|
try {
|
|
406
|
-
const l = await
|
|
406
|
+
const l = await G.post(
|
|
407
407
|
`${t}${n}`,
|
|
408
408
|
e,
|
|
409
409
|
o ?? r
|
|
@@ -413,14 +413,14 @@ const re = _.createContext(
|
|
|
413
413
|
} catch (l) {
|
|
414
414
|
throw l;
|
|
415
415
|
}
|
|
416
|
-
} }),
|
|
416
|
+
} }), O = {
|
|
417
417
|
EDITOR_SCRIPT_URL: "https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",
|
|
418
418
|
EDITOR_PLUGIN_ID: "1afdc3161ec7409a8627a1c8561d45f5",
|
|
419
419
|
EDITOR_SECRET_KEY: "54ba748ed7e94f2e929555783acb03da",
|
|
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
|
-
}, ie =
|
|
423
|
+
}, ie = $.createContext({
|
|
424
424
|
get: () => {
|
|
425
425
|
throw new Error("HttpClientContext.get not implemented");
|
|
426
426
|
},
|
|
@@ -428,12 +428,12 @@ const re = _.createContext(
|
|
|
428
428
|
throw new Error("HttpClientContext.post not implemented");
|
|
429
429
|
}
|
|
430
430
|
}), we = ({ children: t }) => {
|
|
431
|
-
const { clientId: r, apiKey: i } =
|
|
431
|
+
const { clientId: r, apiKey: i } = w(), a = {
|
|
432
432
|
headers: {
|
|
433
433
|
client_id: r,
|
|
434
434
|
"x-api-key": i
|
|
435
435
|
}
|
|
436
|
-
}, { get: n, post: e } = se(
|
|
436
|
+
}, { get: n, post: e } = se(O.API_BASE_URL, a);
|
|
437
437
|
return /* @__PURE__ */ s(ie.Provider, { value: { get: n, post: e }, children: t });
|
|
438
438
|
}, ve = ({ children: t }) => {
|
|
439
439
|
const r = new pe();
|
|
@@ -454,7 +454,7 @@ const re = _.createContext(
|
|
|
454
454
|
if (t)
|
|
455
455
|
return t;
|
|
456
456
|
throw new Error("useHttpClient must be used within a HttpClientProvider");
|
|
457
|
-
},
|
|
457
|
+
}, A = {
|
|
458
458
|
Template_list: "/Template/list/",
|
|
459
459
|
Template: "/Template/GetTemplate/",
|
|
460
460
|
MergeTags: "/Template/TemplateMergeTags/",
|
|
@@ -462,19 +462,19 @@ const re = _.createContext(
|
|
|
462
462
|
SaveTemplate: "/Template/save-update/",
|
|
463
463
|
TemplateTypes: "/Template/TemplateTypes/"
|
|
464
464
|
}, Ce = () => {
|
|
465
|
-
const t = P(), { enerexIdentifier: r, projectId: i } =
|
|
465
|
+
const t = P(), { enerexIdentifier: r, projectId: i } = w();
|
|
466
466
|
return j({
|
|
467
467
|
queryKey: ["getTemplateTags"],
|
|
468
468
|
queryFn: async (n) => await t.get(
|
|
469
|
-
`${
|
|
469
|
+
`${A.MergeTags}${i}/${r}`
|
|
470
470
|
)
|
|
471
471
|
});
|
|
472
472
|
}, xe = () => {
|
|
473
|
-
const t = P(), { enerexIdentifier: r, projectId: i } =
|
|
473
|
+
const t = P(), { enerexIdentifier: r, projectId: i } = w();
|
|
474
474
|
return j({
|
|
475
475
|
queryKey: ["getExcludeCategory"],
|
|
476
476
|
queryFn: async (n) => await t.get(
|
|
477
|
-
`${
|
|
477
|
+
`${A.ExcludeCategory}${i}/${r}`
|
|
478
478
|
)
|
|
479
479
|
});
|
|
480
480
|
}, Ie = ({
|
|
@@ -482,16 +482,16 @@ const re = _.createContext(
|
|
|
482
482
|
className: r = "",
|
|
483
483
|
loading: i = !1
|
|
484
484
|
}) => {
|
|
485
|
-
const { post: a } = se(), { data: n } = Ce(), { data: e } = xe(), [o, l] =
|
|
485
|
+
const { post: a } = se(), { data: n } = Ce(), { data: e } = xe(), [o, l] = x(
|
|
486
486
|
t ?? { html: H, css: "" }
|
|
487
|
-
), p = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png",
|
|
488
|
-
|
|
487
|
+
), { enerexIdentifier: p, projectId: m } = w(), u = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", h = "https://plugins.stripo.email/api/v1/auth";
|
|
488
|
+
q(() => {
|
|
489
489
|
if (n && e && !document.getElementById("UiEditorScript")) {
|
|
490
|
-
const
|
|
491
|
-
|
|
490
|
+
const g = document.createElement("script");
|
|
491
|
+
g.id = "UiEditorScript", g.type = "module", g.src = O.EDITOR_SCRIPT_URL, g.onload = v, document.body.appendChild(g);
|
|
492
492
|
}
|
|
493
493
|
}, [n, e]);
|
|
494
|
-
const
|
|
494
|
+
const v = async () => {
|
|
495
495
|
window.UIEditor.initEditor(
|
|
496
496
|
document.querySelector("#stripoEditorContainer"),
|
|
497
497
|
{
|
|
@@ -500,20 +500,20 @@ const re = _.createContext(
|
|
|
500
500
|
modulesExcludedCategories: e ?? [],
|
|
501
501
|
forceRecreate: !0,
|
|
502
502
|
metadata: {
|
|
503
|
-
emailId:
|
|
503
|
+
emailId: `${m}_${p}`,
|
|
504
504
|
userId: "1",
|
|
505
505
|
username: "Plugin Demo User",
|
|
506
|
-
avatarUrl:
|
|
506
|
+
avatarUrl: u
|
|
507
507
|
},
|
|
508
508
|
locale: "en",
|
|
509
|
-
onTokenRefreshRequest: async function(
|
|
510
|
-
const
|
|
511
|
-
pluginId:
|
|
512
|
-
secretKey:
|
|
509
|
+
onTokenRefreshRequest: async function(g) {
|
|
510
|
+
const T = {
|
|
511
|
+
pluginId: O.EDITOR_PLUGIN_ID,
|
|
512
|
+
secretKey: O.EDITOR_SECRET_KEY,
|
|
513
513
|
userId: "12",
|
|
514
514
|
role: "user"
|
|
515
|
-
},
|
|
516
|
-
|
|
515
|
+
}, c = await a(h, T);
|
|
516
|
+
c && g(c.token);
|
|
517
517
|
},
|
|
518
518
|
codeEditorButtonSelector: "#codeEditor",
|
|
519
519
|
undoButtonSelector: "#undoButton",
|
|
@@ -524,7 +524,7 @@ const re = _.createContext(
|
|
|
524
524
|
}
|
|
525
525
|
);
|
|
526
526
|
};
|
|
527
|
-
return /* @__PURE__ */ s("div", { className: "position-relative", children: /* @__PURE__ */
|
|
527
|
+
return /* @__PURE__ */ s("div", { className: "position-relative", children: /* @__PURE__ */ b("div", { className: `editor-container ${r}`, children: [
|
|
528
528
|
i && /* @__PURE__ */ s("div", { className: "loading-overlay", children: /* @__PURE__ */ s(
|
|
529
529
|
U,
|
|
530
530
|
{
|
|
@@ -546,13 +546,13 @@ const re = _.createContext(
|
|
|
546
546
|
name: n,
|
|
547
547
|
error: e,
|
|
548
548
|
...o
|
|
549
|
-
}) => /* @__PURE__ */
|
|
550
|
-
t ? /* @__PURE__ */
|
|
549
|
+
}) => /* @__PURE__ */ b(I.Group, { className: "mb-1", children: [
|
|
550
|
+
t ? /* @__PURE__ */ b(I.Label, { className: "mb-3 d-block form-label", children: [
|
|
551
551
|
t,
|
|
552
552
|
a && /* @__PURE__ */ s("label", { className: "text-danger", children: "*" })
|
|
553
553
|
] }) : null,
|
|
554
554
|
/* @__PURE__ */ s(
|
|
555
|
-
|
|
555
|
+
I.Control,
|
|
556
556
|
{
|
|
557
557
|
name: n,
|
|
558
558
|
type: "text",
|
|
@@ -564,7 +564,7 @@ const re = _.createContext(
|
|
|
564
564
|
className: `form-control ${e && e[n] && "border border-danger"}`
|
|
565
565
|
}
|
|
566
566
|
),
|
|
567
|
-
e && e[n] ? /* @__PURE__ */ s(
|
|
567
|
+
e && e[n] ? /* @__PURE__ */ s(I.Control.Feedback, { type: "invalid", children: e[n].message }) : null
|
|
568
568
|
] });
|
|
569
569
|
function Ne({
|
|
570
570
|
items: t,
|
|
@@ -608,7 +608,7 @@ const Se = (t) => /* @__PURE__ */ s("svg", { xmlns: "http://www.w3.org/2000/svg"
|
|
|
608
608
|
onCopy: n,
|
|
609
609
|
onSelect: e,
|
|
610
610
|
subItem: o = !1
|
|
611
|
-
}) => /* @__PURE__ */
|
|
611
|
+
}) => /* @__PURE__ */ b(
|
|
612
612
|
"div",
|
|
613
613
|
{
|
|
614
614
|
className: "ps-1 py-1 d-flex position-relative",
|
|
@@ -651,15 +651,15 @@ const Se = (t) => /* @__PURE__ */ s("svg", { xmlns: "http://www.w3.org/2000/svg"
|
|
|
651
651
|
) })
|
|
652
652
|
]
|
|
653
653
|
}
|
|
654
|
-
),
|
|
655
|
-
const t = P(), { enerexIdentifier: r, projectId: i } =
|
|
654
|
+
), $e = () => {
|
|
655
|
+
const t = P(), { enerexIdentifier: r, projectId: i } = w();
|
|
656
656
|
return j({
|
|
657
657
|
queryKey: ["getTemplatesList"],
|
|
658
658
|
queryFn: async (n) => await t.get(
|
|
659
|
-
`${
|
|
659
|
+
`${A.Template_list}${i}/${r}`
|
|
660
660
|
)
|
|
661
661
|
});
|
|
662
|
-
},
|
|
662
|
+
}, Pe = (t, r = []) => {
|
|
663
663
|
const i = /^(?:\(copy(?:-(\d+))?\)\s)?(.+)$/, a = t.match(i);
|
|
664
664
|
if (!a) return `(copy) ${t}`;
|
|
665
665
|
const n = a[2], e = new RegExp(
|
|
@@ -671,34 +671,34 @@ const Se = (t) => /* @__PURE__ */ s("svg", { xmlns: "http://www.w3.org/2000/svg"
|
|
|
671
671
|
let o = 1;
|
|
672
672
|
const l = r.filter((p) => e.test(p));
|
|
673
673
|
return l.length === 0 ? `(copy) ${n}` : (l.forEach((p) => {
|
|
674
|
-
const
|
|
675
|
-
if (
|
|
676
|
-
const
|
|
677
|
-
!isNaN(
|
|
674
|
+
const m = p.match(e);
|
|
675
|
+
if (m && m[1]) {
|
|
676
|
+
const u = parseInt(m[1], 10);
|
|
677
|
+
!isNaN(u) && u >= o && (o = u + 1);
|
|
678
678
|
} else
|
|
679
679
|
o = Math.max(o, 2);
|
|
680
680
|
}), `(copy-${o}) ${n}`);
|
|
681
681
|
}, Ae = () => {
|
|
682
|
-
const t = P(), { enerexIdentifier: r, projectId: i } =
|
|
682
|
+
const t = P(), { enerexIdentifier: r, projectId: i } = w();
|
|
683
683
|
return ne({
|
|
684
684
|
mutationKey: ["getTemplate"],
|
|
685
685
|
mutationFn: async ({ id: n }) => {
|
|
686
686
|
if (n)
|
|
687
687
|
return await t.get(
|
|
688
|
-
`${
|
|
688
|
+
`${A.Template}${r}/${n}/${i}`
|
|
689
689
|
);
|
|
690
690
|
}
|
|
691
691
|
});
|
|
692
692
|
}, Re = () => {
|
|
693
|
-
const t = P(), { enerexIdentifier: r, projectId: i } =
|
|
693
|
+
const t = P(), { enerexIdentifier: r, projectId: i } = w();
|
|
694
694
|
return j({
|
|
695
695
|
queryKey: ["getTemplateTypes"],
|
|
696
696
|
queryFn: async (n) => await t.get(
|
|
697
|
-
`${
|
|
697
|
+
`${A.TemplateTypes}${r}/${i}`
|
|
698
698
|
)
|
|
699
699
|
});
|
|
700
700
|
};
|
|
701
|
-
function
|
|
701
|
+
function ke(t) {
|
|
702
702
|
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
703
703
|
}
|
|
704
704
|
var M = { exports: {} };
|
|
@@ -708,7 +708,7 @@ var M = { exports: {} };
|
|
|
708
708
|
http://jedwatson.github.io/classnames
|
|
709
709
|
*/
|
|
710
710
|
var Z;
|
|
711
|
-
function
|
|
711
|
+
function qe() {
|
|
712
712
|
return Z || (Z = 1, function(t) {
|
|
713
713
|
(function() {
|
|
714
714
|
var r = {}.hasOwnProperty;
|
|
@@ -740,8 +740,8 @@ function ke() {
|
|
|
740
740
|
})();
|
|
741
741
|
}(M)), M.exports;
|
|
742
742
|
}
|
|
743
|
-
var
|
|
744
|
-
const ee = /* @__PURE__ */ De
|
|
743
|
+
var De = qe();
|
|
744
|
+
const ee = /* @__PURE__ */ ke(De), Oe = ({
|
|
745
745
|
name: t = "",
|
|
746
746
|
control: r,
|
|
747
747
|
options: i,
|
|
@@ -751,13 +751,13 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
751
751
|
labelKey: o = "name",
|
|
752
752
|
disabled: l,
|
|
753
753
|
isInvalid: p,
|
|
754
|
-
value:
|
|
755
|
-
onChange:
|
|
756
|
-
uncontrolled:
|
|
757
|
-
menuPlacement:
|
|
758
|
-
closeOnSelect:
|
|
754
|
+
value: m,
|
|
755
|
+
onChange: u,
|
|
756
|
+
uncontrolled: h,
|
|
757
|
+
menuPlacement: v = "auto",
|
|
758
|
+
closeOnSelect: g = !0
|
|
759
759
|
}) => {
|
|
760
|
-
const
|
|
760
|
+
const T = {
|
|
761
761
|
control: (c) => ({
|
|
762
762
|
...c,
|
|
763
763
|
minHeight: "33px",
|
|
@@ -795,25 +795,25 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
795
795
|
display: l ? "none" : "block"
|
|
796
796
|
})
|
|
797
797
|
};
|
|
798
|
-
return
|
|
798
|
+
return h ? /* @__PURE__ */ s(
|
|
799
799
|
J,
|
|
800
800
|
{
|
|
801
801
|
className: ee({
|
|
802
802
|
"is-invalid": p
|
|
803
803
|
}),
|
|
804
|
-
styles:
|
|
804
|
+
styles: T,
|
|
805
805
|
classNamePrefix: "react-select",
|
|
806
806
|
isMulti: a,
|
|
807
807
|
options: i,
|
|
808
|
-
onChange:
|
|
808
|
+
onChange: u,
|
|
809
809
|
placeholder: n,
|
|
810
810
|
menuPortalTarget: document.body,
|
|
811
|
-
value:
|
|
811
|
+
value: m,
|
|
812
812
|
getOptionLabel: typeof o == "string" ? (c) => c[o] : o,
|
|
813
813
|
getOptionValue: (c) => c.id,
|
|
814
814
|
isDisabled: l,
|
|
815
|
-
menuPlacement:
|
|
816
|
-
closeMenuOnSelect:
|
|
815
|
+
menuPlacement: v,
|
|
816
|
+
closeMenuOnSelect: g
|
|
817
817
|
}
|
|
818
818
|
) : /* @__PURE__ */ s(
|
|
819
819
|
ye,
|
|
@@ -821,13 +821,13 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
821
821
|
control: r,
|
|
822
822
|
name: t,
|
|
823
823
|
rules: e,
|
|
824
|
-
render: ({ field: { onChange: c, value:
|
|
824
|
+
render: ({ field: { onChange: c, value: C, onBlur: R } }) => /* @__PURE__ */ s(
|
|
825
825
|
J,
|
|
826
826
|
{
|
|
827
827
|
className: ee({
|
|
828
828
|
"is-invalid": p
|
|
829
829
|
}),
|
|
830
|
-
styles:
|
|
830
|
+
styles: T,
|
|
831
831
|
classNamePrefix: "react-select",
|
|
832
832
|
isMulti: a,
|
|
833
833
|
options: i,
|
|
@@ -835,14 +835,14 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
835
835
|
onChange: c,
|
|
836
836
|
placeholder: n,
|
|
837
837
|
menuPortalTarget: document.body,
|
|
838
|
-
value:
|
|
839
|
-
getOptionLabel: typeof o == "string" ? (
|
|
840
|
-
getOptionValue: (
|
|
838
|
+
value: C,
|
|
839
|
+
getOptionLabel: typeof o == "string" ? (E) => E[o] : o,
|
|
840
|
+
getOptionValue: (E) => E.id,
|
|
841
841
|
isDisabled: l,
|
|
842
|
-
menuPlacement:
|
|
843
|
-
closeMenuOnSelect:
|
|
842
|
+
menuPlacement: v,
|
|
843
|
+
closeMenuOnSelect: g
|
|
844
844
|
},
|
|
845
|
-
|
|
845
|
+
C ? JSON.stringify(C) : "reset"
|
|
846
846
|
)
|
|
847
847
|
}
|
|
848
848
|
);
|
|
@@ -853,8 +853,8 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
853
853
|
control: a,
|
|
854
854
|
error: n,
|
|
855
855
|
...e
|
|
856
|
-
}) => /* @__PURE__ */
|
|
857
|
-
t && /* @__PURE__ */
|
|
856
|
+
}) => /* @__PURE__ */ b(I.Group, { className: "mb-1", children: [
|
|
857
|
+
t && /* @__PURE__ */ b(I.Label, { className: "mb-3 d-block form-label", children: [
|
|
858
858
|
t,
|
|
859
859
|
" ",
|
|
860
860
|
e.required && /* @__PURE__ */ s("span", { className: "text-danger", children: "*" })
|
|
@@ -869,15 +869,15 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
869
869
|
name: r
|
|
870
870
|
}
|
|
871
871
|
),
|
|
872
|
-
n && n[r] ? /* @__PURE__ */ s(
|
|
872
|
+
n && n[r] ? /* @__PURE__ */ s(I.Control.Feedback, { type: "invalid", children: n[r].message }) : null
|
|
873
873
|
] }), Be = () => {
|
|
874
874
|
const t = P();
|
|
875
875
|
ue();
|
|
876
|
-
const { enerexIdentifier: r, projectId: i } =
|
|
876
|
+
const { enerexIdentifier: r, projectId: i } = w();
|
|
877
877
|
return ne({
|
|
878
878
|
mutationKey: ["saveTemplate"],
|
|
879
879
|
mutationFn: async (n) => (n.enerexIdentifier = r ?? "", n.projectId = i ?? "", await t.post(
|
|
880
|
-
`${
|
|
880
|
+
`${A.SaveTemplate}`,
|
|
881
881
|
n
|
|
882
882
|
))
|
|
883
883
|
});
|
|
@@ -893,7 +893,7 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
893
893
|
setValue: o,
|
|
894
894
|
control: l,
|
|
895
895
|
reset: p,
|
|
896
|
-
formState: { errors:
|
|
896
|
+
formState: { errors: m }
|
|
897
897
|
} = he({
|
|
898
898
|
defaultValues: {
|
|
899
899
|
templateName: "",
|
|
@@ -901,47 +901,47 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
901
901
|
},
|
|
902
902
|
mode: "onChange"
|
|
903
903
|
}), {
|
|
904
|
-
data:
|
|
905
|
-
refetch:
|
|
906
|
-
isLoading:
|
|
907
|
-
} =
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
904
|
+
data: u,
|
|
905
|
+
refetch: h,
|
|
906
|
+
isLoading: v
|
|
907
|
+
} = $e(), [g, T] = x([]), [c, C] = x(), [R, E] = x(), { mutateAsync: F, isPending: N } = Ae(), { mutateAsync: oe, isPending: D } = Be(), { data: k, isLoading: z } = Re(), [B, ae] = x([]);
|
|
908
|
+
q(() => {
|
|
909
|
+
k && ae(
|
|
910
|
+
k.map((d) => ({
|
|
911
911
|
id: `${d.id}`,
|
|
912
912
|
name: d.name
|
|
913
913
|
}))
|
|
914
914
|
);
|
|
915
|
-
}, [
|
|
916
|
-
r(!!
|
|
917
|
-
}, [
|
|
918
|
-
|
|
919
|
-
}, [
|
|
915
|
+
}, [k]), q(() => {
|
|
916
|
+
r(!!N);
|
|
917
|
+
}, [N]), q(() => {
|
|
918
|
+
T(u ?? []);
|
|
919
|
+
}, [u]);
|
|
920
920
|
const le = async (d, f) => {
|
|
921
|
-
f &&
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
),
|
|
927
|
-
const
|
|
928
|
-
return
|
|
929
|
-
|
|
930
|
-
}),
|
|
921
|
+
f && T((y) => {
|
|
922
|
+
const S = [...y], L = { ...f };
|
|
923
|
+
L.id = "", L.name = Pe(
|
|
924
|
+
L.name,
|
|
925
|
+
S.map((_) => _.name)
|
|
926
|
+
), S.splice(d + 1, 0, L), C(L), o("templateName", L.name);
|
|
927
|
+
const V = B.find((_) => _.id === `${f.type}`);
|
|
928
|
+
return V ? o("templateType", V) : o("templateType", void 0), e(), F({ id: f?.id }).then((_) => {
|
|
929
|
+
_ && E(_);
|
|
930
|
+
}), S;
|
|
931
931
|
});
|
|
932
932
|
}, ce = async (d) => {
|
|
933
|
-
if (
|
|
934
|
-
if (o("templateName", d?.name),
|
|
935
|
-
const y = B.find((
|
|
933
|
+
if (C(d), d) {
|
|
934
|
+
if (o("templateName", d?.name), k && k.find((y) => y.id === d.type)) {
|
|
935
|
+
const y = B.find((S) => S.id === `${d.type}`);
|
|
936
936
|
y && o("templateType", y);
|
|
937
937
|
} else
|
|
938
938
|
o("templateType", void 0);
|
|
939
939
|
e();
|
|
940
940
|
}
|
|
941
941
|
const f = await F({ id: d?.id });
|
|
942
|
-
f &&
|
|
942
|
+
f && E(f);
|
|
943
943
|
};
|
|
944
|
-
|
|
944
|
+
q(() => {
|
|
945
945
|
t(R && c ? R : void 0);
|
|
946
946
|
}, [R, c, t]);
|
|
947
947
|
const de = (d) => {
|
|
@@ -956,16 +956,16 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
956
956
|
html: f.html,
|
|
957
957
|
css: f.css
|
|
958
958
|
};
|
|
959
|
-
await oe(y) && (e(), c?.id === "" && p(),
|
|
959
|
+
await oe(y) && (e(), c?.id === "" && p(), h());
|
|
960
960
|
}
|
|
961
961
|
);
|
|
962
962
|
};
|
|
963
|
-
return /* @__PURE__ */ s(Q, { className: "border border-0 text-start", children: /* @__PURE__ */ s(Q.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */
|
|
963
|
+
return /* @__PURE__ */ s(Q, { className: "border border-0 text-start", children: /* @__PURE__ */ s(Q.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ b("form", { onSubmit: n(de), children: [
|
|
964
964
|
/* @__PURE__ */ s("label", { className: "mb-2", children: "Templates" }),
|
|
965
965
|
/* @__PURE__ */ s("div", { className: "template-list-container mb-3", children: /* @__PURE__ */ s(
|
|
966
966
|
Ne,
|
|
967
967
|
{
|
|
968
|
-
items:
|
|
968
|
+
items: g,
|
|
969
969
|
renderItem: (d, f) => /* @__PURE__ */ s(
|
|
970
970
|
_e,
|
|
971
971
|
{
|
|
@@ -985,7 +985,7 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
985
985
|
{
|
|
986
986
|
label: "Template Type",
|
|
987
987
|
control: l,
|
|
988
|
-
error:
|
|
988
|
+
error: m,
|
|
989
989
|
options: B,
|
|
990
990
|
required: !0,
|
|
991
991
|
validation: {
|
|
@@ -999,7 +999,7 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
999
999
|
{
|
|
1000
1000
|
label: "Template Name",
|
|
1001
1001
|
register: a,
|
|
1002
|
-
error:
|
|
1002
|
+
error: m,
|
|
1003
1003
|
required: !0,
|
|
1004
1004
|
name: "templateName",
|
|
1005
1005
|
validation: {
|
|
@@ -1008,17 +1008,17 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
1008
1008
|
}
|
|
1009
1009
|
),
|
|
1010
1010
|
/* @__PURE__ */ s("hr", {}),
|
|
1011
|
-
/* @__PURE__ */
|
|
1011
|
+
/* @__PURE__ */ b("div", { className: "d-flex justify-content-between mt-3 ", children: [
|
|
1012
1012
|
/* @__PURE__ */ s(
|
|
1013
1013
|
Y,
|
|
1014
1014
|
{
|
|
1015
1015
|
style: { width: "70px" },
|
|
1016
1016
|
variant: "primary",
|
|
1017
|
-
disabled:
|
|
1017
|
+
disabled: v || N || D || z,
|
|
1018
1018
|
onClick: () => {
|
|
1019
|
-
|
|
1019
|
+
C(void 0), p(), i();
|
|
1020
1020
|
},
|
|
1021
|
-
children:
|
|
1021
|
+
children: N || D ? /* @__PURE__ */ s(
|
|
1022
1022
|
U,
|
|
1023
1023
|
{
|
|
1024
1024
|
animation: "border",
|
|
@@ -1037,8 +1037,8 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
1037
1037
|
type: "submit",
|
|
1038
1038
|
variant: "primary",
|
|
1039
1039
|
style: { width: "80px" },
|
|
1040
|
-
disabled:
|
|
1041
|
-
children:
|
|
1040
|
+
disabled: v || N || D || z,
|
|
1041
|
+
children: N || D ? /* @__PURE__ */ s(
|
|
1042
1042
|
U,
|
|
1043
1043
|
{
|
|
1044
1044
|
animation: "border",
|
|
@@ -1054,8 +1054,8 @@ const ee = /* @__PURE__ */ De(qe), Oe = ({
|
|
|
1054
1054
|
] })
|
|
1055
1055
|
] }) }) });
|
|
1056
1056
|
}, We = ({ config: t }) => {
|
|
1057
|
-
const [r, i] =
|
|
1058
|
-
return /* @__PURE__ */ s(be, { configs: t, children: /* @__PURE__ */ s(ve, { children: /* @__PURE__ */ s("div", { className: "root-widget", children: /* @__PURE__ */
|
|
1057
|
+
const [r, i] = x(), [a, n] = x(!1);
|
|
1058
|
+
return /* @__PURE__ */ s(be, { configs: t, children: /* @__PURE__ */ s(ve, { children: /* @__PURE__ */ s("div", { className: "root-widget", children: /* @__PURE__ */ b(fe, { children: [
|
|
1059
1059
|
/* @__PURE__ */ s(X, { md: 3, lg: 2, className: "p-0", children: /* @__PURE__ */ s(
|
|
1060
1060
|
Me,
|
|
1061
1061
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,t){typeof exports=="object"&&typeof module<"u"?t(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"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.EnerexTemplateEditor={},u.jsxRuntime,u.React,u.reactQuery,u.axios,u.reactBootstrap,u.reactHookForm,u.Select$1))})(this,function(u,t,p,T,U,c,H,z){"use strict";const G=p.createContext(void 0),Q=({children:n,configs:s})=>{const[i,l]=p.useState(s.clientId),[r,e]=p.useState(s.apiKey),[o,a]=p.useState(s.enerexIdentifier),[f,g]=p.useState(s.projectId),y=v=>{e(v.apiKey),l(v.clientId),g(v.projectId),a(v.enerexIdentifier)};return t.jsx(G.Provider,{value:{clientId:i,apiKey:r,setConfiguration:y,enerexIdentifier:o,projectId:f},children:n})},C=()=>{const n=p.useContext(G);if(!n)throw new Error("widgetConfig must be used within a ConfigProvider");return n},O=`<!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
|
-
`,V=(n="",s)=>({get:async(r,e)=>{try{const o=await U.get(`${n}${r}`,e??s);if(o.status===200)return o.data}catch(o){throw o}},post:async(r,e,o)=>{try{const a=await U.post(`${n}${r}`,e,o??s);if(a.status===200)return a.data}catch(a){throw a}}}),
|
|
357
|
+
`,V=(n="",s)=>({get:async(r,e)=>{try{const o=await U.get(`${n}${r}`,e??s);if(o.status===200)return o.data}catch(o){throw o}},post:async(r,e,o)=>{try{const a=await U.post(`${n}${r}`,e,o??s);if(a.status===200)return a.data}catch(a){throw a}}}),j={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"},K=p.createContext({get:()=>{throw new Error("HttpClientContext.get not implemented")},post:()=>{throw new Error("HttpClientContext.post not implemented")}}),Z=({children:n})=>{const{clientId:s,apiKey:i}=C(),l={headers:{client_id:s,"x-api-key":i}},{get:r,post:e}=V(j.API_BASE_URL,l);return t.jsx(K.Provider,{value:{get:r,post:e},children:n})},R=({children:n})=>{const s=new T.QueryClient;return t.jsx(Z,{children:t.jsx(T.QueryClientProvider,{client:s,children:n})})},ee=n=>{const s=Array.from(new Set(n.map(l=>l.category))),i=[];return s.forEach(l=>{const r=n.filter(e=>e.category===l).map(e=>({label:e.label,value:e.value,hint:e.hint,hidden:e.hidden}));i.push({category:l,entries:r})}),i},S=()=>{const n=p.useContext(K);if(n)return n;throw new Error("useHttpClient must be used within a HttpClientProvider")},N={Template_list:"/Template/list/",Template:"/Template/GetTemplate/",MergeTags:"/Template/TemplateMergeTags/",ExcludeCategory:"/Template/GetExcludeCategories/",SaveTemplate:"/Template/save-update/",TemplateTypes:"/Template/TemplateTypes/"},te=()=>{const n=S(),{enerexIdentifier:s,projectId:i}=C();return T.useQuery({queryKey:["getTemplateTags"],queryFn:async r=>await n.get(`${N.MergeTags}${i}/${s}`)})},ne=()=>{const n=S(),{enerexIdentifier:s,projectId:i}=C();return T.useQuery({queryKey:["getExcludeCategory"],queryFn:async r=>await n.get(`${N.ExcludeCategory}${i}/${s}`)})},re=({templateHTML:n,className:s="",loading:i=!1})=>{const{post:l}=V(),{data:r}=te(),{data:e}=ne(),[o,a]=p.useState(n??{html:O,css:""}),{enerexIdentifier:f,projectId:g}=C(),y="https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png",v="https://plugins.stripo.email/api/v1/auth";p.useEffect(()=>{if(r&&e&&!document.getElementById("UiEditorScript")){const h=document.createElement("script");h.id="UiEditorScript",h.type="module",h.src=j.EDITOR_SCRIPT_URL,h.onload=x,document.body.appendChild(h)}},[r,e]);const x=async()=>{window.UIEditor.initEditor(document.querySelector("#stripoEditorContainer"),{html:o.html,css:o.css,modulesExcludedCategories:e??[],forceRecreate:!0,metadata:{emailId:`${g}_${f}`,userId:"1",username:"Plugin Demo User",avatarUrl:y},locale:"en",onTokenRefreshRequest:async function(h){const I={pluginId:j.EDITOR_PLUGIN_ID,secretKey:j.EDITOR_SECRET_KEY,userId:"12",role:"user"},d=await l(v,I);d&&h(d.token)},codeEditorButtonSelector:"#codeEditor",undoButtonSelector:"#undoButton",redoButtonSelector:"#redoButton",mobileViewButtonSelector:"#mobileViewButton",desktopViewButtonSelector:"#desktopViewButton",mergeTags:ee(r??[])})};return t.jsx("div",{className:"position-relative",children:t.jsxs("div",{className:`editor-container ${s}`,children:[i&&t.jsx("div",{className:"loading-overlay",children:t.jsx(c.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1"})}),t.jsx("div",{id:"externalSystemContainer"}),t.jsx("div",{id:"stripoEditorContainer"})]})})},se=({label:n,register:s,validation:i,required:l=!1,name:r,error:e,...o})=>t.jsxs(c.Form.Group,{className:"mb-1",children:[n?t.jsxs(c.Form.Label,{className:"mb-3 d-block form-label",children:[n,l&&t.jsx("label",{className:"text-danger",children:"*"})]}):null,t.jsx(c.Form.Control,{name:r,type:"text",...o,isInvalid:!!(e&&e[r]),...s?s(r,{...i}):{},className:`form-control ${e&&e[r]&&"border border-danger"}`}),e&&e[r]?t.jsx(c.Form.Control.Feedback,{type:"invalid",children:e[r].message}):null]});function oe({items:n,renderItem:s,className:i="",keyExtractor:l}){return t.jsx(c.ListGroup,{className:` ${i}`,children:n.map((r,e)=>t.jsx(c.ListGroup.Item,{children:s(r,e)},l?l(r,e):e))})}const ie=n=>t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",...n,children:t.jsx("path",{d:"M352 528L128 528C119.2 528 112 520.8 112 512L112 288C112 279.2 119.2 272 128 272L176 272L176 224L128 224C92.7 224 64 252.7 64 288L64 512C64 547.3 92.7 576 128 576L352 576C387.3 576 416 547.3 416 512L416 464L368 464L368 512C368 520.8 360.8 528 352 528zM288 368C279.2 368 272 360.8 272 352L272 128C272 119.2 279.2 112 288 112L512 112C520.8 112 528 119.2 528 128L528 352C528 360.8 520.8 368 512 368L288 368zM224 352C224 387.3 252.7 416 288 416L512 416C547.3 416 576 387.3 576 352L576 128C576 92.7 547.3 64 512 64L288 64C252.7 64 224 92.7 224 128L224 352z"})}),le=({children:n,title:s,placement:i})=>{const l=t.jsx(c.Popover,{id:"popover-basic",className:"dark-popover",children:t.jsx(c.Popover.Body,{className:"p-0 text-white",children:s})});return t.jsx(c.OverlayTrigger,{trigger:["hover","focus"],placement:i,overlay:l,containerPadding:0,container:document.body,popperConfig:{modifiers:[{name:"flip",enabled:!1},{name:"preventOverflow",enabled:!0,options:{boundary:"window"}}]},children:n})},ae=({selected:n,group:s,value:i,label:l,onCopy:r,onSelect:e,subItem:o=!1})=>t.jsxs("div",{className:"ps-1 py-1 d-flex position-relative",style:{alignItems:"center"},children:[t.jsx("input",{type:"radio",onChange:()=>{e(i)},className:"me-2",checked:n,name:s}),t.jsx("p",{title:l,className:"mb-0 wraped-text",children:l}),!o&&t.jsx(le,{title:"Copy",placement:"top",children:t.jsx("button",{className:"btn btn-link",type:"button",style:{padding:0,marginLeft:"auto",position:"relative",minWidth:32,flexShrink:0},children:t.jsx(ie,{onClick:()=>r(i),height:20,fill:"black"})})})]}),de=()=>{const n=S(),{enerexIdentifier:s,projectId:i}=C();return T.useQuery({queryKey:["getTemplatesList"],queryFn:async r=>await n.get(`${N.Template_list}${i}/${s}`)})},ce=(n,s=[])=>{const i=/^(?:\(copy(?:-(\d+))?\)\s)?(.+)$/,l=n.match(i);if(!l)return`(copy) ${n}`;const r=l[2],e=new RegExp(`^\\(copy(?:-(\\d+))?\\) ${r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`);let o=1;const a=s.filter(f=>e.test(f));return a.length===0?`(copy) ${r}`:(a.forEach(f=>{const g=f.match(e);if(g&&g[1]){const y=parseInt(g[1],10);!isNaN(y)&&y>=o&&(o=y+1)}else o=Math.max(o,2)}),`(copy-${o}) ${r}`)},pe=()=>{const n=S(),{enerexIdentifier:s,projectId:i}=C();return T.useMutation({mutationKey:["getTemplate"],mutationFn:async({id:r})=>{if(r)return await n.get(`${N.Template}${s}/${r}/${i}`)}})},me=()=>{const n=S(),{enerexIdentifier:s,projectId:i}=C();return T.useQuery({queryKey:["getTemplateTypes"],queryFn:async r=>await n.get(`${N.TemplateTypes}${s}/${i}`)})};function fe(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var M={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 W;function ue(){return W||(W=1,function(n){(function(){var s={}.hasOwnProperty;function i(){for(var e="",o=0;o<arguments.length;o++){var a=arguments[o];a&&(e=r(e,l(a)))}return e}function l(e){if(typeof e=="string"||typeof e=="number")return e;if(typeof e!="object")return"";if(Array.isArray(e))return i.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var o="";for(var a in e)s.call(e,a)&&e[a]&&(o=r(o,a));return o}function r(e,o){return o?e?e+" "+o:e+o:e}n.exports?(i.default=i,n.exports=i):window.classNames=i})()}(M)),M.exports}var ge=ue();const Y=fe(ge),ye=({name:n="",control:s,options:i,multiple:l=!1,placeholder:r,validation:e,labelKey:o="name",disabled:a,isInvalid:f,value:
|
|
361
|
+
*/var W;function ue(){return W||(W=1,function(n){(function(){var s={}.hasOwnProperty;function i(){for(var e="",o=0;o<arguments.length;o++){var a=arguments[o];a&&(e=r(e,l(a)))}return e}function l(e){if(typeof e=="string"||typeof e=="number")return e;if(typeof e!="object")return"";if(Array.isArray(e))return i.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var o="";for(var a in e)s.call(e,a)&&e[a]&&(o=r(o,a));return o}function r(e,o){return o?e?e+" "+o:e+o:e}n.exports?(i.default=i,n.exports=i):window.classNames=i})()}(M)),M.exports}var ge=ue();const Y=fe(ge),ye=({name:n="",control:s,options:i,multiple:l=!1,placeholder:r,validation:e,labelKey:o="name",disabled:a,isInvalid:f,value:g,onChange:y,uncontrolled:v,menuPlacement:x="auto",closeOnSelect:h=!0})=>{const I={control:d=>({...d,minHeight:"33px",borderColor:f?"var(--bs-form-invalid-border-color) !important":"var(--ct-input-border-color)",backgroundImage:f?'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:f?"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:d=>({...d,marginTop:0,width:"max-content",minWidth:"100%"}),menuPortal:d=>({...d,zIndex:9999}),multiValueRemove:d=>({...d,display:a?"none":"block"})};return v?t.jsx(z,{className:Y({"is-invalid":f}),styles:I,classNamePrefix:"react-select",isMulti:l,options:i,onChange:y,placeholder:r,menuPortalTarget:document.body,value:g,getOptionLabel:typeof o=="string"?d=>d[o]:o,getOptionValue:d=>d.id,isDisabled:a,menuPlacement:x,closeMenuOnSelect:h}):t.jsx(H.Controller,{control:s,name:n,rules:e,render:({field:{onChange:d,value:E,onBlur:A}})=>t.jsx(z,{className:Y({"is-invalid":f}),styles:I,classNamePrefix:"react-select",isMulti:l,options:i,onBlur:A,onChange:d,placeholder:r,menuPortalTarget:document.body,value:E,getOptionLabel:typeof o=="string"?L=>L[o]:o,getOptionValue:L=>L.id,isDisabled:a,menuPlacement:x,closeMenuOnSelect:h},E?JSON.stringify(E):"reset")})},he=({label:n,name:s,validation:i,control:l,error:r,...e})=>t.jsxs(c.Form.Group,{className:"mb-1",children:[n&&t.jsxs(c.Form.Label,{className:"mb-3 d-block form-label",children:[n," ",e.required&&t.jsx("span",{className:"text-danger",children:"*"})]}),t.jsx(ye,{control:l,options:e.options??[],validation:i,isInvalid:r&&!!r[s],name:s}),r&&r[s]?t.jsx(c.Form.Control.Feedback,{type:"invalid",children:r[s].message}):null]}),be=()=>{const n=S();T.useQueryClient();const{enerexIdentifier:s,projectId:i}=C();return T.useMutation({mutationKey:["saveTemplate"],mutationFn:async r=>(r.enerexIdentifier=s??"",r.projectId=i??"",await n.post(`${N.SaveTemplate}`,r))})},we=({onSelectItem:n,templateLoading:s,onReset:i})=>{const{register:l,handleSubmit:r,clearErrors:e,setValue:o,control:a,reset:f,formState:{errors:g}}=H.useForm({defaultValues:{templateName:"",templateType:void 0},mode:"onChange"}),{data:y,refetch:v,isLoading:x}=de(),[h,I]=p.useState([]),[d,E]=p.useState(),[A,L]=p.useState(),{mutateAsync:B,isPending:P}=pe(),{mutateAsync:Te,isPending:D}=be(),{data:k,isLoading:X}=me(),[F,Ce]=p.useState([]);p.useEffect(()=>{k&&Ce(k.map(m=>({id:`${m.id}`,name:m.name})))},[k]),p.useEffect(()=>{s(!!P)},[P]),p.useEffect(()=>{I(y??[])},[y]);const xe=async(m,b)=>{b&&I(w=>{const _=[...w],$={...b};$.id="",$.name=ce($.name,_.map(q=>q.name)),_.splice(m+1,0,$),E($),o("templateName",$.name);const J=F.find(q=>q.id===`${b.type}`);return J?o("templateType",J):o("templateType",void 0),e(),B({id:b?.id}).then(q=>{q&&L(q)}),_})},Ie=async m=>{if(E(m),m){if(o("templateName",m?.name),k&&k.find(w=>w.id===m.type)){const w=F.find(_=>_.id===`${m.type}`);w&&o("templateType",w)}else o("templateType",void 0);e()}const b=await B({id:m?.id});b&&L(b)};p.useEffect(()=>{n(A&&d?A:void 0)},[A,d,n]);const Ee=m=>{window.StripoEditorApi.actionsApi.getTemplateData(async b=>{const w={enerexIdentifier:"",projectId:"",templateId:d?.id??"",templateType:m.templateType.id,name:m.templateName,html:b.html,css:b.css};await Te(w)&&(e(),d?.id===""&&f(),v())})};return t.jsx(c.Card,{className:"border border-0 text-start",children:t.jsx(c.Card.Body,{className:"pe-0 ps-2",children:t.jsxs("form",{onSubmit:r(Ee),children:[t.jsx("label",{className:"mb-2",children:"Templates"}),t.jsx("div",{className:"template-list-container mb-3",children:t.jsx(oe,{items:h,renderItem:(m,b)=>t.jsx(ae,{selected:m===d,label:m.name,subItem:m.id==="",onCopy:w=>xe(b,w),onSelect:w=>Ie(w),value:m,group:"templates"})})}),t.jsx(he,{label:"Template Type",control:a,error:g,options:F,required:!0,validation:{required:{value:!0,message:"Template Type is required"}},...l("templateType")}),t.jsx(se,{label:"Template Name",register:l,error:g,required:!0,name:"templateName",validation:{required:{value:!0,message:"Template Name is required"}}}),t.jsx("hr",{}),t.jsxs("div",{className:"d-flex justify-content-between mt-3 ",children:[t.jsx(c.Button,{style:{width:"70px"},variant:"primary",disabled:x||P||D||X,onClick:()=>{E(void 0),f(),i()},children:P||D?t.jsx(c.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:t.jsx("span",{className:"visually-hidden",children:"Loading..."})}):"Clear"}),t.jsx(c.Button,{type:"submit",variant:"primary",style:{width:"80px"},disabled:x||P||D||X,children:P||D?t.jsx(c.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:t.jsx("span",{className:"visually-hidden",children:"Loading..."})}):(d?.id??"")===""?"Save":"Update"})]})]})})})},ve=({config:n})=>{const[s,i]=p.useState(),[l,r]=p.useState(!1),e=a=>{i(a),window.StripoEditorApi&&window.StripoEditorApi.actionsApi&&a&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(a?.html??"",a?.css??"","")},o=()=>{r(!1),i(void 0),window.StripoEditorApi&&window.StripoEditorApi.actionsApi&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(O,"","")};return t.jsx(Q,{configs:n,children:t.jsx(R,{children:t.jsx("div",{className:"root-widget",children:t.jsxs(c.Row,{children:[t.jsx(c.Col,{md:3,lg:2,className:"p-0",children:t.jsx(we,{templateLoading:r,onSelectItem:e,onReset:o})}),t.jsx(c.Col,{md:9,lg:10,children:t.jsx(re,{templateHTML:{css:s?.css??"",html:s?.html??O},loading:l,className:"col-span-5"})})]})})})})};u.EditorWidget=ve,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|