Skip to content

Commit 427736a

Browse files
authored
fix(types): auto-generate TS types by converting barrel to TypeScript (SD-2261) (#2565)
* fix(types): auto-generate TS types by converting barrel to TypeScript (SD-2261) Convert super-editor barrel from index.js to index.ts with type re-exports, replacing the hand-written index.d.ts with types derived from actual source files. This ensures type declarations always match runtime behavior. - Rename super-editor/src/index.js → index.ts, add type re-exports - Delete hand-written index.d.ts (1140 lines of manually maintained types) - Delete redundant Editor.d.ts sidecar (shadows Editor.ts) - Add missing types: BoundingRect, BinaryData, UnsupportedContentItem - Update vite.config.js and package.json entry points - Expand superdoc barrel with missing runtime exports and JSDoc type re-exports * fix(types): correct OpenOptions import path and superdoc vite alias - Move OpenOptions re-export from EditorConfig.js to Editor.js (where it's actually defined) - Update superdoc vite.config.js aliases from index.js to index.ts * fix(types): add missing type re-exports for backward compat Add CoreCommandMap, ExtensionCommandMap, and LayoutUpdatePayload to type re-exports — these were in the old hand-written index.d.ts and need to remain available for consumers. * fix(types): fix shim generation for export type re-exports and common subpaths - Update ensure-types.cjs regex to match `export type { ... } from` in addition to `import { ... } from`, so re-exported names like Fragment are included in workspace package shims - Allow @superdoc/common subpath imports (e.g. BasicUpload.vue) to be shimmed instead of skipped - Update public-api test to reference renamed index.ts * fix(types): include Vue shim in tsconfig and add missing sidecar export - Add vue-shim.d.ts to super-editor tsconfig include so tsc can resolve .vue imports from the renamed index.ts barrel - Add createOrUpdateTrackedChangeComment to comments-plugin.d.ts sidecar * test(types): add TS compatibility matrix and fix .ts extension paths Add typecheck-matrix.mjs that tests consumer types across 9 scenarios: bundler/node16/nodenext module resolution, strict/loose mode, headless Node.js usage, and superdoc/super-editor sub-exports. Fix ensure-types.cjs to convert .ts extensions to .js in generated .d.ts import paths — vite-plugin-dts preserves .ts from the source entry point, but consumers need .js for TypeScript resolution. * fix(types): type CommentsPluginKey and remove dead branch in matrix - Type CommentsPluginKey as PluginKey instead of any - Remove duplicated srcErrors === 0 branch in typecheck matrix * fix(types): delegate runtime exports to v1 barrel, fix type re-export paths The index.ts was duplicating all imports from editors/v1/index.js with wrong relative paths (missing editors/v1/ prefix). Use export * from the v1 barrel for runtime exports and only keep type re-exports with corrected paths. * fix(types): add event and parts type re-exports for consumer handlers Export all types consumers need to type EditorEventMap handlers: - EditorEvents: Comment, CommentsPayload, CommentLocationsPayload, FontsResolvedPayload, PaginationPayload, ListDefinitionsPayload, ProtectionChangeSource, EditorEventMap - Parts: PartChangedEvent, PartId, PartSectionId - Document API: DocumentProtectionState * fix(types): export EditorOptions, User, ProseMirrorJSON and all config types Add all public-facing types consumers need for constructor options, method params, and configuration: EditorOptions, User, ProseMirrorJSON, ExportFormat, EditorLifecycleState, ViewOptions, CommentConfig, CollaborationProvider, LinkPopoverResolver, PermissionParams, etc.
1 parent e1dc6d5 commit 427736a

19 files changed

Lines changed: 638 additions & 1242 deletions

File tree

packages/super-editor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"exports": {
1010
".": {
11-
"source": "./src/index.js",
11+
"source": "./src/index.ts",
1212
"types": "./dist/src/index.d.ts",
1313
"import": "./dist/super-editor.es.js"
1414
},
@@ -72,7 +72,7 @@
7272
"import": "./dist/style.css"
7373
},
7474
"./presentation-editor": {
75-
"source": "./src/index.js",
75+
"source": "./src/index.ts",
7676
"import": "./dist/super-editor.es.js",
7777
"types": "./dist/index.d.ts"
7878
}

packages/super-editor/src/editors/v1/core/Editor.d.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/super-editor/src/editors/v1/core/presentation-editor/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,15 @@ export type RangeRect = {
388388
height: number;
389389
};
390390

391+
export type BoundingRect = {
392+
top: number;
393+
left: number;
394+
bottom: number;
395+
right: number;
396+
width: number;
397+
height: number;
398+
};
399+
391400
export type HeaderFooterMode = 'body' | 'header' | 'footer';
392401

393402
export type HeaderFooterSession = {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ export interface Toolbar {
8585
[key: string]: unknown;
8686
}
8787

88+
/**
89+
* Binary data accepted by document open/import APIs.
90+
*/
91+
export type BinaryData = ArrayBuffer | ArrayBufferView;
92+
93+
/**
94+
* Represents an unsupported HTML element dropped during paste.
95+
*/
96+
export type UnsupportedContentItem = {
97+
tagName: string;
98+
outerHTML: string;
99+
count: number;
100+
};
101+
88102
/**
89103
* Re-export commonly used types
90104
*/
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const CommentsPluginKey: any;
1+
import type { PluginKey } from 'prosemirror-state';
2+
export const CommentsPluginKey: PluginKey;
3+
export function createOrUpdateTrackedChangeComment(options: any): any;

0 commit comments

Comments
 (0)