Skip to content

Commit 049e038

Browse files
committed
[sveltekit] Remove identifiableInputElementsTrie schema value parser option
1 parent a831f47 commit 049e038

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

.changeset/flat-showers-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sjsf/sveltekit": major
3+
---
4+
5+
Remove `identifiableInputElementsTrie` schema value parser option

packages/sveltekit/src/lib/server/schema-value-parser.ts

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { some } from '@sjsf/form/lib/array';
22
import { escapeRegex } from '@sjsf/form/lib/reg-exp';
3-
import { type Trie, getValueByKeys, insertValue } from '@sjsf/form/lib/trie';
43
import { isSchemaObject } from '@sjsf/form/lib/json-schema';
54
import {
65
getClosestMatchingOption,
@@ -30,8 +29,6 @@ import {
3029
type UiSchemaRoot
3130
} from '@sjsf/form';
3231

33-
import { IDENTIFIABLE_INPUT_ELEMENTS } from '../model.js';
34-
3532
import type { Entries, EntriesConverter, Entry } from './entry.js';
3633

3734
export interface SchemaValueParserOptions<T> {
@@ -44,41 +41,13 @@ export interface SchemaValueParserOptions<T> {
4441
validator: Validator;
4542
merger: Merger;
4643
convertEntries: EntriesConverter<T>;
47-
identifiableInputElementsTrie?: Trie<string, true>;
4844
}
4945

5046
const KNOWN_PROPERTIES = Symbol('known-properties');
5147

5248
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';
8251

8352
export function parseSchemaValue<T>(
8453
signal: AbortSignal,
@@ -91,8 +60,7 @@ export function parseSchemaValue<T>(
9160
schema: rootSchema,
9261
uiSchema: rootUiSchema,
9362
validator,
94-
merger,
95-
identifiableInputElementsTrie = DEFAULT_IDENTIFIABLE_INPUT_ELEMENTS_TRIE
63+
merger
9664
}: SchemaValueParserOptions<T>
9765
) {
9866
if (entries.length === 0) {
@@ -104,9 +72,7 @@ export function parseSchemaValue<T>(
10472
const SEPARATED_KEY_INPUT_KEY = `${idPseudoSeparator}${KEY_INPUT_KEY}`;
10573
let filter = '';
10674
const filterLengthStack: number[] = [];
107-
const entriesStack: Entries<T>[] = [
108-
removePseudoElements(entries, idPseudoSeparator, identifiableInputElementsTrie)
109-
];
75+
const entriesStack: Entries<T>[] = [entries];
11076

11177
const groups = new Map<string | typeof KNOWN_PROPERTIES, Entries<T>>();
11278
function addGroupEntry(key: string | typeof KNOWN_PROPERTIES, entry: Entry<T>) {
@@ -299,7 +265,7 @@ export function parseSchemaValue<T>(
299265
schema: Schema,
300266
oneOfUiSchema: UiSchemaDefinition | UiSchemaDefinition[],
301267
value: SchemaValue | undefined,
302-
element: FieldPseudoElement = 'oneof'
268+
element: FieldPseudoElement = ONE_OF
303269
) {
304270
if (isSelect(validator, merger, schema, rootSchema)) {
305271
return value;
@@ -339,7 +305,7 @@ export function parseSchemaValue<T>(
339305
uiSchema: UiSchema,
340306
value: SchemaValue | undefined
341307
) {
342-
return handleOneOf(anyOf, schema, uiSchema.anyOf ?? uiSchema, value, 'anyof');
308+
return handleOneOf(anyOf, schema, uiSchema.anyOf ?? uiSchema, value, ANY_OF);
343309
}
344310

345311
function handleConditions(schema: Schema, uiSchema: UiSchema, value: SchemaValue | undefined) {

0 commit comments

Comments
 (0)