feat(richtext-lexical): support copy & pasting and drag & dopping files/images into the editor (#13868)
This PR adds support for inserting images into the rich text editor via both **copy & paste** and **drag & drop**, whether from local files or image DOM nodes. It leverages the bulk uploads UI to provide a smooth workflow for: - Selecting the target collection - Filling in any required fields defined on the uploads collection - Uploading multiple images at once This significantly improves the UX for adding images to rich text, and also works seamlessly when pasting images from external editors like Google Docs or Microsoft Word. Test pre-release: `3.57.0-internal.801ab5a` ## Showcase - drag & drop images from computer https://github.com/user-attachments/assets/c558c034-d2e4-40d8-9035-c0681389fb7b ## Showcase - copy & paste images from computer https://github.com/user-attachments/assets/f36faf94-5274-4151-b141-00aff2b0efa4 ## Showcase - copy & paste image DOM nodes https://github.com/user-attachments/assets/2839ed0f-3f28-4e8d-8b47-01d0cb947edc --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211217132290841
This commit is contained in:
@@ -2,6 +2,8 @@ import type { FormState, UploadEdits } from 'payload'
|
||||
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
import type { InitialForms } from './index.js'
|
||||
|
||||
export type State = {
|
||||
activeIndex: number
|
||||
forms: {
|
||||
@@ -28,8 +30,7 @@ type Action =
|
||||
uploadEdits?: UploadEdits
|
||||
}
|
||||
| {
|
||||
files: FileList
|
||||
initialState: FormState | null
|
||||
forms: InitialForms
|
||||
type: 'ADD_FORMS'
|
||||
}
|
||||
| {
|
||||
@@ -49,16 +50,16 @@ export function formsManagementReducer(state: State, action: Action): State {
|
||||
switch (action.type) {
|
||||
case 'ADD_FORMS': {
|
||||
const newForms: State['forms'] = []
|
||||
for (let i = 0; i < action.files.length; i++) {
|
||||
for (let i = 0; i < action.forms.length; i++) {
|
||||
newForms[i] = {
|
||||
errorCount: 0,
|
||||
formID: crypto.randomUUID ? crypto.randomUUID() : uuidv4(),
|
||||
formID: action.forms[i].formID ?? (crypto.randomUUID ? crypto.randomUUID() : uuidv4()),
|
||||
formState: {
|
||||
...(action.initialState || {}),
|
||||
...(action.forms[i].initialState || {}),
|
||||
file: {
|
||||
initialValue: action.files[i],
|
||||
initialValue: action.forms[i].file,
|
||||
valid: true,
|
||||
value: action.files[i],
|
||||
value: action.forms[i].file,
|
||||
},
|
||||
},
|
||||
uploadEdits: {},
|
||||
|
||||
Reference in New Issue
Block a user