Skip to content

Commit 44e1ea1

Browse files
author
renjianhua
committed
feat: support vue class component and metadata
1 parent df146c2 commit 44e1ea1

File tree

32 files changed

+5676
-5231
lines changed

32 files changed

+5676
-5231
lines changed

examples/vue/.dumi/global.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@abraham/reflection'

examples/vue/.dumi/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": [
4+
"**/*"
5+
]
6+
}

examples/vue/.dumirc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export default {
77
resolve: {
88
entryFile: './src/index.ts',
99
},
10-
html2sketch: {},
1110
presets: [require.resolve('@dumijs/preset-vue')],
1211
vue: {
12+
supportTsMetadata: true,
1313
tsconfigPath: path.resolve(__dirname, './tsconfig.vue.json'),
1414
checkerOptions: {
1515
externalSymbolLinkMappings: {

examples/vue/package.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,58 @@
77
"directory": "examples/vue"
88
},
99
"license": "MIT",
10+
"sideEffects": [
11+
"**/*.css",
12+
"**/*.less"
13+
],
14+
"exports": {
15+
".": {
16+
"types": "./dist/index.d.ts",
17+
"import": {
18+
"types": "./dist/index.d.ts",
19+
"default": "./dist/index.mjs"
20+
}
21+
},
22+
"./dist/*": "./dist/*"
23+
},
24+
"module": "./dist/index.mjs",
25+
"types": "./dist/index.d.ts",
26+
"files": [
27+
"dist",
28+
"README.MD",
29+
"CHANGELOG.md"
30+
],
1031
"scripts": {
1132
"build": "node ../../bin/dumi.js build",
33+
"build:lib": "vite build",
1234
"dev": "node ../../bin/dumi.js dev",
1335
"preview": "node ../../bin/dumi.js preview",
1436
"setup": "node ../../bin/dumi.js setup",
1537
"start": "npm run dev"
1638
},
1739
"dependencies": {
40+
"@abraham/reflection": "^0.12.0",
1841
"dayjs": "^1.11.10",
1942
"element-plus": "^2.3.14",
43+
"injection-js": "^2.4.0",
2044
"pinia": "^2.1.7",
2145
"react": "^18.2.0",
22-
"vue": "3.4.28"
46+
"vue": "3.4.28",
47+
"vue3-oop": "^1.0.16"
2348
},
2449
"devDependencies": {
2550
"@dumijs/preset-vue": "workspace:*",
2651
"@typescript-eslint/parser": "^6.7.2",
52+
"@vitejs/plugin-vue": "^5.2.1",
53+
"@vue3-oop/plugin-vue-jsx": "^1.4.6",
2754
"eslint-plugin-vue": "^9.17.0",
28-
"typescript": "~4.7.4",
55+
"typescript": "^5.6.3",
2956
"unplugin-auto-import": "^0.16.6",
3057
"unplugin-element-plus": "^0.8.0",
31-
"unplugin-vue-components": "^0.25.2"
58+
"unplugin-vue-components": "^0.25.2",
59+
"vite": "^6.0.3",
60+
"vite-plugin-dts": "^4.3.0",
61+
"vite-plugin-no-bundle": "^4.0.0"
3262
},
3363
"authors": []
3464
}

examples/vue/shims-vue.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable */
2+
declare module '*.vue' {
3+
import type { DefineComponent } from 'vue';
4+
const component: DefineComponent<{}, {}, any>;
5+
export default component;
6+
}

examples/vue/src/Button/demos/Demo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Button } from '@examples/vue';
2-
import { defineComponent, ref } from 'vue';
2+
import { defineComponent, ref, type Ref } from 'vue';
33
import './demo.less';
44

55
export default defineComponent({
66
setup() {
7-
const count = ref(0);
7+
const count: Ref<number> = ref(0);
88
const handleClick = (e: Event) => {
99
count.value++;
1010
};

examples/vue/src/Button/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { defineComponent, PropType, shallowRef, SlotsType } from 'vue';
1+
import {
2+
defineComponent,
3+
renderSlot,
4+
shallowRef,
5+
type PropType,
6+
type SlotsType,
7+
} from 'vue';
28
import './button.less';
39

410
export const buttonProps = {
@@ -83,7 +89,7 @@ const Button = defineComponent({
8389
const { icon } = props;
8490
return (
8591
<button {...buttonProps} ref={buttonNodeRef}>
86-
{slots.icon ? <slot name="icon"></slot> : icon} {slots.default?.()}
92+
{renderSlot(slots, 'icon', {}, () => [icon])} {slots.default?.()}
8793
</button>
8894
);
8995
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
order: 10
3+
---
4+
5+
# Class 组件支持
6+
7+
## 基础例子
8+
9+
```tsx
10+
/**
11+
* title: 代码示例
12+
*/
13+
import { ClassCount } from '@examples/vue';
14+
import { defineComponent } from 'vue';
15+
import { Mut, VueComponent } from 'vue3-oop';
16+
17+
class AAA extends VueComponent {
18+
@Mut() count = 1001;
19+
render() {
20+
return (
21+
<div onClick={() => this.count++}>class component: {this.count}</div>
22+
);
23+
}
24+
}
25+
26+
export default defineComponent(() => () => (
27+
<div>
28+
<ClassCount initValue={10}></ClassCount>
29+
</div>
30+
));
31+
```
32+
33+
## 属性
34+
35+
<API id="ClassCount" type="props"></API>
36+
37+
## 事件
38+
39+
<API id="ClassCount" type="events"></API>
40+
41+
## 方法
42+
43+
<API id="ClassCount" type="imperative"></API>
44+
45+
## slots
46+
47+
<API id="ClassCount" type="slots"></API>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { VNodeChild } from 'vue';
2+
import { Mut, VueComponent, type ComponentProps } from 'vue3-oop';
3+
4+
export interface ClassCountProps {
5+
/**
6+
* @type T
7+
* @description 数据源
8+
*/
9+
data?: Array<number>;
10+
/**
11+
* 默认数量
12+
*/
13+
initValue?: number;
14+
15+
/**
16+
* @description 点击事件
17+
*/
18+
onClick?: () => Promise<string>;
19+
20+
slots: {
21+
icon: ({ name }: { name: number[] }) => VNodeChild;
22+
};
23+
}
24+
25+
export class ClassCount<T> extends VueComponent<ClassCountProps> {
26+
static defaultProps: ComponentProps<ClassCountProps> = [
27+
'initValue',
28+
'onClick',
29+
'data',
30+
];
31+
32+
@Mut() count = this.props.initValue;
33+
/**
34+
* foo方法
35+
* @public
36+
*/
37+
foo(name: string) {}
38+
39+
render() {
40+
return (
41+
<div style={{ accentColor: 'green' }}>
42+
<h2>我是类组件</h2>
43+
<button style={{ marginBottom: '20px' }} onClick={() => this.count++}>
44+
增加
45+
</button>
46+
<div
47+
style={
48+
'display:grid;place-items: center;height: 200px; background-color:yellow;'
49+
}
50+
>
51+
<div style="background-color:red;color: #fff;padding: 10px;">
52+
居中: {this.count}
53+
</div>
54+
</div>
55+
</div>
56+
);
57+
}
58+
}

examples/vue/src/List.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
SetupContext,
2+
type SetupContext,
33
defineComponent,
44
onMounted,
55
ref,

0 commit comments

Comments
 (0)