@koumoul/vjsf 3.0.0-alpha.2 → 3.0.0-alpha.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": "@koumoul/vjsf",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.3",
4
4
  "description": "Generate forms for the vuetify UI library (vuejs) based on annotated JSON schemas.",
5
5
  "scripts": {
6
6
  "test": "vitest",
@@ -52,7 +52,7 @@
52
52
  "vuetify": "^3.4.2"
53
53
  },
54
54
  "dependencies": {
55
- "@json-layout/core": "0.3.0",
55
+ "@json-layout/core": "0.4.0",
56
56
  "@vueuse/core": "^10.5.0",
57
57
  "debug": "^4.3.4",
58
58
  "easymde": "^2.18.0",
package/src/compat/v2.js CHANGED
@@ -1,14 +1,11 @@
1
1
  import ajvModule from 'ajv'
2
- import rfdc from 'rfdc'
3
2
  import addFormats from 'ajv-formats'
4
- import { resolveRefs } from '@json-layout/core'
3
+ import { resolveRefs, clone } from '@json-layout/core'
5
4
  import { isPartialGetItemsObj } from '@json-layout/vocabulary'
6
5
 
7
6
  // @ts-ignore
8
7
  const Ajv = /** @type {typeof ajvModule.default} */ (ajvModule)
9
8
 
10
- const clone = rfdc()
11
-
12
9
  const processFragment = (/** @type {import("ajv").SchemaObject} */schema) => {
13
10
  if (!schema.layout) {
14
11
  /** @type import('@json-layout/vocabulary').PartialCompObject */
@@ -30,7 +30,7 @@ const { el, statefulLayout, stateTree } = useVjsf(
30
30
  computed(() => props.options),
31
31
  emit,
32
32
  null,
33
- compiledLayout
33
+ computed(() => compiledLayout)
34
34
  )
35
35
  </script>
36
36
 
@@ -1,9 +1,8 @@
1
1
  <script setup>
2
2
  import { watch, computed, ref } from 'vue'
3
3
  import { VList, VListItem, VListItemAction, VBtn, VMenu, VIcon } from 'vuetify/components'
4
- import { isSection } from '@json-layout/core'
4
+ import { isSection, clone } from '@json-layout/core'
5
5
  import Node from '../node.vue'
6
- import clone from '../../utils/clone.js'
7
6
  import { moveArrayItem } from '../../utils/arrays.js'
8
7
  import useDnd from '../../composables/use-dnd.js'
9
8
 
@@ -3,8 +3,7 @@ import { defineComponent, h, computed, onMounted, ref, onUnmounted, watch } from
3
3
  import { VInput, VLabel } from 'vuetify/components'
4
4
  import { getInputProps } from '../../utils/props.js'
5
5
  import { getCompSlots } from '../../utils/slots.js'
6
- // import 'easymde/dist/easymde.min.css'
7
- // import EasyMDE from 'easymde'
6
+ import 'easymde/dist/easymde.min.css'
8
7
 
9
8
  export default defineComponent({
10
9
  props: {
@@ -29,7 +28,7 @@ export default defineComponent({
29
28
  fieldSlots.default = () => [
30
29
  h('div', { style: 'width:100%' }, [
31
30
  h(VLabel, { text: fieldProps.value.label }),
32
- h('textarea', { ref: element })
31
+ h('textarea', { ref: element, style: 'display:none' })
33
32
  ])
34
33
  ]
35
34
  return fieldSlots
@@ -41,8 +40,6 @@ export default defineComponent({
41
40
  const initEasyMDE = async () => {
42
41
  if (!element.value) throw new Error('component was not mounted for markdown editor')
43
42
 
44
- // @ts-ignore
45
- await import('easymde/dist/easymde.min.css')
46
43
  const EasyMDE = (await import('easymde')).default
47
44
 
48
45
  const messages = props.modelValue.messages
@@ -187,6 +184,10 @@ export default defineComponent({
187
184
  easymde.codemirror.on('focus', () => {
188
185
  if (blurTimeout) clearTimeout(blurTimeout)
189
186
  })
187
+
188
+ if (props.modelValue.autofocus) {
189
+ easymde.codemirror.focus()
190
+ }
190
191
  }
191
192
 
192
193
  onMounted(initEasyMDE)
@@ -203,8 +204,16 @@ export default defineComponent({
203
204
  })
204
205
 
205
206
  // update easymde config from outside
206
- watch(() => [props.modelValue.messages, props.modelValue.options.easyMDEOptions], () => {
207
- initEasyMDE()
207
+ watch(() => [props.modelValue.messages, props.modelValue.options.easyMDEOptions], (newValues, oldValues) => {
208
+ if (newValues[0] !== oldValues[0] || newValues[1] !== oldValues[1]) {
209
+ initEasyMDE()
210
+ }
211
+ })
212
+
213
+ props.statefulLayout.events.on('autofocus', () => {
214
+ if (props.modelValue.autofocus && easymde) {
215
+ easymde.codemirror.focus()
216
+ }
208
217
  })
209
218
 
210
219
  return () => h(VInput, fieldProps.value, fieldSlots.value)
@@ -88,7 +88,7 @@ const { el, statefulLayout, stateTree } = useVjsf(
88
88
  computed(() => props.options),
89
89
  emit,
90
90
  compile,
91
- props.precompiledLayout
91
+ computed(() => props.precompiledLayout)
92
92
  )
93
93
 
94
94
  </script>
@@ -19,8 +19,8 @@ export const emits = {
19
19
  * @param {import('vue').Ref<any>} modelValue
20
20
  * @param {import('vue').Ref<import("../components/types.js").PartialVjsfOptions>} options
21
21
  * @param {any} emit
22
- * @param {typeof import('@json-layout/core').compile} compile
23
- * @param {import('@json-layout/core').CompiledLayout} [precompiledLayout]
22
+ * @param {typeof import('@json-layout/core').compile} [compile]
23
+ * @param {import('vue').Ref<import('@json-layout/core').CompiledLayout>} [precompiledLayout]
24
24
  */
25
25
  export const useVjsf = (schema, modelValue, options, emit, compile, precompiledLayout) => {
26
26
  const el = ref(null)
@@ -50,7 +50,8 @@ export const useVjsf = (schema, modelValue, options, emit, compile, precompiledL
50
50
  const fullOptions = computed(() => getFullOptions(options.value, form, width.value, slots))
51
51
 
52
52
  const compiledLayout = computed(() => {
53
- if (precompiledLayout) return precompiledLayout
53
+ if (precompiledLayout?.value) return precompiledLayout?.value
54
+ if (!compile) throw new Error('compile function is not available')
54
55
  const compiledLayout = compile(schema.value, fullOptions.value)
55
56
  return compiledLayout
56
57
  })
@@ -87,13 +88,16 @@ export const useVjsf = (schema, modelValue, options, emit, compile, precompiledL
87
88
  // @ts-ignore
88
89
  const autofocusNodeElement = el.value.querySelector('.vjsf-input--autofocus')
89
90
  if (autofocusNodeElement) {
90
- const autofocusInputElement = autofocusNodeElement.querySelector('input')
91
+ const autofocusInputElement = autofocusNodeElement.querySelector('input') ?? autofocusNodeElement.querySelector('textarea:not([style*="display: none"]')
91
92
  if (autofocusInputElement) autofocusInputElement.focus()
92
93
  }
93
94
  })
94
95
  }
95
96
 
96
97
  watch(fullOptions, (newOptions) => {
98
+ // in case of runtime compilation the watch on compiledLayout will be triggered
99
+ if (!precompiledLayout) return
100
+
97
101
  if (statefulLayout.value) {
98
102
  statefulLayout.value.options = newOptions
99
103
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../src/compat/v2.js"],"names":[],"mappings":"AAiGA;;;;;;GAMG;AACH,kCALW,MAAM,+CAEN,MAAM,0BAkBhB;sBAvHqB,KAAK"}
1
+ {"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../src/compat/v2.js"],"names":[],"mappings":"AA8FA;;;;;;GAMG;AACH,kCALW,MAAM,+CAEN,MAAM,0BAkBhB;sBApHqB,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.vue.d.ts","sourceRoot":"","sources":["../../../src/components/nodes/markdown.vue.js"],"names":[],"mappings":";;QAYM,2EAA2E;cAAjE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,aAAa,EAAE,gBAAgB,CAAC;;;;QAKxE,+EAA+E;cAArE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,mBAAmB,EAAE,cAAc,CAAC;;;;;;;QAL5E,2EAA2E;cAAjE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,aAAa,EAAE,gBAAgB,CAAC;;;;QAKxE,+EAA+E;cAArE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,mBAAmB,EAAE,cAAc,CAAC"}
1
+ {"version":3,"file":"markdown.vue.d.ts","sourceRoot":"","sources":["../../../src/components/nodes/markdown.vue.js"],"names":[],"mappings":";;QAWM,2EAA2E;cAAjE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,aAAa,EAAE,gBAAgB,CAAC;;;;QAKxE,+EAA+E;cAArE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,mBAAmB,EAAE,cAAc,CAAC;;;;;;;QAL5E,2EAA2E;cAAjE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,aAAa,EAAE,gBAAgB,CAAC;;;;QAKxE,+EAA+E;cAArE,OAAO,KAAK,EAAE,QAAQ,CAAC,OAAO,mBAAmB,EAAE,cAAc,CAAC"}
@@ -1,12 +1,12 @@
1
1
  declare const _default: import("vue").DefineComponent<{}, {
2
2
  $emit: ((event: "update:modelValue", data: any) => void) & ((event: "update:state", state: import("@json-layout/core").StatefulLayout) => void);
3
- modelValue: any;
4
3
  options: Partial<Omit<import("./types.js").VjsfOptions, "width">>;
4
+ modelValue: any;
5
5
  schema: Record<string, any>;
6
6
  precompiledLayout: import("../../../node_modules/@json-layout/core/types/compile/types.js").CompiledLayout;
7
7
  $props: {
8
- readonly modelValue?: any;
9
8
  readonly options?: Partial<Omit<import("./types.js").VjsfOptions, "width">> | undefined;
9
+ readonly modelValue?: any;
10
10
  readonly schema?: Record<string, any> | undefined;
11
11
  readonly precompiledLayout?: import("../../../node_modules/@json-layout/core/types/compile/types.js").CompiledLayout | undefined;
12
12
  };
@@ -8,7 +8,7 @@ export const emits: {
8
8
  */
9
9
  'update:state': (state: StatefulLayout) => boolean;
10
10
  };
11
- export function useVjsf(schema: import('vue').Ref<Object>, modelValue: import('vue').Ref<any>, options: import('vue').Ref<import("../components/types.js").PartialVjsfOptions>, emit: any, compile: typeof import('@json-layout/core').compile, precompiledLayout?: import("../../../node_modules/@json-layout/core/types/compile/types.js").CompiledLayout | undefined): {
11
+ export function useVjsf(schema: import('vue').Ref<Object>, modelValue: import('vue').Ref<any>, options: import('vue').Ref<import("../components/types.js").PartialVjsfOptions>, emit: any, compile?: typeof import("@json-layout/core").compile | undefined, precompiledLayout?: import("vue").Ref<import("../../../node_modules/@json-layout/core/types/compile/types.js").CompiledLayout> | undefined): {
12
12
  el: import("vue").Ref<null>;
13
13
  statefulLayout: import("vue").ShallowRef<StatefulLayout | null>;
14
14
  stateTree: import("vue").ShallowRef<import("../../../node_modules/@json-layout/core/types/state/types.js").StateTree | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"use-vjsf.d.ts","sourceRoot":"","sources":["../../src/composables/use-vjsf.js"],"names":[],"mappings":"AAKA;IACE;;MAEE;gCADO,GAAG;IAGZ;;MAEE;4BADO,cAAc;EAGxB;AAUM,gCAPI,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,cACzB,OAAO,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,WACtB,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,wBAAwB,EAAE,kBAAkB,CAAC,QACtE,GAAG,WACH,cAAc,mBAAmB,EAAE,OAAO;;;;EA6FpD;+BAlH8B,mBAAmB"}
1
+ {"version":3,"file":"use-vjsf.d.ts","sourceRoot":"","sources":["../../src/composables/use-vjsf.js"],"names":[],"mappings":"AAKA;IACE;;MAEE;gCADO,GAAG;IAGZ;;MAEE;4BADO,cAAc;EAGxB;AAUM,gCAPI,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,cACzB,OAAO,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,WACtB,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,wBAAwB,EAAE,kBAAkB,CAAC,QACtE,GAAG;;;;EAkGb;+BAtH8B,mBAAmB"}
@@ -1,3 +0,0 @@
1
- import rfdc from 'rfdc'
2
-
3
- export default rfdc()