@bildvitta/quasar-ui-asteroid 3.8.0-beta.2 → 3.8.0-beta.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bildvitta/quasar-ui-asteroid",
3
3
  "description": "Asteroid",
4
- "version": "3.8.0-beta.2",
4
+ "version": "3.8.0-beta.3",
5
5
  "author": "Bild & Vitta <systemteam@bild.com.br>",
6
6
  "license": "MIT",
7
7
  "main": "dist/asteroid.cjs.min.js",
@@ -6,34 +6,32 @@
6
6
 
7
7
  <div ref="inputContent">
8
8
  <component :is="componentTag" v-bind="componentProps">
9
- <div v-for="(row, index) in nested" :id="`row-${index}`" :key="`row-${index}`" class="full-width">
10
- <div :key="index" class="col-12 q-mt-md">
11
- <div>
12
- <header class="flex items-center q-py-md" :class="headerClasses">
13
- <qas-label v-if="!useSingleLabel" :label="getRowLabel(index)" />
14
- <qas-actions-menu v-if="hasBlockActions(row)" v-bind="actionsMenuProps" :list="getActionsList(index, row)" />
15
- </header>
16
-
17
- <div ref="formGenerator" class="col-12 justify-between q-col-gutter-x-md row">
18
- <slot :errors="transformedErrors" :fields="children" :index="index" name="fields" :update-value="updateValuesFromInput">
19
- <qas-form-generator v-model="nested[index]" :class="formClasses" :columns="formColumns" :disable="isDisabledRow(row)" :errors="transformedErrors[index]" :fields="children" :fields-props="fieldsProps" @update:model-value="updateValuesFromInput($event, index)">
20
- <template v-for="(slot, key) in $slots" #[key]="scope">
21
- <slot v-bind="scope" :disabled="isDisabledRow(row)" :errors="transformedErrors" :index="index" :name="key" />
22
- </template>
23
- </qas-form-generator>
24
- </slot>
25
-
26
- <div v-if="hasInlineActions(row)" class="flex items-center qas-nested-fields__actions">
27
- <qas-actions-menu v-bind="actionsMenuProps" :list="getActionsList(index, row)" />
28
- </div>
9
+ <template v-for="(row, index) in nested" :key="`row-${index}`">
10
+ <div v-if="!row[destroyKey]" :id="`row-${index}`" class="full-width q-mt-md">
11
+ <header class="flex items-center q-py-md" :class="headerClasses">
12
+ <qas-label v-if="!useSingleLabel" :label="getRowLabel(index)" />
13
+ <qas-actions-menu v-if="hasBlockActions(row)" v-bind="actionsMenuProps" :list="getActionsList(index, row)" />
14
+ </header>
15
+
16
+ <div ref="formGenerator" class="col-12 justify-between q-col-gutter-x-md row">
17
+ <slot :errors="transformedErrors" :fields="children" :index="index" name="fields" :update-value="updateValuesFromInput">
18
+ <qas-form-generator v-model="nested[index]" :class="formClasses" :columns="formColumns" :disable="isDisabledRow(row)" :errors="transformedErrors[index]" :fields="children" :fields-props="fieldsProps" @update:model-value="updateValuesFromInput($event, index)">
19
+ <template v-for="(slot, key) in $slots" #[key]="scope">
20
+ <slot v-bind="scope" :disabled="isDisabledRow(row)" :errors="transformedErrors" :index="index" :name="key" />
21
+ </template>
22
+ </qas-form-generator>
23
+ </slot>
24
+
25
+ <div v-if="hasInlineActions(row)" class="flex items-center qas-nested-fields__actions">
26
+ <qas-actions-menu v-bind="actionsMenuProps" :list="getActionsList(index, row)" />
29
27
  </div>
28
+ </div>
30
29
 
31
- <div class="col-12">
32
- <slot :fields="children" :index="index" :model="nested[index]" name="custom-fields" :update-value="updateValuesFromInput" />
33
- </div>
30
+ <div class="col-12">
31
+ <slot :fields="children" :index="index" :model="nested[index]" name="custom-fields" :update-value="updateValuesFromInput" />
34
32
  </div>
35
33
  </div>
36
- </div>
34
+ </template>
37
35
  </component>
38
36
 
39
37
  <div v-if="useAdd" class="q-mt-md">
@@ -68,6 +66,7 @@ import QasFormGenerator from '../form-generator/QasFormGenerator.vue'
68
66
  import QasInput from '../input/QasInput.vue'
69
67
  import QasLabel from '../label/QasLabel.vue'
70
68
  import { TransitionGroup } from 'vue'
69
+ import { extend } from 'quasar'
71
70
 
72
71
  import { constructObject } from '../../helpers'
73
72
 
@@ -241,7 +240,7 @@ export default {
241
240
 
242
241
  data () {
243
242
  return {
244
- destroyKeyList: {},
243
+ nested: [],
245
244
  hasDestroyAlways: true
246
245
  }
247
246
  },
@@ -293,18 +292,18 @@ export default {
293
292
 
294
293
  headerClasses () {
295
294
  return this.useSingleLabel ? 'justify-end' : 'justify-between'
296
- },
297
-
298
- nested () {
299
- return this.modelValue.filter(item => !item[this.destroyKey])
300
- },
301
-
302
- hasDestroyKeyList () {
303
- return !!Object.keys(this.destroyKeyList).length
304
295
  }
305
296
  },
306
297
 
307
298
  watch: {
299
+ modelValue: {
300
+ handler (value) {
301
+ this.nested = extend(true, [], value)
302
+ },
303
+ deep: true,
304
+ immediate: true
305
+ },
306
+
308
307
  rowObject: {
309
308
  handler () {
310
309
  this.setDefaultNestedValue()
@@ -379,11 +378,9 @@ export default {
379
378
  * ao invés de adicionar a flag [destroyKey]
380
379
  */
381
380
  destroy (index, row) {
382
- const [removedRow] = this.nested.splice(index, 1)
383
-
384
- if (!this.useRemoveOnDestroy && row[this.identifierItemKey]) {
385
- this.destroyKeyList[row[this.identifierItemKey]] = { row: removedRow, index }
386
- }
381
+ !row[this.identifierItemKey] || this.useRemoveOnDestroy
382
+ ? this.nested.splice(index, 1)
383
+ : this.nested.splice(index, 1, { [this.destroyKey]: true, ...row })
387
384
 
388
385
  this.$qas.logger.group('QasNestedFields - destroy', [{ index, row }])
389
386
 
@@ -391,23 +388,13 @@ export default {
391
388
  },
392
389
 
393
390
  updateModelValue () {
394
- const nested = [...this.nested]
395
-
396
- if (this.hasDestroyKeyList) {
397
- for (const key in this.destroyKeyList) {
398
- const { row, index } = this.destroyKeyList[key]
399
-
400
- nested.splice(index, 0, { ...row, [this.destroyKey]: true })
401
- }
402
- }
403
-
404
- this.$emit('update:modelValue', nested)
391
+ this.$emit('update:modelValue', this.nested)
405
392
  },
406
393
 
407
394
  updateValuesFromInput (value, index) {
408
395
  this.nested.splice(index, 1, value)
409
396
 
410
- return this.updateModelValue()
397
+ this.updateModelValue()
411
398
  },
412
399
 
413
400
  setDefaultNestedValue () {
@@ -436,9 +423,17 @@ export default {
436
423
  return firstElementToBeFocused?.focus && firstElementToBeFocused.focus()
437
424
  },
438
425
 
439
- getRowLabel (rowKey) {
426
+ getRealRowIndex (index) {
427
+ return [...this.nested].splice(0, index).filter(item => !item[this.destroyKey]).length
428
+ },
429
+
430
+ getRowLabel (rowIndex) {
440
431
  if (this.rowLabel) {
441
- return this.useIndexLabel ? `${this.rowLabel} ${rowKey + 1}` : this.rowLabel
432
+ if (!this.useIndexLabel) return this.rowLabel
433
+
434
+ const index = this.useRemoveOnDestroy ? rowIndex : this.getRealRowIndex(rowIndex)
435
+
436
+ return `${this.rowLabel} ${index + 1}`
442
437
  }
443
438
 
444
439
  return this.fieldLabel