@enerex/template-studio 1.1.31 → 1.1.32

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