Skip to content

Commit

Permalink
Merge branch 'formily_next' into refactor_schema_expression
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Sep 13, 2021
2 parents eb18ed4 + 6463371 commit f3113ca
Show file tree
Hide file tree
Showing 64 changed files with 929 additions and 163 deletions.
1 change: 1 addition & 0 deletions designable/antd/playground/template.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>
Designable Playground
</title>
Expand Down
4 changes: 2 additions & 2 deletions designable/setters/src/components/ValidatorSetter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ const ValidatorSchema: ISchema = {
'x-component': 'NumberPicker',
},
whitespace: {
type: 'string',
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Switch',
},
required: {
type: 'string',
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Switch',
},
Expand Down
12 changes: 8 additions & 4 deletions docs/guide/advanced/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export default {
[
'babel-plugin-import',
{ libraryName: 'antd', libraryDirectory: 'es', style: true },
'antd',
],
[
'babel-plugin-import',
{ libraryName: '@formily/antd', libraryDirectory: 'esm', style: true },
'@formily/antd',
],
],
}
Expand Down Expand Up @@ -92,12 +94,12 @@ modify `config-overrides.js`
- return config;
- };
+ module.exports = override(
+ fixBabelImports('import', {
+ fixBabelImports('antd', {
+ libraryName: 'antd',
+ libraryDirectory: 'es',
+ style: true
+ }),
+ fixBabelImports('import', {
+ fixBabelImports('@formily/antd', {
+ libraryName: '@formily/antd',
+ libraryDirectory: 'esm',
+ style: true
Expand Down Expand Up @@ -130,15 +132,17 @@ Modify `.babelrc` or babel-loader
"libraryName": "antd",
"libraryDirectory": "es",
"style": true
}
},
"antd"
],
[
"import",
{
"libraryName": "@formily/antd",
"libraryDirectory": "esm",
"style": true
}
},
"@formily/antd"
]
]
}
Expand Down
12 changes: 8 additions & 4 deletions docs/guide/advanced/build.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export default {
[
'babel-plugin-import',
{ libraryName: 'antd', libraryDirectory: 'es', style: true },
'antd',
],
[
'babel-plugin-import',
{ libraryName: '@formily/antd', libraryDirectory: 'esm', style: true },
'@formily/antd',
],
],
}
Expand Down Expand Up @@ -92,12 +94,12 @@ yarn add babel-plugin-import --dev
- return config;
- };
+ module.exports = override(
+ fixBabelImports('import', {
+ fixBabelImports('antd', {
+ libraryName: 'antd',
+ libraryDirectory: 'es',
+ style: true
+ }),
+ fixBabelImports('import', {
+ fixBabelImports('@formily/antd', {
+ libraryName: '@formily/antd',
+ libraryDirectory: 'esm',
+ style: true
Expand Down Expand Up @@ -130,15 +132,17 @@ yarn add babel-plugin-import --dev
"libraryName": "antd",
"libraryDirectory": "es",
"style": true
}
},
"antd"
],
[
"import",
{
"libraryName": "@formily/antd",
"libraryDirectory": "esm",
"style": true
}
},
"@formily/antd"
]
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/antd/docs/components/ArrayTable.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ const schema = {
'x-component-props': { width: 100, title: 'Explicitly hidden->A2' },
properties: {
a1: {
type: 'string',
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Switch',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/antd/docs/components/ArrayTable.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ const schema = {
'x-component-props': { width: 100, title: '显隐->A2' },
properties: {
a1: {
type: 'string',
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Switch',
},
Expand Down
6 changes: 3 additions & 3 deletions packages/antd/docs/components/FormItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export default () => {
bordered: false,
}}
/>
<SchemaField.String
<SchemaField.Boolean
name="Switch"
title="Switch"
x-decorator="FormItem"
Expand Down Expand Up @@ -616,7 +616,7 @@ export default () => {
inset: true,
}}
/>
<SchemaField.String
<SchemaField.Boolean
name="Switch"
title="Switch"
x-decorator="FormItem"
Expand Down Expand Up @@ -1040,7 +1040,7 @@ export default () => {
x-component="TreeSelect"
required
/>
<SchemaField.String
<SchemaField.Boolean
name="Switch"
title="Switch"
x-decorator="FormItem"
Expand Down
6 changes: 3 additions & 3 deletions packages/antd/docs/components/FormItem.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export default () => {
bordered: false,
}}
/>
<SchemaField.String
<SchemaField.Boolean
name="Switch"
title="Switch"
x-decorator="FormItem"
Expand Down Expand Up @@ -616,7 +616,7 @@ export default () => {
inset: true,
}}
/>
<SchemaField.String
<SchemaField.Boolean
name="Switch"
title="Switch"
x-decorator="FormItem"
Expand Down Expand Up @@ -1040,7 +1040,7 @@ export default () => {
x-component="TreeSelect"
required
/>
<SchemaField.String
<SchemaField.Boolean
name="Switch"
title="Switch"
x-decorator="FormItem"
Expand Down
4 changes: 2 additions & 2 deletions packages/antd/docs/components/Switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const form = createForm()
export default () => (
<FormProvider form={form}>
<SchemaField>
<SchemaField.Number
<SchemaField.Boolean
name="switch"
title="Switch"
x-decorator="FormItem"
Expand Down Expand Up @@ -57,7 +57,7 @@ const schema = {
type: 'object',
properties: {
switch: {
type: 'number',
type: 'boolean',
title: 'Switch',
'x-decorator': 'FormItem',
'x-component': 'Switch',
Expand Down
4 changes: 2 additions & 2 deletions packages/antd/docs/components/Switch.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const form = createForm()
export default () => (
<FormProvider form={form}>
<SchemaField>
<SchemaField.Number
<SchemaField.Boolean
name="switch"
title="开关"
x-decorator="FormItem"
Expand Down Expand Up @@ -57,7 +57,7 @@ const schema = {
type: 'object',
properties: {
switch: {
type: 'number',
type: 'boolean',
title: '开关',
'x-decorator': 'FormItem',
'x-component': 'Switch',
Expand Down
7 changes: 6 additions & 1 deletion packages/antd/src/array-base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ ArrayBase.SortHandle = (props) => {

ArrayBase.Index = (props) => {
const index = useIndex()
return <span {...props}>#{index + 1}.</span>
const prefixCls = usePrefixCls('formily-array-base')
return (
<span {...props} className={`${prefixCls}-index`}>
#{index + 1}.
</span>
)
}

ArrayBase.Addition = (props) => {
Expand Down
13 changes: 5 additions & 8 deletions packages/antd/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ const ArrayTablePagination: React.FC<IArrayTablePaginationProps> = (props) => {
)
}

const RowComp = (props: any) => {
return <SortableRow index={props['data-row-key'] || 0} {...props} />
}

export const ArrayTable: ComposedArrayTable = observer(
(props: TableProps<any>) => {
const ref = useRef<HTMLDivElement>()
Expand Down Expand Up @@ -305,14 +309,7 @@ export const ArrayTable: ComposedArrayTable = observer(
{...props}
/>
),
row: (props: any) => {
return (
<SortableRow
index={props['data-row-key'] || 0}
{...props}
/>
)
},
row: RowComp,
},
}}
/>
Expand Down
4 changes: 4 additions & 0 deletions packages/core/docs/api/entry/FormEffectHooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export default () => {

Side effect hooks for monitoring form value changes

<Alert>
It should be noted that this hook is triggered synchronously. For some behaviors that trigger `set` operation of `Proxy` multiple times, the results may not be as expected. For example, when deleting elements from array by `splice`, the array length will be the same as before deletion. (<a href="https://github.com/alibaba/formily/issues/2128">#2128</a>)
</Alert>

#### Signature

```ts
Expand Down
4 changes: 4 additions & 0 deletions packages/core/docs/api/entry/FormEffectHooks.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ export default () => {

用于监听表单值变化的副作用钩子

<Alert>
需要注意此钩子是同步触发的,对于某些会多次触发 Proxy set 操作的行为,得到的结果可能会与预期不符。例如: 数组 splice 删除元素时,数组长度会和删除之前相同,只是被删除元素被置为了 undefined。此时需要使用方按需添加 debounce 或 setTimeout。(<a href="https://github.com/alibaba/formily/issues/2128">#2128</a>)
</Alert>

#### 签名

```ts
Expand Down
47 changes: 47 additions & 0 deletions packages/core/src/__tests__/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,50 @@ test('nest array remove', async () => {
await metrics.remove(1)
expect(form.fields['metrics.0.content.0.attr']).not.toBeUndefined()
})

test('incomplete insertion of array elements', async () => {
const form = attach(
createForm({
values: {
array: [{ aa: 1 }, { aa: 2 }, { aa: 3 }],
},
})
)
const array = attach(
form.createArrayField({
name: 'array',
})
)
attach(
form.createObjectField({
name: '0',
basePath: 'array',
})
)
attach(
form.createField({
name: 'aa',
basePath: 'array.0',
})
)
attach(
form.createObjectField({
name: '2',
basePath: 'array',
})
)
attach(
form.createField({
name: 'aa',
basePath: 'array.2',
})
)
expect(form.fields['array.0.aa']).not.toBeUndefined()
expect(form.fields['array.1.aa']).toBeUndefined()
expect(form.fields['array.2.aa']).not.toBeUndefined()
await array.unshift({})
expect(form.fields['array.0.aa']).toBeUndefined()
expect(form.fields['array.1.aa']).not.toBeUndefined()
expect(form.fields['array.2.aa']).toBeUndefined()
expect(form.fields['array.3.aa']).not.toBeUndefined()
})
2 changes: 2 additions & 0 deletions packages/core/src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export const GlobalState = {
effectStart: false,
effectEnd: false,
}

export const NumberIndexReg = /^\.(\d+)/
Loading

0 comments on commit f3113ca

Please sign in to comment.