feat: upgrade formily and fix type check errors

This commit is contained in:
chenos 2021-08-15 12:16:11 +08:00
parent ce63f0fbe6
commit e9ddd4fd7e
40 changed files with 1248 additions and 1161 deletions

View File

@ -34,7 +34,7 @@
"@typescript-eslint/eslint-plugin": "^4.9.1", "@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.8.2", "@typescript-eslint/parser": "^4.8.2",
"@umijs/plugin-antd": "^0.9.1", "@umijs/plugin-antd": "^0.9.1",
"antd": "^4.16.3", "antd": "^4.16.11",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"dumi": "^1.1.16", "dumi": "^1.1.16",
"eslint": "^7.4.0", "eslint": "^7.4.0",

View File

@ -1,6 +1,4 @@
import { ISchema } from '@formily/react'; export const login = {
export const login: ISchema = {
key: 'dtf9j0b8p9u', key: 'dtf9j0b8p9u',
type: 'object', type: 'object',
properties: { properties: {

View File

@ -21,9 +21,9 @@
"@antv/g2plot": "^2.3.27", "@antv/g2plot": "^2.3.27",
"@dnd-kit/core": "^3.1.1", "@dnd-kit/core": "^3.1.1",
"@dnd-kit/sortable": "^4.0.0", "@dnd-kit/sortable": "^4.0.0",
"@formily/antd": "^2.0.0-beta.72", "@formily/antd": "^2.0.0-rc.1",
"@formily/core": "^2.0.0-beta.72", "@formily/core": "^2.0.0-rc.1",
"@formily/react": "^2.0.0-beta.72", "@formily/react": "^2.0.0-rc.1",
"@monaco-editor/react": "^4.2.1", "@monaco-editor/react": "^4.2.1",
"ahooks": "^2.10.2", "ahooks": "^2.10.2",
"axios": "^0.21.1", "axios": "^0.21.1",

View File

@ -1,10 +1,11 @@
import React, { useContext, useEffect } from 'react'; import React, { useContext, useEffect } from 'react';
import { Button } from 'antd'; import { Button } from 'antd';
import { SchemaRenderer } from '../schema-renderer'; import { SchemaRenderer } from '../schema-renderer';
import { ISchema, useForm } from '@formily/react'; import { useForm } from '@formily/react';
import { Resource } from '../../resource'; import { Resource } from '../../resource';
import { useRequest } from 'ahooks'; import { useRequest } from 'ahooks';
import { VisibleContext } from '../../context'; import { VisibleContext } from '../../context';
import { ISchema } from '../../schemas';
const useResource = ({ onSuccess }) => { const useResource = ({ onSuccess }) => {
const resource = Resource.make({ const resource = Resource.make({

View File

@ -11,11 +11,12 @@ import { Resource } from '../../../resource';
import { TableRowContext, useTable } from '../../../schemas/table'; import { TableRowContext, useTable } from '../../../schemas/table';
import { useRequest } from 'ahooks'; import { useRequest } from 'ahooks';
import { VisibleContext } from '../../../context'; import { VisibleContext } from '../../../context';
import { connect, ISchema, observer, useForm } from '@formily/react'; import { connect, observer, useForm } from '@formily/react';
import { DescriptionsContext } from '../../../schemas/form'; import { DescriptionsContext } from '../../../schemas/form';
import { createContext } from 'react'; import { createContext } from 'react';
import { ActionPermissionField } from './ActionPermissionField'; import { ActionPermissionField } from './ActionPermissionField';
import { MenuPermissionTable } from './MenuPermissionTable'; import { MenuPermissionTable } from './MenuPermissionTable';
import { ISchema } from '../../../';
export const RoleContext = createContext(null); export const RoleContext = createContext(null);

View File

@ -7,7 +7,7 @@ import { useCollectionsContext } from '../../constate/Collections';
export const useAsyncDataSource = (service: any) => (field: any) => { export const useAsyncDataSource = (service: any) => (field: any) => {
field.loading = true; field.loading = true;
service(field).then( service(field).then(
action((data: any) => { action.bound((data: any) => {
field.dataSource = data; field.dataSource = data;
field.loading = false; field.loading = false;
}), }),

View File

@ -2,7 +2,6 @@ import { createForm } from '@formily/core';
import { import {
createSchemaField, createSchemaField,
FormProvider, FormProvider,
ISchema,
Schema, Schema,
SchemaOptionsContext, SchemaOptionsContext,
useFieldSchema, useFieldSchema,
@ -54,6 +53,7 @@ import { Page } from '../../schemas/page';
import { Chart } from '../../schemas/chart'; import { Chart } from '../../schemas/chart';
import { useDesignableSwitchContext } from '../../constate/DesignableSwitch'; import { useDesignableSwitchContext } from '../../constate/DesignableSwitch';
import { action } from '@formily/reactive'; import { action } from '@formily/reactive';
import { ISchema, FormilyISchema } from '../../schemas';
export const BlockContext = createContext({ dragRef: null }); export const BlockContext = createContext({ dragRef: null });
@ -67,7 +67,7 @@ interface DesignableContextProps {
export const useAsyncDataSource = (service: any) => (field: any) => { export const useAsyncDataSource = (service: any) => (field: any) => {
field.loading = true; field.loading = true;
service(field).then( service(field).then(
action((data: any) => { action.bound((data: any) => {
field.dataSource = data; field.dataSource = data;
field.loading = false; field.loading = false;
}), }),
@ -163,7 +163,7 @@ export function findPropertyByPath(schema: Schema, path?: any): Schema {
return property; return property;
} }
export function addPropertyBefore(target: Schema, data: ISchema) { export function addPropertyBefore(target: Schema, data: ISchema | FormilyISchema) {
Object.keys(target.parent.properties).forEach((name) => { Object.keys(target.parent.properties).forEach((name) => {
if (name === target.name) { if (name === target.name) {
target.parent.addProperty(data.name, data); target.parent.addProperty(data.name, data);
@ -174,7 +174,7 @@ export function addPropertyBefore(target: Schema, data: ISchema) {
}); });
} }
export function addPropertyAfter(target: Schema, data: ISchema) { export function addPropertyAfter(target: Schema, data: ISchema | FormilyISchema) {
Object.keys(target.parent.properties).forEach((name) => { Object.keys(target.parent.properties).forEach((name) => {
const property = target.parent.properties[name]; const property = target.parent.properties[name];
property.parent.removeProperty(property.name); property.parent.removeProperty(property.name);
@ -185,7 +185,7 @@ export function addPropertyAfter(target: Schema, data: ISchema) {
}); });
} }
function setKeys(schema: ISchema, parentKey = null) { function setKeys(schema: ISchema | FormilyISchema, parentKey = null) {
if (!schema['key']) { if (!schema['key']) {
schema['key'] = uid(); schema['key'] = uid();
} }
@ -235,7 +235,7 @@ export function useDesignable(path?: any) {
DesignableBar, DesignableBar,
schema: currentSchema, schema: currentSchema,
refresh, refresh,
prepend: (property: ISchema, targetPath?: any): Schema => { prepend: (property: ISchema | FormilyISchema, targetPath?: any): Schema => {
let target = currentSchema; let target = currentSchema;
if (targetPath) { if (targetPath) {
target = findPropertyByPath(schema, targetPath); target = findPropertyByPath(schema, targetPath);
@ -267,7 +267,7 @@ export function useDesignable(path?: any) {
refresh(); refresh();
return target.properties[property.name]; return target.properties[property.name];
}, },
appendChild: (property: ISchema, targetPath?: any): Schema => { appendChild: (property: ISchema | FormilyISchema, targetPath?: any): Schema => {
let target = currentSchema; let target = currentSchema;
if (targetPath) { if (targetPath) {
target = findPropertyByPath(schema, targetPath); target = findPropertyByPath(schema, targetPath);
@ -294,7 +294,7 @@ export function useDesignable(path?: any) {
refresh(); refresh();
return target.properties[property.name]; return target.properties[property.name];
}, },
insertAfter: (property: ISchema, targetPath?: any): Schema => { insertAfter: (property: ISchema | FormilyISchema, targetPath?: any): Schema => {
let target = currentSchema; let target = currentSchema;
if (targetPath) { if (targetPath) {
target = findPropertyByPath(schema, targetPath); target = findPropertyByPath(schema, targetPath);
@ -316,7 +316,7 @@ export function useDesignable(path?: any) {
refresh(); refresh();
return target.parent.properties[property.name]; return target.parent.properties[property.name];
}, },
insertBefore(property: ISchema, targetPath?: any): Schema { insertBefore(property: ISchema | FormilyISchema, targetPath?: any): Schema {
let target = currentSchema; let target = currentSchema;
if (targetPath) { if (targetPath) {
target = findPropertyByPath(schema, targetPath); target = findPropertyByPath(schema, targetPath);
@ -380,7 +380,7 @@ export function useDesignable(path?: any) {
}, },
moveToBefore(path1, path2) { moveToBefore(path1, path2) {
const source = findPropertyByPath(schema, path1); const source = findPropertyByPath(schema, path1);
const property = source.toJSON(); const property = source.toJSON() as ISchema;
const target = findPropertyByPath(schema, path2); const target = findPropertyByPath(schema, path2);
if (!target) { if (!target) {
console.error('target schema does not exist.'); console.error('target schema does not exist.');
@ -400,7 +400,7 @@ export function useDesignable(path?: any) {
}, },
moveToAfter(path1, path2) { moveToAfter(path1, path2) {
const source = findPropertyByPath(schema, path1); const source = findPropertyByPath(schema, path1);
const property = source.toJSON(); const property = source.toJSON() as ISchema;
const target = findPropertyByPath(schema, path2); const target = findPropertyByPath(schema, path2);
if (!target) { if (!target) {
console.error('target schema does not exist.'); console.error('target schema does not exist.');
@ -495,7 +495,7 @@ const CodePreview = ({ schema }) => {
}; };
export interface SchemaRendererProps { export interface SchemaRendererProps {
schema: Schema | ISchema; schema: Schema | ISchema | FormilyISchema;
form?: any; form?: any;
render?: any; render?: any;
components?: any; components?: any;

View File

@ -1,7 +1,7 @@
import { DndContext, DragOverlay } from '@dnd-kit/core'; import { DndContext, DragOverlay } from '@dnd-kit/core';
import { ISchema, observer, RecursionField, Schema } from '@formily/react'; import { observer, RecursionField, Schema } from '@formily/react';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { createSchema, removeSchema, updateSchema } from '..'; import { createSchema, ISchema, removeSchema, updateSchema } from '..';
import { import {
findPropertyByPath, findPropertyByPath,
getSchemaPath, getSchemaPath,

View File

@ -15,7 +15,6 @@ import {
useFieldSchema, useFieldSchema,
RecursionField, RecursionField,
Schema, Schema,
ISchema,
useForm, useForm,
} from '@formily/react'; } from '@formily/react';
import { import {
@ -51,6 +50,7 @@ import {
createCollectionField, createCollectionField,
createOrUpdateCollection, createOrUpdateCollection,
createSchema, createSchema,
ISchema,
removeSchema, removeSchema,
useDesignable, useDesignable,
useSchemaPath, useSchemaPath,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react'; import { FieldOptions } from '.';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
export const attachment: ISchema = { export const attachment: FieldOptions = {
name: 'attachment', name: 'attachment',
type: 'object', type: 'object',
group: 'media', group: 'media',
@ -16,7 +16,7 @@ export const attachment: ISchema = {
'x-component': 'Upload.Attachment', 'x-component': 'Upload.Attachment',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Upload.DesignableBar', 'x-designable-bar': 'Upload.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,7 @@
import { ISchema } from '@formily/react';
import { omit } from 'lodash';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const checkbox: ISchema = { export const checkbox: FieldOptions = {
name: 'checkbox', name: 'checkbox',
type: 'object', type: 'object',
group: 'choices', group: 'choices',
@ -17,7 +16,7 @@ export const checkbox: ISchema = {
'x-component': 'Checkbox', 'x-component': 'Checkbox',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Checkbox.DesignableBar', 'x-designable-bar': 'Checkbox.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { multipleSelect } from './multipleSelect'; import { multipleSelect } from './multipleSelect';
import { defaultProps, dataSource } from './properties'; import { defaultProps, dataSource } from './properties';
import { FieldOptions } from '.';
export const checkboxGroup: ISchema = { export const checkboxGroup: FieldOptions = {
name: 'checkboxGroup', name: 'checkboxGroup',
type: 'object', type: 'object',
group: 'choices', group: 'choices',
@ -18,7 +18,7 @@ export const checkboxGroup: ISchema = {
'x-component': 'Checkbox.Group', 'x-component': 'Checkbox.Group',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Checkbox.Group.DesignableBar', 'x-designable-bar': 'Checkbox.Group.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const chinaRegion: ISchema = { export const chinaRegion: FieldOptions = {
name: 'chinaRegion', name: 'chinaRegion',
type: 'object', type: 'object',
group: 'choices', group: 'choices',
@ -19,7 +19,7 @@ export const chinaRegion: ISchema = {
'x-component-props': {}, 'x-component-props': {},
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Cascader.DesignableBar', 'x-designable-bar': 'Cascader.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { datetime } from './datetime'; import { datetime } from './datetime';
import { dateTimeProps, defaultProps } from './properties'; import { dateTimeProps, defaultProps } from './properties';
import { FieldOptions } from '.';
export const createdAt: ISchema = { export const createdAt: FieldOptions = {
name: 'createdAt', name: 'createdAt',
type: 'object', type: 'object',
group: 'systemInfo', group: 'systemInfo',
@ -21,7 +21,7 @@ export const createdAt: ISchema = {
'x-read-pretty': true, 'x-read-pretty': true,
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'DatePicker.DesignableBar', 'x-designable-bar': 'DatePicker.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,8 @@
import { ISchema } from '@formily/react'; import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const createdBy: ISchema = { export const createdBy: FieldOptions = {
name: 'createdBy', name: 'createdBy',
type: 'object', type: 'object',
group: 'systemInfo', group: 'systemInfo',
@ -20,7 +21,7 @@ export const createdBy: ISchema = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-read-pretty': true, 'x-read-pretty': true,
'x-designable-bar': 'Select.Drawer.DesignableBar', 'x-designable-bar': 'Select.Drawer.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,8 @@
import { ISchema } from '@formily/react'; import { ISchema } from '@formily/react';
import { dateTimeProps, defaultProps } from './properties'; import { dateTimeProps, defaultProps } from './properties';
import { FieldOptions } from '.';
export const datetime: ISchema = { export const datetime: FieldOptions = {
name: 'datetime', name: 'datetime',
type: 'object', type: 'object',
group: 'datetime', group: 'datetime',
@ -20,7 +21,7 @@ export const datetime: ISchema = {
}, },
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'DatePicker.DesignableBar', 'x-designable-bar': 'DatePicker.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { string } from './string'; import { string } from './string';
import { FieldOptions } from '.';
export const email: ISchema = { export const email: FieldOptions = {
name: 'email', name: 'email',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -19,7 +19,7 @@ export const email: ISchema = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-validator': 'email', 'x-validator': 'email',
'x-designable-bar': 'Input.DesignableBar', 'x-designable-bar': 'Input.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const icon: ISchema = { export const icon: FieldOptions = {
name: 'icon', name: 'icon',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -16,7 +16,7 @@ export const icon: ISchema = {
'x-component': 'IconPicker', 'x-component': 'IconPicker',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'IconPicker.DesignableBar', 'x-designable-bar': 'IconPicker.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,18 @@
import { ISchema } from '@formily/react';
import { cloneDeep, set } from 'lodash'; import { cloneDeep, set } from 'lodash';
import * as types from './types'; import * as types from './types';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { ISchema } from '../..';
interface IDefaultSchema {
dataType: string;
uiSchema?: ISchema;
[key: string]: any;
}
export interface FieldOptions extends ISchema {
[key: string]: any;
default?: IDefaultSchema;
}
export const interfaces = new Map<string, ISchema>(); export const interfaces = new Map<string, ISchema>();

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { FieldOptions } from '.';
export const linkTo: ISchema = { export const linkTo: FieldOptions = {
name: 'linkTo', name: 'linkTo',
type: 'object', type: 'object',
group: 'relation', group: 'relation',
@ -18,7 +18,7 @@ export const linkTo: ISchema = {
'x-component-props': {}, 'x-component-props': {},
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Select.Drawer.DesignableBar', 'x-designable-bar': 'Select.Drawer.DesignableBar',
} as ISchema, },
}, },
initialize: (values: any) => { initialize: (values: any) => {
if (values.dataType === 'belongsToMany') { if (values.dataType === 'belongsToMany') {

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const markdown: ISchema = { export const markdown: FieldOptions = {
name: 'markdown', name: 'markdown',
type: 'object', type: 'object',
title: 'Markdown', title: 'Markdown',
@ -15,7 +15,7 @@ export const markdown: ISchema = {
'x-component': 'Markdown', 'x-component': 'Markdown',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Markdown.DesignableBar', 'x-designable-bar': 'Markdown.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps, dataSource } from './properties'; import { defaultProps, dataSource } from './properties';
import { FieldOptions } from '.';
export const multipleSelect: ISchema = { export const multipleSelect: FieldOptions = {
name: 'multipleSelect', name: 'multipleSelect',
type: 'object', type: 'object',
group: 'choices', group: 'choices',
@ -20,7 +20,7 @@ export const multipleSelect: ISchema = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Select.DesignableBar', 'x-designable-bar': 'Select.DesignableBar',
enum: [], enum: [],
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const number: ISchema = { export const number: FieldOptions = {
name: 'number', name: 'number',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -21,7 +21,7 @@ export const number: ISchema = {
}, },
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'InputNumber.DesignableBar', 'x-designable-bar': 'InputNumber.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const password: ISchema = { export const password: FieldOptions = {
name: 'password', name: 'password',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -16,7 +16,7 @@ export const password: ISchema = {
'x-component': 'Password', 'x-component': 'Password',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Password.DesignableBar', 'x-designable-bar': 'Password.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { number } from './number'; import { number } from './number';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const percent: ISchema = { export const percent: FieldOptions = {
name: 'percent', name: 'percent',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -23,7 +23,7 @@ export const percent: ISchema = {
}, },
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'InputNumber.DesignableBar', 'x-designable-bar': 'InputNumber.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { string } from './string'; import { string } from './string';
import { FieldOptions } from '.';
export const phone: ISchema = { export const phone: FieldOptions = {
name: 'phone', name: 'phone',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -19,7 +19,7 @@ export const phone: ISchema = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
"x-validator": 'phone', "x-validator": 'phone',
'x-designable-bar': 'Input.DesignableBar', 'x-designable-bar': 'Input.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { defaultProps, dataSource } from './properties'; import { defaultProps, dataSource } from './properties';
import { select } from './select'; import { select } from './select';
import { FieldOptions } from '.';
export const radioGroup: ISchema = { export const radioGroup: FieldOptions = {
name: 'radioGroup', name: 'radioGroup',
type: 'object', type: 'object',
group: 'choices', group: 'choices',
@ -17,7 +17,7 @@ export const radioGroup: ISchema = {
'x-component': 'Radio.Group', 'x-component': 'Radio.Group',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Radio.DesignableBar', 'x-designable-bar': 'Radio.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps, dataSource } from './properties'; import { defaultProps, dataSource } from './properties';
import { FieldOptions } from '.';
export const select: ISchema = { export const select: FieldOptions = {
name: 'select', name: 'select',
type: 'object', type: 'object',
group: 'choices', group: 'choices',
@ -17,7 +17,7 @@ export const select: ISchema = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Select.DesignableBar', 'x-designable-bar': 'Select.DesignableBar',
enum: [], enum: [],
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const string: ISchema = { export const string: FieldOptions = {
name: 'string', name: 'string',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -18,7 +18,7 @@ export const string: ISchema = {
'x-component': 'Input', 'x-component': 'Input',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'Input.DesignableBar', 'x-designable-bar': 'Input.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { FieldOptions } from '.';
export const subTable: ISchema = { export const subTable: FieldOptions = {
name: 'subTable', name: 'subTable',
type: 'object', type: 'object',
group: 'relation', group: 'relation',
@ -19,7 +19,7 @@ export const subTable: ISchema = {
'x-component-props': {}, 'x-component-props': {},
'x-designable-bar': 'Table.DesignableBar', 'x-designable-bar': 'Table.DesignableBar',
enum: [], enum: [],
} as ISchema, },
}, },
initialize: (values: any) => { initialize: (values: any) => {
if (!values.target) { if (!values.target) {

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const textarea: ISchema = { export const textarea: FieldOptions = {
name: 'textarea', name: 'textarea',
type: 'object', type: 'object',
group: 'basic', group: 'basic',
@ -16,7 +16,7 @@ export const textarea: ISchema = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input.TextArea', 'x-component': 'Input.TextArea',
'x-designable-bar': 'Input.DesignableBar', 'x-designable-bar': 'Input.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const time: ISchema = { export const time: FieldOptions = {
name: 'time', name: 'time',
type: 'object', type: 'object',
group: 'datetime', group: 'datetime',
@ -17,7 +17,7 @@ export const time: ISchema = {
'x-component': 'TimePicker', 'x-component': 'TimePicker',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'TimePicker.DesignableBar', 'x-designable-bar': 'TimePicker.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,8 +1,8 @@
import { ISchema } from '@formily/react';
import { datetime } from './datetime'; import { datetime } from './datetime';
import { dateTimeProps, defaultProps } from './properties'; import { dateTimeProps, defaultProps } from './properties';
import { FieldOptions } from '.';
export const updatedAt: ISchema = { export const updatedAt: FieldOptions = {
name: 'updatedAt', name: 'updatedAt',
type: 'object', type: 'object',
group: 'systemInfo', group: 'systemInfo',
@ -21,7 +21,7 @@ export const updatedAt: ISchema = {
'x-read-pretty': true, 'x-read-pretty': true,
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-designable-bar': 'DatePicker.DesignableBar', 'x-designable-bar': 'DatePicker.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { defaultProps } from './properties'; import { defaultProps } from './properties';
import { FieldOptions } from '.';
export const updatedBy: ISchema = { export const updatedBy: FieldOptions = {
name: 'updatedBy', name: 'updatedBy',
type: 'object', type: 'object',
group: 'systemInfo', group: 'systemInfo',
@ -20,7 +20,7 @@ export const updatedBy: ISchema = {
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-read-pretty': true, 'x-read-pretty': true,
'x-designable-bar': 'Select.Drawer.DesignableBar', 'x-designable-bar': 'Select.Drawer.DesignableBar',
} as ISchema, },
}, },
properties: { properties: {
...defaultProps, ...defaultProps,

View File

@ -1,5 +1,5 @@
import React, { useContext, useMemo, useState } from 'react'; import React, { useContext, useMemo, useState } from 'react';
import { SchemaField } from '..'; import { ISchema, SchemaField } from '..';
import { import {
createForm, createForm,
onFieldChange, onFieldChange,
@ -12,7 +12,6 @@ import {
useFieldSchema, useFieldSchema,
Schema, Schema,
SchemaOptionsContext, SchemaOptionsContext,
ISchema,
SchemaKey, SchemaKey,
RecursionField, RecursionField,
} from '@formily/react'; } from '@formily/react';
@ -172,6 +171,8 @@ export const FilterItem = (props) => {
[], [],
); );
const columnEnum: any = [...columns.values()].map((column) => column.toJSON());
return ( return (
<FormProvider form={form}> <FormProvider form={form}>
<FormLayout layout={'inline'}> <FormLayout layout={'inline'}>
@ -195,7 +196,7 @@ export const FilterItem = (props) => {
value: 'name', value: 'name',
}, },
}} }}
enum={[...columns.values()].map((column) => column.toJSON())} enum={columnEnum}
/> />
<SchemaField.String <SchemaField.String
name="operation" name="operation"

View File

@ -7,12 +7,11 @@ import {
observer, observer,
SchemaExpressionScopeContext, SchemaExpressionScopeContext,
FormProvider, FormProvider,
ISchema,
useField, useField,
useForm, useForm,
RecursionField, RecursionField,
} from '@formily/react'; } from '@formily/react';
import { useSchemaPath, SchemaField, useDesignable, removeSchema } from '../'; import { useSchemaPath, SchemaField, useDesignable, removeSchema, ISchema } from '../';
import get from 'lodash/get'; import get from 'lodash/get';
import { Button, Dropdown, Menu, message, Space } from 'antd'; import { Button, Dropdown, Menu, message, Space } from 'antd';
import { MenuOutlined, DragOutlined } from '@ant-design/icons'; import { MenuOutlined, DragOutlined } from '@ant-design/icons';
@ -78,23 +77,24 @@ const FormMain = (props: any) => {
console.log(displayed.map, 'displayed.map', collection?.name); console.log(displayed.map, 'displayed.map', collection?.name);
} }
}, [displayed.map]); }, [displayed.map]);
const s: ISchema = {
type: 'object',
properties: {
[schema.name]: {
...schema.toJSON(),
'x-path': path,
// 避免死循环
'x-decorator': 'Form.__Decorator',
},
},
}
const content = ( const content = (
<FormProvider form={form}> <FormProvider form={form}>
{schema['x-decorator'] === 'Form' ? ( {schema['x-decorator'] === 'Form' ? (
<SchemaField <SchemaField
components={options.components} components={options.components}
scope={scope} scope={scope}
schema={{ schema={s}
type: 'object',
properties: {
[schema.name]: {
...schema.toJSON(),
'x-path': path,
// 避免死循环
'x-decorator': 'Form.__Decorator',
},
},
}}
/> />
) : ( ) : (
<FormLayout layout={'vertical'} {...others}> <FormLayout layout={'vertical'} {...others}>
@ -196,7 +196,7 @@ Form.Field = observer((props: any) => {
'x-decorator': 'FormilyFormItem', 'x-decorator': 'FormilyFormItem',
}, },
}, },
}) } as ISchema)
} }
/> />
); );

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { ISchema, observer, Schema, useField } from '@formily/react'; import { ISchema as FormilyISchema, observer, Schema, useField } from '@formily/react';
import constate from 'constate'; import constate from 'constate';
import { useState } from 'react'; import { useState } from 'react';
import { createContext } from 'react'; import { createContext } from 'react';
@ -8,6 +8,15 @@ import { extend } from 'umi-request';
import { isVoidField } from '@formily/core'; import { isVoidField } from '@formily/core';
import { useCookieState, useRequest } from 'ahooks'; import { useCookieState, useRequest } from 'ahooks';
export { FormilyISchema };
export interface ISchema extends FormilyISchema {
[key: string]: any;
properties?: {
[key: string]: ISchema | FormilyISchema;
};
}
export * from '../components/schema-renderer'; export * from '../components/schema-renderer';
export function useDefaultAction() { export function useDefaultAction() {

View File

@ -1,5 +1,5 @@
import { ISchema } from '@formily/react';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import { ISchema } from '..';
export function generateDefaultSchema(component) { export function generateDefaultSchema(component) {
const defaultSchemas: { [key: string]: ISchema } = { const defaultSchemas: { [key: string]: ISchema } = {

View File

@ -1,6 +1,5 @@
import { import {
FormProvider, FormProvider,
ISchema,
observer, observer,
RecursionField, RecursionField,
Schema, Schema,
@ -18,6 +17,7 @@ import {
removeSchema, removeSchema,
createSchema, createSchema,
createCollectionField, createCollectionField,
ISchema,
} from '..'; } from '..';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import useRequest from '@ahooksjs/use-request'; import useRequest from '@ahooksjs/use-request';

2153
yarn.lock

File diff suppressed because it is too large Load Diff