@kgalexander/mcreate 0.0.13 → 0.0.14

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.
package/dist/index.mjs CHANGED
@@ -21,7 +21,6 @@ import {
21
21
  FONTS,
22
22
  FONT_SIZE_STEP,
23
23
  History,
24
- IMAGE_SELECTION_VALID_TYPES,
25
24
  Input,
26
25
  LETTER_SPACING_STEP,
27
26
  LINE_HEIGHT_STEP,
@@ -29,7 +28,6 @@ import {
29
28
  MAX_FONT_SIZE,
30
29
  MAX_LETTER_SPACING,
31
30
  MAX_LINE_HEIGHT,
32
- MAX_PAID_LEVEL,
33
31
  MAX_TEMPLATE_SIZE,
34
32
  MIN_FONT_SIZE,
35
33
  MIN_LETTER_SPACING,
@@ -61,7 +59,7 @@ import {
61
59
  setupDragImage,
62
60
  useEditorStore,
63
61
  useSidebarContext
64
- } from "./chunk-LAW7VVEQ.mjs";
62
+ } from "./chunk-QGWWLZOW.mjs";
65
63
 
66
64
  // src/core/editor/components/email-template-v2/header.tsx
67
65
  import { ArrowLeftIcon, CopyIcon, MegaphoneIcon, MoreHorizontalIcon, PencilIcon, TrashIcon } from "lucide-react";
@@ -196,15 +194,23 @@ function TemplateNameDialog() {
196
194
 
197
195
  // src/core/editor/components/email-template-v2/header.tsx
198
196
  import { jsx as jsx4, jsxs as jsxs5 } from "react/jsx-runtime";
199
- function TemplateHeader({ template }) {
200
- const { templateId, onSave, markAsSaved, isSaving, setIsSaving } = useEditorStore();
197
+ function TemplateHeader() {
198
+ const templateId = useEditorStore((s) => s.templateId);
199
+ const onSave = useEditorStore((s) => s.onSave);
200
+ const markAsSaved = useEditorStore((s) => s.markAsSaved);
201
+ const isSaving = useEditorStore((s) => s.isSaving);
202
+ const setIsSaving = useEditorStore((s) => s.setIsSaving);
203
+ const onExit = useEditorStore((s) => s.onExit);
204
+ const templateName = useEditorStore((s) => s.template?.name);
201
205
  const handleExit = async () => {
202
206
  console.log("handleExit - templateId:", templateId);
203
207
  if (isSaving || !templateId || !onSave) return;
204
208
  setIsSaving(true);
205
209
  try {
206
- await onSave(templateId, template);
210
+ await onSave(templateId, useEditorStore.getState().template);
207
211
  markAsSaved();
212
+ onExit?.();
213
+ console.log("handleExit - onExit called");
208
214
  } catch (error) {
209
215
  console.error("Failed to save:", error);
210
216
  } finally {
@@ -221,7 +227,7 @@ function TemplateHeader({ template }) {
221
227
  /* @__PURE__ */ jsx4(TemplateSizeIndicator, {})
222
228
  ] }),
223
229
  /* @__PURE__ */ jsxs5("div", { className: "flex flex-row gap-2 items-center", children: [
224
- template?.name || "Loading...",
230
+ templateName || "Loading...",
225
231
  /* @__PURE__ */ jsx4(TemplateNameDialog, {})
226
232
  ] }),
227
233
  /* @__PURE__ */ jsxs5("div", { className: "flex flex-row gap-1 items-center", children: [
@@ -257,7 +263,7 @@ function TemplateHeader({ template }) {
257
263
 
258
264
  // src/core/editor/components/email-template-v2/sidebar/sidebar.tsx
259
265
  import { useCallback as useCallback8, useEffect as useEffect2, useRef as useRef3, useMemo as useMemo6, useState as useState6 } from "react";
260
- import { BlocksIcon, Hexagon as Hexagon2, Paintbrush, PanelLeftClose, PanelLeftOpen } from "lucide-react";
266
+ import { BlocksIcon, Paintbrush, PanelLeftClose, PanelLeftOpen } from "lucide-react";
261
267
 
262
268
  // src/core/editor/components/email-template-v2/sidebar/view/elements/main.tsx
263
269
  import { useState as useState2 } from "react";
@@ -1357,7 +1363,7 @@ var rgbaArrayToHex = (rgba) => {
1357
1363
  const [r, g, b] = rgba.map((v) => Math.round(v));
1358
1364
  return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase()}`;
1359
1365
  };
1360
- var ColorButton = ({ color, onColorSelect, currentColor }) => /* @__PURE__ */ jsxs19(Tooltip, { children: [
1366
+ var ColorButton = ({ colorName, color, onColorSelect, currentColor }) => /* @__PURE__ */ jsxs19(Tooltip, { children: [
1361
1367
  /* @__PURE__ */ jsx21(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx21(
1362
1368
  "button",
1363
1369
  {
@@ -1366,11 +1372,13 @@ var ColorButton = ({ color, onColorSelect, currentColor }) => /* @__PURE__ */ js
1366
1372
  className: `aspect-square rounded-full cursor-pointer border hover:border-gray-500 ${isColorSelected(color, currentColor) ? "border-2 border-blue-500" : "border-accent"}`
1367
1373
  }
1368
1374
  ) }),
1369
- /* @__PURE__ */ jsx21(TooltipContent, { children: color })
1375
+ /* @__PURE__ */ jsx21(TooltipContent, { children: colorName || color })
1370
1376
  ] });
1371
1377
  function ColorSelection({ setActiveView, lastView, onColorSelect, colorType = "Color", colorTarget, focusIdx, currentColor }) {
1372
1378
  const templateColors = useTemplateColors();
1373
1379
  const lastPickedColorRef = useRef2(null);
1380
+ const userData = useEditorStore((s) => s.userData);
1381
+ const colorPalettes = userData?.brand_kits?.[0]?.color_palettes ?? [];
1374
1382
  const [colorWheelOpen, setColorWheelOpen] = useState4(false);
1375
1383
  const handleColorPickerChange = useCallback6((rgba) => {
1376
1384
  const hex = rgbaArrayToHex(rgba);
@@ -1424,7 +1432,7 @@ function ColorSelection({ setActiveView, lastView, onColorSelect, colorType = "C
1424
1432
  templateColors.map((color) => /* @__PURE__ */ jsx21(ColorButton, { color, onColorSelect, currentColor }, color))
1425
1433
  ] }) })
1426
1434
  ] }),
1427
- /* @__PURE__ */ jsxs19("div", { className: "w-full mb-4", children: [
1435
+ colorPalettes.length > 0 && /* @__PURE__ */ jsxs19("div", { className: "w-full mb-4", children: [
1428
1436
  /* @__PURE__ */ jsxs19("div", { className: "flex flex-row items-center justify-between w-full mb-1", children: [
1429
1437
  /* @__PURE__ */ jsxs19("div", { className: "flex flex-row items-center gap-2 h-[44px]", children: [
1430
1438
  /* @__PURE__ */ jsx21(Hexagon, { className: "w-4 h-4 text-muted-foreground" }),
@@ -1432,16 +1440,10 @@ function ColorSelection({ setActiveView, lastView, onColorSelect, colorType = "C
1432
1440
  ] }),
1433
1441
  /* @__PURE__ */ jsx21(Button, { variant: "link", className: "text-sm pr-0 cursor-pointer", children: "Edit" })
1434
1442
  ] }),
1435
- /* @__PURE__ */ jsxs19("div", { className: "w-full flex flex-col gap-4", children: [
1436
- /* @__PURE__ */ jsxs19("div", { className: "flex flex-col gap-2", children: [
1437
- /* @__PURE__ */ jsx21(Label, { className: "text-xs font-medium text-muted-foreground", children: "Color palette 1" }),
1438
- /* @__PURE__ */ jsx21("div", { className: "w-full grid grid-cols-7 gap-2", children: /* @__PURE__ */ jsx21(ColorButton, { color: "#FFFFFF", onColorSelect, currentColor }) })
1439
- ] }),
1440
- /* @__PURE__ */ jsxs19("div", { className: "flex flex-col gap-2", children: [
1441
- /* @__PURE__ */ jsx21(Label, { className: "text-xs font-medium text-muted-foreground", children: "Color palette 2" }),
1442
- /* @__PURE__ */ jsx21("div", { className: "w-full grid grid-cols-7 gap-2", children: /* @__PURE__ */ jsx21(ColorButton, { color: "#E97575", onColorSelect, currentColor }) })
1443
- ] })
1444
- ] })
1443
+ /* @__PURE__ */ jsx21("div", { className: "w-full flex flex-col gap-4", children: colorPalettes.map((palette) => /* @__PURE__ */ jsxs19("div", { className: "flex flex-col gap-2", children: [
1444
+ /* @__PURE__ */ jsx21(Label, { className: "text-xs font-medium text-muted-foreground", children: palette.name }),
1445
+ /* @__PURE__ */ jsx21("div", { className: "w-full grid grid-cols-7 gap-2", children: palette.colors.map((c) => /* @__PURE__ */ jsx21(ColorButton, { colorName: c.name, color: c.hex, onColorSelect, currentColor }, c.color_id)) })
1446
+ ] }, palette.palette_id)) })
1445
1447
  ] }),
1446
1448
  /* @__PURE__ */ jsxs19("div", { className: "w-full", children: [
1447
1449
  /* @__PURE__ */ jsxs19("div", { className: "flex flex-row items-center justify-between w-full mb-1", children: [
@@ -1527,6 +1529,7 @@ var IMAGES_MOCK_DATA = [
1527
1529
  ];
1528
1530
  var ImageSelection = ({ setActiveView, lastView, onImageSelect, focusIdx }) => {
1529
1531
  const template = useEditorStore((state) => state.template);
1532
+ const images = useEditorStore((state) => state.images);
1530
1533
  const currentImageUrl = useMemo4(() => {
1531
1534
  if (!focusIdx || !template) return null;
1532
1535
  const path = focusIdx.startsWith("content.") ? focusIdx.replace("content.", "content[0].").replace(/\.\[(\d+)\]/g, "[$1]") : focusIdx;
@@ -1541,16 +1544,28 @@ var ImageSelection = ({ setActiveView, lastView, onImageSelect, focusIdx }) => {
1541
1544
  ] }) }),
1542
1545
  /* @__PURE__ */ jsxs20("div", { className: "w-full", children: [
1543
1546
  /* @__PURE__ */ jsx22("div", { className: "flex flex-row items-center justify-between w-full mb-4", children: /* @__PURE__ */ jsx22("p", { className: "text-sm font-medium", children: "Images" }) }),
1544
- /* @__PURE__ */ jsx22("div", { className: "w-full grid grid-cols-3 gap-3", children: IMAGES_MOCK_DATA.map((image, index) => /* @__PURE__ */ jsx22(
1545
- Button,
1546
- {
1547
- variant: "outline",
1548
- className: `aspect-square h-full w-full cursor-pointer shadow-none transition-none rounded-[12px] p-0 ${currentImageUrl === image.src ? "ring-2 ring-blue-500 ring-offset-2" : ""}`,
1549
- onClick: () => onImageSelect?.(image.src),
1550
- children: /* @__PURE__ */ jsx22("img", { src: image.src, alt: image.alt, className: "w-full h-full object-cover rounded-[12px]" })
1551
- },
1552
- index
1553
- )) })
1547
+ /* @__PURE__ */ jsxs20("div", { className: "w-full grid grid-cols-3 gap-3", children: [
1548
+ IMAGES_MOCK_DATA.map((image, index) => /* @__PURE__ */ jsx22(
1549
+ Button,
1550
+ {
1551
+ variant: "outline",
1552
+ className: `aspect-square h-full w-full cursor-pointer shadow-none transition-none rounded-[12px] p-0 ${currentImageUrl === image.src ? "ring-2 ring-blue-500 ring-offset-2" : ""}`,
1553
+ onClick: () => onImageSelect?.(image.src),
1554
+ children: /* @__PURE__ */ jsx22("img", { src: image.src, alt: image.alt, className: "w-full h-full object-cover rounded-[12px]" })
1555
+ },
1556
+ index
1557
+ )),
1558
+ images.map((image, index) => /* @__PURE__ */ jsx22(
1559
+ Button,
1560
+ {
1561
+ variant: "outline",
1562
+ className: `aspect-square h-full w-full cursor-pointer shadow-none transition-none rounded-[12px] p-0 ${currentImageUrl === image.public_url ? "ring-2 ring-blue-500 ring-offset-2" : ""}`,
1563
+ onClick: () => onImageSelect?.(image.public_url),
1564
+ children: /* @__PURE__ */ jsx22("img", { src: image.public_url, alt: image.original_name, className: "w-full h-full object-cover rounded-[12px]" })
1565
+ },
1566
+ index
1567
+ ))
1568
+ ] })
1554
1569
  ] })
1555
1570
  ] });
1556
1571
  };
@@ -1804,11 +1819,24 @@ var toTemplatePath = (focusIdx) => {
1804
1819
  return focusIdx.startsWith("content.") ? focusIdx.replace("content.", "content[0].").replace(/\.\[(\d+)\]/g, "[$1]") : focusIdx;
1805
1820
  };
1806
1821
  function TemplateSidebar({ editorLoading }) {
1807
- const { activeView, setActiveView, lastView, colorType, colorTarget, imageTarget } = useSidebarContext();
1822
+ const { activeView, setActiveView, lastView, colorType, colorTarget, imageTarget, setImageTarget } = useSidebarContext();
1808
1823
  const focusIdx = useEditorStore((state) => state.focusIdx);
1809
- const template = useEditorStore((state) => state.template);
1810
1824
  const tiptapEditor = useEditorStore((state) => state.tiptapEditor);
1825
+ const focusedElementAttrs = useEditorStore(
1826
+ (s) => s.focusIdx ? lodashGet2(s.template, toTemplatePath(s.focusIdx))?.attributes : null
1827
+ );
1828
+ const focusedElementType = useEditorStore(
1829
+ (s) => s.focusIdx ? lodashGet2(s.template, toTemplatePath(s.focusIdx))?.type : null
1830
+ );
1831
+ const parentElementAttrs = useEditorStore((s) => {
1832
+ if (!s.focusIdx) return null;
1833
+ const parentIdx = getParentIdx(s.focusIdx);
1834
+ return parentIdx ? lodashGet2(s.template, toTemplatePath(parentIdx))?.attributes : null;
1835
+ });
1836
+ const pageBgColor = useEditorStore((s) => s.template?.content?.[0]?.attributes?.["background-color"]);
1837
+ const linkColor = useEditorStore((s) => s.template?.content?.[0]?.data?.value?.linkColor);
1811
1838
  const previousElementTypeRef = useRef3(void 0);
1839
+ const previousFocusIdxRef = useRef3(null);
1812
1840
  const [openSidebar, setOpenSidebar] = useState6(true);
1813
1841
  const [updateCounter, forceUpdate] = useState6(0);
1814
1842
  useEffect2(() => {
@@ -1829,97 +1857,71 @@ function TemplateSidebar({ editorLoading }) {
1829
1857
  if (colorTarget === "highlightColor" && tiptapEditor) {
1830
1858
  return tiptapEditor.getAttributes("textStyle").backgroundColor || null;
1831
1859
  }
1832
- if (!focusIdx || !template) return null;
1833
- const path = toTemplatePath(focusIdx);
1834
- const element = lodashGet2(template, path);
1835
- if (!element) return null;
1860
+ if (!focusIdx || !focusedElementAttrs) return null;
1836
1861
  switch (colorTarget) {
1837
1862
  case "sectionBgColor":
1838
1863
  case "buttonBgColor":
1839
- return element.attributes?.["background-color"] || null;
1864
+ return focusedElementAttrs["background-color"] || null;
1840
1865
  case "buttonTextColor":
1841
1866
  case "socialTextColor":
1842
1867
  case "socialItemTextColor":
1843
- return element.attributes?.["color"] || null;
1868
+ return focusedElementAttrs["color"] || null;
1844
1869
  case "strokeColor":
1845
1870
  case "buttonStrokeColor": {
1846
- const parsed = parseBorder(element.attributes?.border);
1871
+ const parsed = parseBorder(focusedElementAttrs.border);
1847
1872
  return parsed.color || null;
1848
1873
  }
1849
1874
  case "spacerBgColor":
1850
1875
  case "dividerBgColor":
1851
1876
  case "imageBgColor":
1852
1877
  case "socialBgColor":
1853
- return element.attributes?.["container-background-color"] || null;
1878
+ return focusedElementAttrs["container-background-color"] || null;
1854
1879
  case "dividerBorderColor":
1855
- return element.attributes?.["border-color"] || null;
1856
- case "columnBgColor": {
1857
- const columnIdx = getParentIdx(focusIdx);
1858
- if (!columnIdx) return null;
1859
- const column = lodashGet2(template, toTemplatePath(columnIdx));
1860
- return column?.attributes?.["background-color"] || null;
1861
- }
1862
- case "columnStrokeColor": {
1863
- const columnIdx = getParentIdx(focusIdx);
1864
- if (!columnIdx) return null;
1865
- const column = lodashGet2(template, toTemplatePath(columnIdx));
1866
- const parsed = parseBorder(column?.attributes?.border);
1867
- return parsed.color || null;
1868
- }
1869
- case "propertyBgColor": {
1870
- const columnIdx = getParentIdx(focusIdx);
1871
- if (!columnIdx) return null;
1872
- const column = lodashGet2(template, toTemplatePath(columnIdx));
1873
- return column?.attributes?.["background-color"] || null;
1874
- }
1880
+ return focusedElementAttrs["border-color"] || null;
1881
+ case "columnBgColor":
1882
+ case "propertyBgColor":
1883
+ return parentElementAttrs?.["background-color"] || null;
1884
+ case "columnStrokeColor":
1875
1885
  case "propertyStrokeColor": {
1876
- const columnIdx = getParentIdx(focusIdx);
1877
- if (!columnIdx) return null;
1878
- const column = lodashGet2(template, toTemplatePath(columnIdx));
1879
- const parsed = parseBorder(column?.attributes?.border);
1886
+ const parsed = parseBorder(parentElementAttrs?.border);
1880
1887
  return parsed.color || null;
1881
1888
  }
1882
1889
  case "propertyTextColor": {
1883
- const element2 = lodashGet2(template, toTemplatePath(focusIdx));
1884
- if (element2?.type === "property-card-triple-item") {
1885
- const parentIdx = getParentIdx(focusIdx);
1886
- if (!parentIdx) return "#111116";
1887
- const parent = lodashGet2(template, toTemplatePath(parentIdx));
1888
- return parent?.attributes?.["text-color"] || "#111116";
1890
+ if (focusedElementType === "property-card-triple-item") {
1891
+ return parentElementAttrs?.["text-color"] || "#111116";
1889
1892
  }
1890
- return element2?.attributes?.["text-color"] || "#111116";
1891
- }
1892
- case "statusColor": {
1893
- const property = lodashGet2(template, toTemplatePath(focusIdx));
1894
- return property?.attributes?.["status-color"] || "#B8B8B8";
1893
+ return focusedElementAttrs["text-color"] || "#111116";
1895
1894
  }
1895
+ case "statusColor":
1896
+ return focusedElementAttrs["status-color"] || "#B8B8B8";
1896
1897
  case "pageBgColor":
1897
- return template?.content?.[0]?.attributes?.["background-color"] || null;
1898
+ return pageBgColor || null;
1898
1899
  case "linkColor":
1899
- return template?.content?.[0]?.data?.value?.linkColor || "#0000ff";
1900
+ return linkColor || "#0000ff";
1900
1901
  default:
1901
1902
  return null;
1902
1903
  }
1903
- }, [colorTarget, focusIdx, template, tiptapEditor, updateCounter]);
1904
+ }, [colorTarget, focusIdx, focusedElementAttrs, parentElementAttrs, focusedElementType, pageBgColor, linkColor, tiptapEditor, updateCounter]);
1904
1905
  useEffect2(() => {
1905
- if (!focusIdx || !template) {
1906
+ if (!focusIdx || !focusedElementType) {
1906
1907
  previousElementTypeRef.current = void 0;
1907
1908
  return;
1908
1909
  }
1909
- const element = lodashGet2(template, toTemplatePath(focusIdx));
1910
- const currentType = normalizeElementType(element?.type);
1910
+ const currentType = normalizeElementType(focusedElementType);
1911
1911
  const previousType = previousElementTypeRef.current;
1912
1912
  if (previousType && currentType !== previousType && activeView === "color") {
1913
1913
  setActiveView(lastView);
1914
1914
  }
1915
- if (activeView === "images" && currentType && !IMAGE_SELECTION_VALID_TYPES.includes(currentType)) {
1915
+ if (activeView === "images" && previousFocusIdxRef.current !== null && previousFocusIdxRef.current !== focusIdx) {
1916
1916
  setActiveView(lastView);
1917
+ setImageTarget(null);
1917
1918
  }
1918
1919
  if (activeView === "add-social" && currentType && !ADD_SOCIAL_VALID_TYPES.includes(currentType)) {
1919
1920
  setActiveView(lastView);
1920
1921
  }
1921
1922
  previousElementTypeRef.current = currentType;
1922
- }, [focusIdx, template, activeView, lastView, setActiveView]);
1923
+ previousFocusIdxRef.current = focusIdx ?? null;
1924
+ }, [focusIdx, focusedElementType, activeView, lastView, setActiveView, setImageTarget]);
1923
1925
  const handleColorSelect = useCallback8((color) => {
1924
1926
  const tiptapEditor2 = useEditorStore.getState().tiptapEditor;
1925
1927
  if (colorTarget === "textColor" && tiptapEditor2) {
@@ -1933,9 +1935,9 @@ function TemplateSidebar({ editorLoading }) {
1933
1935
  }
1934
1936
  window.dispatchEvent(new CustomEvent("toolbar-refresh"));
1935
1937
  } else if (colorTarget === "sectionBgColor") {
1936
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
1937
- if (focusIdx2 && template2) {
1938
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
1938
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
1939
+ if (focusIdx2 && template) {
1940
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
1939
1941
  if (element) {
1940
1942
  updateElement(focusIdx2, {
1941
1943
  attributes: { ...element.attributes, "background-color": color }
@@ -1943,9 +1945,9 @@ function TemplateSidebar({ editorLoading }) {
1943
1945
  }
1944
1946
  }
1945
1947
  } else if (colorTarget === "buttonBgColor") {
1946
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
1947
- if (focusIdx2 && template2) {
1948
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
1948
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
1949
+ if (focusIdx2 && template) {
1950
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
1949
1951
  if (element) {
1950
1952
  updateElement(focusIdx2, {
1951
1953
  attributes: { ...element.attributes, "background-color": color }
@@ -1953,9 +1955,9 @@ function TemplateSidebar({ editorLoading }) {
1953
1955
  }
1954
1956
  }
1955
1957
  } else if (colorTarget === "buttonStrokeColor") {
1956
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
1957
- if (focusIdx2 && template2) {
1958
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
1958
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
1959
+ if (focusIdx2 && template) {
1960
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
1959
1961
  if (element) {
1960
1962
  const parsed = parseBorder(element.attributes?.border);
1961
1963
  const newBorder = formatBorder({
@@ -1969,9 +1971,9 @@ function TemplateSidebar({ editorLoading }) {
1969
1971
  }
1970
1972
  }
1971
1973
  } else if (colorTarget === "buttonTextColor") {
1972
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
1973
- if (focusIdx2 && template2) {
1974
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
1974
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
1975
+ if (focusIdx2 && template) {
1976
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
1975
1977
  if (element) {
1976
1978
  updateElement(focusIdx2, {
1977
1979
  attributes: { ...element.attributes, "color": color }
@@ -1979,10 +1981,10 @@ function TemplateSidebar({ editorLoading }) {
1979
1981
  }
1980
1982
  }
1981
1983
  } else if (colorTarget === "strokeColor") {
1982
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
1984
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
1983
1985
  if (focusIdx2 === "content") return;
1984
- if (focusIdx2 && template2) {
1985
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
1986
+ if (focusIdx2 && template) {
1987
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
1986
1988
  if (element) {
1987
1989
  const parsed = parseBorder(element.attributes?.border);
1988
1990
  const newBorder = formatBorder({
@@ -1996,11 +1998,11 @@ function TemplateSidebar({ editorLoading }) {
1996
1998
  }
1997
1999
  }
1998
2000
  } else if (colorTarget === "columnBgColor") {
1999
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2000
- if (focusIdx2 && template2) {
2001
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2002
+ if (focusIdx2 && template) {
2001
2003
  const columnIdx = getParentIdx(focusIdx2);
2002
2004
  if (columnIdx) {
2003
- const column = lodashGet2(template2, toTemplatePath(columnIdx));
2005
+ const column = lodashGet2(template, toTemplatePath(columnIdx));
2004
2006
  if (column) {
2005
2007
  updateElement(columnIdx, {
2006
2008
  attributes: { ...column.attributes, "background-color": color }
@@ -2009,11 +2011,11 @@ function TemplateSidebar({ editorLoading }) {
2009
2011
  }
2010
2012
  }
2011
2013
  } else if (colorTarget === "columnStrokeColor") {
2012
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2013
- if (focusIdx2 && template2) {
2014
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2015
+ if (focusIdx2 && template) {
2014
2016
  const columnIdx = getParentIdx(focusIdx2);
2015
2017
  if (columnIdx) {
2016
- const column = lodashGet2(template2, toTemplatePath(columnIdx));
2018
+ const column = lodashGet2(template, toTemplatePath(columnIdx));
2017
2019
  if (column) {
2018
2020
  const parsed = parseBorder(column.attributes?.border);
2019
2021
  const newBorder = formatBorder({
@@ -2028,9 +2030,9 @@ function TemplateSidebar({ editorLoading }) {
2028
2030
  }
2029
2031
  }
2030
2032
  } else if (colorTarget === "spacerBgColor") {
2031
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2032
- if (focusIdx2 && template2) {
2033
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2033
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2034
+ if (focusIdx2 && template) {
2035
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2034
2036
  if (element) {
2035
2037
  updateElement(focusIdx2, {
2036
2038
  attributes: { ...element.attributes, "container-background-color": color }
@@ -2038,9 +2040,9 @@ function TemplateSidebar({ editorLoading }) {
2038
2040
  }
2039
2041
  }
2040
2042
  } else if (colorTarget === "dividerBorderColor") {
2041
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2042
- if (focusIdx2 && template2) {
2043
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2043
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2044
+ if (focusIdx2 && template) {
2045
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2044
2046
  if (element) {
2045
2047
  updateElement(focusIdx2, {
2046
2048
  attributes: { ...element.attributes, "border-color": color }
@@ -2048,9 +2050,9 @@ function TemplateSidebar({ editorLoading }) {
2048
2050
  }
2049
2051
  }
2050
2052
  } else if (colorTarget === "dividerBgColor") {
2051
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2052
- if (focusIdx2 && template2) {
2053
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2053
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2054
+ if (focusIdx2 && template) {
2055
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2054
2056
  if (element) {
2055
2057
  updateElement(focusIdx2, {
2056
2058
  attributes: { ...element.attributes, "container-background-color": color }
@@ -2058,9 +2060,9 @@ function TemplateSidebar({ editorLoading }) {
2058
2060
  }
2059
2061
  }
2060
2062
  } else if (colorTarget === "imageBgColor") {
2061
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2062
- if (focusIdx2 && template2) {
2063
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2063
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2064
+ if (focusIdx2 && template) {
2065
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2064
2066
  if (element) {
2065
2067
  updateElement(focusIdx2, {
2066
2068
  attributes: { ...element.attributes, "container-background-color": color }
@@ -2068,9 +2070,9 @@ function TemplateSidebar({ editorLoading }) {
2068
2070
  }
2069
2071
  }
2070
2072
  } else if (colorTarget === "socialBgColor") {
2071
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2072
- if (focusIdx2 && template2) {
2073
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2073
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2074
+ if (focusIdx2 && template) {
2075
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2074
2076
  if (element) {
2075
2077
  updateElement(focusIdx2, {
2076
2078
  attributes: { ...element.attributes, "container-background-color": color }
@@ -2078,9 +2080,9 @@ function TemplateSidebar({ editorLoading }) {
2078
2080
  }
2079
2081
  }
2080
2082
  } else if (colorTarget === "socialTextColor") {
2081
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2082
- if (focusIdx2 && template2) {
2083
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2083
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2084
+ if (focusIdx2 && template) {
2085
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2084
2086
  if (element) {
2085
2087
  updateElement(focusIdx2, {
2086
2088
  attributes: { ...element.attributes, "color": color }
@@ -2088,9 +2090,9 @@ function TemplateSidebar({ editorLoading }) {
2088
2090
  }
2089
2091
  }
2090
2092
  } else if (colorTarget === "socialItemTextColor") {
2091
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2092
- if (focusIdx2 && template2) {
2093
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2093
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2094
+ if (focusIdx2 && template) {
2095
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2094
2096
  if (element) {
2095
2097
  updateElement(focusIdx2, {
2096
2098
  attributes: { ...element.attributes, "color": color }
@@ -2098,9 +2100,9 @@ function TemplateSidebar({ editorLoading }) {
2098
2100
  }
2099
2101
  }
2100
2102
  } else if (colorTarget === "pageBgColor") {
2101
- const { updateElement, template: template2 } = useEditorStore.getState();
2102
- if (template2) {
2103
- const pageElement = template2.content?.[0];
2103
+ const { updateElement, template } = useEditorStore.getState();
2104
+ if (template) {
2105
+ const pageElement = template.content?.[0];
2104
2106
  if (pageElement) {
2105
2107
  updateElement("content", {
2106
2108
  attributes: { ...pageElement.attributes, "background-color": color }
@@ -2108,9 +2110,9 @@ function TemplateSidebar({ editorLoading }) {
2108
2110
  }
2109
2111
  }
2110
2112
  } else if (colorTarget === "linkColor") {
2111
- const { updateElement, template: template2 } = useEditorStore.getState();
2112
- if (template2) {
2113
- const pageElement = template2.content?.[0];
2113
+ const { updateElement, template } = useEditorStore.getState();
2114
+ if (template) {
2115
+ const pageElement = template.content?.[0];
2114
2116
  if (pageElement) {
2115
2117
  updateElement("content", {
2116
2118
  data: { value: { ...pageElement.data?.value, linkColor: color } }
@@ -2118,11 +2120,11 @@ function TemplateSidebar({ editorLoading }) {
2118
2120
  }
2119
2121
  }
2120
2122
  } else if (colorTarget === "propertyBgColor") {
2121
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2122
- if (focusIdx2 && template2) {
2123
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2124
+ if (focusIdx2 && template) {
2123
2125
  const columnIdx = getParentIdx(focusIdx2);
2124
2126
  if (columnIdx) {
2125
- const column = lodashGet2(template2, toTemplatePath(columnIdx));
2127
+ const column = lodashGet2(template, toTemplatePath(columnIdx));
2126
2128
  if (column) {
2127
2129
  updateElement(columnIdx, {
2128
2130
  attributes: { ...column.attributes, "background-color": color }
@@ -2131,12 +2133,12 @@ function TemplateSidebar({ editorLoading }) {
2131
2133
  }
2132
2134
  }
2133
2135
  } else if (colorTarget === "propertyStrokeColor") {
2134
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2135
- if (focusIdx2 && template2) {
2136
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2137
+ if (focusIdx2 && template) {
2136
2138
  const columnIdx = getParentIdx(focusIdx2);
2137
2139
  if (columnIdx) {
2138
- const column = lodashGet2(template2, toTemplatePath(columnIdx));
2139
- const property = lodashGet2(template2, toTemplatePath(focusIdx2));
2140
+ const column = lodashGet2(template, toTemplatePath(columnIdx));
2141
+ const property = lodashGet2(template, toTemplatePath(focusIdx2));
2140
2142
  if (column) {
2141
2143
  const parsed = parseBorder(column.attributes?.border);
2142
2144
  const newBorder = formatBorder({
@@ -2156,13 +2158,13 @@ function TemplateSidebar({ editorLoading }) {
2156
2158
  }
2157
2159
  }
2158
2160
  } else if (colorTarget === "propertyTextColor") {
2159
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2160
- if (focusIdx2 && template2) {
2161
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2161
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2162
+ if (focusIdx2 && template) {
2163
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2162
2164
  if (element?.type === "property-card-triple-item") {
2163
2165
  const parentIdx = getParentIdx(focusIdx2);
2164
2166
  if (parentIdx) {
2165
- const parent = lodashGet2(template2, toTemplatePath(parentIdx));
2167
+ const parent = lodashGet2(template, toTemplatePath(parentIdx));
2166
2168
  if (parent) {
2167
2169
  updateElement(parentIdx, {
2168
2170
  attributes: { ...parent.attributes, "text-color": color }
@@ -2176,9 +2178,9 @@ function TemplateSidebar({ editorLoading }) {
2176
2178
  }
2177
2179
  }
2178
2180
  } else if (colorTarget === "statusColor") {
2179
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2180
- if (focusIdx2 && template2) {
2181
- const property = lodashGet2(template2, toTemplatePath(focusIdx2));
2181
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2182
+ if (focusIdx2 && template) {
2183
+ const property = lodashGet2(template, toTemplatePath(focusIdx2));
2182
2184
  if (property) {
2183
2185
  updateElement(focusIdx2, {
2184
2186
  attributes: { ...property.attributes, "status-color": color }
@@ -2188,10 +2190,17 @@ function TemplateSidebar({ editorLoading }) {
2188
2190
  }
2189
2191
  }, [colorTarget]);
2190
2192
  const handleImageSelect = useCallback8((imageSrc) => {
2191
- const { focusIdx: focusIdx2, updateElement, template: template2 } = useEditorStore.getState();
2192
- if (!focusIdx2 || !template2) return;
2193
- const element = lodashGet2(template2, toTemplatePath(focusIdx2));
2193
+ const { focusIdx: focusIdx2, updateElement, template } = useEditorStore.getState();
2194
+ if (!focusIdx2 || !template) return;
2195
+ const element = lodashGet2(template, toTemplatePath(focusIdx2));
2194
2196
  if (!element) return;
2197
+ const validTypesForTarget = {
2198
+ sectionBgImage: ["section", "section-column", "section-property-km", "section-property-single-two", "section-property-triple"],
2199
+ imageElement: ["image"],
2200
+ propertyImage: ["property-card", "property-card-single-two", "property-card-triple-item"]
2201
+ };
2202
+ const validTypes = validTypesForTarget[imageTarget ?? ""];
2203
+ if (validTypes && !validTypes.includes(element.type)) return;
2195
2204
  const attributeName = imageTarget === "imageElement" ? "src" : imageTarget === "propertyImage" ? "image-src" : "background-url";
2196
2205
  updateElement(focusIdx2, {
2197
2206
  attributes: { ...element.attributes, [attributeName]: imageSrc }
@@ -2235,19 +2244,6 @@ function TemplateSidebar({ editorLoading }) {
2235
2244
  }
2236
2245
  ),
2237
2246
  /* @__PURE__ */ jsx24("span", { className: "text-xs text-muted-foreground", children: "Styles" })
2238
- ] }),
2239
- /* @__PURE__ */ jsxs22("div", { className: "flex flex-col items-center gap-1", children: [
2240
- /* @__PURE__ */ jsx24(
2241
- Button,
2242
- {
2243
- onClick: () => handleViewClick("brand"),
2244
- variant: "ghost",
2245
- size: "icon",
2246
- className: `shadow-none transition-none w-[44px] h-[44px] p-0 flex flex-col items-center cursor-pointer ${activeView === "brand" ? "bg-sidebar-accent" : ""}`,
2247
- children: /* @__PURE__ */ jsx24(Hexagon2, {})
2248
- }
2249
- ),
2250
- /* @__PURE__ */ jsx24("span", { className: "text-xs text-muted-foreground", children: "Brand" })
2251
2247
  ] })
2252
2248
  ] }),
2253
2249
  /* @__PURE__ */ jsx24(
@@ -8192,10 +8188,10 @@ var PropertyTripleItemToolbar = () => {
8192
8188
  // src/core/editor/components/email-template-v2/toolbar/toolbar.tsx
8193
8189
  import { jsx as jsx67 } from "react/jsx-runtime";
8194
8190
  function Toolbar() {
8195
- const { focusIdx, template } = useEditorStore();
8196
- const selectedElement = focusIdx ? getValueByIdx(template, focusIdx) : null;
8197
- const elementType = selectedElement?.type;
8198
- if (selectedElement === null) {
8191
+ const elementType = useEditorStore(
8192
+ (s) => s.focusIdx ? getValueByIdx(s.template, s.focusIdx)?.type : null
8193
+ );
8194
+ if (!elementType) {
8199
8195
  return;
8200
8196
  }
8201
8197
  if (elementType === "text") {
@@ -8298,7 +8294,7 @@ function useAutoSave() {
8298
8294
  // src/core/editor/components/email-template-v2/template-page.tsx
8299
8295
  import "react-json-view-lite/dist/index.css";
8300
8296
  import { jsx as jsx69, jsxs as jsxs54 } from "react/jsx-runtime";
8301
- var Editor2 = lazy(() => import("./core-GBVVYXAB.mjs").then((module) => ({
8297
+ var Editor2 = lazy(() => import("./core-WHUOFMYJ.mjs").then((module) => ({
8302
8298
  default: module.Editor
8303
8299
  })));
8304
8300
  function TemplatePage({
@@ -8306,25 +8302,19 @@ function TemplatePage({
8306
8302
  initialTemplate,
8307
8303
  onSave,
8308
8304
  onToast,
8309
- isPaidLevel = 0
8305
+ onExit,
8306
+ data
8310
8307
  }) {
8311
- console.log("Template page rendered!");
8312
- if (isPaidLevel > MAX_PAID_LEVEL) {
8313
- console.warn("This paid level is invalid:", isPaidLevel);
8314
- } else {
8315
- console.log("This paid level is valid:", isPaidLevel);
8316
- }
8317
8308
  useState20(() => {
8318
- useEditorStore.getState().initializeWithTemplate(templateId, initialTemplate, onSave, onToast, isPaidLevel);
8309
+ useEditorStore.getState().initializeWithTemplate(templateId, initialTemplate, onSave, onToast, data, onExit);
8319
8310
  });
8320
8311
  useAutoSave();
8321
8312
  const [editorLoading, setEditorLoading] = useState20(false);
8322
8313
  const [isPageHovered, setIsPageHovered] = useState20(false);
8323
- const template = useEditorStore((state) => state.template);
8324
8314
  const previewMode = useEditorStore((state) => state.previewMode);
8325
8315
  const focusIdx = useEditorStore((state) => state.focusIdx);
8326
8316
  const setFocusIdx = useEditorStore((state) => state.setFocusIdx);
8327
- const canvasBackgroundColor = template?.content?.[0]?.attributes?.["background-color"] || "#ffffff";
8317
+ const canvasBackgroundColor = useEditorStore((s) => s.template?.content?.[0]?.attributes?.["background-color"]) || "#ffffff";
8328
8318
  const handlePageClick = (e) => {
8329
8319
  if (!previewMode && e.target === e.currentTarget) {
8330
8320
  setFocusIdx("content");
@@ -8345,7 +8335,7 @@ function TemplatePage({
8345
8335
  {
8346
8336
  className: "flex flex-col bg-background overflow-hidden",
8347
8337
  children: [
8348
- /* @__PURE__ */ jsx69(TemplateHeader, { template }),
8338
+ /* @__PURE__ */ jsx69(TemplateHeader, {}),
8349
8339
  /* @__PURE__ */ jsxs54("div", { className: "flex flex-row h-full bg-background", children: [
8350
8340
  /* @__PURE__ */ jsx69(TemplateSidebar, { editorLoading }),
8351
8341
  /* @__PURE__ */ jsxs54("div", { className: "flex flex-col w-full overflow-hidden h-[calc(100vh-60px)] bg-background relative", children: [