@mapomodule/uikit 1.0.0-alpha.27 → 1.0.0-alpha.28

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/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.28](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.27...v1.0.0-alpha.28) (2022-09-01)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **form debounce:** fix form debounce not correctly updating model ([04b392d](https://github.com/lotrekagency/mapo/commit/04b392df7021534c4f30cee6ab3593946dd29414))
12
+ * fixed repeater remaining close on model fetch ([3a30136](https://github.com/lotrekagency/mapo/commit/3a301364ffe26107d890a9100c939a3c32cfc7c2))
13
+ * **repeater:** fix row expansion in nested repeater ([4ed22cd](https://github.com/lotrekagency/mapo/commit/4ed22cd3b0fe8593d1c87e43cbf92bbba8198ae2))
14
+ * **tabs:** show correct label in nested tabs ([30f50b2](https://github.com/lotrekagency/mapo/commit/30f50b277596304b99018e7132a8403c4c2c5639))
15
+
16
+
17
+ ### Features
18
+
19
+ * **detail:** give feedback for all http actions in detail components and prevent interaction during the request ([ceec206](https://github.com/lotrekagency/mapo/commit/ceec206fe50b23e784f9528fe41c02ec11c91e66))
20
+
21
+
22
+ ### Performance Improvements
23
+
24
+ * **repeater:** prevent collapsed repeater from rendering hidden forms ([1ae7d18](https://github.com/lotrekagency/mapo/commit/1ae7d1836f8ff8625f21a2be5fbaf5acef6ef404))
25
+ * increase form performances debouncing the emit events ([5e0bb30](https://github.com/lotrekagency/mapo/commit/5e0bb30f1e660d5b81319f213730c217eb6752a5))
26
+
27
+
28
+
29
+
30
+
6
31
  # [1.0.0-alpha.27](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.26...v1.0.0-alpha.27) (2022-08-25)
7
32
 
8
33
 
@@ -73,14 +73,14 @@
73
73
  <!-- Use this to override the Save button. -->
74
74
  <slot name="button.save" v-bind="slotBindings">
75
75
  <!-- The Save button. -->
76
- <v-btn v-show="canGoBack" :disabled="isReadonly" class="mb-2" tile block @click="saveItem(true)">{{
76
+ <v-btn v-show="canGoBack" :loading="buttonClicked == 'saveAndBackBtn'" :disabled="isReadonly" class="mb-2" tile block @click="saveItem(true)">{{
77
77
  isNew ? $t("mapo.create") : $t("mapo.save")
78
78
  }}</v-btn>
79
79
  </slot>
80
80
  <!-- Use this to override the Save and continue button. -->
81
81
  <slot name="button.savecontinue" v-bind="slotBindings">
82
82
  <!-- The Save and continue button. -->
83
- <v-btn :disabled="isReadonly" class="mb-2" tile block @click="saveItem(false)"
83
+ <v-btn :loading="buttonClicked == 'saveBtn'" :disabled="isReadonly" class="mb-2" tile block @click="saveItem(false)"
84
84
  >{{ isNew ? $t("mapo.createContinue") : $t("mapo.saveContinue") }}</v-btn
85
85
  >
86
86
  </slot>
@@ -92,7 +92,7 @@
92
92
  >
93
93
  </slot>
94
94
  <!-- Use this to override the Delete button. -->
95
- <slot name="button.delete" v-bind="slotBindings">
95
+ <slot name="button.delete" :loading="buttonClicked == 'deleteBtn'" v-bind="slotBindings">
96
96
  <!-- The Delete button. -->
97
97
  <v-btn
98
98
  v-if="!isNew"
@@ -161,7 +161,8 @@ export default {
161
161
  model: {},
162
162
  modelLanguages: [],
163
163
  currentLang: this.lang,
164
- errors: null
164
+ errors: null,
165
+ buttonClicked: null
165
166
  };
166
167
  },
167
168
  props: {
@@ -224,6 +225,7 @@ export default {
224
225
  this.$nuxt.context?.from?.name == "login" ? this.$router.go(-3) : this.$router.back();
225
226
  },
226
227
  saveItem(back = false) {
228
+ this.buttonClicked = back ? "saveAndBackBtn" : "saveBtn";
227
229
  this.errors = null;
228
230
  this.$refs.form?.resetValidation();
229
231
  this.crud
@@ -233,6 +235,7 @@ export default {
233
235
  this.back()
234
236
  } else {
235
237
  this.model = resp;
238
+ this.$mapo.$snack.open({ message: this.isNew ? this.$t("mapo.createSuccess") : this.$t("mapo.saveSuccess"), color: "success" })
236
239
  this.isNew && this.$router.replace({ params: { detail: resp.id } })
237
240
  }
238
241
  })
@@ -242,8 +245,8 @@ export default {
242
245
  this.$mapo.$snack.open({
243
246
  message: error.response?.data?.detail || this.$t("mapo.genericError"),
244
247
  color: "error"
245
- });
246
- });
248
+ })
249
+ }).finally(() => {this.buttonClicked = null;});;
247
250
  },
248
251
  deleteItem() {
249
252
  this.$mapo.$confirm
@@ -254,13 +257,14 @@ export default {
254
257
  })
255
258
  .then(res => {
256
259
  if (res) {
260
+ this.buttonClicked = "deleteBtn";
257
261
  this.crud
258
262
  .delete(this.identifier)
259
263
  .then(() => this.back())
260
264
  .catch(error => this.$mapo.$snack.open({
261
265
  message: error.response?.data?.detail || this.$t("mapo.genericError"),
262
266
  color: "error"
263
- }));
267
+ })).finally(()=> {this.buttonClicked = null;});
264
268
  }
265
269
  });
266
270
  },
@@ -274,6 +278,7 @@ export default {
274
278
  model(val) {
275
279
  // Fired when the v-model changes.
276
280
  // @arg Emits the entire payload modified.
281
+ console.log(val, "model")
277
282
  this.$emit("input", val);
278
283
  },
279
284
  lang(val) {
@@ -282,6 +287,7 @@ export default {
282
287
  }
283
288
  },
284
289
  value(val) {
290
+ console.log(val, "value")
285
291
  if (val) {
286
292
  this.model = val;
287
293
  }
@@ -301,7 +307,7 @@ export default {
301
307
  if (this.$mapo.$auth.routeMiddlewares.includes("permissions")) {
302
308
  return !this.$mapo.$auth.user.permissions.includes(this.isNew ? "add" : "change");
303
309
  }
304
- return false;
310
+ return !!this.buttonClicked;
305
311
  },
306
312
  canDelete() {
307
313
  if (this.$mapo.$auth.routeMiddlewares.includes("permissions")) {
@@ -8,7 +8,7 @@
8
8
  v-show="show(field)"
9
9
  :style="show(field, 'visibility') ? '' : 'opacity: 0; visibility: hidden;'"
10
10
  >
11
- <FormTabs
11
+ <FormTabs
12
12
  v-if="field.tabs"
13
13
  v-model="model"
14
14
  v-bind="{ currentLang, errors, languages, readonly }"
@@ -26,7 +26,7 @@
26
26
  v-slot:[slot]="props"
27
27
  >
28
28
  <slot :name="`group.${field.group.slug}.${slot}`" v-bind="props" />
29
- </template>
29
+ </template>
30
30
  </FormTabs>
31
31
  <FormGroup
32
32
  v-else-if="field.group"
@@ -46,9 +46,9 @@
46
46
  v-slot:[slot]="props"
47
47
  >
48
48
  <slot :name="`group.${field.group.slug}.${slot}`" v-bind="props" />
49
- </template>
49
+ </template>
50
50
  </FormGroup>
51
-
51
+
52
52
  <div v-else>
53
53
  <slot :name="field.slotName + '.before'" v-bind="{ conf: field, ...slotBindings, }" />
54
54
  <slot
@@ -72,7 +72,7 @@
72
72
  v-slot:[slot]="props"
73
73
  >
74
74
  <slot :name="`fields.${field.value}.${slot}`" v-bind="props" />
75
- </template>
75
+ </template>
76
76
  </FormField>
77
77
  </slot>
78
78
  <slot :name="field.slotName + '.after'" v-bind="{ conf: field, ...slotBindings, }" />
@@ -84,6 +84,7 @@
84
84
  import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
85
85
  import { slugify, titleCase } from "@mapomodule/utils/helpers/formatters";
86
86
  import { deepClone } from "@mapomodule/utils/helpers/objHelpers";
87
+ import { debounce } from "@mapomodule/utils/helpers/debounce";
87
88
 
88
89
  export default {
89
90
  name: "Form",
@@ -128,13 +129,17 @@ export default {
128
129
  this.initLang();
129
130
  },
130
131
  model(val) {
131
- this.$emit("input", val);
132
+ if (this.value !== val)
133
+ this.debouncedEmit("input", val);
132
134
  },
133
135
  fields(val){
134
136
  this.internalFields = this.cloneFields(val)
135
137
  }
136
138
  },
137
139
  methods: {
140
+ debouncedEmit: debounce(function (...args) {
141
+ this.$emit(...args);
142
+ }, 300),
138
143
  nameSpacedSlots,
139
144
  initLang(lang = this.currentLang) {
140
145
  if (lang && !this.model.translations) {
@@ -166,11 +171,9 @@ export default {
166
171
  parseTabs(tabs) {
167
172
  return Object.keys(tabs).map(key => {
168
173
  const tab = tabs[key]
169
- return {
170
- label: titleCase(key.replace(/_/, " ")),
171
- slug: key,
172
- ...tab.tab,
173
- fields: this.mapConf(Array.isArray(tab) && tab || tab.fields || [])
174
+ return {
175
+ tab: {label: titleCase(key.replace(/_/, " ")), slug: key, ...tab.tab},
176
+ fields: this.mapConf(Array.isArray(tab) && tab || tab.fields || [])
174
177
  }
175
178
  })
176
179
  },
@@ -182,7 +185,7 @@ export default {
182
185
  mapConf(fields) {
183
186
  return fields.map((f, i) =>
184
187
  f.tabs
185
- ? { group: this.parseTagsGroup(f), tabs: this.parseTabs(f.tabs) }
188
+ ? { group: this.parseTagsGroup(f), tabs: this.parseTabs(f.tabs) }
186
189
  : f.group
187
190
  ? { group: this.parseGroup(f.group), fields: this.mapConf(f.fields) }
188
191
  : this.parseConf(f, i)
@@ -191,7 +194,7 @@ export default {
191
194
  show(conf, type = "display"){
192
195
  const prop = type == "visibility" ? "vVisible" : "vShow"
193
196
  if (typeof conf[prop] == "function") {
194
- return conf[prop]({
197
+ return conf[prop]({
195
198
  model: this.model,
196
199
  errors: this.errors,
197
200
  languages: this.languages,
@@ -225,4 +228,4 @@ export default {
225
228
  this.initLang();
226
229
  }
227
230
  };
228
- </script>
231
+ </script>
@@ -36,6 +36,7 @@ import { getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
36
36
  import { titleCase } from "@mapomodule/utils/helpers/formatters";
37
37
 
38
38
  import defaults from "./defaults";
39
+ import { debounce } from "@mapomodule/utils/helpers/debounce";
39
40
 
40
41
  /**
41
42
  * This is mainly an internal component. It is used by the [`DetailComponent`](/components/detail/Detail/) in order to render dinamic fields inside the main form.
@@ -114,10 +115,13 @@ export default {
114
115
 
115
116
  // Fired when the v-model changes.
116
117
  // @arg Emits the entire payload modified.
117
- this.$emit("input", dump);
118
+ this.debouncedEmit("input", dump);
118
119
  },
119
120
  },
120
121
  methods: {
122
+ debouncedEmit: debounce(function (...args) {
123
+ this.$emit(...args);
124
+ }, 300),
121
125
  setModel(val = this.value) {
122
126
  var model = this.accessor.get({
123
127
  model: { ...val },
@@ -73,7 +73,8 @@ export default {
73
73
  this.model = val;
74
74
  },
75
75
  model(val) {
76
- this.$emit("input", val);
76
+ if (this.value !== val)
77
+ this.$emit("input", val);
77
78
  },
78
79
  },
79
80
  computed: {
@@ -12,13 +12,13 @@
12
12
  <v-tabs v-model="tabIndex" class="tab-wrapper">
13
13
  <v-tab v-for="(tab, index) in conf.tabs" :key="index" v-show="show(tab)">
14
14
  <v-badge :value="hasErrors(tab)" color="error" dot>
15
- {{ tab.label }} <v-icon v-if="tab.icon">{{ tab.icon }}</v-icon>
15
+ {{ tab.tab.label }} <v-icon v-if="tab.tab.icon">{{ tab.tab.icon }}</v-icon>
16
16
  </v-badge>
17
17
  </v-tab>
18
18
  </v-tabs>
19
19
  <v-tabs-items v-model="tabIndex">
20
20
  <v-tab-item v-for="(tab, index) in conf.tabs" :key="index" class="pt-8">
21
- <slot :name="`tab.${tab.slug}`" v-bind="slotBindings">
21
+ <slot :name="`tab.${tab.tab.slug}`" v-bind="slotBindings">
22
22
  <Form
23
23
  v-model="model"
24
24
  v-bind="{ currentLang, errors, languages, readonly }"
@@ -26,19 +26,19 @@
26
26
  :moreSlotBindings="slotBindings"
27
27
  >
28
28
  <template
29
- v-for="slot in nameSpacedSlots($slots, `tab.${tab.slug}.`)"
29
+ v-for="slot in nameSpacedSlots($slots, `tab.${tab.tab.slug}.`)"
30
30
  :slot="slot"
31
31
  >
32
- <slot :name="`tab.${tab.slug}.${slot}`"></slot>
32
+ <slot :name="`tab.${tab.tab.slug}.${slot}`"></slot>
33
33
  </template>
34
34
  <template
35
35
  v-for="slot in nameSpacedSlots(
36
36
  $scopedSlots,
37
- `tab.${tab.slug}.`
37
+ `tab.${tab.tab.slug}.`
38
38
  )"
39
39
  v-slot:[slot]="props"
40
40
  >
41
- <slot :name="`tab.${tab.slug}.${slot}`" v-bind="props" />
41
+ <slot :name="`tab.${tab.tab.slug}.${slot}`" v-bind="props" />
42
42
  </template>
43
43
  </Form>
44
44
  </slot>
@@ -101,7 +101,8 @@ export default {
101
101
  this.model = val;
102
102
  },
103
103
  model(val) {
104
- this.$emit("input", val);
104
+ if (this.value !== val)
105
+ this.$emit("input", val);
105
106
  },
106
107
  },
107
108
  computed: {
@@ -134,7 +135,7 @@ export default {
134
135
  show(conf, type = "display"){
135
136
  const prop = type == "visibility" ? "vVisible" : "vShow"
136
137
  if (typeof conf[prop] == "function") {
137
- return conf[prop]({
138
+ return conf[prop]({
138
139
  model: this.model,
139
140
  errors: this.errors,
140
141
  languages: this.languages,
@@ -148,4 +149,4 @@ export default {
148
149
  this.model = this.value;
149
150
  },
150
151
  };
151
- </script>
152
+ </script>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div ref="repeater" class="container pa-0">
2
+ <div class="container pa-0">
3
3
  <div class="d-flex justify-space-between">
4
4
  <span class="repeater-label">{{ label }}:</span>
5
5
  <v-btn v-if="collapsable" outlined tile text small @click="collapseAll"
@@ -10,27 +10,27 @@
10
10
  v-model="items"
11
11
  handle=".repeater-handle-sort"
12
12
  animation="150"
13
- @change="sortCallback({ ...$event, items, eventType: 'move' })"
13
+ @change="draggableReorder($event)"
14
14
  :style="maxHeightStyle"
15
15
  >
16
16
  <div
17
17
  class="repeater-line-wrapper"
18
- :class="{ expanded: !collapsable }"
18
+ :class="{ expanded: !collapsable || isExpanded(index) }"
19
19
  v-for="(model, index) in items"
20
20
  :key="index"
21
21
  >
22
22
  <div class="d-flex">
23
23
  <div v-if="collapsable" class="collapsed-preview">
24
- <v-icon class="expand-icon" @click.native="toggleExpand($event)"
24
+ <v-icon class="expand-icon" @click.native="toggleExpand(index)"
25
25
  >mdi-chevron-down</v-icon
26
26
  >
27
27
  <span
28
28
  class="v-label collapsed-label"
29
- @click="toggleExpand($event, true)"
29
+ @click="toggleExpand(index, true)"
30
30
  v-html="getCollapsedLabel(model, index)"
31
31
  ></span>
32
32
  </div>
33
- <div class="repeater-fields container">
33
+ <div v-if="isExpanded(index)" class="repeater-fields container">
34
34
  <Form
35
35
  v-model="items[index]"
36
36
  :currentLang="translatable ? currentLang : null"
@@ -189,16 +189,16 @@
189
189
  }
190
190
  }
191
191
  &.expanded {
192
- .expand-icon {
192
+ > div > div >.expand-icon {
193
193
  transform: rotate(180deg);
194
194
  }
195
- .collapsed-label {
195
+ > div > div > .collapsed-label {
196
196
  display: none;
197
197
  }
198
- .repeater-fields {
198
+ > div > .repeater-fields {
199
199
  display: flex;
200
200
  }
201
- .collapsed-preview {
201
+ > div > .collapsed-preview {
202
202
  flex-basis: 0;
203
203
  }
204
204
  }
@@ -265,6 +265,7 @@ export default {
265
265
  items: null,
266
266
  tModalOpen: false,
267
267
  tModalCallback: () => {},
268
+ collapsedStack: (this.value || []).map(() => !!this.collapsable)
268
269
  };
269
270
  },
270
271
  props: {
@@ -317,6 +318,8 @@ export default {
317
318
  watch: {
318
319
  value(val) {
319
320
  this.items = val;
321
+ if (val.length != this.collapsedStack.length)
322
+ this.collapsedStack = (val || []).map(() => !!this.collapsable)
320
323
  },
321
324
  items(val) {
322
325
  this.$emit("input", val);
@@ -326,6 +329,9 @@ export default {
326
329
  },
327
330
  },
328
331
  methods: {
332
+ isExpanded(index){
333
+ return !this.collapsedStack[index];
334
+ },
329
335
  async addItem(index) {
330
336
  const element = {};
331
337
  if (this.hasTemplates) {
@@ -335,10 +341,7 @@ export default {
335
341
  }
336
342
  const newIndex = typeof index == "number" ? index : this.items.length;
337
343
  this.items.splice(newIndex, 0, element);
338
- this.$nextTick(() => {
339
- const line = this.$refs.repeater.querySelectorAll(".repeater-line-wrapper")[newIndex];
340
- line && line.classList.add("expanded");
341
- });
344
+ this.collapsedStack.splice(newIndex, 0, false)
342
345
  this.sortable &&
343
346
  this.sortCallback({
344
347
  moved: { element, newIndex },
@@ -349,6 +352,7 @@ export default {
349
352
  removeItem(index) {
350
353
  const element = this.items[index];
351
354
  this.items.splice(index, 1);
355
+ this.collapsedStack.splice(index, 1);
352
356
  this.sortable &&
353
357
  this.sortCallback({
354
358
  moved: { element, oldIndex: index },
@@ -395,13 +399,19 @@ export default {
395
399
  return getPointed(model, field.value, fallback);
396
400
  }
397
401
  },
398
- toggleExpand(event, forceValue) {
399
- const action = forceValue == undefined ? "toggle" : forceValue ? "add" : "remove";
400
- const target = event.target.closest(".repeater-line-wrapper");
401
- target && target.classList[action]("expanded");
402
+ draggableReorder(event) {
403
+ const { newIndex, oldIndex } = event.moved;
404
+ const stackItem = this.collapsedStack[oldIndex];
405
+ this.collapsedStack.splice(oldIndex, 1);
406
+ this.collapsedStack.splice(newIndex, 0, stackItem);
407
+ this.sortCallback({ ...event, items: this.items, eventType: 'move' })
408
+ },
409
+ toggleExpand(index, forceValue) {
410
+ this.collapsedStack[index] = forceValue == undefined ? !this.collapsedStack[index] : !forceValue;
411
+ this.collapsedStack = [...this.collapsedStack];
402
412
  },
403
413
  collapseAll() {
404
- this.$refs.repeater.querySelectorAll(".repeater-line-wrapper").forEach((e) => e.classList.remove("expanded"));
414
+ this.collapsedStack = this.collapsedStack.map(() => true)
405
415
  },
406
416
  },
407
417
  computed: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "1.0.0-alpha.27",
3
+ "version": "1.0.0-alpha.28",
4
4
  "license": "MIT",
5
5
  "description": "This is part of Mapo nuxt module. Injects Mapo ui components in the nuxt component discovery system.",
6
6
  "author": "bnznamco <gabriele.baldi.01@gmail.com>",
@@ -15,5 +15,5 @@
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "gitHead": "d028345c7ee4cdf43dac3e68d27d4b9f1ad4198c"
18
+ "gitHead": "5d5b4490d8025f6f2740eed7a4c3b31ab58ec2c6"
19
19
  }
@@ -20,6 +20,8 @@ export default {
20
20
  saveContinue: "Save and continue",
21
21
  back: "Back",
22
22
  genericError: "Something whent bad, please try again later...",
23
+ saveSuccess: "Item saved succesfully!",
24
+ createSuccess: "Item succesfully created!",
23
25
  confirmDelete: "Are you sure you want to delete this item?",
24
26
  fetchingData: "Fetching data...",
25
27
  login: "Login",
@@ -20,6 +20,8 @@ export default {
20
20
  saveContinue: "Salva e continua",
21
21
  back: "Indietro",
22
22
  genericError: "Qualcosa è andato storto, riprova più tardi...",
23
+ saveSuccess: "Elemento salvato con successo!",
24
+ createSuccess: "Elemento creato con successo!",
23
25
  confirmDelete: "Vuoi veramente eliminare questo elemento?",
24
26
  fetchingData: "Caricamento in corso...",
25
27
  login: "Login",