@enerex/template-studio 1.1.35 → 1.1.36

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