@ditojs/admin 2.0.5 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dito-admin.es.js +1511 -1435
- package/dist/dito-admin.umd.js +4 -4
- package/dist/style.css +1 -1
- package/package.json +31 -31
- package/src/DitoAdmin.js +66 -31
- package/src/DitoComponent.js +4 -1
- package/src/DitoContext.js +13 -5
- package/src/{TypeComponent.js → DitoTypeComponent.js} +8 -5
- package/src/components/DitoAccount.vue +20 -19
- package/src/components/DitoButtons.vue +14 -12
- package/src/components/DitoClipboard.vue +16 -8
- package/src/components/DitoContainer.vue +56 -43
- package/src/components/DitoCreateButton.vue +20 -15
- package/src/components/DitoDialog.vue +69 -48
- package/src/components/DitoEditButtons.vue +16 -14
- package/src/components/DitoElement.vue +2 -3
- package/src/components/DitoErrors.vue +18 -13
- package/src/components/DitoForm.vue +41 -24
- package/src/components/DitoFormNested.vue +12 -10
- package/src/components/DitoHeader.vue +103 -69
- package/src/components/DitoLabel.vue +108 -81
- package/src/components/DitoMenu.vue +52 -36
- package/src/components/DitoPagination.vue +9 -7
- package/src/components/DitoPane.vue +53 -45
- package/src/components/DitoPanel.vue +62 -42
- package/src/components/DitoPanels.vue +11 -10
- package/src/components/DitoRoot.vue +57 -46
- package/src/components/DitoSchema.vue +179 -131
- package/src/components/DitoSchemaInlined.vue +39 -28
- package/src/components/DitoScopes.vue +41 -31
- package/src/components/DitoSpinner.vue +31 -40
- package/src/components/DitoTableCell.vue +9 -9
- package/src/components/DitoTableHead.vue +52 -37
- package/src/components/DitoTabs.vue +39 -29
- package/src/components/DitoTreeItem.vue +140 -86
- package/src/components/DitoVNode.vue +1 -1
- package/src/components/DitoView.vue +13 -11
- package/src/mixins/DataMixin.js +11 -9
- package/src/mixins/DitoMixin.js +47 -25
- package/src/mixins/EmitterMixin.js +2 -1
- package/src/mixins/ItemMixin.js +15 -10
- package/src/mixins/LoadingMixin.js +2 -1
- package/src/mixins/NumberMixin.js +15 -10
- package/src/mixins/OptionsMixin.js +24 -12
- package/src/mixins/ResourceMixin.js +42 -34
- package/src/mixins/RouteMixin.js +8 -8
- package/src/mixins/SortableMixin.js +1 -1
- package/src/mixins/SourceMixin.js +68 -34
- package/src/mixins/TypeMixin.js +5 -4
- package/src/mixins/ValidationMixin.js +3 -0
- package/src/styles/_base.scss +17 -0
- package/src/styles/_button.scss +212 -0
- package/src/styles/_imports.scss +2 -0
- package/src/styles/_layout.scss +22 -0
- package/src/styles/_notifications.scss +54 -0
- package/src/styles/_pulldown.scss +39 -0
- package/src/styles/_scroll.scss +15 -0
- package/src/styles/_settings.scss +68 -0
- package/src/styles/_sortable.scss +13 -0
- package/src/styles/_table.scss +224 -0
- package/src/styles/style.scss +9 -0
- package/src/types/DitoTypeButton.vue +72 -0
- package/src/types/{TypeCheckbox.vue → DitoTypeCheckbox.vue} +12 -11
- package/src/types/{TypeCheckboxes.vue → DitoTypeCheckboxes.vue} +21 -15
- package/src/types/{TypeCode.vue → DitoTypeCode.vue} +46 -34
- package/src/types/{TypeColor.vue → DitoTypeColor.vue} +71 -52
- package/src/types/{TypeComponent.vue → DitoTypeComponent.vue} +2 -2
- package/src/types/DitoTypeComputed.vue +54 -0
- package/src/types/DitoTypeDate.vue +64 -0
- package/src/types/DitoTypeLabel.vue +23 -0
- package/src/types/{TypeList.vue → DitoTypeList.vue} +83 -61
- package/src/types/{TypeMarkup.vue → DitoTypeMarkup.vue} +172 -122
- package/src/types/DitoTypeMultiselect.vue +434 -0
- package/src/types/DitoTypeNumber.vue +46 -0
- package/src/types/{TypeObject.vue → DitoTypeObject.vue} +41 -26
- package/src/types/{TypePanel.vue → DitoTypePanel.vue} +2 -2
- package/src/types/{TypeProgress.vue → DitoTypeProgress.vue} +4 -6
- package/src/types/{TypeRadio.vue → DitoTypeRadio.vue} +17 -13
- package/src/types/{TypeSection.vue → DitoTypeSection.vue} +17 -17
- package/src/types/{TypeSelect.vue → DitoTypeSelect.vue} +39 -35
- package/src/types/{TypeSlider.vue → DitoTypeSlider.vue} +29 -23
- package/src/types/{TypeSwitch.vue → DitoTypeSwitch.vue} +15 -13
- package/src/types/DitoTypeText.vue +77 -0
- package/src/types/{TypeTextarea.vue → DitoTypeTextarea.vue} +17 -14
- package/src/types/DitoTypeTreeList.vue +191 -0
- package/src/types/{TypeUpload.vue → DitoTypeUpload.vue} +92 -65
- package/src/types/index.js +26 -26
- package/src/utils/SchemaGraph.js +21 -13
- package/src/utils/accessor.js +17 -9
- package/src/utils/data.js +4 -1
- package/src/utils/filter.js +8 -10
- package/src/utils/options.js +3 -3
- package/src/utils/resource.js +12 -10
- package/src/utils/schema.js +190 -125
- package/src/utils/type.js +31 -20
- package/src/validations/_decimals.js +1 -2
- package/types/index.d.ts +27 -23
- package/src/styles/_base.sass +0 -15
- package/src/styles/_button.sass +0 -127
- package/src/styles/_imports.sass +0 -2
- package/src/styles/_layout.sass +0 -13
- package/src/styles/_notifications.sass +0 -33
- package/src/styles/_pulldown.sass +0 -26
- package/src/styles/_scroll.sass +0 -13
- package/src/styles/_settings.sass +0 -55
- package/src/styles/_sortable.sass +0 -9
- package/src/styles/_table.sass +0 -153
- package/src/styles/style.sass +0 -10
- package/src/types/TypeButton.vue +0 -73
- package/src/types/TypeComputed.vue +0 -53
- package/src/types/TypeDate.vue +0 -64
- package/src/types/TypeLabel.vue +0 -19
- package/src/types/TypeMultiselect.vue +0 -376
- package/src/types/TypeNumber.vue +0 -44
- package/src/types/TypeText.vue +0 -67
- package/src/types/TypeTreeList.vue +0 -164
package/src/utils/schema.js
CHANGED
|
@@ -5,7 +5,15 @@ import { getUid } from './uid.js'
|
|
|
5
5
|
import { SchemaGraph } from './SchemaGraph.js'
|
|
6
6
|
import { appendDataPath, isTemporaryId } from './data.js'
|
|
7
7
|
import {
|
|
8
|
-
isObject,
|
|
8
|
+
isObject,
|
|
9
|
+
isString,
|
|
10
|
+
isArray,
|
|
11
|
+
isFunction,
|
|
12
|
+
isPromise,
|
|
13
|
+
isModule,
|
|
14
|
+
clone,
|
|
15
|
+
merge,
|
|
16
|
+
camelize,
|
|
9
17
|
mapConcurrently
|
|
10
18
|
} from '@ditojs/utils'
|
|
11
19
|
import { markRaw } from 'vue'
|
|
@@ -27,16 +35,17 @@ export function getTypeComponent(type, allowNull = false) {
|
|
|
27
35
|
return component
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
|
|
38
|
+
function getSchemas(schema) {
|
|
39
|
+
return schema
|
|
40
|
+
? [...Object.values(schema.tabs || {}), schema]
|
|
41
|
+
: []
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function iterateSchemaComponents(schema, callback) {
|
|
31
45
|
if (isSingleComponentView(schema)) {
|
|
32
|
-
|
|
33
|
-
if (res !== undefined) {
|
|
34
|
-
return res
|
|
35
|
-
}
|
|
46
|
+
return callback(schema.component, schema.name)
|
|
36
47
|
} else {
|
|
37
|
-
const schemas = schema
|
|
38
|
-
? [...Object.values(schema.tabs || {}), schema]
|
|
39
|
-
: []
|
|
48
|
+
const schemas = getSchemas(schema)
|
|
40
49
|
for (const schema of schemas) {
|
|
41
50
|
for (const [name, component] of Object.entries(schema.components || {})) {
|
|
42
51
|
const res = callback(component, name)
|
|
@@ -49,24 +58,32 @@ export function forEachSchemaComponent(schema, callback) {
|
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
export function findSchemaComponent(schema, callback) {
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
return (
|
|
62
|
+
iterateSchemaComponents(
|
|
63
|
+
schema,
|
|
64
|
+
(component, name) => (callback(component, name) ? component : undefined)
|
|
65
|
+
) || null
|
|
66
|
+
)
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
export function someSchemaComponent(schema, callback) {
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
return (
|
|
71
|
+
iterateSchemaComponents(
|
|
72
|
+
schema,
|
|
73
|
+
(component, name) => (callback(component, name) ? true : undefined)
|
|
74
|
+
) ===
|
|
75
|
+
true
|
|
76
|
+
)
|
|
63
77
|
}
|
|
64
78
|
|
|
65
79
|
export function everySchemaComponent(schema, callback) {
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
return (
|
|
81
|
+
iterateSchemaComponents(
|
|
82
|
+
schema,
|
|
83
|
+
(component, name) => (!callback(component, name) ? false : undefined)
|
|
84
|
+
) !==
|
|
85
|
+
false
|
|
86
|
+
)
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
export function isSchema(schema) {
|
|
@@ -174,18 +191,17 @@ export async function resolveSchemaComponents(schemas) {
|
|
|
174
191
|
}
|
|
175
192
|
|
|
176
193
|
export async function processView(component, api, schema, name) {
|
|
177
|
-
const children = []
|
|
178
194
|
processRouteSchema(api, schema, name)
|
|
195
|
+
processDefaults(api, schema)
|
|
179
196
|
await resolvePanels(schema)
|
|
197
|
+
const children = []
|
|
180
198
|
if (isView(schema)) {
|
|
181
|
-
let level = 0
|
|
182
199
|
if (isSingleComponentView(schema)) {
|
|
183
|
-
await processComponent(api, schema.component, name, children,
|
|
200
|
+
await processComponent(api, schema.component, name, children, 0)
|
|
184
201
|
} else {
|
|
185
202
|
// A multi-component view, start at level 1
|
|
186
|
-
await processSchemaComponents(api, schema, children,
|
|
203
|
+
await processSchemaComponents(api, schema, children, 1)
|
|
187
204
|
}
|
|
188
|
-
schema.level = level
|
|
189
205
|
} else {
|
|
190
206
|
throw new Error(`Invalid view schema: '${getSchemaIdentifier(schema)}'`)
|
|
191
207
|
}
|
|
@@ -201,34 +217,62 @@ export async function processView(component, api, schema, name) {
|
|
|
201
217
|
}
|
|
202
218
|
|
|
203
219
|
export async function processComponent(api, schema, name, routes, level) {
|
|
204
|
-
schema
|
|
220
|
+
processDefaults(api, schema)
|
|
205
221
|
// Delegate schema processing to the actual type components.
|
|
206
222
|
await getTypeOptions(schema)?.processSchema?.(
|
|
207
|
-
api,
|
|
223
|
+
api,
|
|
224
|
+
schema,
|
|
225
|
+
name,
|
|
226
|
+
routes,
|
|
227
|
+
level
|
|
208
228
|
)
|
|
209
229
|
}
|
|
210
230
|
|
|
231
|
+
export function processDefaults(api, schema) {
|
|
232
|
+
let defaults = api.defaults[schema.type]
|
|
233
|
+
if (defaults) {
|
|
234
|
+
if (isFunction(defaults)) {
|
|
235
|
+
defaults = defaults(schema)
|
|
236
|
+
}
|
|
237
|
+
if (isObject(defaults)) {
|
|
238
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
239
|
+
if (schema[key] === undefined) {
|
|
240
|
+
schema[key] = value
|
|
241
|
+
} else {
|
|
242
|
+
schema[key] = merge(value, schema[key])
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
211
249
|
export function processRouteSchema(api, schema, name) {
|
|
212
|
-
// Used for view and source schemas, see SourceMixin
|
|
250
|
+
// Used for view and source schemas, see SourceMixin.
|
|
213
251
|
schema.name = name
|
|
214
252
|
schema.path ||= api.normalizePath(name)
|
|
215
253
|
}
|
|
216
254
|
|
|
217
255
|
export async function processSchemaComponents(api, schema, routes, level) {
|
|
218
256
|
const promises = []
|
|
219
|
-
|
|
257
|
+
iterateSchemaComponents(schema, (component, name) => {
|
|
220
258
|
promises.push(processComponent(api, component, name, routes, level))
|
|
221
259
|
})
|
|
222
260
|
await Promise.all(promises)
|
|
223
261
|
}
|
|
224
262
|
|
|
225
263
|
export async function processForms(api, schema, level) {
|
|
264
|
+
const processForm = async form => {
|
|
265
|
+
form = await resolveForm(form)
|
|
266
|
+
processDefaults(api, schema)
|
|
267
|
+
return form
|
|
268
|
+
}
|
|
269
|
+
|
|
226
270
|
// First resolve the forms and store the results back on the schema.
|
|
227
271
|
let { form, forms, components } = schema
|
|
228
272
|
if (forms) {
|
|
229
|
-
forms = schema.forms = await resolveSchemas(forms,
|
|
273
|
+
forms = schema.forms = await resolveSchemas(forms, processForm)
|
|
230
274
|
} else if (form) {
|
|
231
|
-
form = schema.form = await
|
|
275
|
+
form = schema.form = await processForm(form)
|
|
232
276
|
} else if (components) {
|
|
233
277
|
// NOTE: Processing forms in computed components is not supported, since it
|
|
234
278
|
// only can be computed in conjunction with actual data.
|
|
@@ -236,6 +280,7 @@ export async function processForms(api, schema, level) {
|
|
|
236
280
|
form = { components }
|
|
237
281
|
}
|
|
238
282
|
}
|
|
283
|
+
|
|
239
284
|
forms ||= { default: form } // Only used for process loop below.
|
|
240
285
|
const children = []
|
|
241
286
|
for (const form of Object.values(forms)) {
|
|
@@ -249,9 +294,7 @@ export async function resolveForm(schema) {
|
|
|
249
294
|
if (!isForm(schema)) {
|
|
250
295
|
throw new Error(`Invalid form schema: '${getSchemaIdentifier(schema)}'`)
|
|
251
296
|
}
|
|
252
|
-
|
|
253
|
-
await resolvePanels(schema)
|
|
254
|
-
}
|
|
297
|
+
await resolvePanels(schema)
|
|
255
298
|
return schema
|
|
256
299
|
}
|
|
257
300
|
|
|
@@ -282,13 +325,13 @@ export function getViewFormSchema(schema, context) {
|
|
|
282
325
|
const { view } = schema
|
|
283
326
|
const viewSchema = view && context.views[view]
|
|
284
327
|
return viewSchema
|
|
285
|
-
// NOTE: Views can have tabs, in which case the view component is nested
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
328
|
+
? // NOTE: Views can have tabs, in which case the view component is nested
|
|
329
|
+
// in one of the tabs, go find it.
|
|
330
|
+
iterateSchemaComponents(viewSchema, schema => {
|
|
331
|
+
if (hasFormSchema(schema)) {
|
|
332
|
+
return schema
|
|
333
|
+
}
|
|
334
|
+
}) || null
|
|
292
335
|
: null
|
|
293
336
|
}
|
|
294
337
|
|
|
@@ -301,9 +344,9 @@ export function getViewSchema(schema, context) {
|
|
|
301
344
|
export function getViewEditPath(schema, context) {
|
|
302
345
|
const view = getViewSchema(schema, context)
|
|
303
346
|
return view
|
|
304
|
-
? view
|
|
305
|
-
? `/${view.path}`
|
|
306
|
-
: `/${view.path}/${view.path}`
|
|
347
|
+
? isSingleComponentView(view)
|
|
348
|
+
? `/${view.path}`
|
|
349
|
+
: `/${view.path}/${view.path}`
|
|
307
350
|
: null
|
|
308
351
|
}
|
|
309
352
|
|
|
@@ -361,10 +404,7 @@ export function isInlined(schema) {
|
|
|
361
404
|
}
|
|
362
405
|
|
|
363
406
|
export function isNested(schema) {
|
|
364
|
-
return !!(
|
|
365
|
-
schema.nested ||
|
|
366
|
-
getTypeOptions(schema)?.defaultNested === true
|
|
367
|
-
)
|
|
407
|
+
return !!(schema.nested || getTypeOptions(schema)?.defaultNested === true)
|
|
368
408
|
}
|
|
369
409
|
|
|
370
410
|
export function shouldOmitPadding(schema) {
|
|
@@ -378,9 +418,10 @@ export function getDefaultValue(schema) {
|
|
|
378
418
|
// we can't use `dataPath` to get to components, and the `defaultValue` from
|
|
379
419
|
// there. That's why `defaultValue` is defined statically in the components:
|
|
380
420
|
const defaultValue = schema.default
|
|
381
|
-
const value =
|
|
382
|
-
|
|
383
|
-
|
|
421
|
+
const value =
|
|
422
|
+
defaultValue !== undefined
|
|
423
|
+
? defaultValue
|
|
424
|
+
: getTypeOptions(schema)?.defaultValue
|
|
384
425
|
return isFunction(value)
|
|
385
426
|
? value(schema)
|
|
386
427
|
: clone(value)
|
|
@@ -389,8 +430,7 @@ export function getDefaultValue(schema) {
|
|
|
389
430
|
export function ignoreMissingValue(schema) {
|
|
390
431
|
const typeOptions = getTypeOptions(schema)
|
|
391
432
|
return !!(
|
|
392
|
-
typeOptions?.excludeValue ||
|
|
393
|
-
typeOptions?.ignoreMissingValue?.(schema)
|
|
433
|
+
typeOptions?.excludeValue || typeOptions?.ignoreMissingValue?.(schema)
|
|
394
434
|
)
|
|
395
435
|
}
|
|
396
436
|
|
|
@@ -404,7 +444,7 @@ export function hasLabels(schema) {
|
|
|
404
444
|
)
|
|
405
445
|
}
|
|
406
446
|
|
|
407
|
-
export function
|
|
447
|
+
export function setDefaultValues(schema, data = {}, component) {
|
|
408
448
|
const options = { component, rootData: data }
|
|
409
449
|
|
|
410
450
|
const processBefore = (schema, data, name) => {
|
|
@@ -416,7 +456,13 @@ export function setDefaults(schema, data = {}, component) {
|
|
|
416
456
|
// Sets up a data object that has keys with default values for all
|
|
417
457
|
// form fields, so they can be correctly watched for changes.
|
|
418
458
|
return processSchemaData(
|
|
419
|
-
schema,
|
|
459
|
+
schema,
|
|
460
|
+
data,
|
|
461
|
+
null,
|
|
462
|
+
null,
|
|
463
|
+
processBefore,
|
|
464
|
+
null,
|
|
465
|
+
options
|
|
420
466
|
)
|
|
421
467
|
}
|
|
422
468
|
|
|
@@ -426,15 +472,17 @@ export function computeValue(schema, data, name, dataPath, {
|
|
|
426
472
|
} = {}) {
|
|
427
473
|
const { compute } = schema
|
|
428
474
|
if (compute) {
|
|
429
|
-
const value = compute(
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
475
|
+
const value = compute(
|
|
476
|
+
DitoContext.get(component, {
|
|
477
|
+
// Override value to prevent endless recursion through calling the
|
|
478
|
+
// getter for `this.value` in `DitoContext`:
|
|
479
|
+
value: data[name],
|
|
480
|
+
name,
|
|
481
|
+
data,
|
|
482
|
+
dataPath,
|
|
483
|
+
rootData
|
|
484
|
+
})
|
|
485
|
+
)
|
|
438
486
|
if (value !== undefined) {
|
|
439
487
|
// Access `data[name]` directly instead of `this.value = …` to update the
|
|
440
488
|
// value without calling parse():
|
|
@@ -501,11 +549,11 @@ export function processData(schema, sourceSchema, data, dataPath, {
|
|
|
501
549
|
value.sort((a, b) => {
|
|
502
550
|
const id1 = a?.[idKey]
|
|
503
551
|
const id2 = b?.[idKey]
|
|
504
|
-
return (
|
|
505
|
-
|
|
506
|
-
: id2 == null || isTemporaryId(id2)
|
|
507
|
-
|
|
508
|
-
|
|
552
|
+
return id1 == null || isTemporaryId(id1)
|
|
553
|
+
? 1
|
|
554
|
+
: id2 == null || isTemporaryId(id2)
|
|
555
|
+
? -1
|
|
556
|
+
: id1 - id2
|
|
509
557
|
})
|
|
510
558
|
}
|
|
511
559
|
}
|
|
@@ -519,16 +567,17 @@ export function processData(schema, sourceSchema, data, dataPath, {
|
|
|
519
567
|
const typeOptions = getTypeOptions(schema)
|
|
520
568
|
|
|
521
569
|
// NOTE: We don't cache this context, since `value` is changing.
|
|
522
|
-
const getContext = () =>
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
570
|
+
const getContext = () =>
|
|
571
|
+
DitoContext.get(component, {
|
|
572
|
+
value,
|
|
573
|
+
name,
|
|
574
|
+
data,
|
|
575
|
+
dataPath,
|
|
576
|
+
rootData: options.rootData,
|
|
577
|
+
// Pass the already processed data to `process()`, so it can be modified
|
|
578
|
+
// through `processedItem` from there.
|
|
579
|
+
processedData
|
|
580
|
+
})
|
|
532
581
|
|
|
533
582
|
// First unwrap the wrapped primitives again, to bring the data back into
|
|
534
583
|
// its native form. Se `processBefore()` for more details.
|
|
@@ -583,9 +632,10 @@ export function processSchemaData(
|
|
|
583
632
|
options
|
|
584
633
|
) {
|
|
585
634
|
const processComponents = components => {
|
|
586
|
-
const getDataPath = (dataPath, token) =>
|
|
587
|
-
|
|
588
|
-
|
|
635
|
+
const getDataPath = (dataPath, token) =>
|
|
636
|
+
dataPath != null
|
|
637
|
+
? appendDataPath(dataPath, token)
|
|
638
|
+
: null
|
|
589
639
|
|
|
590
640
|
if (components) {
|
|
591
641
|
for (const [name, componentSchema] of Object.entries(components)) {
|
|
@@ -604,9 +654,10 @@ export function processSchemaData(
|
|
|
604
654
|
const componentDataPath = getDataPath(dataPath, name)
|
|
605
655
|
|
|
606
656
|
const processItem = (item, index = null) => {
|
|
607
|
-
const dataPath =
|
|
608
|
-
|
|
609
|
-
|
|
657
|
+
const dataPath =
|
|
658
|
+
index !== null
|
|
659
|
+
? getDataPath(componentDataPath, index)
|
|
660
|
+
: componentDataPath
|
|
610
661
|
const context = DitoContext.get(options.component, {
|
|
611
662
|
data,
|
|
612
663
|
value: item,
|
|
@@ -616,7 +667,7 @@ export function processSchemaData(
|
|
|
616
667
|
})
|
|
617
668
|
const getForms = (
|
|
618
669
|
getTypeOptions(componentSchema)?.getFormSchemasForProcessing ||
|
|
619
|
-
|
|
670
|
+
getFormSchemas
|
|
620
671
|
)
|
|
621
672
|
const forms = getForms(componentSchema, context)
|
|
622
673
|
const form = getItemFormSchemaFromForms(forms, item)
|
|
@@ -641,7 +692,11 @@ export function processSchemaData(
|
|
|
641
692
|
}
|
|
642
693
|
|
|
643
694
|
processBefore?.(
|
|
644
|
-
componentSchema,
|
|
695
|
+
componentSchema,
|
|
696
|
+
data,
|
|
697
|
+
name,
|
|
698
|
+
componentDataPath,
|
|
699
|
+
processedData
|
|
645
700
|
)
|
|
646
701
|
let value = processedData ? processedData[name] : data[name]
|
|
647
702
|
if (value != null && hasFormSchema(componentSchema)) {
|
|
@@ -659,7 +714,11 @@ export function processSchemaData(
|
|
|
659
714
|
}
|
|
660
715
|
}
|
|
661
716
|
processAfter?.(
|
|
662
|
-
componentSchema,
|
|
717
|
+
componentSchema,
|
|
718
|
+
data,
|
|
719
|
+
name,
|
|
720
|
+
componentDataPath,
|
|
721
|
+
processedData
|
|
663
722
|
)
|
|
664
723
|
}
|
|
665
724
|
}
|
|
@@ -683,37 +742,42 @@ export function getNamedSchemas(schemas, defaults) {
|
|
|
683
742
|
const toObject = (array, toSchema) => {
|
|
684
743
|
return array.length > 0
|
|
685
744
|
? array.reduce((object, value) => {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
745
|
+
const schema = toSchema(value)
|
|
746
|
+
if (schema) {
|
|
747
|
+
object[schema.name] =
|
|
748
|
+
schema && defaults
|
|
749
|
+
? { ...defaults, ...schema }
|
|
750
|
+
: schema
|
|
751
|
+
}
|
|
752
|
+
return object
|
|
753
|
+
}, {})
|
|
694
754
|
: null
|
|
695
755
|
}
|
|
696
756
|
|
|
697
757
|
return isArray(schemas)
|
|
698
|
-
? toObject(schemas, value =>
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
758
|
+
? toObject(schemas, value =>
|
|
759
|
+
isObject(value)
|
|
760
|
+
? value
|
|
761
|
+
: {
|
|
762
|
+
name: camelize(value, false)
|
|
763
|
+
}
|
|
764
|
+
)
|
|
703
765
|
: isObject(schemas)
|
|
704
766
|
? toObject(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
767
|
+
Object.entries(schemas),
|
|
768
|
+
([name, value]) =>
|
|
769
|
+
isObject(value)
|
|
770
|
+
? {
|
|
771
|
+
name,
|
|
772
|
+
...value
|
|
773
|
+
}
|
|
774
|
+
: isString(value)
|
|
775
|
+
? {
|
|
776
|
+
name,
|
|
777
|
+
label: value
|
|
778
|
+
}
|
|
779
|
+
: null
|
|
780
|
+
)
|
|
717
781
|
: null
|
|
718
782
|
}
|
|
719
783
|
|
|
@@ -733,22 +797,23 @@ export function getTypeOptions(schemaOrType) {
|
|
|
733
797
|
}
|
|
734
798
|
|
|
735
799
|
export function getSourceType(schemaOrType) {
|
|
736
|
-
return
|
|
737
|
-
getType(schemaOrType)
|
|
738
|
-
|
|
800
|
+
return (
|
|
801
|
+
getTypeOptions(schemaOrType)?.getSourceType?.(getType(schemaOrType)) ??
|
|
802
|
+
null
|
|
803
|
+
)
|
|
739
804
|
}
|
|
740
805
|
|
|
741
806
|
export function getPanelSchema(schema, dataPath, tabComponent) {
|
|
742
807
|
return schema
|
|
743
808
|
? {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
809
|
+
schema,
|
|
810
|
+
// If the panel provides its own name, append it to the dataPath.
|
|
811
|
+
// This is used e.g. for $filters panels.
|
|
812
|
+
dataPath: schema.name
|
|
813
|
+
? appendDataPath(dataPath, schema.name)
|
|
814
|
+
: dataPath,
|
|
815
|
+
tabComponent
|
|
816
|
+
}
|
|
752
817
|
: null
|
|
753
818
|
}
|
|
754
819
|
|
package/src/utils/type.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isArray,
|
|
3
|
-
|
|
2
|
+
isArray,
|
|
3
|
+
isObject,
|
|
4
|
+
isString,
|
|
5
|
+
isBoolean,
|
|
6
|
+
isNumber,
|
|
7
|
+
isFunction,
|
|
8
|
+
isDate,
|
|
9
|
+
isRegExp,
|
|
10
|
+
asArray
|
|
4
11
|
} from '@ditojs/utils'
|
|
5
12
|
|
|
6
13
|
const typeCheckers = {
|
|
@@ -20,27 +27,31 @@ const toBoolean = value => !!value
|
|
|
20
27
|
const toNumber = value => +value
|
|
21
28
|
const toString = value => String(value)
|
|
22
29
|
|
|
23
|
-
const toDate = value =>
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
const toDate = value =>
|
|
31
|
+
isDate(value)
|
|
32
|
+
? value
|
|
33
|
+
: new Date(value)
|
|
26
34
|
|
|
27
|
-
const toArray = value =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
const toArray = value =>
|
|
36
|
+
isArray(value)
|
|
37
|
+
? value
|
|
38
|
+
: isString(value)
|
|
39
|
+
? value.split(',')
|
|
40
|
+
: asArray(value)
|
|
32
41
|
|
|
33
|
-
const toObject = value =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
const toObject = value =>
|
|
43
|
+
isObject(value)
|
|
44
|
+
? value
|
|
45
|
+
: // If a Object is expected but a Boolean provide, convert to an empty
|
|
46
|
+
// object. Used by `creatable` & co, that can be both.
|
|
47
|
+
value === true
|
|
48
|
+
? {}
|
|
49
|
+
: null
|
|
40
50
|
|
|
41
|
-
const toRegExp = value =>
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
const toRegExp = value =>
|
|
52
|
+
isRegExp(value)
|
|
53
|
+
? value
|
|
54
|
+
: new RegExp(value)
|
|
44
55
|
|
|
45
56
|
const typeConverters = {
|
|
46
57
|
Boolean: toBoolean,
|
|
@@ -4,9 +4,8 @@ export const decimals = {
|
|
|
4
4
|
return new RegExp(`^[-+]?\\d*(\\.\\d${match})?$`).test(value)
|
|
5
5
|
},
|
|
6
6
|
|
|
7
|
-
message: (value, decimals) =>
|
|
7
|
+
message: (value, decimals) =>
|
|
8
8
|
`must be numeric and may contain ${
|
|
9
9
|
!decimals || decimals === '*' ? '' : decimals
|
|
10
10
|
} decimal points`
|
|
11
|
-
)
|
|
12
11
|
}
|