Skip to content

refactor: split the map editor script into cohesive files - #347

Merged
TheWitness merged 6 commits into
developfrom
refactor/split-editor-js
Nov 11, 2026
Merged

TheWitness merged 6 commits into
developfrom
refactor/split-editor-js

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes 346

Split js/editor.js into editor.dialogs.js, editor.picker.js, editor.compact.js and editor.assets.js.

  • The moved code is byte-for-byte identical; a script rebuilt the original file from the pieces to check. Functions stay browser globals, and each file also exports them through the CommonJS guard editor.js already uses.
  • Both editor pages include the new files right after editor.js through get_md5_include_js, so the CSP nonce applies. No other asset list needed changes.
  • Browser tests now load whole files through a shared loader in tests/Browser/lib/, instead of slicing source by function name. JSDoc for the exported functions is in a separate commit.
  • New tests:
    • each file's exported API;
    • include order and nonce on both pages (PHP E2E);
    • one call into each module with all scripts loaded.
  • Verified: the full Pest suite passes (353), and 30 of 31 browser tests pass. The failure is ClickableHoverTest, which already fails on develop and is fixed in ci: run the jsdom browser tests with locked dependencies #333.
  • Interaction: refactor: build editor image lists with one library scanner #341 adds EditorImageOptionsTest.cjs, which slices editor.js for wmEditorImageSrc(). Whichever of refactor: build editor image lists with one library scanner #341 and this PR merges second needs that test switched to the loader. I'll update it.

Fixes #346

Move the dialog helpers, the graph and icon pickers, the compact link
and node property editors, and the image and colour library out of
js/editor.js into editor.dialogs.js, editor.picker.js,
editor.compact.js and editor.assets.js. The moved code is unchanged.
Functions stay browser globals because inline handlers and the rest of
the editor call them by name; each new file also exports its functions
under CommonJS, as editor.js already does, for Node checks.

Both pages that include editor.js now include the new files right
after it. The browser checks load whole files through a shared helper
instead of slicing source by function name, so moving a function no
longer breaks them silently.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Add JSDoc with a purpose line, parameters and return value to every
function the new editor files export, and to the browser test loader.
Comments that described a single function become its doc block. The
start page renderer, which now includes the new files, gets a purpose
line. Only comments and blank lines change.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Load each split editor script on its own and check that its CommonJS
exports are exactly its top-level functions and that each is also a
browser global. Check that both editor pages include every editor
script once in the loader's order, that no function is declared in two
files, and that one call into each script works once all are loaded.

Render the start page and the editor page head through their PHP code
in a child process with a CSP nonce double, and check each editor
script is included once, in order, with the nonce.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Move the shared loader to tests/Browser/lib/ so a runner that executes
every tests/Browser/*.cjs file does not treat the helper as a test.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
editor.picker.js and editor.compact.js assign graph picker state that
editor.js declares. Record that with /* global */ directives so per-file
analysis sees the declarations, and sort names with localeCompare in
the script API checks.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Keep tests/Browser/README.md as on develop so this PR does not conflict
with the README rewrite in #333; the loader and each check already
describe themselves in their header comments.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@alcatron

alcatron commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Tested 52c5f0f: all 354 PHP tests passed. Of the 31 browser test files, only the existing ClickableHoverTest failed; #333 fixes that.

I also combined this with #341 and confirmed the image-options test needs updating for the split. EditorImageOptionsTest.cjs still extracts wmEditorImageSrc from editor.js. Using the shared loadEditorScripts helper to load editor.js and editor.picker.js fixes that locally. With #333 included, all 33 combined browser test files passed, covering the link workflow, image pickers, notes, label positioning and undo/redo.

So the automated results look good, with that test adjustment needed when the branches come together. I'd still do one focused real-browser check of the combined editor changes for layout and focus behaviour, which the automated DOM tests don't fully cover.

@somethingwithproof

Copy link
Copy Markdown
Member Author

Real-browser check done in Safari 27.2 against Cacti 1.2.32 with #336, #341, #347 and #333 combined. All five split editor scripts load. The node, link, map properties, map style, colours, images and editor settings dialogs each open fully inside the window without covering the toolbar, move focus into the dialog, and close cleanly, with no JavaScript errors.

One thing I noticed: closing a dialog leaves focus on the page rather than returning it to the toolbar button that opened it. develop does the same in Safari, so it isn't from this change; it could be a separate accessibility follow-up.

@alcatron alcatron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rechecked with the updated #341 test. All 33 browser test files now pass together without a local workaround, along with 648 PHP tests. Thanks for doing the Safari dialog and focus checks. Looks good to me; the existing toolbar-focus behaviour can be handled separately.

@TheWitness
TheWitness merged commit 683b35a into develop Nov 11, 2026
9 checks passed
@TheWitness
TheWitness deleted the refactor/split-editor-js branch November 11, 2026 02:13
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.

Split js/editor.js so browser tests stop slicing it by function name

3 participants