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