@enerex/template-studio 1.1.23 → 1.1.24

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 s, jsxs as T } from "react/jsx-runtime";
2
- import I, { useContext as Z, useState as S, useEffect as _ } from "react";
3
- import { QueryClient as ce, QueryClientProvider as pe, useQuery as O, useMutation as ee, useQueryClient as me } from "@tanstack/react-query";
1
+ import { jsx as s, jsxs as v } from "react/jsx-runtime";
2
+ import I, { useContext as J, useState as S, useEffect as C } from "react";
3
+ import { QueryClient as ce, QueryClientProvider as pe, useQuery as q, useMutation as Z, useQueryClient as me } from "@tanstack/react-query";
4
4
  import V from "axios";
5
- import { Spinner as U, Form as E, Card as K, Row as ue, Col as $, Button as z } from "react-bootstrap";
5
+ import { Spinner as B, Form as E, Card as K, Row as ue, Col as P, Button as z } from "react-bootstrap";
6
6
  import { Controller as ge, useForm as fe } from "react-hook-form";
7
7
  import G from "react-select";
8
- const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
8
+ const R = `<!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,7 +361,7 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
361
361
  </div>\r
362
362
  </body>\r
363
363
  </html>\r
364
- `, te = I.createContext(
364
+ `, ee = I.createContext(
365
365
  void 0
366
366
  ), ye = ({
367
367
  children: t,
@@ -369,11 +369,11 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
369
369
  }) => {
370
370
  const [i, l] = I.useState(r.clientId), [n, e] = I.useState(r.apiKey), [a, o] = I.useState(
371
371
  r.enerexIdentifier
372
- ), [p, y] = I.useState(r.userName), [f, h] = I.useState(r.projectId), b = (m) => {
372
+ ), [c, y] = I.useState(r.userName), [f, h] = I.useState(r.projectId), b = (m) => {
373
373
  e(m.apiKey), l(m.clientId), h(m.projectId), o(m.enerexIdentifier), y(m.userName);
374
374
  };
375
375
  return /* @__PURE__ */ s(
376
- te.Provider,
376
+ ee.Provider,
377
377
  {
378
378
  value: {
379
379
  clientId: i,
@@ -381,17 +381,17 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
381
381
  setConfiguration: b,
382
382
  enerexIdentifier: a,
383
383
  projectId: f,
384
- userName: p
384
+ userName: c
385
385
  },
386
386
  children: t
387
387
  }
388
388
  );
389
- }, v = () => {
390
- const t = Z(te);
389
+ }, T = () => {
390
+ const t = J(ee);
391
391
  if (!t)
392
392
  throw new Error("widgetConfig must be used within a ConfigProvider");
393
393
  return t;
394
- }, ne = (t = "", r) => ({ get: async (n, e) => {
394
+ }, te = (t = "", r) => ({ get: async (n, e) => {
395
395
  try {
396
396
  const a = await V.get(
397
397
  `${t}${n}`,
@@ -414,14 +414,14 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
414
414
  } catch (o) {
415
415
  throw o;
416
416
  }
417
- } }), k = {
417
+ } }), $ = {
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
- }, re = I.createContext({
424
+ }, ne = I.createContext({
425
425
  get: () => {
426
426
  throw new Error("HttpClientContext.get not implemented");
427
427
  },
@@ -429,13 +429,13 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
429
429
  throw new Error("HttpClientContext.post not implemented");
430
430
  }
431
431
  }), he = ({ children: t }) => {
432
- const { clientId: r, apiKey: i } = v(), l = {
432
+ const { clientId: r, apiKey: i } = T(), l = {
433
433
  headers: {
434
434
  client_id: r,
435
435
  "x-api-key": i
436
436
  }
437
- }, { get: n, post: e } = ne(k.API_BASE_URL, l);
438
- return /* @__PURE__ */ s(re.Provider, { value: { get: n, post: e }, children: t });
437
+ }, { get: n, post: e } = te($.API_BASE_URL, l);
438
+ return /* @__PURE__ */ s(ne.Provider, { value: { get: n, post: e }, children: t });
439
439
  }, be = ({ children: t }) => {
440
440
  const r = new ce();
441
441
  return /* @__PURE__ */ s(he, { children: /* @__PURE__ */ s(pe, { client: r, children: t }) });
@@ -450,32 +450,32 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
450
450
  }));
451
451
  i.push({ category: l, entries: n });
452
452
  }), i;
453
- }, A = () => {
454
- const t = Z(re);
453
+ }, _ = () => {
454
+ const t = J(ne);
455
455
  if (t)
456
456
  return t;
457
457
  throw new Error("useHttpClient must be used within a HttpClientProvider");
458
- }, P = {
458
+ }, A = {
459
459
  Template_list: "/Template/list/",
460
460
  Template: "/Template/GetTemplate/",
461
461
  MergeTags: "/Template/TemplateMergeTags/",
462
462
  ExcludeCategory: "/Template/GetExcludeCategories/",
463
463
  SaveTemplate: "/Template/save-update/",
464
464
  TemplateTypes: "/Template/TemplateTypes/"
465
- }, Te = () => {
466
- const t = A(), { enerexIdentifier: r, projectId: i } = v();
467
- return O({
465
+ }, ve = () => {
466
+ const t = _(), { enerexIdentifier: r, projectId: i } = T();
467
+ return q({
468
468
  queryKey: ["getTemplateTags"],
469
469
  queryFn: async (n) => await t.get(
470
- `${P.MergeTags}${i}/${r}`
470
+ `${A.MergeTags}${i}/${r}`
471
471
  )
472
472
  });
473
- }, ve = () => {
474
- const t = A(), { enerexIdentifier: r, projectId: i } = v();
475
- return O({
473
+ }, Te = () => {
474
+ const t = _(), { enerexIdentifier: r, projectId: i } = T();
475
+ return q({
476
476
  queryKey: ["getExcludeCategory"],
477
477
  queryFn: async (n) => await t.get(
478
- `${P.ExcludeCategory}${i}/${r}`
478
+ `${A.ExcludeCategory}${i}/${r}`
479
479
  )
480
480
  });
481
481
  }, xe = ({
@@ -483,13 +483,13 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
483
483
  className: r = "",
484
484
  loading: i = !1
485
485
  }) => {
486
- const { post: l } = ne(), { data: n } = Te(), { data: e } = ve(), [a, o] = S(
487
- t ?? { html: D, css: "" }
488
- ), { enerexIdentifier: p, projectId: y, userName: f } = v(), h = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", b = "https://plugins.stripo.email/api/v1/auth";
489
- _(() => {
486
+ const { post: l } = te(), { data: n } = ve(), { data: e } = Te(), [a, o] = S(
487
+ t ?? { html: R, css: "" }
488
+ ), { enerexIdentifier: c, projectId: y, userName: f } = T(), h = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", b = "https://plugins.stripo.email/api/v1/auth";
489
+ C(() => {
490
490
  if (n && e && !document.getElementById("UiEditorScript")) {
491
491
  const u = document.createElement("script");
492
- u.id = "UiEditorScript", u.type = "module", u.src = k.EDITOR_SCRIPT_URL, u.onload = m, document.body.appendChild(u);
492
+ u.id = "UiEditorScript", u.type = "module", u.src = $.EDITOR_SCRIPT_URL, u.onload = m, document.body.appendChild(u);
493
493
  }
494
494
  }, [n, e]);
495
495
  const m = async () => {
@@ -501,19 +501,19 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
501
501
  modulesExcludedCategories: e ?? [],
502
502
  forceRecreate: !0,
503
503
  metadata: {
504
- emailId: `${y}_${p}`,
504
+ emailId: `${y}_${c}`,
505
505
  userId: "1",
506
506
  username: f,
507
507
  avatarUrl: h
508
508
  },
509
509
  locale: "en",
510
510
  onTokenRefreshRequest: async function(u) {
511
- const c = {
512
- pluginId: k.EDITOR_PLUGIN_ID,
513
- secretKey: k.EDITOR_SECRET_KEY,
511
+ const p = {
512
+ pluginId: $.EDITOR_PLUGIN_ID,
513
+ secretKey: $.EDITOR_SECRET_KEY,
514
514
  userId: "12",
515
515
  role: "user"
516
- }, g = await l(b, c);
516
+ }, g = await l(b, p);
517
517
  g && u(g.token);
518
518
  },
519
519
  codeEditorButtonSelector: "#codeEditor",
@@ -525,9 +525,9 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
525
525
  }
526
526
  );
527
527
  };
528
- return /* @__PURE__ */ s("div", { className: "position-relative", children: /* @__PURE__ */ T("div", { className: `editor-container ${r}`, children: [
528
+ return /* @__PURE__ */ s("div", { className: "position-relative", children: /* @__PURE__ */ v("div", { className: `editor-container ${r}`, children: [
529
529
  i && /* @__PURE__ */ s("div", { className: "loading-overlay", children: /* @__PURE__ */ s(
530
- U,
530
+ B,
531
531
  {
532
532
  animation: "border",
533
533
  style: { width: "11px", height: "11px" },
@@ -548,8 +548,8 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
548
548
  error: e,
549
549
  className: a = "",
550
550
  ...o
551
- }) => /* @__PURE__ */ T(E.Group, { className: a + " mb-1", children: [
552
- t ? /* @__PURE__ */ T(E.Label, { className: "mb-3 d-block form-label", children: [
551
+ }) => /* @__PURE__ */ v(E.Group, { className: a + " mb-1", children: [
552
+ t ? /* @__PURE__ */ v(E.Label, { className: "mb-3 d-block form-label", children: [
553
553
  t,
554
554
  l && /* @__PURE__ */ s("label", { className: "text-danger", children: "*" })
555
555
  ] }) : null,
@@ -568,37 +568,37 @@ const D = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
568
568
  ),
569
569
  e && e[n] ? /* @__PURE__ */ s(E.Control.Feedback, { type: "invalid", children: e[n].message }) : null
570
570
  ] }), Ce = () => {
571
- const t = A(), { enerexIdentifier: r, projectId: i } = v();
572
- return O({
571
+ const t = _(), { enerexIdentifier: r, projectId: i } = T();
572
+ return q({
573
573
  queryKey: ["getTemplatesList"],
574
574
  queryFn: async (n) => await t.get(
575
- `${P.Template_list}${i}/${r}`
575
+ `${A.Template_list}${i}/${r}`
576
576
  )
577
577
  });
578
578
  }, Ie = () => {
579
- const t = A(), { enerexIdentifier: r, projectId: i } = v();
580
- return ee({
579
+ const t = _(), { enerexIdentifier: r, projectId: i } = T();
580
+ return Z({
581
581
  mutationKey: ["getTemplate"],
582
582
  mutationFn: async ({ id: n }) => {
583
583
  if (n)
584
584
  return await t.get(
585
- `${P.Template}${r}/${n}/${i}`
585
+ `${A.Template}${r}/${n}/${i}`
586
586
  );
587
587
  }
588
588
  });
589
589
  }, Se = () => {
590
- const t = A(), { enerexIdentifier: r, projectId: i } = v();
591
- return O({
590
+ const t = _(), { enerexIdentifier: r, projectId: i } = T();
591
+ return q({
592
592
  queryKey: ["getTemplateTypes"],
593
593
  queryFn: async (n) => await t.get(
594
- `${P.TemplateTypes}${r}/${i}`
594
+ `${A.TemplateTypes}${r}/${i}`
595
595
  )
596
596
  });
597
597
  };
598
598
  function Ee(t) {
599
599
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
600
600
  }
601
- var B = { exports: {} };
601
+ var k = { exports: {} };
602
602
  /*!
603
603
  Copyright (c) 2018 Jed Watson.
604
604
  Licensed under the MIT License (MIT), see
@@ -635,7 +635,7 @@ function Ne() {
635
635
  }
636
636
  t.exports ? (i.default = i, t.exports = i) : window.classNames = i;
637
637
  })();
638
- }(B)), B.exports;
638
+ }(k)), k.exports;
639
639
  }
640
640
  var _e = Ne();
641
641
  const Y = /* @__PURE__ */ Ee(_e), Ae = ({
@@ -647,7 +647,7 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
647
647
  validation: e,
648
648
  labelKey: a = "name",
649
649
  disabled: o,
650
- isInvalid: p,
650
+ isInvalid: c,
651
651
  value: y,
652
652
  onChange: f,
653
653
  uncontrolled: h,
@@ -655,17 +655,17 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
655
655
  closeOnSelect: m = !0
656
656
  }) => {
657
657
  const u = {
658
- control: (c) => ({
659
- ...c,
658
+ control: (p) => ({
659
+ ...p,
660
660
  minHeight: "33px",
661
661
  // state.isFocused can display different borderColor if you need it
662
- borderColor: p ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
663
- backgroundImage: p ? '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",
662
+ borderColor: c ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
663
+ backgroundImage: c ? '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",
664
664
  backgroundRepeat: "no-repeat",
665
665
  backgroundPosition: "right calc(0.375em + 0.225rem) center",
666
666
  backgroundSize: "calc(0.75em + 0.45rem) calc(0.75em + 0.45rem)",
667
667
  "&:hover": {
668
- borderColor: p ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
668
+ borderColor: c ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
669
669
  },
670
670
  "& .react-select__single-value": {
671
671
  color: "var(--ct-input-color) !important"
@@ -677,18 +677,18 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
677
677
  display: "none"
678
678
  }
679
679
  }),
680
- menu: (c) => ({
681
- ...c,
680
+ menu: (p) => ({
681
+ ...p,
682
682
  marginTop: 0,
683
683
  width: "max-content",
684
684
  minWidth: "100%"
685
685
  }),
686
- menuPortal: (c) => ({
687
- ...c,
686
+ menuPortal: (p) => ({
687
+ ...p,
688
688
  zIndex: 9999
689
689
  }),
690
- multiValueRemove: (c) => ({
691
- ...c,
690
+ multiValueRemove: (p) => ({
691
+ ...p,
692
692
  display: o ? "none" : "block"
693
693
  })
694
694
  };
@@ -696,7 +696,7 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
696
696
  G,
697
697
  {
698
698
  className: Y({
699
- "is-invalid": p
699
+ "is-invalid": c
700
700
  }),
701
701
  styles: u,
702
702
  classNamePrefix: "react-select",
@@ -706,8 +706,8 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
706
706
  placeholder: n,
707
707
  menuPortalTarget: document.body,
708
708
  value: y,
709
- getOptionLabel: typeof a == "string" ? (c) => c[a] : a,
710
- getOptionValue: (c) => c.id,
709
+ getOptionLabel: typeof a == "string" ? (p) => p[a] : a,
710
+ getOptionValue: (p) => p.id,
711
711
  isDisabled: o,
712
712
  menuPlacement: b,
713
713
  closeMenuOnSelect: m
@@ -718,18 +718,18 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
718
718
  control: r,
719
719
  name: t,
720
720
  rules: e,
721
- render: ({ field: { onChange: c, value: g, onBlur: L } }) => /* @__PURE__ */ s(
721
+ render: ({ field: { onChange: p, value: g, onBlur: j } }) => /* @__PURE__ */ s(
722
722
  G,
723
723
  {
724
724
  className: Y({
725
- "is-invalid": p
725
+ "is-invalid": c
726
726
  }),
727
727
  styles: u,
728
728
  classNamePrefix: "react-select",
729
729
  isMulti: l,
730
730
  options: i,
731
- onBlur: L,
732
- onChange: c,
731
+ onBlur: j,
732
+ onChange: p,
733
733
  placeholder: n,
734
734
  menuPortalTarget: document.body,
735
735
  value: g,
@@ -750,8 +750,8 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
750
750
  control: l,
751
751
  error: n,
752
752
  ...e
753
- }) => /* @__PURE__ */ T(E.Group, { className: "mb-1", children: [
754
- t && /* @__PURE__ */ T(E.Label, { className: "mb-3 d-block form-label", children: [
753
+ }) => /* @__PURE__ */ v(E.Group, { className: "mb-1", children: [
754
+ t && /* @__PURE__ */ v(E.Label, { className: "mb-3 d-block form-label", children: [
755
755
  t,
756
756
  " ",
757
757
  e.required && /* @__PURE__ */ s("span", { className: "text-danger", children: "*" })
@@ -768,17 +768,17 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
768
768
  ),
769
769
  n && n[r] ? /* @__PURE__ */ s(E.Control.Feedback, { type: "invalid", children: n[r].message }) : null
770
770
  ] }), Pe = () => {
771
- const t = A();
771
+ const t = _();
772
772
  me();
773
- const { enerexIdentifier: r, projectId: i } = v();
774
- return ee({
773
+ const { enerexIdentifier: r, projectId: i } = T();
774
+ return Z({
775
775
  mutationKey: ["saveTemplate"],
776
776
  mutationFn: async (n) => (n.enerexIdentifier = r ?? "", n.projectId = i ?? "", await t.post(
777
- `${P.SaveTemplate}`,
777
+ `${A.SaveTemplate}`,
778
778
  n
779
779
  ))
780
780
  });
781
- }, J = { id: "", name: "New (Blank)" }, je = ({
781
+ }, O = { id: "", name: "New (Blank)" }, je = ({
782
782
  onSelectItem: t,
783
783
  templateLoading: r,
784
784
  onReset: i
@@ -789,7 +789,7 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
789
789
  clearErrors: e,
790
790
  setValue: a,
791
791
  control: o,
792
- watch: p,
792
+ watch: c,
793
793
  reset: y,
794
794
  formState: { errors: f }
795
795
  } = fe({
@@ -797,72 +797,67 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
797
797
  templateName: "",
798
798
  subject: "",
799
799
  templateType: void 0,
800
- template: J
800
+ template: O
801
801
  },
802
802
  mode: "onChange"
803
803
  }), {
804
804
  data: h,
805
805
  refetch: b,
806
806
  isLoading: m
807
- } = Ce(), [u, c] = S([]), [g, L] = S(), [w, H] = S(), { mutateAsync: se, isPending: N } = Ie(), { mutateAsync: ie, isPending: R } = Pe(), { data: j, isLoading: M } = Se(), [F, ae] = S([]);
808
- _(() => {
809
- j && ae(
810
- j.filter((d) => d.id !== void 0).map((d) => ({
807
+ } = Ce(), [u, p] = S([]), [g, j] = S(), [w, U] = S(), { mutateAsync: re, isPending: N } = Ie(), { mutateAsync: se, isPending: L } = Pe(), { data: D, isLoading: H } = Se(), [ie, ae] = S([]);
808
+ C(() => {
809
+ D && ae(
810
+ D.filter((d) => d.id !== void 0).map((d) => ({
811
811
  id: `${d.id}`,
812
812
  name: d.name
813
813
  }))
814
814
  );
815
- }, [j]), _(() => {
815
+ }, [D]), C(() => {
816
816
  r(!!N);
817
- }, [N]), _(() => {
818
- c(h ?? []);
817
+ }, [N]), C(() => {
818
+ p(h ?? []);
819
819
  }, [h]);
820
820
  const le = async (d) => {
821
- if (L(d), d) {
822
- if (a("templateName", d?.name), j && j.find((C) => C.id === d.type)) {
823
- const C = F.find((q) => q.id === `${d.type}`);
824
- C && a("templateType", C);
825
- }
826
- e();
827
- } else
828
- a("templateName", ""), a("subject", "");
829
- const x = await se({ id: d?.id });
830
- H(x || void 0);
821
+ j(d), d ? (a("templateName", d?.name), e()) : (a("templateName", ""), a("subject", ""));
822
+ const x = await re({ id: d?.id });
823
+ U(x || void 0);
831
824
  };
832
- _(() => {
833
- let d = u.find((x) => x.id === p("template")?.id);
825
+ C(() => {
826
+ a("template", O);
827
+ }, [c("templateType")]), C(() => {
828
+ let d = u.find((x) => x.id === c("template")?.id);
834
829
  le(d);
835
- }, [p("template")]), _(() => {
830
+ }, [c("template")]), C(() => {
836
831
  w && g ? (t(w), a("subject", w.subject ?? "")) : t(void 0);
837
832
  }, [w, g, t]);
838
833
  const oe = (d) => {
839
834
  window.StripoEditorApi.actionsApi.getTemplateData(
840
835
  async (x) => {
841
- let C = d.template.id, q = "";
842
- g?.readonly && (C = "", q = d.template.id);
836
+ let M = d.template.id, F = "";
837
+ g?.readonly && (M = "", F = d.template.id);
843
838
  const de = {
844
839
  enerexIdentifier: "",
845
840
  projectId: "",
846
- templateId: C,
841
+ templateId: M,
847
842
  templateType: d.templateType.id,
848
843
  name: d.templateName,
849
844
  html: x.html,
850
845
  css: x.css,
851
846
  subject: d.templateType.id === "2" ? d?.subject ?? "" : "",
852
- parent_id: q
847
+ parent_id: F
853
848
  };
854
- await ie(de) && (e(), y(), b());
849
+ await se(de) && (e(), y(), b());
855
850
  }
856
851
  );
857
852
  };
858
- return /* @__PURE__ */ s(K, { className: "border border-0 text-start", children: /* @__PURE__ */ s(K.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ s("form", { onSubmit: n(oe), children: /* @__PURE__ */ s("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ T(ue, { children: [
859
- /* @__PURE__ */ s($, { children: /* @__PURE__ */ s(
853
+ return /* @__PURE__ */ s(K, { className: "border border-0 text-start", children: /* @__PURE__ */ s(K.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ s("form", { onSubmit: n(oe), children: /* @__PURE__ */ s("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ v(ue, { children: [
854
+ /* @__PURE__ */ s(P, { children: /* @__PURE__ */ s(
860
855
  X,
861
856
  {
862
857
  label: "Type",
863
858
  control: o,
864
859
  error: f,
865
- options: F,
860
+ options: ie,
866
861
  required: !0,
867
862
  validation: {
868
863
  required: {
@@ -873,16 +868,16 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
873
868
  ...l("templateType")
874
869
  }
875
870
  ) }),
876
- /* @__PURE__ */ s($, { children: /* @__PURE__ */ s(
871
+ /* @__PURE__ */ s(P, { children: /* @__PURE__ */ s(
877
872
  X,
878
873
  {
879
874
  label: "Template",
880
875
  control: o,
881
876
  error: f,
882
877
  options: [
883
- J,
878
+ O,
884
879
  ...u.filter(
885
- (d) => (d.type?.toString() === p("templateType")?.id || d.type === null) && p("templateType")?.id != null
880
+ (d) => (d.type?.toString() === c("templateType")?.id || d.type === null) && c("templateType")?.id != null
886
881
  ).map((d) => ({
887
882
  id: d.id,
888
883
  name: d.name
@@ -892,7 +887,7 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
892
887
  ...l("template")
893
888
  }
894
889
  ) }),
895
- /* @__PURE__ */ s($, { children: /* @__PURE__ */ s(
890
+ /* @__PURE__ */ s(P, { children: /* @__PURE__ */ s(
896
891
  Q,
897
892
  {
898
893
  label: "Name",
@@ -908,7 +903,7 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
908
903
  }
909
904
  }
910
905
  ) }),
911
- p("templateType")?.id === "2" && /* @__PURE__ */ s($, { children: /* @__PURE__ */ s(
906
+ c("templateType")?.id === "2" && /* @__PURE__ */ s(P, { children: /* @__PURE__ */ s(
912
907
  Q,
913
908
  {
914
909
  label: "Subject",
@@ -918,18 +913,18 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
918
913
  name: "subject"
919
914
  }
920
915
  ) }),
921
- /* @__PURE__ */ T($, { className: "d-flex align-items-end justify-content-end gap-2 mb-3", children: [
916
+ /* @__PURE__ */ v(P, { className: "d-flex align-items-end justify-content-end gap-2 mb-3", children: [
922
917
  /* @__PURE__ */ s(
923
918
  z,
924
919
  {
925
920
  style: { width: "70px" },
926
921
  variant: "primary",
927
- disabled: m || N || R || M,
922
+ disabled: m || N || L || H,
928
923
  onClick: () => {
929
- L(void 0), y(), i();
924
+ j(void 0), y(), i();
930
925
  },
931
- children: N || R ? /* @__PURE__ */ s(
932
- U,
926
+ children: N || L ? /* @__PURE__ */ s(
927
+ B,
933
928
  {
934
929
  animation: "border",
935
930
  style: { width: "11px", height: "11px" },
@@ -941,15 +936,15 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
941
936
  ) : "Clear"
942
937
  }
943
938
  ),
944
- (p("templateType")?.id !== "2" || (g?.id ?? "") !== "") && /* @__PURE__ */ s(
939
+ (c("templateType")?.id !== "2" || (g?.id ?? "") !== "") && /* @__PURE__ */ s(
945
940
  z,
946
941
  {
947
942
  type: "submit",
948
943
  variant: "primary",
949
944
  style: { width: "80px" },
950
- disabled: m || N || R || M,
951
- children: N || R ? /* @__PURE__ */ s(
952
- U,
945
+ disabled: m || N || L || H,
946
+ children: N || L ? /* @__PURE__ */ s(
947
+ B,
953
948
  {
954
949
  animation: "border",
955
950
  style: { width: "11px", height: "11px" },
@@ -965,20 +960,20 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
965
960
  ] }) }) }) }) });
966
961
  }, Ue = ({ config: t }) => {
967
962
  const [r, i] = S(), [l, n] = S(!1);
968
- return /* @__PURE__ */ s(ye, { configs: t, children: /* @__PURE__ */ s(be, { children: /* @__PURE__ */ T("div", { className: "root-widget", children: [
963
+ return /* @__PURE__ */ s(ye, { configs: t, children: /* @__PURE__ */ s(be, { children: /* @__PURE__ */ v("div", { className: "root-widget", children: [
969
964
  /* @__PURE__ */ s(
970
965
  je,
971
966
  {
972
967
  templateLoading: n,
973
968
  onSelectItem: (o) => {
974
969
  i(o), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
975
- o?.html ?? D,
970
+ o?.html ?? R,
976
971
  o?.css ?? "",
977
972
  ""
978
973
  );
979
974
  },
980
975
  onReset: () => {
981
- n(!1), i(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(D, "", "");
976
+ n(!1), i(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(R, "", "");
982
977
  }
983
978
  }
984
979
  ),
@@ -987,7 +982,7 @@ const Y = /* @__PURE__ */ Ee(_e), Ae = ({
987
982
  {
988
983
  templateHTML: {
989
984
  css: r?.css ?? "",
990
- html: r?.html ?? D
985
+ html: r?.html ?? R
991
986
  },
992
987
  loading: l,
993
988
  className: "col-span-5"
@@ -1,4 +1,4 @@
1
- (function(f,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):(f=typeof globalThis<"u"?globalThis:f||self,n(f.EnerexTemplateEditor={},f.jsxRuntime,f.React,f.reactQuery,f.axios,f.reactBootstrap,f.reactHookForm,f.Select$1))})(this,function(f,n,c,w,O,p,F,M){"use strict";const P=`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
1
+ (function(f,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):(f=typeof globalThis<"u"?globalThis:f||self,n(f.EnerexTemplateEditor={},f.jsxRuntime,f.React,f.reactQuery,f.axios,f.reactBootstrap,f.reactHookForm,f.Select$1))})(this,function(f,n,c,w,D,p,O,F){"use strict";const j=`<!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
- `,U=c.createContext(void 0),Q=({children:t,configs:s})=>{const[l,o]=c.useState(s.clientId),[r,e]=c.useState(s.apiKey),[i,a]=c.useState(s.enerexIdentifier),[u,v]=c.useState(s.userName),[b,x]=c.useState(s.projectId),C=g=>{e(g.apiKey),o(g.clientId),x(g.projectId),a(g.enerexIdentifier),v(g.userName)};return n.jsx(U.Provider,{value:{clientId:l,apiKey:r,setConfiguration:C,enerexIdentifier:i,projectId:b,userName:u},children:t})},T=()=>{const t=c.useContext(U);if(!t)throw new Error("widgetConfig must be used within a ConfigProvider");return t},H=(t="",s)=>({get:async(r,e)=>{try{const i=await O.get(`${t}${r}`,e??s);if(i.status===200)return i.data}catch(i){throw i}},post:async(r,e,i)=>{try{const a=await O.post(`${t}${r}`,e,i??s);if(a.status===200)return a.data}catch(a){throw a}}}),A={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"},V=c.createContext({get:()=>{throw new Error("HttpClientContext.get not implemented")},post:()=>{throw new Error("HttpClientContext.post not implemented")}}),Z=({children:t})=>{const{clientId:s,apiKey:l}=T(),o={headers:{client_id:s,"x-api-key":l}},{get:r,post:e}=H(A.API_BASE_URL,o);return n.jsx(V.Provider,{value:{get:r,post:e},children:t})},R=({children:t})=>{const s=new w.QueryClient;return n.jsx(Z,{children:n.jsx(w.QueryClientProvider,{client:s,children:t})})},ee=t=>{const s=Array.from(new Set(t.map(o=>o.category))),l=[];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}));l.push({category:o,entries:r})}),l},N=()=>{const t=c.useContext(V);if(t)return t;throw new Error("useHttpClient must be used within a HttpClientProvider")},_={Template_list:"/Template/list/",Template:"/Template/GetTemplate/",MergeTags:"/Template/TemplateMergeTags/",ExcludeCategory:"/Template/GetExcludeCategories/",SaveTemplate:"/Template/save-update/",TemplateTypes:"/Template/TemplateTypes/"},te=()=>{const t=N(),{enerexIdentifier:s,projectId:l}=T();return w.useQuery({queryKey:["getTemplateTags"],queryFn:async r=>await t.get(`${_.MergeTags}${l}/${s}`)})},ne=()=>{const t=N(),{enerexIdentifier:s,projectId:l}=T();return w.useQuery({queryKey:["getExcludeCategory"],queryFn:async r=>await t.get(`${_.ExcludeCategory}${l}/${s}`)})},re=({templateHTML:t,className:s="",loading:l=!1})=>{const{post:o}=H(),{data:r}=te(),{data:e}=ne(),[i,a]=c.useState(t??{html:P,css:""}),{enerexIdentifier:u,projectId:v,userName:b}=T(),x="https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png",C="https://plugins.stripo.email/api/v1/auth";c.useEffect(()=>{if(r&&e&&!document.getElementById("UiEditorScript")){const y=document.createElement("script");y.id="UiEditorScript",y.type="module",y.src=A.EDITOR_SCRIPT_URL,y.onload=g,document.body.appendChild(y)}},[r,e]);const g=async()=>{window.UIEditor.initEditor(document.querySelector("#stripoEditorContainer"),{html:i.html,css:i.css,modulesExcludedCategories:e??[],forceRecreate:!0,metadata:{emailId:`${v}_${u}`,userId:"1",username:b,avatarUrl:x},locale:"en",onTokenRefreshRequest:async function(y){const m={pluginId:A.EDITOR_PLUGIN_ID,secretKey:A.EDITOR_SECRET_KEY,userId:"12",role:"user"},h=await o(C,m);h&&y(h.token)},codeEditorButtonSelector:"#codeEditor",undoButtonSelector:"#undoButton",redoButtonSelector:"#redoButton",mobileViewButtonSelector:"#mobileViewButton",desktopViewButtonSelector:"#desktopViewButton",mergeTags:ee(r??[])})};return n.jsx("div",{className:"position-relative",children:n.jsxs("div",{className:`editor-container ${s}`,children:[l&&n.jsx("div",{className:"loading-overlay",children:n.jsx(p.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"})]})})},K=({label:t,register:s,validation:l,required:o=!1,name:r,error:e,className:i="",...a})=>n.jsxs(p.Form.Group,{className:i+" mb-1",children:[t?n.jsxs(p.Form.Label,{className:"mb-3 d-block form-label",children:[t,o&&n.jsx("label",{className:"text-danger",children:"*"})]}):null,n.jsx(p.Form.Control,{name:r,type:"text",...a,isInvalid:!!(e&&e[r]),...s?s(r,{...l}):{},className:`react-select__control ${e&&e[r]&&"border border-danger"}`}),e&&e[r]?n.jsx(p.Form.Control.Feedback,{type:"invalid",children:e[r].message}):null]}),se=()=>{const t=N(),{enerexIdentifier:s,projectId:l}=T();return w.useQuery({queryKey:["getTemplatesList"],queryFn:async r=>await t.get(`${_.Template_list}${l}/${s}`)})},ie=()=>{const t=N(),{enerexIdentifier:s,projectId:l}=T();return w.useMutation({mutationKey:["getTemplate"],mutationFn:async({id:r})=>{if(r)return await t.get(`${_.Template}${s}/${r}/${l}`)}})},le=()=>{const t=N(),{enerexIdentifier:s,projectId:l}=T();return w.useQuery({queryKey:["getTemplateTypes"],queryFn:async r=>await t.get(`${_.TemplateTypes}${s}/${l}`)})};function oe(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var D={exports:{}};/*!
357
+ `,M=c.createContext(void 0),J=({children:t,configs:s})=>{const[i,o]=c.useState(s.clientId),[r,e]=c.useState(s.apiKey),[l,a]=c.useState(s.enerexIdentifier),[m,v]=c.useState(s.userName),[b,x]=c.useState(s.projectId),C=g=>{e(g.apiKey),o(g.clientId),x(g.projectId),a(g.enerexIdentifier),v(g.userName)};return n.jsx(M.Provider,{value:{clientId:i,apiKey:r,setConfiguration:C,enerexIdentifier:l,projectId:b,userName:m},children:t})},T=()=>{const t=c.useContext(M);if(!t)throw new Error("widgetConfig must be used within a ConfigProvider");return t},U=(t="",s)=>({get:async(r,e)=>{try{const l=await D.get(`${t}${r}`,e??s);if(l.status===200)return l.data}catch(l){throw l}},post:async(r,e,l)=>{try{const a=await D.post(`${t}${r}`,e,l??s);if(a.status===200)return a.data}catch(a){throw a}}}),q={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"},H=c.createContext({get:()=>{throw new Error("HttpClientContext.get not implemented")},post:()=>{throw new Error("HttpClientContext.post not implemented")}}),Q=({children:t})=>{const{clientId:s,apiKey:i}=T(),o={headers:{client_id:s,"x-api-key":i}},{get:r,post:e}=U(q.API_BASE_URL,o);return n.jsx(H.Provider,{value:{get:r,post:e},children:t})},Z=({children:t})=>{const s=new w.QueryClient;return n.jsx(Q,{children:n.jsx(w.QueryClientProvider,{client:s,children:t})})},R=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},I=()=>{const t=c.useContext(H);if(t)return t;throw new Error("useHttpClient must be used within a HttpClientProvider")},N={Template_list:"/Template/list/",Template:"/Template/GetTemplate/",MergeTags:"/Template/TemplateMergeTags/",ExcludeCategory:"/Template/GetExcludeCategories/",SaveTemplate:"/Template/save-update/",TemplateTypes:"/Template/TemplateTypes/"},ee=()=>{const t=I(),{enerexIdentifier:s,projectId:i}=T();return w.useQuery({queryKey:["getTemplateTags"],queryFn:async r=>await t.get(`${N.MergeTags}${i}/${s}`)})},te=()=>{const t=I(),{enerexIdentifier:s,projectId:i}=T();return w.useQuery({queryKey:["getExcludeCategory"],queryFn:async r=>await t.get(`${N.ExcludeCategory}${i}/${s}`)})},ne=({templateHTML:t,className:s="",loading:i=!1})=>{const{post:o}=U(),{data:r}=ee(),{data:e}=te(),[l,a]=c.useState(t??{html:j,css:""}),{enerexIdentifier:m,projectId:v,userName:b}=T(),x="https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png",C="https://plugins.stripo.email/api/v1/auth";c.useEffect(()=>{if(r&&e&&!document.getElementById("UiEditorScript")){const y=document.createElement("script");y.id="UiEditorScript",y.type="module",y.src=q.EDITOR_SCRIPT_URL,y.onload=g,document.body.appendChild(y)}},[r,e]);const g=async()=>{window.UIEditor.initEditor(document.querySelector("#stripoEditorContainer"),{html:l.html,css:l.css,modulesExcludedCategories:e??[],forceRecreate:!0,metadata:{emailId:`${v}_${m}`,userId:"1",username:b,avatarUrl:x},locale:"en",onTokenRefreshRequest:async function(y){const u={pluginId:q.EDITOR_PLUGIN_ID,secretKey:q.EDITOR_SECRET_KEY,userId:"12",role:"user"},h=await o(C,u);h&&y(h.token)},codeEditorButtonSelector:"#codeEditor",undoButtonSelector:"#undoButton",redoButtonSelector:"#redoButton",mobileViewButtonSelector:"#mobileViewButton",desktopViewButtonSelector:"#desktopViewButton",mergeTags:R(r??[])})};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(p.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"})]})})},V=({label:t,register:s,validation:i,required:o=!1,name:r,error:e,className:l="",...a})=>n.jsxs(p.Form.Group,{className:l+" mb-1",children:[t?n.jsxs(p.Form.Label,{className:"mb-3 d-block form-label",children:[t,o&&n.jsx("label",{className:"text-danger",children:"*"})]}):null,n.jsx(p.Form.Control,{name:r,type:"text",...a,isInvalid:!!(e&&e[r]),...s?s(r,{...i}):{},className:`react-select__control ${e&&e[r]&&"border border-danger"}`}),e&&e[r]?n.jsx(p.Form.Control.Feedback,{type:"invalid",children:e[r].message}):null]}),re=()=>{const t=I(),{enerexIdentifier:s,projectId:i}=T();return w.useQuery({queryKey:["getTemplatesList"],queryFn:async r=>await t.get(`${N.Template_list}${i}/${s}`)})},se=()=>{const t=I(),{enerexIdentifier:s,projectId:i}=T();return w.useMutation({mutationKey:["getTemplate"],mutationFn:async({id:r})=>{if(r)return await t.get(`${N.Template}${s}/${r}/${i}`)}})},le=()=>{const t=I(),{enerexIdentifier:s,projectId:i}=T();return w.useQuery({queryKey:["getTemplateTypes"],queryFn:async r=>await t.get(`${N.TemplateTypes}${s}/${i}`)})};function ie(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var L={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 z;function ae(){return z||(z=1,function(t){(function(){var s={}.hasOwnProperty;function l(){for(var e="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(e=r(e,o(a)))}return e}function o(e){if(typeof e=="string"||typeof e=="number")return e;if(typeof e!="object")return"";if(Array.isArray(e))return l.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var i="";for(var a in e)s.call(e,a)&&e[a]&&(i=r(i,a));return i}function r(e,i){return i?e?e+" "+i:e+i:e}t.exports?(l.default=l,t.exports=l):window.classNames=l})()}(D)),D.exports}var de=ae();const G=oe(de),ce=({name:t="",control:s,options:l,multiple:o=!1,placeholder:r,validation:e,labelKey:i="name",disabled:a,isInvalid:u,value:v,onChange:b,uncontrolled:x,menuPlacement:C="auto",closeOnSelect:g=!0})=>{const y={control:m=>({...m,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:m=>({...m,marginTop:0,width:"max-content",minWidth:"100%"}),menuPortal:m=>({...m,zIndex:9999}),multiValueRemove:m=>({...m,display:a?"none":"block"})};return x?n.jsx(M,{className:G({"is-invalid":u}),styles:y,classNamePrefix:"react-select",isMulti:o,options:l,onChange:b,placeholder:r,menuPortalTarget:document.body,value:v,getOptionLabel:typeof i=="string"?m=>m[i]:i,getOptionValue:m=>m.id,isDisabled:a,menuPlacement:C,closeMenuOnSelect:g}):n.jsx(F.Controller,{control:s,name:t,rules:e,render:({field:{onChange:m,value:h,onBlur:L}})=>n.jsx(M,{className:G({"is-invalid":u}),styles:y,classNamePrefix:"react-select",isMulti:o,options:l,onBlur:L,onChange:m,placeholder:r,menuPortalTarget:document.body,value:h,getOptionLabel:typeof i=="string"?S=>S[i]:i,getOptionValue:S=>S.id,isDisabled:a,menuPlacement:C,closeMenuOnSelect:g},h?JSON.stringify(h):"reset")})},W=({label:t,name:s,validation:l,control:o,error:r,...e})=>n.jsxs(p.Form.Group,{className:"mb-1",children:[t&&n.jsxs(p.Form.Label,{className:"mb-3 d-block form-label",children:[t," ",e.required&&n.jsx("span",{className:"text-danger",children:"*"})]}),n.jsx(ce,{control:o,options:e.options??[],validation:l,isInvalid:r&&!!r[s],name:s}),r&&r[s]?n.jsx(p.Form.Control.Feedback,{type:"invalid",children:r[s].message}):null]}),pe=()=>{const t=N();w.useQueryClient();const{enerexIdentifier:s,projectId:l}=T();return w.useMutation({mutationKey:["saveTemplate"],mutationFn:async r=>(r.enerexIdentifier=s??"",r.projectId=l??"",await t.post(`${_.SaveTemplate}`,r))})},B={id:"",name:"New (Blank)"},me=({onSelectItem:t,templateLoading:s,onReset:l})=>{const{register:o,handleSubmit:r,clearErrors:e,setValue:i,control:a,watch:u,reset:v,formState:{errors:b}}=F.useForm({defaultValues:{templateName:"",subject:"",templateType:void 0,template:B},mode:"onChange"}),{data:x,refetch:C,isLoading:g}=se(),[y,m]=c.useState([]),[h,L]=c.useState(),[S,Y]=c.useState(),{mutateAsync:fe,isPending:j}=ie(),{mutateAsync:ge,isPending:$}=pe(),{data:q,isLoading:X}=le(),[J,ye]=c.useState([]);c.useEffect(()=>{q&&ye(q.filter(d=>d.id!==void 0).map(d=>({id:`${d.id}`,name:d.name})))},[q]),c.useEffect(()=>{s(!!j)},[j]),c.useEffect(()=>{m(x??[])},[x]);const he=async d=>{if(L(d),d){if(i("templateName",d?.name),q&&q.find(I=>I.id===d.type)){const I=J.find(k=>k.id===`${d.type}`);I&&i("templateType",I)}e()}else i("templateName",""),i("subject","");const E=await fe({id:d?.id});Y(E||void 0)};c.useEffect(()=>{let d=y.find(E=>E.id===u("template")?.id);he(d)},[u("template")]),c.useEffect(()=>{S&&h?(t(S),i("subject",S.subject??"")):t(void 0)},[S,h,t]);const be=d=>{window.StripoEditorApi.actionsApi.getTemplateData(async E=>{let I=d.template.id,k="";h?.readonly&&(I="",k=d.template.id);const we={enerexIdentifier:"",projectId:"",templateId:I,templateType:d.templateType.id,name:d.templateName,html:E.html,css:E.css,subject:d.templateType.id==="2"?d?.subject??"":"",parent_id:k};await ge(we)&&(e(),v(),C())})};return n.jsx(p.Card,{className:"border border-0 text-start",children:n.jsx(p.Card.Body,{className:"pe-0 ps-2",children:n.jsx("form",{onSubmit:r(be),children:n.jsx("div",{className:"template-list-container gap-3",children:n.jsxs(p.Row,{children:[n.jsx(p.Col,{children:n.jsx(W,{label:"Type",control:a,error:b,options:J,required:!0,validation:{required:{value:!0,message:"Select a type"}},...o("templateType")})}),n.jsx(p.Col,{children:n.jsx(W,{label:"Template",control:a,error:b,options:[B,...y.filter(d=>(d.type?.toString()===u("templateType")?.id||d.type===null)&&u("templateType")?.id!=null).map(d=>({id:d.id,name:d.name}))],required:!1,...o("template")})}),n.jsx(p.Col,{children:n.jsx(K,{label:"Name",register:o,error:b,required:!0,name:"templateName",validation:{required:{value:!0,message:"Enter a name"}}})}),u("templateType")?.id==="2"&&n.jsx(p.Col,{children:n.jsx(K,{label:"Subject",register:o,error:b,required:!1,name:"subject"})}),n.jsxs(p.Col,{className:"d-flex align-items-end justify-content-end gap-2 mb-3",children:[n.jsx(p.Button,{style:{width:"70px"},variant:"primary",disabled:g||j||$||X,onClick:()=>{L(void 0),v(),l()},children:j||$?n.jsx(p.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!=="2"||(h?.id??"")!=="")&&n.jsx(p.Button,{type:"submit",variant:"primary",style:{width:"80px"},disabled:g||j||$||X,children:j||$?n.jsx(p.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:n.jsx("span",{className:"visually-hidden",children:"Loading..."})}):h?.readonly?"Save as":"Save"})]})]})})})})})},ue=({config:t})=>{const[s,l]=c.useState(),[o,r]=c.useState(!1),e=a=>{l(a),window.StripoEditorApi&&window.StripoEditorApi.actionsApi&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(a?.html??P,a?.css??"","")},i=()=>{r(!1),l(void 0),window.StripoEditorApi&&window.StripoEditorApi.actionsApi&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(P,"","")};return n.jsx(Q,{configs:t,children:n.jsx(R,{children:n.jsxs("div",{className:"root-widget",children:[n.jsx(me,{templateLoading:r,onSelectItem:e,onReset:i}),n.jsx(re,{templateHTML:{css:s?.css??"",html:s?.html??P},loading:o,className:"col-span-5"})]})})})};f.EditorWidget=ue,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
361
+ */var K;function oe(){return K||(K=1,function(t){(function(){var s={}.hasOwnProperty;function i(){for(var e="",l=0;l<arguments.length;l++){var a=arguments[l];a&&(e=r(e,o(a)))}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 a in e)s.call(e,a)&&e[a]&&(l=r(l,a));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})()}(L)),L.exports}var ae=oe();const z=ie(ae),de=({name:t="",control:s,options:i,multiple:o=!1,placeholder:r,validation:e,labelKey:l="name",disabled:a,isInvalid:m,value:v,onChange:b,uncontrolled:x,menuPlacement:C="auto",closeOnSelect:g=!0})=>{const y={control:u=>({...u,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:u=>({...u,marginTop:0,width:"max-content",minWidth:"100%"}),menuPortal:u=>({...u,zIndex:9999}),multiValueRemove:u=>({...u,display:a?"none":"block"})};return x?n.jsx(F,{className:z({"is-invalid":m}),styles:y,classNamePrefix:"react-select",isMulti:o,options:i,onChange:b,placeholder:r,menuPortalTarget:document.body,value:v,getOptionLabel:typeof l=="string"?u=>u[l]:l,getOptionValue:u=>u.id,isDisabled:a,menuPlacement:C,closeMenuOnSelect:g}):n.jsx(O.Controller,{control:s,name:t,rules:e,render:({field:{onChange:u,value:h,onBlur:P}})=>n.jsx(F,{className:z({"is-invalid":m}),styles:y,classNamePrefix:"react-select",isMulti:o,options:i,onBlur:P,onChange:u,placeholder:r,menuPortalTarget:document.body,value:h,getOptionLabel:typeof l=="string"?S=>S[l]:l,getOptionValue:S=>S.id,isDisabled:a,menuPlacement:C,closeMenuOnSelect:g},h?JSON.stringify(h):"reset")})},G=({label:t,name:s,validation:i,control:o,error:r,...e})=>n.jsxs(p.Form.Group,{className:"mb-1",children:[t&&n.jsxs(p.Form.Label,{className:"mb-3 d-block form-label",children:[t," ",e.required&&n.jsx("span",{className:"text-danger",children:"*"})]}),n.jsx(de,{control:o,options:e.options??[],validation:i,isInvalid:r&&!!r[s],name:s}),r&&r[s]?n.jsx(p.Form.Control.Feedback,{type:"invalid",children:r[s].message}):null]}),ce=()=>{const t=I();w.useQueryClient();const{enerexIdentifier:s,projectId:i}=T();return w.useMutation({mutationKey:["saveTemplate"],mutationFn:async r=>(r.enerexIdentifier=s??"",r.projectId=i??"",await t.post(`${N.SaveTemplate}`,r))})},$={id:"",name:"New (Blank)"},pe=({onSelectItem:t,templateLoading:s,onReset:i})=>{const{register:o,handleSubmit:r,clearErrors:e,setValue:l,control:a,watch:m,reset:v,formState:{errors:b}}=O.useForm({defaultValues:{templateName:"",subject:"",templateType:void 0,template:$},mode:"onChange"}),{data:x,refetch:C,isLoading:g}=re(),[y,u]=c.useState([]),[h,P]=c.useState(),[S,W]=c.useState(),{mutateAsync:ue,isPending:_}=se(),{mutateAsync:fe,isPending:A}=ce(),{data:k,isLoading:B}=le(),[ge,ye]=c.useState([]);c.useEffect(()=>{k&&ye(k.filter(d=>d.id!==void 0).map(d=>({id:`${d.id}`,name:d.name})))},[k]),c.useEffect(()=>{s(!!_)},[_]),c.useEffect(()=>{u(x??[])},[x]);const he=async d=>{P(d),d?(l("templateName",d?.name),e()):(l("templateName",""),l("subject",""));const E=await ue({id:d?.id});W(E||void 0)};c.useEffect(()=>{l("template",$)},[m("templateType")]),c.useEffect(()=>{let d=y.find(E=>E.id===m("template")?.id);he(d)},[m("template")]),c.useEffect(()=>{S&&h?(t(S),l("subject",S.subject??"")):t(void 0)},[S,h,t]);const be=d=>{window.StripoEditorApi.actionsApi.getTemplateData(async E=>{let Y=d.template.id,X="";h?.readonly&&(Y="",X=d.template.id);const we={enerexIdentifier:"",projectId:"",templateId:Y,templateType:d.templateType.id,name:d.templateName,html:E.html,css:E.css,subject:d.templateType.id==="2"?d?.subject??"":"",parent_id:X};await fe(we)&&(e(),v(),C())})};return n.jsx(p.Card,{className:"border border-0 text-start",children:n.jsx(p.Card.Body,{className:"pe-0 ps-2",children:n.jsx("form",{onSubmit:r(be),children:n.jsx("div",{className:"template-list-container gap-3",children:n.jsxs(p.Row,{children:[n.jsx(p.Col,{children:n.jsx(G,{label:"Type",control:a,error:b,options:ge,required:!0,validation:{required:{value:!0,message:"Select a type"}},...o("templateType")})}),n.jsx(p.Col,{children:n.jsx(G,{label:"Template",control:a,error:b,options:[$,...y.filter(d=>(d.type?.toString()===m("templateType")?.id||d.type===null)&&m("templateType")?.id!=null).map(d=>({id:d.id,name:d.name}))],required:!1,...o("template")})}),n.jsx(p.Col,{children:n.jsx(V,{label:"Name",register:o,error:b,required:!0,name:"templateName",validation:{required:{value:!0,message:"Enter a name"}}})}),m("templateType")?.id==="2"&&n.jsx(p.Col,{children:n.jsx(V,{label:"Subject",register:o,error:b,required:!1,name:"subject"})}),n.jsxs(p.Col,{className:"d-flex align-items-end justify-content-end gap-2 mb-3",children:[n.jsx(p.Button,{style:{width:"70px"},variant:"primary",disabled:g||_||A||B,onClick:()=>{P(void 0),v(),i()},children:_||A?n.jsx(p.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!=="2"||(h?.id??"")!=="")&&n.jsx(p.Button,{type:"submit",variant:"primary",style:{width:"80px"},disabled:g||_||A||B,children:_||A?n.jsx(p.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:n.jsx("span",{className:"visually-hidden",children:"Loading..."})}):h?.readonly?"Save as":"Save"})]})]})})})})})},me=({config:t})=>{const[s,i]=c.useState(),[o,r]=c.useState(!1),e=a=>{i(a),window.StripoEditorApi&&window.StripoEditorApi.actionsApi&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(a?.html??j,a?.css??"","")},l=()=>{r(!1),i(void 0),window.StripoEditorApi&&window.StripoEditorApi.actionsApi&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(j,"","")};return n.jsx(J,{configs:t,children:n.jsx(Z,{children:n.jsxs("div",{className:"root-widget",children:[n.jsx(pe,{templateLoading:r,onSelectItem:e,onReset:l}),n.jsx(ne,{templateHTML:{css:s?.css??"",html:s?.html??j},loading:o,className:"col-span-5"})]})})})};f.EditorWidget=me,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enerex/template-studio",
3
- "version": "1.1.23",
3
+ "version": "1.1.24",
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",