1
1
import { some } from '@sjsf/form/lib/array' ;
2
2
import { escapeRegex } from '@sjsf/form/lib/reg-exp' ;
3
- import { type Trie , getValueByKeys , insertValue } from '@sjsf/form/lib/trie' ;
4
3
import { isSchemaObject } from '@sjsf/form/lib/json-schema' ;
5
4
import {
6
5
getClosestMatchingOption ,
@@ -30,8 +29,6 @@ import {
30
29
type UiSchemaRoot
31
30
} from '@sjsf/form' ;
32
31
33
- import { IDENTIFIABLE_INPUT_ELEMENTS } from '../model.js' ;
34
-
35
32
import type { Entries , EntriesConverter , Entry } from './entry.js' ;
36
33
37
34
export interface SchemaValueParserOptions < T > {
@@ -44,41 +41,13 @@ export interface SchemaValueParserOptions<T> {
44
41
validator : Validator ;
45
42
merger : Merger ;
46
43
convertEntries : EntriesConverter < T > ;
47
- identifiableInputElementsTrie ?: Trie < string , true > ;
48
44
}
49
45
50
46
const KNOWN_PROPERTIES = Symbol ( 'known-properties' ) ;
51
47
52
48
const KEY_INPUT_KEY : keyof IdentifiableFieldElement = 'key-input' ;
53
-
54
- let DEFAULT_IDENTIFIABLE_INPUT_ELEMENTS_TRIE : Trie < string , true > ;
55
-
56
- for ( const key of IDENTIFIABLE_INPUT_ELEMENTS ) {
57
- DEFAULT_IDENTIFIABLE_INPUT_ELEMENTS_TRIE = insertValue (
58
- DEFAULT_IDENTIFIABLE_INPUT_ELEMENTS_TRIE ,
59
- key ,
60
- true
61
- ) ;
62
- }
63
-
64
- function removePseudoElements < T > (
65
- entries : Entries < T > ,
66
- idPseudoSeparator : string ,
67
- blacklist : Trie < string , boolean >
68
- ) {
69
- return entries . filter ( ( [ key ] ) => {
70
- const index = key . lastIndexOf ( idPseudoSeparator ) ;
71
- if ( index === - 1 ) {
72
- return true ;
73
- }
74
- const subKey = key . substring ( index + idPseudoSeparator . length ) ;
75
- // Numbers are used for enum option ids, not inputs
76
- // if (Number.isInteger(Number(subKey))) {
77
- // return false;
78
- // }
79
- return getValueByKeys ( blacklist , subKey ) !== true ;
80
- } ) ;
81
- }
49
+ const ONE_OF : keyof IdentifiableFieldElement = 'oneof' ;
50
+ const ANY_OF : keyof IdentifiableFieldElement = 'anyof' ;
82
51
83
52
export function parseSchemaValue < T > (
84
53
signal : AbortSignal ,
@@ -91,8 +60,7 @@ export function parseSchemaValue<T>(
91
60
schema : rootSchema ,
92
61
uiSchema : rootUiSchema ,
93
62
validator,
94
- merger,
95
- identifiableInputElementsTrie = DEFAULT_IDENTIFIABLE_INPUT_ELEMENTS_TRIE
63
+ merger
96
64
} : SchemaValueParserOptions < T >
97
65
) {
98
66
if ( entries . length === 0 ) {
@@ -104,9 +72,7 @@ export function parseSchemaValue<T>(
104
72
const SEPARATED_KEY_INPUT_KEY = `${ idPseudoSeparator } ${ KEY_INPUT_KEY } ` ;
105
73
let filter = '' ;
106
74
const filterLengthStack : number [ ] = [ ] ;
107
- const entriesStack : Entries < T > [ ] = [
108
- removePseudoElements ( entries , idPseudoSeparator , identifiableInputElementsTrie )
109
- ] ;
75
+ const entriesStack : Entries < T > [ ] = [ entries ] ;
110
76
111
77
const groups = new Map < string | typeof KNOWN_PROPERTIES , Entries < T > > ( ) ;
112
78
function addGroupEntry ( key : string | typeof KNOWN_PROPERTIES , entry : Entry < T > ) {
@@ -299,7 +265,7 @@ export function parseSchemaValue<T>(
299
265
schema : Schema ,
300
266
oneOfUiSchema : UiSchemaDefinition | UiSchemaDefinition [ ] ,
301
267
value : SchemaValue | undefined ,
302
- element : FieldPseudoElement = 'oneof'
268
+ element : FieldPseudoElement = ONE_OF
303
269
) {
304
270
if ( isSelect ( validator , merger , schema , rootSchema ) ) {
305
271
return value ;
@@ -339,7 +305,7 @@ export function parseSchemaValue<T>(
339
305
uiSchema : UiSchema ,
340
306
value : SchemaValue | undefined
341
307
) {
342
- return handleOneOf ( anyOf , schema , uiSchema . anyOf ?? uiSchema , value , 'anyof' ) ;
308
+ return handleOneOf ( anyOf , schema , uiSchema . anyOf ?? uiSchema , value , ANY_OF ) ;
343
309
}
344
310
345
311
function handleConditions ( schema : Schema , uiSchema : UiSchema , value : SchemaValue | undefined ) {
0 commit comments