The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix screenshot paste in the rich text editor
Pedro Ladeira0f44cd72f5b6
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 9bf9260746..49e7c8231c 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -19,7 +19,7 @@"prisma:format": "dotenv-flow -e .env -- prisma format --schema=./prisma/schema"},"dependencies": {- "@ai-sdk/anthropic": "^3.0.1",+ "@ai-sdk/anthropic": "^4.0.63","@ai-sdk/react": "^4.0.110","@ai-sdk/rsc": "^3.0.107","@axiomhq/js": "^1.3.1",diff --git a/packages/ui/src/rich-text-area/rich-text-provider.tsx b/packages/ui/src/rich-text-area/rich-text-provider.tsxindex d1b9f51568..87edc9f8a2 100644--- a/packages/ui/src/rich-text-area/rich-text-provider.tsx+++ b/packages/ui/src/rich-text-area/rich-text-provider.tsx@@ -55,6 +55,32 @@ export const DEFAULT_RICH_TEXT_FEATURES = CORE_FEATURES;const OPTIONAL_FEATURES = ["imageControls"] as const;+const PASTE_IMAGE_MIME_TYPES = new Set([+ "image/png",+ "image/jpeg",+ "image/gif",+ "image/webp",+]);++function clipboardImageFiles(data: DataTransfer) {+ const files = Array.from(data.files).filter((file) =>+ PASTE_IMAGE_MIME_TYPES.has(file.type),+ );+ if (files.length > 0) return files;++ for (const item of Array.from(data.items)) {+ if (item.kind !== "file" || !PASTE_IMAGE_MIME_TYPES.has(item.type)) {+ continue;+ }+ const file = item.getAsFile();+ if (file) files.push(file);+ }++ return files;+}++const pastedImageFiles = new WeakMap<ClipboardEvent, File[]>();+export type RichTextFeature =| (typeof FEATURES)[number]| (typeof OPTIONAL_FEATURES)[number];@@ -255,27 +281,12 @@ export const RichTextProvider = forwardRef<}),]),FileHandler.configure({- allowedMimeTypes: [- "image/png",- "image/jpeg",- "image/gif",- "image/webp",- ],+ allowedMimeTypes: [...PASTE_IMAGE_MIME_TYPES],onDrop: (currentEditor, files, pos) => {files.forEach((file) =>handleImageUpload(file, currentEditor, pos),);},- onPaste: (currentEditor, files, htmlContent) => {- if (htmlContent) return false;- files.forEach((file) =>- handleImageUpload(- file,- currentEditor,- currentEditor.state.selection.anchor,- ),- );- },}),]: []),@@ -344,6 +355,63 @@ export const RichTextProvider = forwardRef<editorClassName,),},+ handleDOMEvents: {+ ...editorProps?.handleDOMEvents,+ paste: (view, event) => {+ if (editorProps?.handleDOMEvents?.paste?.(view, event)) {+ return true;+ }++ const data = event.clipboardData;+ if (+ !view.editable ||+ !features.includes("images") ||+ !handleImageUpload ||+ !data+ ) {+ return false;+ }++ const files = clipboardImageFiles(data);+ if (files.length > 0) pastedImageFiles.set(event, files);+ return false;+ },+ },+ handlePaste: (view, event, slice) => {+ if (editorProps?.handlePaste?.(view, event, slice)) return true;++ const currentEditor = editorRef.current;+ const files = pastedImageFiles.get(event);+ if (+ !view.editable ||+ !features.includes("images") ||+ !handleImageUpload ||+ !currentEditor ||+ !files?.length+ ) {+ return false;+ }++ const html = event.clipboardData?.getData("text/html") ?? "";+ const pastedText = (+ html.trim()+ ? new DOMParser().parseFromString(html, "text/html").body+ .textContent+ : event.clipboardData?.getData("text/plain")+ )+ ?.replace(/\u00a0/g, " ")+ .trim();+ if (pastedText) return false;++ files.forEach((file) =>+ handleImageUpload(+ file,+ currentEditor,+ currentEditor.state.selection.anchor,+ ),+ );+ return true;+ },handleClick: (view, pos, event) => {if (editorProps?.handleClick?.(view, pos, event)) return true;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 6eb36ee3bf..85ea99d3fa 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -36,8 +36,8 @@ importers:apps/web:dependencies:'@ai-sdk/anthropic':- specifier: ^3.0.1- version: 3.0.1([email protected])+ specifier: ^4.0.63+ version: 4.0.63([email protected])'@ai-sdk/react':specifier: ^4.0.110version: 4.0.110([email protected])([email protected])@@ -1026,9 +1026,9 @@ packages:'@adobe/[email protected]':resolution: {integrity: sha512-Elp+iwUx5rN5+Y8xLt5/GRoG20WGoDCQ/1Fb+1LiGtvwbDavuSk0jhD/eZdckHAuzcDzccnkv+rEjyWfRx18gg==}- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-MOiwKs76ilEmau/WRMnGWlheTUoB+cbvXCse+SAtpW5ATLreInsuYlspLABn12Dxu3w1Xzke1dT+tmEnxhy9SA==}- engines: {node: '>=18'}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-DuhaMr18pIvTLOd8sNm+kc1T/Uh0lv3prNKhgFMp0yXEnLy1MeHdoiokaimwHINPqI/9JzAiHZO/rq19L7iRQA==}+ engines: {node: '>=22'}peerDependencies:zod: ^3.25.76 || ^4.1.8@@ -1044,26 +1044,26 @@ packages:peerDependencies:zod: ^3.25.76 || ^4.1.8- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-de2v8gH9zj47tRI38oSxhQIewmNc+OZjYIOOaMoVWKL65ERSav2PYYZHPSPCrfOeLMkv+Dyh8Y0QGwkO29wMWQ==}- engines: {node: '>=18'}- peerDependencies:- zod: ^3.25.76 || ^4.1.8-'@ai-sdk/[email protected]':resolution: {integrity: sha512-gLuaCups8OCIRz3eO6WWz5op7VLYNNtFzyH0sWUr0FE9v7cTxR0qxDpQdrKnGcql+9WWttobjnZsJVsuEbsPQQ==}engines: {node: '>=22'}peerDependencies:zod: ^3.25.76 || ^4.1.8- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-m9ka3ptkPQbaHHZHqDXDF9C9B5/Mav0KTdky1k2HZ3/nrW2t1AgObxIVPyGDWQNS9FXT/FS6PIoSjpcP/No8rQ==}- engines: {node: '>=18'}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-NZQ1hMxY6Hd4ZiinjpU5HUOsyCHiTFkHw7AiM1EVN+Cd3kNTi47flZWNvFwGqnBojntB1+2eBRTeHRuVLtPhEg==}+ engines: {node: '>=22'}+ peerDependencies:+ zod: ^3.25.76 || ^4.1.8'@ai-sdk/[email protected]':resolution: {integrity: sha512-VYMBxIQdcHqbIf1j+YZlI9Ati6LZ4wJe0GGd4z4a5H/KxTggjeOiyaVYTnfF7LHZK5jMQ+rofmzz4QPqf++NUw==}engines: {node: '>=22'}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-+GZJIgz1jk86pwEbb3f1BD2bdoSKyWE4Jg4YUc7NMnMozbWemSKYZcw2F4nMaO5qwsL5A8RmioAKW81YktRpIQ==}+ engines: {node: '>=22'}+'@ai-sdk/[email protected]':resolution: {integrity: sha512-5WSYzAwdnECdDekICJjj2e83793YYNAcTk8yAEvt/sxme1NXTE3OWr3QLSJPjkyOaa6XAmJ6iE/R9l+2YvcI3Q==}engines: {node: '>=22'}@@ -8172,10 +8172,6 @@ packages:resolution: {integrity: sha512-T1C0XCUimhxVQzW4zFipdx0SficT651NnkR0ZSH3yQwh+mFMdLfgjABVi4YtMTtaL4s168593DaoaRLMqryavA==}engines: {node: '>=18.0.0'}- resolution: {integrity: sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==}- engines: {node: '>=18.0.0'}-resolution: {integrity: sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==}engines: {node: '>=18.0.0'}@@ -13727,10 +13723,10 @@ snapshots:'@adobe/[email protected]':optional: true- '@ai-sdk/[email protected]([email protected])':+ '@ai-sdk/[email protected]([email protected])':dependencies:- '@ai-sdk/provider': 3.0.0- '@ai-sdk/provider-utils': 4.0.1([email protected])+ '@ai-sdk/provider': 4.0.18+ '@ai-sdk/provider-utils': 5.0.47([email protected])zod: 4.3.5'@ai-sdk/[email protected]([email protected])':@@ -13748,27 +13744,29 @@ snapshots:pkce-challenge: 5.0.1zod: 4.3.5- '@ai-sdk/[email protected]([email protected])':+ '@ai-sdk/[email protected]([email protected])':dependencies:- '@ai-sdk/provider': 3.0.0+ '@ai-sdk/provider': 4.0.17'@standard-schema/spec': 1.1.0- eventsource-parser: 3.0.6+ '@workflow/serde': 4.1.0+ eventsource-parser: 3.1.1+ undici: 7.29.0zod: 4.3.5- '@ai-sdk/[email protected]([email protected])':+ '@ai-sdk/[email protected]([email protected])':dependencies:- '@ai-sdk/provider': 4.0.17+ '@ai-sdk/provider': 4.0.18'@standard-schema/spec': 1.1.0'@workflow/serde': 4.1.0eventsource-parser: 3.1.1undici: 7.29.0zod: 4.3.5- '@ai-sdk/[email protected]':+ '@ai-sdk/[email protected]':dependencies:json-schema: 0.4.0- '@ai-sdk/[email protected]':+ '@ai-sdk/[email protected]':dependencies:json-schema: 0.4.0@@ -22397,13 +22395,11 @@ snapshots:optional: true- [email protected]: {}-dependencies:- eventsource-parser: 3.0.6+ eventsource-parser: 3.1.1optional: true