1
+ import { fieldArrayPrimitive } from './triage/array-primitive' ;
1
2
/* eslint-disable max-lines */
2
3
/* eslint-disable class-methods-use-this */
3
4
/* eslint-disable no-underscore-dangle */
@@ -19,12 +20,12 @@ import set from 'lodash-es/set';
19
20
import type { JSONSchema7 } from '@jsfe/types' ;
20
21
21
22
// import { alternateField } from './triage/alternate.js';
22
- import { arrayField } from './triage/array.js' ;
23
- import { objectField } from './triage/object.js' ;
24
- import { field } from './triage/field .js' ;
23
+ import { fieldArray } from './triage/array.js' ;
24
+ import { fieldObject } from './triage/object.js' ;
25
+ import { fieldPrimitive } from './triage/primitive .js' ;
25
26
26
27
import type {
27
- OnDataChange ,
28
+ DataChangeCallback ,
28
29
FeatureFlags ,
29
30
OnFormSubmit ,
30
31
Path ,
@@ -41,7 +42,7 @@ export class Jsf extends LitElement {
41
42
42
43
public submitCallback : OnFormSubmit = ( ) => { } ;
43
44
44
- public onDataChange : OnDataChange = ( ) => { } ;
45
+ public dataChangeCallback : DataChangeCallback = ( ) => { } ;
45
46
46
47
@property ( { type : Object } ) public widgets : Widgets = { } ;
47
48
@@ -103,7 +104,7 @@ export class Jsf extends LitElement {
103
104
// if (typeof propName !== 'undefined') schemaPathAugmented.push(propName);
104
105
// schemaPathAugmented.push('properties');
105
106
106
- result = field (
107
+ result = fieldPrimitive (
107
108
currentNode ,
108
109
dataLevel ,
109
110
path ,
@@ -141,7 +142,7 @@ export class Jsf extends LitElement {
141
142
schemaPathAugmented . push ( 'properties' ) ;
142
143
// schemaPathAugmented.push(path);
143
144
144
- result = objectField (
145
+ result = fieldObject (
145
146
nodeParsed ,
146
147
dataLevel ,
147
148
path ,
@@ -153,6 +154,33 @@ export class Jsf extends LitElement {
153
154
) ;
154
155
}
155
156
157
+ /* --- Arrays of primitives --- */
158
+ if (
159
+ currentNode . type === 'array' &&
160
+ typeof currentNode . items === 'object' &&
161
+ ! Array . isArray ( currentNode . items ) &&
162
+ currentNode . items . enum &&
163
+ currentNode . uniqueItems &&
164
+ ( currentNode . items . type === 'string' ||
165
+ currentNode . items . type === 'number' ||
166
+ currentNode . items . type === 'integer' ||
167
+ currentNode . items . type === 'boolean' )
168
+ ) {
169
+ const schemaPathAugmented = [ ...schemaPath ] ;
170
+ result = fieldArrayPrimitive (
171
+ currentNode ,
172
+ dataLevel ,
173
+ path ,
174
+ uiState ,
175
+ uiSchema ,
176
+ required ,
177
+ this . _handleChange . bind ( this ) ,
178
+ // this._handleKeydown.bind(this),
179
+ schemaPathAugmented ,
180
+ this . widgets ,
181
+ ) ;
182
+ }
183
+
156
184
/* --- Arrays --- */
157
185
if ( typeof currentNode . items === 'object' ) {
158
186
/* --- Fixed Array --- */
@@ -169,14 +197,15 @@ export class Jsf extends LitElement {
169
197
// if (typeof propName !== 'undefined') schemaPathAugmented.push(propName);
170
198
// schemaPathAugmented.push('items');
171
199
172
- result = objectField (
200
+ result = fieldObject (
173
201
newNode ,
174
202
dataLevel ,
175
203
path ,
176
204
uiState ,
177
205
uiSchema ,
178
206
this . _dig . bind ( this ) ,
179
207
schemaPathAugmented ,
208
+ this . widgets ,
180
209
) ;
181
210
182
211
/* --- Additionals Array items --- */
@@ -227,7 +256,7 @@ export class Jsf extends LitElement {
227
256
// if (typeof propName !== 'undefined') schemaPathAugmented.push(propName);
228
257
// schemaPathAugmented.push('items');
229
258
dataLevel ||= [ ] ;
230
- result = arrayField (
259
+ result = fieldArray (
231
260
node ,
232
261
dataLevel ,
233
262
path ,
@@ -259,17 +288,19 @@ export class Jsf extends LitElement {
259
288
if ( Object . entries ( node ) . length === 0 ) {
260
289
const error = `Empty schema` ;
261
290
return (
262
- this . widgets ?. callout ?.( { id : '' , message : error } ) ?? html `${ error } `
291
+ this . widgets ?. callout ?.( { id : '' , message : error } ) ??
292
+ html `< p > ${ error } </ p > `
263
293
) ;
264
294
}
265
295
266
296
if ( result ) return result ;
267
297
268
- const error = `Cannot dig this level:${ path . join ( '/' ) } ${ String (
298
+ const error = `Cannot dig this level: ${ path . join ( '/' ) } - ( ${ String (
269
299
currentNode . type ,
270
- ) } `;
300
+ ) } ) `;
271
301
return (
272
- this . widgets ?. callout ?.( { id : '' , message : error } ) ?? html `${ error } `
302
+ this . widgets ?. callout ?.( { id : '' , message : error } ) ??
303
+ html `< p > ${ error } </ p > `
273
304
) ;
274
305
} ;
275
306
@@ -301,7 +332,7 @@ export class Jsf extends LitElement {
301
332
// NOTE: May be debounced / throttled
302
333
this . data = newData ;
303
334
304
- this . onDataChange ( newData , path , value , schemaPath ) ;
335
+ this . dataChangeCallback ( newData , path , value , schemaPath ) ;
305
336
306
337
// TODO:
307
338
// this.dispatchEvent(new CustomEvent('jsf-data', { detail: newData }));
0 commit comments