@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 +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +67 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -24
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +26 -3
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React__default from 'react';
|
|
2
|
-
import React__default__default, { createContext, memo, forwardRef, createElement, useRef, useContext, useState,
|
|
2
|
+
import React__default__default, { createContext, memo, forwardRef, createElement, useRef, useCallback, useContext, useState, useEffect, useMemo, useLayoutEffect } from 'react';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { fieldsPlugin, Puck, Render, FieldLabel } from '@puckeditor/core';
|
|
5
5
|
import { useEditor, EditorContent } from '@tiptap/react';
|
|
@@ -23435,9 +23435,15 @@ var CodeEditorField = forwardRef(({
|
|
|
23435
23435
|
theme = "vs-dark"
|
|
23436
23436
|
}, ref) => {
|
|
23437
23437
|
const editorRef = useRef(null);
|
|
23438
|
-
const
|
|
23438
|
+
const onChangeRef = useRef(onChange);
|
|
23439
|
+
onChangeRef.current = onChange;
|
|
23440
|
+
const handleEditorDidMount = useCallback((editor2) => {
|
|
23439
23441
|
editorRef.current = editor2;
|
|
23440
|
-
|
|
23442
|
+
editor2.onDidChangeModelContent(() => {
|
|
23443
|
+
const newValue = editor2.getValue();
|
|
23444
|
+
onChangeRef.current(newValue);
|
|
23445
|
+
});
|
|
23446
|
+
}, []);
|
|
23441
23447
|
return /* @__PURE__ */ jsx("div", { ref, className: "tecof-code-editor-container", children: /* @__PURE__ */ jsx(
|
|
23442
23448
|
Ft,
|
|
23443
23449
|
{
|
|
@@ -23446,8 +23452,7 @@ var CodeEditorField = forwardRef(({
|
|
|
23446
23452
|
width: "100%",
|
|
23447
23453
|
height,
|
|
23448
23454
|
defaultLanguage,
|
|
23449
|
-
|
|
23450
|
-
onChange: (val) => onChange(val || ""),
|
|
23455
|
+
defaultValue: value || "",
|
|
23451
23456
|
options: {
|
|
23452
23457
|
readOnly,
|
|
23453
23458
|
minimap: { enabled: false },
|
|
@@ -23489,6 +23494,7 @@ var LinkField = ({
|
|
|
23489
23494
|
placeholder = "https://..."
|
|
23490
23495
|
}) => {
|
|
23491
23496
|
const { apiClient } = useTecof();
|
|
23497
|
+
const { merchantInfo, loading: langLoading, activeTab, setActiveTab } = useLanguages();
|
|
23492
23498
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
23493
23499
|
const [pages, setPages] = useState([]);
|
|
23494
23500
|
const [loading, setLoading] = useState(false);
|
|
@@ -23497,6 +23503,30 @@ var LinkField = ({
|
|
|
23497
23503
|
const [manualUrl, setManualUrl] = useState("");
|
|
23498
23504
|
const [manualLabel, setManualLabel] = useState("");
|
|
23499
23505
|
const [manualTarget, setManualTarget] = useState("_self");
|
|
23506
|
+
const values = useMemo(() => {
|
|
23507
|
+
if (!merchantInfo) return value || [];
|
|
23508
|
+
const current = value || [];
|
|
23509
|
+
return merchantInfo.languages.map((code) => {
|
|
23510
|
+
const existing = current.find((v2) => v2.code === code);
|
|
23511
|
+
return existing || { code, value: { url: "" } };
|
|
23512
|
+
});
|
|
23513
|
+
}, [value, merchantInfo]);
|
|
23514
|
+
const activeValueItem = values.find((v2) => v2.code === activeTab);
|
|
23515
|
+
const activeValue = activeValueItem?.value || { url: "" };
|
|
23516
|
+
const updateActiveValue = useCallback((newLinkVal) => {
|
|
23517
|
+
const updated = [...values];
|
|
23518
|
+
const idx = updated.findIndex((v2) => v2.code === activeTab);
|
|
23519
|
+
if (idx >= 0) {
|
|
23520
|
+
if (newLinkVal) {
|
|
23521
|
+
updated[idx] = { ...updated[idx], value: newLinkVal };
|
|
23522
|
+
} else {
|
|
23523
|
+
updated[idx] = { ...updated[idx], value: { url: "" } };
|
|
23524
|
+
}
|
|
23525
|
+
} else if (newLinkVal) {
|
|
23526
|
+
updated.push({ code: activeTab, value: newLinkVal });
|
|
23527
|
+
}
|
|
23528
|
+
onChange(updated);
|
|
23529
|
+
}, [values, activeTab, onChange]);
|
|
23500
23530
|
useEffect(() => {
|
|
23501
23531
|
if (!drawerOpen) return;
|
|
23502
23532
|
setLoading(true);
|
|
@@ -23511,17 +23541,17 @@ var LinkField = ({
|
|
|
23511
23541
|
(p) => p.slug?.toLowerCase().includes(search.toLowerCase()) || p.title?.toLowerCase().includes(search.toLowerCase())
|
|
23512
23542
|
) : pages;
|
|
23513
23543
|
const handleSelectPage = useCallback((page) => {
|
|
23514
|
-
|
|
23544
|
+
updateActiveValue({
|
|
23515
23545
|
url: `/${page.slug}`,
|
|
23516
23546
|
label: page.title || page.slug,
|
|
23517
23547
|
target: "_self",
|
|
23518
23548
|
type: "page"
|
|
23519
23549
|
});
|
|
23520
23550
|
setDrawerOpen(false);
|
|
23521
|
-
}, [
|
|
23551
|
+
}, [updateActiveValue]);
|
|
23522
23552
|
const handleConfirmManual = useCallback(() => {
|
|
23523
23553
|
if (!manualUrl.trim()) return;
|
|
23524
|
-
|
|
23554
|
+
updateActiveValue({
|
|
23525
23555
|
url: manualUrl.trim(),
|
|
23526
23556
|
label: manualLabel.trim() || manualUrl.trim(),
|
|
23527
23557
|
target: manualTarget,
|
|
@@ -23530,28 +23560,42 @@ var LinkField = ({
|
|
|
23530
23560
|
setShowManual(false);
|
|
23531
23561
|
setManualUrl("");
|
|
23532
23562
|
setManualLabel("");
|
|
23533
|
-
}, [manualUrl, manualLabel, manualTarget,
|
|
23563
|
+
}, [manualUrl, manualLabel, manualTarget, updateActiveValue]);
|
|
23534
23564
|
const handleClear = useCallback(() => {
|
|
23535
|
-
|
|
23536
|
-
}, [
|
|
23565
|
+
updateActiveValue(null);
|
|
23566
|
+
}, [updateActiveValue]);
|
|
23537
23567
|
const handleEditManual = useCallback(() => {
|
|
23538
|
-
if (
|
|
23539
|
-
setManualUrl(
|
|
23540
|
-
setManualLabel(
|
|
23541
|
-
setManualTarget(
|
|
23568
|
+
if (activeValue && activeValue.url) {
|
|
23569
|
+
setManualUrl(activeValue.url || "");
|
|
23570
|
+
setManualLabel(activeValue.label || "");
|
|
23571
|
+
setManualTarget(activeValue.target || "_self");
|
|
23572
|
+
} else {
|
|
23573
|
+
setManualUrl("");
|
|
23574
|
+
setManualLabel("");
|
|
23575
|
+
setManualTarget("_self");
|
|
23542
23576
|
}
|
|
23543
23577
|
setShowManual(true);
|
|
23544
|
-
}, [
|
|
23545
|
-
const hasValue =
|
|
23578
|
+
}, [activeValue]);
|
|
23579
|
+
const hasValue = activeValue && activeValue.url && activeValue.url !== "";
|
|
23546
23580
|
return /* @__PURE__ */ jsxs("div", { className: "tecof-link-container", children: [
|
|
23581
|
+
merchantInfo && merchantInfo.languages.length > 1 && /* @__PURE__ */ jsx(
|
|
23582
|
+
LanguageTabBar,
|
|
23583
|
+
{
|
|
23584
|
+
languages: merchantInfo.languages,
|
|
23585
|
+
defaultLanguage: merchantInfo.defaultLanguage,
|
|
23586
|
+
activeTab,
|
|
23587
|
+
onTabChange: setActiveTab
|
|
23588
|
+
}
|
|
23589
|
+
),
|
|
23590
|
+
langLoading && /* @__PURE__ */ jsx(FieldLoading, {}),
|
|
23547
23591
|
hasValue && /* @__PURE__ */ jsxs("div", { className: "tecof-link-value-box", children: [
|
|
23548
|
-
/* @__PURE__ */ jsx("div", { className: "tecof-link-value-icon", children:
|
|
23592
|
+
/* @__PURE__ */ jsx("div", { className: "tecof-link-value-icon", children: activeValue.type === "page" ? /* @__PURE__ */ jsx(FileText, { size: 16 }) : /* @__PURE__ */ jsx(Globe, { size: 16 }) }),
|
|
23549
23593
|
/* @__PURE__ */ jsxs("div", { className: "tecof-link-value-info", children: [
|
|
23550
|
-
/* @__PURE__ */ jsx("p", { className: "tecof-link-value-label", children:
|
|
23551
|
-
/* @__PURE__ */ jsx("p", { className: "tecof-link-value-url", children:
|
|
23594
|
+
/* @__PURE__ */ jsx("p", { className: "tecof-link-value-label", children: activeValue.label || activeValue.url }),
|
|
23595
|
+
/* @__PURE__ */ jsx("p", { className: "tecof-link-value-url", children: activeValue.url })
|
|
23552
23596
|
] }),
|
|
23553
|
-
/* @__PURE__ */ jsx("span", { className: `tecof-link-value-badge ${
|
|
23554
|
-
|
|
23597
|
+
/* @__PURE__ */ jsx("span", { className: `tecof-link-value-badge ${activeValue.type === "page" ? "tecof-link-badge-page" : "tecof-link-badge-custom"}`, children: activeValue.type === "page" ? "Sayfa" : "Link" }),
|
|
23598
|
+
activeValue.target === "_blank" && /* @__PURE__ */ jsx(ExternalLink, { size: 14, color: "#a1a1aa" }),
|
|
23555
23599
|
!readOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
23556
23600
|
/* @__PURE__ */ jsx("button", { type: "button", className: "tecof-link-action-btn-small", onClick: handleEditManual, title: "D\xFCzenle", children: /* @__PURE__ */ jsx(Pencil, { size: 14 }) }),
|
|
23557
23601
|
/* @__PURE__ */ jsx("button", { type: "button", className: "tecof-link-action-btn-small", onClick: handleClear, title: "Kald\u0131r", children: /* @__PURE__ */ jsx(X, { size: 14 }) })
|
|
@@ -23637,7 +23681,7 @@ var LinkField = ({
|
|
|
23637
23681
|
)
|
|
23638
23682
|
] }),
|
|
23639
23683
|
loading ? /* @__PURE__ */ jsx("div", { className: "tecof-text-center tecof-p-40 tecof-text-muted", children: "Y\xFCkleniyor..." }) : filteredPages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "tecof-text-center tecof-p-40 tecof-text-muted", children: search ? "Sonu\xE7 bulunamad\u0131" : "Hen\xFCz sayfa yok" }) : /* @__PURE__ */ jsx("div", { className: "tecof-link-page-list", children: filteredPages.map((page) => {
|
|
23640
|
-
const selected =
|
|
23684
|
+
const selected = activeValue?.url === `/${page.slug}`;
|
|
23641
23685
|
return /* @__PURE__ */ jsxs(
|
|
23642
23686
|
"div",
|
|
23643
23687
|
{
|
|
@@ -23676,7 +23720,7 @@ var createLinkField = (options = {}) => {
|
|
|
23676
23720
|
field,
|
|
23677
23721
|
name: name3,
|
|
23678
23722
|
id,
|
|
23679
|
-
value: value ||
|
|
23723
|
+
value: value || [],
|
|
23680
23724
|
onChange,
|
|
23681
23725
|
readOnly,
|
|
23682
23726
|
...fieldOptions
|