@live-change/vue3-components 0.1.12 → 0.1.16

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.
@@ -22,7 +22,8 @@
22
22
  </template>
23
23
 
24
24
  <script>
25
- import DefinedForm from "./DefinedForm.vue"
25
+ import DefinedForm from './DefinedForm.vue'
26
+ import analytics from '../logic/analytics.js'
26
27
  import createDebug from 'debug'
27
28
  const debug = createDebug("live-change/command-form")
28
29
 
@@ -76,6 +77,7 @@
76
77
  type: String
77
78
  }
78
79
  },
80
+ emits: ['submit', 'done', 'error'],
79
81
  inject: ['loadingZone', 'workingZone'],
80
82
  data() {
81
83
  return {
@@ -91,15 +93,15 @@
91
93
  serviceDefinition() {
92
94
  if(this.serviceDefinitionSource) {
93
95
  if(typeof this.serviceDefinitionSource == 'string') {
94
- const definition = this.$api.metadata.serviceDefinitions
96
+ const definition = this.$api.metadata.serviceDefinitions.value
95
97
  .find(service => service.name == this.serviceDefinitionSource)
96
98
  return definition
97
99
  } else {
98
100
  return this.serviceDefinitionSource
99
101
  }
100
102
  }
101
- if(!this.$api.metadata.api?.services) return
102
- const definition = this.$api.metadata.api?.services.find(service => service.name == this.service)
103
+ if(!this.$api.metadata.api?.value?.services) return
104
+ const definition = this.$api.metadata.api?.value?.services.find(service => service.name == this.service)
103
105
  return definition
104
106
  },
105
107
  actionDefinition() {
@@ -193,26 +195,26 @@
193
195
  this.$refs.defined.scrollToError()
194
196
  },
195
197
  async submit(additionalParameters) {
196
- if(!(this.state == 'ready' || this.state == 'error')) return;
198
+ if(!(this.state == 'ready' || this.state == 'error')) return
197
199
  this.state = 'working'
198
200
  this.workingTask = this.workingZone.started({ name: `service ${this.service} action ${this.action}` })
199
201
 
200
202
  this.clearValidation()
201
203
 
202
- const _commandId = this.$api.guid()
204
+ const _commandId = this.$api.uid()
203
205
 
204
206
  const analyticsValue = this.$refs.defined.formRoot.getAnalyticsValue()
205
207
  const analyticsParameters =
206
208
  { ...analyticsValue, ...this.parameters, ...(additionalParameters || {}), _commandId }
207
209
 
208
- if(this.$analytics && this.$analytics.form)
209
- this.$analytics.form(this.service, this.action, analyticsParameters)
210
+ analytics.emit('form', { service: this.service, action: this.action, parameters: analyticsParameters })
210
211
 
211
212
  return this.validate({ parameters: {...this.parameters, ...additionalParameters} }).then(validationError => {
212
213
  debug("VALIDATION ERROR?", validationError)
213
214
  if(validationError) {
214
- if(this.$analytics && this.$analytics.formError)
215
- this.$analytics.formError(this.service, this.action, { analyticsParameters, error: validationError })
215
+ analytics.emit('formError', {
216
+ service: this.service, action: this.action, parameters: analyticsParameters, error: validationError
217
+ })
216
218
  this.workingZone.finished(this.workingTask)
217
219
  this.state = 'ready'
218
220
  this.scrollToError()
@@ -228,8 +230,9 @@
228
230
 
229
231
  return this.$api.request([this.service, this.action], parameters).then((result) => {
230
232
  debug("DATA SUBMITED")
231
- if(this.$analytics && this.$analytics.formDone)
232
- this.$analytics.formDone(this.service, this.action, analyticsParameters)
233
+ analytics.emit('formDone', {
234
+ service: this.service, action: this.action, parameters: analyticsParameters, error: validationError
235
+ })
233
236
  if(this.resetOnDone) {
234
237
  this.state = 'ready'
235
238
  this.reset()
@@ -241,8 +244,10 @@
241
244
  this.$emit('done', { result , parameters })
242
245
  this.workingZone.finished(this.workingTask)
243
246
  }).catch((error) => {
244
- if(this.$analytics && this.$analytics.formError)
245
- this.$analytics.formError(this.service, this.action, { analyticsParameters, error })
247
+ console.error("FORM ERROR", error)
248
+ analytics.emit('formError', {
249
+ service: this.service, action: this.action, parameters: analyticsParameters, error
250
+ })
246
251
  this.$refs.defined.formRoot.afterError(this.initialValues)
247
252
  if(error.properties) {
248
253
  for(let propName in error.properties) {
@@ -289,6 +294,7 @@
289
294
  })
290
295
  },
291
296
  handleSubmitEvent(ev) {
297
+ //console.log("HANDLE SUBMIT EVENT!", ev)
292
298
  ev.preventDefault()
293
299
  this.submit()
294
300
  },
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <component v-if="tag" :is="tag" v-on:submit="ev => $emit('submit', ev)" :class="class" :style="style">
2
+ <component v-if="tag" :is="tag" v-on:submit="ev => handleSubmitEvent(ev)" :class="class" :style="style">
3
3
  <slot v-bind="{ data }"></slot>
4
4
  </component>
5
5
  <slot v-else v-bind="{ data }"></slot>
@@ -379,7 +379,7 @@
379
379
  },
380
380
  parameters: {
381
381
  type: Object,
382
- default: null
382
+ default() { return {} }
383
383
  },
384
384
  class: {
385
385
  type: String
@@ -388,6 +388,7 @@
388
388
  type: String
389
389
  }
390
390
  },
391
+ //emits: ['submit', 'update'],
391
392
  provide() {
392
393
  return {
393
394
  form: {
@@ -407,7 +408,7 @@
407
408
  validate: () => this.validate(),
408
409
  clearFieldValidation: (propName) => this.clearFieldValidation(propName),
409
410
  clearValidation: () => this.clearValidation(),
410
-
411
+
411
412
  addElementToArray: (propName, initialValue) => this.addElementToArray(propName, initialValue),
412
413
  removeElementFromArray: (propName, index) => this.removeElementFromArray(propName, index)
413
414
  }
@@ -519,6 +520,10 @@
519
520
  let position = getElementPositionInDocument(errorFieldElement)
520
521
  window.scrollTo(0, position.y - 100) /// TODO: remove fixed nav-bar and do it properly.
521
522
  },
523
+ handleSubmitEvent(ev) {
524
+ ev.preventDefault()
525
+ this.$emit('submit', ev)
526
+ }
522
527
  },
523
528
  created() {
524
529
  this.initForm()
package/index.js CHANGED
@@ -8,6 +8,7 @@ import { registerViewComponents } from "./view"
8
8
 
9
9
  function registerComponents(app, settings = {}) {
10
10
  registerLogicComponents(app, settings)
11
+ console.log("reg", registerFormComponents)
11
12
  registerFormComponents(app, settings)
12
13
  registerViewComponents(app, settings)
13
14
  }
@@ -17,3 +18,7 @@ export { registerComponents }
17
18
  import createReactiveObject from "./utils/createReactiveObject.mjs"
18
19
 
19
20
  export { createReactiveObject }
21
+
22
+ import { analytics, useAnalytics, installRouterAnalytics } from "./logic"
23
+ export { analytics, useAnalytics, installRouterAnalytics }
24
+
@@ -13,6 +13,7 @@
13
13
  <slot name="loading">
14
14
  Loading...
15
15
  </slot>
16
+ <div style="display: none">SUSPEND FALLBACK</div>
16
17
  </div>
17
18
  </template>
18
19
  </suspense>
@@ -30,6 +31,7 @@
30
31
 
31
32
  <script>
32
33
  import { onErrorCaptured, ref, reactive } from 'vue'
34
+ import analytics from './analytics.js'
33
35
  import debugLib from 'debug'
34
36
 
35
37
  const info = debugLib('loading:info')
@@ -37,6 +39,7 @@
37
39
 
38
40
  export default {
39
41
  name: "LoadingZone",
42
+ emits: ['isLoading', 'error'],
40
43
  props: {
41
44
  suspense: {
42
45
  type: Boolean,
@@ -60,24 +63,30 @@
60
63
  errors
61
64
  }
62
65
  },
66
+ watch: {
67
+ isLoading(l) {
68
+ this.$emit('isLoading', l)
69
+ }
70
+ },
63
71
  computed: {
72
+ isLoading() {
73
+ return this.loading.length > 0
74
+ }
64
75
  },
65
76
  methods: {
66
77
  loadingStarted(task) {
67
78
  if(this.loading.length == 0) {
68
- if(this.$analytics && this.$analytics.loadingStarted)
69
- this.$analytics.loadingStarted({ task: task.name })
79
+ analytics.emit('loadingStarted', { task: task.name })
70
80
  info('LOADING STARTED!')
71
81
 
72
82
  const loadingBlockId = this.loadingBlockId
73
- this.loagindTimeout = setTimeout(() => {
83
+ this.loadingTimeout = setTimeout(() => {
74
84
  if(loadingBlockId == this.loadingBlockId && this.loading.length > 0) {
75
85
  this.connectionProblem = true
76
- if(this.$analytics && this.$analytics.loadingError)
77
- this.$analytics.loadingError({
78
- task: "View loading", reason: "connection problem",
79
- tasks: this.loading.map(t => t.name)
80
- })
86
+ analytics.emit('loadingError', {
87
+ task: 'View loading', reason: "connection problem",
88
+ tasks: this.loading.map(t => t.name)
89
+ })
81
90
  }
82
91
  }, 4000)
83
92
  }
@@ -97,8 +106,7 @@
97
106
  if(this.loading.length == 0) {
98
107
  this.loadingBlockId++
99
108
  clearTimeout(this.loadingTimeout)
100
- if(this.$analytics && this.$analytics.loadingDone)
101
- this.$analytics.loadingDone({ task: task.name })
109
+ analytics.emit('loadingDone', { task: task.name })
102
110
  this.$nextTick(this.$router.loadingDone)
103
111
  }
104
112
  },
@@ -108,9 +116,7 @@
108
116
  clearTimeout(this.loadingTimeout)
109
117
 
110
118
  this.errors.push({ task, reason })
111
- if(this.$analytics && this.$analytics.loadingError) {
112
- this.$analytics.loadingError({ task: task.name, reason })
113
- }
119
+ analytics.emit('loadingError', { task: task.name, reason })
114
120
  let id = this.loading.indexOf(task)
115
121
  if(id == -1) {
116
122
  this.errors.push({ task, reason: "unknown task "+task.name })
@@ -122,6 +128,7 @@
122
128
  this.$allLoadingTasks.splice(this.$allLoadingTasks.indexOf(task), 1)
123
129
  if(this.$allLoadingErrors)
124
130
  this.$allLoadingErrors.push({ task, reason })
131
+ this.$emit('error', this.errors)
125
132
  },
126
133
  addLoadingPromise(name, promise) {
127
134
  let task = this.loadingStarted({ name, promise })
@@ -133,7 +140,7 @@
133
140
  promise
134
141
  .then((result) => this.loadingFinished(task))
135
142
  return promise
136
- }
143
+ },
137
144
  },
138
145
  provide() {
139
146
  return {
@@ -1,5 +1,5 @@
1
- <template>
2
- <slot v-bind="{ isWorking: !!working.length, working, errors }"></slot>
1
+ <template>
2
+ <slot v-bind="{ isWorking: !!working.length, working, errors }"></slot>
3
3
  <slot name="working" v-if="working.length && !errors.length">
4
4
  Processing...
5
5
  </slot>
@@ -21,6 +21,7 @@
21
21
 
22
22
  export default {
23
23
  name: "WorkingZone",
24
+ emits: ['isWorking', 'error'],
24
25
  data() {
25
26
  return {
26
27
  working: [],
@@ -29,21 +30,28 @@
29
30
  connectionProblem: false
30
31
  }
31
32
  },
33
+ watch: {
34
+ isWorking(w) {
35
+ this.$emit('isWorking', w)
36
+ }
37
+ },
32
38
  computed: {
39
+ isWorking() {
40
+ return this.working.length > 0
41
+ }
33
42
  },
34
43
  methods: {
35
44
  workingStarted(task) {
36
45
  if(this.working.length == 0) {
37
- if(this.$analytics && this.$analytics.workingStarted)
38
- this.$analytics.workingStarted({ task: task.name })
46
+ analytics.emit('workingStarted', { task: task.name })
47
+
39
48
  info('WORKING STARTED!')
40
49
 
41
50
  const workingBlockId = this.workingBlockId
42
51
  this.loagindTimeout = setTimeout(() => {
43
52
  if(workingBlockId == this.workingBlockId && this.working.length > 0) {
44
53
  this.connectionProblem = true
45
- if(this.$analytics && this.$analytics.workingError)
46
- this.$analytics.workingError({
54
+ analytics.emit('workingError', {
47
55
  task: "View working", reason: "connection problem",
48
56
  tasks: this.working.map(t => t.name)
49
57
  })
@@ -66,8 +74,7 @@
66
74
  if(this.working.length == 0) {
67
75
  this.workingBlockId++
68
76
  clearTimeout(this.workingTimeout)
69
- if(this.$analytics && this.$analytics.workingDone)
70
- this.$analytics.workingDone({ task: task.name })
77
+ analytics.emit('workingDone', { task: task.name })
71
78
  this.$nextTick(this.$router.workingDone)
72
79
  }
73
80
  },
@@ -77,8 +84,7 @@
77
84
  clearTimeout(this.workingTimeout)
78
85
 
79
86
  this.errors.push({ task, reason })
80
- if(this.$analytics && this.$analytics.workingError)
81
- this.$analytics.workingError({ task: task.name, reason })
87
+ analytics.emit('workingError', { task: task.name, reason })
82
88
 
83
89
  let id = this.working.indexOf(task)
84
90
  if(id == -1) {
@@ -91,6 +97,7 @@
91
97
  this.$allWorkingTasks.splice(this.$allWorkingTasks.indexOf(task), 1)
92
98
  if(this.$allWorkingErrors)
93
99
  this.$allWorkingErrors.push({ task, reason })
100
+ this.$emit('error', this.errors)
94
101
  },
95
102
  addWorkingPromise(name, promise) {
96
103
  let task = this.workingStarted({ name, promise })
@@ -0,0 +1,16 @@
1
+ import mitt from "mitt"
2
+
3
+ const analytics = mitt()
4
+
5
+ function useAnalytics() {
6
+ return analytics
7
+ }
8
+
9
+ function installRouterAnalytics(router) {
10
+ router.afterEach((to, from) => {
11
+ analytics.emit('pageView', { ...to })
12
+ })
13
+ }
14
+
15
+ export { analytics, useAnalytics, installRouterAnalytics }
16
+ export default analytics
package/logic/index.js CHANGED
@@ -5,6 +5,9 @@ import Observe from "./Observe.vue"
5
5
 
6
6
  export { Loading, LoadingZone, WorkingZone, Observe }
7
7
 
8
+ import { analytics, useAnalytics, installRouterAnalytics } from "./analytics.js"
9
+ export { analytics, useAnalytics, installRouterAnalytics }
10
+
8
11
  function registerLogicComponents(app) {
9
12
  app.component("loading", Loading)
10
13
  app.component("loading-zone", LoadingZone)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/vue3-components",
3
- "version": "0.1.12",
3
+ "version": "0.1.16",
4
4
  "description": "Live Change Framework - vue components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,6 +22,8 @@
22
22
  "homepage": "https://github.com/live-change/vue3-components",
23
23
  "dependencies": {
24
24
  "debug": "^4.3.2",
25
- "vue": "^3.2.21"
25
+ "vue": "^3.2.21",
26
+ "@live-change/vue3-ssr": "^0.1.9",
27
+ "mitt": "3.0.0"
26
28
  }
27
29
  }