diff --git a/packages/plugin-declaration-generator/src/tsgenerator.ts b/packages/plugin-declaration-generator/src/tsgenerator.ts index 580b6564..004d96d8 100644 --- a/packages/plugin-declaration-generator/src/tsgenerator.ts +++ b/packages/plugin-declaration-generator/src/tsgenerator.ts @@ -14,6 +14,7 @@ export interface ExportModuleItem { export interface DeclarationModuleItem { name: string; text: string; + comment?: string; pos?: number; } @@ -38,12 +39,25 @@ export function parseModuleDeclaration( node.body.forEachChild((item) => { if (ts.isVariableStatement(item)) { + let comment: string | undefined = undefined; + const commentRange = ts.getLeadingCommentRanges( + sourceFile.getFullText(), + item.pos + ); + if (Array.isArray(commentRange) && commentRange.length > 0) { + comment = ''; + commentRange.map(({ pos, end }) => { + comment += sourceFile.text.substring(pos, end); + }); + } + item.declarationList.declarations.forEach((declaration) => { const name = declaration.name.getText(); const pos = declaration.pos; modules[moduleName].push({ name, text: declaration.getText(), + comment, pos, }); }); diff --git a/web/scripts/generate-plugin-declaration.typescript.ts b/web/scripts/generate-plugin-declaration.typescript.ts index f92b0f84..90d6afb0 100644 --- a/web/scripts/generate-plugin-declaration.typescript.ts +++ b/web/scripts/generate-plugin-declaration.typescript.ts @@ -17,7 +17,9 @@ function exportModulesTemplate( .map((item) => { const findedModule = existedModules.find((m) => m.name === item.name); if (findedModule) { - return `export const ${findedModule.text};`; + return `${ + findedModule.comment ? findedModule.comment + '\n ' : '' + }export const ${findedModule.text};`; } else { return `export const ${item.name}: any;`; } @@ -66,7 +68,6 @@ declare module '@capital/common' { )} } - /** * Tailchat 组件 */ diff --git a/web/tailchat.d.ts b/web/tailchat.d.ts index 3301ddc5..879a292a 100644 --- a/web/tailchat.d.ts +++ b/web/tailchat.d.ts @@ -12,7 +12,30 @@ declare module '@capital/common' { export const useGroupPanelParams: any; - export const openModal: any; + /** + * 打开模态框 + */ + export const openModal: ( + content: React.ReactNode, + + props?: { + /** + * 是否显示右上角的关闭按钮 + * @default false + */ + closable?: boolean; + + /** + * 遮罩层是否可关闭 + */ + maskClosable?: boolean; + + /** + * 关闭modal的回调 + */ + onCloseModal?: () => void; + } + ) => number; export const closeModal: any;