Skip to content
Open
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
7 changes: 7 additions & 0 deletions packages/superdoc/src/core/v2-integration/v2-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// constructed (e.g. a non-DOM context); it never selects v1.

import { defineComponent, h, onMounted } from 'vue';
import { installWebKitCollapsedCaretRectFix } from './webkit-collapsed-caret-rect.js';
/** @type {() => Promise<unknown>} */
let engineModuleLoader = () => import('@superdoc/docx-engine');
/** @type {Promise<void> | null} */
Expand All @@ -39,6 +40,12 @@ export function configureDefaultV2IntegrationLoader(loader) {

/** Load the engine before Vue evaluates the synchronous integration seam. */
export async function loadDefaultV2Integration() {
// Every distribution mode reaches the engine through this function, so it is
// the one place that guarantees the workaround is installed before the engine
// can paint a caret. The quirk probe measures a throwaway element of its own,
// so no editor document has to exist yet. It never throws: a caret nicety must
// not be able to reject this promise and drop the editor to its stub.
if (typeof window !== 'undefined') installWebKitCollapsedCaretRectFix(window);
if (!engineModulePromise) {
const loadPromise = Promise.resolve()
.then(() => engineModuleLoader())
Expand Down
20 changes: 19 additions & 1 deletion packages/superdoc/src/core/v2-integration/v2-integration.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vite-plus/test';
import { describe, it, expect, vi } from 'vite-plus/test';
import {
createDefaultV2Integration,
loadDefaultV2Integration,
Expand All @@ -9,6 +9,24 @@ import {
isV2SyntheticTrackedChangeRow,
} from './v2-integration.js';

// The WebKit caret-rect workaround is wired in here and nowhere else, so the
// call is what the fix ships on. Mocked so the wiring itself is asserted rather
// than the workaround's own behaviour, which its module tests cover.
vi.mock('./webkit-collapsed-caret-rect.js', () => ({
installWebKitCollapsedCaretRectFix: vi.fn(() => null),
}));

describe('WebKit caret-rect workaround wiring', () => {
it('installs the workaround when the engine is loaded', async () => {
const { installWebKitCollapsedCaretRectFix } = await import('./webkit-collapsed-caret-rect.js');
installWebKitCollapsedCaretRectFix.mockClear();

await loadDefaultV2Integration();

expect(installWebKitCollapsedCaretRectFix).toHaveBeenCalledWith(window);
});
});

// V2 branch: the integration is the single DOCX Engine runtime. There is no
// customer-provided integration and no v1 fallback selection.
describe('createDefaultV2Integration', () => {
Expand Down
Loading
Loading