wysimark-lite 0.25.11 → 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
  }
@@ -8264,7 +8266,6 @@ function TableDialog({
8264
8266
  }
8265
8267
 
8266
8268
  // src/toolbar-plugin/components/toolbar/toolbar.tsx
8267
- import debounce from "lodash.debounce";
8268
8269
  import { useEffect as useEffect9, useRef as useRef13, useState as useState11 } from "react";
8269
8270
  import { useSlateStatic as useSlateStatic20 } from "slate-react";
8270
8271
 
@@ -8404,13 +8405,20 @@ function ImageUrlDialog({
8404
8405
  }, []);
8405
8406
  const savedState = editor.wysimark?.imageDialogState;
8406
8407
  const hasOnImageChange = !!editor.wysimark?.onImageChange;
8408
+ const hasOnFileSelect = !!editor.wysimark?.onFileSelect;
8409
+ const defaultSource = savedState?.imageSource ?? (hasOnFileSelect ? "select" : hasOnImageChange ? "file" : "url");
8407
8410
  const [url, setUrl] = useState9(savedState?.url ?? "");
8408
8411
  const [alt, setAlt] = useState9(savedState?.alt ?? "");
8409
8412
  const [title, setTitle] = useState9(savedState?.title ?? "");
8410
8413
  const [titleManuallyEdited, setTitleManuallyEdited] = useState9(false);
8411
- const [imageSource, setImageSource] = useState9(savedState?.imageSource ?? (hasOnImageChange ? "file" : "url"));
8414
+ const [imageSource, setImageSource] = useState9(defaultSource);
8412
8415
  const [isUploading, setIsUploading] = useState9(false);
8413
8416
  const [uploadedUrl, setUploadedUrl] = useState9(savedState?.uploadedUrl ?? "");
8417
+ const handleImageSourceChange = (source) => {
8418
+ setImageSource(source);
8419
+ setUploadedUrl("");
8420
+ setUploadedFileName("");
8421
+ };
8414
8422
  const [uploadedFileName, setUploadedFileName] = useState9("");
8415
8423
  const handleAltChange = useCallback14((e) => {
8416
8424
  const newAlt = e.target.value;
@@ -8427,7 +8435,7 @@ function ImageUrlDialog({
8427
8435
  if (editor.wysimark) {
8428
8436
  editor.wysimark.imageDialogState = { url, alt, title, imageSource, uploadedUrl };
8429
8437
  }
8430
- }, [url, alt, title, imageSource, uploadedUrl]);
8438
+ }, [editor, url, alt, title, imageSource, uploadedUrl]);
8431
8439
  const clearState = () => {
8432
8440
  if (editor.wysimark) {
8433
8441
  editor.wysimark.imageDialogState = void 0;
@@ -8454,7 +8462,7 @@ function ImageUrlDialog({
8454
8462
  };
8455
8463
  function handleSubmit(e) {
8456
8464
  e.preventDefault();
8457
- const finalUrl = imageSource === "file" ? uploadedUrl : url;
8465
+ const finalUrl = imageSource === "file" || imageSource === "select" ? uploadedUrl : url;
8458
8466
  if (finalUrl.trim() === "") return;
8459
8467
  editor.image.insertImageFromUrl(finalUrl, alt, title);
8460
8468
  clearState();
@@ -8481,14 +8489,42 @@ function ImageUrlDialog({
8481
8489
  function handleSelectFileClick() {
8482
8490
  fileInputRef.current?.click();
8483
8491
  }
8484
- 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() === "";
8485
8507
  return /* @__PURE__ */ jsxs29(Fragment9, { children: [
8486
8508
  /* @__PURE__ */ jsx61(CloseMask, { close }),
8487
8509
  /* @__PURE__ */ jsxs29($FileDialog, { ref, style, children: [
8488
8510
  /* @__PURE__ */ jsx61(DraggableHeader, { onDrag: handleDrag }),
8489
8511
  /* @__PURE__ */ jsxs29("form", { onSubmit: (e) => void handleSubmit(e), style: { padding: "8px" }, children: [
8490
- hasOnImageChange && /* @__PURE__ */ jsxs29("div", { style: { marginBottom: "12px" }, children: [
8491
- /* @__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: [
8492
8528
  /* @__PURE__ */ jsx61(
8493
8529
  "input",
8494
8530
  {
@@ -8496,7 +8532,7 @@ function ImageUrlDialog({
8496
8532
  name: "imageSource",
8497
8533
  value: "file",
8498
8534
  checked: imageSource === "file",
8499
- onChange: () => setImageSource("file"),
8535
+ onChange: () => handleImageSourceChange("file"),
8500
8536
  style: { marginRight: "4px" }
8501
8537
  }
8502
8538
  ),
@@ -8510,7 +8546,7 @@ function ImageUrlDialog({
8510
8546
  name: "imageSource",
8511
8547
  value: "url",
8512
8548
  checked: imageSource === "url",
8513
- onChange: () => setImageSource("url"),
8549
+ onChange: () => handleImageSourceChange("url"),
8514
8550
  style: { marginRight: "4px" }
8515
8551
  }
8516
8552
  ),
@@ -8537,6 +8573,30 @@ function ImageUrlDialog({
8537
8573
  placeholder: "https://example.com/image.jpg"
8538
8574
  }
8539
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
+ ] }) })
8540
8600
  ] }) : /* @__PURE__ */ jsxs29("div", { style: { marginBottom: "8px" }, children: [
8541
8601
  /* @__PURE__ */ jsx61(
8542
8602
  "input",
@@ -9189,14 +9249,14 @@ function measureItemSetWidth(items, buttonWidth, dividerWidth) {
9189
9249
  }
9190
9250
  return width;
9191
9251
  }
9192
- var WIDTH_BUFFER_PX = 48;
9252
+ var WIDTH_BUFFER_PX = 4;
9193
9253
  function Toolbar() {
9194
9254
  const ref = useRef13(null);
9195
9255
  const [items, setItems] = useState11(initialItems);
9196
9256
  useEffect9(() => {
9257
+ const toolbar = ref.current;
9258
+ if (!toolbar) return;
9197
9259
  const refresh = () => {
9198
- const toolbar = ref.current;
9199
- if (!toolbar) throw new Error("Toolbar not found");
9200
9260
  const widths = getWidths(toolbar);
9201
9261
  if (!widths) return;
9202
9262
  for (let i = 0; i < itemSets.length - 1; i++) {
@@ -9212,13 +9272,10 @@ function Toolbar() {
9212
9272
  }
9213
9273
  setItems(itemSets[itemSets.length - 1]);
9214
9274
  };
9215
- const debouncedRefresh = debounce(refresh, 150);
9216
- const timeoutId = setTimeout(refresh, 0);
9217
- window.addEventListener("resize", debouncedRefresh);
9275
+ const observer = new ResizeObserver(refresh);
9276
+ observer.observe(toolbar);
9218
9277
  return () => {
9219
- clearTimeout(timeoutId);
9220
- debouncedRefresh.cancel();
9221
- window.removeEventListener("resize", debouncedRefresh);
9278
+ observer.disconnect();
9222
9279
  };
9223
9280
  }, []);
9224
9281
  return /* @__PURE__ */ jsx64($ToolbarContainer, { ref, children: /* @__PURE__ */ jsx64($Toolbar, { children: items.map((item, index) => /* @__PURE__ */ jsx64(
@@ -9476,7 +9533,8 @@ function Editable2({
9476
9533
  placeholder,
9477
9534
  className,
9478
9535
  style,
9479
- onImageChange
9536
+ onImageChange,
9537
+ onFileSelect
9480
9538
  }) {
9481
9539
  const [isRawMode, setIsRawMode] = useState13(false);
9482
9540
  const [rawText, setRawText] = useState13(value);
@@ -9499,7 +9557,6 @@ function Editable2({
9499
9557
  throttleInMs,
9500
9558
  { leading: false, trailing: true }
9501
9559
  ),
9502
- // eslint-disable-next-line react-hooks/exhaustive-deps
9503
9560
  [editor, throttleInMs]
9504
9561
  );
9505
9562
  const onSlateChange = useCallback18(() => {
@@ -9564,6 +9621,7 @@ function Editable2({
9564
9621
  setIsRawMode(!isRawMode);
9565
9622
  };
9566
9623
  editor.wysimark.onImageChange = onImageChange;
9624
+ editor.wysimark.onFileSelect = onFileSelect;
9567
9625
  editor.wysimark.onChange = onChange;
9568
9626
  const disableRawMode = editor.wysimark.disableRawMode;
9569
9627
  return /* @__PURE__ */ jsxs33("div", { style: { position: "relative" }, children: [