@live-change/frontend-auto-form 0.3.1 → 0.3.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/ArrayInput.vue CHANGED
@@ -15,18 +15,20 @@
15
15
  :i18n="i18n" />
16
16
  </div>
17
17
  <div>
18
- <Button label="Add item" icon="pi pi-plus" @click="insertItem" />
18
+ <Button class="w-10rem" :label="t('autoform.addItem')" icon="pi pi-plus" @click="insertItem" />
19
19
  </div>
20
20
  </div>
21
21
  </template>
22
22
 
23
23
  <script setup>
24
+ import { useI18n } from 'vue-i18n'
25
+ const { t, n, d } = useI18n()
26
+
24
27
  import Button from "primevue/button";
25
28
  import AutoInput from "./AutoInput.vue"
26
29
 
27
30
  import { inputs, types } from './config.js'
28
- import { computed, getCurrentInstance } from 'vue'
29
- import { toRefs } from '@vueuse/core'
31
+ import { computed, getCurrentInstance, toRefs } from 'vue'
30
32
 
31
33
  const props = defineProps({
32
34
  modelValue: {
package/AutoEditor.vue CHANGED
@@ -14,8 +14,7 @@
14
14
  <script setup>
15
15
  import AutoField from "./AutoField.vue"
16
16
 
17
- import { computed, inject, getCurrentInstance } from 'vue'
18
- import { toRefs } from '@vueuse/core'
17
+ import { computed, inject, getCurrentInstance, toRefs } from 'vue'
19
18
 
20
19
  const props = defineProps({
21
20
  modelValue: {},
@@ -46,7 +45,7 @@
46
45
  function updateModelProperty(property, value) {
47
46
  const data = modelValue.value || {}
48
47
  data[property] = value
49
- console.log("UPDATE MODEL", data)
48
+ //console.log("UPDATE MODEL", data)
50
49
  emit('update:modelValue', data)
51
50
  }
52
51
 
package/AutoField.vue CHANGED
@@ -22,11 +22,10 @@
22
22
  import AutoInput from "./AutoInput.vue"
23
23
 
24
24
  import { inputs, types } from './config.js'
25
- import { computed, getCurrentInstance } from 'vue'
26
- import { toRefs } from '@vueuse/core'
25
+ import { computed, getCurrentInstance, inject, toRefs } from 'vue'
27
26
 
28
27
  import { useI18n } from 'vue-i18n'
29
- const { t } = useI18n()
28
+ const { t, rt } = useI18n()
30
29
 
31
30
  const props = defineProps({
32
31
  modelValue: {},
@@ -96,17 +95,21 @@
96
95
  })
97
96
 
98
97
  import { validateData } from "@live-change/vue3-components"
99
-
98
+ const appContext = getCurrentInstance().appContext
100
99
  const validationResult = computed(() => {
101
- const validationResult = validateData(definition.value, modelValue.value, 'validation')
102
- const softValidationResult = validateData(definition.value, modelValue.value, 'softValidation')
100
+ const validationResult = validateData(definition.value, modelValue.value, 'validation', appContext)
101
+ const softValidationResult = validateData(definition.value, modelValue.value, 'softValidation', appContext)
103
102
  return validationResult || softValidationResult || error.value
104
103
  })
105
104
 
105
+ const config = inject('auto-form', {
106
+ inputs: {},
107
+ types: {}
108
+ })
106
109
  const inputConfig = computed(() => {
107
- if(definition.value.input) return inputs[definition.value.input]
108
- if(definition.value.type) return types[definition.value.type]
109
- return inputs.default
110
+ if(definition.value.input) return config.inputs?.[definition.value.input] ?? inputs[definition.value.input]
111
+ if(definition.value.type) return config.types?.[definition.value.type] ?? types[definition.value.type]
112
+ return config.inputs?.default ?? inputs.default
110
113
  })
111
114
 
112
115
  const label = computed(() => props.i18n + (props.label || definition.value.label || props.name))
package/AutoInput.vue CHANGED
@@ -3,14 +3,14 @@
3
3
  @update:modelValue="updateValue" :class="inputClass" :style="inputStyle" />
4
4
  <div v-else-if="visible" class="font-bold text-red-600">
5
5
  No input found for definition:
6
- <pre style="white-space: pre-wrap; word-wrap: break-word;">{{ JSON.stringify(definition, null, " ") }}</pre>
6
+ <pre style="white-space: pre-wrap; word-wrap: break-word;"
7
+ >{{propName}}: {{ JSON.stringify(definition, null, " ") }}</pre>
7
8
  </div>
8
9
  </template>
9
10
 
10
11
  <script setup>
11
12
  import { inputs, types } from './config.js'
12
- import { computed, inject } from 'vue'
13
- import { toRefs } from '@vueuse/core'
13
+ import { computed, inject, toRefs } from 'vue'
14
14
 
15
15
  const props = defineProps({
16
16
  modelValue: {
@@ -42,10 +42,14 @@
42
42
 
43
43
  const { definition, modelValue, propName } = toRefs(props)
44
44
 
45
+ const config = inject('auto-form', {
46
+ inputs: {},
47
+ types: {}
48
+ })
45
49
  const inputConfig = computed(() => {
46
- if(definition.value.input) return inputs[definition.value.input]
47
- if(definition.value.type) return types[definition.value.type]
48
- return inputs.default
50
+ if(definition.value.input) return config.inputs?.[definition.value.input] ?? inputs[definition.value.input]
51
+ if(definition.value.type) return config.types?.[definition.value.type] ?? types[definition.value.type]
52
+ return config.inputs?.default ?? inputs.default
49
53
  })
50
54
 
51
55
  const definitionIf = computed(() => {
@@ -60,7 +64,7 @@
60
64
  const visible = computed(() => {
61
65
  if(!definition.value) return false
62
66
  if(definitionIf.value) {
63
- console.log("DIF", propName.value, definitionIf.value, 'IN', props.rootValue)
67
+ //console.log("DIF", propName.value, definitionIf.value, 'IN', props.rootValue)
64
68
  return definitionIf.value({
65
69
  source: definition.value,
66
70
  props: props.rootValue,
@@ -71,21 +75,22 @@
71
75
  })
72
76
 
73
77
  import { useI18n } from 'vue-i18n'
74
- const { t, d, n } = useI18n()
78
+ const { rt, t, d, n, te } = useI18n()
75
79
 
76
80
  const configAttributes = computed(() => {
77
81
  const attributes = inputConfig.value?.attributes
78
82
  if(!attributes) return attributes
79
83
  if(typeof attributes == 'function') {
80
84
  const fieldName = props.propName.split('.').pop()
81
- console.log("PROPS", JSON.stringify(props))
82
- console.log("PROPNAME", propName.value)
85
+ //console.log("PROPS", JSON.stringify(props))
86
+ //console.log("PROPNAME", propName.value)
83
87
  return attributes({
84
88
  definition: definition.value,
85
89
  i18n: props.i18n + fieldName,
86
90
  propName: props.propName,
87
91
  fieldName,
88
- t, d, n
92
+ rootValue: props.rootValue,
93
+ t, d, n, rt, te
89
94
  })
90
95
  }
91
96
  return attributes
package/GroupField.vue CHANGED
@@ -7,14 +7,14 @@
7
7
  :rootValue="props.rootValue" :propName="props.propName"
8
8
  @update:modelValue="value => emit('update:modelValue', value)"
9
9
  :i18n="props.i18n + props.propName.split('.').pop() + '.'" />
10
+ <small v-if="typeof validationResult == 'string'" class="p-error">{{ t( 'errors.' + validationResult ) }}</small>
10
11
  </div>
11
12
  </template>
12
13
 
13
14
  <script setup>
14
15
  import AutoInput from "./AutoInput.vue"
15
- import {inputs, types} from "./config";
16
- import { computed, inject } from 'vue'
17
- import { toRefs } from '@vueuse/core'
16
+ import { inputs, types } from "./config";
17
+ import { computed, inject, toRefs, getCurrentInstance } from 'vue'
18
18
 
19
19
  import { useI18n } from 'vue-i18n'
20
20
  const { t } = useI18n()
@@ -90,6 +90,18 @@
90
90
  return inputs.default
91
91
  })
92
92
 
93
+ import { validateData } from "@live-change/vue3-components"
94
+
95
+ const appContext = getCurrentInstance().appContext
96
+
97
+ const validationResult = computed(() => {
98
+ console.log('validation', definition.value, modelValue.value)
99
+ const validationResult = validateData(definition.value, modelValue.value, 'validation', appContext)
100
+ const softValidationResult = validateData(definition.value, modelValue.value, 'softValidation', appContext)
101
+ console.log('validationResult', validationResult, softValidationResult, error.value)
102
+ return validationResult || softValidationResult || error.value
103
+ })
104
+
93
105
  const label = computed(() => props.label || definition.value?.label || props.name)
94
106
 
95
107
  const fieldClass = computed(() => [inputConfig.value?.fieldClass, definition.value?.fieldClass, props.class, {
package/config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineAsyncComponent } from 'vue'
2
2
 
3
+
3
4
  export const inputs = {
4
5
  }
5
6
  export const types = {
@@ -36,11 +37,30 @@ types.Date = inputs.datetime = input(() => import('primevue/calendar'), { attrib
36
37
 
37
38
  inputs.select = input(() => import('primevue/dropdown'), {
38
39
  attributes: (config) => {
39
- const { definition, i18n, t } = config
40
- console.log("SELECT", config)
40
+ const { definition, i18n, t, te } = config
41
+ // console.log("SELECT", config)
41
42
  return {
42
43
  options: definition.options,
43
- optionLabel: option => t(i18n + ':options.' + option)
44
+ optionLabel: option => {
45
+ const i18nId = i18n + ':options.' + option
46
+ if(te(i18nId)) return t(i18nId)
47
+ return t(option)
48
+ }
49
+ }
50
+ }
51
+ })
52
+
53
+ inputs.multiselect = input(() => import('primevue/multiselect'), {
54
+ attributes: (config) => {
55
+ const { definition, i18n, t, te } = config
56
+ console.log("MULTISELECT", config)
57
+ return {
58
+ options: definition.of.options ?? definition.options,
59
+ optionLabel: option => {
60
+ const i18nId = i18n + ':options.' + option
61
+ if(te(i18nId)) return t(i18nId)
62
+ return t(option)
63
+ }
44
64
  }
45
65
  }
46
66
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/frontend-auto-form",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "scripts": {
5
5
  "memDev": "lcli memDev --enableSessions --initScript ./init.js --dbAccess",
6
6
  "localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
@@ -21,15 +21,15 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@fortawesome/fontawesome-free": "^6.4.2",
24
- "@live-change/cli": "0.7.32",
25
- "@live-change/dao": "0.5.21",
26
- "@live-change/dao-vue3": "0.5.21",
27
- "@live-change/dao-websocket": "0.5.21",
28
- "@live-change/framework": "0.7.32",
29
- "@live-change/image-service": "0.3.30",
30
- "@live-change/session-service": "0.3.30",
31
- "@live-change/vue3-components": "0.2.29",
32
- "@live-change/vue3-ssr": "0.2.29",
24
+ "@live-change/cli": "0.7.34",
25
+ "@live-change/dao": "0.5.22",
26
+ "@live-change/dao-vue3": "0.5.22",
27
+ "@live-change/dao-websocket": "0.5.22",
28
+ "@live-change/framework": "0.7.34",
29
+ "@live-change/image-service": "0.3.32",
30
+ "@live-change/session-service": "0.3.32",
31
+ "@live-change/vue3-components": "0.2.30",
32
+ "@live-change/vue3-ssr": "0.2.30",
33
33
  "@vueuse/core": "^10.4.1",
34
34
  "codeceptjs-assert": "^0.0.5",
35
35
  "compression": "^1.7.4",
@@ -50,7 +50,7 @@
50
50
  "vue3-scroll-border": "0.1.5"
51
51
  },
52
52
  "devDependencies": {
53
- "@live-change/codeceptjs-helper": "0.7.32",
53
+ "@live-change/codeceptjs-helper": "0.7.34",
54
54
  "@wdio/selenium-standalone-service": "^8.15.0",
55
55
  "codeceptjs": "^3.5.4",
56
56
  "generate-password": "1.7.0",
@@ -62,5 +62,5 @@
62
62
  "author": "",
63
63
  "license": "ISC",
64
64
  "description": "",
65
- "gitHead": "5e3d6a0e0a8b9ab07d430d3a72ecc719be660738"
65
+ "gitHead": "dff1aa7df92ffd7c5b63c12ef4d1b4dadefe3a06"
66
66
  }