@live-change/frontend-auto-form 0.2.8 → 0.2.9

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
@@ -11,7 +11,8 @@
11
11
  </div>
12
12
  <auto-input :modelValue="value" :definition="definition.of"
13
13
  @update:modelValue="value => updateItem(index, value)"
14
- :rootValue="props.rootValue" :propName="props.propName + '.' + index" />
14
+ :rootValue="props.rootValue" :propName="props.propName + '.' + index"
15
+ :i18n="i18n" />
15
16
  </div>
16
17
  <div>
17
18
  <Button label="Add item" icon="pi pi-plus" @click="insertItem" />
@@ -45,6 +46,10 @@
45
46
  type: String,
46
47
  default: ''
47
48
  },
49
+ i18n: {
50
+ type: String,
51
+ default: ''
52
+ }
48
53
  })
49
54
 
50
55
  const emit = defineEmits(['update:modelValue'])
package/AutoEditor.vue CHANGED
@@ -6,6 +6,7 @@
6
6
  :definition="definition.properties[property]"
7
7
  :label="property"
8
8
  :rootValue="props.rootValue" :propName="(propName ? propName + '.' : '') + property"
9
+ :i18n="i18n"
9
10
  class="col-12" />
10
11
  </div>
11
12
  </template>
@@ -28,10 +29,14 @@
28
29
  propName: {
29
30
  type: String,
30
31
  default: ''
32
+ },
33
+ i18n: {
34
+ type: String,
35
+ default: ''
31
36
  }
32
37
  })
33
38
 
34
- const { modelValue, definition } = toRefs(props)
39
+ const { modelValue, definition, propName } = toRefs(props)
35
40
 
36
41
  const emit = defineEmits(['update:modelValue'])
37
42
 
package/AutoField.vue CHANGED
@@ -1,16 +1,19 @@
1
1
  <template>
2
2
  <component v-if="fieldComponent && visible" :is="fieldComponent" v-bind="attributes"
3
- @update:modelValue="value => emit('update:modelValue', value)" />
3
+ @update:modelValue="value => emit('update:modelValue', value)" :i18n="i18n" />
4
4
  <div v-else-if="visible" class="field" :class="fieldClass" :style="fieldStyle">
5
- <label :for="uid">{{ label }}</label>
5
+ <label :for="uid">{{ t( label ) }}</label>
6
6
  <slot>
7
7
  <auto-input :modelValue="modelValue" :definition="definition"
8
8
  :class="props.inputClass" :style="props.inputStyle"
9
9
  :attributes="props.inputAttributes"
10
+ :propName="props.propName"
11
+ :rootValue="props.rootValue"
10
12
  @update:modelValue="value => emit('update:modelValue', value)"
11
- :id="uid" />
13
+ :id="uid"
14
+ :i18n="i18n" />
12
15
  </slot>
13
- <small v-if="validationResult" class="p-error">{{ validationResult }}</small>
16
+ <small v-if="validationResult" class="p-error">{{ t( 'errors.' + validationResult ) }}</small>
14
17
  </div>
15
18
  </template>
16
19
 
@@ -22,6 +25,9 @@
22
25
  import { computed, getCurrentInstance } from 'vue'
23
26
  import { toRefs } from '@vueuse/core'
24
27
 
28
+ import { useI18n } from 'vue-i18n'
29
+ const { t } = useI18n()
30
+
25
31
  const props = defineProps({
26
32
  modelValue: {},
27
33
  error: {
@@ -55,6 +61,10 @@
55
61
  propName: {
56
62
  type: String,
57
63
  default: ''
64
+ },
65
+ i18n: {
66
+ type: String,
67
+ default: ''
58
68
  }
59
69
  })
60
70
 
@@ -99,7 +109,7 @@
99
109
  return inputs.default
100
110
  })
101
111
 
102
- const label = computed(() => props.label || definition.value.label || props.name)
112
+ const label = computed(() => props.i18n + (props.label || definition.value.label || props.name))
103
113
 
104
114
  const fieldClass = computed(() => [inputConfig.value?.fieldClass, definition.value?.fieldClass, props.class, {
105
115
  'p-invalid': !!error.value
package/AutoInput.vue CHANGED
@@ -31,12 +31,16 @@
31
31
  propName: {
32
32
  type: String,
33
33
  default: ''
34
+ },
35
+ i18n: {
36
+ type: String,
37
+ default: ''
34
38
  }
35
39
  })
36
40
 
37
41
  const emit = defineEmits(['update:modelValue'])
38
42
 
39
- const { definition, modelValue } = toRefs(props)
43
+ const { definition, modelValue, propName } = toRefs(props)
40
44
 
41
45
  const inputConfig = computed(() => {
42
46
  if(definition.value.input) return inputs[definition.value.input]
@@ -56,6 +60,7 @@
56
60
  const visible = computed(() => {
57
61
  if(!definition.value) return false
58
62
  if(definitionIf.value) {
63
+ console.log("DIF", propName.value, definitionIf.value, 'IN', props.rootValue)
59
64
  return definitionIf.value({
60
65
  source: definition.value,
61
66
  props: props.rootValue,
@@ -65,10 +70,24 @@
65
70
  return true
66
71
  })
67
72
 
73
+ import { useI18n } from 'vue-i18n'
74
+ const { t, d, n } = useI18n()
75
+
68
76
  const configAttributes = computed(() => {
69
77
  const attributes = inputConfig.value?.attributes
70
78
  if(!attributes) return attributes
71
- if(typeof attributes == 'function') return attributes(definition.value)
79
+ if(typeof attributes == 'function') {
80
+ const fieldName = props.propName.split('.').pop()
81
+ console.log("PROPS", JSON.stringify(props))
82
+ console.log("PROPNAME", propName.value)
83
+ return attributes({
84
+ definition: definition.value,
85
+ i18n: props.i18n + fieldName,
86
+ propName: props.propName,
87
+ fieldName,
88
+ t, d, n
89
+ })
90
+ }
72
91
  return attributes
73
92
  })
74
93
 
@@ -79,7 +98,8 @@
79
98
  modelValue: modelValue.value,
80
99
  definition: definition.value,
81
100
  rootValue: props.rootValue,
82
- propName: props.propName
101
+ propName: props.propName,
102
+ i18n: props.i18n
83
103
  }))
84
104
 
85
105
  const inputClass = computed(() => [inputConfig.value?.inputClass, definition.value?.inputClass, props.class])
package/GroupField.vue CHANGED
@@ -1,11 +1,12 @@
1
1
  <template>
2
2
  <div v-if="visible" class="pl-3 border-left-3 border-400 mb-3" :class="fieldClass" :style="fieldStyle">
3
- <h3>{{ label }}:</h3>
3
+ <h3>{{ t( i18n + label + ':title' ) }}</h3>
4
4
  <auto-input :modelValue="modelValue" :definition="definition" :name="props.name"
5
5
  :class="props.inputClass" :style="props.inputStyle"
6
6
  :properties="props.inputAttributes"
7
7
  :rootValue="props.rootValue" :propName="props.propName"
8
- @update:modelValue="value => emit('update:modelValue', value)" />
8
+ @update:modelValue="value => emit('update:modelValue', value)"
9
+ :i18n="props.i18n + props.propName.split('.').pop() + '.'" />
9
10
  </div>
10
11
  </template>
11
12
 
@@ -15,6 +16,9 @@
15
16
  import { computed, inject } from 'vue'
16
17
  import { toRefs } from '@vueuse/core'
17
18
 
19
+ import { useI18n } from 'vue-i18n'
20
+ const { t } = useI18n()
21
+
18
22
  const props = defineProps({
19
23
  modelValue: {},
20
24
  error: {
@@ -48,6 +52,10 @@
48
52
  propName: {
49
53
  type: String,
50
54
  default: ''
55
+ },
56
+ i18n: {
57
+ type: String,
58
+ default: ''
51
59
  }
52
60
  })
53
61
 
package/config.js CHANGED
@@ -35,7 +35,14 @@ types.Array = inputs.list = input(() => import('./ArrayInput.vue'), {
35
35
  types.Date = inputs.datetime = input(() => import('primevue/calendar'), { attributes: { showTime: true } })
36
36
 
37
37
  inputs.select = input(() => import('primevue/dropdown'), {
38
- attributes: (definition) => ({ options: definition.options })
38
+ attributes: (config) => {
39
+ const { definition, i18n, t } = config
40
+ console.log("SELECT", config)
41
+ return {
42
+ options: definition.options,
43
+ optionLabel: option => t(i18n + ':options.' + option)
44
+ }
45
+ }
39
46
  })
40
47
 
41
48
  inputs.duration = input(() => import('primevue/inputmask'), {
package/index.js CHANGED
@@ -6,3 +6,7 @@ export { AutoInput, AutoField, AutoEditor }
6
6
 
7
7
  import * as inputConfig from './config.js'
8
8
  export { inputConfig }
9
+
10
+ import en from "./locales/en.json"
11
+ const locales = { en }
12
+ export { locales }
@@ -0,0 +1,5 @@
1
+ {
2
+ "errors": {
3
+ "empty": "This field is required."
4
+ }
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/frontend-auto-form",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
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",
@@ -20,7 +20,7 @@
20
20
  "debug": "node --inspect-brk server"
21
21
  },
22
22
  "dependencies": {
23
- "@fortawesome/fontawesome-free": "^6.1.1",
23
+ "@fortawesome/fontawesome-free": "^6.2.0",
24
24
  "@live-change/cli": "0.7.4",
25
25
  "@live-change/dao": "0.5.8",
26
26
  "@live-change/dao-vue3": "0.5.8",
@@ -66,5 +66,5 @@
66
66
  "author": "",
67
67
  "license": "ISC",
68
68
  "description": "",
69
- "gitHead": "72bd46680370e7804b168fec5dde28de205487e0"
69
+ "gitHead": "703c9723562ade7b2420e1b25b28ced51a96db09"
70
70
  }