@enerex/template-studio 1.1.37 → 1.1.38

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 l, jsxs as $, Fragment as De } from "react/jsx-runtime";
2
- import O, { useContext as we, useState as S, useRef as qe, useEffect as v } from "react";
3
- import { QueryClient as $e, QueryClientProvider as Re, useQuery as J, useMutation as ve, useQueryClient as Be } from "@tanstack/react-query";
4
- import me from "axios";
5
- import { Spinner as Y, Form as H, Card as ue, Row as ke, Col as M, Button as se } from "react-bootstrap";
6
- import { Controller as Ue, useForm as Me } from "react-hook-form";
7
- import fe, { components as He } from "react-select";
8
- const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
1
+ import { jsx as r, jsxs as S, Fragment as we } from "react/jsx-runtime";
2
+ import k, { useContext as je, useState as v, useRef as We, useEffect as x } from "react";
3
+ import { QueryClient as Ye, QueryClientProvider as ze, useQuery as le, useMutation as Le, useQueryClient as Je } from "@tanstack/react-query";
4
+ import xe from "axios";
5
+ import { Spinner as J, Form as F, Card as Se, Row as Xe, Col as H, Button as re } from "react-bootstrap";
6
+ import { Controller as Ze, useForm as et } from "react-hook-form";
7
+ import Ce, { components as tt } from "react-select";
8
+ const ie = `<!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,45 +361,45 @@ const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
361
361
  </div>\r
362
362
  </body>\r
363
363
  </html>\r
364
- `, xe = O.createContext(
364
+ `, Pe = k.createContext(
365
365
  void 0
366
- ), Fe = ({
366
+ ), nt = ({
367
367
  children: t,
368
368
  configs: s
369
369
  }) => {
370
- const [o, i] = O.useState(s.clientId), [r, e] = O.useState(s.apiKey), [a, c] = O.useState(
370
+ const [o, l] = k.useState(s.clientId), [i, e] = k.useState(s.apiKey), [a, c] = k.useState(
371
371
  s.enerexIdentifier
372
- ), [T, y] = O.useState(s.projectId), [C, f] = O.useState(s.userEmail), [_, P] = O.useState(s.isAdmin), [x, g] = O.useState(s.meBaseUrl), [h, u] = O.useState(
372
+ ), [T, g] = k.useState(s.projectId), [N, f] = k.useState(s.userEmail), [I, j] = k.useState(s.isAdmin), [L, y] = k.useState(s.meBaseUrl), [h, b] = k.useState(
373
373
  s.defaultSelector
374
- ), m = (b) => {
375
- e(b.apiKey), i(b.clientId), y(b.projectId), c(b.enerexIdentifier), f(b.userEmail), P(b.isAdmin), u(b.defaultSelector), g(b.meBaseUrl);
374
+ ), p = (u) => {
375
+ e(u.apiKey), l(u.clientId), g(u.projectId), c(u.enerexIdentifier), f(u.userEmail), j(u.isAdmin), b(u.defaultSelector), y(u.meBaseUrl);
376
376
  };
377
- return /* @__PURE__ */ l(
378
- xe.Provider,
377
+ return /* @__PURE__ */ r(
378
+ Pe.Provider,
379
379
  {
380
380
  value: {
381
381
  clientId: o,
382
- apiKey: r,
383
- setConfiguration: m,
382
+ apiKey: i,
383
+ setConfiguration: p,
384
384
  enerexIdentifier: a,
385
385
  projectId: T,
386
- userEmail: C,
387
- isAdmin: _,
386
+ userEmail: N,
387
+ isAdmin: I,
388
388
  defaultSelector: h,
389
- meBaseUrl: x
389
+ meBaseUrl: L
390
390
  },
391
391
  children: t
392
392
  }
393
393
  );
394
394
  }, R = () => {
395
- const t = we(xe);
395
+ const t = je(Pe);
396
396
  if (!t)
397
397
  throw new Error("widgetConfig must be used within a ConfigProvider");
398
398
  return t;
399
- }, Se = (t = "", s) => ({ get: async (r, e) => {
399
+ }, Oe = (t = "", s) => ({ get: async (i, e) => {
400
400
  try {
401
- const a = await me.get(
402
- `${t}${r}`,
401
+ const a = await xe.get(
402
+ `${t}${i}`,
403
403
  e ?? s
404
404
  );
405
405
  if (a.status === 200)
@@ -407,10 +407,10 @@ const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
407
407
  } catch (a) {
408
408
  throw a;
409
409
  }
410
- }, post: async (r, e, a) => {
410
+ }, post: async (i, e, a) => {
411
411
  try {
412
- const c = await me.post(
413
- `${t}${r}`,
412
+ const c = await xe.post(
413
+ `${t}${i}`,
414
414
  e,
415
415
  a ?? s
416
416
  );
@@ -419,100 +419,100 @@ const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
419
419
  } catch (c) {
420
420
  throw c;
421
421
  }
422
- } }), Ce = O.createContext({
422
+ } }), De = k.createContext({
423
423
  get: () => {
424
424
  throw new Error("HttpClientContext.get not implemented");
425
425
  },
426
426
  post: () => {
427
427
  throw new Error("HttpClientContext.post not implemented");
428
428
  }
429
- }), Ge = ({ children: t }) => {
430
- const { clientId: s, apiKey: o, isAdmin: i, meBaseUrl: r } = R(), e = {
429
+ }), rt = ({ children: t }) => {
430
+ const { clientId: s, apiKey: o, isAdmin: l, meBaseUrl: i } = R(), e = {
431
431
  headers: {
432
432
  client_id: s,
433
433
  "x-api-key": o,
434
- "Security-Context": i ? "admin" : "viewer"
434
+ "Security-Context": l ? "admin" : "viewer"
435
435
  }
436
- }, { get: a, post: c } = Se(r, e);
437
- return /* @__PURE__ */ l(Ce.Provider, { value: { get: a, post: c }, children: t });
438
- }, Ve = ({ children: t }) => {
439
- const s = new $e();
440
- return /* @__PURE__ */ l(Ge, { children: /* @__PURE__ */ l(Re, { client: s, children: t }) });
441
- }, ie = {
436
+ }, { get: a, post: c } = Oe(i, e);
437
+ return /* @__PURE__ */ r(De.Provider, { value: { get: a, post: c }, children: t });
438
+ }, st = ({ children: t }) => {
439
+ const s = new Ye();
440
+ return /* @__PURE__ */ r(rt, { children: /* @__PURE__ */ r(ze, { client: s, children: t }) });
441
+ }, ue = {
442
442
  EDITOR_SCRIPT_URL: "https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",
443
443
  EDITOR_PLUGIN_ID: "1afdc3161ec7409a8627a1c8561d45f5",
444
444
  EDITOR_SECRET_KEY: "54ba748ed7e94f2e929555783acb03da"
445
- }, Ke = (t) => {
446
- const s = Array.from(new Set(t.map((i) => i.category))), o = [];
447
- return s.forEach((i) => {
448
- const r = t.filter((e) => e.category === i).map((e) => ({
445
+ }, it = (t) => {
446
+ const s = Array.from(new Set(t.map((l) => l.category))), o = [];
447
+ return s.forEach((l) => {
448
+ const i = t.filter((e) => e.category === l).map((e) => ({
449
449
  label: e.label,
450
450
  value: e.value,
451
451
  hint: e.hint,
452
452
  hidden: e.hidden
453
453
  }));
454
- o.push({ category: i, entries: r });
454
+ o.push({ category: l, entries: i });
455
455
  }), o;
456
- }, G = () => {
457
- const t = we(Ce);
456
+ }, K = () => {
457
+ const t = je(De);
458
458
  if (t)
459
459
  return t;
460
460
  throw new Error("useHttpClient must be used within a HttpClientProvider");
461
- }, V = {
461
+ }, Q = {
462
462
  Template_list: "/Template/list/",
463
463
  Template: "/Template/GetTemplate/",
464
464
  MergeTags: "/Template/TemplateMergeTags/",
465
465
  ExcludeCategory: "/Template/GetExcludeCategories/",
466
466
  SaveTemplate: "/Template/save-update/",
467
467
  TemplateTypes: "/Template/TemplateTypes/"
468
- }, Qe = () => {
469
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
470
- return J({
468
+ }, lt = () => {
469
+ const t = K(), { enerexIdentifier: s, projectId: o } = R();
470
+ return le({
471
471
  queryKey: ["getTemplateTags"],
472
- queryFn: async (r) => await t.get(
473
- `${V.MergeTags}${o}/${s}`
472
+ queryFn: async (i) => await t.get(
473
+ `${Q.MergeTags}${o}/${s}`
474
474
  )
475
475
  });
476
- }, We = () => {
477
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
478
- return J({
476
+ }, at = () => {
477
+ const t = K(), { enerexIdentifier: s, projectId: o } = R();
478
+ return le({
479
479
  queryKey: ["getExcludeCategory"],
480
- queryFn: async (r) => await t.get(
481
- `${V.ExcludeCategory}${o}/${s}`
480
+ queryFn: async (i) => await t.get(
481
+ `${Q.ExcludeCategory}${o}/${s}`
482
482
  )
483
483
  });
484
- }, Ye = ({
484
+ }, ot = ({
485
485
  templateHTML: t,
486
486
  className: s = "",
487
487
  loading: o = !1,
488
- onEditorInitialized: i
488
+ onEditorInitialized: l
489
489
  }) => {
490
- const { post: r } = Se(), { data: e } = Qe(), { data: a } = We(), [c, T] = S(
491
- t ?? { html: z, css: "" }
492
- ), { userEmail: y } = R(), C = qe(null), f = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", _ = "https://plugins.stripo.email/api/v1/auth";
493
- v(() => {
494
- (async () => (await P(), e && a && await x(ie.EDITOR_SCRIPT_URL)))();
490
+ const { post: i } = Oe(), { data: e } = lt(), { data: a } = at(), [c, T] = v(
491
+ t ?? { html: ie, css: "" }
492
+ ), { userEmail: g } = R(), N = We(null), f = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", I = "https://plugins.stripo.email/api/v1/auth";
493
+ x(() => {
494
+ (async () => (await j(), e && a && await L(ue.EDITOR_SCRIPT_URL)))();
495
495
  }, [e, a]);
496
- async function P() {
497
- window.Zone || await new Promise((h, u) => {
498
- const m = document.createElement("script");
499
- m.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
500
- const b = document.querySelector("script[nonce]")?.nonce;
501
- b && m.setAttribute("nonce", b), m.onload = () => h(), m.onerror = () => u(new Error("Failed to load zone.js")), document.head.appendChild(m);
496
+ async function j() {
497
+ window.Zone || await new Promise((h, b) => {
498
+ const p = document.createElement("script");
499
+ p.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
500
+ const u = document.querySelector("script[nonce]")?.nonce;
501
+ u && p.setAttribute("nonce", u), p.onload = () => h(), p.onerror = () => b(new Error("Failed to load zone.js")), document.head.appendChild(p);
502
502
  });
503
503
  }
504
- async function x(h) {
505
- let u = document.getElementById(
504
+ async function L(h) {
505
+ let b = document.getElementById(
506
506
  "UiEditorScript"
507
507
  );
508
- u || (u = document.createElement("script"), u.id = "UiEditorScript", u.src = h, u.onload = async () => {
509
- await g();
510
- }, document.body.appendChild(u)), await new Promise(
511
- (m) => u.addEventListener("load", () => m(), { once: !0 })
508
+ b || (b = document.createElement("script"), b.id = "UiEditorScript", b.src = h, b.onload = async () => {
509
+ await y();
510
+ }, document.body.appendChild(b)), await new Promise(
511
+ (p) => b.addEventListener("load", () => p(), { once: !0 })
512
512
  );
513
513
  }
514
- const g = async () => {
515
- const h = C.current;
514
+ const y = async () => {
515
+ const h = N.current;
516
516
  if (!h) {
517
517
  console.error("Missing #stripoEditorContainer in DOM");
518
518
  return;
@@ -521,159 +521,230 @@ const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
521
521
  console.error("UIEditor script not loaded or not exposing initEditor");
522
522
  return;
523
523
  }
524
- const u = {
524
+ const b = {
525
525
  html: c.html,
526
526
  css: c.css,
527
527
  modulesExcludedCategories: a ?? [],
528
528
  forceRecreate: !0,
529
529
  metadata: {
530
- emailId: y,
530
+ emailId: g,
531
531
  userId: "1",
532
532
  // username: userName,
533
533
  avatarUrl: f
534
534
  },
535
535
  locale: "en",
536
- onTokenRefreshRequest: async (m) => {
537
- const b = {
538
- pluginId: ie.EDITOR_PLUGIN_ID,
539
- secretKey: ie.EDITOR_SECRET_KEY,
540
- userId: y,
536
+ onTokenRefreshRequest: async (p) => {
537
+ const u = {
538
+ pluginId: ue.EDITOR_PLUGIN_ID,
539
+ secretKey: ue.EDITOR_SECRET_KEY,
540
+ userId: g,
541
541
  role: "user"
542
- }, B = await r(
543
- _,
544
- b
542
+ }, B = await i(
543
+ I,
544
+ u
545
545
  );
546
- B?.token && m(B.token);
546
+ B?.token && p(B.token);
547
547
  },
548
548
  onTemplateLoaded: () => {
549
- i && i(!0);
549
+ l && l(!0);
550
550
  },
551
- mergeTags: Ke(e ?? [])
551
+ mergeTags: it(e ?? [])
552
552
  };
553
- for (const [m, b] of Object.entries({
553
+ for (const [p, u] of Object.entries({
554
554
  codeEditorButtonSelector: "#codeEditor",
555
555
  undoButtonSelector: "#undoButton",
556
556
  redoButtonSelector: "#redoButton",
557
557
  mobileViewButtonSelector: "#mobileViewButton",
558
558
  desktopViewButtonSelector: "#desktopViewButton"
559
559
  }))
560
- h.ownerDocument && h.getRootNode() instanceof ShadowRoot && h.getRootNode().querySelector(b) && (u[m] = b);
561
- await window.UIEditor.initEditor(h, u);
560
+ h.ownerDocument && h.getRootNode() instanceof ShadowRoot && h.getRootNode().querySelector(u) && (b[p] = u);
561
+ await window.UIEditor.initEditor(h, b);
562
562
  };
563
- return /* @__PURE__ */ l("div", { className: "position-relative", children: /* @__PURE__ */ $("div", { className: `editor-container ${s}`, children: [
564
- o && /* @__PURE__ */ l("div", { className: "loading-overlay", children: /* @__PURE__ */ l(
565
- Y,
563
+ return /* @__PURE__ */ r("div", { className: "position-relative", children: /* @__PURE__ */ S("div", { className: `editor-container ${s}`, children: [
564
+ o && /* @__PURE__ */ r("div", { className: "loading-overlay", children: /* @__PURE__ */ r(
565
+ J,
566
566
  {
567
567
  animation: "border",
568
568
  style: { width: "11px", height: "11px" },
569
569
  size: "sm",
570
570
  role: "status",
571
571
  className: "me-1",
572
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
572
+ children: /* @__PURE__ */ r("span", { className: "visually-hidden", children: "Loading..." })
573
573
  }
574
574
  ) }),
575
- /* @__PURE__ */ l("div", { id: "externalSystemContainer" }),
576
- /* @__PURE__ */ l("div", { id: "stripoEditorContainer", ref: C })
575
+ /* @__PURE__ */ r("div", { id: "externalSystemContainer" }),
576
+ /* @__PURE__ */ r("div", { id: "stripoEditorContainer", ref: N })
577
577
  ] }) });
578
- }, ye = ({
578
+ }, Ee = ({
579
579
  label: t,
580
580
  register: s,
581
581
  validation: o,
582
- required: i = !1,
583
- name: r,
582
+ required: l = !1,
583
+ name: i,
584
584
  error: e,
585
585
  className: a = "",
586
586
  ...c
587
- }) => /* @__PURE__ */ $(H.Group, { className: a + " mb-1", children: [
588
- t ? /* @__PURE__ */ $(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
587
+ }) => /* @__PURE__ */ S(F.Group, { className: a + " mb-1", children: [
588
+ t ? /* @__PURE__ */ S(F.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
589
589
  t,
590
- i && /* @__PURE__ */ l("label", { className: "text-danger", children: "*" })
590
+ l && /* @__PURE__ */ r("label", { className: "text-danger", children: "*" })
591
591
  ] }) : null,
592
- /* @__PURE__ */ l(
593
- H.Control,
592
+ /* @__PURE__ */ r(
593
+ F.Control,
594
594
  {
595
- name: r,
595
+ name: i,
596
596
  type: "text",
597
597
  ...c,
598
- isInvalid: !!(e && e[r]),
599
- ...s ? s(r, {
598
+ isInvalid: !!(e && e[i]),
599
+ ...s ? s(i, {
600
600
  ...o
601
601
  }) : {},
602
- className: `react-select__control ${e && e[r] && "border border-danger"}`
602
+ className: `react-select__control ${e && e[i] && "border border-danger"}`
603
603
  }
604
604
  ),
605
- e && e[r] ? /* @__PURE__ */ l(H.Control.Feedback, { type: "invalid", children: e[r].message }) : null
606
- ] }), ze = () => {
607
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
608
- return J({
605
+ e && e[i] ? /* @__PURE__ */ r(F.Control.Feedback, { type: "invalid", children: e[i].message }) : null
606
+ ] }), dt = ({
607
+ show: t,
608
+ variant: s,
609
+ title: o = "Are you sure?",
610
+ message: l,
611
+ label: i = "Name",
612
+ value: e = "",
613
+ placeholder: a = "",
614
+ requiredMessage: c = "This field is required",
615
+ externalError: T = !1,
616
+ externalErrorMessage: g = "",
617
+ confirmText: N = "Ok",
618
+ cancelText: f = "Cancel",
619
+ confirmButtonVariant: I = "danger",
620
+ onConfirm: j,
621
+ onCancel: L,
622
+ onInputChange: y
623
+ }) => {
624
+ const [h, b] = v(e), [p, u] = v(!1);
625
+ if (x(() => {
626
+ t && (b(e), u(!1));
627
+ }, [t, e]), x(() => {
628
+ T && u(!0);
629
+ }, [T]), !t) return null;
630
+ const B = s === "input" && !h.trim(), M = s === "input" && (B || T), ae = B ? c : T ? g : "", q = () => {
631
+ if (M) {
632
+ u(!0);
633
+ return;
634
+ }
635
+ j(h.trim());
636
+ };
637
+ return /* @__PURE__ */ r("div", { className: "template-studio-modal-overlay", children: /* @__PURE__ */ S("div", { className: "template-studio-modal", children: [
638
+ /* @__PURE__ */ S("div", { className: "template-studio-modal-header", children: [
639
+ /* @__PURE__ */ r("h4", { children: o }),
640
+ /* @__PURE__ */ r("button", { className: "template-studio-modal-close", onClick: L, children: "✕" })
641
+ ] }),
642
+ /* @__PURE__ */ S("div", { className: "template-studio-modal-body", children: [
643
+ l && /* @__PURE__ */ r("p", { children: l }),
644
+ s === "input" && /* @__PURE__ */ S("div", { className: "mb-3", children: [
645
+ /* @__PURE__ */ S("label", { className: "form-label", children: [
646
+ i,
647
+ /* @__PURE__ */ r("span", { className: "text-danger", children: "*" })
648
+ ] }),
649
+ /* @__PURE__ */ r(
650
+ "input",
651
+ {
652
+ type: "text",
653
+ className: `form-control ${p && M ? "is-invalid" : ""}`,
654
+ placeholder: a,
655
+ value: h,
656
+ onChange: (V) => {
657
+ b(V.target.value), p && u(!1), y?.(V.target.value);
658
+ },
659
+ autoFocus: !0
660
+ }
661
+ ),
662
+ p && M && /* @__PURE__ */ r("div", { className: "invalid-feedback d-block", children: ae })
663
+ ] })
664
+ ] }),
665
+ /* @__PURE__ */ S("div", { className: "template-studio-modal-footer", children: [
666
+ /* @__PURE__ */ r("button", { className: "btn btn-secondary", onClick: L, children: f }),
667
+ /* @__PURE__ */ r(
668
+ "button",
669
+ {
670
+ className: `btn btn-${I}`,
671
+ onClick: q,
672
+ children: N
673
+ }
674
+ )
675
+ ] })
676
+ ] }) });
677
+ }, ct = () => {
678
+ const t = K(), { enerexIdentifier: s, projectId: o } = R();
679
+ return le({
609
680
  queryKey: ["getTemplatesList"],
610
- queryFn: async (r) => await t.get(
611
- `${V.Template_list}${o}/${s}`
681
+ queryFn: async (i) => await t.get(
682
+ `${Q.Template_list}${o}/${s}`
612
683
  )
613
684
  });
614
685
  };
615
- function le(t) {
686
+ function fe(t) {
616
687
  return t.sort((s, o) => s.name.localeCompare(o.name));
617
688
  }
618
- function Je(t) {
689
+ function pt(t) {
619
690
  const s = /* @__PURE__ */ new Map(), o = [];
620
691
  t.forEach((e) => s.set(e.id, e));
621
- let i = t.filter((e) => e.parent_id === 0), r = 0;
622
- for (; i.length > 0; ) {
623
- o.push({ level: r, data: i });
624
- const e = i.map((c) => c.id);
625
- i = t.filter(
692
+ let l = t.filter((e) => e.parent_id === 0), i = 0;
693
+ for (; l.length > 0; ) {
694
+ o.push({ level: i, data: l });
695
+ const e = l.map((c) => c.id);
696
+ l = t.filter(
626
697
  (c) => e.includes(c.parent_id)
627
- ), r++;
698
+ ), i++;
628
699
  }
629
700
  return o;
630
701
  }
631
- function ae(t, s) {
632
- const i = Je(t).find((r) => r.level === s);
633
- return i ? i.data : [];
702
+ function ye(t, s) {
703
+ const l = pt(t).find((i) => i.level === s);
704
+ return l ? l.data : [];
634
705
  }
635
- const Xe = () => {
636
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
637
- return ve({
706
+ const mt = () => {
707
+ const t = K(), { enerexIdentifier: s, projectId: o } = R();
708
+ return Le({
638
709
  mutationKey: ["getTemplate"],
639
- mutationFn: async ({ id: r }) => {
640
- if (r)
710
+ mutationFn: async ({ id: i }) => {
711
+ if (i)
641
712
  return await t.get(
642
- `${V.Template}${s}/${r}/${o}`
713
+ `${Q.Template}${s}/${i}/${o}`
643
714
  );
644
715
  }
645
716
  });
646
- }, Ze = () => {
647
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
648
- return J({
717
+ }, ut = () => {
718
+ const t = K(), { enerexIdentifier: s, projectId: o } = R();
719
+ return le({
649
720
  queryKey: ["getTemplateTypes"],
650
- queryFn: async (r) => await t.get(
651
- `${V.TemplateTypes}${s}/${o}`
721
+ queryFn: async (i) => await t.get(
722
+ `${Q.TemplateTypes}${s}/${o}`
652
723
  )
653
724
  });
654
725
  };
655
- function et(t) {
726
+ function ft(t) {
656
727
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
657
728
  }
658
- var oe = { exports: {} };
729
+ var ge = { exports: {} };
659
730
  /*!
660
731
  Copyright (c) 2018 Jed Watson.
661
732
  Licensed under the MIT License (MIT), see
662
733
  http://jedwatson.github.io/classnames
663
734
  */
664
- var ge;
665
- function tt() {
666
- return ge || (ge = 1, function(t) {
735
+ var Ne;
736
+ function yt() {
737
+ return Ne || (Ne = 1, function(t) {
667
738
  (function() {
668
739
  var s = {}.hasOwnProperty;
669
740
  function o() {
670
741
  for (var e = "", a = 0; a < arguments.length; a++) {
671
742
  var c = arguments[a];
672
- c && (e = r(e, i(c)));
743
+ c && (e = i(e, l(c)));
673
744
  }
674
745
  return e;
675
746
  }
676
- function i(e) {
747
+ function l(e) {
677
748
  if (typeof e == "string" || typeof e == "number")
678
749
  return e;
679
750
  if (typeof e != "object")
@@ -684,18 +755,18 @@ function tt() {
684
755
  return e.toString();
685
756
  var a = "";
686
757
  for (var c in e)
687
- s.call(e, c) && e[c] && (a = r(a, c));
758
+ s.call(e, c) && e[c] && (a = i(a, c));
688
759
  return a;
689
760
  }
690
- function r(e, a) {
761
+ function i(e, a) {
691
762
  return a ? e ? e + " " + a : e + a : e;
692
763
  }
693
764
  t.exports ? (o.default = o, t.exports = o) : window.classNames = o;
694
765
  })();
695
- }(oe)), oe.exports;
766
+ }(ge)), ge.exports;
696
767
  }
697
- var nt = tt();
698
- const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__ */ l("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ l(
768
+ var gt = yt();
769
+ const Ie = /* @__PURE__ */ ft(gt), _e = (t) => t.data.isSeparator ? /* @__PURE__ */ r("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ r(
699
770
  "hr",
700
771
  {
701
772
  style: {
@@ -705,25 +776,25 @@ const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__
705
776
  margin: 0
706
777
  }
707
778
  }
708
- ) }) : /* @__PURE__ */ l(He.Option, { ...t }), rt = ({
779
+ ) }) : /* @__PURE__ */ r(tt.Option, { ...t }), ht = ({
709
780
  name: t = "",
710
781
  control: s,
711
782
  options: o,
712
- multiple: i = !1,
713
- placeholder: r,
783
+ multiple: l = !1,
784
+ placeholder: i,
714
785
  validation: e,
715
786
  labelKey: a = "name",
716
787
  disabled: c,
717
788
  isInvalid: T,
718
- value: y,
719
- onChange: C,
789
+ value: g,
790
+ onChange: N,
720
791
  uncontrolled: f,
721
- menuPlacement: _ = "auto",
722
- closeOnSelect: P = !0
792
+ menuPlacement: I = "auto",
793
+ closeOnSelect: j = !0
723
794
  }) => {
724
- const x = {
725
- control: (g) => ({
726
- ...g,
795
+ const L = {
796
+ control: (y) => ({
797
+ ...y,
727
798
  minHeight: "33px",
728
799
  // state.isFocused can display different borderColor if you need it
729
800
  borderColor: T ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
@@ -744,505 +815,586 @@ const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__
744
815
  display: "none"
745
816
  }
746
817
  }),
747
- menu: (g) => ({
748
- ...g,
818
+ menu: (y) => ({
819
+ ...y,
749
820
  marginTop: 0,
750
821
  width: "max-content",
751
822
  minWidth: "100%"
752
823
  }),
753
- menuPortal: (g) => ({
754
- ...g,
824
+ menuPortal: (y) => ({
825
+ ...y,
755
826
  zIndex: 9999
756
827
  }),
757
- multiValueRemove: (g) => ({
758
- ...g,
828
+ multiValueRemove: (y) => ({
829
+ ...y,
759
830
  display: c ? "none" : "block"
760
831
  })
761
832
  };
762
- return f ? /* @__PURE__ */ l(
763
- fe,
833
+ return f ? /* @__PURE__ */ r(
834
+ Ce,
764
835
  {
765
- components: { Option: be },
766
- isOptionDisabled: (g) => !!g.isSeparator,
767
- className: he({
836
+ components: { Option: _e },
837
+ isOptionDisabled: (y) => !!y.isSeparator,
838
+ className: Ie({
768
839
  "is-invalid": T
769
840
  }),
770
- styles: x,
841
+ styles: L,
771
842
  classNamePrefix: "react-select",
772
- isMulti: i,
843
+ isMulti: l,
773
844
  options: o,
774
- onChange: C,
775
- placeholder: r,
845
+ onChange: N,
846
+ placeholder: i,
776
847
  menuPortalTarget: document.body,
777
- value: y,
778
- getOptionLabel: typeof a == "string" ? (g) => g[a] : a,
779
- getOptionValue: (g) => g.id,
848
+ value: g,
849
+ getOptionLabel: typeof a == "string" ? (y) => y[a] : a,
850
+ getOptionValue: (y) => y.id,
780
851
  isDisabled: c,
781
- menuPlacement: _,
782
- closeMenuOnSelect: P
852
+ menuPlacement: I,
853
+ closeMenuOnSelect: j
783
854
  }
784
- ) : /* @__PURE__ */ l(
785
- Ue,
855
+ ) : /* @__PURE__ */ r(
856
+ Ze,
786
857
  {
787
858
  control: s,
788
859
  name: t,
789
860
  rules: e,
790
- render: ({ field: { onChange: g, value: h, onBlur: u } }) => /* @__PURE__ */ l(
791
- fe,
861
+ render: ({ field: { onChange: y, value: h, onBlur: b } }) => /* @__PURE__ */ r(
862
+ Ce,
792
863
  {
793
- components: { Option: be },
794
- isOptionDisabled: (m) => !!m.isSeparator,
795
- className: he({
864
+ components: { Option: _e },
865
+ isOptionDisabled: (p) => !!p.isSeparator,
866
+ className: Ie({
796
867
  "is-invalid": T
797
868
  }),
798
- styles: x,
869
+ styles: L,
799
870
  classNamePrefix: "react-select",
800
- isMulti: i,
871
+ isMulti: l,
801
872
  options: o,
802
- onBlur: u,
803
- onChange: g,
804
- placeholder: r,
873
+ onBlur: b,
874
+ onChange: y,
875
+ placeholder: i,
805
876
  menuPortalTarget: document.body,
806
877
  value: h,
807
- getOptionLabel: typeof a == "string" ? (m) => m[a] : a,
808
- getOptionValue: (m) => m.id,
878
+ getOptionLabel: typeof a == "string" ? (p) => p[a] : a,
879
+ getOptionValue: (p) => p.id,
809
880
  isDisabled: c,
810
- menuPlacement: _,
811
- closeMenuOnSelect: P
881
+ menuPlacement: I,
882
+ closeMenuOnSelect: j
812
883
  },
813
884
  h ? JSON.stringify(h) : "reset"
814
885
  )
815
886
  }
816
887
  );
817
- }, W = ({
888
+ }, se = ({
818
889
  label: t,
819
890
  name: s,
820
891
  validation: o,
821
- control: i,
822
- error: r,
892
+ control: l,
893
+ error: i,
823
894
  ...e
824
- }) => /* @__PURE__ */ $(H.Group, { className: "mb-1", children: [
825
- t && /* @__PURE__ */ $(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
895
+ }) => /* @__PURE__ */ S(F.Group, { className: "mb-1", children: [
896
+ t && /* @__PURE__ */ S(F.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
826
897
  t,
827
898
  " ",
828
- e.required && /* @__PURE__ */ l("span", { className: "text-danger", children: "*" })
899
+ e.required && /* @__PURE__ */ r("span", { className: "text-danger", children: "*" })
829
900
  ] }),
830
- /* @__PURE__ */ l(
831
- rt,
901
+ /* @__PURE__ */ r(
902
+ ht,
832
903
  {
833
- control: i,
904
+ control: l,
834
905
  disabled: e.disabled,
835
906
  options: e.options ?? [],
836
907
  validation: o,
837
- isInvalid: r && !!r[s],
908
+ isInvalid: i && !!i[s],
838
909
  name: s
839
910
  }
840
911
  ),
841
- r && r[s] ? /* @__PURE__ */ l(H.Control.Feedback, { type: "invalid", children: r[s].message }) : null
842
- ] }), st = () => {
843
- const t = G();
844
- Be();
912
+ i && i[s] ? /* @__PURE__ */ r(F.Control.Feedback, { type: "invalid", children: i[s].message }) : null
913
+ ] }), bt = () => {
914
+ const t = K();
915
+ Je();
845
916
  const { enerexIdentifier: s, projectId: o } = R();
846
- return ve({
917
+ return Le({
847
918
  mutationKey: ["saveTemplate"],
848
- mutationFn: async (r) => (r.enerexIdentifier = s ?? "", r.projectId = o ?? "", await t.post(
849
- `${V.SaveTemplate}`,
850
- r
919
+ mutationFn: async (i) => (i.enerexIdentifier = s ?? "", i.projectId = o ?? "", await t.post(
920
+ `${Q.SaveTemplate}`,
921
+ i
851
922
  ))
852
923
  });
853
- }, K = {
924
+ }, z = {
854
925
  id: "",
855
926
  name: "New (Blank)"
856
- }, Te = {
927
+ }, Ae = {
857
928
  id: "",
858
929
  name: "Separator",
859
930
  isSeparator: !0
860
- }, it = ({
931
+ }, Tt = ({
861
932
  onSelectItem: t,
862
933
  templateLoading: s,
863
934
  onReset: o,
864
- editorInitialized: i
935
+ editorInitialized: l
865
936
  }) => {
866
- const { isAdmin: r, defaultSelector: e } = R(), {
937
+ const { isAdmin: i, defaultSelector: e } = R(), {
867
938
  register: a,
868
939
  handleSubmit: c,
869
940
  clearErrors: T,
870
- setValue: y,
871
- control: C,
941
+ setValue: g,
942
+ control: N,
872
943
  watch: f,
873
- reset: _,
874
- setError: P,
875
- formState: { errors: x }
876
- } = Me({
944
+ reset: I,
945
+ setError: j,
946
+ getValues: L,
947
+ formState: { errors: y }
948
+ } = et({
877
949
  defaultValues: {
878
950
  templateName: "",
879
951
  subTemplateType: void 0,
880
952
  subTemplateType2: void 0,
881
953
  subject: "",
882
954
  templateType: void 0,
883
- template: K
955
+ template: z
884
956
  },
885
957
  mode: "onChange"
886
958
  }), {
887
- data: g,
888
- refetch: h,
889
- isLoading: u
890
- } = ze(), [m, b] = S([]), [B, Ee] = S(!1), [k, X] = S(), [Q, F] = S(), { mutateAsync: Z, isPending: E } = Xe(), { mutateAsync: de, isPending: I } = st(), { data: U, isLoading: D } = Ze(), [ee, Ie] = S([]), [L, te] = S([]), [j, ne] = S([]);
891
- v(() => {
959
+ data: h,
960
+ refetch: b,
961
+ isLoading: p
962
+ } = ct(), [u, B] = v([]), [M, ae] = v(!1), [q, V] = v(), [X, Z] = v(), { mutateAsync: oe, isPending: _ } = mt(), { mutateAsync: de, isPending: A } = bt(), { data: U, isLoading: $ } = ut(), [ce, qe] = v([]), [P, ee] = v([]), [O, te] = v([]), [$e, pe] = v(!1), [G, ke] = v("confirm"), [Re, me] = v(!1), [he, be] = v(!1);
963
+ x(() => {
892
964
  if (U) {
893
- let n = U.filter((p) => p.id != null), d = ae(n, 0);
894
- Ie(le(d));
965
+ let n = U.filter((m) => m.id != null), d = ye(n, 0);
966
+ qe(fe(d));
895
967
  }
896
968
  }, [U]);
897
- const Ne = (n, d) => {
898
- let p = [];
899
- return n.forEach((N, w) => {
900
- d.includes(w) && w !== 0 && p.push(Te), p.push(N);
901
- }), p;
969
+ const Be = (n, d) => {
970
+ let m = [];
971
+ return n.forEach((C, E) => {
972
+ d.includes(E) && E !== 0 && m.push(Ae), m.push(C);
973
+ }), m;
902
974
  };
903
- v(() => {
904
- s(!!(u || E || I || D || !i));
905
- }, [u, E, I, D, i]), v(() => {
906
- g?.sort((n, d) => n.readonly !== d.readonly ? (n.readonly ? 0 : 1) - (d.readonly ? 0 : 1) : n.name.localeCompare(d.name)), b(g ?? []);
907
- }, [g]);
908
- const _e = async (n) => {
909
- X(n), n && (r || !n.readonly) ? (y("templateName", n?.name), T()) : (y("templateName", ""), y("subject", ""));
910
- const d = await Z({ id: n?.id });
911
- F(d || void 0);
975
+ x(() => {
976
+ s(!!(p || _ || A || $ || !l));
977
+ }, [p, _, A, $, l]), x(() => {
978
+ h?.sort((n, d) => n.readonly !== d.readonly ? (n.readonly ? 0 : 1) - (d.readonly ? 0 : 1) : n.name.localeCompare(d.name)), B(h ?? []);
979
+ }, [h]);
980
+ const Me = async (n) => {
981
+ V(n), n && (i || !n.readonly) ? (g("templateName", n?.name), T()) : (g("templateName", ""), g("subject", ""));
982
+ const d = await oe({ id: n?.id });
983
+ d ? Z(d) : ne();
912
984
  };
913
- v(() => {
914
- if ((e === void 0 || e.templateId === void 0 || B) && y("template", K), f("templateType")) {
915
- let n = U?.filter((p) => p.id !== void 0) ?? [], d = ae(n, 1);
916
- te(
917
- le(
985
+ x(() => {
986
+ if ((e === void 0 || e.templateId === void 0 || M) && g("template", z), f("templateType")) {
987
+ let n = U?.filter((m) => m.id !== void 0) ?? [], d = ye(n, 1);
988
+ ee(
989
+ fe(
918
990
  d.filter(
919
- (p) => p.parent_id.toString() === `${f("templateType")?.id}`
991
+ (m) => m.parent_id.toString() === `${f("templateType")?.id}`
920
992
  )
921
993
  )
922
- ), y("subTemplateType", void 0), y("subTemplateType2", void 0);
994
+ ), g("subTemplateType", void 0), g("subTemplateType2", void 0);
923
995
  }
924
- }, [f("templateType")]), v(() => {
925
- if ((e === void 0 || e.templateId === void 0) && y("template", K), f("subTemplateType")) {
926
- let n = U?.filter((p) => p.id !== void 0) ?? [], d = ae(n, 2);
927
- ne(
928
- le(
996
+ }, [f("templateType")]), x(() => {
997
+ if ((e === void 0 || e.templateId === void 0) && g("template", z), f("subTemplateType")) {
998
+ let n = U?.filter((m) => m.id !== void 0) ?? [], d = ye(n, 2);
999
+ te(
1000
+ fe(
929
1001
  d.filter(
930
- (p) => p.parent_id.toString() === `${f("subTemplateType")?.id}`
1002
+ (m) => m.parent_id.toString() === `${f("subTemplateType")?.id}`
931
1003
  )
932
1004
  )
933
- ), y("subTemplateType2", void 0);
1005
+ ), g("subTemplateType2", void 0);
934
1006
  }
935
- }, [f("subTemplateType")]), v(() => {
936
- const n = pe();
937
- n.length > 0 && n[0].id !== "" ? (e === void 0 || e.templateId === void 0 || B) && y("template", n[0]) : (e === void 0 || e.templateId === void 0 || B) && y("template", K);
938
- }, [f("subTemplateType2")]), v(() => {
939
- let n = m.find((d) => d.id === f("template")?.id);
940
- _e(n);
1007
+ }, [f("subTemplateType")]), x(() => {
1008
+ const n = ve();
1009
+ n.length > 0 && n[0].id !== "" ? (e === void 0 || e.templateId === void 0 || M) && g("template", n[0]) : (e === void 0 || e.templateId === void 0 || M) && g("template", z);
1010
+ }, [f("subTemplateType2")]), x(() => {
1011
+ let n = u.find((d) => d.id === f("template")?.id);
1012
+ Me(n);
941
1013
  }, [f("template")]);
942
- const [Ae, ce] = S(!1);
943
- v(() => {
944
- Ae || (Q && k && i ? (ce(!0), t(Q), y("subject", Q.subject ?? ""), setTimeout(() => {
945
- ce(!1);
946
- }, 1e3)) : t(void 0));
947
- }, [Q, k, t, i]);
948
- const pe = () => {
949
- let n = [K], d = "templateType";
950
- j.length > 0 ? d = "subTemplateType2" : L.length > 0 && (d = "subTemplateType");
951
- let p = m.filter(
952
- (w) => (w.type?.toString() === f(d)?.id.toString() || w.type === null) && f(d)?.id != null
953
- ), N = Ne(p, [p.findIndex((w) => !w.readonly)]);
954
- return N.length > 0 && (N[0].readonly === !0 && !r ? n = [] : n.push(Te), n = [
1014
+ const [Ue, Te] = v(!1);
1015
+ x(() => {
1016
+ he || Ue || X && q && l && (Te(!0), t(X), g("subject", X.subject ?? ""), setTimeout(() => {
1017
+ Te(!1);
1018
+ }, 1e3));
1019
+ }, [X, q, l, he]);
1020
+ const ve = () => {
1021
+ let n = [z], d = "templateType";
1022
+ O.length > 0 ? d = "subTemplateType2" : P.length > 0 && (d = "subTemplateType");
1023
+ let m = u.filter(
1024
+ (E) => (E.type?.toString() === f(d)?.id.toString() || E.type === null) && f(d)?.id != null
1025
+ ), C = Be(m, [m.findIndex((E) => !E.readonly)]);
1026
+ return C.length > 0 && (C[0].readonly === !0 && !i ? n = [] : n.push(Ae), n = [
955
1027
  ...n,
956
- ...N.map((A) => ({
957
- id: A.id,
958
- name: Le(p, A.id),
959
- isSeparator: A.isSeparator
1028
+ ...C.map((w) => ({
1029
+ id: w.id,
1030
+ name: He(m, w.id),
1031
+ isSeparator: w.isSeparator
960
1032
  }))
961
1033
  ]), n.length ? n : [];
962
1034
  };
963
- v(() => {
1035
+ x(() => {
964
1036
  if (e && e.type1) {
965
- const n = ee?.find(
1037
+ const n = ce?.find(
966
1038
  (d) => `${d.id}` === e.type1
967
1039
  );
968
- y("templateType", n);
1040
+ g("templateType", n);
969
1041
  }
970
- }, [U, ee]), v(() => {
1042
+ }, [U, ce]), x(() => {
971
1043
  if (e && e.type2) {
972
- const n = L?.find(
1044
+ const n = P?.find(
973
1045
  (d) => `${d.id}` === e.type2
974
1046
  );
975
- y("subTemplateType", n);
1047
+ g("subTemplateType", n);
976
1048
  }
977
- }, [U, L]), v(() => {
1049
+ }, [U, P]), x(() => {
978
1050
  if (e && e.type3) {
979
- const n = j?.find(
1051
+ const n = O?.find(
980
1052
  (d) => `${d.id}` === e.type3
981
1053
  );
982
- y("subTemplateType2", n);
1054
+ g("subTemplateType2", n);
983
1055
  }
984
- }, [U, j]), v(() => {
985
- if (e && e.templateId && m && m.length > 0 && !B && i) {
986
- const n = m?.find(
1056
+ }, [U, O]), x(() => {
1057
+ if (e && e.templateId && u && u.length > 0 && !M && l) {
1058
+ const n = u?.find(
987
1059
  (d) => `${d.id}` === e.templateId
988
1060
  );
989
- Ee(!0), n && (X(n), y("template", n));
1061
+ ae(!0), n && (V(n), g("template", n));
990
1062
  }
991
- }, [m, i]);
992
- const Le = (n, d) => {
993
- let p = n.find((N) => N.id === d);
994
- return p ? `${p.displayName}` : "";
995
- }, je = (n) => {
1063
+ }, [u, l]);
1064
+ const He = (n, d) => {
1065
+ let m = n.find((C) => C.id === d);
1066
+ return m ? `${m.displayName}` : "";
1067
+ }, Fe = (n) => {
996
1068
  window.StripoEditorApi.actionsApi.getTemplateData(
997
1069
  async (d) => {
998
- let p = n.template.id, N = "";
999
- k?.readonly && (p = "", N = n.template.id);
1000
- let w = m.find(
1001
- (q) => q.name === n.templateName.trim()
1070
+ let m = n.template.id, C = "";
1071
+ q?.readonly && (m = "", C = n.template.id);
1072
+ let E = u.find(
1073
+ (D) => D.name === n.templateName.trim()
1002
1074
  );
1003
- if (w && w.id !== p) {
1004
- P("templateName", {
1075
+ if (E && E.id !== m) {
1076
+ j("templateName", {
1005
1077
  type: "validate",
1006
1078
  message: "Template name already exists. Please choose a different name."
1007
1079
  });
1008
1080
  return;
1009
1081
  }
1010
- let A = n.templateType.id;
1011
- j && j.length > 0 ? A = n.subTemplateType2.id : L && L.length > 0 && (A = n.subTemplateType.id);
1012
- const re = {
1082
+ let w = n.templateType.id;
1083
+ O && O.length > 0 ? w = n.subTemplateType2.id : P && P.length > 0 && (w = n.subTemplateType.id);
1084
+ const W = {
1013
1085
  enerexIdentifier: "",
1014
1086
  projectId: "",
1015
- templateId: p,
1016
- templateType: A,
1087
+ templateId: m,
1088
+ templateType: w,
1017
1089
  name: n.templateName.trim(),
1018
1090
  html: d.html,
1019
1091
  css: d.css,
1020
1092
  subject: n.templateType.id === "2" ? n?.subject ?? "" : "",
1021
- parent_id: N
1093
+ parent_id: C
1022
1094
  };
1023
- if (await de(re)) {
1024
- if (T(), k?.readonly && !r)
1025
- _(), te([]), ne([]);
1095
+ if (await de(W)) {
1096
+ if (T(), q?.readonly && !i)
1097
+ I(), ee([]), te([]);
1026
1098
  else {
1027
- const q = await Z({ id: p });
1028
- F(q || void 0);
1099
+ const D = await oe({ id: m });
1100
+ D ? Z(D) : ne();
1029
1101
  }
1030
- h();
1102
+ b();
1031
1103
  }
1032
1104
  }
1033
1105
  );
1034
- }, Oe = (n) => {
1106
+ }, ne = () => {
1107
+ be(!0), s(!1), Z(void 0), t(void 0), setTimeout(() => {
1108
+ be(!1);
1109
+ }, 0);
1110
+ }, Ve = (n, d) => {
1111
+ const m = d.trim(), C = "";
1112
+ if (u.find(
1113
+ (w) => w.name === m && w.id !== C
1114
+ )) {
1115
+ me(!0);
1116
+ return;
1117
+ }
1118
+ pe(!1), window.StripoEditorApi.actionsApi.getTemplateData(
1119
+ async (w) => {
1120
+ const W = n.template.id;
1121
+ let Y = n.templateType.id;
1122
+ O?.length ? Y = n.subTemplateType2.id : P?.length && (Y = n.subTemplateType.id);
1123
+ const D = {
1124
+ enerexIdentifier: "",
1125
+ projectId: "",
1126
+ templateId: C,
1127
+ templateType: Y,
1128
+ name: m,
1129
+ html: w.html,
1130
+ css: w.css,
1131
+ subject: n.templateType.id === "2" ? n?.subject ?? "" : "",
1132
+ parent_id: W
1133
+ };
1134
+ await de(D) && (T(), ne(), I(), ee([]), te([]), b());
1135
+ }
1136
+ );
1137
+ }, Ge = (n) => {
1035
1138
  window.StripoEditorApi.actionsApi.getTemplateData(
1036
1139
  async (d) => {
1037
- let p = n.template.id, N = "", w = m.find(
1038
- (q) => q.name === n.templateName.trim()
1140
+ let m = n.template.id, C = "", E = u.find(
1141
+ (D) => D.name === n.templateName.trim()
1039
1142
  );
1040
- if (w && w.id !== p) {
1041
- P("templateName", {
1143
+ if (E && E.id !== m) {
1144
+ j("templateName", {
1042
1145
  type: "validate",
1043
1146
  message: "Template name already exists. Please choose a different name."
1044
1147
  });
1045
1148
  return;
1046
1149
  }
1047
- let A = n.templateType.id;
1048
- j && j.length > 0 ? A = n.subTemplateType2.id : L && L.length > 0 && (A = n.subTemplateType.id);
1049
- const re = {
1150
+ let w = n.templateType.id;
1151
+ O && O.length > 0 ? w = n.subTemplateType2.id : P && P.length > 0 && (w = n.subTemplateType.id);
1152
+ const W = {
1050
1153
  enerexIdentifier: "",
1051
1154
  projectId: "",
1052
- templateId: p,
1053
- templateType: A,
1155
+ templateId: m,
1156
+ templateType: w,
1054
1157
  name: n.templateName.trim(),
1055
1158
  html: d.html,
1056
1159
  css: d.css,
1057
1160
  subject: n.templateType.id === "2" ? n?.subject ?? "" : "",
1058
- parent_id: N
1161
+ parent_id: C
1059
1162
  };
1060
- if (await de(re)) {
1163
+ if (await de(W)) {
1061
1164
  T();
1062
- const q = await Z({ id: p });
1063
- F(q || void 0), h();
1165
+ const D = await oe({ id: m });
1166
+ D ? Z(D) : ne(), b();
1064
1167
  }
1065
1168
  }
1066
1169
  );
1170
+ }, Ke = () => {
1171
+ ke("input"), pe(!0), me(!1);
1172
+ }, Qe = (n) => {
1173
+ if (G === "input") {
1174
+ const d = L();
1175
+ Ve(d, n || "");
1176
+ return;
1177
+ }
1067
1178
  };
1068
- return /* @__PURE__ */ l(ue, { className: "border border-0 text-start", children: /* @__PURE__ */ l(ue.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ l("form", { children: /* @__PURE__ */ l("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ $(ke, { children: [
1069
- /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1070
- W,
1071
- {
1072
- label: "Category",
1073
- control: C,
1074
- error: x,
1075
- options: ee,
1076
- required: !0,
1077
- disabled: u || E || I || D || !i,
1078
- validation: {
1079
- required: {
1080
- value: !0,
1081
- message: "Select a category"
1082
- }
1083
- },
1084
- ...a("templateType")
1085
- }
1086
- ) }),
1087
- L && L.length > 0 && /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1088
- W,
1089
- {
1090
- label: "Type",
1091
- control: C,
1092
- error: x,
1093
- options: L,
1094
- required: !0,
1095
- disabled: u || E || I || D || !i,
1096
- validation: {
1097
- required: {
1098
- value: !0,
1099
- message: "Select a type"
1100
- }
1101
- },
1102
- ...a("subTemplateType")
1103
- }
1104
- ) }),
1105
- j && j.length > 0 && /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1106
- W,
1107
- {
1108
- label: "Sub Type",
1109
- control: C,
1110
- error: x,
1111
- options: j,
1112
- required: !0,
1113
- disabled: u || E || I || D || !i,
1114
- validation: {
1115
- required: {
1116
- value: !0,
1117
- message: "Select a subtype"
1118
- }
1119
- },
1120
- ...a("subTemplateType2")
1121
- }
1122
- ) }),
1123
- /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1124
- W,
1125
- {
1126
- label: "Template",
1127
- control: C,
1128
- error: x,
1129
- disabled: u || E || I || D || !i,
1130
- options: pe(),
1131
- required: !1,
1132
- ...a("template")
1133
- }
1134
- ) }),
1135
- /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1136
- ye,
1137
- {
1138
- label: "Name",
1139
- register: a,
1140
- error: x,
1141
- required: !0,
1142
- name: "templateName",
1143
- validation: {
1144
- required: {
1145
- value: !0,
1146
- message: "Enter a name"
1147
- }
1179
+ return /* @__PURE__ */ S(we, { children: [
1180
+ /* @__PURE__ */ r(Se, { className: "border border-0 text-start", children: /* @__PURE__ */ r(Se.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ r("form", { children: /* @__PURE__ */ r("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ S(Xe, { children: [
1181
+ /* @__PURE__ */ r(H, { children: /* @__PURE__ */ r(
1182
+ se,
1183
+ {
1184
+ label: "Category",
1185
+ control: N,
1186
+ error: y,
1187
+ options: ce,
1188
+ required: !0,
1189
+ disabled: p || _ || A || $ || !l,
1190
+ validation: {
1191
+ required: {
1192
+ value: !0,
1193
+ message: "Select a category"
1194
+ }
1195
+ },
1196
+ ...a("templateType")
1148
1197
  }
1149
- }
1150
- ) }),
1151
- f("templateType")?.id === "2" && /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1152
- ye,
1153
- {
1154
- label: "Subject",
1155
- register: a,
1156
- error: x,
1157
- required: !1,
1158
- name: "subject"
1159
- }
1160
- ) }),
1161
- /* @__PURE__ */ $(M, { className: "d-flex align-self-start justify-content-end gap-2 mb-1 btn-padding", children: [
1162
- /* @__PURE__ */ l(
1198
+ ) }),
1199
+ P && P.length > 0 && /* @__PURE__ */ r(H, { children: /* @__PURE__ */ r(
1163
1200
  se,
1164
1201
  {
1165
- style: { width: "70px" },
1166
- variant: "primary",
1167
- disabled: u || E || I || D || !i,
1168
- onClick: () => {
1169
- X(void 0), _(), te([]), ne([]), o();
1202
+ label: "Type",
1203
+ control: N,
1204
+ error: y,
1205
+ options: P,
1206
+ required: !0,
1207
+ disabled: p || _ || A || $ || !l,
1208
+ validation: {
1209
+ required: {
1210
+ value: !0,
1211
+ message: "Select a type"
1212
+ }
1170
1213
  },
1171
- children: E || I ? /* @__PURE__ */ l(
1172
- Y,
1173
- {
1174
- animation: "border",
1175
- style: { width: "11px", height: "11px" },
1176
- size: "sm",
1177
- role: "status",
1178
- className: "me-1",
1179
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
1214
+ ...a("subTemplateType")
1215
+ }
1216
+ ) }),
1217
+ O && O.length > 0 && /* @__PURE__ */ r(H, { children: /* @__PURE__ */ r(
1218
+ se,
1219
+ {
1220
+ label: "Sub Type",
1221
+ control: N,
1222
+ error: y,
1223
+ options: O,
1224
+ required: !0,
1225
+ disabled: p || _ || A || $ || !l,
1226
+ validation: {
1227
+ required: {
1228
+ value: !0,
1229
+ message: "Select a subtype"
1180
1230
  }
1181
- ) : "Clear"
1231
+ },
1232
+ ...a("subTemplateType2")
1182
1233
  }
1183
- ),
1184
- (f("templateType")?.id.toString() !== "2" || (f("templateType")?.id.toString() === "2" && (k?.id ?? "")) !== "") && /* @__PURE__ */ $(De, { children: [
1185
- !(k?.readonly && r) && /* @__PURE__ */ l(
1186
- se,
1187
- {
1188
- type: "button",
1189
- onClick: c(je),
1190
- variant: "primary",
1191
- style: { width: "80px" },
1192
- disabled: u || E || I || D || !i,
1193
- children: E || I ? /* @__PURE__ */ l(
1194
- Y,
1195
- {
1196
- animation: "border",
1197
- style: { width: "11px", height: "11px" },
1198
- size: "sm",
1199
- role: "status",
1200
- className: "me-1",
1201
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
1202
- }
1203
- ) : k?.readonly ? "Save as" : "Save"
1234
+ ) }),
1235
+ /* @__PURE__ */ r(H, { children: /* @__PURE__ */ r(
1236
+ se,
1237
+ {
1238
+ label: "Template",
1239
+ control: N,
1240
+ error: y,
1241
+ disabled: p || _ || A || $ || !l,
1242
+ options: ve(),
1243
+ required: !1,
1244
+ ...a("template")
1245
+ }
1246
+ ) }),
1247
+ /* @__PURE__ */ r(H, { children: /* @__PURE__ */ r(
1248
+ Ee,
1249
+ {
1250
+ label: "Name",
1251
+ register: a,
1252
+ error: y,
1253
+ required: !0,
1254
+ name: "templateName",
1255
+ validation: {
1256
+ required: {
1257
+ value: !0,
1258
+ message: "Enter a name"
1259
+ }
1204
1260
  }
1205
- ),
1206
- k?.readonly && r && /* @__PURE__ */ l(
1207
- se,
1261
+ }
1262
+ ) }),
1263
+ f("templateType")?.id === "2" && /* @__PURE__ */ r(H, { children: /* @__PURE__ */ r(
1264
+ Ee,
1265
+ {
1266
+ label: "Subject",
1267
+ register: a,
1268
+ error: y,
1269
+ required: !1,
1270
+ name: "subject"
1271
+ }
1272
+ ) }),
1273
+ /* @__PURE__ */ S(H, { className: "d-flex align-self-start justify-content-end gap-2 mb-1 btn-padding", children: [
1274
+ /* @__PURE__ */ r(
1275
+ re,
1208
1276
  {
1209
- type: "button",
1210
- onClick: c(Oe),
1277
+ style: { width: "70px" },
1211
1278
  variant: "primary",
1212
- style: { width: "80px" },
1213
- disabled: u || E || I || D || !i,
1214
- children: E || I ? /* @__PURE__ */ l(
1215
- Y,
1279
+ disabled: p || _ || A || $ || !l,
1280
+ onClick: () => {
1281
+ V(void 0), I(), ee([]), te([]), o();
1282
+ },
1283
+ children: _ || A ? /* @__PURE__ */ r(
1284
+ J,
1216
1285
  {
1217
1286
  animation: "border",
1218
1287
  style: { width: "11px", height: "11px" },
1219
1288
  size: "sm",
1220
1289
  role: "status",
1221
1290
  className: "me-1",
1222
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
1291
+ children: /* @__PURE__ */ r("span", { className: "visually-hidden", children: "Loading..." })
1223
1292
  }
1224
- ) : "Save"
1293
+ ) : "Clear"
1225
1294
  }
1226
- )
1295
+ ),
1296
+ (f("templateType")?.id.toString() !== "2" || (f("templateType")?.id.toString() === "2" && (q?.id ?? "")) !== "") && /* @__PURE__ */ S(we, { children: [
1297
+ !(q?.readonly && i) && /* @__PURE__ */ r(
1298
+ re,
1299
+ {
1300
+ type: "button",
1301
+ onClick: c(Fe),
1302
+ variant: "primary",
1303
+ style: { width: "80px" },
1304
+ disabled: p || _ || A || $ || !l,
1305
+ children: _ || A ? /* @__PURE__ */ r(
1306
+ J,
1307
+ {
1308
+ animation: "border",
1309
+ style: { width: "11px", height: "11px" },
1310
+ size: "sm",
1311
+ role: "status",
1312
+ className: "me-1",
1313
+ children: /* @__PURE__ */ r("span", { className: "visually-hidden", children: "Loading..." })
1314
+ }
1315
+ ) : q?.readonly ? "Save as" : "Save"
1316
+ }
1317
+ ),
1318
+ (f("templateType")?.id.toString() === "28" || f("subTemplateType")?.id.toString() === "9" && f("subTemplateType2")?.id.toString() === "12") && !!f("templateName")?.trim() && /* @__PURE__ */ r(
1319
+ re,
1320
+ {
1321
+ type: "button",
1322
+ variant: "primary",
1323
+ style: { width: "80px" },
1324
+ onClick: () => Ke(),
1325
+ disabled: p || _ || A || $ || !l,
1326
+ children: _ || A ? /* @__PURE__ */ r(
1327
+ J,
1328
+ {
1329
+ animation: "border",
1330
+ style: { width: "11px", height: "11px" },
1331
+ size: "sm",
1332
+ role: "status",
1333
+ className: "me-1",
1334
+ children: /* @__PURE__ */ r("span", { className: "visually-hidden", children: "Loading..." })
1335
+ }
1336
+ ) : "Save as"
1337
+ }
1338
+ ),
1339
+ q?.readonly && i && /* @__PURE__ */ r(
1340
+ re,
1341
+ {
1342
+ type: "button",
1343
+ onClick: c(Ge),
1344
+ variant: "primary",
1345
+ style: { width: "80px" },
1346
+ disabled: p || _ || A || $ || !l,
1347
+ children: _ || A ? /* @__PURE__ */ r(
1348
+ J,
1349
+ {
1350
+ animation: "border",
1351
+ style: { width: "11px", height: "11px" },
1352
+ size: "sm",
1353
+ role: "status",
1354
+ className: "me-1",
1355
+ children: /* @__PURE__ */ r("span", { className: "visually-hidden", children: "Loading..." })
1356
+ }
1357
+ ) : "Save"
1358
+ }
1359
+ )
1360
+ ] })
1227
1361
  ] })
1228
- ] })
1229
- ] }) }) }) }) });
1230
- }, ut = ({ config: t }) => {
1231
- const [s, o] = S(!1), [i, r] = S(), [e, a] = S(!1);
1232
- v(() => {
1362
+ ] }) }) }) }) }),
1363
+ /* @__PURE__ */ r(
1364
+ dt,
1365
+ {
1366
+ show: $e,
1367
+ variant: G,
1368
+ title: G === "confirm" ? "Are you sure?" : "Save Template As",
1369
+ message: G === "confirm" ? 'Are you sure you want to remove custom template ""?' : "",
1370
+ label: "New Name",
1371
+ requiredMessage: "Enter a new name",
1372
+ externalError: Re,
1373
+ externalErrorMessage: "Template name already exists. Please choose a different name",
1374
+ confirmText: G === "confirm" ? "Ok" : "Save as",
1375
+ confirmButtonVariant: G === "confirm" ? "danger" : "primary",
1376
+ onConfirm: Qe,
1377
+ onCancel: () => pe(!1),
1378
+ onInputChange: () => me(!1)
1379
+ }
1380
+ )
1381
+ ] });
1382
+ }, _t = ({ config: t }) => {
1383
+ const [s, o] = v(!1), [l, i] = v(), [e, a] = v(!1);
1384
+ x(() => {
1233
1385
  t.isAdmin || a(!0);
1234
1386
  }, []);
1235
- const [c, T] = S(!1);
1236
- return /* @__PURE__ */ l(Fe, { configs: t, children: /* @__PURE__ */ l(Ve, { children: /* @__PURE__ */ $("div", { className: "root-widget", children: [
1237
- /* @__PURE__ */ l(
1238
- it,
1387
+ const [c, T] = v(!1);
1388
+ return /* @__PURE__ */ r(nt, { configs: t, children: /* @__PURE__ */ r(st, { children: /* @__PURE__ */ S("div", { className: "root-widget", children: [
1389
+ /* @__PURE__ */ r(
1390
+ Tt,
1239
1391
  {
1240
1392
  templateLoading: T,
1241
1393
  onSelectItem: (f) => {
1242
- if (r(f), t.isAdmin && a(!0), window.StripoEditorApi && window.StripoEditorApi.actionsApi) {
1243
- let _ = z;
1244
- window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1245
- f?.html ?? _,
1394
+ if (i(f), t.isAdmin && a(!0), window.StripoEditorApi && window.StripoEditorApi.actionsApi) {
1395
+ let I = ie;
1396
+ console.log("selected template:"), window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1397
+ f?.html ?? I,
1246
1398
  f?.css ?? "",
1247
1399
  ""
1248
1400
  );
@@ -1250,21 +1402,21 @@ const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__
1250
1402
  },
1251
1403
  editorInitialized: s,
1252
1404
  onReset: () => {
1253
- T(!1), r(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1254
- z,
1405
+ T(!1), i(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1406
+ ie,
1255
1407
  "",
1256
1408
  ""
1257
1409
  );
1258
1410
  }
1259
1411
  }
1260
1412
  ),
1261
- e && /* @__PURE__ */ l(
1262
- Ye,
1413
+ e && /* @__PURE__ */ r(
1414
+ ot,
1263
1415
  {
1264
1416
  onEditorInitialized: o,
1265
1417
  templateHTML: {
1266
- css: i?.css ?? "",
1267
- html: i?.html ?? z
1418
+ css: l?.css ?? "",
1419
+ html: l?.html ?? ie
1268
1420
  },
1269
1421
  loading: c,
1270
1422
  className: "col-span-5"
@@ -1273,5 +1425,5 @@ const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__
1273
1425
  ] }) }) });
1274
1426
  };
1275
1427
  export {
1276
- ut as EditorWidget
1428
+ _t as EditorWidget
1277
1429
  };