@ditojs/admin 2.27.1 → 2.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/admin",
3
- "version": "2.27.1",
3
+ "version": "2.27.2",
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",
@@ -83,7 +83,7 @@
83
83
  "vite": "^5.2.8"
84
84
  },
85
85
  "types": "types",
86
- "gitHead": "f8e8c86149487d9a7b991c9c4b8d9165974fb0a2",
86
+ "gitHead": "d15a80e1ecdf916fd087ad7c5b21eee0b2ee9daf",
87
87
  "scripts": {
88
88
  "build": "vite build",
89
89
  "watch": "yarn build --mode 'development' --watch",
@@ -1,5 +1,5 @@
1
1
  import { isFunction } from '@ditojs/utils'
2
- import * as validations from '../validations/index.js'
2
+ import * as validators from '../validators/index.js'
3
3
 
4
4
  // @vue/component
5
5
  export default {
@@ -36,11 +36,15 @@ export default {
36
36
  this.clearErrors()
37
37
  }
38
38
  const { value } = this
39
- // console.log('validate', this.dataPath, value, this.validations)
40
39
  for (const [rule, setting] of Object.entries(this.validations)) {
41
40
  // eslint-disable-next-line import/namespace
42
- const validator = validations[rule]
43
- if (validator && (validator.nullish || value != null)) {
41
+ const validator = validators[rule]
42
+ if (
43
+ validator &&
44
+ // Only apply 'required' validator to empty values.
45
+ // Apply all other validators only to non-empty values.
46
+ (rule === 'required' || value != null && value !== '')
47
+ ) {
44
48
  const { validate, message } = validator
45
49
  if (!validate(value, setting, this.validations)) {
46
50
  isValid = false
@@ -19,7 +19,7 @@ import {
19
19
  mapConcurrently,
20
20
  getValueAtDataPath
21
21
  } from '@ditojs/utils'
22
- import { markRaw } from 'vue'
22
+ import { markRaw, reactive } from 'vue'
23
23
 
24
24
  const typeComponents = {}
25
25
  const unknownTypeReported = {}
@@ -243,7 +243,7 @@ export async function resolveSchemaComponents(schemas) {
243
243
  }
244
244
 
245
245
  const processedSchemaDepths = new WeakMap()
246
- export async function processSchemaComponents(
246
+ export function processSchemaComponents(
247
247
  api,
248
248
  schema,
249
249
  routes = null,
@@ -270,12 +270,12 @@ export async function processSchemaComponents(
270
270
  iterateNestedSchemaComponents(schema, process)
271
271
  iterateSchemaComponents(getPanelSchemas(schema), process)
272
272
 
273
- await Promise.all(promises)
273
+ return Promise.all(promises)
274
274
  }
275
275
  }
276
276
  }
277
277
 
278
- export async function processSchemaComponent(
278
+ export function processSchemaComponent(
279
279
  api,
280
280
  schema,
281
281
  name,
@@ -284,7 +284,7 @@ export async function processSchemaComponent(
284
284
  ) {
285
285
  processSchemaDefaults(api, schema)
286
286
 
287
- await Promise.all([
287
+ return Promise.all([
288
288
  // Also process nested panel schemas.
289
289
  mapConcurrently(
290
290
  getPanelSchemas(schema),
@@ -370,38 +370,41 @@ export function processRouteSchema(api, schema, name, fullPath = null) {
370
370
  }
371
371
 
372
372
  export async function processForms(api, schema, level) {
373
+ const routes = []
373
374
  // First resolve the forms and store the results back on the schema.
374
- let { form, forms, components, maxDepth = 1 } = schema
375
+ const { form, forms, components, maxDepth = 1 } = schema
375
376
  if (forms) {
376
- forms = schema.forms = await resolveSchemas(forms, form =>
377
- processForm(api, form)
377
+ schema.forms = await resolveSchemas(forms, form =>
378
+ processForm(api, form, routes, level, maxDepth)
378
379
  )
379
380
  } else if (form) {
380
- form = schema.form = await processForm(api, form)
381
+ schema.form = await processForm(api, form, routes, level, maxDepth)
381
382
  } else if (isObject(components)) {
382
383
  // NOTE: Processing forms in computed components is not supported, since it
383
384
  // only can be computed in conjunction with actual data.
384
- form = {
385
+ const form = {
385
386
  type: 'form',
386
387
  components
387
388
  }
389
+ await processForm(api, form, routes, level, maxDepth)
388
390
  }
389
-
390
- forms ||= { default: form } // Only used for process loop below.
391
- const children = []
392
- for (const form of Object.values(forms)) {
393
- await processSchemaComponents(api, form, children, level, maxDepth)
394
- }
395
- return children
391
+ return routes
396
392
  }
397
393
 
398
- export async function processForm(api, schema) {
394
+ export async function processForm(
395
+ api,
396
+ schema,
397
+ routes = null,
398
+ level = 0,
399
+ maxDepth = 1
400
+ ) {
399
401
  schema = await resolveSchema(schema, true)
400
402
  if (!isForm(schema)) {
401
403
  throw new Error(`Invalid form schema: '${getSchemaIdentifier(schema)}'`)
402
404
  }
403
405
  processSchemaDefaults(api, schema)
404
406
  await processNestedSchemas(api, schema)
407
+ await processSchemaComponents(api, schema, routes, level, maxDepth)
405
408
  return schema
406
409
  }
407
410
 
@@ -518,10 +521,14 @@ export function getFormSchemas(schema, context, modifyForm) {
518
521
  Object.entries(forms).map(([type, form]) => {
519
522
  // Support `schema.components` callbacks to create components on the fly.
520
523
  if (context && isFunction(form.components)) {
521
- form = {
524
+ // Make the form schema reactive since `processForm()` is async, so that
525
+ // the setting of defaults will be picked up by downstream code.
526
+ form = reactive({
522
527
  ...form,
523
528
  components: form.components(context)
524
- }
529
+ })
530
+ // Process the form again, now that we have the components.
531
+ processForm(context.api, form).catch(console.error)
525
532
  }
526
533
  return [type, modifyForm?.(form) ?? form]
527
534
  })
@@ -5,6 +5,5 @@ export const required = {
5
5
  // but unchanged, allow this to pass through:
6
6
  (password && value === undefined)
7
7
  ),
8
- message: 'is required',
9
- nullish: true
8
+ message: 'is required'
10
9
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes