@particle-academy/fancy-cms-ui 0.1.0 → 0.2.0

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.cjs CHANGED
@@ -569,7 +569,14 @@ function useEditor(initialDoc) {
569
569
  [state, apply, undo, redo, select, replace]
570
570
  );
571
571
  }
572
- function Canvas({ doc, selection, onSelect, apply }) {
572
+ function useLatestRef(value) {
573
+ const ref = react.useRef(value);
574
+ react.useEffect(() => {
575
+ ref.current = value;
576
+ });
577
+ return ref;
578
+ }
579
+ function Canvas({ doc, selection, onSelect, apply, registry, data }) {
573
580
  const ref = react.useRef(null);
574
581
  const [box, setBox] = react.useState(null);
575
582
  const drag = react.useRef(null);
@@ -626,7 +633,7 @@ function Canvas({ doc, selection, onSelect, apply }) {
626
633
  position: "relative",
627
634
  overflow: "auto",
628
635
  height: "100%",
629
- background: "#f8fafc"
636
+ background: "var(--fcms-canvas)"
630
637
  };
631
638
  const overlay = box ? {
632
639
  position: "absolute",
@@ -634,13 +641,13 @@ function Canvas({ doc, selection, onSelect, apply }) {
634
641
  top: box.y,
635
642
  width: box.w,
636
643
  height: box.h,
637
- outline: "2px solid #8b5cf6",
644
+ outline: "2px solid var(--fcms-accent, #8b5cf6)",
638
645
  outlineOffset: -1,
639
646
  cursor: "move",
640
647
  touchAction: "none"
641
648
  } : { display: "none" };
642
649
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, onClick: handleClick, style: surface, children: [
643
- /* @__PURE__ */ jsxRuntime.jsx(CmsPage, { doc }),
650
+ /* @__PURE__ */ jsxRuntime.jsx(CmsPage, { doc, registry, data }),
644
651
  /* @__PURE__ */ jsxRuntime.jsx(
645
652
  "div",
646
653
  {
@@ -711,10 +718,10 @@ function LayerRow({ doc, id, depth, selection, onSelect, onMove, overId, setOver
711
718
  cursor: draggable ? "grab" : "pointer",
712
719
  padding: "4px 8px",
713
720
  paddingLeft: 8 + depth * 14,
714
- background: selected ? "#ede9fe" : "transparent",
715
- color: selected ? "#5b21b6" : "#334155",
721
+ background: selected ? "var(--fcms-sel-bg)" : "transparent",
722
+ color: selected ? "var(--fcms-sel-fg)" : "var(--fcms-row-fg)",
716
723
  font: "inherit",
717
- boxShadow: overId === id ? "inset 0 -2px 0 0 #8b5cf6" : "none"
724
+ boxShadow: overId === id ? "inset 0 -2px 0 0 var(--fcms-accent, #8b5cf6)" : "none"
718
725
  },
719
726
  children: [
720
727
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: { opacity: 0.6 }, children: node.type }),
@@ -731,7 +738,7 @@ var label = {
731
738
  fontSize: 11,
732
739
  textTransform: "uppercase",
733
740
  letterSpacing: "0.04em",
734
- color: "#94a3b8",
741
+ color: "var(--fcms-muted)",
735
742
  margin: "10px 0 4px"
736
743
  };
737
744
  var input = {
@@ -739,21 +746,23 @@ var input = {
739
746
  boxSizing: "border-box",
740
747
  padding: "6px 8px",
741
748
  borderRadius: 6,
742
- border: "1px solid #e2e8f0",
749
+ border: "1px solid var(--fcms-border)",
750
+ background: "var(--fcms-input-bg)",
751
+ color: "var(--fcms-fg)",
743
752
  font: "inherit",
744
753
  fontSize: 13
745
754
  };
746
755
  function Inspector({ doc, selection, apply }) {
747
756
  const node = selection ? doc.nodes[selection] : null;
748
757
  if (!node) {
749
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 16, color: "#94a3b8", fontFamily: "system-ui, sans-serif", fontSize: 13 }, children: "Select an element to edit." });
758
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 16, color: "var(--fcms-muted)", fontFamily: "system-ui, sans-serif", fontSize: 13 }, children: "Select an element to edit." });
750
759
  }
751
760
  const s = node.style.base;
752
761
  const setStyle = (patch) => apply({ t: "set_style", id: node.id, breakpoint: "base", patch });
753
762
  const setProp = (key, value) => apply({ t: "set_props", id: node.id, patch: { [key]: value } });
754
763
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { overflow: "auto", padding: 16, fontFamily: "system-ui, sans-serif", height: "100%", boxSizing: "border-box" }, children: [
755
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, fontWeight: 600, color: "#0f172a" }, children: node.type }),
756
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 11, color: "#94a3b8", marginBottom: 8 }, children: node.id }),
764
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, fontWeight: 600, color: "var(--fcms-fg)" }, children: node.type }),
765
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 11, color: "var(--fcms-muted)", marginBottom: 8 }, children: node.id }),
757
766
  node.type === "text" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
758
767
  /* @__PURE__ */ jsxRuntime.jsx("label", { style: label, children: "Content" }),
759
768
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -831,29 +840,31 @@ function Inspector({ doc, selection, apply }) {
831
840
  )
832
841
  ] });
833
842
  }
834
- function Editor({ defaultValue, onChange }) {
843
+ function Editor({ defaultValue, onChange, registry, data }) {
835
844
  const ed = useEditor(defaultValue);
836
845
  const first = react.useRef(true);
846
+ const onChangeRef = useLatestRef(onChange);
837
847
  react.useEffect(() => {
838
848
  if (first.current) {
839
849
  first.current = false;
840
850
  return;
841
851
  }
842
- onChange?.(ed.state.doc);
843
- }, [ed.state.doc, onChange]);
852
+ onChangeRef.current?.(ed.state.doc);
853
+ }, [ed.state.doc, onChangeRef]);
844
854
  const shell = {
845
855
  display: "grid",
846
856
  gridTemplateColumns: "220px 1fr 300px",
847
857
  height: "100%",
848
858
  minHeight: 0,
849
- background: "#fff",
850
- color: "#0f172a",
851
- border: "1px solid #e2e8f0",
859
+ background: "var(--fcms-bg)",
860
+ color: "var(--fcms-fg)",
861
+ border: "1px solid var(--fcms-border)",
852
862
  borderRadius: 12,
853
863
  overflow: "hidden"
854
864
  };
855
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: shell, children: [
856
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { borderRight: "1px solid #e2e8f0", display: "flex", flexDirection: "column", minHeight: 0 }, children: [
865
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "fancy-cms-editor", style: shell, children: [
866
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: CHROME_CSS }),
867
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { borderRight: "1px solid var(--fcms-border)", display: "flex", flexDirection: "column", minHeight: 0 }, children: [
857
868
  /* @__PURE__ */ jsxRuntime.jsx(Toolbar, { ed }),
858
869
  /* @__PURE__ */ jsxRuntime.jsx(
859
870
  LayersPanel,
@@ -865,8 +876,8 @@ function Editor({ defaultValue, onChange }) {
865
876
  }
866
877
  )
867
878
  ] }),
868
- /* @__PURE__ */ jsxRuntime.jsx(Canvas, { doc: ed.state.doc, selection: ed.state.selection, onSelect: ed.select, apply: ed.apply }),
869
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { borderLeft: "1px solid #e2e8f0", minHeight: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(Inspector, { doc: ed.state.doc, selection: ed.state.selection, apply: ed.apply }) })
879
+ /* @__PURE__ */ jsxRuntime.jsx(Canvas, { doc: ed.state.doc, selection: ed.state.selection, onSelect: ed.select, apply: ed.apply, registry, data }),
880
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { borderLeft: "1px solid var(--fcms-border)", minHeight: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(Inspector, { doc: ed.state.doc, selection: ed.state.selection, apply: ed.apply }) })
870
881
  ] });
871
882
  }
872
883
  function Toolbar({ ed }) {
@@ -875,8 +886,9 @@ function Toolbar({ ed }) {
875
886
  fontSize: 12,
876
887
  padding: "4px 10px",
877
888
  borderRadius: 6,
878
- border: "1px solid #e2e8f0",
879
- background: "#fff",
889
+ border: "1px solid var(--fcms-border)",
890
+ background: "var(--fcms-bg)",
891
+ color: "var(--fcms-fg)",
880
892
  cursor: "pointer"
881
893
  };
882
894
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -886,7 +898,7 @@ function Toolbar({ ed }) {
886
898
  display: "flex",
887
899
  gap: 6,
888
900
  padding: 8,
889
- borderBottom: "1px solid #e2e8f0",
901
+ borderBottom: "1px solid var(--fcms-border)",
890
902
  fontFamily: "system-ui, sans-serif"
891
903
  },
892
904
  children: [
@@ -896,6 +908,9 @@ function Toolbar({ ed }) {
896
908
  }
897
909
  );
898
910
  }
911
+ var DARK_VARS = "color-scheme:dark;--fcms-bg:#0b0f19;--fcms-fg:#e5e7eb;--fcms-muted:#94a3b8;--fcms-border:#27272a;--fcms-canvas:#0f141f;--fcms-input-bg:#111827;--fcms-row-fg:#cbd5e1;--fcms-sel-bg:color-mix(in oklab, #8b5cf6 24%, transparent);--fcms-sel-fg:#ddd6fe;";
912
+ var LIGHT_VARS = "color-scheme:light;--fcms-bg:#ffffff;--fcms-fg:#0f172a;--fcms-muted:#64748b;--fcms-border:#e2e8f0;--fcms-canvas:#f8fafc;--fcms-input-bg:#ffffff;--fcms-row-fg:#334155;--fcms-sel-bg:#ede9fe;--fcms-sel-fg:#5b21b6;";
913
+ var CHROME_CSS = `.fancy-cms-editor{--fcms-accent:#8b5cf6;${LIGHT_VARS}}@media (prefers-color-scheme:dark){.fancy-cms-editor{${DARK_VARS}}}:where(.light,[data-theme="light"]) .fancy-cms-editor{${LIGHT_VARS}}:where(.dark,[data-theme="dark"]) .fancy-cms-editor{${DARK_VARS}}`;
899
914
 
900
915
  exports.Canvas = Canvas;
901
916
  exports.CmsPage = CmsPage;