Skip to content

Commit 8a7ea0b

Browse files
committed
feat: add component: input space submit reset form form-item form-layout form-button-group
1 parent 12fb5e5 commit 8a7ea0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2801
-129
lines changed

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"node": true
44
},
55
"extends": [
6-
"plugin:vue/vue3-recommended",
6+
"plugin:vue/vue3-essential",
77
"plugin:@typescript-eslint/recommended",
88
"prettier/@typescript-eslint"
99
],

docs/.vuepress/config.js

+23
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ module.exports = {
1818
href: '//img.alicdn.com/imgextra/i3/O1CN01XtT3Tv1Wd1b5hNVKy_!!6000000002810-55-tps-360-360.svg',
1919
},
2020
],
21+
[
22+
'link',
23+
{
24+
rel: 'stylesheet',
25+
href: 'https://unpkg.com/ant-design-vue@1.7.8/dist/antd.css',
26+
},
27+
],
2128
],
2229
themeConfig: {
2330
logo: '//img.alicdn.com/imgextra/i2/O1CN01Kq3OHU1fph6LGqjIz_!!6000000004056-55-tps-1141-150.svg',
@@ -53,4 +60,20 @@ module.exports = {
5360
},
5461
],
5562
],
63+
less: {
64+
modifyVars: {},
65+
javascriptEnabled: true,
66+
},
67+
configureWebpack: (config, isServer) => {
68+
return {
69+
resolve: {
70+
alias: {
71+
'@formily/antdv': path.resolve(
72+
__dirname,
73+
'../../packages/components/src'
74+
),
75+
},
76+
},
77+
}
78+
},
5679
}

docs/.vuepress/enhanceApp.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import pageComponents from '@internal/page-components'
2+
import AntDesign from 'ant-design-vue'
3+
import '@formily/antdv/style.ts'
24

35
export default ({ Vue }) => {
46
for (const [name, component] of Object.entries(pageComponents)) {
57
Vue.component(name, component)
68
}
9+
Vue.use(AntDesign)
710
}

docs/guide/input.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
## API
1818

19-
参考 [https://element.eleme.io/#/zh-CN/component/input](https://element.eleme.io/#/zh-CN/component/input)
19+
参考 [https://antdv.com/components/input-cn](https://antdv.com/components/input-cn)

docs/guide/reset.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
## API
2020

21-
按钮相关的 API 属性,我们参考 [https://element.eleme.io/#/zh-CN/component/button](https://element.eleme.io/#/zh-CN/component/button) 即可,剩下是 Reset 组件独有的 API 属性
21+
按钮相关的 API 属性,我们参考 [https://antdv.com/components/button-cn](https://antdv.com/components/button-cn) 即可,剩下是 Reset 组件独有的 API 属性
2222

2323
### 事件
2424

docs/guide/space.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
## API
1818

19-
参考 [https://ant.design/components/space-cn/](https://ant.design/components/space-cn/)
19+
参考 [https://antdv.com/components/space-cn](https://antdv.com/components/space-cn)

docs/guide/submit.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## API
1414

15-
按钮相关的 API 属性,我们参考 [https://element.eleme.io/#/zh-CN/component/button](https://element.eleme.io/#/zh-CN/component/button) 即可,剩下是 Submit 组件独有的 API 属性
15+
按钮相关的 API 属性,我们参考 [https://antdv.com/components/button-cn](https://antdv.com/components/button-cn) 即可,剩下是 Submit 组件独有的 API 属性
1616

1717
| 属性名 | 类型 | 描述 | 默认值 |
1818
| --------------- | ------------------------------------------------------------------------------------------------ | -------------------- | ------------------------------------- | --- |

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@
2525
"lint": "eslint ."
2626
},
2727
"devDependencies": {
28-
"@formily/template": "^1.0.0-alpha.0",
28+
"@commitlint/cli": "^14.1.0",
29+
"@commitlint/config-conventional": "^14.1.0",
30+
"@commitlint/prompt-cli": "^14.1.0",
2931
"@formily/core": "^2.0.0",
32+
"@formily/template": "^1.0.0-alpha.0",
3033
"@formily/vue": "^2.0.0",
31-
"@vue/composition-api": "^1.4.0",
3234
"@testing-library/jest-dom": "^5.0.0",
3335
"@testing-library/vue": "^5.6.2",
34-
"@vue/test-utils": "1.0.0-beta.22",
3536
"@types/jest": "^24.0.18",
3637
"@typescript-eslint/eslint-plugin": "^4.9.1",
3738
"@typescript-eslint/parser": "^4.8.2",
39+
"@vue/composition-api": "^1.4.0",
40+
"@vue/test-utils": "1.0.0-beta.22",
3841
"@vuepress-dumi/vuepress-plugin-dumi-previewer": "0.3.3",
3942
"@vuepress-dumi/vuepress-theme-dumi": "0.3.3",
4043
"@vuepress/plugin-back-to-top": "^1.8.2",
@@ -50,23 +53,20 @@
5053
"eslint-plugin-promise": "^4.0.0",
5154
"eslint-plugin-vue": "^7.0.1",
5255
"ghooks": "^2.0.4",
56+
"lerna": "^4.0.0",
57+
"less": "^4.1.2",
58+
"less-loader": "^5.0.0",
5359
"lint-staged": "^8.2.1",
54-
"@commitlint/cli": "^14.1.0",
55-
"@commitlint/prompt-cli": "^14.1.0",
56-
"@commitlint/config-conventional": "^14.1.0",
5760
"prettier": "^2.2.1",
5861
"pretty-quick": "^3.1.0",
62+
"raw-loader": "^4.0.0",
5963
"ts-import-plugin": "1.6.1",
6064
"ts-jest": "^26.0.0",
6165
"ts-node": "^9.1.1",
62-
"lerna": "^4.0.0",
6366
"typescript": "^4.1.5",
6467
"vue": "^2.6.0",
6568
"vuepress": "^1.8.2",
66-
"vuepress-plugin-typescript": "^0.3.1",
67-
"sass": "^1.34.1",
68-
"sass-loader": "^8.0.2",
69-
"raw-loader": "^4.0.0"
69+
"vuepress-plugin-typescript": "^0.3.1"
7070
},
7171
"repository": {
7272
"type": "git",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const stylePrefix = 'formily-antdv'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './configs'
2+
export * from './shared'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { Component } from 'vue'
2+
import {
3+
defineComponent,
4+
provide,
5+
inject,
6+
readonly,
7+
InjectionKey,
8+
ref,
9+
Ref,
10+
toRef,
11+
} from '@vue/composition-api'
12+
13+
export type CreateContext<T> = {
14+
Provider: Component
15+
Consumer: Component
16+
injectKey: InjectionKey<Ref<T>>
17+
}
18+
19+
export const createContext = <T>(defaultValue?: T): CreateContext<T> => {
20+
const injectKey: InjectionKey<Ref<T>> = Symbol()
21+
22+
return {
23+
Provider: defineComponent({
24+
name: 'ContextProvider',
25+
props: {
26+
value: {
27+
type: null,
28+
default() {
29+
return defaultValue ?? null
30+
},
31+
},
32+
},
33+
setup(props, { slots }) {
34+
const value = toRef(props, 'value')
35+
provide(injectKey, readonly(value))
36+
37+
return () => slots?.default?.()
38+
},
39+
}),
40+
41+
Consumer: defineComponent({
42+
name: 'ContextConsumer',
43+
setup(_props, { slots }) {
44+
const value = inject(injectKey)
45+
46+
return () => slots?.default?.(value)
47+
},
48+
}),
49+
injectKey,
50+
}
51+
}
52+
53+
export const useContext = <T>(context: CreateContext<T>) => {
54+
const key = context.injectKey
55+
56+
return inject(key, ref(null))
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from './transform-component'
2+
export * from './resolve-component'
3+
export * from './create-context'
4+
export * from './utils'
5+
export * from './portal'
6+
export * from './loading'
7+
export * from './types'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { message } from 'ant-design-vue'
2+
import { MessageType } from 'ant-design-vue/types/message'
3+
4+
export const loading = async (
5+
loadingText = 'Loading...',
6+
processor: () => Promise<any>
7+
) => {
8+
let loadingInstance: MessageType = null
9+
let loading = setTimeout(() => {
10+
loadingInstance = message.loading(loadingText)
11+
}, 100)
12+
try {
13+
return await processor()
14+
} finally {
15+
loadingInstance()
16+
clearTimeout(loading)
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { defineComponent, onBeforeUnmount } from '@vue/composition-api'
2+
import { h, Fragment } from '@formily/vue'
3+
export interface IPortalProps {
4+
id?: string | symbol
5+
}
6+
7+
const PortalMap = new Map<string | symbol, any>()
8+
9+
export const createPortalProvider = (id: string | symbol) => {
10+
const Portal = defineComponent({
11+
name: 'ProtalProvider',
12+
props: {
13+
id: {
14+
type: [String, Symbol],
15+
default: id,
16+
},
17+
},
18+
19+
setup(props) {
20+
onBeforeUnmount(() => {
21+
const { id } = props
22+
if (id && PortalMap.has(id)) {
23+
PortalMap.delete(id)
24+
}
25+
})
26+
},
27+
28+
render() {
29+
const { id } = this
30+
if (id && !PortalMap.has(id)) {
31+
PortalMap.set(id, this)
32+
}
33+
34+
return h(Fragment, {}, this.$scopedSlots)
35+
},
36+
})
37+
38+
return Portal
39+
}
40+
41+
export function getProtalContext(id: string | symbol) {
42+
return PortalMap.get(id)
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component } from 'vue'
2+
import { h, toRaw } from '@vue/composition-api'
3+
import { SlotTypes } from '.'
4+
import { isVnode } from './utils'
5+
6+
export const resolveComponent = (
7+
child?: SlotTypes,
8+
props?: Record<string, any>
9+
) => {
10+
if (child) {
11+
if (typeof child === 'string' || typeof child === 'number') {
12+
return child
13+
} else if (typeof child === 'function') {
14+
return (child as Function)(props)
15+
} else if (isVnode(child)) {
16+
return child
17+
} else {
18+
return h(toRaw(child as Component), { props })
19+
}
20+
}
21+
22+
return null
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import type { Component } from 'vue'
2+
import { merge } from '@formily/shared'
3+
import { h } from '@formily/vue'
4+
import { isVue2, h as hInVue2, defineComponent } from 'vue-demi'
5+
6+
type ListenersTransformRules = Record<string, string>
7+
8+
export const transformComponent = <T extends Record<string, any>>(
9+
tag: any,
10+
transformRules?: ListenersTransformRules,
11+
defaultProps?: Partial<T>
12+
): Component<T> | any => {
13+
if (isVue2) {
14+
return defineComponent({
15+
setup(props, { attrs, slots, listeners }) {
16+
return () => {
17+
const data = {
18+
attrs: {
19+
...attrs,
20+
},
21+
on: {
22+
...listeners,
23+
},
24+
}
25+
26+
if (transformRules) {
27+
const transformListeners = transformRules
28+
Object.keys(transformListeners).forEach((extract) => {
29+
if (data.on !== undefined) {
30+
data.on[transformListeners[extract]] = listeners[extract]
31+
}
32+
})
33+
}
34+
if (defaultProps) {
35+
data.attrs = merge(defaultProps, data.attrs)
36+
}
37+
38+
return h(tag, data, slots)
39+
}
40+
},
41+
})
42+
} else {
43+
return defineComponent({
44+
setup(props, { attrs, slots }) {
45+
return () => {
46+
let data = {
47+
...attrs,
48+
}
49+
if (transformRules) {
50+
const listeners = transformRules
51+
Object.keys(listeners).forEach((extract) => {
52+
const event = listeners[extract]
53+
data[`on${event[0].toUpperCase()}${event.slice(1)}`] =
54+
attrs[`on${extract[0].toUpperCase()}${extract.slice(1)}`]
55+
})
56+
}
57+
if (defaultProps) {
58+
data = merge(defaultProps, data)
59+
}
60+
return h(tag, data, slots)
61+
}
62+
},
63+
})
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component, VNode } from 'vue'
2+
3+
export type SlotTypes =
4+
| Component
5+
| string
6+
| number
7+
| ((props: Record<string, any>) => VNode[] | VNode)
8+
| VNode

0 commit comments

Comments
 (0)