@tecof/theme-editor 0.0.23 → 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,
@@ -946,19 +1057,24 @@ var LanguageField = ({
946
1057
  return existing || { code, value: "" };
947
1058
  });
948
1059
  }, [value, merchantInfo]);
1060
+ const valuesRef = useRef(values);
1061
+ valuesRef.current = values;
1062
+ const onChangeRef = useRef(onChange);
1063
+ onChangeRef.current = onChange;
949
1064
  const handleChange = useCallback((code, newVal) => {
950
- const updated = [...values];
1065
+ const current = valuesRef.current;
1066
+ const updated = [...current];
951
1067
  const idx = updated.findIndex((v2) => v2.code === code);
952
1068
  if (idx >= 0) {
953
1069
  updated[idx] = { ...updated[idx], value: newVal };
954
1070
  } else {
955
1071
  updated.push({ code, value: newVal });
956
1072
  }
957
- onChange(updated);
958
- }, [values, onChange]);
1073
+ onChangeRef.current(updated);
1074
+ }, []);
959
1075
  const getCurrentText = useCallback(() => {
960
- return values.find((v2) => v2.code === activeTab)?.value || "";
961
- }, [values, activeTab]);
1076
+ return valuesRef.current.find((v2) => v2.code === activeTab)?.value || "";
1077
+ }, [activeTab]);
962
1078
  const handleFastFill = useCallback(() => {
963
1079
  const text2 = getCurrentText();
964
1080
  if (!text2) return;
@@ -967,10 +1083,10 @@ var LanguageField = ({
967
1083
  code,
968
1084
  value: text2
969
1085
  }));
970
- onChange(updated);
1086
+ onChangeRef.current(updated);
971
1087
  setStatusMsg({ text: "T\xFCm dillere kopyaland\u0131", type: "success" });
972
1088
  setTimeout(() => setStatusMsg(null), 2e3);
973
- }, [getCurrentText, merchantInfo, onChange]);
1089
+ }, [getCurrentText, merchantInfo]);
974
1090
  const handleTranslate = useCallback(async () => {
975
1091
  const text2 = getCurrentText();
976
1092
  if (!text2 || !merchantInfo) return;
@@ -981,7 +1097,7 @@ var LanguageField = ({
981
1097
  try {
982
1098
  const res2 = await apiClient.translate(text2, activeTab, otherLocales, isHtml);
983
1099
  if (res2.success && Array.isArray(res2.data)) {
984
- const updated = [...values];
1100
+ const updated = [...valuesRef.current];
985
1101
  for (const t2 of res2.data) {
986
1102
  const idx = updated.findIndex((v2) => v2.code === t2.code);
987
1103
  if (idx >= 0) {
@@ -990,7 +1106,7 @@ var LanguageField = ({
990
1106
  updated.push({ code: t2.code, value: t2.value });
991
1107
  }
992
1108
  }
993
- onChange(updated);
1109
+ onChangeRef.current(updated);
994
1110
  setStatusMsg({ text: "\xC7eviri tamamland\u0131", type: "success" });
995
1111
  } else {
996
1112
  setStatusMsg({ text: res2.message || "\xC7eviri hatas\u0131", type: "error" });
@@ -1001,7 +1117,7 @@ var LanguageField = ({
1001
1117
  setTranslating(false);
1002
1118
  setTimeout(() => setStatusMsg(null), 3e3);
1003
1119
  }
1004
- }, [getCurrentText, merchantInfo, activeTab, values, onChange, apiClient, isHtml]);
1120
+ }, [getCurrentText, merchantInfo, activeTab, apiClient, isHtml]);
1005
1121
  if (loading) return /* @__PURE__ */ jsx(FieldLoading, {});
1006
1122
  if (error2 && !merchantInfo) return /* @__PURE__ */ jsx("div", { className: "tecof-lang-error", children: error2 });
1007
1123
  if (!merchantInfo) return null;
@@ -1022,21 +1138,20 @@ var LanguageField = ({
1022
1138
  if (activeTab !== code) return null;
1023
1139
  const currentValue = values.find((v2) => v2.code === code)?.value || "";
1024
1140
  return /* @__PURE__ */ jsx("div", { className: "tecof-lang-input-wrapper", children: isTextarea ? /* @__PURE__ */ jsx(
1025
- "textarea",
1141
+ StableTextarea,
1026
1142
  {
1027
1143
  value: currentValue,
1028
- onChange: (e3) => handleChange(code, e3.target.value),
1144
+ onChange: (val) => handleChange(code, val),
1029
1145
  rows: textareaRows,
1030
1146
  placeholder: placeholder || `${code.toUpperCase()} text...`,
1031
1147
  disabled: readOnly,
1032
1148
  className: "tecof-lang-input tecof-lang-textarea"
1033
1149
  }
1034
1150
  ) : /* @__PURE__ */ jsx(
1035
- "input",
1151
+ StableInput,
1036
1152
  {
1037
- type: "text",
1038
1153
  value: currentValue,
1039
- onChange: (e3) => handleChange(code, e3.target.value),
1154
+ onChange: (val) => handleChange(code, val),
1040
1155
  placeholder: placeholder || `${code.toUpperCase()} text...`,
1041
1156
  disabled: readOnly,
1042
1157
  className: "tecof-lang-input"
@@ -1084,7 +1199,7 @@ var createLanguageField = (options = {}) => {
1084
1199
  label,
1085
1200
  labelIcon,
1086
1201
  visible,
1087
- 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(
1088
1203
  LanguageField,
1089
1204
  {
1090
1205
  field,
@@ -1095,7 +1210,7 @@ var createLanguageField = (options = {}) => {
1095
1210
  readOnly,
1096
1211
  ...fieldOptions
1097
1212
  }
1098
- ) })
1213
+ ) }) })
1099
1214
  };
1100
1215
  };
1101
1216
  var createExtensions = () => [
@@ -1329,16 +1444,21 @@ var EditorField = ({
1329
1444
  return existing || { code, value: "" };
1330
1445
  });
1331
1446
  }, [value, merchantInfo]);
1447
+ const valuesRef = useRef(values);
1448
+ valuesRef.current = values;
1449
+ const onChangeRef = useRef(onChange);
1450
+ onChangeRef.current = onChange;
1332
1451
  const handleChange = useCallback((code, html) => {
1333
- const updated = [...values];
1452
+ const current = valuesRef.current;
1453
+ const updated = [...current];
1334
1454
  const idx = updated.findIndex((v2) => v2.code === code);
1335
1455
  if (idx >= 0) {
1336
1456
  updated[idx] = { ...updated[idx], value: html };
1337
1457
  } else {
1338
1458
  updated.push({ code, value: html });
1339
1459
  }
1340
- onChange(updated);
1341
- }, [values, onChange]);
1460
+ onChangeRef.current(updated);
1461
+ }, []);
1342
1462
  if (loading) return /* @__PURE__ */ jsx(FieldLoading, {});
1343
1463
  if (error2 && !merchantInfo) return /* @__PURE__ */ jsx("div", { className: "tecof-lang-error", children: error2 });
1344
1464
  if (!merchantInfo) return null;
@@ -1375,7 +1495,7 @@ var createEditorField = (options = {}) => {
1375
1495
  label,
1376
1496
  labelIcon,
1377
1497
  visible,
1378
- 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(
1379
1499
  EditorField,
1380
1500
  {
1381
1501
  field,
@@ -1386,7 +1506,7 @@ var createEditorField = (options = {}) => {
1386
1506
  readOnly,
1387
1507
  ...fieldOptions
1388
1508
  }
1389
- ) })
1509
+ ) }) })
1390
1510
  };
1391
1511
  };
1392
1512
 
@@ -22896,7 +23016,7 @@ var createUploadField = (options = {}) => {
22896
23016
  label,
22897
23017
  labelIcon,
22898
23018
  visible,
22899
- 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(
22900
23020
  UploadField,
22901
23021
  {
22902
23022
  field,
@@ -22907,7 +23027,7 @@ var createUploadField = (options = {}) => {
22907
23027
  readOnly,
22908
23028
  ...fieldOptions
22909
23029
  }
22910
- ) })
23030
+ ) }) })
22911
23031
  };
22912
23032
  };
22913
23033
 
@@ -23591,7 +23711,7 @@ var createCodeEditorField = (options = {}) => {
23591
23711
  label,
23592
23712
  labelIcon,
23593
23713
  visible,
23594
- 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(
23595
23715
  CodeEditorField,
23596
23716
  {
23597
23717
  field,
@@ -23602,7 +23722,7 @@ var createCodeEditorField = (options = {}) => {
23602
23722
  readOnly,
23603
23723
  ...fieldOptions
23604
23724
  }
23605
- ) })
23725
+ ) }) })
23606
23726
  };
23607
23727
  };
23608
23728
  var LinkField = ({
@@ -23630,10 +23750,14 @@ var LinkField = ({
23630
23750
  return existing || { code, value: { url: "" } };
23631
23751
  });
23632
23752
  }, [value, merchantInfo]);
23753
+ const valuesRef = useRef(values);
23754
+ valuesRef.current = values;
23755
+ const onChangeRef = useRef(onChange);
23756
+ onChangeRef.current = onChange;
23633
23757
  const activeValueItem = values.find((v2) => v2.code === activeTab);
23634
23758
  const activeValue = activeValueItem?.value || { url: "" };
23635
23759
  const updateActiveValue = useCallback((newLinkVal) => {
23636
- const updated = [...values];
23760
+ const updated = [...valuesRef.current];
23637
23761
  const idx = updated.findIndex((v2) => v2.code === activeTab);
23638
23762
  if (idx >= 0) {
23639
23763
  if (newLinkVal) {
@@ -23644,8 +23768,8 @@ var LinkField = ({
23644
23768
  } else if (newLinkVal) {
23645
23769
  updated.push({ code: activeTab, value: newLinkVal });
23646
23770
  }
23647
- onChange(updated);
23648
- }, [values, activeTab, onChange]);
23771
+ onChangeRef.current(updated);
23772
+ }, [activeTab]);
23649
23773
  useEffect(() => {
23650
23774
  if (!drawerOpen) return;
23651
23775
  setLoading(true);
@@ -23834,7 +23958,7 @@ var createLinkField = (options = {}) => {
23834
23958
  label,
23835
23959
  labelIcon,
23836
23960
  visible,
23837
- 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(
23838
23962
  LinkField,
23839
23963
  {
23840
23964
  field,
@@ -23845,7 +23969,7 @@ var createLinkField = (options = {}) => {
23845
23969
  readOnly,
23846
23970
  ...fieldOptions
23847
23971
  }
23848
- ) })
23972
+ ) }) })
23849
23973
  };
23850
23974
  };
23851
23975
  var isValidHex = (hex) => /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(hex);
@@ -24015,7 +24139,7 @@ var createColorField = (options = {}) => {
24015
24139
  label,
24016
24140
  labelIcon,
24017
24141
  visible,
24018
- 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(
24019
24143
  ColorField,
24020
24144
  {
24021
24145
  field,
@@ -24026,7 +24150,7 @@ var createColorField = (options = {}) => {
24026
24150
  readOnly,
24027
24151
  ...fieldOptions
24028
24152
  }
24029
- ) })
24153
+ ) }) })
24030
24154
  };
24031
24155
  };
24032
24156
 
@@ -24291,6 +24415,6 @@ filepond-plugin-image-edit/dist/filepond-plugin-image-edit.esm.js:
24291
24415
  *)
24292
24416
  */
24293
24417
 
24294
- 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 };
24295
24419
  //# sourceMappingURL=index.mjs.map
24296
24420
  //# sourceMappingURL=index.mjs.map