@live-change/frontend-auto-form 0.9.12 → 0.9.13

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.
@@ -1,10 +1,14 @@
1
1
  <template>
2
2
  <div>
3
- <h4>identifiers</h4>
4
- <pre>{{ identifiers }}</pre>
5
3
 
6
- <h4>definition</h4>
7
- <pre>{{ modelDefinition }}</pre>
4
+ <!-- <h4>identifiers</h4>
5
+ <pre>{{ identifiers }}</pre>
6
+
7
+ <h4>definition</h4>
8
+ <pre>{{ modelDefinition }}</pre>
9
+
10
+ <h4>object</h4>
11
+ <pre>{{ object }}</pre>-->
8
12
 
9
13
  <div class="">
10
14
  Service <strong>{{ service }}</strong>
@@ -19,11 +23,15 @@
19
23
  />
20
24
  </div>
21
25
 
26
+ <AutoView :value="object" :root-value="object" :i18n="i18n" :attributes="attributes"
27
+ :definition="modelDefinition" />
28
+
22
29
  </div>
23
30
  </template>
24
31
 
25
32
  <script setup>
26
33
 
34
+ import AutoView from '../view/AutoView.vue'
27
35
 
28
36
  import { ref, computed, onMounted, defineProps, defineEmits, toRefs } from 'vue'
29
37
  import { RangeViewer, injectComponent } from "@live-change/vue3-components"
@@ -45,7 +53,7 @@
45
53
  type: Boolean,
46
54
  default: false
47
55
  },
48
- options: {
56
+ attributes: {
49
57
  type: Object,
50
58
  default: () => ({})
51
59
  },
@@ -54,7 +62,7 @@
54
62
  default: ''
55
63
  }
56
64
  })
57
- const { service, model, identifiers, draft, options, i18n } = toRefs(props)
65
+ const { service, model, identifiers, draft, attributes, i18n } = toRefs(props)
58
66
 
59
67
  const emit = defineEmits(['saved', 'draftSaved', 'draftDiscarded', 'saveError', 'created' ])
60
68
 
@@ -90,7 +98,6 @@
90
98
  viewDataPromise
91
99
  ])
92
100
 
93
-
94
101
  </script>
95
102
 
96
103
  <style scoped>
@@ -42,7 +42,7 @@
42
42
  import AutoInput from "./AutoInput.vue"
43
43
 
44
44
  import { inputs, types } from '../../config.js'
45
- import { computed, getCurrentInstance, inject, toRefs, onMounted, ref } from 'vue'
45
+ import { computed, getCurrentInstance, inject, toRefs, onMounted, ref, useId } from 'vue'
46
46
 
47
47
  const isMounted = ref(false)
48
48
  onMounted(() => isMounted.value = true)
@@ -94,8 +94,7 @@
94
94
  }
95
95
  })
96
96
 
97
- const instanceUid = getCurrentInstance().uid
98
- const uid = computed(() => isMounted.value ? 'field_'+instanceUid.toFixed().padStart(6, '0') : undefined)
97
+ const uid = useId()
99
98
 
100
99
  const emit = defineEmits(['update:modelValue'])
101
100
 
@@ -105,6 +104,8 @@
105
104
  if(definition.value?.if) {
106
105
  if(definition.value?.if.function) {
107
106
  return eval(`(${definition.value.if.function})`)
107
+ } else {
108
+ throw new Error('Unknown if type' + JSON.stringify(definition.value.if))
108
109
  }
109
110
  }
110
111
  return false
@@ -61,6 +61,8 @@
61
61
  if(definition.value?.if) {
62
62
  if(definition.value?.if.function) {
63
63
  return eval(`(${definition.value.if.function})`)
64
+ } else {
65
+ throw new Error('Unknown if type' + JSON.stringify(definition.value.if))
64
66
  }
65
67
  }
66
68
  return false
@@ -1,19 +1,11 @@
1
1
  <template>
2
- <div v-if="definition" class="grid formgrid p-fluid mt-2 mb-2">
3
- <auto-field-view v-for="property in propertiesList" :key="property"
4
- :value="value?.[property]"
5
- :definition="definition.properties[property]"
6
- :label="property"
7
- :rootValue="props.rootValue" :propName="(propName ? propName + '.' : '') + property"
8
- :i18n="i18n"
9
- class="col-12" />
10
- </div>
2
+ <component v-if="viewComponent && visible" :is="viewComponent" v-bind="attributes" :i18n="i18n" />
11
3
  </template>
12
4
 
13
5
  <script setup>
14
- //import AutoFieldView from "./AutoFieldView.vue"
6
+ import { injectComponent } from '@live-change/vue3-components'
15
7
 
16
- import { computed, inject, getCurrentInstance, toRefs } from 'vue'
8
+ import { computed, inject, getCurrentInstance, toRefs, defineAsyncComponent } from 'vue'
17
9
 
18
10
  const props = defineProps({
19
11
  value: {},
@@ -37,16 +29,82 @@
37
29
  items: {
38
30
  type: String
39
31
  }
32
+ },
33
+ class: {},
34
+ style: {},
35
+ attributes: {
36
+ type: Object,
37
+ default: () => ({})
40
38
  }
41
39
  })
42
40
 
43
- const { value, definition, propName, visibleProperties } = toRefs(props)
41
+ const { value, definition, propName, rootValue, visibleProperties } = toRefs(props)
42
+
43
+ const definitionIf = computed(() => {
44
+ if(definition.value?.if) {
45
+ if(definition.value?.if.function) {
46
+ return eval(`(${definition.value.if.function})`)
47
+ } else {
48
+ throw new Error('Unknown if type' + JSON.stringify(definition.value.if))
49
+ }
50
+ }
51
+ return false
52
+ })
53
+
54
+ const visible = computed(() => {
55
+ if(!definition.value) return false
56
+ if(definitionIf.value) {
57
+ //console.log("DIF", propName.value, definitionIf.value, 'IN', props.rootValue)
58
+ return definitionIf.value({
59
+ source: definition.value,
60
+ props: props.rootValue,
61
+ propName: props.propName
62
+ })
63
+ }
64
+ return true
65
+ })
66
+
67
+ const viewFilter = computed(() => {
68
+ const filter = definition?.view?.componentFilter
69
+ if(filter) {
70
+ if(filter.function) {
71
+ return eval(`(${filter.function})`)
72
+ } else {
73
+ throw new Error('Unknown filter type' + JSON.stringify(filter))
74
+ }
75
+ }
76
+ return undefined
77
+ })
78
+
79
+ const viewComponent = computed(() => {
80
+ const type = definition.value.type ?? 'Object'
81
+ const defaultComponent = (type === 'Object')
82
+ ? defineAsyncComponent(() => import('./ObjectView.vue'))
83
+ : defineAsyncComponent(() => import('./JsonView.vue'))
84
+ return injectComponent(definition.value?.view?.componentRequest ?? {
85
+ ...(definition.value?.view?.componentRequestProperties),
86
+ name: 'AutoView',
87
+ type,
88
+ view: definition?.view?.name ?? definition?.view,
89
+ filter: viewFilter.value
90
+ }, defaultComponent)
91
+ })
92
+
93
+ const viewClass = computed(() => [definition.value?.view?.class, props.class])
94
+ const viewStyle = computed(() => [definition.value?.view?.style, props.style])
44
95
 
45
- const propertiesList = computed(() =>
46
- visibleProperties.value ??
47
- props.definition.visibleProperties ??
48
- Object.keys(props.definition.properties).filter(key => props.definition.properties[key])
49
- )
96
+ const attributes = computed(() => ({
97
+ visibleProperties: visibleProperties.value,
98
+ i18n: i18n.value,
99
+ ...(definition.value?.view?.attributes),
100
+ ...(props.attributes),
101
+ value: value.value,
102
+ definition: definition.value,
103
+ class: viewClass.value,
104
+ style: viewStyle.value,
105
+ rootValue: rootValue.value,
106
+ propName: propName.value,
107
+ }))
50
108
 
51
109
  </script>
52
110
 
@@ -0,0 +1,120 @@
1
+ <template>
2
+ <component v-if="fieldComponent && visible" :is="fieldComponent" v-bind="attributes" :i18n="i18n" />
3
+ </template>
4
+
5
+ <script setup>
6
+ import { injectComponent } from '@live-change/vue3-components'
7
+
8
+ import { computed, inject, getCurrentInstance, toRefs } from 'vue'
9
+ import DefaultFieldView from './DefaultFieldView.vue'
10
+
11
+ const props = defineProps({
12
+ name: {
13
+ type: String
14
+ },
15
+ label: {
16
+ type: String
17
+ },
18
+ value: {},
19
+ definition: {
20
+ type: Object
21
+ },
22
+ rootValue: {
23
+ type: Object,
24
+ default: () => ({})
25
+ },
26
+ propName: {
27
+ type: String,
28
+ default: ''
29
+ },
30
+ i18n: {
31
+ type: String,
32
+ default: ''
33
+ },
34
+ visibleProperties: {
35
+ type: Array,
36
+ items: {
37
+ type: String
38
+ }
39
+ },
40
+ class: {},
41
+ style: {},
42
+ attributes: {
43
+ type: Object,
44
+ default: () => ({})
45
+ }
46
+ })
47
+
48
+ const { value, definition, propName, rootValue, label, name } = toRefs(props)
49
+
50
+ const definitionIf = computed(() => {
51
+ if(definition.value?.if) {
52
+ if(definition.value?.if.function) {
53
+ return eval(`(${definition.value.if.function})`)
54
+ } else {
55
+ throw new Error('Unknown if type' + JSON.stringify(definition.value.if))
56
+ }
57
+ }
58
+ return false
59
+ })
60
+
61
+ const visible = computed(() => {
62
+ if(!definition.value) return false
63
+ if(definitionIf.value) {
64
+ //console.log("DIF", propName.value, definitionIf.value, 'IN', props.rootValue)
65
+ return definitionIf.value({
66
+ source: definition.value,
67
+ props: props.rootValue,
68
+ propName: props.propName
69
+ })
70
+ }
71
+ return true
72
+ })
73
+
74
+ const fieldFilter = computed(() => {
75
+ const filter = definition?.view?.fieldComponentFilter
76
+ if(filter) {
77
+ if(filter.function) {
78
+ return eval(`(${filter.function})`)
79
+ } else {
80
+ throw new Error('Unknown filter type' + JSON.stringify(filter))
81
+ }
82
+ }
83
+ return undefined
84
+ })
85
+
86
+ const fieldComponent = computed(() => injectComponent(definition.value?.view?.fieldComponentRequest ?? {
87
+ ...(definition.value?.view?.fieldComponentRequestProperties),
88
+ name: 'AutoFieldView',
89
+ type: definition.type ?? 'Object',
90
+ view: definition?.view?.name ?? definition?.view,
91
+ filter: fieldFilter.value
92
+ }, DefaultFieldView))
93
+
94
+ const fieldClass = computed(() => [definition.value?.view?.fieldClass, props.class])
95
+ const fieldStyle = computed(() => [definition.value?.view?.fieldStyle, props.style])
96
+
97
+ const viewClass = computed(() => [definition.value?.view?.class, props.viewClass])
98
+ const viewStyle = computed(() => [definition.value?.view?.style, props.viewStyle])
99
+
100
+ const attributes = computed(() => ({
101
+ i18n: i18n.value,
102
+ name: name.value,
103
+ label: label.value,
104
+ ...(definition.value?.view?.attributes),
105
+ ...(props.attributes),
106
+ value: value.value,
107
+ definition: definition.value,
108
+ class: fieldClass.value,
109
+ style: fieldStyle.value,
110
+ viewClass: viewClass.value,
111
+ viewStyle: viewStyle.value,
112
+ rootValue: rootValue.value,
113
+ propName: propName.value,
114
+ }))
115
+
116
+ </script>
117
+
118
+ <style scoped>
119
+
120
+ </style>
@@ -0,0 +1,82 @@
1
+ <template>
2
+ <div class="field" :class="fieldClass" :style="fieldStyle">
3
+ <slot name="label"
4
+ v-bind="{ uid, value, definition, viewClass, viewStyle, attributes, propName, rootValue, i18n }">
5
+ <label :for="uid">{{ t( label ) }}</label>
6
+ </slot>
7
+ <slot v-bind="{ uid, value, definition, viewClass, viewStyle, attributes, propName, rootValue, i18n }">
8
+ <AutoView :value="value" :definition="definition"
9
+ :class="viewClass" :style="viewStyle"
10
+ :attributes="attributes"
11
+ :propName="propName"
12
+ :rootValue="rootValue"
13
+ :id="uid"
14
+ :i18n="i18n" />
15
+ </slot>
16
+ </div>
17
+ </template>
18
+
19
+ <script setup>
20
+
21
+ import AutoView from "./AutoView.vue"
22
+
23
+ import { computed, getCurrentInstance, inject, toRefs, onMounted, ref, useId } from 'vue'
24
+
25
+ const isMounted = ref(false)
26
+ onMounted(() => isMounted.value = true)
27
+
28
+ import { useI18n } from 'vue-i18n'
29
+ const { t, rt } = useI18n()
30
+
31
+ const props = defineProps({
32
+ value: {},
33
+ definition: {
34
+ type: Object
35
+ },
36
+ name: {
37
+ type: String
38
+ },
39
+ label: {
40
+ type: String
41
+ },
42
+ class: {},
43
+ style: {},
44
+ viewClass: {},
45
+ viewStyle: {},
46
+ attributes: {
47
+ type: Object,
48
+ default: () => ({})
49
+ },
50
+ rootValue: {
51
+ type: Object,
52
+ default: () => ({})
53
+ },
54
+ propName: {
55
+ type: String,
56
+ default: ''
57
+ },
58
+ i18n: {
59
+ type: String,
60
+ default: ''
61
+ },
62
+ })
63
+
64
+ const instanceUid = getCurrentInstance().uid
65
+ const uid = useId()
66
+
67
+ const emit = defineEmits(['update:modelValue'])
68
+
69
+ const { error, definition, value } = toRefs(props)
70
+
71
+ const label = computed(() => props.i18n + (props.label || definition.value.label || props.name))
72
+
73
+ const viewClass = computed(() => [definition.value?.view?.class, props.viewClass])
74
+ const viewStyle = computed(() => [definition.value?.view?.style, props.viewStyle])
75
+ const fieldClass = computed(() => [definition.value?.view?.class, props.class])
76
+ const fieldStyle = computed(() => [definition.value?.view?.style, props.style])
77
+
78
+ </script>
79
+
80
+ <style scoped>
81
+
82
+ </style>
@@ -0,0 +1,39 @@
1
+ <template>
2
+ <div>
3
+ <pre>{{ JSON.stringify(value, null, 2) }}</pre>
4
+ </div>
5
+ </template>
6
+
7
+ <script setup>
8
+ import AutoViewField from "./AutoViewField.vue"
9
+
10
+ import { computed, inject, getCurrentInstance, toRefs } from 'vue'
11
+
12
+ const props = defineProps({
13
+ value: {},
14
+ definition: {
15
+ type: Object
16
+ },
17
+ rootValue: {
18
+ type: Object,
19
+ default: () => ({})
20
+ },
21
+ propName: {
22
+ type: String,
23
+ default: ''
24
+ },
25
+ class: {},
26
+ style: {},
27
+ i18n: {
28
+ type: String,
29
+ default: ''
30
+ },
31
+ })
32
+
33
+ const { value, definition, propName } = toRefs(props)
34
+
35
+ </script>
36
+
37
+ <style scoped>
38
+
39
+ </style>
@@ -0,0 +1,60 @@
1
+ <template>
2
+ <div v-if="definition" class="grid formgrid p-fluid mt-2 mb-2">
3
+ <AutoViewField v-for="property in propertiesList" :key="property"
4
+ :value="value?.[property]"
5
+ :definition="definition.properties[property]"
6
+ :label="property"
7
+ :name="property"
8
+ :rootValue="props.rootValue" :propName="(propName ? propName + '.' : '') + property"
9
+ :i18n="i18n"
10
+ class="col-12" />
11
+ </div>
12
+ </template>
13
+
14
+ <script setup>
15
+ import AutoViewField from "./AutoViewField.vue"
16
+
17
+ import { computed, inject, getCurrentInstance, toRefs } from 'vue'
18
+
19
+ const props = defineProps({
20
+ value: {},
21
+ definition: {
22
+ type: Object
23
+ },
24
+ rootValue: {
25
+ type: Object,
26
+ default: () => ({})
27
+ },
28
+ propName: {
29
+ type: String,
30
+ default: ''
31
+ },
32
+ class: {},
33
+ style: {},
34
+ i18n: {
35
+ type: String,
36
+ default: ''
37
+ },
38
+ visibleProperties: {
39
+ type: Array,
40
+ items: {
41
+ type: String
42
+ }
43
+ }
44
+ })
45
+
46
+ const { value, definition, propName, visibleProperties } = toRefs(props)
47
+
48
+ const propertiesList = computed(() =>
49
+ visibleProperties.value ??
50
+ props.definition.visibleProperties ??
51
+ (definition.value.properties
52
+ ? Object.keys(definition.value.properties).filter(key => props.definition.properties[key])
53
+ : [])
54
+ )
55
+
56
+ </script>
57
+
58
+ <style scoped>
59
+
60
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/frontend-auto-form",
3
- "version": "0.9.12",
3
+ "version": "0.9.13",
4
4
  "scripts": {
5
5
  "memDev": "node server/start.js memDev --enableSessions --initScript ./init.js --dbAccess",
6
6
  "localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
@@ -22,16 +22,16 @@
22
22
  "type": "module",
23
23
  "dependencies": {
24
24
  "@fortawesome/fontawesome-free": "^6.5.2",
25
- "@live-change/cli": "^0.9.12",
26
- "@live-change/dao": "^0.9.12",
27
- "@live-change/dao-vue3": "^0.9.12",
28
- "@live-change/dao-websocket": "^0.9.12",
29
- "@live-change/framework": "^0.9.12",
30
- "@live-change/image-frontend": "^0.9.12",
31
- "@live-change/image-service": "^0.9.12",
32
- "@live-change/session-service": "^0.9.12",
33
- "@live-change/vue3-components": "^0.9.12",
34
- "@live-change/vue3-ssr": "^0.9.12",
25
+ "@live-change/cli": "^0.9.13",
26
+ "@live-change/dao": "^0.9.13",
27
+ "@live-change/dao-vue3": "^0.9.13",
28
+ "@live-change/dao-websocket": "^0.9.13",
29
+ "@live-change/framework": "^0.9.13",
30
+ "@live-change/image-frontend": "^0.9.13",
31
+ "@live-change/image-service": "^0.9.13",
32
+ "@live-change/session-service": "^0.9.13",
33
+ "@live-change/vue3-components": "^0.9.13",
34
+ "@live-change/vue3-ssr": "^0.9.13",
35
35
  "@vueuse/core": "^10.11.0",
36
36
  "codeceptjs-assert": "^0.0.5",
37
37
  "compression": "^1.7.4",
@@ -52,7 +52,7 @@
52
52
  "vue3-scroll-border": "0.1.6"
53
53
  },
54
54
  "devDependencies": {
55
- "@live-change/codeceptjs-helper": "^0.9.12",
55
+ "@live-change/codeceptjs-helper": "^0.9.13",
56
56
  "codeceptjs": "^3.6.5",
57
57
  "generate-password": "1.7.1",
58
58
  "playwright": "1.48.1",
@@ -63,5 +63,5 @@
63
63
  "author": "Michał Łaszczewski <michal@laszczewski.pl>",
64
64
  "license": "ISC",
65
65
  "description": "",
66
- "gitHead": "1dba75a1fc90c5b796f7a8dab2895e6085ddce22"
66
+ "gitHead": "b0b18e7a8e253195c6df4b25c6bb5c407b1a2450"
67
67
  }