@koumoul/vjsf 3.0.0-alpha.8 → 3.0.0-beta.0

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-alpha.8",
3
+ "version": "3.0.0-beta.0",
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.7.0",
78
+ "@json-layout/core": "0.9.0",
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
- required: true
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
- easyMDEOptions: {},
27
- nodeComponents: {}
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.context ? JSON.parse(JSON.stringify(options.context)) : {},
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.nodeComponents }
25
+ nodeComponents: { ...nodeComponents, ...options?.nodeComponents }
48
26
  }
49
27
  return /** @type import('../types.js').VjsfOptions */ (fullOptions)
50
28
  }
@@ -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
- required: true
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]
@@ -1,7 +1,3 @@
1
- .vjsf {
2
- overflow: hidden;
3
- }
4
-
5
1
  /* override vuetify styles to manage readOnly fields more usable than the default disabled fields */
6
2
  .vjsf-input--readonly.v-input--disabled.v-text-field .v-field--disabled input {
7
3
  pointer-events: auto;
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 & {
@@ -0,0 +1 @@
1
+ export { commonjsDeps } from '@json-layout/core/utils/build'
@@ -8,5 +8,6 @@ export const registeredNodeComponents = ref({})
8
8
  * @param {import('vue').Component} component
9
9
  */
10
10
  export function registerNodeComponent (name, component) {
11
+ console.log('vjsf - register plugin node component', name)
11
12
  registeredNodeComponents.value[name] = component
12
13
  }
@@ -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 = [options.fieldProps]
42
- if (options.density === 'comfortable') propsLevels.push(options.fieldPropsComfortable)
43
- if (options.density === 'compact') propsLevels.push(options.fieldPropsCompact)
44
- if (node.options.readOnly) propsLevels.push(options.fieldPropsReadOnly)
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.layout.props)
73
+ if (node.props) propsLevels.push(node.props)
49
74
  }
50
75
 
51
76
  const fullProps = mergePropsLevels(propsLevels)
@@ -0,0 +1,2 @@
1
+ export { commonjsDeps } from "@json-layout/core/utils/build";
2
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/utils/build.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"global-register.d.ts","sourceRoot":"","sources":["../../src/utils/global-register.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH,4CAHW,MAAM,aACN,OAAO,KAAK,EAAE,SAAS,QAIjC;AATD,yEAAyE;AACzE,uCADW,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,MAAM,EAAE,OAAO,KAAK,EAAE,SAAS,CAAC,CAAC,CACtB"}
1
+ {"version":3,"file":"global-register.d.ts","sourceRoot":"","sources":["../../src/utils/global-register.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH,4CAHW,MAAM,aACN,OAAO,KAAK,EAAE,SAAS,QAKjC;AAVD,yEAAyE;AACzE,uCADW,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,MAAM,EAAE,OAAO,KAAK,EAAE,SAAS,CAAC,CAAC,CACtB"}