-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add component: input space submit reset form form-item form-lay…
…out form-button-group
- Loading branch information
1 parent
12fb5e5
commit 8a7ea0b
Showing
49 changed files
with
2,801 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,13 @@ module.exports = { | |
href: '//img.alicdn.com/imgextra/i3/O1CN01XtT3Tv1Wd1b5hNVKy_!!6000000002810-55-tps-360-360.svg', | ||
}, | ||
], | ||
[ | ||
'link', | ||
{ | ||
rel: 'stylesheet', | ||
href: 'https://unpkg.com/[email protected]/dist/antd.css', | ||
}, | ||
], | ||
], | ||
themeConfig: { | ||
logo: '//img.alicdn.com/imgextra/i2/O1CN01Kq3OHU1fph6LGqjIz_!!6000000004056-55-tps-1141-150.svg', | ||
|
@@ -53,4 +60,20 @@ module.exports = { | |
}, | ||
], | ||
], | ||
less: { | ||
modifyVars: {}, | ||
javascriptEnabled: true, | ||
}, | ||
configureWebpack: (config, isServer) => { | ||
return { | ||
resolve: { | ||
alias: { | ||
'@formily/antdv': path.resolve( | ||
__dirname, | ||
'../../packages/components/src' | ||
), | ||
}, | ||
}, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import pageComponents from '@internal/page-components' | ||
import AntDesign from 'ant-design-vue' | ||
import '@formily/antdv/style.ts' | ||
|
||
export default ({ Vue }) => { | ||
for (const [name, component] of Object.entries(pageComponents)) { | ||
Vue.component(name, component) | ||
} | ||
Vue.use(AntDesign) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const stylePrefix = 'formily-antdv' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './configs' | ||
export * from './shared' |
57 changes: 57 additions & 0 deletions
57
packages/components/src/__builtins__/shared/create-context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { Component } from 'vue' | ||
import { | ||
defineComponent, | ||
provide, | ||
inject, | ||
readonly, | ||
InjectionKey, | ||
ref, | ||
Ref, | ||
toRef, | ||
} from '@vue/composition-api' | ||
|
||
export type CreateContext<T> = { | ||
Provider: Component | ||
Consumer: Component | ||
injectKey: InjectionKey<Ref<T>> | ||
} | ||
|
||
export const createContext = <T>(defaultValue?: T): CreateContext<T> => { | ||
const injectKey: InjectionKey<Ref<T>> = Symbol() | ||
|
||
return { | ||
Provider: defineComponent({ | ||
name: 'ContextProvider', | ||
props: { | ||
value: { | ||
type: null, | ||
default() { | ||
return defaultValue ?? null | ||
}, | ||
}, | ||
}, | ||
setup(props, { slots }) { | ||
const value = toRef(props, 'value') | ||
provide(injectKey, readonly(value)) | ||
|
||
return () => slots?.default?.() | ||
}, | ||
}), | ||
|
||
Consumer: defineComponent({ | ||
name: 'ContextConsumer', | ||
setup(_props, { slots }) { | ||
const value = inject(injectKey) | ||
|
||
return () => slots?.default?.(value) | ||
}, | ||
}), | ||
injectKey, | ||
} | ||
} | ||
|
||
export const useContext = <T>(context: CreateContext<T>) => { | ||
const key = context.injectKey | ||
|
||
return inject(key, ref(null)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export * from './transform-component' | ||
export * from './resolve-component' | ||
export * from './create-context' | ||
export * from './utils' | ||
export * from './portal' | ||
export * from './loading' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { message } from 'ant-design-vue' | ||
import { MessageType } from 'ant-design-vue/types/message' | ||
|
||
export const loading = async ( | ||
loadingText = 'Loading...', | ||
processor: () => Promise<any> | ||
) => { | ||
let loadingInstance: MessageType = null | ||
let loading = setTimeout(() => { | ||
loadingInstance = message.loading(loadingText) | ||
}, 100) | ||
try { | ||
return await processor() | ||
} finally { | ||
loadingInstance() | ||
clearTimeout(loading) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { defineComponent, onBeforeUnmount } from '@vue/composition-api' | ||
import { h, Fragment } from '@formily/vue' | ||
export interface IPortalProps { | ||
id?: string | symbol | ||
} | ||
|
||
const PortalMap = new Map<string | symbol, any>() | ||
|
||
export const createPortalProvider = (id: string | symbol) => { | ||
const Portal = defineComponent({ | ||
name: 'ProtalProvider', | ||
props: { | ||
id: { | ||
type: [String, Symbol], | ||
default: id, | ||
}, | ||
}, | ||
|
||
setup(props) { | ||
onBeforeUnmount(() => { | ||
const { id } = props | ||
if (id && PortalMap.has(id)) { | ||
PortalMap.delete(id) | ||
} | ||
}) | ||
}, | ||
|
||
render() { | ||
const { id } = this | ||
if (id && !PortalMap.has(id)) { | ||
PortalMap.set(id, this) | ||
} | ||
|
||
return h(Fragment, {}, this.$scopedSlots) | ||
}, | ||
}) | ||
|
||
return Portal | ||
} | ||
|
||
export function getProtalContext(id: string | symbol) { | ||
return PortalMap.get(id) | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/components/src/__builtins__/shared/resolve-component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Component } from 'vue' | ||
import { h, toRaw } from '@vue/composition-api' | ||
import { SlotTypes } from '.' | ||
import { isVnode } from './utils' | ||
|
||
export const resolveComponent = ( | ||
child?: SlotTypes, | ||
props?: Record<string, any> | ||
) => { | ||
if (child) { | ||
if (typeof child === 'string' || typeof child === 'number') { | ||
return child | ||
} else if (typeof child === 'function') { | ||
return (child as Function)(props) | ||
} else if (isVnode(child)) { | ||
return child | ||
} else { | ||
return h(toRaw(child as Component), { props }) | ||
} | ||
} | ||
|
||
return null | ||
} |
65 changes: 65 additions & 0 deletions
65
packages/components/src/__builtins__/shared/transform-component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { Component } from 'vue' | ||
import { merge } from '@formily/shared' | ||
import { h } from '@formily/vue' | ||
import { isVue2, h as hInVue2, defineComponent } from 'vue-demi' | ||
|
||
type ListenersTransformRules = Record<string, string> | ||
|
||
export const transformComponent = <T extends Record<string, any>>( | ||
tag: any, | ||
transformRules?: ListenersTransformRules, | ||
defaultProps?: Partial<T> | ||
): Component<T> | any => { | ||
if (isVue2) { | ||
return defineComponent({ | ||
setup(props, { attrs, slots, listeners }) { | ||
return () => { | ||
const data = { | ||
attrs: { | ||
...attrs, | ||
}, | ||
on: { | ||
...listeners, | ||
}, | ||
} | ||
|
||
if (transformRules) { | ||
const transformListeners = transformRules | ||
Object.keys(transformListeners).forEach((extract) => { | ||
if (data.on !== undefined) { | ||
data.on[transformListeners[extract]] = listeners[extract] | ||
} | ||
}) | ||
} | ||
if (defaultProps) { | ||
data.attrs = merge(defaultProps, data.attrs) | ||
} | ||
|
||
return h(tag, data, slots) | ||
} | ||
}, | ||
}) | ||
} else { | ||
return defineComponent({ | ||
setup(props, { attrs, slots }) { | ||
return () => { | ||
let data = { | ||
...attrs, | ||
} | ||
if (transformRules) { | ||
const listeners = transformRules | ||
Object.keys(listeners).forEach((extract) => { | ||
const event = listeners[extract] | ||
data[`on${event[0].toUpperCase()}${event.slice(1)}`] = | ||
attrs[`on${extract[0].toUpperCase()}${extract.slice(1)}`] | ||
}) | ||
} | ||
if (defaultProps) { | ||
data = merge(defaultProps, data) | ||
} | ||
return h(tag, data, slots) | ||
} | ||
}, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Component, VNode } from 'vue' | ||
|
||
export type SlotTypes = | ||
| Component | ||
| string | ||
| number | ||
| ((props: Record<string, any>) => VNode[] | VNode) | ||
| VNode |
Oops, something went wrong.