@mapomodule/uikit 1.0.0-alpha.19 → 1.0.0-alpha.21

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,26 @@
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.21](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.20...v1.0.0-alpha.21) (2022-04-25)
7
+
8
+ **Note:** Version bump only for package @mapomodule/uikit
9
+
10
+
11
+
12
+
13
+
14
+ # [1.0.0-alpha.20](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.19...v1.0.0-alpha.20) (2022-04-25)
15
+
16
+
17
+ ### Features
18
+
19
+ * **repeater:** added multilanguage capabilities to Repeater Field ([4736d52](https://github.com/lotrekagency/mapo/commit/4736d52c0ef78adb0ac856056b950e7cfe7bfac1))
20
+ * **repeater:** added templates to repeater to compose rows block by block ([c2546b1](https://github.com/lotrekagency/mapo/commit/c2546b1f04f303ed4728624367de3b05010473e3))
21
+
22
+
23
+
24
+
25
+
6
26
  # [1.0.0-alpha.19](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.18...v1.0.0-alpha.19) (2022-04-06)
7
27
 
8
28
 
@@ -72,6 +72,8 @@
72
72
  <!-- A [`DetailField`](/components/detail/DetailField/) configured by a [`FieldConfiguration`](#fieldconfiguration). -->
73
73
  <DetailField
74
74
  v-model="model"
75
+ :langs="langs"
76
+ :currentLang="currentLang"
75
77
  :conf="fields"
76
78
  :errors="errors"
77
79
  />
@@ -88,7 +90,13 @@
88
90
  ...slotBindings,
89
91
  }"
90
92
  >
91
- <DetailField v-model="model" :conf="field" :errors="errors" />
93
+ <DetailField
94
+ v-model="model"
95
+ :langs="langs"
96
+ :currentLang="currentLang"
97
+ :conf="field"
98
+ :errors="errors"
99
+ />
92
100
  </slot>
93
101
  </div>
94
102
  </div>
@@ -173,6 +181,8 @@
173
181
  >
174
182
  <DetailField
175
183
  v-model="model"
184
+ :langs="langs"
185
+ :currentLang="currentLang"
176
186
  :conf="fields"
177
187
  :errors="errors"
178
188
  />
@@ -189,7 +199,13 @@
189
199
  ...slotBindings,
190
200
  }"
191
201
  >
192
- <DetailField v-model="model" :conf="field" :errors="errors" />
202
+ <DetailField
203
+ v-model="model"
204
+ :langs="langs"
205
+ :currentLang="currentLang"
206
+ :conf="field"
207
+ :errors="errors"
208
+ />
193
209
  </slot>
194
210
  </div>
195
211
  </div>
@@ -62,6 +62,11 @@ export default {
62
62
  type: Object,
63
63
  required: true,
64
64
  },
65
+ langs: {
66
+ type: Array,
67
+ default: () => []
68
+ },
69
+ currentLang: String
65
70
  },
66
71
  watch: {
67
72
  value: {
@@ -129,6 +134,8 @@ export default {
129
134
  this.is.replace(/-./g, (x) => x[1].toUpperCase())
130
135
  ] || {}),
131
136
  ...this.conf.attrs,
137
+ currentLang: this.currentLang,
138
+ langs: this.langs,
132
139
  };
133
140
  },
134
141
  label() {
@@ -61,6 +61,8 @@
61
61
  <!-- A [`DetailField`](/components/detail/DetailField/) configured by a [`FieldConfiguration`](#fieldconfiguration). -->
62
62
  <DetailField
63
63
  v-model="model"
64
+ :langs="langs"
65
+ :currentLang="currentLang"
64
66
  :conf="fields"
65
67
  :errors="errors"
66
68
  />
@@ -79,6 +81,8 @@
79
81
  >
80
82
  <DetailField
81
83
  v-model="model"
84
+ :langs="langs"
85
+ :currentLang="currentLang"
82
86
  :conf="field"
83
87
  :errors="errors"
84
88
  />
@@ -17,7 +17,7 @@
17
17
  <v-divider vertical />
18
18
  <div class="row ma-0">
19
19
  <div
20
- v-for="(field, i) in parsedFields"
20
+ v-for="(field, i) in parseFields(model)"
21
21
  :key="i"
22
22
  :class="field.class || 'col-12'"
23
23
  >
@@ -86,6 +86,38 @@
86
86
  <v-icon>mdi-plus</v-icon> Add</v-btn
87
87
  >
88
88
  </div>
89
+ <v-dialog v-if="hasTemplates" v-model="tModalOpen" width="600" scrollable>
90
+ <v-card>
91
+ <v-card-title class="text-h5"> Select template </v-card-title>
92
+ <v-card-text>
93
+ <div class="row mt-4">
94
+ <div
95
+ v-for="(template, i) in templates"
96
+ :key="i"
97
+ class="col-12 col-md-6 pa-0"
98
+ >
99
+ <div @click="tModalCallback(template)" class="template-button">
100
+ <span class="text-h5">{{ template.name }}</span
101
+ ><br />
102
+ <span>{{ template.description }}</span>
103
+ <v-img
104
+ v-if="template.preview"
105
+ max-height="150"
106
+ min-width="250px"
107
+ :src="template.preview"
108
+ />
109
+ <v-skeleton-loader
110
+ v-else
111
+ boilerplate
112
+ min-width="250px"
113
+ type="list-item-avatar-three-line"
114
+ />
115
+ </div>
116
+ </div>
117
+ </div>
118
+ </v-card-text>
119
+ </v-card>
120
+ </v-dialog>
89
121
  </div>
90
122
  </template>
91
123
 
@@ -126,6 +158,15 @@
126
158
  .repeater-add-line {
127
159
  border-top: none;
128
160
  }
161
+ .template-button {
162
+ padding: 0.5rem;
163
+ margin: 3px;
164
+ border: solid 1px #393939;
165
+ cursor: pointer;
166
+ }
167
+ .theme--light .template-button {
168
+ border-color: #e0e0e0;
169
+ }
129
170
  </style>
130
171
 
131
172
  <script>
@@ -137,13 +178,15 @@ import draggable from "vuedraggable";
137
178
  export default {
138
179
  name: "Repeater",
139
180
  components: {
140
- // For recursive dynamic components is better to resolve dependency tree at runtime :P
141
- DetailField: () => import('@mapomodule/uikit/components/Detail/DetailField.vue'),
181
+ // For recursive dynamic components is better to resolve dependencies at runtime to avoid circular deps
182
+ DetailField: () => import("@mapomodule/uikit/components/Detail/DetailField.vue"),
142
183
  draggable,
143
184
  },
144
185
  data() {
145
186
  return {
146
187
  items: null,
188
+ tModalOpen: false,
189
+ tModalCallback: () => {},
147
190
  };
148
191
  },
149
192
  props: {
@@ -155,7 +198,7 @@ export default {
155
198
  // The main configuration that determines the arrangement of the fields in each line.
156
199
  fields: {
157
200
  // [`Array<FieldConfiguration>`](/components/Detail/Detail/#fieldconfiguration)
158
- type: Array,
201
+ type: Array | Object,
159
202
  default: () => [],
160
203
  },
161
204
  // Puts the input in an error state and passes through custom error messages.
@@ -169,11 +212,18 @@ export default {
169
212
  readonly: Boolean,
170
213
  // Makes the repeater field sortable.
171
214
  sortable: Boolean,
215
+ // Make the repeater multilanguage. This means that it's going to inherit the languages and the current language from the parent detail component, creating the translations for each line of the repeater.
216
+ translatable: Boolean,
172
217
  // This callback is called during sort/add/remove item if the Repeater is sortable. Use this callback to change some prop of the items in the list.
173
218
  sortCallback: {
174
219
  type: Function,
175
220
  default: () => {},
176
221
  },
222
+ langs: {
223
+ type: Array,
224
+ default: () => [],
225
+ },
226
+ currentLang: String,
177
227
  },
178
228
  watch: {
179
229
  value(val) {
@@ -182,10 +232,18 @@ export default {
182
232
  items(val) {
183
233
  this.$emit("input", val);
184
234
  },
235
+ tModalOpen(val) {
236
+ !val && this.tModalCallback();
237
+ },
185
238
  },
186
239
  methods: {
187
- addItem(index) {
240
+ async addItem(index) {
188
241
  const element = {};
242
+ if (this.hasTemplates) {
243
+ const template = await this.chooseTemplate();
244
+ if (!template) return;
245
+ element[template.tCodeField] = template.tCode;
246
+ }
189
247
  const newIndex = typeof index == "number" ? index : this.items.length;
190
248
  this.items.splice(newIndex, 0, element);
191
249
  this.sortable &&
@@ -205,34 +263,72 @@ export default {
205
263
  eventType: "remove",
206
264
  });
207
265
  },
266
+ async chooseTemplate() {
267
+ this.tModalOpen = true;
268
+ return new Promise((resolve) => {
269
+ this.tModalCallback = function (template) {
270
+ resolve(template);
271
+ this.tModalCallback = () => {};
272
+ this.tModalOpen = false;
273
+ };
274
+ });
275
+ },
208
276
  getErrors(index) {
209
277
  return (this.errorMessages || [])[index] || {};
210
278
  },
211
279
  parseConf(field, i) {
212
280
  const conf = typeof field === "string" ? { value: field } : field;
213
281
  conf.value = conf.value || "";
282
+ conf.value = this.translatable ? conf.value.replace(new RegExp(`^translations\.(${this.langs.join("|")})\.?`), "") : conf.value;
214
283
  conf.slotName = `fields.${conf.value || i}`;
284
+ if (this.translatable && this.currentLang && !field.synci18n) {
285
+ const base = `translations.${this.currentLang}`;
286
+ conf.value = (conf.value && `${base}.${conf.value}`) || base;
287
+ }
215
288
  if (this.readonly) {
216
289
  conf.attrs = { ...conf.attrs, readonly: true };
217
290
  }
218
291
  return conf;
219
292
  },
220
293
  mapConf(fields) {
294
+ fields = this.translatable ? JSON.parse(JSON.stringify(fields)) : fields; // this hack fixes rendering loop on translatable repeater. :/
221
295
  const icon = "mdi-cube-outline";
222
- const parseGroup = (group) =>
223
- typeof group === "string"
224
- ? { name: group, icon }
225
- : { ...group, icon: group.icon !== undefined ? group.icon : icon };
296
+ const parseGroup = (group) => typeof group === "string" ? { name: group, icon } : { ...group, icon: group.icon !== undefined ? group.icon : icon };
226
297
  return fields.map((f, i) =>
227
298
  f.group
228
299
  ? { group: parseGroup(f.group), fields: this.mapConf(f.fields) }
229
300
  : this.parseConf(f, i)
230
301
  );
231
302
  },
303
+ parseFields(model) {
304
+ if (this.hasTemplates) {
305
+ const template = this.templates.find(t => model[t.tCodeField] == t.tCode)
306
+ return template ? this.mapConf(template.fields) : [];
307
+ }
308
+ return this.mapConf(this.fields);
309
+ },
232
310
  },
233
311
  computed: {
234
- parsedFields() {
235
- return this.mapConf(this.fields);
312
+ hasTemplates() {
313
+ return typeof this.fields == "object" && !Array.isArray(this.fields);
314
+ },
315
+ templates() {
316
+ const templates = {};
317
+ if (this.hasTemplates) {
318
+ const titleCase = (string) => (string && string[0].toUpperCase() + string.slice(1).toLowerCase()) || "";
319
+ Object.keys(this.fields).forEach((tKey) => {
320
+ const tValue = this.fields[tKey];
321
+ const { preview, description } = tValue;
322
+ templates[tKey] = {
323
+ fields: tValue.fields || tValue,
324
+ name: tValue.name || titleCase(tKey.replace(/_/, " ")),
325
+ tCode: tValue.tCode || tKey,
326
+ tCodeField: tValue.tCodeField || "tCode",
327
+ preview, description,
328
+ };
329
+ });
330
+ }
331
+ return Object.values(templates);
236
332
  },
237
333
  },
238
334
  mounted() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "1.0.0-alpha.19",
3
+ "version": "1.0.0-alpha.21",
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>",
@@ -14,5 +14,5 @@
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
- "gitHead": "3bc598b7ecb64c67a164b438847eb237f78efc75"
17
+ "gitHead": "2331ccbff7c6f457455c42831981eec9f5ed6570"
18
18
  }