@koumoul/vjsf 3.0.0-alpha.9 → 3.0.0-beta.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koumoul/vjsf",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "Generate forms for the vuetify UI library (vuejs) based on annotated JSON schemas.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "vitest",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"vuetify": "^3.4.9"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@json-layout/core": "0.
|
|
78
|
+
"@json-layout/core": "0.9.1",
|
|
79
79
|
"@vueuse/core": "^10.5.0",
|
|
80
80
|
"debug": "^4.3.4",
|
|
81
81
|
"ejs": "^3.1.9"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
|
|
4
4
|
import { StatefulLayout } from '@json-layout/core'
|
|
5
|
-
import { ref, shallowRef, getCurrentInstance, useSlots } from 'vue'
|
|
5
|
+
import { ref, shallowRef, getCurrentInstance, useSlots, computed } from 'vue'
|
|
6
6
|
import { useElementSize } from '@vueuse/core'
|
|
7
7
|
|
|
8
8
|
import { defaultOptions } from '<%- baseImport %>/components/options.js'
|
|
@@ -28,9 +28,9 @@ const props = defineProps({
|
|
|
28
28
|
default: null
|
|
29
29
|
},
|
|
30
30
|
options: {
|
|
31
|
-
/** @type import('vue').PropType<import('<%- baseImport %>/types.js').PartialVjsfOptions> */
|
|
31
|
+
/** @type import('vue').PropType<import('<%- baseImport %>/types.js').PartialVjsfOptions | null> */
|
|
32
32
|
type: Object,
|
|
33
|
-
|
|
33
|
+
default: null
|
|
34
34
|
}
|
|
35
35
|
})
|
|
36
36
|
|
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
/** @type import("../types.js").PartialVjsfOptions */
|
|
1
|
+
/** @type {import("../types.js").PartialVjsfOptions} */
|
|
2
2
|
export const defaultOptions = {
|
|
3
|
-
// matches the density prop found in many vuetify components
|
|
4
|
-
density: 'default',
|
|
5
|
-
titleDepth: 2,
|
|
6
|
-
fieldProps: {},
|
|
7
|
-
fieldPropsCompact: {
|
|
8
|
-
density: 'compact',
|
|
9
|
-
hideDetails: 'auto'
|
|
10
|
-
},
|
|
11
|
-
fieldPropsComfortable: {
|
|
12
|
-
density: 'comfortable'
|
|
13
|
-
},
|
|
14
|
-
fieldPropsReadOnly: { hideDetails: 'auto', variant: 'plain' },
|
|
15
|
-
fieldPropsSummary: { hideDetails: true },
|
|
16
|
-
textfieldProps: {},
|
|
17
|
-
textfieldPropsReadOnly: {},
|
|
18
|
-
textareaProps: {},
|
|
19
|
-
textareaPropsReadOnly: {},
|
|
20
|
-
// it is not very common to show an error below checkboxes and switches and without hide-details=auto they take a lot of space
|
|
21
|
-
checkboxProps: { hideDetails: 'auto' },
|
|
22
|
-
checkboxPropsReadOnly: {},
|
|
23
|
-
switchProps: { hideDetails: 'auto' },
|
|
24
|
-
switchPropsReadOnly: {},
|
|
25
3
|
errorAlertProps: { type: 'error', variant: 'tonal' },
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
nodeComponents: {},
|
|
5
|
+
plugins: {}
|
|
28
6
|
}
|
|
29
7
|
|
|
30
8
|
/**
|
|
31
9
|
*
|
|
32
|
-
* @param {Partial<import("../types.js").VjsfOptions>} options
|
|
10
|
+
* @param {Partial<import("../types.js").VjsfOptions> | null} options
|
|
33
11
|
* @param {any} form
|
|
34
12
|
* @param {number} width
|
|
35
13
|
* @param {import("vue").Slots} slots
|
|
@@ -41,10 +19,10 @@ export const getFullOptions = (options, form, width, slots, nodeComponents) => {
|
|
|
41
19
|
...defaultOptions,
|
|
42
20
|
readOnly: !!(form && (form.isDisabled.value || form.isReadonly.value)),
|
|
43
21
|
...options,
|
|
44
|
-
context: options
|
|
22
|
+
context: options?.context ? JSON.parse(JSON.stringify(options.context)) : {},
|
|
45
23
|
width: Math.round(width ?? 0),
|
|
46
24
|
vjsfSlots: { ...slots },
|
|
47
|
-
nodeComponents: { ...nodeComponents, ...options
|
|
25
|
+
nodeComponents: { ...nodeComponents, ...options?.nodeComponents }
|
|
48
26
|
}
|
|
49
27
|
return /** @type import('../types.js').VjsfOptions */ (fullOptions)
|
|
50
28
|
}
|
package/src/components/vjsf.vue
CHANGED
|
@@ -68,9 +68,9 @@ const props = defineProps({
|
|
|
68
68
|
default: null
|
|
69
69
|
},
|
|
70
70
|
options: {
|
|
71
|
-
/** @type import('vue').PropType<import('../types.js').PartialVjsfOptions> */
|
|
71
|
+
/** @type import('vue').PropType<import('../types.js').PartialVjsfOptions | null> */
|
|
72
72
|
type: Object,
|
|
73
|
-
|
|
73
|
+
default: null
|
|
74
74
|
}
|
|
75
75
|
})
|
|
76
76
|
|
|
@@ -18,7 +18,7 @@ export const emits = {
|
|
|
18
18
|
/**
|
|
19
19
|
* @param {import('vue').Ref<Object>} schema
|
|
20
20
|
* @param {import('vue').Ref<any>} modelValue
|
|
21
|
-
* @param {import('vue').Ref<import("../types.js").PartialVjsfOptions>} options
|
|
21
|
+
* @param {import('vue').Ref<import("../types.js").PartialVjsfOptions | null>} options
|
|
22
22
|
* @param {Record<string, import('vue').Component>} nodeComponents
|
|
23
23
|
* @param {any} emit
|
|
24
24
|
* @param {typeof import('@json-layout/core').compile} [compile]
|
package/src/styles/vjsf.css
CHANGED
package/src/types.ts
CHANGED
|
@@ -30,24 +30,9 @@ import {
|
|
|
30
30
|
export type Density = 'default' | 'comfortable' | 'compact'
|
|
31
31
|
|
|
32
32
|
export type VjsfStatefulLayoutOptions = StatefulLayoutOptions & {
|
|
33
|
-
density: Density,
|
|
34
|
-
fieldProps: Record<string, unknown>,
|
|
35
|
-
fieldPropsCompact: Record<string, unknown>,
|
|
36
|
-
fieldPropsComfortable: Record<string, unknown>,
|
|
37
|
-
fieldPropsReadOnly: Record<string, unknown>,
|
|
38
|
-
fieldPropsSummary: Record<string, unknown>,
|
|
39
|
-
textfieldProps: Record<string, unknown>,
|
|
40
|
-
textfieldPropsReadOnly: Record<string, unknown>,
|
|
41
|
-
textareaProps: Record<string, unknown>,
|
|
42
|
-
textareaPropsReadOnly: Record<string, unknown>,
|
|
43
|
-
checkboxProps: Record<string, unknown>,
|
|
44
|
-
checkboxPropsReadOnly: Record<string, unknown>,
|
|
45
|
-
switchProps: Record<string, unknown>,
|
|
46
|
-
switchPropsReadOnly: Record<string, unknown>,
|
|
47
|
-
errorAlertProps: Record<string, unknown>,
|
|
48
33
|
vjsfSlots: Record<string, () => unknown>,
|
|
49
|
-
easyMDEOptions: Record<string, unknown>,
|
|
50
34
|
nodeComponents: Record<string, Component>,
|
|
35
|
+
plugins: Record<string, unknown>
|
|
51
36
|
}
|
|
52
37
|
|
|
53
38
|
export type VjsfCompileOptions = CompileOptions & {
|
package/src/utils/props.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { camelize } from 'vue'
|
|
3
3
|
|
|
4
|
+
// NOTE: in a previous draft we used to have this in options,
|
|
5
|
+
// but it was not very flexible and not very easy to use, user defined props should be managed
|
|
6
|
+
// by a combination of layout.props, layout.getProps and vuetify defaults provider (https://vuetifyjs.com/en/components/defaults-providers/#usage)
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
fieldProps: {},
|
|
9
|
+
fieldPropsCompact: {
|
|
10
|
+
density: 'compact',
|
|
11
|
+
hideDetails: 'auto'
|
|
12
|
+
},
|
|
13
|
+
fieldPropsComfortable: {
|
|
14
|
+
density: 'comfortable'
|
|
15
|
+
},
|
|
16
|
+
fieldPropsReadOnly: { hideDetails: 'auto', variant: 'plain' },
|
|
17
|
+
fieldPropsSummary: { hideDetails: true },
|
|
18
|
+
textfieldProps: {},
|
|
19
|
+
textfieldPropsReadOnly: {},
|
|
20
|
+
textareaProps: {},
|
|
21
|
+
textareaPropsReadOnly: {},
|
|
22
|
+
// it is not very common to show an error below checkboxes and switches and without hide-details=auto they take a lot of space
|
|
23
|
+
checkboxProps: { hideDetails: 'auto' },
|
|
24
|
+
checkboxPropsReadOnly: {},
|
|
25
|
+
switchProps: { hideDetails: 'auto' },
|
|
26
|
+
switchPropsReadOnly: {}
|
|
27
|
+
}
|
|
28
|
+
|
|
4
29
|
/**
|
|
5
30
|
* @param {(Record<string, any> | undefined)[]} propsLevels
|
|
6
31
|
* @returns {Record<string, any> & {class: string[]}}
|
|
@@ -38,14 +63,14 @@ export function mergePropsLevels (propsLevels) {
|
|
|
38
63
|
export function getInputProps (node, statefulLayout, layoutPropsMap, isMainComp = true) {
|
|
39
64
|
const options = node.options
|
|
40
65
|
/** @type {(Record<string, any> | undefined)[]} */
|
|
41
|
-
const propsLevels = [
|
|
42
|
-
if (options.density === 'comfortable') propsLevels.push(
|
|
43
|
-
if (options.density === 'compact') propsLevels.push(
|
|
44
|
-
if (node.options.readOnly) propsLevels.push(
|
|
66
|
+
const propsLevels = [defaultProps.fieldProps]
|
|
67
|
+
if (options.density === 'comfortable') propsLevels.push(defaultProps.fieldPropsComfortable)
|
|
68
|
+
if (options.density === 'compact') propsLevels.push(defaultProps.fieldPropsCompact)
|
|
69
|
+
if (node.options.readOnly) propsLevels.push(defaultProps.fieldPropsReadOnly)
|
|
45
70
|
if (isMainComp) {
|
|
46
71
|
propsLevels.push(/** @type Record<string, any> | undefined */(options[`${node.layout.comp}Props`]))
|
|
47
72
|
if (node.options.readOnly) propsLevels.push(/** @type Record<string, any> | undefined */(options[`${node.layout.comp}PropsReadOnly`]))
|
|
48
|
-
propsLevels.push(node.
|
|
73
|
+
if (node.props) propsLevels.push(node.props)
|
|
49
74
|
}
|
|
50
75
|
|
|
51
76
|
const fullProps = mergePropsLevels(propsLevels)
|