@ditojs/admin 2.1.2 → 2.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/admin",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "type": "module",
5
5
  "description": "Dito.js Admin is a schema based admin interface for Dito.js Server, featuring auto-generated views and forms and built with Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/admin",
@@ -82,7 +82,7 @@
82
82
  "vite": "^4.2.1"
83
83
  },
84
84
  "types": "types",
85
- "gitHead": "90bf14abf59293794f94d47c8866d9e85dd49ac8",
85
+ "gitHead": "39cbb715f40b8c3c657ca8d6790def22f170b31b",
86
86
  "scripts": {
87
87
  "build": "vite build",
88
88
  "watch": "yarn build --mode 'development' --watch",
@@ -16,7 +16,8 @@ export default {
16
16
  getSortableOptions(draggable, fallback = false) {
17
17
  return {
18
18
  animation: 150,
19
- disabled: !draggable,
19
+ // TODO: This is broken in VueSortable, always enable it for now.
20
+ // disabled: !draggable,
20
21
  handle: '.dito-button-drag',
21
22
  dragClass: 'dito-sortable-active',
22
23
  chosenClass: 'dito-sortable-chosen',
@@ -98,6 +98,14 @@ export function isView(schema) {
98
98
  return isSchema(schema) && schema.type === 'view'
99
99
  }
100
100
 
101
+ export function isTab(schema) {
102
+ return isSchema(schema) && schema.type === 'tab'
103
+ }
104
+
105
+ export function isPanel(schema) {
106
+ return isSchema(schema) && schema.type === 'panel'
107
+ }
108
+
101
109
  export function getSchemaIdentifier(schema) {
102
110
  return schema.name || schema.label || schema.type
103
111
  }
@@ -161,16 +169,6 @@ export async function resolveSchemas(
161
169
  return schemas
162
170
  }
163
171
 
164
- export async function resolveNestedSchemas(schema) {
165
- const { tabs, panels } = schema
166
- if (tabs) {
167
- schema.tabs = await resolveSchemas(tabs)
168
- }
169
- if (panels) {
170
- schema.panels = await resolveSchemas(panels)
171
- }
172
- }
173
-
174
172
  export async function resolveSchemaComponent(schema) {
175
173
  // Resolves async schema components and adds DitoMixin and TypeMixin to them.
176
174
  let { component } = schema
@@ -193,51 +191,6 @@ export async function resolveSchemaComponents(schemas) {
193
191
  await mapConcurrently(Object.values(schemas || {}), resolveSchemaComponent)
194
192
  }
195
193
 
196
- export async function processView(component, api, schema, name) {
197
- processRouteSchema(api, schema, name)
198
- processDefaults(api, schema)
199
- await resolveNestedSchemas(schema)
200
- const children = []
201
- if (isView(schema)) {
202
- await processSchemaComponents(api, schema, children, 0)
203
- } else {
204
- throw new Error(`Invalid view schema: '${getSchemaIdentifier(schema)}'`)
205
- }
206
- return {
207
- path: `/${schema.path}`,
208
- children,
209
- component,
210
- meta: {
211
- api,
212
- schema
213
- }
214
- }
215
- }
216
-
217
- export function processDefaults(api, schema) {
218
- let defaults = api.defaults[schema.type]
219
- if (defaults) {
220
- if (isFunction(defaults)) {
221
- defaults = defaults(schema)
222
- }
223
- if (isObject(defaults)) {
224
- for (const [key, value] of Object.entries(defaults)) {
225
- if (schema[key] === undefined) {
226
- schema[key] = value
227
- } else {
228
- schema[key] = merge(value, schema[key])
229
- }
230
- }
231
- }
232
- }
233
- }
234
-
235
- export function processRouteSchema(api, schema, name) {
236
- // Used for view and source schemas, see SourceMixin.
237
- schema.name = name
238
- schema.path ||= api.normalizePath(name)
239
- }
240
-
241
194
  export async function processSchemaComponents(api, schema, routes, level) {
242
195
  const promises = []
243
196
  const process = (component, name, relativeLevel) => {
@@ -277,19 +230,59 @@ export async function processSchemaComponent(api, schema, name, routes, level) {
277
230
  ])
278
231
  }
279
232
 
280
- export async function processForms(api, schema, level) {
281
- const processForm = async form => {
282
- form = await resolveForm(form)
283
- processDefaults(api, schema)
284
- return form
233
+ export async function processView(component, api, schema, name) {
234
+ if (!isView(schema)) {
235
+ throw new Error(`Invalid view schema: '${getSchemaIdentifier(schema)}'`)
285
236
  }
237
+ processRouteSchema(api, schema, name)
238
+ processDefaults(api, schema)
239
+ await resolveNestedSchemas(api, schema)
240
+ const children = []
241
+ await processSchemaComponents(api, schema, children, 0)
242
+ return {
243
+ path: `/${schema.path}`,
244
+ children,
245
+ component,
246
+ meta: {
247
+ api,
248
+ schema
249
+ }
250
+ }
251
+ }
252
+
253
+ export function processDefaults(api, schema) {
254
+ let defaults = api.defaults[schema.type]
255
+ if (defaults) {
256
+ if (isFunction(defaults)) {
257
+ defaults = defaults(schema)
258
+ }
259
+ if (isObject(defaults)) {
260
+ for (const [key, value] of Object.entries(defaults)) {
261
+ if (schema[key] === undefined) {
262
+ schema[key] = value
263
+ } else {
264
+ schema[key] = merge(value, schema[key])
265
+ }
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ export function processRouteSchema(api, schema, name) {
272
+ // Used for view and source schemas, see SourceMixin.
273
+ schema.name = name
274
+ schema.path ||= api.normalizePath(name)
275
+ }
286
276
 
277
+ export async function processForms(api, schema, level) {
287
278
  // First resolve the forms and store the results back on the schema.
288
279
  let { form, forms, components } = schema
289
280
  if (forms) {
290
- forms = schema.forms = await resolveSchemas(forms, processForm)
281
+ forms = schema.forms = await resolveSchemas(forms, form =>
282
+ processForm(api, form)
283
+ )
291
284
  } else if (form) {
292
- form = schema.form = await processForm(form)
285
+ form = schema.form = await processForm(api, form)
293
286
  } else if (components) {
294
287
  // NOTE: Processing forms in computed components is not supported, since it
295
288
  // only can be computed in conjunction with actual data.
@@ -306,15 +299,50 @@ export async function processForms(api, schema, level) {
306
299
  return children
307
300
  }
308
301
 
309
- export async function resolveForm(schema) {
302
+ export async function processForm(api, schema) {
310
303
  schema = await resolveSchema(schema, true)
311
304
  if (!isForm(schema)) {
312
305
  throw new Error(`Invalid form schema: '${getSchemaIdentifier(schema)}'`)
313
306
  }
314
- await resolveNestedSchemas(schema)
307
+ processDefaults(api, schema)
308
+ await resolveNestedSchemas(api, schema)
315
309
  return schema
316
310
  }
317
311
 
312
+ export async function processTab(api, schema) {
313
+ schema = await resolveSchema(schema, true)
314
+ if (!isTab(schema)) {
315
+ throw new Error(`Invalid tab schema: '${getSchemaIdentifier(schema)}'`)
316
+ }
317
+ processDefaults(api, schema)
318
+ return schema
319
+ }
320
+
321
+ export async function processPanel(api, schema) {
322
+ schema = await resolveSchema(schema, true)
323
+ if (!isPanel(schema)) {
324
+ throw new Error(`Invalid panel schema: '${getSchemaIdentifier(schema)}'`)
325
+ }
326
+ processDefaults(api, schema)
327
+ return schema
328
+ }
329
+
330
+ export async function resolveNestedSchemas(api, schema) {
331
+ const { tabs, panels } = schema
332
+ if (tabs) {
333
+ schema.tabs = await resolveSchemas(
334
+ tabs,
335
+ tab => processTab(api, tab)
336
+ )
337
+ }
338
+ if (panels) {
339
+ schema.panels = await resolveSchemas(
340
+ panels,
341
+ panel => processPanel(api, panel)
342
+ )
343
+ }
344
+ }
345
+
318
346
  export function hasFormSchema(schema) {
319
347
  // Support both single form and multiple forms notation, as well as inlined
320
348
  // components.