diff --git a/packages/client/src/blocks/DesignableSchemaField/index.tsx b/packages/client/src/blocks/DesignableSchemaField/index.tsx index 82951d76b..2ba04a815 100644 --- a/packages/client/src/blocks/DesignableSchemaField/index.tsx +++ b/packages/client/src/blocks/DesignableSchemaField/index.tsx @@ -20,7 +20,7 @@ import { observable } from '@formily/reactive'; import { uid, clone } from '@formily/shared'; import { ArrayCollapse, ArrayTable, FormLayout } from '@formily/antd'; -import { Space, Card } from 'antd'; +import { Space, Card, Modal } from 'antd'; import { Action, useLogin, useRegister, useSubmit } from '../action'; import { AddNew } from '../add-new'; import { Cascader } from '../cascader'; @@ -46,6 +46,9 @@ import { TimePicker } from '../time-picker'; import { Upload } from '../upload'; import { FormItem } from '../form-item'; +import { CodeOutlined } from '@ant-design/icons'; +import Editor from '@monaco-editor/react'; + export const BlockContext = createContext({ dragRef: null }); const Div = (props) =>
; @@ -170,6 +173,30 @@ export function useDesignable(path?: any) { return { schema: currentSchema, refresh, + prepend: (property: ISchema, targetPath?: any): Schema => { + let target = currentSchema; + if (targetPath) { + target = findPropertyByPath(schema, targetPath); + } + if (!target) { + console.error('target schema does not exist.'); + return; + } + if (!property.name) { + property.name = uid(); + } + const properties = {}; + properties[property.name] = property; + Object.keys(target.properties).forEach((name, index) => { + const current = target.properties[name]; + current.parent.removeProperty(current.name); + properties[current.name] = current.toJSON(); + }); + console.log({ properties }, target.properties) + target.setProperties(properties); + refresh(); + return target.properties[property.name]; + }, appendChild: (property: ISchema, targetPath?: any): Schema => { let target = currentSchema; if (targetPath) { @@ -222,6 +249,27 @@ export function useDesignable(path?: any) { refresh(); return target.parent.properties[property.name]; }, + deepRemove(targetPath?: any) { + let target = currentSchema; + if (targetPath) { + target = findPropertyByPath(schema, targetPath); + } + if (!target) { + console.error('target schema does not exist.'); + return; + } + const remove = (s: Schema) => { + if (!s.parent) { + return; + } + s.parent.removeProperty(s.name); + if (Object.keys(s.parent.properties || {}).length === 0) { + remove(s.parent); + } + }; + remove(target); + refresh(); + }, remove(targetPath?: any) { let target = currentSchema; if (targetPath) { @@ -274,6 +322,7 @@ export const createDesignableSchemaField = (options) => { }} >{JSON.stringify(schema.toJSON(), null, 2)}*/} +