AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
Show upload placeholders for all note attachments
tianma-if474c4e978027
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex e8b7c11b..5c60c56b 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -71,7 +71,7 @@ import { useEditorMarkdownMode } from "./editor/useEditorMarkdownMode";import {ImageUploadPlaceholderExtension,addImageUploadPlaceholder,- createImageUploadPlaceholder,+ createResourceUploadPlaceholder,removeImageUploadPlaceholder,waitForImageSourceReady,updateImageUploadPlaceholder,@@ -1022,14 +1022,14 @@ const RichEditorPane = ({const targetMemoId = currentMemo.id;const interactionVersionAtRequest = editorCanvasInteractionVersionRef.current;const placeholderPosition = currentEditor.state.selection.from;- const imagePlaceholderByFile = new Map(files- .filter((file) => SUPPORTED_PASTE_IMAGE_TYPES.has(file.type))- .map((file) => [file, createImageUploadPlaceholder(- file,- t("editor.uploadState.imagePreparing"),- )] as const));- const imagePlaceholders = [...imagePlaceholderByFile.values()];- imagePlaceholders.forEach((placeholder) => {+ const placeholderByFile = new Map(files.map((file) => [file,+ createResourceUploadPlaceholder(file, {+ imagePreparing: t("editor.uploadState.imagePreparing"),+ fileWaiting: t("editor.uploadState.waitingToUpload"),+ }),+ ] as const));+ const placeholders = [...placeholderByFile.values()];+ placeholders.forEach((placeholder) => {addImageUploadPlaceholder(currentEditor, placeholder, placeholderPosition);});@@ -1052,9 +1052,9 @@ const RichEditorPane = ({const results = await processFileUploadBatch(files, async (file) => {const isImage = SUPPORTED_PASTE_IMAGE_TYPES.has(file.type);const shouldCompress = isImage && imageCompressionEnabledRef.current;- const placeholder = imagePlaceholderByFile.get(file);+ const placeholder = placeholderByFile.get(file);if (placeholder) updateImageUploadPlaceholder(editorRef.current, placeholder,- t(shouldCompress ? "editor.uploadState.imageCompressing" : "editor.uploadState.uploading"));+ t(shouldCompress ? "editor.uploadState.imageCompressing" : "editor.uploadState.waitingToUpload"));setImageUploadState(shouldCompress ? "compressing" : "uploading");const preparedFile = shouldCompress ? (await compressImageForUpload(file)).file : file;if (placeholder) updateImageUploadPlaceholder(editorRef.current, placeholder,@@ -1062,7 +1062,7 @@ const RichEditorPane = ({return preparedFile;}, async (uploadFile, file) => {const isImage = SUPPORTED_PASTE_IMAGE_TYPES.has(file.type);- const placeholder = imagePlaceholderByFile.get(file);+ const placeholder = placeholderByFile.get(file);setImageUploadState("uploading");if (placeholder) updateImageUploadPlaceholder(editorRef.current, placeholder,t("editor.uploadState.uploading"));@@ -1165,7 +1165,7 @@ const RichEditorPane = ({}}).finally(() => {const placeholderEditor = editorRef.current;- imagePlaceholders.forEach((placeholder) => {+ placeholders.forEach((placeholder) => {removeImageUploadPlaceholder(placeholderEditor, placeholder);});});diff --git a/apps/web/src/components/editor/image-upload-placeholder.test.mjs b/apps/web/src/components/editor/image-upload-placeholder.test.mjsindex 57ffd528..ab6ab7df 100644--- a/apps/web/src/components/editor/image-upload-placeholder.test.mjs+++ b/apps/web/src/components/editor/image-upload-placeholder.test.mjs@@ -4,8 +4,11 @@ import { EditorState } from "@tiptap/pm/state";import {IMAGE_UPLOAD_PLACEHOLDER_PLUGIN_KEY,addImageUploadPlaceholder,+ createFileUploadPlaceholder,createImageUploadPlaceholderPlugin,+ createResourceUploadPlaceholder,removeImageUploadPlaceholder,+ updateImageUploadPlaceholder,} from "./image-upload-placeholder.ts";const placeholder = {@@ -13,9 +16,88 @@ const placeholder = {filename: "photo.png",previewUrl: null,statusLabel: "Processing image",+ kind: "image",};-describe("image upload placeholder", () => {+describe("resource upload placeholder", () => {+ test("uses the loading card for non-PDF attachment types too", () => {+ const files = [+ new File(["notes"], "notes.txt", { type: "text/plain" }),+ new File(["zip"], "archive.zip", { type: "application/zip" }),+ new File(["audio"], "recording.mp3", { type: "audio/mpeg" }),+ new File(["video"], "clip.mp4", { type: "video/mp4" }),+ new File(["doc"], "report.docx", { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }),+ new File(["data"], "unknown.bin"),+ ];+ for (const file of files) {+ const pending = createResourceUploadPlaceholder(file, {+ imagePreparing: "Preparing image",+ fileWaiting: "Waiting to upload",+ });+ expect(pending.kind).toBe("file");+ expect(pending.filename).toBe(file.name);+ expect(pending.statusLabel).toBe("Waiting to upload");+ }+ });++ test("shows a file card and updates its upload status before insertion", () => {+ const file = new File(["pdf"], "estimate.pdf", { type: "application/pdf" });+ const pending = createFileUploadPlaceholder(file, "Waiting to upload");+ const schema = new Schema({+ nodes: {+ doc: { content: "block+" },+ paragraph: { content: "inline*", group: "block" },+ text: { group: "inline" },+ },+ });+ const editor = {+ isDestroyed: false,+ state: EditorState.create({ schema, plugins: [createImageUploadPlaceholderPlugin()] }),+ view: {+ dispatch(transaction) { editor.state = editor.state.apply(transaction); },+ dom: null,+ },+ };+ addImageUploadPlaceholder(editor, pending);+ const widget = IMAGE_UPLOAD_PLACEHOLDER_PLUGIN_KEY.getState(editor.state)?.find()[0];+ expect(widget).toBeDefined();++ const makeElement = (tagName) => ({+ tagName,+ className: "",+ dataset: {},+ children: [],+ attributes: {},+ textContent: "",+ setAttribute(name, value) { this.attributes[name] = value; },+ appendChild(child) { this.children.push(child); },+ querySelector(selector) {+ if (selector.startsWith("[data-placeholder-id=")) {+ return this.dataset.placeholderId === pending.id ? this : null;+ }+ const className = selector.slice(1);+ return this.children.find((child) => child.className === className)+ ?? this.children.map((child) => child.querySelector(selector)).find(Boolean)+ ?? null;+ },+ });+ const originalDocument = globalThis.document;+ globalThis.document = { createElement: makeElement, createElementNS: (_, tagName) => makeElement(tagName) };+ try {+ editor.view.dom = widget.type.toDOM();+ expect(editor.view.dom.className).toBe("edgeever-file-upload-placeholder");+ expect(editor.view.dom.querySelector(".edgeever-file-upload-placeholder__filename")?.textContent)+ .toBe("estimate.pdf");+ expect(editor.view.dom.attributes["aria-label"]).toBe("Waiting to upload: estimate.pdf");+ updateImageUploadPlaceholder(editor, pending, "Uploading");+ expect(editor.view.dom.querySelector(".edgeever-upload-placeholder__label")?.textContent)+ .toBe("Uploading");+ expect(editor.view.dom.attributes["aria-label"]).toBe("Uploading: estimate.pdf");+ } finally {+ globalThis.document = originalDocument;+ }+ });+test("appears immediately, follows document changes, and can be removed", () => {const schema = new Schema({nodes: {diff --git a/apps/web/src/components/editor/image-upload-placeholder.ts b/apps/web/src/components/editor/image-upload-placeholder.tsindex b710c9c2..b069eb16 100644--- a/apps/web/src/components/editor/image-upload-placeholder.ts+++ b/apps/web/src/components/editor/image-upload-placeholder.ts@@ -1,12 +1,14 @@import { Extension, type Editor } from "@tiptap/core";import { Plugin, PluginKey } from "@tiptap/pm/state";import { Decoration, DecorationSet } from "@tiptap/pm/view";+import { SUPPORTED_PASTE_IMAGE_TYPES } from "./editor-pane-helpers";export type ImageUploadPlaceholder = {id: string;filename: string;previewUrl: string | null;statusLabel: string;+ kind: "image" | "file";};type ImageUploadPlaceholderAction =@@ -21,13 +23,35 @@ export const IMAGE_UPLOAD_PLACEHOLDER_PLUGIN_KEY = new PluginKey<DecorationSet>(const renderPlaceholder = (placeholder: ImageUploadPlaceholder) => {const element = document.createElement("figure");- element.className = "edgeever-image-upload-placeholder";+ const isFile = placeholder.kind === "file";+ element.className = isFile ? "edgeever-file-upload-placeholder" : "edgeever-image-upload-placeholder";element.contentEditable = "false";element.dataset.placeholderId = placeholder.id;element.setAttribute("role", "status");element.setAttribute("aria-label", `${placeholder.statusLabel}: ${placeholder.filename}`);- if (placeholder.previewUrl) {+ if (isFile) {+ const icon = document.createElement("span");+ icon.className = "edgeever-file-upload-placeholder__icon";+ icon.setAttribute("aria-hidden", "true");+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");+ svg.setAttribute("viewBox", "0 0 24 24");+ svg.setAttribute("fill", "none");+ svg.setAttribute("stroke", "currentColor");+ svg.setAttribute("stroke-width", "1.8");+ svg.setAttribute("stroke-linecap", "round");+ svg.setAttribute("stroke-linejoin", "round");+ const outline = document.createElementNS("http://www.w3.org/2000/svg", "path");+ outline.setAttribute("d", "M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z M13 2v7h7 M8 14h8 M8 18h6");+ svg.appendChild(outline);+ icon.appendChild(svg);+ element.appendChild(icon);++ const filename = document.createElement("span");+ filename.className = "edgeever-file-upload-placeholder__filename";+ filename.textContent = placeholder.filename;+ element.appendChild(filename);+ } else if (placeholder.previewUrl) {const preview = document.createElement("img");preview.className = "edgeever-image-upload-placeholder__preview";preview.src = placeholder.previewUrl;@@ -38,14 +62,16 @@ const renderPlaceholder = (placeholder: ImageUploadPlaceholder) => {}const status = document.createElement("figcaption");- status.className = "edgeever-image-upload-placeholder__status";+ status.className = isFile+ ? "edgeever-file-upload-placeholder__status"+ : "edgeever-image-upload-placeholder__status";const spinner = document.createElement("span");spinner.className = "edgeever-image-upload-placeholder__spinner";spinner.setAttribute("aria-hidden", "true");const label = document.createElement("span");- label.className = "edgeever-image-upload-placeholder__label";+ label.className = "edgeever-upload-placeholder__label";label.textContent = placeholder.statusLabel;status.appendChild(spinner);status.appendChild(label);@@ -108,9 +134,32 @@ export const createImageUploadPlaceholder = (filename: file.name,previewUrl,statusLabel,+ kind: "image",};};+export const createFileUploadPlaceholder = (+ file: File,+ statusLabel: string,+): ImageUploadPlaceholder => {+ nextPlaceholderId += 1;+ return {+ id: `file-upload-${nextPlaceholderId}`,+ filename: file.name,+ previewUrl: null,+ statusLabel,+ kind: "file",+ };+};++/** Every accepted resource gets an immediate placeholder; images keep their local preview. */+export const createResourceUploadPlaceholder = (+ file: File,+ labels: { imagePreparing: string; fileWaiting: string },+): ImageUploadPlaceholder => SUPPORTED_PASTE_IMAGE_TYPES.has(file.type)+ ? createImageUploadPlaceholder(file, labels.imagePreparing)+ : createFileUploadPlaceholder(file, labels.fileWaiting);+export const addImageUploadPlaceholder = (editor: Editor,placeholder: ImageUploadPlaceholder,@@ -148,7 +197,7 @@ export const updateImageUploadPlaceholder = (// Update the widget in place so its decoded local preview stays mounted.const element = editor.view.dom.querySelector(`[data-placeholder-id="${placeholder.id}"]`);element?.setAttribute("aria-label", `${statusLabel}: ${placeholder.filename}`);- const label = element?.querySelector(".edgeever-image-upload-placeholder__label");+ const label = element?.querySelector(".edgeever-upload-placeholder__label");if (label) label.textContent = statusLabel;};diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.cssindex 710283f8..d86a78b4 100644--- a/apps/web/src/styles/globals.css+++ b/apps/web/src/styles/globals.css@@ -1922,6 +1922,56 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {animation: edgeever-image-placeholder-spin 700ms linear infinite;}+.ProseMirror .edgeever-file-upload-placeholder {+ display: flex;+ align-items: center;+ gap: 0.75rem;+ width: min(100%, 48rem);+ min-height: 3.5rem;+ margin: 0.5rem 0;+ padding: 0.75rem 1rem;+ border: 1px solid var(--brand-green-border);+ border-radius: 0.75rem;+ background: rgb(var(--slate-100-rgb) / 0.55);+ box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);+ line-height: normal;+}++.ProseMirror .edgeever-file-upload-placeholder__icon {+ display: flex;+ flex: none;+ width: 1.4rem;+ height: 1.4rem;+ color: var(--brand-green);+}++.ProseMirror .edgeever-file-upload-placeholder__icon svg {+ width: 100%;+ height: 100%;+}++.ProseMirror .edgeever-file-upload-placeholder__filename {+ min-width: 0;+ overflow: hidden;+ color: rgb(var(--slate-800-rgb));+ font-size: 0.875rem;+ font-weight: 600;+ text-overflow: ellipsis;+ white-space: nowrap;+}++.ProseMirror .edgeever-file-upload-placeholder__status {+ display: inline-flex;+ flex: none;+ align-items: center;+ gap: 0.4rem;+ margin-left: auto;+ color: rgb(var(--slate-500-rgb));+ font-size: 0.75rem;+ font-weight: 600;+ white-space: nowrap;+}+@keyframes edgeever-image-placeholder-shimmer {to { background-position: calc(100% + 18rem) 0, 0 0; }}