@tecof/theme-editor 0.0.24 → 0.0.25

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