refactor(dom): route all DOM access through the Dom module, type it with VNode interfaces - #1441
Open
xdan wants to merge 1 commit into
Open
refactor(dom): route all DOM access through the Dom module, type it with VNode interfaces#1441xdan wants to merge 1 commit into
xdan wants to merge 1 commit into
Conversation
…ith VNode interfaces Preparation for virtual-DOM editing (no public API changes): - New src/types/vdom.d.ts: VNode/VElement/VHTMLElement/VStyle/VText/ VFragment/VDocument — a minimal structural subset of the browser DOM. Browser nodes satisfy the interfaces, so every call site compiles as is. - Dom module: mutation/structural core (append, prepend, after, before, appendChildFirst, detach, unwrap, moveContent, sibling, hide/show) is typed against VNode; moveContent/sibling get overloads so explicitly typed user callbacks keep compiling. Deduplicated first/last (__deepMost), prevWithClass/nextWithClass (__siblingWithClass), simplified after/appendChildFirst, temporaryList no longer uses querySelectorAll. - The contract is pinned by a new 'Virtual DOM contract' suite in dom.test.js: Dom methods run against a hand-rolled non-browser VNode implementation. - Codebase sweep (core, modules, plugins, jodit.ts): no direct appendChild/insertBefore/removeChild/replaceChild left outside the Dom module; .style. property access replaced with css()/VStyle methods; get/setAttribute with attr(); querySelector reduced from 36 call sites to 4 sanctioned ones (user-supplied selectors, pasted stylesheets, BASE_PATH bootstrap). - Sanitizers (safe-html, clean-html/allow-attributes) intentionally keep raw attribute access: attr() kebab-cases names, a sanitizer must not. - VDOM-MIGRATION-IDEAS.md collects the follow-ups that need a minor release (NodeCondition on VNode, css()/cssInline split, attr.raw, guards narrowing to V-types) and the fundamental VDOM blockers.
Contributor
📊 Bundle Size
Validation details✅ All checks passed · Full diff report → (see Artifacts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Groundwork for moving the editor to virtual-DOM editing. No public API changes — parameter types are only widened, return types untouched.
src/types/vdom.d.ts:VNode/VElement/VHTMLElement/VStyle/VText/VFragment/VDocument— a minimal structural subset of the browser DOM. Browser nodes satisfy these interfaces, so all existing call sites compile unchanged.Dommodule is typed against the subset (mutation/structural core:append,prepend,after,before,appendChildFirst,detach,unwrap,moveContent,sibling,hide/show) and deduplicated:first/lastshare one traversal,prevWithClass/nextWithClassshare one helper,after/appendChildFirstsimplified,temporaryListno longer usesquerySelectorAll.dom.test.jsrunsDomagainst a hand-rolled non-browser VNode implementation, pinning the "Dom relies only on the subset" invariant at runtime.core/modules/plugins/jodit.ts(file by file):appendChild/insertBefore/removeChild/replaceChildleft outside theDommodule (was ~207 call sites);.style.property access →css()orVStylemethods (getPropertyValue/setPropertyfor exact inline reads and CSS custom properties);get/setAttribute→attr();querySelectorreduced 36 → 4 sanctioned call sites (user-supplied selectors inselector.ts, pasted-stylesheet selectors inapply-styles.ts,BASE_PATHbootstrap inconstants.ts).safe-html.ts,clean-html/allow-attributes.ts):attr()kebab-cases keys (onLoad→on-load), which a sanitizer must never do. Commented in place.VDOM-MIGRATION-IDEAS.md: follow-ups that need a minor release (NodeConditiononVNode,css()/cssInlinesplit,attr.raw, guards narrowing to V-types, dialog registry) and the fundamental VDOM blockers (Range/Selection, layout measurements,beforeinputas the diff source).Checks
make lint: 0 errors (3 pre-existing complexity warnings), no circular dependenciestsc --noEmit: clean🤖 Generated with Claude Code