@cyberyozh/text-editor 0.3.1 → 0.3.2

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/editor.mjs CHANGED
@@ -1935,11 +1935,20 @@ var ImageDialog = ({
1935
1935
  width: constrainedDimensions.width,
1936
1936
  height: constrainedDimensions.height
1937
1937
  });
1938
+ const [fileUploadError, setFileUploadError] = useState6(null);
1938
1939
  const handleSelectFile = (file) => {
1940
+ setFileUploadError(null);
1939
1941
  if (!file) return;
1942
+ if (!file.type.startsWith("image/")) {
1943
+ setFileUploadError(new Error(translations2.imageDialog.invalidFileType));
1944
+ return;
1945
+ }
1940
1946
  const imageUrl = URL.createObjectURL(file);
1941
1947
  const img = new Image();
1942
1948
  img.src = imageUrl;
1949
+ img.onerror = () => {
1950
+ setFileUploadError(new Error(translations2.imageDialog.invalidFileType));
1951
+ };
1943
1952
  img.onload = () => {
1944
1953
  const naturalWidth = img.width;
1945
1954
  const naturalHeight = img.height;
@@ -2032,6 +2041,8 @@ var ImageDialog = ({
2032
2041
  storageKey: result.storageKey
2033
2042
  });
2034
2043
  handleClose();
2044
+ } catch (error) {
2045
+ setFileUploadError(error instanceof Error ? error : new Error(translations2.imageDialog.unknownError));
2035
2046
  } finally {
2036
2047
  setIsUploading(false);
2037
2048
  }
@@ -2047,7 +2058,9 @@ var ImageDialog = ({
2047
2058
  });
2048
2059
  handleClose();
2049
2060
  };
2050
- const handleSave = mode === "edit" ? handleEditImage : handleAddImage;
2061
+ const isEditMode = mode === "edit";
2062
+ const canSave = isEditMode || Boolean(formState.file);
2063
+ const handleSave = isEditMode ? handleEditImage : handleAddImage;
2051
2064
  const handleClose = () => {
2052
2065
  clearImageFormFields();
2053
2066
  onClose();
@@ -2140,6 +2153,19 @@ var ImageDialog = ({
2140
2153
  )
2141
2154
  ] })
2142
2155
  ] }) }),
2156
+ fileUploadError && /* @__PURE__ */ jsxs18("div", { className: "image-dialog-error", children: [
2157
+ fileUploadError.message || translations2.imageDialog.unknownError,
2158
+ /* @__PURE__ */ jsx67(
2159
+ "button",
2160
+ {
2161
+ type: "button",
2162
+ className: "image-dialog-error-clear-button",
2163
+ onClick: () => setFileUploadError(null),
2164
+ "aria-label": translations2.imageDialog.clearError,
2165
+ children: /* @__PURE__ */ jsx67(X_default, {})
2166
+ }
2167
+ )
2168
+ ] }),
2143
2169
  /* @__PURE__ */ jsxs18("div", { className: "image-dialog-actions", children: [
2144
2170
  /* @__PURE__ */ jsx67(
2145
2171
  Button,
@@ -2157,6 +2183,7 @@ var ImageDialog = ({
2157
2183
  isLoading: isUploading,
2158
2184
  type: "button",
2159
2185
  onClick: handleSave,
2186
+ disabled: !canSave,
2160
2187
  children: saveButtonText
2161
2188
  }
2162
2189
  )
@@ -6843,9 +6870,9 @@ function useInsertionHandlers(imageHandlers) {
6843
6870
  }
6844
6871
  }, [insertedImage, activeDialog]);
6845
6872
  function genericInsertionHandler(file, event) {
6846
- if (!file || !file.type.startsWith("image/")) return;
6847
6873
  event.preventDefault();
6848
6874
  event.stopPropagation();
6875
+ if (!file || !file.type.startsWith("image/")) return;
6849
6876
  if (!imageHandlers?.upload) return;
6850
6877
  setInsertedImage(file);
6851
6878
  openDialogCommand("image");
@@ -7420,7 +7447,10 @@ var ru_default = {
7420
7447
  captionLabel: "\u041F\u043E\u0434\u043F\u0438\u0441\u044C \u043A \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044E",
7421
7448
  captionPlaceholder: "\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435 \u043F\u043E\u0434 \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435\u043C...",
7422
7449
  save: "\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C",
7423
- add: "\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C"
7450
+ add: "\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C",
7451
+ invalidFileType: "\u0424\u0430\u0439\u043B \u043D\u0435 \u044F\u0432\u043B\u044F\u0435\u0442\u0441\u044F \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u0435\u043C",
7452
+ unknownError: "\u041D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430",
7453
+ clearError: "\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C \u043E\u0448\u0438\u0431\u043A\u0443"
7424
7454
  },
7425
7455
  videoUpload: {
7426
7456
  title: "\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0432\u0438\u0434\u0435\u043E",
@@ -7584,7 +7614,10 @@ var en_default = {
7584
7614
  captionLabel: "Image caption",
7585
7615
  captionPlaceholder: "Description under image...",
7586
7616
  save: "Save",
7587
- add: "Add"
7617
+ add: "Add",
7618
+ invalidFileType: "File is not an image",
7619
+ unknownError: "Unknown error",
7620
+ clearError: "Clear error"
7588
7621
  },
7589
7622
  videoUpload: {
7590
7623
  title: "Add video",