@mapomodule/uikit 1.0.0-alpha.18 → 1.0.0-alpha.20
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,29 @@
|
|
|
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.20](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.19...v1.0.0-alpha.20) (2022-04-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **repeater:** added multilanguage capabilities to Repeater Field ([4736d52](https://github.com/lotrekagency/mapo/commit/4736d52c0ef78adb0ac856056b950e7cfe7bfac1))
|
|
12
|
+
* **repeater:** added templates to repeater to compose rows block by block ([c2546b1](https://github.com/lotrekagency/mapo/commit/c2546b1f04f303ed4728624367de3b05010473e3))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [1.0.0-alpha.19](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.18...v1.0.0-alpha.19) (2022-04-06)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* fix repeater field in production build ([7c10bcb](https://github.com/lotrekagency/mapo/commit/7c10bcb02aa5332247a6a6652a7aa834935d707e))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
# [1.0.0-alpha.18](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.17...v1.0.0-alpha.18) (2022-04-04)
|
|
7
30
|
|
|
8
31
|
|
|
@@ -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
|
|
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
|
|
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
|
|
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,11 +178,15 @@ import draggable from "vuedraggable";
|
|
|
137
178
|
export default {
|
|
138
179
|
name: "Repeater",
|
|
139
180
|
components: {
|
|
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"),
|
|
140
183
|
draggable,
|
|
141
184
|
},
|
|
142
185
|
data() {
|
|
143
186
|
return {
|
|
144
187
|
items: null,
|
|
188
|
+
tModalOpen: false,
|
|
189
|
+
tModalCallback: () => {},
|
|
145
190
|
};
|
|
146
191
|
},
|
|
147
192
|
props: {
|
|
@@ -153,7 +198,7 @@ export default {
|
|
|
153
198
|
// The main configuration that determines the arrangement of the fields in each line.
|
|
154
199
|
fields: {
|
|
155
200
|
// [`Array<FieldConfiguration>`](/components/Detail/Detail/#fieldconfiguration)
|
|
156
|
-
type: Array,
|
|
201
|
+
type: Array | Object,
|
|
157
202
|
default: () => [],
|
|
158
203
|
},
|
|
159
204
|
// Puts the input in an error state and passes through custom error messages.
|
|
@@ -167,11 +212,18 @@ export default {
|
|
|
167
212
|
readonly: Boolean,
|
|
168
213
|
// Makes the repeater field sortable.
|
|
169
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
|
+
multilang: Boolean,
|
|
170
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.
|
|
171
218
|
sortCallback: {
|
|
172
219
|
type: Function,
|
|
173
220
|
default: () => {},
|
|
174
221
|
},
|
|
222
|
+
langs: {
|
|
223
|
+
type: Array,
|
|
224
|
+
default: () => [],
|
|
225
|
+
},
|
|
226
|
+
currentLang: String,
|
|
175
227
|
},
|
|
176
228
|
watch: {
|
|
177
229
|
value(val) {
|
|
@@ -180,10 +232,18 @@ export default {
|
|
|
180
232
|
items(val) {
|
|
181
233
|
this.$emit("input", val);
|
|
182
234
|
},
|
|
235
|
+
tModalOpen(val) {
|
|
236
|
+
!val && this.tModalCallback();
|
|
237
|
+
},
|
|
183
238
|
},
|
|
184
239
|
methods: {
|
|
185
|
-
addItem(index) {
|
|
240
|
+
async addItem(index) {
|
|
186
241
|
const element = {};
|
|
242
|
+
if (this.hasTemplates) {
|
|
243
|
+
const template = await this.chooseTemplate();
|
|
244
|
+
if (!template) return;
|
|
245
|
+
element[template.tCodeField] = template.tCode;
|
|
246
|
+
}
|
|
187
247
|
const newIndex = typeof index == "number" ? index : this.items.length;
|
|
188
248
|
this.items.splice(newIndex, 0, element);
|
|
189
249
|
this.sortable &&
|
|
@@ -203,34 +263,72 @@ export default {
|
|
|
203
263
|
eventType: "remove",
|
|
204
264
|
});
|
|
205
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
|
+
},
|
|
206
276
|
getErrors(index) {
|
|
207
277
|
return (this.errorMessages || [])[index] || {};
|
|
208
278
|
},
|
|
209
279
|
parseConf(field, i) {
|
|
210
280
|
const conf = typeof field === "string" ? { value: field } : field;
|
|
211
281
|
conf.value = conf.value || "";
|
|
282
|
+
conf.value = this.multilang ? conf.value.replace(new RegExp(`^translations\.(${this.langs.join("|")})\.?`), "") : conf.value;
|
|
212
283
|
conf.slotName = `fields.${conf.value || i}`;
|
|
284
|
+
if (this.multilang && this.currentLang && !field.synci18n) {
|
|
285
|
+
const base = `translations.${this.currentLang}`;
|
|
286
|
+
conf.value = (conf.value && `${base}.${conf.value}`) || base;
|
|
287
|
+
}
|
|
213
288
|
if (this.readonly) {
|
|
214
289
|
conf.attrs = { ...conf.attrs, readonly: true };
|
|
215
290
|
}
|
|
216
291
|
return conf;
|
|
217
292
|
},
|
|
218
293
|
mapConf(fields) {
|
|
294
|
+
fields = this.multilang ? JSON.parse(JSON.stringify(fields)) : fields; // this hack fixes rendering loop on multilang scenario. :/
|
|
219
295
|
const icon = "mdi-cube-outline";
|
|
220
|
-
const parseGroup = (group) =>
|
|
221
|
-
typeof group === "string"
|
|
222
|
-
? { name: group, icon }
|
|
223
|
-
: { ...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 };
|
|
224
297
|
return fields.map((f, i) =>
|
|
225
298
|
f.group
|
|
226
299
|
? { group: parseGroup(f.group), fields: this.mapConf(f.fields) }
|
|
227
300
|
: this.parseConf(f, i)
|
|
228
301
|
);
|
|
229
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
|
+
},
|
|
230
310
|
},
|
|
231
311
|
computed: {
|
|
232
|
-
|
|
233
|
-
return this.
|
|
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);
|
|
234
332
|
},
|
|
235
333
|
},
|
|
236
334
|
mounted() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/uikit",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20",
|
|
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": "
|
|
17
|
+
"gitHead": "8f3b7f4cfbde70e26be50593eaf8238b7ccf5c18"
|
|
18
18
|
}
|