Repository navigation
Commit 6246909
refactor(editor): split the 1975-line onlyoffice-editor into a facade and one module per concern
lib/onlyoffice-editor.ts had grown to seven unrelated concerns in one file, and
prepareEditorIframe alone was 584 lines: nine independent vendor patches inside
a single frame loop, each with its own `win as unknown as {...}` cast and
`__oo*` flag, with a "everything is in place" check reading five locals
scattered through it.
It is now a facade -- mount, rebuild, loadEditorApi -- over lib/onlyoffice/:
iframe-guards (orchestration) with one file per guard under guards/, open-state,
open-failure, font-system, save-stream, viewport, sdk-api, readonly, ui-theme,
file-helpers. Each guard file leads with the production defect it exists for.
The public surface is unchanged: the facade re-exports every symbol
lib/embed-api, lib/web-mcp, lib/converter and the unit tests import, so not a
line of test code moves.
Two rules the split follows:
- Cross-module state has exactly one owner. documentContentReady /
documentOpenError / lastFrameError were module-level variables read and
written from three places; they now live in open-state and everyone else
calls its accessors. Readonly belongs to readonly.ts, the in-flight save
request to save-stream.ts (the guard fails it through
failPendingSaveConversion instead of reaching into another module's state).
Duplicating any of it is the one thing that would actually introduce bugs.
- No cycles. The retry path needs createEditorInstance, which lives in the
facade, so it goes through an injected runner (setOpenRunner) the same way
the converter and UI callbacks already do.
Behaviour is unchanged by construction: every line of the old file was matched
verbatim against the new tree, and the 39 differences are all deliberate
(added `export`, module variables read through accessors, the injected runner,
moved imports). Guards report "in place" as a return value; iframe-guards
combines the same five as before.
Verified: tsc + oxlint clean, 617 unit tests green (untouched), full local e2e
against the real editor 82 passed / 16 skipped / 0 failed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent bc96ff0 commit 6246909
23 files changed
Lines changed: 2005 additions & 1670 deletions
File tree
- docs/explorations
- lib
- onlyoffice
- guards
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
64 | 78 | | |
65 | 79 | | |
66 | 80 | | |
| |||
106 | 120 | | |
107 | 121 | | |
108 | 122 | | |
109 | | - | |
| 123 | + | |
110 | 124 | | |
111 | 125 | | |
112 | | - | |
113 | | - | |
| 126 | + | |
| 127 | + | |
114 | 128 | | |
115 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
116 | 136 | | |
117 | 137 | | |
118 | 138 | | |
| |||
570 | 590 | | |
571 | 591 | | |
572 | 592 | | |
573 | | - | |
| 593 | + | |
574 | 594 | | |
575 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
576 | 598 | | |
577 | 599 | | |
578 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
0 commit comments