File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
primitives/filed-form /src Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -10,4 +10,6 @@ export { default as List } from './List';
1010
1111export type { InternalFieldProps } from './types/field' ;
1212
13+ export type { FormInstance } from './FieldContext' ;
14+
1315export { default as useForm } from './useForm' ;
Original file line number Diff line number Diff line change @@ -118,3 +118,31 @@ export const isUnderPrefix = (key: string, prefix: string) => {
118118 if ( key === prefix ) return true ; // 自身节点
119119 return key . startsWith ( `${ prefix } .` ) ; // 子节点(点分隔)
120120} ;
121+
122+ export function collectDeepKeys ( obj : any , prefix : string = '' ) : string [ ] {
123+ if ( obj === null || obj === undefined ) {
124+ // 叶子节点(值是 null/undefined)
125+ return [ prefix ] ;
126+ }
127+
128+ if ( typeof obj !== 'object' || obj instanceof Date ) {
129+ // 基础值(string/number/boolean/function/Date...)
130+ return [ prefix ] ;
131+ }
132+
133+ // 对象/数组:即使值是 undefined/null,也要保留路径
134+ const keys : string [ ] = [ ] ;
135+
136+ // 如果是空对象/数组,也要把自己 push 出来
137+ if ( Object . keys ( obj ) . length === 0 ) {
138+ keys . push ( prefix ) ;
139+ return keys ;
140+ }
141+
142+ for ( const k of Object . keys ( obj ) ) {
143+ const path = prefix ? `${ prefix } .${ k } ` : k ;
144+ keys . push ( ...collectDeepKeys ( obj [ k ] , path ) ) ;
145+ }
146+
147+ return keys ;
148+ }
You can’t perform that action at this time.
0 commit comments