@tecof/theme-editor 0.0.12 → 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.d.mts CHANGED
@@ -144,6 +144,10 @@ interface LinkFieldValue {
144
144
  target?: '_self' | '_blank';
145
145
  type?: 'page' | 'custom';
146
146
  }
147
+ interface LocalizedLinkFieldValue {
148
+ code: string;
149
+ value: LinkFieldValue;
150
+ }
147
151
 
148
152
  /**
149
153
  * Tecof API Client — handles communication with the Tecof backend
@@ -475,8 +479,8 @@ interface LinkFieldProps {
475
479
  field: any;
476
480
  name: string;
477
481
  id: string;
478
- value: LinkFieldValue | null;
479
- onChange: (value: LinkFieldValue | null) => void;
482
+ value: LocalizedLinkFieldValue[] | null;
483
+ onChange: (value: LocalizedLinkFieldValue[] | null) => void;
480
484
  readOnly?: boolean;
481
485
  }
482
486
  interface LinkFieldOptions {
package/dist/index.d.ts CHANGED
@@ -144,6 +144,10 @@ interface LinkFieldValue {
144
144
  target?: '_self' | '_blank';
145
145
  type?: 'page' | 'custom';
146
146
  }
147
+ interface LocalizedLinkFieldValue {
148
+ code: string;
149
+ value: LinkFieldValue;
150
+ }
147
151
 
148
152
  /**
149
153
  * Tecof API Client — handles communication with the Tecof backend
@@ -475,8 +479,8 @@ interface LinkFieldProps {
475
479
  field: any;
476
480
  name: string;
477
481
  id: string;
478
- value: LinkFieldValue | null;
479
- onChange: (value: LinkFieldValue | null) => void;
482
+ value: LocalizedLinkFieldValue[] | null;
483
+ onChange: (value: LocalizedLinkFieldValue[] | null) => void;
480
484
  readOnly?: boolean;
481
485
  }
482
486
  interface LinkFieldOptions {
package/dist/index.js CHANGED
@@ -23473,9 +23473,15 @@ var CodeEditorField = React__default.forwardRef(({
23473
23473
  theme = "vs-dark"
23474
23474
  }, ref) => {
23475
23475
  const editorRef = React__default.useRef(null);
23476
- const handleEditorDidMount = (editor2) => {
23476
+ const onChangeRef = React__default.useRef(onChange);
23477
+ onChangeRef.current = onChange;
23478
+ const handleEditorDidMount = React__default.useCallback((editor2) => {
23477
23479
  editorRef.current = editor2;
23478
- };
23480
+ editor2.onDidChangeModelContent(() => {
23481
+ const newValue = editor2.getValue();
23482
+ onChangeRef.current(newValue);
23483
+ });
23484
+ }, []);
23479
23485
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: "tecof-code-editor-container", children: /* @__PURE__ */ jsxRuntime.jsx(
23480
23486
  Ft,
23481
23487
  {
@@ -23484,8 +23490,7 @@ var CodeEditorField = React__default.forwardRef(({
23484
23490
  width: "100%",
23485
23491
  height,
23486
23492
  defaultLanguage,
23487
- value: value || "",
23488
- onChange: (val) => onChange(val || ""),
23493
+ defaultValue: value || "",
23489
23494
  options: {
23490
23495
  readOnly,
23491
23496
  minimap: { enabled: false },
@@ -23527,6 +23532,7 @@ var LinkField = ({
23527
23532
  placeholder = "https://..."
23528
23533
  }) => {
23529
23534
  const { apiClient } = useTecof();
23535
+ const { merchantInfo, loading: langLoading, activeTab, setActiveTab } = useLanguages();
23530
23536
  const [drawerOpen, setDrawerOpen] = React__default.useState(false);
23531
23537
  const [pages, setPages] = React__default.useState([]);
23532
23538
  const [loading, setLoading] = React__default.useState(false);
@@ -23535,6 +23541,30 @@ var LinkField = ({
23535
23541
  const [manualUrl, setManualUrl] = React__default.useState("");
23536
23542
  const [manualLabel, setManualLabel] = React__default.useState("");
23537
23543
  const [manualTarget, setManualTarget] = React__default.useState("_self");
23544
+ const values = React__default.useMemo(() => {
23545
+ if (!merchantInfo) return value || [];
23546
+ const current = value || [];
23547
+ return merchantInfo.languages.map((code) => {
23548
+ const existing = current.find((v2) => v2.code === code);
23549
+ return existing || { code, value: { url: "" } };
23550
+ });
23551
+ }, [value, merchantInfo]);
23552
+ const activeValueItem = values.find((v2) => v2.code === activeTab);
23553
+ const activeValue = activeValueItem?.value || { url: "" };
23554
+ const updateActiveValue = React__default.useCallback((newLinkVal) => {
23555
+ const updated = [...values];
23556
+ const idx = updated.findIndex((v2) => v2.code === activeTab);
23557
+ if (idx >= 0) {
23558
+ if (newLinkVal) {
23559
+ updated[idx] = { ...updated[idx], value: newLinkVal };
23560
+ } else {
23561
+ updated[idx] = { ...updated[idx], value: { url: "" } };
23562
+ }
23563
+ } else if (newLinkVal) {
23564
+ updated.push({ code: activeTab, value: newLinkVal });
23565
+ }
23566
+ onChange(updated);
23567
+ }, [values, activeTab, onChange]);
23538
23568
  React__default.useEffect(() => {
23539
23569
  if (!drawerOpen) return;
23540
23570
  setLoading(true);
@@ -23549,17 +23579,17 @@ var LinkField = ({
23549
23579
  (p) => p.slug?.toLowerCase().includes(search.toLowerCase()) || p.title?.toLowerCase().includes(search.toLowerCase())
23550
23580
  ) : pages;
23551
23581
  const handleSelectPage = React__default.useCallback((page) => {
23552
- onChange({
23582
+ updateActiveValue({
23553
23583
  url: `/${page.slug}`,
23554
23584
  label: page.title || page.slug,
23555
23585
  target: "_self",
23556
23586
  type: "page"
23557
23587
  });
23558
23588
  setDrawerOpen(false);
23559
- }, [onChange]);
23589
+ }, [updateActiveValue]);
23560
23590
  const handleConfirmManual = React__default.useCallback(() => {
23561
23591
  if (!manualUrl.trim()) return;
23562
- onChange({
23592
+ updateActiveValue({
23563
23593
  url: manualUrl.trim(),
23564
23594
  label: manualLabel.trim() || manualUrl.trim(),
23565
23595
  target: manualTarget,
@@ -23568,28 +23598,42 @@ var LinkField = ({
23568
23598
  setShowManual(false);
23569
23599
  setManualUrl("");
23570
23600
  setManualLabel("");
23571
- }, [manualUrl, manualLabel, manualTarget, onChange]);
23601
+ }, [manualUrl, manualLabel, manualTarget, updateActiveValue]);
23572
23602
  const handleClear = React__default.useCallback(() => {
23573
- onChange(null);
23574
- }, [onChange]);
23603
+ updateActiveValue(null);
23604
+ }, [updateActiveValue]);
23575
23605
  const handleEditManual = React__default.useCallback(() => {
23576
- if (value) {
23577
- setManualUrl(value.url || "");
23578
- setManualLabel(value.label || "");
23579
- setManualTarget(value.target || "_self");
23606
+ if (activeValue && activeValue.url) {
23607
+ setManualUrl(activeValue.url || "");
23608
+ setManualLabel(activeValue.label || "");
23609
+ setManualTarget(activeValue.target || "_self");
23610
+ } else {
23611
+ setManualUrl("");
23612
+ setManualLabel("");
23613
+ setManualTarget("_self");
23580
23614
  }
23581
23615
  setShowManual(true);
23582
- }, [value]);
23583
- const hasValue = value && value.url;
23616
+ }, [activeValue]);
23617
+ const hasValue = activeValue && activeValue.url && activeValue.url !== "";
23584
23618
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tecof-link-container", children: [
23619
+ merchantInfo && merchantInfo.languages.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
23620
+ LanguageTabBar,
23621
+ {
23622
+ languages: merchantInfo.languages,
23623
+ defaultLanguage: merchantInfo.defaultLanguage,
23624
+ activeTab,
23625
+ onTabChange: setActiveTab
23626
+ }
23627
+ ),
23628
+ langLoading && /* @__PURE__ */ jsxRuntime.jsx(FieldLoading, {}),
23585
23629
  hasValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tecof-link-value-box", children: [
23586
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tecof-link-value-icon", children: value.type === "page" ? /* @__PURE__ */ jsxRuntime.jsx(FileText, { size: 16 }) : /* @__PURE__ */ jsxRuntime.jsx(Globe, { size: 16 }) }),
23630
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tecof-link-value-icon", children: activeValue.type === "page" ? /* @__PURE__ */ jsxRuntime.jsx(FileText, { size: 16 }) : /* @__PURE__ */ jsxRuntime.jsx(Globe, { size: 16 }) }),
23587
23631
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tecof-link-value-info", children: [
23588
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-label", children: value.label || value.url }),
23589
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-url", children: value.url })
23632
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-label", children: activeValue.label || activeValue.url }),
23633
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-url", children: activeValue.url })
23590
23634
  ] }),
23591
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: `tecof-link-value-badge ${value.type === "page" ? "tecof-link-badge-page" : "tecof-link-badge-custom"}`, children: value.type === "page" ? "Sayfa" : "Link" }),
23592
- value.target === "_blank" && /* @__PURE__ */ jsxRuntime.jsx(ExternalLink, { size: 14, color: "#a1a1aa" }),
23635
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: `tecof-link-value-badge ${activeValue.type === "page" ? "tecof-link-badge-page" : "tecof-link-badge-custom"}`, children: activeValue.type === "page" ? "Sayfa" : "Link" }),
23636
+ activeValue.target === "_blank" && /* @__PURE__ */ jsxRuntime.jsx(ExternalLink, { size: 14, color: "#a1a1aa" }),
23593
23637
  !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
23594
23638
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "tecof-link-action-btn-small", onClick: handleEditManual, title: "D\xFCzenle", children: /* @__PURE__ */ jsxRuntime.jsx(Pencil, { size: 14 }) }),
23595
23639
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "tecof-link-action-btn-small", onClick: handleClear, title: "Kald\u0131r", children: /* @__PURE__ */ jsxRuntime.jsx(X, { size: 14 }) })
@@ -23675,7 +23719,7 @@ var LinkField = ({
23675
23719
  )
23676
23720
  ] }),
23677
23721
  loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tecof-text-center tecof-p-40 tecof-text-muted", children: "Y\xFCkleniyor..." }) : filteredPages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tecof-text-center tecof-p-40 tecof-text-muted", children: search ? "Sonu\xE7 bulunamad\u0131" : "Hen\xFCz sayfa yok" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tecof-link-page-list", children: filteredPages.map((page) => {
23678
- const selected = value?.url === `/${page.slug}`;
23722
+ const selected = activeValue?.url === `/${page.slug}`;
23679
23723
  return /* @__PURE__ */ jsxRuntime.jsxs(
23680
23724
  "div",
23681
23725
  {
@@ -23714,7 +23758,7 @@ var createLinkField = (options = {}) => {
23714
23758
  field,
23715
23759
  name: name3,
23716
23760
  id,
23717
- value: value || { url: "" },
23761
+ value: value || [],
23718
23762
  onChange,
23719
23763
  readOnly,
23720
23764
  ...fieldOptions