Skip to content

Commit f4f5fef

Browse files
authored
1.1.10 (#291)
* feat: update form * docs: update form demo * fix: update vue-ref to 1.0.3 & update form demo * feat: update form demo * feat: update form demo * docs: add 1.1.10 changelog
1 parent 65311fb commit f4f5fef

24 files changed

+1059
-947
lines changed

CHANGELOG.en-US.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
---
44

5+
## 1.1.10
6+
7+
`2018-12-7`
8+
- 🔥🔥🔥 In the 1.1.10 version, the `Form` component better supports the single-file tempalte syntax. In previous versions, complex component requirements were required to be implemented using JSX. In order to better use the automatic collection and validation of Form forms in the template, we have optimized the way components are used. All Demo files are refactored using the latest syntax.
9+
However, for the previous API, continue to support, you can not worry about the API changes, resulting in problems in the existing system.
10+
````html
11+
<template>
12+
<a-form :form="form">
13+
<a-form-item>
14+
<a-input v-decorator="[id, options]">
15+
</a-form-item>
16+
</a-form>
17+
</template>
18+
<script>
19+
export default {
20+
beforeCreate () {
21+
this.form = this.$form.createForm(this, options)
22+
},
23+
}
24+
</script>
25+
````
26+
- 🐞 Fix `Steps` component `labelPlacement` does not work [#281](https://github.com/vueComponent/ant-design-vue/issues/281)
27+
- 🐞 Fix the `Timeline` component style problem, add `reverse` `mode` props [#8e37cd](https://github.com/vueComponent/ant-design-vue/commit/8e37cd89f92ee2541f641fd860785cfd2361b2b3)
28+
- `Tree`
29+
- 🐞 Fix `treeDefaultExpandedKeys` does not work [#284](https://github.com/vueComponent/ant-design-vue/issues/284)
30+
- 🐞 Fixes the component not update when other array attributes such as `expandedKeys` `selectedKeys` changed by array’s mutation methods. [#239](https://github.com/vueComponent/ant-design-vue/issues/239)
31+
532
## 1.1.9
633

734
`2018-11-26`

CHANGELOG.zh-CN.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# 更新日志
22

3+
---
4+
5+
## 1.1.10
6+
7+
`2018-12-7`
8+
- 🔥🔥🔥 在1.1.10版本中`Form`组件更好地支持单文件tempalte语法,在以往版本中,对于复杂的组件需求,需要使用JSX才可以实现。为了更好地在template中使用Form表单的自动收集校验功能,我们优化了组件的使用方式。文档全部Demo使用最新语法重构。
9+
不过对于以往API,还是继续支持,你可以不用担心API的改变,导致已有系统出现问题。
10+
````html
11+
<template>
12+
<a-form :form="form">
13+
<a-form-item>
14+
<a-input v-decorator="[id, options]">
15+
</a-form-item>
16+
</a-form>
17+
</template>
18+
<script>
19+
export default {
20+
beforeCreate () {
21+
this.form = this.$form.createForm(this, options)
22+
},
23+
}
24+
</script>
25+
````
26+
- 🐞 修复`Steps`组件`labelPlacement`不生效问题 [#281](https://github.com/vueComponent/ant-design-vue/issues/281)
27+
- 🐞 修复`Timeline`组件样式问题,添加`reverse` `mode`属性 [#8e37cd](https://github.com/vueComponent/ant-design-vue/commit/8e37cd89f92ee2541f641fd860785cfd2361b2b3)
28+
- `Tree`
29+
- 🐞 修复`treeDefaultExpandedKeys`不生效问题 [#284](https://github.com/vueComponent/ant-design-vue/issues/284)
30+
- 🐞 修复`expandedKeys` `selectedKeys`等其它数组属性通过组件变异方法改变时组件不更新问题 [#239](https://github.com/vueComponent/ant-design-vue/issues/239)
31+
32+
333
---
434

535
## 1.1.9
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
// just for tag
3+
install: (Vue, options) => {
4+
Vue.directive('decorator', {
5+
})
6+
},
7+
}

components/_util/props-util.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const getSlots = (ele) => {
4949
if (ele.$vnode) {
5050
componentOptions = ele.$vnode.componentOptions || {}
5151
}
52-
const children = componentOptions.children || []
52+
const children = ele.children || componentOptions.children || []
5353
const slots = {}
5454
children.forEach(child => {
5555
const name = (child.data && child.data.slot) || 'default'
@@ -58,6 +58,13 @@ const getSlots = (ele) => {
5858
})
5959
return slots
6060
}
61+
const getAllChildren = (ele) => {
62+
let componentOptions = ele.componentOptions || {}
63+
if (ele.$vnode) {
64+
componentOptions = ele.$vnode.componentOptions || {}
65+
}
66+
return ele.children || componentOptions.children || []
67+
}
6168
const getSlotOptions = (ele) => {
6269
if (ele.fnOptions) { // 函数式组件
6370
return ele.fnOptions
@@ -258,5 +265,6 @@ export {
258265
camelize,
259266
getSlots,
260267
getAllProps,
268+
getAllChildren,
261269
}
262270
export default hasProp

components/form/Form.jsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import PropTypes from '../_util/vue-types'
22
import classNames from 'classnames'
3+
import Vue from 'vue'
34
import isRegExp from 'lodash/isRegExp'
5+
import warning from '../_util/warning'
46
import createDOMForm from '../vc-form/src/createDOMForm'
57
import createFormField from '../vc-form/src/createFormField'
68
import FormItem from './FormItem'
@@ -54,7 +56,7 @@ export const WrappedFormUtils = {
5456

5557
export const FormProps = {
5658
layout: PropTypes.oneOf(['horizontal', 'inline', 'vertical']),
57-
form: PropTypes.shape(WrappedFormUtils).loose,
59+
form: PropTypes.object,
5860
// onSubmit: React.FormEventHandler<any>;
5961
prefixCls: PropTypes.string,
6062
hideRequiredMark: PropTypes.bool,
@@ -110,29 +112,13 @@ export const ValidationRule = {
110112
// validateFirst?: boolean;
111113
// };
112114

113-
export default {
115+
const Form = {
114116
name: 'AForm',
115117
props: initDefaultProps(FormProps, {
116118
prefixCls: 'ant-form',
117119
layout: 'horizontal',
118120
hideRequiredMark: false,
119121
}),
120-
// static defaultProps = {
121-
// prefixCls: 'ant-form',
122-
// layout: 'horizontal',
123-
// hideRequiredMark: false,
124-
// onSubmit (e) {
125-
// e.preventDefault()
126-
// },
127-
// };
128-
129-
// static propTypes = {
130-
// prefixCls: PropTypes.string,
131-
// layout: PropTypes.oneOf(['horizontal', 'inline', 'vertical']),
132-
// children: PropTypes.any,
133-
// onSubmit: PropTypes.func,
134-
// hideRequiredMark: PropTypes.bool,
135-
// };
136122

137123
Item: FormItem,
138124

@@ -146,11 +132,19 @@ export default {
146132
fieldDataProp: FIELD_DATA_PROP,
147133
})
148134
},
135+
createForm (context, options = {}) {
136+
return new Vue(Form.create({ ...options, templateContext: context })())
137+
},
149138
provide () {
150139
return {
151140
FormProps: this.$props,
152141
}
153142
},
143+
watch: {
144+
form () {
145+
this.$forceUpdate()
146+
},
147+
},
154148
methods: {
155149
onSubmit (e) {
156150
const { $listeners } = this
@@ -174,6 +168,10 @@ export default {
174168
[`${prefixCls}-hide-required-mark`]: hideRequiredMark,
175169
})
176170
if (autoFormCreate) {
171+
warning(
172+
false,
173+
'`autoFormCreate` is deprecated. please use `form` instead.'
174+
)
177175
const DomForm = this.DomForm || createDOMForm({
178176
fieldNameProp: 'id',
179177
...options,
@@ -214,3 +212,5 @@ export default {
214212
return <form onSubmit={onSubmit} class={formClassName}>{$slots.default}</form>
215213
},
216214
}
215+
216+
export default Form

components/form/FormItem.jsx

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import intersperse from 'intersperse'
22
import PropTypes from '../_util/vue-types'
33
import classNames from 'classnames'
4+
import find from 'lodash/find'
45
import Row from '../grid/Row'
56
import Col, { ColProps } from '../grid/Col'
67
import warning from '../_util/warning'
78
import { FIELD_META_PROP, FIELD_DATA_PROP } from './constants'
8-
import { initDefaultProps, getComponentFromProp, filterEmpty, getSlotOptions, getSlots, isValidElement } from '../_util/props-util'
9+
import { initDefaultProps, getComponentFromProp, filterEmpty, getSlotOptions, isValidElement, getSlots, getAllChildren } from '../_util/props-util'
910
import getTransitionProps from '../_util/getTransitionProps'
1011
import BaseMixin from '../_util/BaseMixin'
11-
import { cloneElement } from '../_util/vnode'
12+
import { cloneElement, cloneVNodes } from '../_util/vnode'
1213
export const FormItemProps = {
1314
id: PropTypes.string,
1415
prefixCls: PropTypes.string,
@@ -47,6 +48,10 @@ export default {
4748
'`Form.Item` cannot generate `validateStatus` and `help` automatically, ' +
4849
'while there are more than one `getFieldDecorator` in it.',
4950
)
51+
warning(
52+
!this.fieldDecoratorId,
53+
'`fieldDecoratorId` is deprecated. please use `v-decorator={id, options}` instead.'
54+
)
5055
},
5156
methods: {
5257
getHelpMessage () {
@@ -81,15 +86,12 @@ export default {
8186
if (getSlotOptions(child).__ANT_FORM_ITEM) {
8287
continue
8388
}
84-
const attrs = child.data && child.data.attrs
85-
if (!attrs) {
86-
continue
87-
}
88-
const slots = getSlots(child)
89+
const children = getAllChildren(child)
90+
const attrs = child.data && child.data.attrs || {}
8991
if (FIELD_META_PROP in attrs) { // And means FIELD_DATA_PROP in child.props, too.
9092
controls.push(child)
91-
} else if (slots.default) {
92-
controls = controls.concat(this.getControls(slots.default, recursively))
93+
} else if (children) {
94+
controls = controls.concat(this.getControls(children, recursively))
9395
}
9496
}
9597
return controls
@@ -339,21 +341,54 @@ export default {
339341
</Row>
340342
)
341343
},
344+
decoratorOption (vnode) {
345+
if (vnode.data && vnode.data.directives) {
346+
const directive = find(vnode.data.directives, ['name', 'decorator'])
347+
warning(
348+
!directive || (directive && Array.isArray(directive.value)),
349+
`Invalid directive: type check failed for directive "decorator". Expected Array, got ${typeof directive.value}. At ${vnode.tag}.`,
350+
)
351+
return directive ? directive.value : null
352+
} else {
353+
return null
354+
}
355+
},
356+
decoratorChildren (vnodes) {
357+
const { FormProps } = this
358+
const getFieldDecorator = FormProps.form.getFieldDecorator
359+
vnodes.forEach((vnode, index) => {
360+
if (vnode.children) {
361+
vnode.children = this.decoratorChildren(cloneVNodes(vnode.children))
362+
} else if (vnode.componentOptions && vnode.componentOptions.children) {
363+
vnode.componentOptions.children = this.decoratorChildren(cloneVNodes(vnode.componentOptions.children))
364+
}
365+
const option = this.decoratorOption(vnode)
366+
if (option && option[0]) {
367+
vnodes[index] = getFieldDecorator(option[0], option[1])(vnode)
368+
}
369+
})
370+
return vnodes
371+
},
342372
},
343373

344374
render () {
345-
const { $slots, decoratorFormProps, fieldDecoratorId, fieldDecoratorOptions = {}} = this
346-
const child = filterEmpty($slots.default || [])
375+
const { $slots, decoratorFormProps, fieldDecoratorId, fieldDecoratorOptions = {}, FormProps } = this
376+
let child = filterEmpty($slots.default || [])
347377
if (decoratorFormProps.form && fieldDecoratorId && child.length) {
348378
const getFieldDecorator = decoratorFormProps.form.getFieldDecorator
349379
child[0] = getFieldDecorator(fieldDecoratorId, fieldDecoratorOptions)(child[0])
350380
warning(
351381
!(child.length > 1),
352382
'`autoFormCreate` just `decorator` then first children. but you can use JSX to support multiple children',
353383
)
384+
this.slotDefault = child
385+
} else if (FormProps.form) {
386+
child = cloneVNodes(child)
387+
this.slotDefault = this.decoratorChildren(child)
388+
} else {
389+
this.slotDefault = child
354390
}
355391

356-
this.slotDefault = child
357392
const children = this.renderChildren()
358393
return this.renderFormItem(children)
359394
},

0 commit comments

Comments
 (0)