@mapomodule/uikit 1.0.0-alpha.4 → 1.0.0-alpha.40
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 +730 -0
- package/components/ConfirmDialog.vue +12 -16
- package/components/Detail/Detail.vue +406 -272
- package/components/Detail/DetailLangSwitch.vue +7 -2
- package/components/DropArea.vue +63 -56
- package/components/Form/Form.vue +218 -0
- package/components/Form/FormField.vue +213 -0
- package/components/Form/FormGroup.vue +146 -0
- package/components/Form/FormTabs.vue +188 -0
- package/components/Form/defaults.js +91 -0
- package/components/Form/fields/ColorField.vue +79 -0
- package/components/{fields → Form/fields}/DateField.vue +20 -11
- package/components/Form/fields/EnhancedMediaField.vue +224 -0
- package/components/Form/fields/FileField.vue +125 -0
- package/components/Form/fields/FksField.vue +88 -0
- package/components/Form/fields/MediaField.vue +159 -0
- package/components/Form/fields/MediaM2mField.vue +149 -0
- package/components/Form/fields/Repeater.vue +593 -0
- package/components/Form/fields/SeoPreview.vue +89 -0
- package/components/Form/fields/wygEditor/defaults.js +25 -0
- package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/events.js +0 -0
- package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/mapomedia.plugin.js +7 -6
- package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/script.injector.js +0 -0
- package/components/Form/fields/wygEditor/wygEditor.vue +285 -0
- package/components/LangSwitcher.vue +44 -0
- package/components/List/List.vue +119 -42
- package/components/List/ListActions.vue +60 -21
- package/components/List/ListFilters.vue +166 -114
- package/components/List/ListHead.vue +30 -12
- package/components/List/ListQuickEdit.vue +130 -61
- package/components/List/ListTable.vue +292 -80
- package/components/Login.vue +17 -7
- package/components/LogoutButton.vue +42 -28
- package/components/MediaManager/MediaBreadcrumbs.vue +45 -0
- package/components/MediaManager/MediaEditor.vue +282 -121
- package/components/MediaManager/MediaFolders.vue +169 -116
- package/components/MediaManager/MediaGallery.vue +151 -146
- package/components/MediaManager/MediaManager.vue +117 -159
- package/components/MediaManager/MediaManagerDialog.vue +36 -31
- package/components/MediaManager/MediaPreview.vue +203 -0
- package/components/MediaManager/MediaUploader.vue +55 -43
- package/components/SnackBar.vue +5 -7
- package/components/ThemeToggle.vue +13 -0
- package/components/layout/Sidebar/Sidebar.vue +61 -30
- package/components/layout/Sidebar/SidebarList.vue +19 -15
- package/components/layout/Sidebar/SidebarListItem.vue +111 -39
- package/components/layout/Sidebar/SidebarProfile.vue +42 -0
- package/components/layout/Sidebar/SidebarTitle.vue +45 -0
- package/components/layout/Topbar/Topbar.vue +11 -42
- package/components/layout/routebuilder.js +3 -3
- package/defaults/i18n.js +37 -0
- package/defaults/vuetify.js +34 -0
- package/layouts/default.vue +33 -18
- package/layouts/empty.vue +10 -0
- package/module.js +7 -5
- package/package.json +6 -4
- package/pages/index.vue +19 -18
- package/static/{favicon.ico → mapo/favicon.ico} +0 -0
- package/static/mapo/tinymce-skins/mapo-dark/content.inline.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-dark/content.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-dark/content.mobile.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-dark/skin.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-dark/skin.mobile.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-light/content.inline.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-light/content.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-light/content.mobile.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-light/skin.min.css +7 -0
- package/static/mapo/tinymce-skins/mapo-light/skin.mobile.min.css +7 -0
- package/translations/en-US.js +134 -0
- package/translations/it-IT.js +136 -0
- package/components/Detail/DetailField.vue +0 -129
- package/components/Detail/defaults.js +0 -50
- package/components/fields/M2mField.vue +0 -95
- package/components/fields/MediaField.vue +0 -195
- package/components/fields/MediaM2mField.vue +0 -238
- package/components/fields/TinyMce/TinyMce.vue +0 -177
- package/components/fields/TinyMce/defaults.js +0 -55
- package/components/layout/Sidebar/SidebarFooter.vue +0 -75
- package/defaults.js +0 -29
- package/layouts/error.vue +0 -45
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<v-tabs v-model="tab">
|
|
2
|
+
<v-tabs v-model="tab" show-arrows>
|
|
3
3
|
<v-tab v-for="lang in langs" :key="lang">
|
|
4
4
|
<v-badge :value="hasErrors(lang)" color="error" dot>
|
|
5
5
|
{{ lang }}
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
</v-tabs>
|
|
9
9
|
</template>
|
|
10
10
|
|
|
11
|
+
<style lang="scss">
|
|
12
|
+
.theme--light.mapo-detail--language-tabs.v-tabs > .v-tabs-bar {
|
|
13
|
+
background: #f5f5f5;
|
|
14
|
+
}
|
|
15
|
+
</style>
|
|
11
16
|
<script>
|
|
12
17
|
import { getPointed } from "@mapomodule/utils/helpers/objHelpers";
|
|
13
18
|
/**
|
|
@@ -26,7 +31,7 @@ export default {
|
|
|
26
31
|
// A list of languages into which the payload needs to be translated.
|
|
27
32
|
langs: {
|
|
28
33
|
type: Array,
|
|
29
|
-
default
|
|
34
|
+
default() { return this.$mapo.$options?.content?.languages || []; }
|
|
30
35
|
},
|
|
31
36
|
// An object representing all the errors of all fields. This component will find errors in each language and will display a little dot in the tab if there are any errors.
|
|
32
37
|
errors: Object,
|
package/components/DropArea.vue
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<v-icon :class="[dragover ? 'mt-2, mb-6' : 'mt-5']" size="60">
|
|
20
20
|
mdi-cloud-upload
|
|
21
21
|
</v-icon>
|
|
22
|
-
<p>
|
|
22
|
+
<p>{{ $t("mapo.dropArea.dropOrClick") }}</p>
|
|
23
23
|
<input
|
|
24
24
|
type="file"
|
|
25
25
|
style="display: none"
|
|
@@ -30,37 +30,45 @@
|
|
|
30
30
|
</v-row>
|
|
31
31
|
<v-virtual-scroll
|
|
32
32
|
:items="uploadedFiles"
|
|
33
|
-
:height="
|
|
34
|
-
uploadedFiles.length * 64 > 256 ? 256 : uploadedFiles.length * 64
|
|
35
|
-
"
|
|
33
|
+
:height="uploadedFiles.length * 64 > 256 ? 256 : uploadedFiles.length * 64"
|
|
36
34
|
item-height="64"
|
|
37
35
|
>
|
|
38
|
-
<template v-slot:default="
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
<template v-slot:default="ctx">
|
|
37
|
+
<slot name="list-item.before" v-bind="{...ctx, editItem, removeItem}"/>
|
|
38
|
+
<slot name="list-item" v-bind="{...ctx, editItem, removeItem}">
|
|
39
|
+
<v-list-item :key="ctx.item.info.name" class="drop-area--item">
|
|
40
|
+
<slot name="list-item.preview.before" v-bind="{...ctx, editItem, removeItem}"/>
|
|
41
|
+
<slot name="list-item.preview" v-bind="{...ctx, editItem, removeItem}">
|
|
42
|
+
<v-list-item-avatar tile v-if="ctx.item.info.objectURL">
|
|
43
|
+
<v-img :src="ctx.item.info.objectURL"></v-img>
|
|
44
|
+
</v-list-item-avatar>
|
|
45
|
+
</slot>
|
|
46
|
+
<slot name="list-item.preview.after" v-bind="{...ctx, editItem, removeItem}"/>
|
|
47
|
+
<slot name="list-item.content.before" v-bind="{...ctx, editItem, removeItem}"/>
|
|
48
|
+
<slot name="list-item.content" v-bind="{...ctx, editItem, removeItem}">
|
|
49
|
+
<v-list-item-content class="cursor-pointer" @click.stop="editItem(ctx.item)">
|
|
50
|
+
<v-list-item-title>
|
|
51
|
+
{{ ctx.item.info.name }}
|
|
52
|
+
</v-list-item-title>
|
|
53
|
+
<v-list-item-subtitle>
|
|
54
|
+
{{ ctx.item.info.type || "type/unknow" }}, {{ ctx.item.info.size }}
|
|
55
|
+
</v-list-item-subtitle>
|
|
56
|
+
</v-list-item-content>
|
|
57
|
+
</slot>
|
|
58
|
+
<slot name="list-item.content.after" v-bind="{...ctx, editItem, removeItem}"/>
|
|
59
|
+
<slot name="list-item.action.before" v-bind="{...ctx, editItem, removeItem}"/>
|
|
60
|
+
<slot name="list-item.action" v-bind="{...ctx, editItem, removeItem}">
|
|
61
|
+
<v-list-item-action>
|
|
62
|
+
<v-btn @click.stop="removeItem(ctx.item.info.name)" icon>
|
|
63
|
+
<v-icon> mdi-close-circle </v-icon>
|
|
64
|
+
</v-btn>
|
|
65
|
+
</v-list-item-action>
|
|
66
|
+
</slot>
|
|
67
|
+
<slot name="list-item.action.after" v-bind="{...ctx, editItem, removeItem}"/>
|
|
43
68
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
>
|
|
48
|
-
<v-list-item-title>
|
|
49
|
-
{{ item.info.name }}
|
|
50
|
-
</v-list-item-title>
|
|
51
|
-
<v-list-item-subtitle>
|
|
52
|
-
{{ item.info.type || "type/unknow" }}, {{ item.info.size }}
|
|
53
|
-
</v-list-item-subtitle>
|
|
54
|
-
</v-list-item-content>
|
|
55
|
-
|
|
56
|
-
<v-list-item-action>
|
|
57
|
-
<v-btn @click.stop="removeFile(item.info.name)" icon>
|
|
58
|
-
<v-icon> mdi-close-circle </v-icon>
|
|
59
|
-
</v-btn>
|
|
60
|
-
</v-list-item-action>
|
|
61
|
-
</v-list-item>
|
|
62
|
-
|
|
63
|
-
<v-divider></v-divider>
|
|
69
|
+
</v-list-item>
|
|
70
|
+
</slot>
|
|
71
|
+
<slot name="list-item.after" v-bind="{...ctx, editItem, removeItem}"/>
|
|
64
72
|
</template>
|
|
65
73
|
</v-virtual-scroll>
|
|
66
74
|
</v-card-text>
|
|
@@ -69,16 +77,12 @@
|
|
|
69
77
|
<!-- Slot to provide custom button actions inside the drop area -->
|
|
70
78
|
<slot v-bind:clearList="clearList" name="actions">
|
|
71
79
|
<!-- `<v-btn @click="clearList" icon><v-icon>mdi-close</v-icon></v-btn>` -->
|
|
72
|
-
<v-btn @click="clearList" icon>
|
|
80
|
+
<v-btn v-if="uploadedFiles && uploadedFiles.length" @click="clearList" icon>
|
|
73
81
|
<v-icon>mdi-close</v-icon>
|
|
74
82
|
</v-btn>
|
|
75
83
|
</slot>
|
|
76
84
|
</v-card-actions>
|
|
77
|
-
<v-dialog
|
|
78
|
-
v-model="editDialog"
|
|
79
|
-
v-bind="{ light, dark, elevation }"
|
|
80
|
-
max-width="500px"
|
|
81
|
-
>
|
|
85
|
+
<v-dialog v-model="editDialog" v-bind="{ light, dark, elevation }" max-width="500px">
|
|
82
86
|
<v-card v-if="editedItem">
|
|
83
87
|
<v-card-title>
|
|
84
88
|
<!-- Slot to provide custom edit card title. Exposes `editedItem`. -->
|
|
@@ -102,7 +106,7 @@
|
|
|
102
106
|
<v-col cols="12">
|
|
103
107
|
<v-text-field
|
|
104
108
|
v-model="editedItem.name"
|
|
105
|
-
label="
|
|
109
|
+
:label="$t('mapo.fileName')"
|
|
106
110
|
></v-text-field>
|
|
107
111
|
</v-col>
|
|
108
112
|
</v-row>
|
|
@@ -112,8 +116,8 @@
|
|
|
112
116
|
|
|
113
117
|
<v-card-actions>
|
|
114
118
|
<v-spacer></v-spacer>
|
|
115
|
-
<v-btn color="
|
|
116
|
-
<v-btn color="
|
|
119
|
+
<v-btn color="primary" text @click="closeEdit">{{ $t("mapo.cancel") }}</v-btn>
|
|
120
|
+
<v-btn color="primary" text @click="saveEdit">{{ $t("mapo.save") }}</v-btn>
|
|
117
121
|
</v-card-actions>
|
|
118
122
|
</v-card>
|
|
119
123
|
</v-dialog>
|
|
@@ -124,6 +128,15 @@
|
|
|
124
128
|
.cursor-pointer {
|
|
125
129
|
cursor: pointer;
|
|
126
130
|
}
|
|
131
|
+
.v-virtual-scroll__item:not(:last-child){
|
|
132
|
+
.drop-area--item{
|
|
133
|
+
border-bottom: 1px solid;
|
|
134
|
+
border-color: rgba(255, 255, 255, 0.12);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
.theme--light .v-virtual-scroll__item .drop-area--item {
|
|
138
|
+
border-color: rgba(0, 0, 0, 0.12);
|
|
139
|
+
}
|
|
127
140
|
</style>
|
|
128
141
|
|
|
129
142
|
<script>
|
|
@@ -133,8 +146,8 @@ import { humanFileSize } from "@mapomodule/utils/helpers/formatters";
|
|
|
133
146
|
* You can drag and drop over the button or click it to load the files.
|
|
134
147
|
* When files are loaded into the component it will emit an event containing all the files.
|
|
135
148
|
* This component will not take care of the actual file upload.
|
|
136
|
-
*
|
|
137
|
-
*/
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
138
151
|
export default {
|
|
139
152
|
name: "DropArea",
|
|
140
153
|
props: {
|
|
@@ -173,10 +186,8 @@ export default {
|
|
|
173
186
|
clearList() {
|
|
174
187
|
this.uploadedFiles = [];
|
|
175
188
|
},
|
|
176
|
-
|
|
177
|
-
const index = this.uploadedFiles.findIndex(
|
|
178
|
-
(file) => file.info.name === fileName
|
|
179
|
-
);
|
|
189
|
+
removeItem(fileName) {
|
|
190
|
+
const index = this.uploadedFiles.findIndex((file) => file.info.name === fileName);
|
|
180
191
|
if (index > -1) this.uploadedFiles.splice(index, 1);
|
|
181
192
|
},
|
|
182
193
|
pickFile() {
|
|
@@ -193,7 +204,7 @@ export default {
|
|
|
193
204
|
if (this.uploadedFiles.length > 0) this.uploadedFiles = [];
|
|
194
205
|
if (!this.multiple && files.length > 1) {
|
|
195
206
|
this.$mapo.$snack.open({
|
|
196
|
-
message: "
|
|
207
|
+
message: this.$t("mapo.dropArea.onlyOneFile"),
|
|
197
208
|
color: "error",
|
|
198
209
|
});
|
|
199
210
|
} else {
|
|
@@ -207,11 +218,10 @@ export default {
|
|
|
207
218
|
processFile(blob) {
|
|
208
219
|
return {
|
|
209
220
|
info: {
|
|
210
|
-
objectURL: blob.type.startsWith("image/")
|
|
211
|
-
? URL.createObjectURL(blob)
|
|
212
|
-
: null,
|
|
221
|
+
objectURL: blob.type.startsWith("image/") ? URL.createObjectURL(blob) : null,
|
|
213
222
|
name: blob.name,
|
|
214
223
|
size: humanFileSize(blob.size, true, 2),
|
|
224
|
+
rawsize: blob.size,
|
|
215
225
|
type: blob.type,
|
|
216
226
|
},
|
|
217
227
|
blob,
|
|
@@ -223,10 +233,7 @@ export default {
|
|
|
223
233
|
this.editDialog = true;
|
|
224
234
|
},
|
|
225
235
|
saveEdit() {
|
|
226
|
-
this.uploadedFiles[this.editedIndex].info = Object.assign(
|
|
227
|
-
{},
|
|
228
|
-
this.editedItem
|
|
229
|
-
);
|
|
236
|
+
this.uploadedFiles[this.editedIndex].info = Object.assign({}, this.editedItem);
|
|
230
237
|
this.closeEdit();
|
|
231
238
|
},
|
|
232
239
|
closeEdit() {
|
|
@@ -240,11 +247,11 @@ export default {
|
|
|
240
247
|
watch: {
|
|
241
248
|
uploadedFiles(val) {
|
|
242
249
|
/** Fires when the list of files loaded changes
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
250
|
+
* @arg This emits a list of files in the format {info, blob} where the blob is a
|
|
251
|
+
* [File](https://developer.mozilla.org/en-US/docs/Web/API/File) and info are some custom info about the file.
|
|
252
|
+
*/
|
|
246
253
|
this.$emit("change", val);
|
|
247
254
|
},
|
|
248
255
|
},
|
|
249
256
|
};
|
|
250
|
-
</script>
|
|
257
|
+
</script>
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="row">
|
|
3
|
+
<div
|
|
4
|
+
class="col-12"
|
|
5
|
+
:class="field.class"
|
|
6
|
+
v-for="(field, index) in computedFields"
|
|
7
|
+
:key="index"
|
|
8
|
+
v-show="show(field)"
|
|
9
|
+
:style="show(field, 'visibility') ? '' : 'opacity: 0; visibility: hidden;'"
|
|
10
|
+
>
|
|
11
|
+
<FormTabs
|
|
12
|
+
v-if="field.tabs"
|
|
13
|
+
v-model="model"
|
|
14
|
+
v-bind="{ currentLang, errors, languages, readonly }"
|
|
15
|
+
:conf="field"
|
|
16
|
+
:moreSlotBindings="slotBindings"
|
|
17
|
+
>
|
|
18
|
+
<template
|
|
19
|
+
v-for="slot in nameSpacedSlots($slots, `group.${field.group.slug}.`)"
|
|
20
|
+
:slot="slot"
|
|
21
|
+
>
|
|
22
|
+
<slot :name="`group.${field.group.slug}.${slot}`"></slot>
|
|
23
|
+
</template>
|
|
24
|
+
<template
|
|
25
|
+
v-for="slot in nameSpacedSlots($scopedSlots, `group.${field.group.slug}.`)"
|
|
26
|
+
v-slot:[slot]="props"
|
|
27
|
+
>
|
|
28
|
+
<slot :name="`group.${field.group.slug}.${slot}`" v-bind="props" />
|
|
29
|
+
</template>
|
|
30
|
+
</FormTabs>
|
|
31
|
+
<FormGroup
|
|
32
|
+
v-else-if="field.group"
|
|
33
|
+
v-model="model"
|
|
34
|
+
v-bind="{ currentLang, errors, languages, readonly }"
|
|
35
|
+
:conf="field"
|
|
36
|
+
:moreSlotBindings="slotBindings"
|
|
37
|
+
>
|
|
38
|
+
<template
|
|
39
|
+
v-for="slot in nameSpacedSlots($slots, `group.${field.group.slug}.`)"
|
|
40
|
+
:slot="slot"
|
|
41
|
+
>
|
|
42
|
+
<slot :name="`group.${field.group.slug}.${slot}`"></slot>
|
|
43
|
+
</template>
|
|
44
|
+
<template
|
|
45
|
+
v-for="slot in nameSpacedSlots($scopedSlots, `group.${field.group.slug}.`)"
|
|
46
|
+
v-slot:[slot]="props"
|
|
47
|
+
>
|
|
48
|
+
<slot :name="`group.${field.group.slug}.${slot}`" v-bind="props" />
|
|
49
|
+
</template>
|
|
50
|
+
</FormGroup>
|
|
51
|
+
|
|
52
|
+
<template v-else>
|
|
53
|
+
<slot :name="field.slotName + '.before'" v-bind="{ conf: field, ...slotBindings, }" />
|
|
54
|
+
<slot
|
|
55
|
+
:name="field.slotName"
|
|
56
|
+
v-bind="{ conf: field, ...slotBindings, }"
|
|
57
|
+
>
|
|
58
|
+
<FormField
|
|
59
|
+
v-model="model"
|
|
60
|
+
v-bind="{ currentLang, errors, readonly }"
|
|
61
|
+
:langs="languages"
|
|
62
|
+
:conf="field"
|
|
63
|
+
>
|
|
64
|
+
<template
|
|
65
|
+
v-for="slot in nameSpacedSlots($slots, `fields.${field.value}.`)"
|
|
66
|
+
:slot="slot"
|
|
67
|
+
>
|
|
68
|
+
<slot :name="`fields.${field.value}.${slot}`"></slot>
|
|
69
|
+
</template>
|
|
70
|
+
<template
|
|
71
|
+
v-for="slot in nameSpacedSlots($scopedSlots, `fields.${field.value}.`)"
|
|
72
|
+
v-slot:[slot]="props"
|
|
73
|
+
>
|
|
74
|
+
<slot :name="`fields.${field.value}.${slot}`" v-bind="props" />
|
|
75
|
+
</template>
|
|
76
|
+
</FormField>
|
|
77
|
+
</slot>
|
|
78
|
+
<slot :name="field.slotName + '.after'" v-bind="{ conf: field, ...slotBindings, }" />
|
|
79
|
+
</template>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
83
|
+
<script>
|
|
84
|
+
import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
|
|
85
|
+
import { slugify, titleCase } from "@mapomodule/utils/helpers/formatters";
|
|
86
|
+
import { debounce } from "@mapomodule/utils/helpers/debounce";
|
|
87
|
+
|
|
88
|
+
export default {
|
|
89
|
+
name: "Form",
|
|
90
|
+
data() {
|
|
91
|
+
return {
|
|
92
|
+
model: this.value,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
props: {
|
|
96
|
+
// V-model of the object we are editing.
|
|
97
|
+
value: {
|
|
98
|
+
type: Object,
|
|
99
|
+
required: true,
|
|
100
|
+
},
|
|
101
|
+
// Set the current lang to value.
|
|
102
|
+
currentLang: {
|
|
103
|
+
type: String,
|
|
104
|
+
required: false,
|
|
105
|
+
},
|
|
106
|
+
// Makes all the fields readonly.
|
|
107
|
+
readonly: Boolean,
|
|
108
|
+
// An object representing all the errors of all fields. This means that this component will find the error of its field following the dottedPath of the value in the error dict.
|
|
109
|
+
errors: Object,
|
|
110
|
+
// Additional bindings to indrease slots capabilities
|
|
111
|
+
moreSlotBindings: Object,
|
|
112
|
+
// The main configuration that determines the arrangement of the fields in the detail layout.
|
|
113
|
+
fields: {
|
|
114
|
+
// [`DetailConfiguration`](#detailconfiguration)
|
|
115
|
+
type: Object | Array,
|
|
116
|
+
required: true,
|
|
117
|
+
},
|
|
118
|
+
// A list of languages into which the payload needs to be translated.
|
|
119
|
+
languages: {
|
|
120
|
+
type: Array,
|
|
121
|
+
default() { return this.$mapo.$options?.content?.languages || []; },
|
|
122
|
+
},
|
|
123
|
+
// Removes debounce from the emitter.
|
|
124
|
+
immediate: Boolean
|
|
125
|
+
},
|
|
126
|
+
watch: {
|
|
127
|
+
value(val) {
|
|
128
|
+
if (JSON.stringify(this.model) !== JSON.stringify(val)){
|
|
129
|
+
this.model = val;
|
|
130
|
+
this.initLang();
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
model(val) {
|
|
134
|
+
this.immediate ? this.$emit("input", val) : this.debouncedEmit("input", val);
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
methods: {
|
|
138
|
+
debouncedEmit: debounce(function (...args) {
|
|
139
|
+
this.$emit(...args);
|
|
140
|
+
}, 300),
|
|
141
|
+
nameSpacedSlots,
|
|
142
|
+
initLang(lang = this.currentLang) {
|
|
143
|
+
if (lang && !this.model.translations) {
|
|
144
|
+
this.model.translations = {};
|
|
145
|
+
}
|
|
146
|
+
if (lang && !this.model.translations[lang]) {
|
|
147
|
+
this.model.translations[lang] = {};
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
parseConf(field, i) {
|
|
151
|
+
const conf = typeof field === "string" ? { value: field } : { ...field };
|
|
152
|
+
conf.value = conf.value || "";
|
|
153
|
+
conf.slotName = `fields.${conf.value || i}`;
|
|
154
|
+
if (this.isReadonly) {
|
|
155
|
+
conf.attrs = { ...conf.attrs, readonly: true };
|
|
156
|
+
}
|
|
157
|
+
return conf;
|
|
158
|
+
},
|
|
159
|
+
parseGroup(group, icon="mdi-cube-outline") {
|
|
160
|
+
return typeof group === "string"
|
|
161
|
+
? { name: group, slug: slugify && slugify(group), icon }
|
|
162
|
+
: { slug: slugify && slugify(group.name), icon, ...group };
|
|
163
|
+
},
|
|
164
|
+
parseTabs(tabs) {
|
|
165
|
+
return Object.keys(tabs).map(key => {
|
|
166
|
+
const tab = tabs[key]
|
|
167
|
+
return {
|
|
168
|
+
tab: {label: titleCase(key.replace(/_/, " ")), slug: key, ...tab.tab},
|
|
169
|
+
fields: this.mapConf(Array.isArray(tab) && tab || tab.fields || [])
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
},
|
|
173
|
+
parseTagsGroup(field){
|
|
174
|
+
const gType = typeof field.group
|
|
175
|
+
const slug = gType == "string" && slugify(field.group) || gType == "object" && slugify(field.group?.name) || Object.keys(field.tabs).join("-")
|
|
176
|
+
return this.parseGroup(gType == "string" ? { ...this.parseGroup(field.group, null), slug} : { slug,...field.group }, null)
|
|
177
|
+
},
|
|
178
|
+
mapConf(fields) {
|
|
179
|
+
return fields.map((f, i) =>
|
|
180
|
+
f.tabs
|
|
181
|
+
? { ...f, group: this.parseTagsGroup(f), tabs: this.parseTabs(f.tabs) }
|
|
182
|
+
: f.group
|
|
183
|
+
? { ...f, group: this.parseGroup(f.group), fields: this.mapConf(f.fields) }
|
|
184
|
+
: this.parseConf(f, i)
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
show(conf, type = "display"){
|
|
188
|
+
const prop = type == "visibility" ? "vVisible" : "vShow"
|
|
189
|
+
if (typeof conf[prop] == "function") {
|
|
190
|
+
return conf[prop]({
|
|
191
|
+
model: this.model,
|
|
192
|
+
errors: this.errors,
|
|
193
|
+
languages: this.languages,
|
|
194
|
+
currentLang: this.currentLang
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
return true
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
computed: {
|
|
201
|
+
slotBindings() {
|
|
202
|
+
return {
|
|
203
|
+
model: this.model,
|
|
204
|
+
errors: this.errors,
|
|
205
|
+
currentLang: this.currentLang,
|
|
206
|
+
langs: this.languages,
|
|
207
|
+
...this.moreSlotBindings,
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
computedFields() {
|
|
211
|
+
return this.mapConf(this.fields);
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
created(){
|
|
215
|
+
this.initLang();
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
</script>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component
|
|
3
|
+
class="mapo-field"
|
|
4
|
+
:class="classes"
|
|
5
|
+
:is="is"
|
|
6
|
+
v-model="model"
|
|
7
|
+
v-bind="fieldAttrs"
|
|
8
|
+
>
|
|
9
|
+
<template v-for="(_, slot) in $slots" :slot="slot">
|
|
10
|
+
<!-- @vuese-ignore -->
|
|
11
|
+
<slot :name="slot"></slot>
|
|
12
|
+
</template>
|
|
13
|
+
<template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
|
|
14
|
+
<!-- @vuese-ignore -->
|
|
15
|
+
<slot :name="slot" v-bind="props" />
|
|
16
|
+
</template>
|
|
17
|
+
</component>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script>
|
|
21
|
+
import { getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
|
|
22
|
+
import { titleCase } from "@mapomodule/utils/helpers/formatters";
|
|
23
|
+
|
|
24
|
+
import defaults from "./defaults";
|
|
25
|
+
import { debounce } from "@mapomodule/utils/helpers/debounce";
|
|
26
|
+
const _ = require("lodash");
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 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.
|
|
30
|
+
*/
|
|
31
|
+
export default {
|
|
32
|
+
name: "FormField",
|
|
33
|
+
data() { return { model: null, }; },
|
|
34
|
+
props: {
|
|
35
|
+
// V-model of the payload needed to edit the field value in realtime.
|
|
36
|
+
value: {
|
|
37
|
+
type: Object,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
// Makes the field readonly.
|
|
41
|
+
readonly: Boolean,
|
|
42
|
+
// An object representing all the errors of all fields. This means that this component will find the error of its field following the dottedPath of the value in the error dict.
|
|
43
|
+
errors: Object,
|
|
44
|
+
// The main configuration that determines the rendering of the field. See [FieldConfiguration](/components/detail/Detail/#fieldconfiguration).
|
|
45
|
+
conf: {
|
|
46
|
+
// [`FieldConfiguration`](/components/detail/Detail/#fieldconfiguration)
|
|
47
|
+
type: Object,
|
|
48
|
+
required: true,
|
|
49
|
+
},
|
|
50
|
+
langs: {
|
|
51
|
+
type: Array,
|
|
52
|
+
default() { return this.$mapo.$options?.content?.languages || []; },
|
|
53
|
+
},
|
|
54
|
+
currentLang: String,
|
|
55
|
+
},
|
|
56
|
+
watch: {
|
|
57
|
+
value: {
|
|
58
|
+
deep: true,
|
|
59
|
+
handler(val) {
|
|
60
|
+
this.setModel(val);
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
kpointed(newValue, oldValue) {
|
|
64
|
+
if (newValue !== oldValue) {
|
|
65
|
+
this.setModel();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
model(val) {
|
|
69
|
+
var model = this.extractValue(val);
|
|
70
|
+
if (JSON.stringify(val) !== JSON.stringify(model))
|
|
71
|
+
this.debouncedSetValue(val);
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
methods: {
|
|
75
|
+
debouncedSetValue: debounce(function (...args) {
|
|
76
|
+
this.setValue(...args);
|
|
77
|
+
}, 300),
|
|
78
|
+
setValue(val) {
|
|
79
|
+
const dump = { ...this.value }; // since we cannot directly edit a prop
|
|
80
|
+
setPointed(dump, this.kpointed, this.accessor.set({ model: dump, val }));
|
|
81
|
+
if (typeof this.conf.onChange == "function")
|
|
82
|
+
this.conf.onChange({
|
|
83
|
+
val,
|
|
84
|
+
model: dump,
|
|
85
|
+
currentLang: this.currentLang,
|
|
86
|
+
languages: this.langs,
|
|
87
|
+
conf: this.conf,
|
|
88
|
+
kpointed: this.kpointed,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Fired when the v-model changes.
|
|
92
|
+
// @arg Emits the entire payload modified.
|
|
93
|
+
this.$emit("input", dump);
|
|
94
|
+
},
|
|
95
|
+
extractValue(val = this.value) {
|
|
96
|
+
return this.accessor.get({
|
|
97
|
+
model: { ...val },
|
|
98
|
+
val: getPointed({ ...val }, this.kpointed),
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
setModel(val = this.value) {
|
|
102
|
+
var model = this.extractValue(val);
|
|
103
|
+
if (val && JSON.stringify(this.model) !== JSON.stringify(model))
|
|
104
|
+
this.model = model;
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
computed: {
|
|
108
|
+
componentInfo() {
|
|
109
|
+
const originalName = this.is?.options?.name || this.is?.name || this.is;
|
|
110
|
+
const camelName = originalName.replace(/-./g, (x) => x[1].toUpperCase());
|
|
111
|
+
const kebabName = originalName.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
112
|
+
return { originalName, camelName, kebabName }
|
|
113
|
+
},
|
|
114
|
+
options(){
|
|
115
|
+
return _.merge(defaults, this.$mapo.$options?.ui?.forms?.fields);
|
|
116
|
+
},
|
|
117
|
+
defaultAccess() {
|
|
118
|
+
return this.options.accessor[this.componentInfo.camelName] || this.options.accessor[this.componentInfo.kebabName];
|
|
119
|
+
},
|
|
120
|
+
defaultAttrs() {
|
|
121
|
+
const componentAttrs = this.options.attrs[this.componentInfo.camelName] || this.options.attrs[this.componentInfo.kebabName];
|
|
122
|
+
return {...componentAttrs, ...this.options.attrs.All};
|
|
123
|
+
},
|
|
124
|
+
classes() {
|
|
125
|
+
var upperClasses = this.fieldAttrs.class;
|
|
126
|
+
if (typeof upperClasses == "string") {
|
|
127
|
+
upperClasses = { [upperClasses]: true };
|
|
128
|
+
} else if (Array.isArray(upperClasses)) {
|
|
129
|
+
upperClasses = upperClasses.reduce(
|
|
130
|
+
(acc, next) => ({ ...acc, [next]: true }),
|
|
131
|
+
{}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
...upperClasses,
|
|
136
|
+
[`mapo-field-${this.conf.value}`]: true,
|
|
137
|
+
"mapo-field--has-errors": this.hasErrors,
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
kpointed() {
|
|
141
|
+
let kpointed = this.conf.value;
|
|
142
|
+
if (this.currentLang && !this.conf.synci18n) {
|
|
143
|
+
const base = `translations.${this.currentLang}`;
|
|
144
|
+
kpointed = kpointed ? `${base}.${kpointed}` : base;
|
|
145
|
+
}
|
|
146
|
+
return kpointed;
|
|
147
|
+
},
|
|
148
|
+
accessor() {
|
|
149
|
+
let func = function ({ val }) {
|
|
150
|
+
return val;
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
get: func,
|
|
154
|
+
set: func,
|
|
155
|
+
...this.defaultAccess,
|
|
156
|
+
...this.conf.accessor,
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
errorMessages() {
|
|
160
|
+
return this.kpointed
|
|
161
|
+
.split(".")
|
|
162
|
+
.map((_, i, a) => a.slice(0, i + 1).join("."))
|
|
163
|
+
.reduce((acc, next) => {
|
|
164
|
+
const error = getPointed(this.errors || {}, next, []);
|
|
165
|
+
if (Array.isArray(error)) {
|
|
166
|
+
acc = [...acc, ...error];
|
|
167
|
+
} else if (typeof error == "string") {
|
|
168
|
+
acc = [...acc, error];
|
|
169
|
+
}
|
|
170
|
+
return acc;
|
|
171
|
+
}, []);
|
|
172
|
+
},
|
|
173
|
+
hasErrors() {
|
|
174
|
+
return !!this.errorMessages.length;
|
|
175
|
+
},
|
|
176
|
+
fieldAttrs() {
|
|
177
|
+
return {
|
|
178
|
+
label: this.label,
|
|
179
|
+
errorMessages: this.errorMessages,
|
|
180
|
+
hideDetails: !this.hasErrors,
|
|
181
|
+
...this.defaultAttrs,
|
|
182
|
+
readonly: this.readonly,
|
|
183
|
+
...this.conf.attrs,
|
|
184
|
+
currentLang: this.currentLang,
|
|
185
|
+
langs: this.langs,
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
label() {
|
|
189
|
+
if (this.conf.label !== undefined) {
|
|
190
|
+
return this.conf.label;
|
|
191
|
+
}
|
|
192
|
+
return titleCase(
|
|
193
|
+
(this.conf.value || "")
|
|
194
|
+
.replace(/^translations\.\w\w\./, "")
|
|
195
|
+
.split(".")
|
|
196
|
+
.join(" ")
|
|
197
|
+
.replace(/_/, " ")
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
is() {
|
|
201
|
+
const dynImport = typeof this.conf.is == "string" && this.options.components[this.conf.is.replace(/-./g, (x) => x[1].toUpperCase())];
|
|
202
|
+
return (
|
|
203
|
+
dynImport || this.conf.is ||
|
|
204
|
+
(this.conf.type && this.options.mapping[this.conf.type]) ||
|
|
205
|
+
this.options.mapping.text
|
|
206
|
+
);
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
mounted() {
|
|
210
|
+
this.setModel();
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
</script>
|