Skip to content

Commit d2c45ec

Browse files
authored
fix(types): add exportDocx overloads and fix Toolbar compat (#2703)
1. Add exportDocx overloads narrowing return type per flag: - exportXmlOnly: true β†’ Promise<string> - exportJsonOnly: true β†’ Promise<string> - getUpdatedDocs: true β†’ Promise<Record<string, string | null>> - default β†’ Promise<Blob | Buffer> Extract ExportDocxParams interface extending SaveOptions. 2. Remove [key: string]: unknown index signature from Toolbar interface. SuperToolbar (extends EventEmitter) was incompatible because EventEmitter methods return specific types, not unknown. Keep setActiveEditor(editor: Editor) matching Editor.#onFocus usage.
1 parent f3e837c commit d2c45ec

3 files changed

Lines changed: 35 additions & 13 deletions

File tree

β€Žpackages/super-editor/src/editors/v1/core/Editor.tsβ€Ž

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ export interface SaveOptions {
228228
*/
229229
export type ExportOptions = SaveOptions;
230230

231+
/**
232+
* Full parameter set for `Editor.exportDocx()`.
233+
* Extends SaveOptions with internal export format flags.
234+
*/
235+
export interface ExportDocxParams extends SaveOptions {
236+
/** Return raw XML string instead of a binary blob */
237+
exportXmlOnly?: boolean;
238+
/** Return JSON string instead of a binary blob */
239+
exportJsonOnly?: boolean;
240+
/** Return the updated file map instead of a binary blob */
241+
getUpdatedDocs?: boolean;
242+
}
243+
231244
/**
232245
* Main editor class that manages document state, extensions, and user interactions
233246
*/
@@ -3061,7 +3074,17 @@ export class Editor extends EventEmitter<EditorEventMap> {
30613074

30623075
/**
30633076
* Export the editor document to DOCX.
3077+
*
3078+
* Return type depends on flags:
3079+
* - `exportXmlOnly: true` β†’ `string` (raw XML)
3080+
* - `exportJsonOnly: true` β†’ `string` (JSON string)
3081+
* - `getUpdatedDocs: true` β†’ `Record<string, string | null>` (file map)
3082+
* - Default β†’ `Blob` (browser) or `Buffer` (Node.js headless)
30643083
*/
3084+
async exportDocx(params: ExportDocxParams & { exportXmlOnly: true }): Promise<string>;
3085+
async exportDocx(params: ExportDocxParams & { exportJsonOnly: true }): Promise<string>;
3086+
async exportDocx(params: ExportDocxParams & { getUpdatedDocs: true }): Promise<Record<string, string | null>>;
3087+
async exportDocx(params?: ExportDocxParams): Promise<Blob | Buffer>;
30653088
async exportDocx({
30663089
isFinalDoc = false,
30673090
commentsType = 'external',
@@ -3071,16 +3094,7 @@ export class Editor extends EventEmitter<EditorEventMap> {
30713094
getUpdatedDocs = false,
30723095
fieldsHighlightColor = null,
30733096
compression,
3074-
}: {
3075-
isFinalDoc?: boolean;
3076-
commentsType?: string;
3077-
exportJsonOnly?: boolean;
3078-
exportXmlOnly?: boolean;
3079-
comments?: Comment[];
3080-
getUpdatedDocs?: boolean;
3081-
fieldsHighlightColor?: string | null;
3082-
compression?: 'DEFLATE' | 'STORE';
3083-
} = {}): Promise<Blob | ArrayBuffer | Buffer | Record<string, string | null> | ProseMirrorJSON | string | undefined> {
3097+
}: ExportDocxParams = {}): Promise<Blob | Buffer | Record<string, string | null> | string | undefined> {
30843098
try {
30853099
// Use provided comments, or fall back to imported comments from converter
30863100
const effectiveComments = comments ?? this.converter.comments ?? [];

β€Žpackages/super-editor/src/editors/v1/core/types/EditorTypes.tsβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ export interface PageStyles {
7878
}
7979

8080
/**
81-
* Toolbar configuration
81+
* Toolbar instance accepted by `Editor.setToolbar()`.
82+
*
83+
* Any object with an optional `setActiveEditor` method satisfies this interface,
84+
* including `SuperToolbar` which extends EventEmitter.
8285
*/
8386
export interface Toolbar {
8487
setActiveEditor?: (editor: Editor) => void;
85-
[key: string]: unknown;
8688
}
8789

8890
/**

β€Žpackages/super-editor/src/index.tsβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ export type {
7676
ExportFormat,
7777
PageStyles,
7878
} from './editors/v1/core/types/EditorTypes.js';
79-
export type { OpenOptions, SaveOptions, ExportOptions, EditorLifecycleState } from './editors/v1/core/Editor.js';
79+
export type {
80+
OpenOptions,
81+
SaveOptions,
82+
ExportOptions,
83+
ExportDocxParams,
84+
EditorLifecycleState,
85+
} from './editors/v1/core/Editor.js';
8086

8187
// PresentationEditor public types
8288
export type {

0 commit comments

Comments
Β (0)