@tecof/theme-editor 0.0.11 → 0.0.13

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
@@ -157,7 +161,8 @@ interface LinkFieldValue {
157
161
  declare class TecofApiClient {
158
162
  private apiUrl;
159
163
  private secretKey;
160
- constructor(apiUrl: string, secretKey: string);
164
+ private customCdnUrl?;
165
+ constructor(apiUrl: string, secretKey: string, customCdnUrl?: string);
161
166
  private get headers();
162
167
  /**
163
168
  * Fetch a page by ID (for the editor)
@@ -197,7 +202,7 @@ declare class TecofApiClient {
197
202
  code: string;
198
203
  value: string;
199
204
  }[]>>;
200
- /** CDN base URL (derived from apiUrl) */
205
+ /** CDN base URL (defaults to apiUrl if not set) */
201
206
  get cdnUrl(): string;
202
207
  }
203
208
 
@@ -205,8 +210,9 @@ interface TecofContextValue {
205
210
  apiClient: TecofApiClient;
206
211
  secretKey: string;
207
212
  apiUrl: string;
213
+ cdnUrl?: string;
208
214
  }
209
- declare const TecofProvider: ({ apiUrl, secretKey, children }: TecofProviderProps) => react_jsx_runtime.JSX.Element;
215
+ declare const TecofProvider: ({ apiUrl, secretKey, cdnUrl, children }: TecofProviderProps) => react_jsx_runtime.JSX.Element;
210
216
  declare function useTecof(): TecofContextValue;
211
217
 
212
218
  /**
@@ -473,8 +479,8 @@ interface LinkFieldProps {
473
479
  field: any;
474
480
  name: string;
475
481
  id: string;
476
- value: LinkFieldValue | null;
477
- onChange: (value: LinkFieldValue | null) => void;
482
+ value: LocalizedLinkFieldValue[] | null;
483
+ onChange: (value: LocalizedLinkFieldValue[] | null) => void;
478
484
  readOnly?: boolean;
479
485
  }
480
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
@@ -157,7 +161,8 @@ interface LinkFieldValue {
157
161
  declare class TecofApiClient {
158
162
  private apiUrl;
159
163
  private secretKey;
160
- constructor(apiUrl: string, secretKey: string);
164
+ private customCdnUrl?;
165
+ constructor(apiUrl: string, secretKey: string, customCdnUrl?: string);
161
166
  private get headers();
162
167
  /**
163
168
  * Fetch a page by ID (for the editor)
@@ -197,7 +202,7 @@ declare class TecofApiClient {
197
202
  code: string;
198
203
  value: string;
199
204
  }[]>>;
200
- /** CDN base URL (derived from apiUrl) */
205
+ /** CDN base URL (defaults to apiUrl if not set) */
201
206
  get cdnUrl(): string;
202
207
  }
203
208
 
@@ -205,8 +210,9 @@ interface TecofContextValue {
205
210
  apiClient: TecofApiClient;
206
211
  secretKey: string;
207
212
  apiUrl: string;
213
+ cdnUrl?: string;
208
214
  }
209
- declare const TecofProvider: ({ apiUrl, secretKey, children }: TecofProviderProps) => react_jsx_runtime.JSX.Element;
215
+ declare const TecofProvider: ({ apiUrl, secretKey, cdnUrl, children }: TecofProviderProps) => react_jsx_runtime.JSX.Element;
210
216
  declare function useTecof(): TecofContextValue;
211
217
 
212
218
  /**
@@ -473,8 +479,8 @@ interface LinkFieldProps {
473
479
  field: any;
474
480
  name: string;
475
481
  id: string;
476
- value: LinkFieldValue | null;
477
- onChange: (value: LinkFieldValue | null) => void;
482
+ value: LocalizedLinkFieldValue[] | null;
483
+ onChange: (value: LocalizedLinkFieldValue[] | null) => void;
478
484
  readOnly?: boolean;
479
485
  }
480
486
  interface LinkFieldOptions {
package/dist/index.js CHANGED
@@ -64,9 +64,10 @@ var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
64
64
 
65
65
  // src/api.ts
66
66
  var TecofApiClient = class {
67
- constructor(apiUrl, secretKey) {
67
+ constructor(apiUrl, secretKey, customCdnUrl) {
68
68
  this.apiUrl = apiUrl.replace(/\/+$/, "");
69
69
  this.secretKey = secretKey;
70
+ this.customCdnUrl = customCdnUrl ? customCdnUrl.replace(/\/+$/, "") : void 0;
70
71
  }
71
72
  get headers() {
72
73
  return {
@@ -227,20 +228,21 @@ var TecofApiClient = class {
227
228
  };
228
229
  }
229
230
  }
230
- /** CDN base URL (derived from apiUrl) */
231
+ /** CDN base URL (defaults to apiUrl if not set) */
231
232
  get cdnUrl() {
232
- return this.apiUrl;
233
+ return this.customCdnUrl || this.apiUrl;
233
234
  }
234
235
  };
235
236
  var TecofContext = React__default.createContext(null);
236
- var TecofProvider = ({ apiUrl, secretKey, children }) => {
237
+ var TecofProvider = ({ apiUrl, secretKey, cdnUrl, children }) => {
237
238
  const value = React__default.useMemo(
238
239
  () => ({
239
- apiClient: new TecofApiClient(apiUrl, secretKey),
240
+ apiClient: new TecofApiClient(apiUrl, secretKey, cdnUrl),
240
241
  secretKey,
241
- apiUrl
242
+ apiUrl,
243
+ cdnUrl
242
244
  }),
243
- [apiUrl, secretKey]
245
+ [apiUrl, secretKey, cdnUrl]
244
246
  );
245
247
  return /* @__PURE__ */ jsxRuntime.jsx(TecofContext.Provider, { value, children });
246
248
  };
@@ -22348,8 +22350,9 @@ var FileItemRenderer = ({
22348
22350
  data: file2,
22349
22351
  alt: file2.meta?.originalName || file2.name,
22350
22352
  size: "thumbnail",
22353
+ fill: true,
22351
22354
  className: "tecof-upload-file-thumb",
22352
- imgStyle: { width: "100%", height: "100%", objectFit: "cover", borderRadius: "10px" }
22355
+ imgStyle: { objectFit: "cover", borderRadius: "10px" }
22353
22356
  }
22354
22357
  ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tecof-upload-file-icon", children: /* @__PURE__ */ jsxRuntime.jsx(File2, { size: 20 }) }),
22355
22358
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tecof-upload-file-info", children: [
@@ -22791,8 +22794,9 @@ var UploadField = ({
22791
22794
  data: file2,
22792
22795
  alt: file2.name,
22793
22796
  size: "thumbnail",
22797
+ fill: true,
22794
22798
  className: "tecof-upload-gallery-thumb",
22795
- imgStyle: { width: "100%", height: "100%", objectFit: "cover", borderRadius: "6px" }
22799
+ imgStyle: { objectFit: "cover", borderRadius: "6px" }
22796
22800
  }
22797
22801
  ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tecof-upload-gallery-thumb tecof-upload-gallery-file-icon-wrap", children: /* @__PURE__ */ jsxRuntime.jsx(File2, { size: 24, color: "#a1a1aa" }) }),
22798
22802
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-upload-gallery-file-name", children: file2.meta?.originalName || file2.name })
@@ -23525,6 +23529,7 @@ var LinkField = ({
23525
23529
  placeholder = "https://..."
23526
23530
  }) => {
23527
23531
  const { apiClient } = useTecof();
23532
+ const { merchantInfo, loading: langLoading, activeTab, setActiveTab } = useLanguages();
23528
23533
  const [drawerOpen, setDrawerOpen] = React__default.useState(false);
23529
23534
  const [pages, setPages] = React__default.useState([]);
23530
23535
  const [loading, setLoading] = React__default.useState(false);
@@ -23533,6 +23538,30 @@ var LinkField = ({
23533
23538
  const [manualUrl, setManualUrl] = React__default.useState("");
23534
23539
  const [manualLabel, setManualLabel] = React__default.useState("");
23535
23540
  const [manualTarget, setManualTarget] = React__default.useState("_self");
23541
+ const values = React__default.useMemo(() => {
23542
+ if (!merchantInfo) return value || [];
23543
+ const current = value || [];
23544
+ return merchantInfo.languages.map((code) => {
23545
+ const existing = current.find((v2) => v2.code === code);
23546
+ return existing || { code, value: { url: "" } };
23547
+ });
23548
+ }, [value, merchantInfo]);
23549
+ const activeValueItem = values.find((v2) => v2.code === activeTab);
23550
+ const activeValue = activeValueItem?.value || { url: "" };
23551
+ const updateActiveValue = React__default.useCallback((newLinkVal) => {
23552
+ const updated = [...values];
23553
+ const idx = updated.findIndex((v2) => v2.code === activeTab);
23554
+ if (idx >= 0) {
23555
+ if (newLinkVal) {
23556
+ updated[idx] = { ...updated[idx], value: newLinkVal };
23557
+ } else {
23558
+ updated[idx] = { ...updated[idx], value: { url: "" } };
23559
+ }
23560
+ } else if (newLinkVal) {
23561
+ updated.push({ code: activeTab, value: newLinkVal });
23562
+ }
23563
+ onChange(updated);
23564
+ }, [values, activeTab, onChange]);
23536
23565
  React__default.useEffect(() => {
23537
23566
  if (!drawerOpen) return;
23538
23567
  setLoading(true);
@@ -23547,17 +23576,17 @@ var LinkField = ({
23547
23576
  (p) => p.slug?.toLowerCase().includes(search.toLowerCase()) || p.title?.toLowerCase().includes(search.toLowerCase())
23548
23577
  ) : pages;
23549
23578
  const handleSelectPage = React__default.useCallback((page) => {
23550
- onChange({
23579
+ updateActiveValue({
23551
23580
  url: `/${page.slug}`,
23552
23581
  label: page.title || page.slug,
23553
23582
  target: "_self",
23554
23583
  type: "page"
23555
23584
  });
23556
23585
  setDrawerOpen(false);
23557
- }, [onChange]);
23586
+ }, [updateActiveValue]);
23558
23587
  const handleConfirmManual = React__default.useCallback(() => {
23559
23588
  if (!manualUrl.trim()) return;
23560
- onChange({
23589
+ updateActiveValue({
23561
23590
  url: manualUrl.trim(),
23562
23591
  label: manualLabel.trim() || manualUrl.trim(),
23563
23592
  target: manualTarget,
@@ -23566,28 +23595,42 @@ var LinkField = ({
23566
23595
  setShowManual(false);
23567
23596
  setManualUrl("");
23568
23597
  setManualLabel("");
23569
- }, [manualUrl, manualLabel, manualTarget, onChange]);
23598
+ }, [manualUrl, manualLabel, manualTarget, updateActiveValue]);
23570
23599
  const handleClear = React__default.useCallback(() => {
23571
- onChange(null);
23572
- }, [onChange]);
23600
+ updateActiveValue(null);
23601
+ }, [updateActiveValue]);
23573
23602
  const handleEditManual = React__default.useCallback(() => {
23574
- if (value) {
23575
- setManualUrl(value.url || "");
23576
- setManualLabel(value.label || "");
23577
- setManualTarget(value.target || "_self");
23603
+ if (activeValue && activeValue.url) {
23604
+ setManualUrl(activeValue.url || "");
23605
+ setManualLabel(activeValue.label || "");
23606
+ setManualTarget(activeValue.target || "_self");
23607
+ } else {
23608
+ setManualUrl("");
23609
+ setManualLabel("");
23610
+ setManualTarget("_self");
23578
23611
  }
23579
23612
  setShowManual(true);
23580
- }, [value]);
23581
- const hasValue = value && value.url;
23613
+ }, [activeValue]);
23614
+ const hasValue = activeValue && activeValue.url && activeValue.url !== "";
23582
23615
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tecof-link-container", children: [
23616
+ merchantInfo && merchantInfo.languages.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
23617
+ LanguageTabBar,
23618
+ {
23619
+ languages: merchantInfo.languages,
23620
+ defaultLanguage: merchantInfo.defaultLanguage,
23621
+ activeTab,
23622
+ onTabChange: setActiveTab
23623
+ }
23624
+ ),
23625
+ langLoading && /* @__PURE__ */ jsxRuntime.jsx(FieldLoading, {}),
23583
23626
  hasValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tecof-link-value-box", children: [
23584
- /* @__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 }) }),
23627
+ /* @__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 }) }),
23585
23628
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tecof-link-value-info", children: [
23586
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-label", children: value.label || value.url }),
23587
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-url", children: value.url })
23629
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-label", children: activeValue.label || activeValue.url }),
23630
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tecof-link-value-url", children: activeValue.url })
23588
23631
  ] }),
23589
- /* @__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" }),
23590
- value.target === "_blank" && /* @__PURE__ */ jsxRuntime.jsx(ExternalLink, { size: 14, color: "#a1a1aa" }),
23632
+ /* @__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" }),
23633
+ activeValue.target === "_blank" && /* @__PURE__ */ jsxRuntime.jsx(ExternalLink, { size: 14, color: "#a1a1aa" }),
23591
23634
  !readOnly && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
23592
23635
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "tecof-link-action-btn-small", onClick: handleEditManual, title: "D\xFCzenle", children: /* @__PURE__ */ jsxRuntime.jsx(Pencil, { size: 14 }) }),
23593
23636
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "tecof-link-action-btn-small", onClick: handleClear, title: "Kald\u0131r", children: /* @__PURE__ */ jsxRuntime.jsx(X, { size: 14 }) })
@@ -23673,7 +23716,7 @@ var LinkField = ({
23673
23716
  )
23674
23717
  ] }),
23675
23718
  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) => {
23676
- const selected = value?.url === `/${page.slug}`;
23719
+ const selected = activeValue?.url === `/${page.slug}`;
23677
23720
  return /* @__PURE__ */ jsxRuntime.jsxs(
23678
23721
  "div",
23679
23722
  {
@@ -23712,7 +23755,7 @@ var createLinkField = (options = {}) => {
23712
23755
  field,
23713
23756
  name: name3,
23714
23757
  id,
23715
- value: value || { url: "" },
23758
+ value: value || [],
23716
23759
  onChange,
23717
23760
  readOnly,
23718
23761
  ...fieldOptions