@ditojs/admin 2.1.1 → 2.1.2
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 +1525 -1489
- package/dist/dito-admin.umd.js +4 -4
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/DitoContext.js +7 -3
- package/src/components/DitoPane.vue +4 -4
- package/src/components/DitoSchema.vue +6 -6
- package/src/components/DitoView.vue +1 -4
- package/src/mixins/OptionsMixin.js +2 -0
- package/src/types/DitoTypeMultiselect.vue +214 -181
- package/src/types/DitoTypeText.vue +3 -1
- package/src/utils/filter.js +2 -0
- package/src/utils/schema.js +109 -79
package/src/utils/schema.js
CHANGED
|
@@ -35,20 +35,16 @@ export function getTypeComponent(type, allowNull = false) {
|
|
|
35
35
|
return component
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return callback(schema.component, schema.name)
|
|
47
|
-
} else {
|
|
48
|
-
const schemas = getSchemas(schema)
|
|
49
|
-
for (const schema of schemas) {
|
|
38
|
+
export function iterateSchemaComponents(schemas, callback) {
|
|
39
|
+
for (const schema of schemas) {
|
|
40
|
+
if (isSingleComponentView(schema)) {
|
|
41
|
+
const res = callback(schema.component, schema.name, 0)
|
|
42
|
+
if (res !== undefined) {
|
|
43
|
+
return res
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
50
46
|
for (const [name, component] of Object.entries(schema.components || {})) {
|
|
51
|
-
const res = callback(component, name)
|
|
47
|
+
const res = callback(component, name, 1)
|
|
52
48
|
if (res !== undefined) {
|
|
53
49
|
return res
|
|
54
50
|
}
|
|
@@ -57,32 +53,36 @@ export function iterateSchemaComponents(schema, callback) {
|
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
|
|
56
|
+
export function iterateNestedSchemaComponents(schema, callback) {
|
|
57
|
+
return schema
|
|
58
|
+
? iterateSchemaComponents([schema, ...getAllTabSchemas(schema)], callback)
|
|
59
|
+
: undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
60
62
|
export function findSchemaComponent(schema, callback) {
|
|
61
63
|
return (
|
|
62
|
-
|
|
64
|
+
iterateNestedSchemaComponents(
|
|
63
65
|
schema,
|
|
64
|
-
|
|
66
|
+
component => (callback(component) ? component : undefined)
|
|
65
67
|
) || null
|
|
66
68
|
)
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
export function someSchemaComponent(schema, callback) {
|
|
70
72
|
return (
|
|
71
|
-
|
|
73
|
+
iterateNestedSchemaComponents(
|
|
72
74
|
schema,
|
|
73
|
-
|
|
74
|
-
) ===
|
|
75
|
-
true
|
|
75
|
+
component => (callback(component) ? true : undefined)
|
|
76
|
+
) === true
|
|
76
77
|
)
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
export function everySchemaComponent(schema, callback) {
|
|
80
81
|
return (
|
|
81
|
-
|
|
82
|
+
iterateNestedSchemaComponents(
|
|
82
83
|
schema,
|
|
83
|
-
|
|
84
|
-
) !==
|
|
85
|
-
false
|
|
84
|
+
component => (callback(component) ? undefined : false)
|
|
85
|
+
) !== false
|
|
86
86
|
)
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -161,8 +161,11 @@ export async function resolveSchemas(
|
|
|
161
161
|
return schemas
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
export async function
|
|
165
|
-
const { panels } = schema
|
|
164
|
+
export async function resolveNestedSchemas(schema) {
|
|
165
|
+
const { tabs, panels } = schema
|
|
166
|
+
if (tabs) {
|
|
167
|
+
schema.tabs = await resolveSchemas(tabs)
|
|
168
|
+
}
|
|
166
169
|
if (panels) {
|
|
167
170
|
schema.panels = await resolveSchemas(panels)
|
|
168
171
|
}
|
|
@@ -193,15 +196,10 @@ export async function resolveSchemaComponents(schemas) {
|
|
|
193
196
|
export async function processView(component, api, schema, name) {
|
|
194
197
|
processRouteSchema(api, schema, name)
|
|
195
198
|
processDefaults(api, schema)
|
|
196
|
-
await
|
|
199
|
+
await resolveNestedSchemas(schema)
|
|
197
200
|
const children = []
|
|
198
201
|
if (isView(schema)) {
|
|
199
|
-
|
|
200
|
-
await processComponent(api, schema.component, name, children, 0)
|
|
201
|
-
} else {
|
|
202
|
-
// A multi-component view, start at level 1
|
|
203
|
-
await processSchemaComponents(api, schema, children, 1)
|
|
204
|
-
}
|
|
202
|
+
await processSchemaComponents(api, schema, children, 0)
|
|
205
203
|
} else {
|
|
206
204
|
throw new Error(`Invalid view schema: '${getSchemaIdentifier(schema)}'`)
|
|
207
205
|
}
|
|
@@ -216,18 +214,6 @@ export async function processView(component, api, schema, name) {
|
|
|
216
214
|
}
|
|
217
215
|
}
|
|
218
216
|
|
|
219
|
-
export async function processComponent(api, schema, name, routes, level) {
|
|
220
|
-
processDefaults(api, schema)
|
|
221
|
-
// Delegate schema processing to the actual type components.
|
|
222
|
-
await getTypeOptions(schema)?.processSchema?.(
|
|
223
|
-
api,
|
|
224
|
-
schema,
|
|
225
|
-
name,
|
|
226
|
-
routes,
|
|
227
|
-
level
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
217
|
export function processDefaults(api, schema) {
|
|
232
218
|
let defaults = api.defaults[schema.type]
|
|
233
219
|
if (defaults) {
|
|
@@ -254,12 +240,43 @@ export function processRouteSchema(api, schema, name) {
|
|
|
254
240
|
|
|
255
241
|
export async function processSchemaComponents(api, schema, routes, level) {
|
|
256
242
|
const promises = []
|
|
257
|
-
|
|
258
|
-
promises.push(
|
|
259
|
-
|
|
243
|
+
const process = (component, name, relativeLevel) => {
|
|
244
|
+
promises.push(
|
|
245
|
+
processSchemaComponent(
|
|
246
|
+
api,
|
|
247
|
+
component,
|
|
248
|
+
name,
|
|
249
|
+
routes,
|
|
250
|
+
level + relativeLevel
|
|
251
|
+
)
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
iterateNestedSchemaComponents(schema, process)
|
|
256
|
+
iterateSchemaComponents(getAllPanelSchemas(schema), process)
|
|
257
|
+
|
|
260
258
|
await Promise.all(promises)
|
|
261
259
|
}
|
|
262
260
|
|
|
261
|
+
export async function processSchemaComponent(api, schema, name, routes, level) {
|
|
262
|
+
processDefaults(api, schema)
|
|
263
|
+
|
|
264
|
+
await Promise.all([
|
|
265
|
+
// Also process nested panel schemas.
|
|
266
|
+
mapConcurrently(getAllPanelSchemas(schema), panel =>
|
|
267
|
+
processSchemaComponents(api, panel, routes, level)
|
|
268
|
+
),
|
|
269
|
+
// Delegate schema processing to the actual type components.
|
|
270
|
+
await getTypeOptions(schema)?.processSchema?.(
|
|
271
|
+
api,
|
|
272
|
+
schema,
|
|
273
|
+
name,
|
|
274
|
+
routes,
|
|
275
|
+
level
|
|
276
|
+
)
|
|
277
|
+
])
|
|
278
|
+
}
|
|
279
|
+
|
|
263
280
|
export async function processForms(api, schema, level) {
|
|
264
281
|
const processForm = async form => {
|
|
265
282
|
form = await resolveForm(form)
|
|
@@ -284,7 +301,7 @@ export async function processForms(api, schema, level) {
|
|
|
284
301
|
forms ||= { default: form } // Only used for process loop below.
|
|
285
302
|
const children = []
|
|
286
303
|
for (const form of Object.values(forms)) {
|
|
287
|
-
await processSchemaComponents(api, form, children, level
|
|
304
|
+
await processSchemaComponents(api, form, children, level)
|
|
288
305
|
}
|
|
289
306
|
return children
|
|
290
307
|
}
|
|
@@ -294,7 +311,7 @@ export async function resolveForm(schema) {
|
|
|
294
311
|
if (!isForm(schema)) {
|
|
295
312
|
throw new Error(`Invalid form schema: '${getSchemaIdentifier(schema)}'`)
|
|
296
313
|
}
|
|
297
|
-
await
|
|
314
|
+
await resolveNestedSchemas(schema)
|
|
298
315
|
return schema
|
|
299
316
|
}
|
|
300
317
|
|
|
@@ -327,11 +344,7 @@ export function getViewFormSchema(schema, context) {
|
|
|
327
344
|
return viewSchema
|
|
328
345
|
? // NOTE: Views can have tabs, in which case the view component is nested
|
|
329
346
|
// in one of the tabs, go find it.
|
|
330
|
-
|
|
331
|
-
if (hasFormSchema(schema)) {
|
|
332
|
-
return schema
|
|
333
|
-
}
|
|
334
|
-
}) || null
|
|
347
|
+
findSchemaComponent(viewSchema, hasFormSchema) || null
|
|
335
348
|
: null
|
|
336
349
|
}
|
|
337
350
|
|
|
@@ -474,6 +487,7 @@ export function computeValue(schema, data, name, dataPath, {
|
|
|
474
487
|
if (compute) {
|
|
475
488
|
const value = compute(
|
|
476
489
|
DitoContext.get(component, {
|
|
490
|
+
schema,
|
|
477
491
|
// Override value to prevent endless recursion through calling the
|
|
478
492
|
// getter for `this.value` in `DitoContext`:
|
|
479
493
|
value: data[name],
|
|
@@ -569,6 +583,7 @@ export function processData(schema, sourceSchema, data, dataPath, {
|
|
|
569
583
|
// NOTE: We don't cache this context, since `value` is changing.
|
|
570
584
|
const getContext = () =>
|
|
571
585
|
DitoContext.get(component, {
|
|
586
|
+
schema,
|
|
572
587
|
value,
|
|
573
588
|
name,
|
|
574
589
|
data,
|
|
@@ -659,6 +674,7 @@ export function processSchemaData(
|
|
|
659
674
|
? getDataPath(componentDataPath, index)
|
|
660
675
|
: componentDataPath
|
|
661
676
|
const context = DitoContext.get(options.component, {
|
|
677
|
+
schema: componentSchema,
|
|
662
678
|
data,
|
|
663
679
|
value: item,
|
|
664
680
|
dataPath,
|
|
@@ -726,13 +742,11 @@ export function processSchemaData(
|
|
|
726
742
|
}
|
|
727
743
|
|
|
728
744
|
processComponents(schema.components)
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
processComponents(tab.components)
|
|
732
|
-
}
|
|
745
|
+
for (const tab of getAllTabSchemas(schema)) {
|
|
746
|
+
processComponents(tab.components)
|
|
733
747
|
}
|
|
734
|
-
for (const panel of getAllPanelSchemas(schema
|
|
735
|
-
processComponents(panel.
|
|
748
|
+
for (const panel of getAllPanelSchemas(schema)) {
|
|
749
|
+
processComponents(panel.components)
|
|
736
750
|
}
|
|
737
751
|
|
|
738
752
|
return processedData || data
|
|
@@ -803,52 +817,68 @@ export function getSourceType(schemaOrType) {
|
|
|
803
817
|
)
|
|
804
818
|
}
|
|
805
819
|
|
|
806
|
-
export function
|
|
820
|
+
export function getPanelEntry(schema, dataPath = null, tabComponent = null) {
|
|
807
821
|
return schema
|
|
808
822
|
? {
|
|
809
823
|
schema,
|
|
810
824
|
// If the panel provides its own name, append it to the dataPath.
|
|
811
825
|
// This is used e.g. for $filters panels.
|
|
812
|
-
dataPath:
|
|
813
|
-
|
|
814
|
-
|
|
826
|
+
dataPath:
|
|
827
|
+
dataPath != null && schema.name
|
|
828
|
+
? appendDataPath(dataPath, schema.name)
|
|
829
|
+
: dataPath,
|
|
815
830
|
tabComponent
|
|
816
831
|
}
|
|
817
832
|
: null
|
|
818
833
|
}
|
|
819
834
|
|
|
820
|
-
export function
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
835
|
+
export function getPanelEntries(
|
|
836
|
+
panelSchemas,
|
|
837
|
+
dataPath = null,
|
|
838
|
+
tabComponent = null,
|
|
839
|
+
panelEntries = []
|
|
840
|
+
) {
|
|
841
|
+
if (panelSchemas) {
|
|
842
|
+
for (const [key, schema] of Object.entries(panelSchemas)) {
|
|
843
|
+
const entry = getPanelEntry(
|
|
824
844
|
schema,
|
|
825
|
-
appendDataPath(dataPath, key),
|
|
845
|
+
dataPath != null ? appendDataPath(dataPath, key) : null,
|
|
826
846
|
tabComponent
|
|
827
847
|
)
|
|
828
|
-
if (
|
|
829
|
-
|
|
848
|
+
if (entry) {
|
|
849
|
+
panelEntries.push(entry)
|
|
830
850
|
}
|
|
831
851
|
}
|
|
832
852
|
}
|
|
833
|
-
return
|
|
853
|
+
return panelEntries
|
|
834
854
|
}
|
|
835
855
|
|
|
836
|
-
export function
|
|
856
|
+
export function getAllTabSchemas(schema) {
|
|
857
|
+
return schema?.tabs ? Object.values(schema.tabs) : []
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
export function getAllPanelSchemas(schema) {
|
|
861
|
+
return getAllPanelEntries(schema).map(entry => entry.schema)
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
export function getAllPanelEntries(
|
|
837
865
|
schema,
|
|
838
|
-
dataPath,
|
|
866
|
+
dataPath = null,
|
|
839
867
|
schemaComponent = null,
|
|
840
868
|
tabComponent = null
|
|
841
869
|
) {
|
|
842
|
-
const
|
|
870
|
+
const panelSchema = getTypeOptions(schema)?.getPanelSchema?.(
|
|
843
871
|
schema,
|
|
844
872
|
dataPath,
|
|
845
873
|
schemaComponent
|
|
846
874
|
)
|
|
847
|
-
const
|
|
875
|
+
const panelEntries = panelSchema
|
|
876
|
+
? [getPanelEntry(panelSchema, dataPath, tabComponent)]
|
|
877
|
+
: []
|
|
848
878
|
// Allow each component to provide its own set of panels, in
|
|
849
|
-
// addition to the default one (e.g. $
|
|
850
|
-
|
|
851
|
-
return
|
|
879
|
+
// addition to the default one (e.g. getFiltersPanel(), $filters):
|
|
880
|
+
getPanelEntries(schema?.panels, dataPath, tabComponent, panelEntries)
|
|
881
|
+
return panelEntries
|
|
852
882
|
}
|
|
853
883
|
|
|
854
884
|
export function isObjectSource(schemaOrType) {
|