Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type error #2045

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
92db2c4
refactor: extract inline plugin templates as independent files (#1874)
zombieJ Sep 7, 2023
3528057
feat: split markdown meta loader (#1875)
MadCcc Sep 8, 2023
2dcc72a
refactor: extract runtime tpl (#1883)
zombieJ Sep 8, 2023
ed76ee6
refactor: load text data from self in markdown loader (#1881)
MadCcc Sep 11, 2023
595a3d8
refactor: provider `useDemoData` which is given by `getDemoById` (#1876)
zombieJ Sep 11, 2023
f9e77a0
refactor: remove full demos from context (#1885)
zombieJ Sep 11, 2023
7b47630
chore: rm texts (#1886)
zombieJ Sep 11, 2023
baec225
refactor: useRouteMeta & useTabMeta with getRouteMetaById (#1888)
MadCcc Sep 12, 2023
ff343de
refactor: useRouteMeta fully use getRouteMetaById (#1889)
MadCcc Sep 13, 2023
a42dfb2
refactor: better frontmatter code (#1892)
MadCcc Sep 14, 2023
bf55a95
refactor: clean up meta (#1894)
zombieJ Sep 14, 2023
d969e98
feat: Make searchable again (#1898)
zombieJ Sep 15, 2023
e0cac83
feat: merge chunk & optimize meta loading (#1906)
MadCcc Sep 22, 2023
d72e8fe
perf: loadSearchData on focus & show loading only once (#1915)
MadCcc Sep 26, 2023
898a39a
Merge remote-tracking branch 'origin/master' into feature/2.3.0
PeachScript Sep 27, 2023
5ef7c33
fix: demo should export html file (#1931)
MadCcc Oct 8, 2023
52d8774
Merge remote-tracking branch 'origin/master' into feature/2.3.0
PeachScript Oct 12, 2023
5a588c6
feat: support live demo (#1905)
MadCcc Oct 18, 2023
b962cf9
feat: enhance live regexp (#1946)
MadCcc Oct 19, 2023
5ffeaa4
refactor: optimize async route meta solution (#1974)
PeachScript Dec 14, 2023
e14fa51
feat: add default loading skeleton (#1512)
Wxh16144 Jan 4, 2024
206b04e
refactor: optimize live demo feature in v2.3 (#1992)
PeachScript Jan 4, 2024
a80758a
fix: multi-instance problem and styles of live demo feature (#2001)
PeachScript Jan 8, 2024
c29cd1e
refactor: avoid breaking change for useRouteMeta api (#2002)
PeachScript Jan 8, 2024
f09a859
Merge remote-tracking branch 'origin/master' into feature/2.3.0
PeachScript Jan 12, 2024
14620d9
feat: live demo support custom tech stack (#2012)
PeachScript Jan 16, 2024
9fb0a0e
feat: useLiveDemo support iframe demo (#2013)
PeachScript Jan 19, 2024
f37fe97
fix: unexpected suspense from useRouteMeta (#2019)
PeachScript Jan 23, 2024
5d169bb
feat: tech stack supports declare runtime plugin (#2020)
PeachScript Jan 23, 2024
eb7f122
fix: overflow for source code editor (#2014)
MadCcc Jan 24, 2024
fae28cb
fix: code editor scroll bar should be draggable (#2023)
MadCcc Feb 4, 2024
f2a0b9e
feat: support vue tech stack (#1922)
jeffwcx Mar 3, 2024
88ea15a
fix: unexpected return type of useRouteMeta
PeachScript Jan 23, 2024
396a886
Merge remote-tracking branch 'origin/master' into feature/2.3.0
PeachScript Mar 3, 2024
19ebd41
refactor: improve vue tech stack support (#2036)
PeachScript Mar 4, 2024
932eab7
fix: type error
jeffwcx Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/dist
/compiled
/theme-default
/suites/*/compiled
/suites/preset-vue/lib
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
extends: require.resolve('@umijs/lint/dist/config/eslint'),
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true },
],
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
/target
/compiled/crates
.swc
/server
12 changes: 12 additions & 0 deletions assets-types/typings/atom/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export interface AtomComponentAsset extends AtomBaseAsset {
* props definition of component
*/
propsConfig: ObjectPropertySchema;
/**
* slots definition of component
*/
slotsConfig?: ObjectPropertySchema;
/**
* events definition of component
*/
eventsConfig?: ObjectPropertySchema;
/**
* methods definition of component
*/
methodsConfig?: ObjectPropertySchema;

/**
* available parent components of component
Expand Down
16 changes: 16 additions & 0 deletions assets-types/typings/atom/props/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,29 @@ export interface ObjectPropertySchema extends BasePropertySchema {
required?: string[];
}

export interface FunctionArgSchema {
key: string;
type: PropertySchema | string;
hasQuestionToken?: boolean;
}

export interface FunctionPropertySchema extends BasePropertySchema {
type: 'function';
signature: {
isAsync: boolean;
returnType: PropertySchema;
arguments: FunctionArgSchema[];
};
}

/**
* prop definition
*/
export type PropertySchema =
| BasePropertySchema
| ObjectPropertySchema
| ArrayPropertySchema
| FunctionPropertySchema
| StringPropertySchema
| NumberPropertySchema
| BooleanPropertySchema;
4 changes: 4 additions & 0 deletions assets-types/typings/example.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export interface ExampleBlockAsset extends ExampleBaseAsset {
value: string;
}
>;
/**
* Entry file name, you can find the relevant entry file content from `dependencies`
*/
entry?: string;
}

/**
Expand Down
155 changes: 155 additions & 0 deletions docs/guide/vue-api-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
title: 自动 API 表格
group:
title: 使用vue
order: 1
order: 2
---

# Vue 的自动 API 表格

dumi 支持 Vue 组件的自动 API 表格生成,用户只需配置`entryFile`即可开始 API 表格的使用:

```ts
import { defineConfig } from 'dumi';

export default defineConfig({
resolve: {
// 配置入口文件路径,API 解析将从这里开始
entryFile: './src/index.ts',
},
});
```

## tsconfig 配置

Vue 组件的元信息提取主要使用 TypeScript 的 TypeChecker, 所以配置`tsconfig.json`时请务必将`strictNullChecks`设为`false`

```json
{
"compilerOptions": {
"strictNullChecks": false
}
}
```

如果项目中一定要使用`strictNullChecks`,你也可以为 Vue 解析专门配置一个`tsconfig.vue.json`文件

```ts
// .dumirc.ts
import * as path from 'path';
export default {
plugins: ['@dumijs/preset-vue'],
vue: {
tsconfigPath: path.resolve(__dirname, './tsconfig.vue.json'),
},
};
```

## JSDoc 编写

:::warning
推荐在 props 中定义组件的事件,这样可以获得完整的 JSDoc 支持
:::

插件主要支持以下 JSDoc 标签:

### @description

属性描述,可以在`props`, `slots`, `methods`中使用,例如:

```ts
export default defineComponent({
props: {
/**
* @description 标题
*/
title: {
type: String,
default: '',
},
},
});
```

### @default

当 prop 的`default`选项为函数时,`default`值不会被解析,这时可以使用`@default`来声明它

```ts
defineComponent({
props: {
/**
* @default {}
*/
foo: {
default() {
return {};
},
},
},
});
```

### @exposed/@expose

:::warning
组件实例的方法或是属性的暴露,必须使用@exposed/@expose 标识,单文件组件也不例外
:::

```ts
defineExpose({
/**
* @exposed
*/
focus() {},
});
```

JSX/TSX 的组件方法暴露比较麻烦,需要用户另外声明

```ts
export default Button as typeof Button & {
new (): {
/**
* The signature of the expose api should be obtained from here
* @exposed
*/
focus: () => void;
};
};
```

### @ignore

被`@ignore`标记的属性就会被忽略,不会被解析

## Markdown 编写

在 Markdown 文件编写时

```md
<API id="Button"></API>
```

只显示 Vue 组件的`props`部分,完整的显示应该这样编写:

```md
## Button API

### Props

<API id="Button" type="props"></API>

### Slots

<API id="Button" type="slots"></API>

### Events

<API id="Button" type="events"></API>

### Methods

<API id="Button" type="methods"></API>
```
81 changes: 81 additions & 0 deletions docs/guide/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: 安装插件
group:
title: 使用vue
order: 1
order: 1
---

# 安装 Vue 支持插件

dumi 中对 Vue 的支持主要通过`@dumijs/preset-vue`插件集实现, 目前只支持 Vue3

## 安装

```bash
pnpm i vue
pnpm i -D @dumijs/preset-vue
```

> [!NOTE]
> 如果您的 Vue 版本低于 3.3.6,请安装`@vue/compiler-sfc`

## 配置

```ts
// .dumirc.ts
export default {
presets: ['@dumijs/preset-vue'],
};
```

## 插件选项

### checkerOptions

Vue 组件元数据解析选项

例如,以下配置可以使得名称为`InternalType`的类型跳过检查

```ts
// .dumirc.ts
export default {
presets: ['@dumijs/preset-vue'],
vue: {
checkerOptions: {
schema: { ignore: ['InternalType'] },
},
},
};
```

默认情况下,从`node_modules`中引入所有类型不会被解析,这样可以有效避免元信息冗余,你也可以通过配置`exclude`来定制化类型引入

```ts
// .dumirc.ts
export default {
presets: ['@dumijs/preset-vue'],
vue: {
checkerOptions: {
schema: { exclude: [/node_modules/, /mylib/] },
},
},
};
```

### tsconfigPath

TypeChecker 使用的 tsconfig,默认值为 `<project-root>/tsconfig.json`

### compiler

Live demo 需要浏览器端的编译器,因此需要加载@babel/standalone。我们提供 `babelStandaloneCDN` 选项来更改其加载地址。默认 CDN 是
`https://cdn.bootcdn.net/ajax/libs/babel-standalone/7.22.17/babel.min.js`

```js
vue: {
compiler: {
babelStandaloneCDN: 'https://cdn.bootcdn.net/ajax/libs/babel-standalone/7.22.17/babel.min.js'
},
},
```
38 changes: 36 additions & 2 deletions docs/plugin/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ api.modifyTheme((memo) => {

```ts
// CustomTechStack.ts
import type { ITechStack } from 'dumi';
import type {
IDumiTechStack,
IDumiTechStackRuntimeOpts,
} from 'dumi/tech-stack-utils';

class CustomTechStack implements IDumiTechStack {
/**
Expand All @@ -110,14 +113,45 @@ class CustomTechStack implements IDumiTechStack {
isSupported(node: hastElement, lang: string) {
return lang === 'jsx';
}

/**
* 默认情况下, dumi 只支持js/jsx/ts/tsx模块的依赖分析,
* 所以对于无法识别的文件类型需要通过此方法将文件转换为js模块
*/
onBlockLoad?(
args: IDumiTechStackOnBlockLoadArgs,
): IDumiTechStackOnBlockLoadResult {
// do something
}

/**
* 代码转换函数,返回值必须是 React 组件代码字符串
* 代码转换函数
* @note https://github.com/umijs/dumi/tree/master/src/types.ts#L57
*/
transformCode(raw: string, opts) {
// do something
return 'function Demo() { return ... }';
}

/**
* 运行时选项
*/
runtimeOpts: IDumiTechStackRuntimeOpts = {
/**
* IDemoCancelableFn函数所在的模块路径
* 操作(挂载/卸载)第三方框架组件
*/
rendererPath: '',
/**
* 运行时编译功能模块的路径
*/
compilePath: '',
/**
* 该技术堆栈的运行时插件的路径
*/
pluginPath: '',
};

/**
* 生成 demo 资产元数据(可选,通常仅在 dumi 无法分析出元数据时使用,例如非 JS 模块)
* @note https://github.com/umijs/dumi/tree/master/src/types.ts#L64
Expand Down