@live-change/vue3-components 0.2.30 → 0.2.32

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.
@@ -130,6 +130,18 @@
130
130
  this.object = this.data[this.property]
131
131
  this.properties = {}
132
132
 
133
+ this.bindProperties(definition)
134
+
135
+ this.unwatch = watch(() => this.data[this.property], () => {
136
+ if(this.object != this.data[this.property]) {
137
+ this.object = this.data[this.property]
138
+ console.log("OBJECT OBJECT CHANGE", this.property)
139
+ this.bindProperties(definition)
140
+ }
141
+ }, { deep: true })
142
+ }
143
+
144
+ bindProperties(definition) {
133
145
  for(let propName in definition.properties) {
134
146
  let propDefn = definition.properties[propName]
135
147
 
@@ -264,7 +276,6 @@
264
276
  this.properties[propName].reset(oldData)
265
277
  this.object[propName] = this.properties[propName].getValue()
266
278
  }
267
-
268
279
  }
269
280
 
270
281
  class FormArray extends FormValue {
@@ -274,22 +285,37 @@
274
285
  this.elements = []
275
286
  if(!this.data[this.property]) this.data[this.property] = []
276
287
  this.object = this.data[this.property]
288
+ this.bindElements()
277
289
  this.unwatch = watch(() => this.data[this.property], () => {
278
- this.object = this.data[this.property]
279
- while(this.elements.length > this.object.length) {
280
- this.elements.pop()
281
- }
282
- while(this.elements.length < this.object.length) {
283
- this.elements.push(this.newElement(this.elements.length))
290
+ if(this.object != this.data[this.property]) {
291
+ //console.log("ARRAY OBJECT CHANGE", this.property)
292
+ this.object = this.data[this.property]
293
+ this.elements = []
284
294
  }
295
+ this.bindElements()
296
+ //this.check()
285
297
  }, { deep: true })
286
298
  }
287
299
 
300
+ bindElements() {
301
+ while(this.elements.length > this.object.length) {
302
+ this.elements.pop()
303
+ }
304
+ while(this.elements.length < this.object.length) {
305
+ this.elements.push(this.newElement(this.elements.length))
306
+ }
307
+ }
308
+
288
309
  setProperty(name) {
289
310
  if(this.unwatch) this.unwatch()
290
311
  this.property = name
291
312
  this.object = this.data[this.property]
292
313
  this.unwatch = watch(() => this.data[this.property], () => {
314
+ if(this.object != this.data[this.property]) {
315
+ //console.log("ARRAY OBJECT CHANGE", this.property)
316
+ this.object = this.data[this.property]
317
+ this.elements = []
318
+ }
293
319
  this.object = this.data[this.property]
294
320
  while(this.elements.length > this.object.length) {
295
321
  this.elements.pop()
@@ -313,13 +339,24 @@
313
339
  reset(initialValue) {
314
340
  initialValue = initialValue || this.definition.defaultValue || []
315
341
  this.data[this.property] = new Array(initialValue.length)
316
- this.elements = this.data[this.property]
342
+ this.elements = new Array(this.object.length)
317
343
  for(let i = 0; i < initialValue.length; i++) {
318
- let n = this.newElement(this.elements.length)
344
+ let n = this.newElement(i)
319
345
  n.reset(initialValue[i])
320
346
  this.elements[i] = n
321
347
  }
322
348
  super.setValue(initialValue)
349
+ /* if(this.property == 'query') {
350
+ this.check()
351
+ this.object.bzz = 1
352
+ }*/
353
+ }
354
+
355
+ check() {
356
+ console.log("ARRAY", this, JSON.stringify(this.data))
357
+ for(let i = 0; i < this.elements.length; i++) {
358
+ console.log("ELEMENT", i, this.elements[i].data[i] == this.object[i])
359
+ }
323
360
  }
324
361
 
325
362
  afterError(initialValue) {
@@ -384,18 +421,28 @@
384
421
  }
385
422
 
386
423
  setValue(value) {
387
- this.data[this.property] = value
388
- if(!value) return;
389
- for(let i = 0; i < value.length; i++) {
390
- if(this.elements[i]) {
391
- this.elements[i].setValue(value[i])
392
- } else {
393
- let n = this.newElement()
424
+ if(value != this.object) {
425
+ this.data[this.property] = value
426
+ this.object = value
427
+ this.elements = []
428
+ if(!value) return;
429
+ for(let i = 0; i < value.length; i++) {
430
+ let n = this.newElement(i)
394
431
  n.reset(value[i])
395
432
  this.elements.push(n)
396
433
  }
434
+ } else {
435
+ for (let i = 0; i < value.length; i++) {
436
+ if (this.elements[i]) {
437
+ this.elements[i].setValue(value[i])
438
+ } else {
439
+ let n = this.newElement(i)
440
+ n.reset(value[i])
441
+ this.elements.push(n)
442
+ }
443
+ }
444
+ this.elements = this.elements.slice(0, value.length)
397
445
  }
398
- this.elements = this.elements.slice(0, value.length)
399
446
  }
400
447
 
401
448
  updateElementIndices() {
@@ -464,6 +511,8 @@
464
511
  getValue: () => this.formRoot.getValue(),
465
512
  reset: () => this.reset(),
466
513
 
514
+ getNode: (name) => this.getNode(name),
515
+
467
516
  addValidator: (propName, validator) => this.addValidator(propName, validator),
468
517
  removeValidator: (propName, validator) => this.addValidator(propName, validator),
469
518
  validateField: (propName) => this.validateField(propName),
@@ -477,7 +526,11 @@
477
526
  waitForBarriers: (propName) => this.waitForBarriers(),
478
527
 
479
528
  addElementToArray: (propName, initialValue) => this.addElementToArray(propName, initialValue),
480
- removeElementFromArray: (propName, index) => this.removeElementFromArray(propName, index)
529
+ removeElementFromArray: (propName, index) => this.removeElementFromArray(propName, index),
530
+
531
+ data: computed(() => this.data),
532
+ root: computed(() => this.formRoot),
533
+ state: computed(() => this.state),
481
534
  }
482
535
  }
483
536
  },
@@ -489,11 +542,6 @@
489
542
  formRoot: {}
490
543
  }
491
544
  },
492
- computed: {
493
- rootValue() {
494
- return this.formRoot && this.formRoot.value
495
- }
496
- },
497
545
  methods: {
498
546
  getNode(name) {
499
547
  let np = name.split('.')
@@ -620,6 +668,8 @@
620
668
  created() {
621
669
  this.initForm()
622
670
  this.state = 'ready'
671
+
672
+ globalThis.form = this
623
673
  },
624
674
  unmounted() {
625
675
  },
package/form/FormBind.vue CHANGED
@@ -22,7 +22,17 @@ export default {
22
22
  },
23
23
  value: {
24
24
  get() {
25
- return this.form.getFieldValue(this.name)
25
+ let np = this.name.split('.')
26
+ let data = this.form.data.value
27
+ for(let p of np) {
28
+ if(!p) continue
29
+ data = data[p]
30
+ }
31
+ return data
32
+ /* const node = this.form.getNode(this.name)
33
+ console.log("RECOMPUTE VALUE OF", this.name, node.data[node.property])
34
+ return node.data[node.property]
35
+ //return this.form.getFieldValue(this.name)*/
26
36
  },
27
37
  set(value) {
28
38
  const filtered = this.valueFilter(value)
@@ -8,6 +8,7 @@ function useAnalytics() {
8
8
 
9
9
  function installRouterAnalytics(router) {
10
10
  router.afterEach((to, from) => {
11
+ if(typeof window === 'undefined') return
11
12
  analytics.emit('pageView', { ...to })
12
13
  })
13
14
  }
@@ -1,5 +1,5 @@
1
1
  import { computed, ref, watch } from "vue"
2
- import { useThrottleFn } from "@vueuse/core"
2
+ import { useThrottleFn, useDebounceFn } from "@vueuse/core"
3
3
 
4
4
  function copy(value) {
5
5
  let res = JSON.parse(JSON.stringify(value || {}))
@@ -23,7 +23,8 @@ function synchronized(options) {
23
23
  onSaveError = (e) => { console.error("SAVE ERROR", e) },
24
24
  resetOnError = true,
25
25
  recursive = false,
26
- throttle = 300,
26
+ throttle = 0,
27
+ debounce = 300,
27
28
  autoSave = true
28
29
  } = options
29
30
  if(!source) throw new Error('source must be defined')
@@ -61,11 +62,16 @@ function synchronized(options) {
61
62
  }
62
63
  return true
63
64
  }
64
- const throttledSave = throttle ? useThrottleFn(save, throttle) : save
65
+ const throttledSave = debounce ? () => {} : (throttle ? useThrottleFn(save, throttle) : save)
66
+ const debouncedSave = debounce ? useDebounceFn(save, throttle)
67
+ : (throttle ? useDebounceFn(save, throttle) : () => {}) // debounce after throttle
65
68
  watch(() => synchronizedJSON.value, json => {
66
69
  lastLocalUpdate.value = timeSource()
67
70
  onChange()
68
- if(autoSave) throttledSave()
71
+ if(autoSave) {
72
+ throttledSave()
73
+ debouncedSave()
74
+ }
69
75
  })
70
76
  //console.log("WATCH SOURCE VALUE", source.value)
71
77
  watch(() => JSON.stringify(source.value), sourceJson => {
@@ -101,7 +107,9 @@ function synchronized(options) {
101
107
  }
102
108
  return true
103
109
  }
104
- const throttledSave = throttle ? useThrottleFn(save, throttle) : save
110
+ const throttledSave = debounce ? () => {} : (throttle ? useThrottleFn(save, throttle) : save)
111
+ const debouncedSave = debounce ? useDebounceFn(save, throttle)
112
+ : (throttle ? useDebounceFn(save, throttle) : () => {}) // debounce after throttle
105
113
  const synchronizedComputed = computed({
106
114
  get: () => {
107
115
  const localTime = ((local.value && local.value[timeField]) ?? '')
@@ -111,7 +119,10 @@ function synchronized(options) {
111
119
  set: newValue => {
112
120
  local.value = { ...newValue, [timeField]: timeSource() }
113
121
  onChange()
114
- if(autoSave) throttledSave()
122
+ if(autoSave) {
123
+ throttledSave()
124
+ debouncedSave()
125
+ }
115
126
  }
116
127
  })
117
128
  return { value: synchronizedComputed, save, changed }
@@ -45,6 +45,7 @@ function synchronizedList(options) {
45
45
  move: moveAction,
46
46
  identifiers = {},
47
47
  objectIdentifiers = object => ({ id: object.id }),
48
+ prefix = '',
48
49
  timeField = 'lastUpdate',
49
50
  timeSource = () => (new Date()).toISOString(),
50
51
  onChange = () => {},
@@ -114,14 +115,15 @@ function synchronizedList(options) {
114
115
  return createSynchronizedElement(locallyAddedElement)
115
116
  }
116
117
  }, synchronizedList.value, source.value || [], locallyAdded.value, locallyDeleted.value)
117
- if(obsoleteLocallyAdded.length > 0) {
118
+ console.log("OBSOLETE", obsoleteLocallyAdded, obsoleteLocallyDeleted)
119
+ if(obsoleteLocallyAdded.size > 0) {
118
120
  locallyAdded.value = locallyAdded.value.filter(
119
- locallyAddedElement => obsoleteLocallyAdded.has(locallyAddedElement.id)
121
+ locallyAddedElement => !obsoleteLocallyAdded.has(locallyAddedElement.id)
120
122
  )
121
123
  }
122
- if(obsoleteLocallyDeleted.length > 0) {
124
+ if(obsoleteLocallyDeleted.size > 0) {
123
125
  locallyDeleted.value = locallyDeleted.value.filter(
124
- locallyDeletedElement => obsoleteLocallyDeleted.has(locallyDeletedElement.id)
126
+ locallyDeletedElement => !obsoleteLocallyDeleted.has(locallyDeletedElement.id)
125
127
  )
126
128
  }
127
129
  synchronizedList.value = newSynchronized
@@ -142,8 +144,12 @@ function synchronizedList(options) {
142
144
  }
143
145
 
144
146
  async function insert(element) {
145
- locallyAdded.value.push(element)
146
- await insertAction({ ...element, [timeField]: timeSource(), ...identifiers })
147
+ locallyAdded.value.push({
148
+ ...element,
149
+ to: element.id,
150
+ id: prefix + element.id
151
+ })
152
+ await insertAction({ ...element, [timeField]: timeSource(), ...identifiers, ...objectIdentifiers(element) })
147
153
  }
148
154
 
149
155
  async function deleteElement(element) {
@@ -157,7 +163,7 @@ function synchronizedList(options) {
157
163
  }
158
164
 
159
165
  const synchronizedValue = computed(() => synchronizedList.value.map(synchronizedElement => synchronizedElement.value))
160
- return { value: synchronizedValue, save, changed, insert, delete: deleteElement, move }
166
+ return { value: synchronizedValue, save, changed, insert, delete: deleteElement, move, locallyAdded }
161
167
  }
162
168
 
163
169
  export default synchronizedList
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/vue3-components",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "Live Change Framework - vue components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,10 +21,10 @@
21
21
  },
22
22
  "homepage": "https://github.com/live-change/live-change-framework-vue3",
23
23
  "dependencies": {
24
- "@live-change/vue3-ssr": "^0.2.30",
24
+ "@live-change/vue3-ssr": "^0.2.32",
25
25
  "debug": "^4.3.4",
26
26
  "mitt": "3.0.0",
27
27
  "vue": "^3.2.47"
28
28
  },
29
- "gitHead": "623e5d40a7457b5a2a3f55783c59360396161ca8"
29
+ "gitHead": "d8c0b754ac74a94f586cc1cd872ae9a2c60c86a7"
30
30
  }