Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ var allTerrainFormsWidget = function(exports) {
unsubscribe?.();
};
}
const registryHost = window;
const registry = registryHost.openStationWidgets || registryHost.desktopModeWidgets || {};
registry["allterrain-forms/recent"] = renderWidget;
registryHost.openStationWidgets = registryHost.desktopModeWidgets = registry;
function mountStandalone() {
document.querySelectorAll("[data-atfw-root]").forEach((host) => {
if (host.dataset.atfwMounted) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/widget.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,22 @@ export function renderWidget( host: HTMLElement ): () => void {
* overwritten a moment later by the bundle itself, which is a bug that only
* shows up in the built file and never in a test.
*
* So the contract is expressed as an export instead: the shell finds
* `window.allTerrainFormsWidget.render` because `render` is what this module
* exports.
* The export stays for anything that reads that global. The shell itself does
* not: OpenStation looks up mount callbacks by widget id in
* `window.openStationWidgets` (`window.desktopModeWidgets` on older Desktop
* Mode builds), so the callback is registered there too. That is a different
* global from the one the IIFE overwrites, so assigning it here is safe.
*/
export { renderWidget as render };

type WidgetRegistry = Record< string, ( host: HTMLElement ) => ( () => void ) | void >;

// Merge, never replace: other plugins' widgets live in the same object.
const registryHost = window as unknown as { openStationWidgets?: WidgetRegistry; desktopModeWidgets?: WidgetRegistry };
const registry: WidgetRegistry = registryHost.openStationWidgets || registryHost.desktopModeWidgets || {};
registry[ 'allterrain-forms/recent' ] = renderWidget;
registryHost.openStationWidgets = registryHost.desktopModeWidgets = registry;

/**
* Mounts into a plain container, for the admin page.
*
Expand Down
Loading