Skip to content

Commit b229613

Browse files
authored
chore(project): release v0.1.15 (#94)
* fix(@uform/core): fix #84 #91
1 parent f0cd37d commit b229613

File tree

14 files changed

+82
-40
lines changed

14 files changed

+82
-40
lines changed

packages/antd/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/antd",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib",
66
"repository": {
@@ -21,7 +21,7 @@
2121
"react-dom": ">=16.8.0"
2222
},
2323
"dependencies": {
24-
"@uform/react": "0.1.14",
24+
"@uform/react": "0.1.15",
2525
"@uform/utils": "0.1.8",
2626
"classnames": "^2.2.6",
2727
"moveto": "^1.7.4",

packages/builder-next/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/builder-next",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib/index.js",
66
"repository": {
@@ -21,7 +21,7 @@
2121
"react-dom": ">=16.8.0"
2222
},
2323
"dependencies": {
24-
"@uform/builder": "0.1.14"
24+
"@uform/builder": "0.1.15"
2525
},
2626
"devDependencies": {
2727
"@alifd/next": "^1.13.1"

packages/builder/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/builder",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib/index.js",
66
"repository": {
@@ -24,7 +24,7 @@
2424
"react-dom": ">=16.8.0"
2525
},
2626
"dependencies": {
27-
"@uform/react": "0.1.14",
27+
"@uform/react": "0.1.15",
2828
"@uform/utils": "0.1.8",
2929
"@uform/validator": "0.1.8",
3030
"classnames": "^2.2.5",

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/core",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib",
66
"repository": {

packages/core/src/field.js

+27-19
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,56 @@ export class Field {
2828
this.destructed = false
2929
this.loading = false
3030
this.errors = []
31+
this.props = {}
3132
this.effectErrors = []
3233
this.initialized = false
3334
this.initialize(options)
3435
this.initialized = true
3536
}
3637

3738
initialize(options) {
38-
const editable = this.getEditableFromProps(options.props)
3939
const rules = this.getRulesFromProps(options.props)
4040
this.value = !isEmpty(options.value) ? clone(options.value) : this.value
41-
this.initialValue = !isEmpty(options.initialValue)
42-
? options.initialValue
43-
: !isEmpty(this.initialValue)
44-
? this.initialValue
45-
: this.getInitialValueFromProps(options.props)
4641
this.name = !isEmpty(options.name) ? options.name : this.name || ''
4742
this.namePath = resolveFieldPath(this.name)
48-
this.editable = !isEmpty(editable)
49-
? editable
50-
: isEmpty(this.editable)
51-
? this.editable
52-
: this.getContextEditable()
43+
5344
this.path = resolveFieldPath(
5445
!isEmpty(options.path) ? options.path : this.path || []
5546
)
5647
this.rules = !isEmpty(rules) ? rules : this.rules
5748
this.required = hasRequired(this.rules)
58-
this.props = !isEmpty(options.props)
59-
? !isEmpty(this.props)
49+
50+
if (isEmpty(options.props)) {
51+
this.initialValue = !isEmpty(options.initialValue)
52+
? options.initialValue
53+
: this.initialValue
54+
} else {
55+
this.initialValue = !isEmpty(options.initialValue)
56+
? options.initialValue
57+
: !isEmpty(this.initialValue)
58+
? this.initialValue
59+
: this.getInitialValueFromProps(options.props)
60+
this.props = !isEmpty(this.props)
6061
? { ...this.props, ...clone(options.props) }
6162
: clone(options.props)
62-
: this.props || {}
63-
if (this.removed) {
64-
this.removed = false
65-
this.visible = true
63+
const editable = this.getEditableFromProps(options.props)
64+
this.editable = !isEmpty(editable) ? editable : this.getContextEditable()
6665
}
66+
6767
if (!this.initialized) {
6868
if (isEmpty(this.value) && !isEmpty(this.initialValue)) {
6969
this.value = clone(this.initialValue)
7070
this.context.setIn(this.name, this.value)
7171
this.context.setInitialValueIn(this.name, this.initialValue)
7272
}
7373
}
74+
75+
if (this.removed) {
76+
this.removed = false
77+
this.visible = true
78+
this.context.triggerEffect('onFieldChange', this.publishState())
79+
}
80+
7481
if (isFn(options.onChange)) {
7582
this.onChange(options.onChange)
7683
}
@@ -192,14 +199,15 @@ export class Field {
192199
this.notify()
193200
}
194201

195-
restore() {
202+
mount() {
196203
if (this.removed) {
197204
this.visible = true
198205
this.removed = false
206+
this.context.triggerEffect('onFieldChange', this.publishState())
199207
}
200208
}
201209

202-
remove() {
210+
unmount() {
203211
this.value = undefined
204212
this.initialValue = undefined
205213
this.visible = false

packages/core/src/form.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,14 @@ export class Form {
333333
const field = this.fields[name]
334334
if (field) {
335335
field.initialize({
336-
...options,
336+
path: options.path,
337+
onChange: options.onChange,
337338
value: !isEmpty(value) ? value : initialValue,
338339
initialValue: initialValue
339340
})
340341
this.asyncUpdate(() => {
341342
this.updateFieldStateFromBuffer(field)
342343
})
343-
this.triggerEffect('onFieldChange', field.publishState())
344344
} else {
345345
this.fields[name] = new Field(this, {
346346
name,

packages/core/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export const createForm = ({
5252

5353
form.syncUpdate(() => {
5454
form.triggerEffect('onFormInit', form.publishState())
55+
fields.forEach(field => {
56+
form.triggerEffect('onFieldChange', field.publishState())
57+
})
5558
})
5659
return form
5760
}

packages/next/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/next",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib",
66
"repository": {
@@ -21,7 +21,7 @@
2121
"react-dom": ">=16.8.0"
2222
},
2323
"dependencies": {
24-
"@uform/react": "0.1.14",
24+
"@uform/react": "0.1.15",
2525
"@uform/utils": "0.1.8",
2626
"classnames": "^2.2.6",
2727
"moveto": "^1.7.4",

packages/printer/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/printer",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib",
66
"repository": {
@@ -20,7 +20,7 @@
2020
"react-dom": ">=16.8.0"
2121
},
2222
"dependencies": {
23-
"@uform/react": "0.1.14",
23+
"@uform/react": "0.1.15",
2424
"react-modal": "^3.8.1",
2525
"styled-components": "^4.1.1"
2626
},

packages/react/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/react",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib",
66
"repository": {
@@ -20,7 +20,7 @@
2020
"react-dom": ">=16.8.0"
2121
},
2222
"dependencies": {
23-
"@uform/core": "0.1.14",
23+
"@uform/core": "0.1.15",
2424
"@uform/utils": "0.1.8",
2525
"@uform/validator": "0.1.8",
2626
"pascal-case": "^2.0.1",

packages/react/src/__tests__/effects.spec.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ beforeEach(() => {
2626
})
2727
registerFormField(
2828
'string',
29-
connect()(props => <input {...props} value={props.value || ''} />)
29+
connect()(props =>
30+
props.disabled ? (
31+
'Disabled'
32+
) : (
33+
<input {...props} value={props.value || ''} />
34+
)
35+
)
3036
)
3137
})
3238

@@ -130,3 +136,28 @@ test('onFieldChange will trigger with initialValues', async () => {
130136
expect(callback.mock.calls[0][0].value).toBe(undefined)
131137
expect(callback.mock.calls[1][0].value).toBe(123)
132138
})
139+
140+
test('setFieldState x-props with onFormInit', async () => {
141+
const TestComponent = () => {
142+
return (
143+
<SchemaForm
144+
effects={($, { setFieldState }) => {
145+
$('onFormInit').subscribe(() => {
146+
setFieldState('aaa', state => {
147+
state.props['x-props'].disabled = true
148+
})
149+
})
150+
}}
151+
>
152+
<Field name='aaa' type='string' x-props={{ disabled: false }} />
153+
<button type='submit' data-testid='btn'>
154+
Submit
155+
</button>
156+
</SchemaForm>
157+
)
158+
}
159+
160+
const { queryByText } = render(<TestComponent />)
161+
await sleep(33)
162+
expect(queryByText('Disabled')).toBeVisible()
163+
})

packages/react/src/state/field.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ const StateField = createHOC((options, Field) => {
4444

4545
componentWillUnmount() {
4646
this.unmounted = true
47-
this.field.remove()
47+
this.field.unmount()
4848
}
4949

5050
componentDidMount() {
5151
this.unmounted = false
52-
this.field.restore()
52+
this.field.mount()
5353
}
5454

5555
componentDidUpdate(prevProps) {

packages/utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/utils",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib",
66
"repository": {

packages/validator/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uform/validator",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"license": "MIT",
55
"main": "lib",
66
"repository": {
@@ -18,7 +18,7 @@
1818
"@babel/runtime": "^7.4.4"
1919
},
2020
"dependencies": {
21-
"@uform/utils": "0.1.14"
21+
"@uform/utils": "0.1.15"
2222
},
2323
"publishConfig": {
2424
"access": "public"

0 commit comments

Comments
 (0)