Skip to content

Comments

Add upload lifecycle events#736

Open
MatheusRich wants to merge 1 commit intobasecamp:mainfrom
MatheusRich:upload-lifecycle-events
Open

Add upload lifecycle events#736
MatheusRich wants to merge 1 commit intobasecamp:mainfrom
MatheusRich:upload-lifecycle-events

Conversation

@MatheusRich
Copy link

@MatheusRich MatheusRich commented Feb 17, 2026

Dispatches lexxy:upload-start, lexxy:upload-progress, and lexxy:upload-end events on the editor element during file uploads. This lets consumers react to the upload lifecycle — for example, disabling submit buttons or showing custom progress UI.

Events bubble up from the element with relevant detail (file, progress, error).

Closes #735

@MatheusRich MatheusRich force-pushed the upload-lifecycle-events branch from 79801ff to eeead96 Compare February 17, 2026 14:30
Comment on lines 224 to 227
get #editorElement() {
return this.editor.getRootElement().parentElement
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this. We could instead invert the dependency here and pass editorElement instead of editor?

@MatheusRich I agree this doesn't feel great. this.editor isn't passed in: the reference is created at node init.

Nodes having knowledge of top-level DOM, even if only to fire an event, feels against the grain of Lexical's design. How would you feel about firing a bubbling event against the Node's DOM? This could be achieved by passing the DOM ref we already have in createDOM, or using getElementByKey if the delegate had the node key.

Alternatively, the messages might be passed via registered Lexical commands, but that facade might be too much weight for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelpecher I've changed the implementation. Seems much simpler now. Thank you!

@MatheusRich MatheusRich force-pushed the upload-lifecycle-events branch from eeead96 to ef8fd9d Compare February 20, 2026 15:56
Copy link
Collaborator

@samuelpecher samuelpecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be ok to propose documentation for the new events?

Comment on lines 77 to 86
test "dispatch lexxy:upload-progress during upload" do
visit edit_post_path(posts(:empty))

attach_file file_fixture("example.png") do
click_on "Upload file"
end

assert_image_figure_attachment content_type: "image/png", caption: "example.png"
assert_dispatched_event "lexxy:upload-progress"
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be combined with the test above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Docs were also added.

Dispatch lexxy:upload-start, lexxy:upload-progress, and lexxy:upload-end
events on the editor element during file uploads, letting consumers react
to the upload lifecycle (e.g., disabling submit buttons, showing progress).

Closes basecamp#735

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add events for attachment upload start/end

2 participants