refactor: extract view fullscreen manager

This commit is contained in:
zsviczian committed 2026-08-09 12:17:21 +02:00
1 parent da9dd0fa0b
commit f1e089930b
3 files changed
+193 -123

No files matched your search

+16 -7
View File
@@ -27,6 +27,7 @@ validated, and what remains uncertain.
| Remove confirmed dead `main.ts` code | Implemented; awaiting manual validation | Removed the uncalled cache-registration method and the never-assigned duplicate file-explorer observer field/cleanup; the active observer in `ObserverManager` remains unchanged |
| Extract view export pipeline | Implemented; awaiting manual validation | `ViewExportManager` now owns raw scene, SVG, PNG, clipboard, PDF, option-resolution, and alternate-theme embedded-file export behavior; all view methods and `exportDialog` compatibility remain intact |
| Remove inert `ExcalidrawView` fragments | Complete | Removed obsolete commented declarations, experiments, debug calls, and alternative implementations; no active code or workaround documentation changed |
| Extract view fullscreen handling | Implemented; awaiting manual validation | `ViewFullscreenManager` now owns the existing document-scoped fullscreen class and style mutations while `ExcalidrawView` retains its public compatibility methods |
| Audit and consolidate duplicate logic | In progress | Consolidated `updateFrontmatterInString()`, `arrayToMap()`, `wrapTextAtCharLength()`, `getLinkParts()`/`LinkParts`, `getBinaryFileFromDataURL()`, `svgToBase64()`, `getFontDataURL()`, `cropCanvas()`, `getImageSize()`, `promiseTry()`, `isVersionNewerThanOther()`, `repositionElementsToCursor()`, the internal `cloneElement()`, and `getBoundTextElementId()`; continue one independently testable helper family at a time |
| Remaining view phases | Planned | Begin only after the export-manager checkpoint is manually validated |
@@ -62,6 +63,7 @@ validated, and what remains uncertain.
| 2026-08-09 | Rejected a catch-all Markdown integration manager and removed proven dead code from `main.ts` | Markdown post-processing, install-codeblock handling, observer setup, and rerender behavior have different lifecycle and ownership constraints, so they will remain explicit rather than being grouped under a weak abstraction. Removed the uncalled private `registerEventListeners()`, its `MetadataCache` import, the never-assigned `main.ts` `fileExplorerObserver`, and its inert unload check. The active file-explorer observer and teardown in `ObserverManager` were not changed | Repository-wide reference searches confirmed both removed members had no callers or assignments and that `PluginFileManager.initialize()` owns the active initial cache walk; `npm run build` passed with the existing circular-dependency warnings; targeted lint reports only the same four pre-existing startup-script `any` diagnostics and none on changed lines; `git diff --check` passed; `main.ts` decreased by 29 lines from 1,376 to 1,347 and the bundle decreased by 381 bytes to 5,095,366 bytes; manual unload/reload validation remains pending |
| 2026-08-09 | Extracted the complete `ExcalidrawView` export pipeline | Added documented `ViewExportManager` to own raw `.excalidraw`, SVG, PNG, clipboard, PDF, export-option resolution, autoexport file writing, and alternate-theme embedded-file loading. Retained every existing public method on `ExcalidrawView` as a documented delegate, kept the public `exportDialog` field and its persistence/teardown lifecycle on the view, and supplied existing runtime dependencies explicitly to avoid a new import cycle. Converted seven type-only imports and pointed `exportUtils` directly at canonical `svgToBase64()` to remove runtime back-edges without changing behavior | `npm run build` passed after every code change; `npm run lib`, manager-targeted ESLint, repository reference searches, and `git diff --check` passed. Broader touched-file lint retains the existing backlog but reports no manager diagnostics. Circular dependency warnings decreased from 34 to 33; `ExcalidrawView.ts` decreased by 365 lines from 9,080 to 8,715; the bundle increased by 2,177 bytes to 5,097,543 bytes and remains below 5 MiB; manual export validation remains pending |
| 2026-08-09 | Removed inert commented-out fragments from `ExcalidrawView` | Deleted the obsolete `excalidrawRef` declaration, disabled dimensions state/effect experiment and matching width/height props, old tooltip and paste alternatives, commented debug logging, and retired `setLocalFont()` calls. Retained comments that explain active semaphore, timer, observer, and sizing workarounds | `npm run build` passed with the same 33 circular-dependency warnings; residue search found none of the targeted fragments; `git diff --check` passed; `ExcalidrawView.ts` decreased by 46 lines from 8,715 to 8,669; bundle size is unchanged at 5,097,543 bytes because comments were not emitted; no runtime testing is required beyond the export-manager checkpoint |
| 2026-08-09 | Extracted fullscreen DOM coordination from `ExcalidrawView` | Added documented `ViewFullscreenManager` with a narrow structural host to own the existing enter, state-check, and exit algorithms. Preserved the public `gotoFullscreen()`, `isFullscreen()`, and `exitFullscreen()` methods as delegates, the owner-document scoping needed by popout windows, tools-panel state updates, leaf-change timeout cancellation, CSS class names, selectors, and mobile layout restoration | `npm run build`, `npm run lib`, manager-targeted ESLint, repository call-site searches, and `git diff --check` passed. The same 33 circular-dependency warnings remain; `ExcalidrawView.ts` decreased by 105 lines from 8,669 to 8,564; the manager contains 166 documented lines; bundle size increased by 828 bytes to 5,098,371 bytes and remains below 5 MiB. Manual main-window, popout, mobile, and teardown validation remains pending, with cross-document DOM restoration the highest-risk area |
## Executive recommendation
@@ -512,13 +514,17 @@ Recommended order:
1. Completed: `ViewExportManager` owns export preference resolution, file
collection, SVG, PNG, PDF, clipboard, and save-to-file operations while the
view retains compatibility delegates and dialog lifecycle.
2. `ViewLinkNavigationManager`: link parsing, hook invocation, navigation, and
2. Implemented: `ViewFullscreenManager` owns fullscreen DOM class and style
coordination while the view retains compatibility delegates. Validate the
unchanged selectors in the main window, popouts, mobile layouts, screenshot
capture, link-driven exit, and view teardown before closing this checkpoint.
3. `ViewLinkNavigationManager`: link parsing, hook invocation, navigation, and
link click handling.
3. `ViewSceneFileManager`: active/next/deferred embedded-file loaders and
4. `ViewSceneFileManager`: active/next/deferred embedded-file loaders and
deferred validation scheduling.
4. `MarkdownImageController`: deletion queue, edit handoff, conversion, and
5. `MarkdownImageController`: deletion queue, edit handoff, conversion, and
local-source operations.
5. `ViewInteractionController`: hover preview and pointer/key interaction only
6. `ViewInteractionController`: hover preview and pointer/key interaction only
after the earlier controllers establish a working host-interface pattern.
Each manager should depend on the smallest host interface practical rather
@@ -750,9 +756,12 @@ Before merging any refactor step, answer all of the following:
`ExcalidrawView` export methods as delegates. This establishes the
view-controller pattern away from lifecycle and synchronization.
The next checkpoint is extracting the package-aware React root using
`createElement()` without TSX or state changes, followed by popout validation.
Convert to TSX only in the subsequent change.
The current checkpoint is manual validation of `ViewFullscreenManager`, with
particular attention to owner-document isolation and DOM restoration in popout
and mobile layouts. The next low-coupling candidate is
`ViewLinkNavigationManager`. Extract the package-aware React root only after
these controller checkpoints, using `createElement()` without TSX or state
changes first; convert to TSX only in a subsequent change.
After those steps, reassess coupling, bundle size, and manual-test coverage
before committing to the next phase. The plan is deliberately a sequence of
+11 -116
View File
@@ -252,6 +252,7 @@ import {
} from "../types/excalidrawViewTypes";
import { DropManager } from "./managers/DropManager";
import { ViewExportManager } from "./managers/ViewExportManager";
import { ViewFullscreenManager } from "./managers/ViewFullscreenManager";
import { ImageInfo } from "src/types/excalidrawAutomateTypes";
import { PageOrientation, PageSize } from "src/types/exportUtilTypes";
import { CaptureUpdateAction } from "src/constants/constants";
@@ -293,9 +294,6 @@ interface WorkspaceItemExt extends WorkspaceItem {
containerEl: HTMLElement;
}
const HIDE = "excalidraw-hidden";
const SHOW = "excalidraw-visible";
export const addFiles = async (
files: FileData[],
view: ExcalidrawView,
@@ -401,6 +399,7 @@ export default class ExcalidrawView
{
private dropManager: DropManager;
private exportManager: ViewExportManager;
private fullscreenManager: ViewFullscreenManager;
public hoverPopover: HoverPopover | null = null;
private freedrawLastActiveTimestamp: number = 0;
public exportDialog: ExportDialog | null = null;
@@ -538,6 +537,7 @@ export default class ExcalidrawView
isMaskFile,
sceneRemoveInternalLinks,
});
this.fullscreenManager = new ViewFullscreenManager(this);
this.setHookServer();
this.dropManager = new DropManager(this);
}
@@ -1264,124 +1264,19 @@ export default class ExcalidrawView
);
}
gotoFullscreen() {
if (this.plugin.leafChangeTimeout) {
window.clearTimeout(this.plugin.leafChangeTimeout); //leafChangeTimeout is created on window in main.ts!!!
this.plugin.clearLeafChangeTimeout();
}
if (!this.excalidrawWrapperRef) {
return;
}
if (this.toolsPanelRef && this.toolsPanelRef.current) {
this.toolsPanelRef.current.setFullscreen(true);
}
const hide = (el: HTMLElement) => {
setStyle(el, { marginTop: "0px" });
let tmpEl = el;
while (tmpEl && !tmpEl.hasClass("workspace-split")) {
el.addClass(SHOW);
el = tmpEl;
tmpEl = el.parentElement;
}
if (el) {
el.addClass(SHOW);
el.querySelectorAll(`div.workspace-split:not(.${SHOW})`).forEach(
(node) => {
if (node !== el) {
node.addClass(SHOW);
}
},
);
el.querySelector(
`div.workspace-leaf-content.${SHOW} > .view-header`,
).addClass(SHOW);
el.querySelectorAll(
`div.workspace-tab-container.${SHOW} > div.workspace-leaf:not(.${SHOW})`,
).forEach((node) => node.addClass(SHOW));
el.querySelectorAll(
`div.workspace-tabs.${SHOW} > div.workspace-tab-header-container`,
).forEach((node) => node.addClass(SHOW));
el.querySelectorAll(
`div.workspace-split.${SHOW} > div.workspace-tabs:not(.${SHOW})`,
).forEach((node) => node.addClass(SHOW));
}
const doc = this.ownerDocument;
doc.body
.querySelectorAll(`div.workspace-split:not(.${SHOW})`)
.forEach((node) => {
if (node !== tmpEl) {
node.addClass(HIDE);
} else {
node.addClass(SHOW);
}
});
doc.body
.querySelector(`div.workspace-leaf-content.${SHOW} > .view-header`)
.addClass(HIDE);
doc.body
.querySelectorAll(
`div.workspace-tab-container.${SHOW} > div.workspace-leaf:not(.${SHOW})`,
)
.forEach((node) => node.addClass(HIDE));
doc.body
.querySelectorAll(
`div.workspace-tabs.${SHOW} > div.workspace-tab-header-container`,
)
.forEach((node) => node.addClass(HIDE));
doc.body
.querySelectorAll(
`div.workspace-split.${SHOW} > div.workspace-tabs:not(.${SHOW})`,
)
.forEach((node) => node.addClass(HIDE));
doc.body
.querySelectorAll(`div.workspace-ribbon`)
.forEach((node) => node.addClass(HIDE));
doc.body
.querySelectorAll(`div.mobile-navbar`)
.forEach((node) => node.addClass(HIDE));
doc.body
.querySelectorAll(`div.status-bar`)
.forEach((node) => node.addClass(HIDE));
doc.body
.querySelectorAll(`div.titlebar`)
.forEach((node) => node.addClass(HIDE));
const topPadding = doc.body.querySelector(
".is-mobile .workspace > .mod-root",
);
if (topPadding && isInstanceOfHTMLElement(topPadding)) {
setStyle(topPadding, { paddingTop: "0px" });
}
};
hide(this.contentEl);
/** Enters fullscreen through the view-scoped fullscreen manager. */
gotoFullscreen(): void {
this.fullscreenManager.gotoFullscreen();
}
/** Reports fullscreen state through the view-scoped fullscreen manager. */
isFullscreen(): boolean {
return Boolean(this.ownerDocument.body.querySelector(".excalidraw-hidden"));
return this.fullscreenManager.isFullscreen();
}
exitFullscreen() {
if (!this.isFullscreen()) {
return;
}
if (this.toolsPanelRef && this.toolsPanelRef.current) {
this.toolsPanelRef.current.setFullscreen(false);
}
const doc = this.ownerDocument;
doc
.querySelectorAll(".excalidraw-hidden")
.forEach((el) => el.removeClass(HIDE));
doc
.querySelectorAll(".excalidraw-visible")
.forEach((el) => el.removeClass(SHOW));
const topPadding = doc.body.querySelector(
".is-mobile .workspace > .mod-root",
);
if (topPadding && isInstanceOfHTMLElement(topPadding)) {
setStyle(topPadding, { paddingTop: "" });
}
setStyle(this.contentEl, { marginTop: "" });
/** Exits fullscreen through the view-scoped fullscreen manager. */
exitFullscreen(): void {
this.fullscreenManager.exitFullscreen();
}
removeLinkTooltip() {
+166
View File
@@ -0,0 +1,166 @@
import { setStyle } from "../../utils/styleUtils";
import { isInstanceOfHTMLElement } from "../../utils/typechecks";
const FULLSCREEN_HIDDEN_CLASS = "excalidraw-hidden";
const FULLSCREEN_VISIBLE_CLASS = "excalidraw-visible";
interface FullscreenToolsPanel {
setFullscreen(isFullscreen: boolean): void;
}
/**
* Minimal view surface required by {@link ViewFullscreenManager}.
*
* `ownerDocument` must remain view-scoped so fullscreen DOM changes target the
* correct Obsidian window when the view is hosted in a popout.
*/
export interface ViewFullscreenHost {
contentEl: HTMLElement;
readonly ownerDocument: Document;
excalidrawWrapperRef: { current: HTMLDivElement | null } | null;
toolsPanelRef: { current: FullscreenToolsPanel | null } | null;
plugin: {
readonly leafChangeTimeout: number | null;
clearLeafChangeTimeout(): void;
};
}
/**
* Applies and restores the DOM classes used by one Excalidraw view's
* fullscreen mode.
*/
export class ViewFullscreenManager {
public constructor(private readonly host: ViewFullscreenHost) {}
/** Enters fullscreen mode within the view's owning Obsidian document. */
public gotoFullscreen(): void {
if (this.host.plugin.leafChangeTimeout) {
// The timeout is created on the main window by EventManager.
window.clearTimeout(this.host.plugin.leafChangeTimeout);
this.host.plugin.clearLeafChangeTimeout();
}
if (!this.host.excalidrawWrapperRef) {
return;
}
if (this.host.toolsPanelRef?.current) {
this.host.toolsPanelRef.current.setFullscreen(true);
}
const hide = (el: HTMLElement) => {
setStyle(el, { marginTop: "0px" });
let tmpEl = el;
while (tmpEl && !tmpEl.hasClass("workspace-split")) {
el.addClass(FULLSCREEN_VISIBLE_CLASS);
el = tmpEl;
tmpEl = el.parentElement;
}
if (el) {
el.addClass(FULLSCREEN_VISIBLE_CLASS);
el.querySelectorAll(
`div.workspace-split:not(.${FULLSCREEN_VISIBLE_CLASS})`,
).forEach((node) => {
if (node !== el) {
node.addClass(FULLSCREEN_VISIBLE_CLASS);
}
});
el.querySelector(
`div.workspace-leaf-content.${FULLSCREEN_VISIBLE_CLASS} > .view-header`,
).addClass(FULLSCREEN_VISIBLE_CLASS);
el.querySelectorAll(
`div.workspace-tab-container.${FULLSCREEN_VISIBLE_CLASS} > div.workspace-leaf:not(.${FULLSCREEN_VISIBLE_CLASS})`,
).forEach((node) => node.addClass(FULLSCREEN_VISIBLE_CLASS));
el.querySelectorAll(
`div.workspace-tabs.${FULLSCREEN_VISIBLE_CLASS} > div.workspace-tab-header-container`,
).forEach((node) => node.addClass(FULLSCREEN_VISIBLE_CLASS));
el.querySelectorAll(
`div.workspace-split.${FULLSCREEN_VISIBLE_CLASS} > div.workspace-tabs:not(.${FULLSCREEN_VISIBLE_CLASS})`,
).forEach((node) => node.addClass(FULLSCREEN_VISIBLE_CLASS));
}
const doc = this.host.ownerDocument;
doc.body
.querySelectorAll(
`div.workspace-split:not(.${FULLSCREEN_VISIBLE_CLASS})`,
)
.forEach((node) => {
if (node !== tmpEl) {
node.addClass(FULLSCREEN_HIDDEN_CLASS);
} else {
node.addClass(FULLSCREEN_VISIBLE_CLASS);
}
});
doc.body
.querySelector(
`div.workspace-leaf-content.${FULLSCREEN_VISIBLE_CLASS} > .view-header`,
)
.addClass(FULLSCREEN_HIDDEN_CLASS);
doc.body
.querySelectorAll(
`div.workspace-tab-container.${FULLSCREEN_VISIBLE_CLASS} > div.workspace-leaf:not(.${FULLSCREEN_VISIBLE_CLASS})`,
)
.forEach((node) => node.addClass(FULLSCREEN_HIDDEN_CLASS));
doc.body
.querySelectorAll(
`div.workspace-tabs.${FULLSCREEN_VISIBLE_CLASS} > div.workspace-tab-header-container`,
)
.forEach((node) => node.addClass(FULLSCREEN_HIDDEN_CLASS));
doc.body
.querySelectorAll(
`div.workspace-split.${FULLSCREEN_VISIBLE_CLASS} > div.workspace-tabs:not(.${FULLSCREEN_VISIBLE_CLASS})`,
)
.forEach((node) => node.addClass(FULLSCREEN_HIDDEN_CLASS));
doc.body
.querySelectorAll("div.workspace-ribbon")
.forEach((node) => node.addClass(FULLSCREEN_HIDDEN_CLASS));
doc.body
.querySelectorAll("div.mobile-navbar")
.forEach((node) => node.addClass(FULLSCREEN_HIDDEN_CLASS));
doc.body
.querySelectorAll("div.status-bar")
.forEach((node) => node.addClass(FULLSCREEN_HIDDEN_CLASS));
doc.body
.querySelectorAll("div.titlebar")
.forEach((node) => node.addClass(FULLSCREEN_HIDDEN_CLASS));
const topPadding = doc.body.querySelector(
".is-mobile .workspace > .mod-root",
);
if (topPadding && isInstanceOfHTMLElement(topPadding)) {
setStyle(topPadding, { paddingTop: "0px" });
}
};
hide(this.host.contentEl);
}
/** Returns whether this view's owning document contains fullscreen classes. */
public isFullscreen(): boolean {
return Boolean(
this.host.ownerDocument.body.querySelector(
`.${FULLSCREEN_HIDDEN_CLASS}`,
),
);
}
/** Restores DOM classes and layout styles applied by fullscreen mode. */
public exitFullscreen(): void {
if (!this.isFullscreen()) {
return;
}
if (this.host.toolsPanelRef?.current) {
this.host.toolsPanelRef.current.setFullscreen(false);
}
const doc = this.host.ownerDocument;
doc
.querySelectorAll(`.${FULLSCREEN_HIDDEN_CLASS}`)
.forEach((el) => el.removeClass(FULLSCREEN_HIDDEN_CLASS));
doc
.querySelectorAll(`.${FULLSCREEN_VISIBLE_CLASS}`)
.forEach((el) => el.removeClass(FULLSCREEN_VISIBLE_CLASS));
const topPadding = doc.body.querySelector(
".is-mobile .workspace > .mod-root",
);
if (topPadding && isInstanceOfHTMLElement(topPadding)) {
setStyle(topPadding, { paddingTop: "" });
}
setStyle(this.host.contentEl, { marginTop: "" });
}
}