-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
G
committed
Dec 13, 2023
1 parent
b565ae7
commit b47b6c2
Showing
15 changed files
with
90 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,59 @@ | ||
import { ReactElement, ReactNode } from 'react'; | ||
import { Field } from '../GForm/g-form'; | ||
import { isObj } from '../utils'; | ||
import { Field } from '../GForm/g-form' | ||
import { ReactElement, ReactNode } from 'react' | ||
import { isObj } from '../utils' | ||
|
||
const getAyFieldsNode = (children: ReactNode) => { | ||
if (!Array.isArray(children)) { | ||
children = [children]; | ||
children = [children] | ||
} | ||
console.log(children) | ||
|
||
// @ts-ignore | ||
return children.find( | ||
(node: ReactElement) => node?.type?.componentName === 'GFields', | ||
); | ||
}; | ||
return children.find((node: ReactElement) => node?.type?.componentName === 'MwFields') | ||
} | ||
|
||
export const convertChildrenToField = (children: ReactNode) => { | ||
// 获得子元素名为 GFields 的节点 | ||
let ayFields = getAyFieldsNode(children); | ||
// 获得子元素名为 MwFields 的节点 | ||
let ayFields = getAyFieldsNode(children) | ||
|
||
if (!ayFields) { | ||
return []; | ||
return [] | ||
} | ||
|
||
// 获得到子元素 | ||
let ayFieldsChildren = ayFields?.props.children; | ||
return loop(ayFieldsChildren); | ||
}; | ||
let ayFieldsChildren = ayFields?.props.children | ||
return loop(ayFieldsChildren) | ||
} | ||
|
||
function loop(children: ReactNode) { | ||
if (!Array.isArray(children)) { | ||
children = [children]; | ||
children = [children] | ||
} | ||
|
||
let newChildren: Field[] = []; | ||
let newChildren: Field[] = [] | ||
|
||
// @ts-ignore | ||
children.forEach((node) => { | ||
children.forEach(node => { | ||
if (node) { | ||
if ( | ||
node?.type?.toString() === 'Symbol(react.fragment)' && | ||
node?.props?.children | ||
) { | ||
newChildren.push(...loop(node.props.children)); | ||
return; | ||
if (node?.type?.toString() === 'Symbol(react.fragment)' && node?.props?.children) { | ||
newChildren.push(...loop(node.props.children)) | ||
return | ||
} | ||
let newNode = { | ||
...node?.props, | ||
key: node.key, | ||
}; | ||
key: node.key | ||
} | ||
|
||
if (Array.isArray(newNode?.children) || isObj(newNode?.children)) { | ||
if (isObj(newNode?.children)) { | ||
newNode.children = loop([newNode.children]); | ||
newNode.children = loop([newNode.children]) | ||
} else { | ||
newNode.children = loop([...newNode.children]); | ||
newNode.children = loop([...newNode.children]) | ||
} | ||
} | ||
|
||
newChildren.push(newNode); | ||
newChildren.push(newNode) | ||
} | ||
}); | ||
return newChildren; | ||
}) | ||
return newChildren | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
export default function GFields() { | ||
return null; | ||
import React from 'react'; | ||
|
||
export interface GFieldsCompProps { | ||
// Define your component props here | ||
children: React.ReactNode; | ||
} | ||
|
||
GFields.componentName = 'GFields'; | ||
const GFields: React.FC<GFieldsCompProps> = (props) => { | ||
// Your component logic here | ||
return null; | ||
}; | ||
|
||
// Adding a static property to the function component | ||
(GFields as any).componentName = 'GFields'; | ||
|
||
export default GFields; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.