Skip to content

Commit

Permalink
feat(formily-transformer): remove designable core code dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Oct 25, 2021
1 parent e026af4 commit be8b182
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions formily/transformer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ISchema, Schema } from '@formily/json-schema'
import { ITreeNode, TreeNode } from '@designable/core'
import { ITreeNode } from '@designable/core'
import { clone, uid } from '@designable/shared'

export interface ITransformerOptions {
Expand All @@ -20,20 +20,30 @@ const createOptions = (options: ITransformerOptions): ITransformerOptions => {
}
}

const findNode = (node: ITreeNode, finder?: (node: ITreeNode) => boolean) => {
if (!node) return
if (finder(node)) return node
if (!node.children) return
for (let i = 0; i < node.children.length; i++) {
if (findNode(node.children[i])) return node.children[i]
}
return
}

export const transformToSchema = (
node: TreeNode,
node: ITreeNode,
options?: ITransformerOptions
): IFormilySchema => {
const realOptions = createOptions(options)
const root = node.find((child) => {
const root = findNode(node, (child) => {
return child.componentName === realOptions.designableFormName
})
const schema = {
type: 'object',
properties: {},
}
if (!root) return { schema }
const createSchema = (node: TreeNode, schema: ISchema = {}) => {
const createSchema = (node: ITreeNode, schema: ISchema = {}) => {
if (node !== root) {
Object.assign(schema, clone(node.props))
}
Expand Down

0 comments on commit be8b182

Please sign in to comment.