@enerex/template-studio 1.1.28 → 1.1.30

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