Skip to content

Split out code from telepath/widgets.js #13222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

gasman
Copy link
Contributor

@gasman gasman commented Jul 10, 2025

Preliminary cleanup as part of the work for using Telepath to manage overall edit form state.

entrypoints/admin/telepath/widgets.js has accumulated a lot of widget implementation code (including a large chunk relating to Draftail), probably because of the perception that these are conceptually "within" Telepath, rather than JS classes with a meaningful API in their own right (with Telepath just being the mechanism to map these to Python-side objects).

The goal here is to move these class definitions into client/src/components, and handle the Telepath registration in the most appropriate top-level entrypoint: admin/draftail.js (for DraftailRichTextArea), admin/date-time-chooser.js (for AdminDateInput etc) or admin/telepath/widgets.js (for the 'regular' widgets).

This change requires us to be more rigorous about import order - previously the DraftailRichTextArea only referenced window.draftail within its method code, meaning that it could be defined before or after Draftail was loaded, but now we definitely require telepath to come first. To achieve this, we make it explicit that the telepath registry included with Wagtail is only valid for use within the Wagtail admin - where we load it early in the global includes - and move the wagtail.telepath and wagtail.widget_adapters modules to wagtail.admin.telepath to formalise this.

(Incidentally, it would make sense to reshuffle our chooser widgets to follow the same pattern and have the Telepath registration in chooser-widget.js, rather than having separate chooser-widget-telepath.js and page-chooser-telepath.js endpoints. But at that point I'd be getting completely derailed from working on the form management stuff :-) )

gasman added 15 commits July 10, 2025 12:25
It references wagtailadmin/js/telepath/telepath.js and wagtail.admin.staticfiles, and we don't want wagtail core to depend on code in wagtail.admin. Also, we don't want to encourage use of this registry outside of admin views, as adapters registered here are likely to depend on admin-specific JS includes.
…er it in entrypoints/admin/draftail.js

The definition of DraftailRichTextArea needs to be in index.js because we want to export it as part of the top-level `draftail` API (rather than having to import a submodule of components/Draftail when registering it with telepath), but it also depends on initEditor.
…nstead of widgets.js

This puts them in the same file as the window.init* functions that they depend on, so that we aren't reliant on getting the import order of these two files correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

1 participant