@mapomodule/uikit 1.0.0-alpha.2 → 1.0.0-alpha.22

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +406 -0
  2. package/components/Detail/Detail.vue +288 -260
  3. package/components/Detail/DetailLangSwitch.vue +1 -1
  4. package/components/DropArea.vue +3 -3
  5. package/components/Form/Form.vue +224 -0
  6. package/components/Form/FormField.vue +185 -0
  7. package/components/Form/FormGroup.vue +88 -0
  8. package/components/Form/FormTabs.vue +134 -0
  9. package/components/Form/defaults.js +58 -0
  10. package/components/{fields → Form/fields}/DateField.vue +9 -3
  11. package/components/Form/fields/FileField.vue +125 -0
  12. package/components/Form/fields/FksField.vue +88 -0
  13. package/components/{fields → Form/fields}/MediaField.vue +36 -6
  14. package/components/{fields → Form/fields}/MediaM2mField.vue +8 -3
  15. package/components/Form/fields/Repeater.vue +562 -0
  16. package/components/Form/fields/SeoPreview.vue +89 -0
  17. package/components/{fields/TinyMce → Form/fields/wygEditor}/defaults.js +7 -5
  18. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/events.js +0 -0
  19. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/mapomedia.plugin.js +7 -6
  20. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/script.injector.js +0 -0
  21. package/components/Form/fields/wygEditor/wygEditor.vue +256 -0
  22. package/components/List/List.vue +120 -42
  23. package/components/List/ListActions.vue +56 -17
  24. package/components/List/ListFilters.vue +158 -113
  25. package/components/List/ListHead.vue +30 -12
  26. package/components/List/ListQuickEdit.vue +128 -59
  27. package/components/List/ListTable.vue +293 -80
  28. package/components/Login.vue +14 -5
  29. package/components/MediaManager/MediaEditor.vue +253 -107
  30. package/components/MediaManager/MediaFolders.vue +134 -43
  31. package/components/MediaManager/MediaGallery.vue +56 -52
  32. package/components/MediaManager/MediaManager.vue +127 -83
  33. package/components/MediaManager/MediaManagerDialog.vue +19 -22
  34. package/components/MediaManager/MediaPreview.vue +180 -0
  35. package/components/MediaManager/MediaUploader.vue +35 -32
  36. package/components/SnackBar.vue +3 -4
  37. package/components/ThemeToggle.vue +13 -0
  38. package/components/layout/Sidebar/Sidebar.vue +35 -32
  39. package/components/layout/Sidebar/SidebarFooter.vue +42 -46
  40. package/components/layout/Sidebar/SidebarList.vue +13 -14
  41. package/components/layout/Sidebar/SidebarListItem.vue +99 -38
  42. package/components/layout/Sidebar/SidebarProfile.vue +42 -0
  43. package/components/layout/Topbar/Topbar.vue +3 -35
  44. package/components/layout/routebuilder.js +3 -3
  45. package/defaults.js +2 -2
  46. package/layouts/default.vue +20 -18
  47. package/layouts/empty.vue +10 -0
  48. package/module.js +1 -1
  49. package/package.json +5 -4
  50. package/pages/index.vue +1 -2
  51. package/components/Detail/DetailField.vue +0 -129
  52. package/components/Detail/defaults.js +0 -50
  53. package/components/fields/M2mField.vue +0 -95
  54. package/components/fields/TinyMce/TinyMce.vue +0 -177
  55. 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 }}
@@ -69,7 +69,7 @@
69
69
  <!-- Slot to provide custom button actions inside the drop area -->
70
70
  <slot v-bind:clearList="clearList" name="actions">
71
71
  <!-- `<v-btn @click="clearList" icon><v-icon>mdi-close</v-icon></v-btn>` -->
72
- <v-btn @click="clearList" icon>
72
+ <v-btn v-if="uploadedFiles && uploadedFiles.length" @click="clearList" icon>
73
73
  <v-icon>mdi-close</v-icon>
74
74
  </v-btn>
75
75
  </slot>
@@ -112,8 +112,8 @@
112
112
 
113
113
  <v-card-actions>
114
114
  <v-spacer></v-spacer>
115
- <v-btn color="green darken-1" text @click="closeEdit"> Cancel </v-btn>
116
- <v-btn color="green darken-1" text @click="saveEdit"> Save </v-btn>
115
+ <v-btn color="primary" text @click="closeEdit"> Cancel </v-btn>
116
+ <v-btn color="primary" text @click="saveEdit"> Save </v-btn>
117
117
  </v-card-actions>
118
118
  </v-card>
119
119
  </v-dialog>
@@ -0,0 +1,224 @@
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 }"
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 }"
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
+ <div 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
+ :langs="languages"
61
+ :currentLang="currentLang"
62
+ :conf="field"
63
+ :errors="errors"
64
+ >
65
+ <template
66
+ v-for="slot in nameSpacedSlots($slots, `fields.${field.value}.`)"
67
+ :slot="slot"
68
+ >
69
+ <slot :name="`fields.${field.value}.${slot}`"></slot>
70
+ </template>
71
+ <template
72
+ v-for="slot in nameSpacedSlots($scopedSlots, `fields.${field.value}.`)"
73
+ v-slot:[slot]="props"
74
+ >
75
+ <slot :name="`fields.${field.value}.${slot}`" v-bind="props" />
76
+ </template>
77
+ </FormField>
78
+ </slot>
79
+ <slot :name="field.slotName + '.after'" v-bind="{ conf: field, ...slotBindings, }" />
80
+ </div>
81
+ </div>
82
+ </div>
83
+ </template>
84
+ <script>
85
+ import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
86
+ import { slugify, titleCase } from "@mapomodule/utils/helpers/formatters";
87
+ import { findPropPaths, getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
88
+
89
+ export default {
90
+ name: "Form",
91
+ data() {
92
+ return {
93
+ model: {},
94
+ };
95
+ },
96
+ props: {
97
+ // V-model of the object we are editing.
98
+ value: {
99
+ type: Object,
100
+ required: true,
101
+ },
102
+ // Set the current lang to value.
103
+ currentLang: {
104
+ type: String,
105
+ required: false,
106
+ },
107
+ // 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.
108
+ errors: Object,
109
+ // Additional bindings to indrease slots capabilities
110
+ moreSlotBindings: Object,
111
+ // The main configuration that determines the arrangement of the fields in the detail layout.
112
+ fields: {
113
+ // [`DetailConfiguration`](#detailconfiguration)
114
+ type: Object | Array,
115
+ required: true,
116
+ },
117
+ // A list of languages into which the payload needs to be translated.
118
+ languages: {
119
+ type: Array,
120
+ default: () => [],
121
+ },
122
+ },
123
+ watch: {
124
+ value(val) {
125
+ this.model = val;
126
+ this.initLang();
127
+ },
128
+ model(val) {
129
+ this.$emit("input", val);
130
+ },
131
+ },
132
+ methods: {
133
+ nameSpacedSlots,
134
+ initLang(lang = this.currentLang) {
135
+ if (lang && !this.model.translations) {
136
+ this.model.translations = {};
137
+ }
138
+ if (lang && !this.model.translations[lang]) {
139
+ this.model.translations[lang] = {};
140
+ }
141
+ },
142
+ parseConf(field, i) {
143
+ const conf = typeof field === "string" ? { value: field } : field;
144
+ conf.value = conf.value || "";
145
+ conf.value = conf.value.replace(new RegExp(`^translations\.(${this.languages.join("|")})\.?`), "");
146
+ conf.slotName = `fields.${conf.value || i}`;
147
+ if (this.currentLang && !field.synci18n) {
148
+ const base = `translations.${this.currentLang}`;
149
+ conf.value = (conf.value && `${base}.${conf.value}`) || base;
150
+ }
151
+ if (this.isReadonly) {
152
+ conf.attrs = { ...conf.attrs, readonly: true };
153
+ }
154
+ return conf;
155
+ },
156
+ parseGroup(group, icon="mdi-cube-outline") {
157
+ return typeof group === "string"
158
+ ? { name: group, slug: slugify && slugify(group), icon }
159
+ : { slug: slugify && slugify(group.name), icon, ...group };
160
+ },
161
+ parseTabs(tabs) {
162
+ return Object.keys(tabs).map(key => {
163
+ const tab = tabs[key]
164
+ return {
165
+ label: titleCase(key.replace(/_/, " ")),
166
+ slug: key,
167
+ ...tab.tab,
168
+ fields: this.mapConf(Array.isArray(tab) && tab || tab.fields || [])
169
+ }
170
+ })
171
+ },
172
+ parseTagsGroup(field){
173
+ const gType = typeof field.group
174
+ const slug = gType == "string" && slugify(field.group) || gType == "object" && slugify(field.group?.name) || Object.keys(field.tabs).join("-")
175
+ return this.parseGroup(gType == "string" ? { ...this.parseGroup(field.group, null), slug} : { slug,...field.group }, null)
176
+ },
177
+ mapConf(fields) {
178
+ ////// This is an hack to prevent render loop
179
+ const functions = findPropPaths(fields, ({ val }) => typeof val == "function" ).reduce((acc, key) => ({[key]: getPointed(fields, key, undefined) , ...acc}), {})
180
+ fields = JSON.parse(JSON.stringify(fields))
181
+ Object.keys(functions).forEach(key => setPointed(fields, key, functions[key]))
182
+ //// End of hack ====> TODO: find a better way to avoid loops
183
+ return fields.map((f, i) =>
184
+ f.tabs
185
+ ? { group: this.parseTagsGroup(f), tabs: this.parseTabs(f.tabs) }
186
+ : f.group
187
+ ? { group: this.parseGroup(f.group), fields: this.mapConf(f.fields) }
188
+ : this.parseConf(f, i)
189
+ );
190
+ },
191
+ show(conf, type = "display"){
192
+ const prop = type == "visibility" ? "vVisible" : "vShow"
193
+ if (typeof conf[prop] == "function") {
194
+ return conf[prop]({
195
+ model: this.model,
196
+ errors: this.errors,
197
+ languages: this.languages,
198
+ currentLang: this.currentLang
199
+ })
200
+ }
201
+ return true
202
+ }
203
+
204
+ },
205
+ computed: {
206
+ slotBindings() {
207
+ return {
208
+ model: this.model,
209
+ errors: this.errors,
210
+ currentLang: this.currentLang,
211
+ langs: this.languages,
212
+ ...this.moreSlotBindings,
213
+ };
214
+ },
215
+ computedFields() {
216
+ return this.mapConf(this.fields);
217
+ },
218
+ },
219
+ created(){
220
+ this.model = this.value
221
+ this.initLang();
222
+ }
223
+ };
224
+ </script>
@@ -0,0 +1,185 @@
1
+ <template>
2
+ <div>
3
+ <span class="mapo-label" :class="`mapo-label-${conf.value}`">{{label}}</span>
4
+ <component :is="is" v-model="model" v-bind="fieldAttrs">
5
+ <template v-for="(_, slot) in $slots" :slot="slot">
6
+ <!-- @vuese-ignore -->
7
+ <slot :name="slot"></slot>
8
+ </template>
9
+ <template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
10
+ <!-- @vuese-ignore -->
11
+ <slot :name="slot" v-bind="props" />
12
+ </template>
13
+ </component>
14
+ </div>
15
+ </template>
16
+
17
+ <style>
18
+ .mapo-label {
19
+ display: none;
20
+ }
21
+ </style>
22
+
23
+ <script>
24
+ import wygEditor from "@mapomodule/uikit/components/Form/fields/wygEditor/wygEditor.vue";
25
+ import DateField from "@mapomodule/uikit/components/Form/fields/DateField.vue";
26
+ import FksField from "@mapomodule/uikit/components/Form/fields/FksField.vue";
27
+ import MediaM2mField from "@mapomodule/uikit/components/Form/fields/MediaM2mField.vue";
28
+ import MediaField from "@mapomodule/uikit/components/Form/fields/MediaField.vue";
29
+ import SeoPreview from "@mapomodule/uikit/components/Form/fields/SeoPreview.vue";
30
+ import FileField from "@mapomodule/uikit/components/Form/fields/FileField.vue";
31
+ import Repeater from "@mapomodule/uikit/components/Form/fields/Repeater.vue"
32
+
33
+ import { getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
34
+ import { titleCase } from "@mapomodule/utils/helpers/formatters";
35
+
36
+ import defaults from "./defaults";
37
+
38
+ /**
39
+ * 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.
40
+ */
41
+ export default {
42
+ name: "FormField",
43
+ components: {
44
+ wygEditor,
45
+ DateField,
46
+ FksField,
47
+ MediaM2mField,
48
+ MediaField,
49
+ SeoPreview,
50
+ FileField,
51
+ Repeater,
52
+ },
53
+
54
+ data() {
55
+ return {
56
+ model: null,
57
+ defaultMap: defaults.mapping,
58
+ defaultAttrs: defaults.props,
59
+ defaultAccess: defaults.accessor,
60
+ };
61
+ },
62
+ props: {
63
+ // V-model of the payload needed to edit the field value in realtime.
64
+ value: {
65
+ type: Object,
66
+ required: true,
67
+ },
68
+ // 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.
69
+ errors: Object,
70
+ // The main configuration that determines the rendering of the field. See [FieldConfiguration](/components/detail/Detail/#fieldconfiguration).
71
+ conf: {
72
+ // [`FieldConfiguration`](/components/detail/Detail/#fieldconfiguration)
73
+ type: Object,
74
+ required: true,
75
+ },
76
+ langs: {
77
+ type: Array,
78
+ default: () => []
79
+ },
80
+ currentLang: String
81
+ },
82
+ watch: {
83
+ value: {
84
+ deep: true,
85
+ handler(val) {
86
+ this.setModel(val);
87
+ },
88
+ },
89
+ "conf.value"(newValue, oldValue) {
90
+ if (newValue !== oldValue) {
91
+ this.setModel();
92
+ }
93
+ },
94
+ model(val) {
95
+ const dump = { ...this.value }; // since we cannot directly edit a prop
96
+ setPointed(
97
+ dump,
98
+ this.conf.value,
99
+ this.accessor.set({ model: dump, val })
100
+ );
101
+ if (typeof this.conf.onChange == "function")
102
+ this.conf.onChange({
103
+ val,
104
+ model: dump,
105
+ currentLang: this.currentLang,
106
+ languages: this.langs,
107
+ conf: this.conf
108
+ })
109
+
110
+ // Fired when the v-model changes.
111
+ // @arg Emits the entire payload modified.
112
+ this.$emit("input", dump);
113
+ },
114
+ },
115
+ methods: {
116
+ setModel(val = this.value) {
117
+ var model = this.accessor.get({
118
+ model: { ...val },
119
+ val: getPointed({ ...val }, this.conf.value),
120
+ });
121
+ if (val && JSON.stringify(this.model) !== JSON.stringify(model))
122
+ this.model = model;
123
+ },
124
+ },
125
+ computed: {
126
+ accessor() {
127
+ let func = function ({ val }) {
128
+ return val;
129
+ };
130
+ return {
131
+ get: func,
132
+ set: func,
133
+ ...(this.defaultAccess[this.is] || {}),
134
+ ...this.conf.accessor,
135
+ };
136
+ },
137
+ fieldAttrs() {
138
+ return {
139
+ label: this.label,
140
+ errorMessages: this.conf.value
141
+ .split(".")
142
+ .map((_, i, a) => a.slice(0, i + 1).join("."))
143
+ .reduce((acc, next) => {
144
+ const error = getPointed(this.errors || {}, next, []);
145
+ if (Array.isArray(error)) {
146
+ acc = [...acc, ...error];
147
+ } else if (typeof error == "string") {
148
+ acc = [...acc, error];
149
+ }
150
+ return acc;
151
+ }, []),
152
+ ...this.defaultAttrs.All,
153
+ ...(this.defaultAttrs[
154
+ this.is.replace(/-./g, (x) => x[1].toUpperCase())
155
+ ] || {}),
156
+ ...this.conf.attrs,
157
+ currentLang: this.currentLang,
158
+ langs: this.langs,
159
+ };
160
+ },
161
+ label() {
162
+ if (this.conf.label !== undefined) {
163
+ return this.conf.label;
164
+ }
165
+ return titleCase(
166
+ (this.conf.value || "")
167
+ .replace(/^translations\.\w\w\./, "")
168
+ .split(".")
169
+ .join(" ")
170
+ .replace(/_/, " ")
171
+ );
172
+ },
173
+ is() {
174
+ return (
175
+ this.conf.is ||
176
+ (this.conf.type && this.defaultMap[this.conf.type]) ||
177
+ "vTextField"
178
+ );
179
+ },
180
+ },
181
+ mounted(){
182
+ this.setModel()
183
+ }
184
+ };
185
+ </script>
@@ -0,0 +1,88 @@
1
+ <template>
2
+ <v-card v-if="conf" class="my-2 rounded-0">
3
+ <v-card-title :class="conf.group.titleClass">
4
+ <slot name="title.before" v-bind="slotBindings" />
5
+ <slot name="title" v-bind="slotBindings">
6
+ <v-icon left> {{ conf.group.icon }} </v-icon>
7
+ <span>{{ conf.group.name }}</span>
8
+ </slot>
9
+ <slot name="title.after" v-bind="slotBindings" />
10
+ </v-card-title>
11
+ <div class="container">
12
+ <Form
13
+ v-model="model"
14
+ v-bind="{ currentLang, errors, languages }"
15
+ :fields="conf.fields"
16
+ :moreSlotBindings="slotBindings"
17
+ >
18
+ <template v-for="(_, slot) in $slots" :slot="slot">
19
+ <!-- @vuese-ignore -->
20
+ <slot :name="slot" />
21
+ </template>
22
+ <template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
23
+ <!-- @vuese-ignore -->
24
+ <slot :name="slot" v-bind="props" />
25
+ </template>
26
+ </Form>
27
+ </div>
28
+ </v-card>
29
+ </template>
30
+
31
+ <script>
32
+ export default {
33
+ name: "FormGroup",
34
+ data() {
35
+ return {
36
+ model: {},
37
+ };
38
+ },
39
+ props: {
40
+ // V-model of the object we are editing.
41
+ value: {
42
+ type: Object,
43
+ required: true,
44
+ },
45
+ // Set the current lang to value.
46
+ currentLang: {
47
+ type: String,
48
+ required: false,
49
+ },
50
+ // 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.
51
+ errors: Object,
52
+ // Additional bindings to indrease slots capabilities
53
+ moreSlotBindings: Object,
54
+ // The main configuration that determines the arrangement of the fields in the detail layout.
55
+ conf: {
56
+ type: Object,
57
+ required: true,
58
+ },
59
+ // A list of languages into which the payload needs to be translated.
60
+ languages: {
61
+ type: Array,
62
+ default: () => [],
63
+ },
64
+ },
65
+ watch: {
66
+ value(val) {
67
+ this.model = val;
68
+ },
69
+ model(val) {
70
+ this.$emit("input", val);
71
+ },
72
+ },
73
+ computed: {
74
+ slotBindings() {
75
+ return {
76
+ model: this.model,
77
+ errors: this.errors,
78
+ currentLang: this.currentLang,
79
+ langs: this.languages,
80
+ ...this.moreSlotBindings,
81
+ };
82
+ },
83
+ },
84
+ created() {
85
+ this.model = this.value;
86
+ },
87
+ };
88
+ </script>
@@ -0,0 +1,134 @@
1
+ <template>
2
+ <v-card v-if="conf" class="my-2 rounded-0">
3
+ <v-card-title :class="conf.group.titleClass" v-if="hasTitle">
4
+ <slot name="title.before" v-bind="slotBindings" />
5
+ <slot name="title" v-bind="slotBindings">
6
+ <v-icon left> {{ conf.group.icon }} </v-icon>
7
+ <span>{{ conf.group.name }}</span>
8
+ </slot>
9
+ <slot name="title.after" v-bind="slotBindings" />
10
+ </v-card-title>
11
+ <div class="container">
12
+ <v-tabs v-model="tabIndex" class="tab-wrapper">
13
+ <v-tab v-for="(tab, index) in conf.tabs" :key="index">
14
+ <v-badge :value="hasErrors(tab)" color="error" dot>
15
+ {{ tab.label }} <v-icon v-if="tab.icon">{{ tab.icon }}</v-icon>
16
+ </v-badge>
17
+ </v-tab>
18
+ </v-tabs>
19
+ <v-tabs-items v-model="tabIndex">
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">
22
+ <Form
23
+ v-model="model"
24
+ v-bind="{ currentLang, errors, languages }"
25
+ :fields="tab.fields"
26
+ :moreSlotBindings="slotBindings"
27
+ >
28
+ <template
29
+ v-for="slot in nameSpacedSlots($slots, `tab.${tab.slug}.`)"
30
+ :slot="slot"
31
+ >
32
+ <slot :name="`tab.${tab.slug}.${slot}`"></slot>
33
+ </template>
34
+ <template
35
+ v-for="slot in nameSpacedSlots(
36
+ $scopedSlots,
37
+ `tab.${tab.slug}.`
38
+ )"
39
+ v-slot:[slot]="props"
40
+ >
41
+ <slot :name="`tab.${tab.slug}.${slot}`" v-bind="props" />
42
+ </template>
43
+ </Form>
44
+ </slot>
45
+ </v-tab-item>
46
+ </v-tabs-items>
47
+ </div>
48
+ </v-card>
49
+ </template>
50
+
51
+ <style lang="scss" scoped>
52
+ .tab-wrapper {
53
+ margin: -12px 0 0 -12px;
54
+ }
55
+ </style>
56
+ <script>
57
+ import { findPropPaths } from "@mapomodule/utils/helpers/objHelpers";
58
+ import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
59
+
60
+ export default {
61
+ name: "FormTabs",
62
+ data() {
63
+ return {
64
+ model: {},
65
+ tabIndex: 0,
66
+ };
67
+ },
68
+ props: {
69
+ // V-model of the object we are editing.
70
+ value: {
71
+ type: Object,
72
+ required: true,
73
+ },
74
+ // Set the current lang to value.
75
+ currentLang: {
76
+ type: String,
77
+ required: false,
78
+ },
79
+ // 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.
80
+ errors: Object,
81
+ // Additional bindings to indrease slots capabilities
82
+ moreSlotBindings: Object,
83
+ // The main configuration that determines the arrangement of the fields in the detail layout.
84
+ conf: {
85
+ type: Object,
86
+ required: true,
87
+ },
88
+ // A list of languages into which the payload needs to be translated.
89
+ languages: {
90
+ type: Array,
91
+ default: () => [],
92
+ },
93
+ },
94
+ watch: {
95
+ value(val) {
96
+ this.model = val;
97
+ },
98
+ model(val) {
99
+ this.$emit("input", val);
100
+ },
101
+ },
102
+ computed: {
103
+ slotBindings() {
104
+ return {
105
+ model: this.model,
106
+ errors: this.errors,
107
+ currentLang: this.currentLang,
108
+ langs: this.languages,
109
+ ...this.moreSlotBindings,
110
+ };
111
+ },
112
+ hasTitle() {
113
+ return !!(
114
+ Object.keys({ ...this.$scopedSlots, ...this.$slots }).some((s) =>
115
+ s.startsWith("title")
116
+ ) ||
117
+ this.conf.group.name ||
118
+ this.conf.group.icon
119
+ );
120
+ },
121
+ },
122
+ methods: {
123
+ nameSpacedSlots,
124
+ hasErrors(tab) {
125
+ return findPropPaths(this.errors || {}, ({ val }) =>
126
+ Array.isArray(val)
127
+ ).some((k) => tab.fields.some((f) => k.startsWith(f.value)));
128
+ },
129
+ },
130
+ created() {
131
+ this.model = this.value;
132
+ },
133
+ };
134
+ </script>