@enerex/template-studio 1.1.34 → 1.1.35

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