wysimark-lite 0.25.12 → 0.25.13

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
@@ -1700,6 +1700,7 @@ var translations = {
1700
1700
  uploading: "\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D...",
1701
1701
  saving: "\u4FDD\u5B58\u4E2D...",
1702
1702
  uploadComplete: "\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u5B8C\u4E86",
1703
+ imageSourceSelect: "\u30D5\u30A1\u30A4\u30EB\u9078\u629E",
1703
1704
  vaultPath: "\u4FDD\u5B58\u5148\u30D1\u30B9\uFF1A",
1704
1705
  vaultPathHint: "vault\u5185\u306E\u4FDD\u5B58\u5148\u30D1\u30B9\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"
1705
1706
  },
@@ -1753,6 +1754,7 @@ var translations = {
1753
1754
  uploading: "Uploading...",
1754
1755
  saving: "Saving...",
1755
1756
  uploadComplete: "Upload Complete",
1757
+ imageSourceSelect: "Select File",
1756
1758
  vaultPath: "Save Path:",
1757
1759
  vaultPathHint: "Enter the path within the vault to save the file"
1758
1760
  }
@@ -8403,13 +8405,20 @@ function ImageUrlDialog({
8403
8405
  }, []);
8404
8406
  const savedState = editor.wysimark?.imageDialogState;
8405
8407
  const hasOnImageChange = !!editor.wysimark?.onImageChange;
8408
+ const hasOnFileSelect = !!editor.wysimark?.onFileSelect;
8409
+ const defaultSource = savedState?.imageSource ?? (hasOnFileSelect ? "select" : hasOnImageChange ? "file" : "url");
8406
8410
  const [url, setUrl] = useState9(savedState?.url ?? "");
8407
8411
  const [alt, setAlt] = useState9(savedState?.alt ?? "");
8408
8412
  const [title, setTitle] = useState9(savedState?.title ?? "");
8409
8413
  const [titleManuallyEdited, setTitleManuallyEdited] = useState9(false);
8410
- const [imageSource, setImageSource] = useState9(savedState?.imageSource ?? (hasOnImageChange ? "file" : "url"));
8414
+ const [imageSource, setImageSource] = useState9(defaultSource);
8411
8415
  const [isUploading, setIsUploading] = useState9(false);
8412
8416
  const [uploadedUrl, setUploadedUrl] = useState9(savedState?.uploadedUrl ?? "");
8417
+ const handleImageSourceChange = (source) => {
8418
+ setImageSource(source);
8419
+ setUploadedUrl("");
8420
+ setUploadedFileName("");
8421
+ };
8413
8422
  const [uploadedFileName, setUploadedFileName] = useState9("");
8414
8423
  const handleAltChange = useCallback14((e) => {
8415
8424
  const newAlt = e.target.value;
@@ -8426,7 +8435,7 @@ function ImageUrlDialog({
8426
8435
  if (editor.wysimark) {
8427
8436
  editor.wysimark.imageDialogState = { url, alt, title, imageSource, uploadedUrl };
8428
8437
  }
8429
- }, [url, alt, title, imageSource, uploadedUrl]);
8438
+ }, [editor, url, alt, title, imageSource, uploadedUrl]);
8430
8439
  const clearState = () => {
8431
8440
  if (editor.wysimark) {
8432
8441
  editor.wysimark.imageDialogState = void 0;
@@ -8453,7 +8462,7 @@ function ImageUrlDialog({
8453
8462
  };
8454
8463
  function handleSubmit(e) {
8455
8464
  e.preventDefault();
8456
- const finalUrl = imageSource === "file" ? uploadedUrl : url;
8465
+ const finalUrl = imageSource === "file" || imageSource === "select" ? uploadedUrl : url;
8457
8466
  if (finalUrl.trim() === "") return;
8458
8467
  editor.image.insertImageFromUrl(finalUrl, alt, title);
8459
8468
  clearState();
@@ -8480,14 +8489,42 @@ function ImageUrlDialog({
8480
8489
  function handleSelectFileClick() {
8481
8490
  fileInputRef.current?.click();
8482
8491
  }
8483
- const isSubmitDisabled = imageSource === "file" ? uploadedUrl.trim() === "" || isUploading : url.trim() === "";
8492
+ async function handleFileSelectFromPicker() {
8493
+ if (!editor.wysimark?.onFileSelect) return;
8494
+ setIsUploading(true);
8495
+ try {
8496
+ const resultUrl = await editor.wysimark.onFileSelect();
8497
+ if (resultUrl) {
8498
+ setUploadedUrl(resultUrl);
8499
+ }
8500
+ } catch (error) {
8501
+ void error;
8502
+ } finally {
8503
+ setIsUploading(false);
8504
+ }
8505
+ }
8506
+ const isSubmitDisabled = imageSource === "file" || imageSource === "select" ? uploadedUrl.trim() === "" || isUploading : url.trim() === "";
8484
8507
  return /* @__PURE__ */ jsxs29(Fragment9, { children: [
8485
8508
  /* @__PURE__ */ jsx61(CloseMask, { close }),
8486
8509
  /* @__PURE__ */ jsxs29($FileDialog, { ref, style, children: [
8487
8510
  /* @__PURE__ */ jsx61(DraggableHeader, { onDrag: handleDrag }),
8488
8511
  /* @__PURE__ */ jsxs29("form", { onSubmit: (e) => void handleSubmit(e), style: { padding: "8px" }, children: [
8489
- hasOnImageChange && /* @__PURE__ */ jsxs29("div", { style: { marginBottom: "12px" }, children: [
8490
- /* @__PURE__ */ jsxs29("label", { style: { display: "inline-flex", alignItems: "center", marginRight: "16px", cursor: "pointer" }, children: [
8512
+ (hasOnImageChange || hasOnFileSelect) && /* @__PURE__ */ jsxs29("div", { style: { marginBottom: "12px" }, children: [
8513
+ hasOnFileSelect && /* @__PURE__ */ jsxs29("label", { style: { display: "inline-flex", alignItems: "center", marginRight: "16px", cursor: "pointer" }, children: [
8514
+ /* @__PURE__ */ jsx61(
8515
+ "input",
8516
+ {
8517
+ type: "radio",
8518
+ name: "imageSource",
8519
+ value: "select",
8520
+ checked: imageSource === "select",
8521
+ onChange: () => handleImageSourceChange("select"),
8522
+ style: { marginRight: "4px" }
8523
+ }
8524
+ ),
8525
+ t("imageSourceSelect")
8526
+ ] }),
8527
+ hasOnImageChange && /* @__PURE__ */ jsxs29("label", { style: { display: "inline-flex", alignItems: "center", marginRight: "16px", cursor: "pointer" }, children: [
8491
8528
  /* @__PURE__ */ jsx61(
8492
8529
  "input",
8493
8530
  {
@@ -8495,7 +8532,7 @@ function ImageUrlDialog({
8495
8532
  name: "imageSource",
8496
8533
  value: "file",
8497
8534
  checked: imageSource === "file",
8498
- onChange: () => setImageSource("file"),
8535
+ onChange: () => handleImageSourceChange("file"),
8499
8536
  style: { marginRight: "4px" }
8500
8537
  }
8501
8538
  ),
@@ -8509,7 +8546,7 @@ function ImageUrlDialog({
8509
8546
  name: "imageSource",
8510
8547
  value: "url",
8511
8548
  checked: imageSource === "url",
8512
- onChange: () => setImageSource("url"),
8549
+ onChange: () => handleImageSourceChange("url"),
8513
8550
  style: { marginRight: "4px" }
8514
8551
  }
8515
8552
  ),
@@ -8536,6 +8573,30 @@ function ImageUrlDialog({
8536
8573
  placeholder: "https://example.com/image.jpg"
8537
8574
  }
8538
8575
  )
8576
+ ] }) : imageSource === "select" ? /* @__PURE__ */ jsxs29("div", { style: { marginBottom: "8px" }, children: [
8577
+ /* @__PURE__ */ jsx61(
8578
+ "button",
8579
+ {
8580
+ type: "button",
8581
+ onClick: () => void handleFileSelectFromPicker(),
8582
+ disabled: isUploading,
8583
+ style: {
8584
+ padding: "8px 16px",
8585
+ backgroundColor: isUploading ? "#ccc" : "#0078d4",
8586
+ color: isUploading ? "#666" : "white",
8587
+ border: "none",
8588
+ borderRadius: "4px",
8589
+ cursor: isUploading ? "not-allowed" : "pointer",
8590
+ marginBottom: "8px",
8591
+ fontWeight: "bold"
8592
+ },
8593
+ children: isUploading ? t("uploading") : t("imageSourceSelect")
8594
+ }
8595
+ ),
8596
+ uploadedUrl && /* @__PURE__ */ jsx61("div", { style: { marginTop: "8px", padding: "8px", backgroundColor: "var(--shade-100)", borderRadius: "4px" }, children: /* @__PURE__ */ jsxs29("div", { style: { color: "green", marginBottom: "4px" }, children: [
8597
+ "\u2713 ",
8598
+ t("uploadComplete")
8599
+ ] }) })
8539
8600
  ] }) : /* @__PURE__ */ jsxs29("div", { style: { marginBottom: "8px" }, children: [
8540
8601
  /* @__PURE__ */ jsx61(
8541
8602
  "input",
@@ -9472,7 +9533,8 @@ function Editable2({
9472
9533
  placeholder,
9473
9534
  className,
9474
9535
  style,
9475
- onImageChange
9536
+ onImageChange,
9537
+ onFileSelect
9476
9538
  }) {
9477
9539
  const [isRawMode, setIsRawMode] = useState13(false);
9478
9540
  const [rawText, setRawText] = useState13(value);
@@ -9495,7 +9557,6 @@ function Editable2({
9495
9557
  throttleInMs,
9496
9558
  { leading: false, trailing: true }
9497
9559
  ),
9498
- // eslint-disable-next-line react-hooks/exhaustive-deps
9499
9560
  [editor, throttleInMs]
9500
9561
  );
9501
9562
  const onSlateChange = useCallback18(() => {
@@ -9560,6 +9621,7 @@ function Editable2({
9560
9621
  setIsRawMode(!isRawMode);
9561
9622
  };
9562
9623
  editor.wysimark.onImageChange = onImageChange;
9624
+ editor.wysimark.onFileSelect = onFileSelect;
9563
9625
  editor.wysimark.onChange = onChange;
9564
9626
  const disableRawMode = editor.wysimark.disableRawMode;
9565
9627
  return /* @__PURE__ */ jsxs33("div", { style: { position: "relative" }, children: [