Set newly uploaded note images to small size

This commit is contained in:
tianma-if committed 2026-09-24 17:37:46 +08:00
1 parent fd88ded9ca
commit ec5e7bc8d6
8 files changed
+693 -684

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -45,6 +45,7 @@ import {
import { createEdgeEverMathematics } from "@edgeever/shared/mathematics";
import { createIosImageGallery } from "./document-nodes";
import { createImageInsertTransaction, groupUploadedImages, NATIVE_IMAGE_GALLERY_CSS } from "@edgeever/shared/native-image-gallery";
import { NEW_IMAGE_WIDTH_PERCENT } from "@edgeever/shared/image-display";
const galleryStyle = document.createElement("style");
galleryStyle.textContent = NATIVE_IMAGE_GALLERY_CSS;
@@ -1523,7 +1524,7 @@ const api: EdgeEverEditorAPI = {
editor
.chain()
.focus()
.setImage({ src: previewDataUrl, alt: uploadId })
.setImage({ src: previewDataUrl, alt: uploadId, width: NEW_IMAGE_WIDTH_PERCENT })
.run();
// mark last image
const imgs = editorEl.querySelectorAll("img");
@@ -1536,6 +1537,7 @@ const api: EdgeEverEditorAPI = {
if (!editor.isEditable) return;
editor.view.dispatch(createImageInsertTransaction(editor.state, {
src: imageUrl, alt: alt || uploadId || "",
width: NEW_IMAGE_WIDTH_PERCENT,
}));
emitChange(editor);
},
@@ -54,6 +54,7 @@ import {
import { createEdgeEverMathematics } from "@edgeever/shared/mathematics";
import {
DEFAULT_IMAGE_WIDTH_PERCENT,
NEW_IMAGE_WIDTH_PERCENT,
IMAGE_WIDTH_PRESETS,
clampImageWidth,
parseImageWidth,
@@ -2922,7 +2923,7 @@ const insertImageUploadPlaceholder = (
alt,
src: source,
title: previewDataUrl,
width: DEFAULT_IMAGE_WIDTH_PERCENT,
width: NEW_IMAGE_WIDTH_PERCENT,
}, selection ?? editor.state.selection);
tr.setMeta(TRANSIENT_IMAGE_UPLOAD_META, true);
editor.view.dispatch(tr);
+2 -2
View File
@@ -132,7 +132,7 @@ import {
createMemoLinkHref,
parseMemoLinkHref,
} from "@edgeever/shared";
import { DEFAULT_IMAGE_WIDTH_PERCENT } from "@edgeever/shared/image-display";
import { NEW_IMAGE_WIDTH_PERCENT } from "@edgeever/shared/image-display";
import { EdgeEverLink } from "@edgeever/shared/editor-link";
import { createEdgeEverMathematics } from "@edgeever/shared/mathematics";
import { codeBlockLowlight, EdgeEverCodeBlock } from "@/lib/code-block";
@@ -1003,7 +1003,7 @@ const RichEditorPane = ({
src: resource.url,
alt: file.name,
title: file.name,
width: DEFAULT_IMAGE_WIDTH_PERCENT,
width: NEW_IMAGE_WIDTH_PERCENT,
},
};
}
@@ -9,6 +9,7 @@ import { mergeAttributes } from "@tiptap/core";
import Placeholder from "@tiptap/extension-placeholder";
import { createExcerpt, createEdgeEverDocumentExtensions, docToMarkdown, docToText, emptyDoc, getImageReferrerPolicy, isPdfAttachment, wrapDetailsContentHtml, type MemoDetail, type MemoEditSession, type Notebook, type TagSummary, type TiptapDoc } from "@edgeever/shared";
import { createEdgeEverMathematics } from "@edgeever/shared/mathematics";
import { NEW_IMAGE_WIDTH_PERCENT } from "@edgeever/shared/image-display";
import { getMobileEditorInputAttributes, getMobileEditorPlaceholder } from "@edgeever/shared/mobile-editor";
import { EdgeEverLink } from "@edgeever/shared/editor-link";
import { createInlineFieldExtension } from "@/components/editor/InlineField";
@@ -633,6 +634,7 @@ export const MobileStandaloneTiptapEditor = ({
src: resource.url,
alt: file.name,
title: file.name,
width: NEW_IMAGE_WIDTH_PERCENT,
})
.run();
} else if (isPdfAttachment(file.type, resource.filename || file.name)) {
@@ -1,6 +1,7 @@
import { describe, expect, test } from "bun:test";
import {
DEFAULT_IMAGE_WIDTH_PERCENT,
NEW_IMAGE_WIDTH_PERCENT,
IMAGE_WIDTH_PRESETS,
clampImageWidth,
parseImageWidth,
@@ -9,6 +10,7 @@ import {
describe("shared image display widths", () => {
test("keeps the four editor presets stable across clients", () => {
expect(DEFAULT_IMAGE_WIDTH_PERCENT).toBe(72);
expect(NEW_IMAGE_WIDTH_PERCENT).toBe(IMAGE_WIDTH_PRESETS[0].width);
expect(IMAGE_WIDTH_PRESETS.map(({ id, width }) => [id, width])).toEqual([
["small", 35],
["medium", 50],
+2
View File
@@ -9,6 +9,8 @@ export const IMAGE_WIDTH_PRESETS = [
{ id: "full", width: 100, labelKey: "editor.imageSizeFull" },
] as const;
export const NEW_IMAGE_WIDTH_PERCENT = IMAGE_WIDTH_PRESETS[0].width;
export type ImageWidthPresetId = (typeof IMAGE_WIDTH_PRESETS)[number]["id"];
export const clampImageWidth = (width: number): number =>