@tecof/theme-editor 0.0.24 → 0.0.26

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
@@ -1,5 +1,5 @@
1
1
  import * as React__default from 'react';
2
- import React__default__default, { createContext, memo, forwardRef, createElement, useRef, useCallback, useContext, useState, useEffect, useMemo, useLayoutEffect } from 'react';
2
+ import React__default__default, { createContext, memo, forwardRef, createElement, useRef, useCallback, useContext, useState, useEffect, useMemo, Component, 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';
@@ -507,8 +507,9 @@ var TecofPicture = memo(({
507
507
  const { apiClient } = useTecof();
508
508
  const cdnUrl = apiClient.cdnUrl;
509
509
  if (!data3) return null;
510
+ const buildPath = (fileName) => data3?.folder && data3.folder !== "/" ? `${data3.folder.replace(/^\//, "")}/${fileName}` : fileName;
510
511
  const isExternal = data3?.type === "external" || data3?.provider === "external";
511
- const fileURL = isExternal ? data3?.url || "" : `${cdnUrl}/${data3?.name}`;
512
+ const fileURL = isExternal ? data3?.url || "" : `${cdnUrl}/${buildPath(data3?.name)}`;
512
513
  const isImageType2 = isExternal ? true : isImage(data3?.type);
513
514
  const isVideoType = isExternal ? false : isVideo(data3?.type);
514
515
  if (!fileURL) return null;
@@ -703,7 +704,7 @@ var Icon = forwardRef(
703
704
 
704
705
  // node_modules/lucide-react/dist/esm/createLucideIcon.js
705
706
  var createLucideIcon = (iconName, iconNode) => {
706
- const Component = forwardRef(
707
+ const Component2 = forwardRef(
707
708
  ({ className, ...props }, ref) => createElement(Icon, {
708
709
  ref,
709
710
  iconNode,
@@ -715,8 +716,8 @@ var createLucideIcon = (iconName, iconNode) => {
715
716
  ...props
716
717
  })
717
718
  );
718
- Component.displayName = toPascalCase(iconName);
719
- return Component;
719
+ Component2.displayName = toPascalCase(iconName);
720
+ return Component2;
720
721
  };
721
722
 
722
723
  // node_modules/lucide-react/dist/esm/icons/check.js
@@ -898,6 +899,50 @@ var __iconNode21 = [
898
899
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
899
900
  ];
900
901
  var X = createLucideIcon("x", __iconNode21);
902
+ var FieldErrorBoundary = class extends Component {
903
+ constructor(props) {
904
+ super(props);
905
+ this.handleRetry = () => {
906
+ this.setState({ hasError: false, error: null });
907
+ };
908
+ this.state = { hasError: false, error: null };
909
+ }
910
+ static getDerivedStateFromError(error2) {
911
+ return { hasError: true, error: error2 };
912
+ }
913
+ componentDidCatch(error2, errorInfo) {
914
+ console.error(
915
+ `[TecofEditor] Field "${this.props.fieldName || "unknown"}" crashed:`,
916
+ error2,
917
+ errorInfo
918
+ );
919
+ this.props.onError?.(error2, errorInfo);
920
+ }
921
+ render() {
922
+ if (this.state.hasError) {
923
+ if (this.props.fallback) {
924
+ return this.props.fallback;
925
+ }
926
+ return /* @__PURE__ */ jsxs("div", { className: "tecof-field-error-boundary", children: [
927
+ /* @__PURE__ */ jsx("div", { className: "tecof-field-error-icon", children: "\u26A0\uFE0F" }),
928
+ /* @__PURE__ */ jsxs("div", { className: "tecof-field-error-content", children: [
929
+ /* @__PURE__ */ jsx("p", { className: "tecof-field-error-title", children: "Bu alan y\xFCklenemedi" }),
930
+ /* @__PURE__ */ jsx("p", { className: "tecof-field-error-detail", children: this.state.error?.message || "Beklenmeyen bir hata olu\u015Ftu" })
931
+ ] }),
932
+ /* @__PURE__ */ jsx(
933
+ "button",
934
+ {
935
+ type: "button",
936
+ className: "tecof-field-error-retry",
937
+ onClick: this.handleRetry,
938
+ children: "Tekrar Dene"
939
+ }
940
+ )
941
+ ] });
942
+ }
943
+ return this.props.children;
944
+ }
945
+ };
901
946
  var LanguageTabBar = ({
902
947
  languages,
903
948
  defaultLanguage,
@@ -925,6 +970,73 @@ var FieldLoading = () => /* @__PURE__ */ jsxs("div", { className: "tecof-lang-lo
925
970
  /* @__PURE__ */ jsx("span", { className: "tecof-lang-loading-dot" }),
926
971
  /* @__PURE__ */ jsx("span", { className: "tecof-lang-loading-dot" })
927
972
  ] });
973
+ var StableInput = ({
974
+ value: externalValue,
975
+ onChange,
976
+ disabled,
977
+ placeholder,
978
+ className
979
+ }) => {
980
+ const [localValue, setLocalValue] = useState(externalValue);
981
+ const lastEmitted = useRef(externalValue);
982
+ useEffect(() => {
983
+ if (externalValue !== lastEmitted.current) {
984
+ setLocalValue(externalValue);
985
+ lastEmitted.current = externalValue;
986
+ }
987
+ }, [externalValue]);
988
+ const handleChange = (e3) => {
989
+ const val = e3.target.value;
990
+ setLocalValue(val);
991
+ lastEmitted.current = val;
992
+ onChange(val);
993
+ };
994
+ return /* @__PURE__ */ jsx(
995
+ "input",
996
+ {
997
+ type: "text",
998
+ value: localValue,
999
+ onChange: handleChange,
1000
+ disabled,
1001
+ placeholder,
1002
+ className
1003
+ }
1004
+ );
1005
+ };
1006
+ var StableTextarea = ({
1007
+ value: externalValue,
1008
+ onChange,
1009
+ disabled,
1010
+ placeholder,
1011
+ className,
1012
+ rows
1013
+ }) => {
1014
+ const [localValue, setLocalValue] = useState(externalValue);
1015
+ const lastEmitted = useRef(externalValue);
1016
+ useEffect(() => {
1017
+ if (externalValue !== lastEmitted.current) {
1018
+ setLocalValue(externalValue);
1019
+ lastEmitted.current = externalValue;
1020
+ }
1021
+ }, [externalValue]);
1022
+ const handleChange = (e3) => {
1023
+ const val = e3.target.value;
1024
+ setLocalValue(val);
1025
+ lastEmitted.current = val;
1026
+ onChange(val);
1027
+ };
1028
+ return /* @__PURE__ */ jsx(
1029
+ "textarea",
1030
+ {
1031
+ value: localValue,
1032
+ onChange: handleChange,
1033
+ rows,
1034
+ disabled,
1035
+ placeholder,
1036
+ className
1037
+ }
1038
+ );
1039
+ };
928
1040
  var LanguageField = ({
929
1041
  value,
930
1042
  onChange,
@@ -948,6 +1060,8 @@ var LanguageField = ({
948
1060
  }, [value, merchantInfo]);
949
1061
  const valuesRef = useRef(values);
950
1062
  valuesRef.current = values;
1063
+ const onChangeRef = useRef(onChange);
1064
+ onChangeRef.current = onChange;
951
1065
  const handleChange = useCallback((code, newVal) => {
952
1066
  const current = valuesRef.current;
953
1067
  const updated = [...current];
@@ -957,8 +1071,8 @@ var LanguageField = ({
957
1071
  } else {
958
1072
  updated.push({ code, value: newVal });
959
1073
  }
960
- onChange(updated);
961
- }, [onChange]);
1074
+ onChangeRef.current(updated);
1075
+ }, []);
962
1076
  const getCurrentText = useCallback(() => {
963
1077
  return valuesRef.current.find((v2) => v2.code === activeTab)?.value || "";
964
1078
  }, [activeTab]);
@@ -970,10 +1084,10 @@ var LanguageField = ({
970
1084
  code,
971
1085
  value: text2
972
1086
  }));
973
- onChange(updated);
1087
+ onChangeRef.current(updated);
974
1088
  setStatusMsg({ text: "T\xFCm dillere kopyaland\u0131", type: "success" });
975
1089
  setTimeout(() => setStatusMsg(null), 2e3);
976
- }, [getCurrentText, merchantInfo, onChange]);
1090
+ }, [getCurrentText, merchantInfo]);
977
1091
  const handleTranslate = useCallback(async () => {
978
1092
  const text2 = getCurrentText();
979
1093
  if (!text2 || !merchantInfo) return;
@@ -993,7 +1107,7 @@ var LanguageField = ({
993
1107
  updated.push({ code: t2.code, value: t2.value });
994
1108
  }
995
1109
  }
996
- onChange(updated);
1110
+ onChangeRef.current(updated);
997
1111
  setStatusMsg({ text: "\xC7eviri tamamland\u0131", type: "success" });
998
1112
  } else {
999
1113
  setStatusMsg({ text: res2.message || "\xC7eviri hatas\u0131", type: "error" });
@@ -1004,7 +1118,7 @@ var LanguageField = ({
1004
1118
  setTranslating(false);
1005
1119
  setTimeout(() => setStatusMsg(null), 3e3);
1006
1120
  }
1007
- }, [getCurrentText, merchantInfo, activeTab, onChange, apiClient, isHtml]);
1121
+ }, [getCurrentText, merchantInfo, activeTab, apiClient, isHtml]);
1008
1122
  if (loading) return /* @__PURE__ */ jsx(FieldLoading, {});
1009
1123
  if (error2 && !merchantInfo) return /* @__PURE__ */ jsx("div", { className: "tecof-lang-error", children: error2 });
1010
1124
  if (!merchantInfo) return null;
@@ -1025,21 +1139,20 @@ var LanguageField = ({
1025
1139
  if (activeTab !== code) return null;
1026
1140
  const currentValue = values.find((v2) => v2.code === code)?.value || "";
1027
1141
  return /* @__PURE__ */ jsx("div", { className: "tecof-lang-input-wrapper", children: isTextarea ? /* @__PURE__ */ jsx(
1028
- "textarea",
1142
+ StableTextarea,
1029
1143
  {
1030
1144
  value: currentValue,
1031
- onChange: (e3) => handleChange(code, e3.target.value),
1145
+ onChange: (val) => handleChange(code, val),
1032
1146
  rows: textareaRows,
1033
1147
  placeholder: placeholder || `${code.toUpperCase()} text...`,
1034
1148
  disabled: readOnly,
1035
1149
  className: "tecof-lang-input tecof-lang-textarea"
1036
1150
  }
1037
1151
  ) : /* @__PURE__ */ jsx(
1038
- "input",
1152
+ StableInput,
1039
1153
  {
1040
- type: "text",
1041
1154
  value: currentValue,
1042
- onChange: (e3) => handleChange(code, e3.target.value),
1155
+ onChange: (val) => handleChange(code, val),
1043
1156
  placeholder: placeholder || `${code.toUpperCase()} text...`,
1044
1157
  disabled: readOnly,
1045
1158
  className: "tecof-lang-input"
@@ -1087,7 +1200,7 @@ var createLanguageField = (options = {}) => {
1087
1200
  label,
1088
1201
  labelIcon,
1089
1202
  visible,
1090
- render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(
1203
+ render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(FieldErrorBoundary, { fieldName: name3, children: /* @__PURE__ */ jsx(
1091
1204
  LanguageField,
1092
1205
  {
1093
1206
  field,
@@ -1098,7 +1211,7 @@ var createLanguageField = (options = {}) => {
1098
1211
  readOnly,
1099
1212
  ...fieldOptions
1100
1213
  }
1101
- ) })
1214
+ ) }) })
1102
1215
  };
1103
1216
  };
1104
1217
  var createExtensions = () => [
@@ -1332,16 +1445,21 @@ var EditorField = ({
1332
1445
  return existing || { code, value: "" };
1333
1446
  });
1334
1447
  }, [value, merchantInfo]);
1448
+ const valuesRef = useRef(values);
1449
+ valuesRef.current = values;
1450
+ const onChangeRef = useRef(onChange);
1451
+ onChangeRef.current = onChange;
1335
1452
  const handleChange = useCallback((code, html) => {
1336
- const updated = [...values];
1453
+ const current = valuesRef.current;
1454
+ const updated = [...current];
1337
1455
  const idx = updated.findIndex((v2) => v2.code === code);
1338
1456
  if (idx >= 0) {
1339
1457
  updated[idx] = { ...updated[idx], value: html };
1340
1458
  } else {
1341
1459
  updated.push({ code, value: html });
1342
1460
  }
1343
- onChange(updated);
1344
- }, [values, onChange]);
1461
+ onChangeRef.current(updated);
1462
+ }, []);
1345
1463
  if (loading) return /* @__PURE__ */ jsx(FieldLoading, {});
1346
1464
  if (error2 && !merchantInfo) return /* @__PURE__ */ jsx("div", { className: "tecof-lang-error", children: error2 });
1347
1465
  if (!merchantInfo) return null;
@@ -1378,7 +1496,7 @@ var createEditorField = (options = {}) => {
1378
1496
  label,
1379
1497
  labelIcon,
1380
1498
  visible,
1381
- render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(
1499
+ render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(FieldErrorBoundary, { fieldName: name3, children: /* @__PURE__ */ jsx(
1382
1500
  EditorField,
1383
1501
  {
1384
1502
  field,
@@ -1389,7 +1507,7 @@ var createEditorField = (options = {}) => {
1389
1507
  readOnly,
1390
1508
  ...fieldOptions
1391
1509
  }
1392
- ) })
1510
+ ) }) })
1393
1511
  };
1394
1512
  };
1395
1513
 
@@ -22899,7 +23017,7 @@ var createUploadField = (options = {}) => {
22899
23017
  label,
22900
23018
  labelIcon,
22901
23019
  visible,
22902
- render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(
23020
+ render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(FieldErrorBoundary, { fieldName: name3, children: /* @__PURE__ */ jsx(
22903
23021
  UploadField,
22904
23022
  {
22905
23023
  field,
@@ -22910,7 +23028,7 @@ var createUploadField = (options = {}) => {
22910
23028
  readOnly,
22911
23029
  ...fieldOptions
22912
23030
  }
22913
- ) })
23031
+ ) }) })
22914
23032
  };
22915
23033
  };
22916
23034
 
@@ -23594,7 +23712,7 @@ var createCodeEditorField = (options = {}) => {
23594
23712
  label,
23595
23713
  labelIcon,
23596
23714
  visible,
23597
- render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(
23715
+ render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(FieldErrorBoundary, { fieldName: name3, children: /* @__PURE__ */ jsx(
23598
23716
  CodeEditorField,
23599
23717
  {
23600
23718
  field,
@@ -23605,7 +23723,7 @@ var createCodeEditorField = (options = {}) => {
23605
23723
  readOnly,
23606
23724
  ...fieldOptions
23607
23725
  }
23608
- ) })
23726
+ ) }) })
23609
23727
  };
23610
23728
  };
23611
23729
  var LinkField = ({
@@ -23633,10 +23751,14 @@ var LinkField = ({
23633
23751
  return existing || { code, value: { url: "" } };
23634
23752
  });
23635
23753
  }, [value, merchantInfo]);
23754
+ const valuesRef = useRef(values);
23755
+ valuesRef.current = values;
23756
+ const onChangeRef = useRef(onChange);
23757
+ onChangeRef.current = onChange;
23636
23758
  const activeValueItem = values.find((v2) => v2.code === activeTab);
23637
23759
  const activeValue = activeValueItem?.value || { url: "" };
23638
23760
  const updateActiveValue = useCallback((newLinkVal) => {
23639
- const updated = [...values];
23761
+ const updated = [...valuesRef.current];
23640
23762
  const idx = updated.findIndex((v2) => v2.code === activeTab);
23641
23763
  if (idx >= 0) {
23642
23764
  if (newLinkVal) {
@@ -23647,8 +23769,8 @@ var LinkField = ({
23647
23769
  } else if (newLinkVal) {
23648
23770
  updated.push({ code: activeTab, value: newLinkVal });
23649
23771
  }
23650
- onChange(updated);
23651
- }, [values, activeTab, onChange]);
23772
+ onChangeRef.current(updated);
23773
+ }, [activeTab]);
23652
23774
  useEffect(() => {
23653
23775
  if (!drawerOpen) return;
23654
23776
  setLoading(true);
@@ -23837,7 +23959,7 @@ var createLinkField = (options = {}) => {
23837
23959
  label,
23838
23960
  labelIcon,
23839
23961
  visible,
23840
- render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(
23962
+ render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(FieldErrorBoundary, { fieldName: name3, children: /* @__PURE__ */ jsx(
23841
23963
  LinkField,
23842
23964
  {
23843
23965
  field,
@@ -23848,7 +23970,7 @@ var createLinkField = (options = {}) => {
23848
23970
  readOnly,
23849
23971
  ...fieldOptions
23850
23972
  }
23851
- ) })
23973
+ ) }) })
23852
23974
  };
23853
23975
  };
23854
23976
  var isValidHex = (hex) => /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(hex);
@@ -24018,7 +24140,7 @@ var createColorField = (options = {}) => {
24018
24140
  label,
24019
24141
  labelIcon,
24020
24142
  visible,
24021
- render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(
24143
+ render: ({ value, onChange, readOnly, field, name: name3, id }) => /* @__PURE__ */ jsx(FieldLabel, { label: label || "", icon: labelIcon, readOnly, children: /* @__PURE__ */ jsx(FieldErrorBoundary, { fieldName: name3, children: /* @__PURE__ */ jsx(
24022
24144
  ColorField,
24023
24145
  {
24024
24146
  field,
@@ -24029,7 +24151,7 @@ var createColorField = (options = {}) => {
24029
24151
  readOnly,
24030
24152
  ...fieldOptions
24031
24153
  }
24032
- ) })
24154
+ ) }) })
24033
24155
  };
24034
24156
  };
24035
24157
 
@@ -24294,6 +24416,6 @@ filepond-plugin-image-edit/dist/filepond-plugin-image-edit.esm.js:
24294
24416
  *)
24295
24417
  */
24296
24418
 
24297
- export { CodeEditorField, ColorField, EditorField, LanguageField, LinkField, TecofApiClient, TecofEditor, TecofPicture, TecofProvider, TecofRender, UploadField, createCodeEditorField, createColorField, createEditorField, createLanguageField, createLinkField, createUploadField, darken, generateCSSVariables, getDefaultTheme, hexToHsl, hslToHex, lighten, mergeTheme, useTecof };
24419
+ export { CodeEditorField, ColorField, EditorField, FieldErrorBoundary, LanguageField, LinkField, TecofApiClient, TecofEditor, TecofPicture, TecofProvider, TecofRender, UploadField, createCodeEditorField, createColorField, createEditorField, createLanguageField, createLinkField, createUploadField, darken, generateCSSVariables, getDefaultTheme, hexToHsl, hslToHex, lighten, mergeTheme, useTecof };
24298
24420
  //# sourceMappingURL=index.mjs.map
24299
24421
  //# sourceMappingURL=index.mjs.map