@mapomodule/uikit 1.0.0-alpha.20 → 1.0.0-alpha.23

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.
@@ -0,0 +1,228 @@
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
+ <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
+ 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
+ </div>
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 { deepClone } from "@mapomodule/utils/helpers/objHelpers";
87
+
88
+ export default {
89
+ name: "Form",
90
+ data() {
91
+ return {
92
+ model: {},
93
+ internalFields: []
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
+ // Makes all the fields readonly.
108
+ readonly: Boolean,
109
+ // 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.
110
+ errors: Object,
111
+ // Additional bindings to indrease slots capabilities
112
+ moreSlotBindings: Object,
113
+ // The main configuration that determines the arrangement of the fields in the detail layout.
114
+ fields: {
115
+ // [`DetailConfiguration`](#detailconfiguration)
116
+ type: Object | Array,
117
+ required: true,
118
+ },
119
+ // A list of languages into which the payload needs to be translated.
120
+ languages: {
121
+ type: Array,
122
+ default: () => [],
123
+ },
124
+ },
125
+ watch: {
126
+ value(val) {
127
+ this.model = val;
128
+ this.initLang();
129
+ },
130
+ model(val) {
131
+ this.$emit("input", val);
132
+ },
133
+ fields(val){
134
+ this.internalFields = this.cloneFields(val)
135
+ }
136
+ },
137
+ methods: {
138
+ nameSpacedSlots,
139
+ initLang(lang = this.currentLang) {
140
+ if (lang && !this.model.translations) {
141
+ this.model.translations = {};
142
+ }
143
+ if (lang && !this.model.translations[lang]) {
144
+ this.model.translations[lang] = {};
145
+ }
146
+ },
147
+ parseConf(field, i) {
148
+ const conf = typeof field === "string" ? { value: field } : field;
149
+ conf.value = conf.value || "";
150
+ conf.value = conf.value.replace(new RegExp(`^translations\.(${this.languages.join("|")})\.?`), "");
151
+ conf.slotName = `fields.${conf.value || i}`;
152
+ if (this.currentLang && !field.synci18n) {
153
+ const base = `translations.${this.currentLang}`;
154
+ conf.value = (conf.value && `${base}.${conf.value}`) || base;
155
+ }
156
+ if (this.isReadonly) {
157
+ conf.attrs = { ...conf.attrs, readonly: true };
158
+ }
159
+ return conf;
160
+ },
161
+ parseGroup(group, icon="mdi-cube-outline") {
162
+ return typeof group === "string"
163
+ ? { name: group, slug: slugify && slugify(group), icon }
164
+ : { slug: slugify && slugify(group.name), icon, ...group };
165
+ },
166
+ parseTabs(tabs) {
167
+ return Object.keys(tabs).map(key => {
168
+ 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
+ }
175
+ })
176
+ },
177
+ parseTagsGroup(field){
178
+ const gType = typeof field.group
179
+ const slug = gType == "string" && slugify(field.group) || gType == "object" && slugify(field.group?.name) || Object.keys(field.tabs).join("-")
180
+ return this.parseGroup(gType == "string" ? { ...this.parseGroup(field.group, null), slug} : { slug,...field.group }, null)
181
+ },
182
+ mapConf(fields) {
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
+ cloneFields(fields){
204
+ return process.browser ? deepClone(fields) : fields
205
+ }
206
+
207
+ },
208
+ computed: {
209
+ slotBindings() {
210
+ return {
211
+ model: this.model,
212
+ errors: this.errors,
213
+ currentLang: this.currentLang,
214
+ langs: this.languages,
215
+ ...this.moreSlotBindings,
216
+ };
217
+ },
218
+ computedFields() {
219
+ return this.mapConf(this.internalFields);
220
+ },
221
+ },
222
+ created(){
223
+ this.internalFields = this.cloneFields(this.fields)
224
+ this.model = this.value
225
+ this.initLang();
226
+ }
227
+ };
228
+ </script>
@@ -1,7 +1,16 @@
1
1
  <template>
2
2
  <div>
3
3
  <span class="mapo-label" :class="`mapo-label-${conf.value}`">{{label}}</span>
4
- <component :is="is" v-model="model" v-bind="fieldAttrs"></component>
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>
5
14
  </div>
6
15
  </template>
7
16
 
@@ -12,23 +21,25 @@
12
21
  </style>
13
22
 
14
23
  <script>
15
- import wygEditor from "@mapomodule/uikit/components/fields/wygEditor/wygEditor.vue";
16
- import DateField from "@mapomodule/uikit/components/fields/DateField.vue";
17
- import FksField from "@mapomodule/uikit/components/fields/FksField.vue";
18
- import MediaM2mField from "@mapomodule/uikit/components/fields/MediaM2mField.vue";
19
- import MediaField from "@mapomodule/uikit/components/fields/MediaField.vue";
20
- import SeoPreview from "@mapomodule/uikit/components/fields/SeoPreview.vue";
21
- import FileField from "@mapomodule/uikit/components/fields/FileField.vue";
22
- import Repeater from "@mapomodule/uikit/components/fields/Repeater.vue"
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"
23
32
 
24
33
  import { getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
34
+ import { titleCase } from "@mapomodule/utils/helpers/formatters";
35
+
25
36
  import defaults from "./defaults";
26
37
 
27
38
  /**
28
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.
29
40
  */
30
41
  export default {
31
- name: "DetailField",
42
+ name: "FormField",
32
43
  components: {
33
44
  wygEditor,
34
45
  DateField,
@@ -54,6 +65,8 @@ export default {
54
65
  type: Object,
55
66
  required: true,
56
67
  },
68
+ // Makes the field readonly.
69
+ readonly: Boolean,
57
70
  // 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.
58
71
  errors: Object,
59
72
  // The main configuration that determines the rendering of the field. See [FieldConfiguration](/components/detail/Detail/#fieldconfiguration).
@@ -81,12 +94,21 @@ export default {
81
94
  }
82
95
  },
83
96
  model(val) {
84
- const dump = { ...this.value };
97
+ const dump = { ...this.value }; // since we cannot directly edit a prop
85
98
  setPointed(
86
99
  dump,
87
100
  this.conf.value,
88
- this.accessor.set({ model: { ...this.value }, val })
101
+ this.accessor.set({ model: dump, val })
89
102
  );
103
+ if (typeof this.conf.onChange == "function")
104
+ this.conf.onChange({
105
+ val,
106
+ model: dump,
107
+ currentLang: this.currentLang,
108
+ languages: this.langs,
109
+ conf: this.conf
110
+ })
111
+
90
112
  // Fired when the v-model changes.
91
113
  // @arg Emits the entire payload modified.
92
114
  this.$emit("input", dump);
@@ -133,6 +155,7 @@ export default {
133
155
  ...(this.defaultAttrs[
134
156
  this.is.replace(/-./g, (x) => x[1].toUpperCase())
135
157
  ] || {}),
158
+ readonly: this.readonly,
136
159
  ...this.conf.attrs,
137
160
  currentLang: this.currentLang,
138
161
  langs: this.langs,
@@ -142,9 +165,6 @@ export default {
142
165
  if (this.conf.label !== undefined) {
143
166
  return this.conf.label;
144
167
  }
145
- const titleCase = (string) =>
146
- (string && string[0].toUpperCase() + string.slice(1).toLowerCase()) ||
147
- "";
148
168
  return titleCase(
149
169
  (this.conf.value || "")
150
170
  .replace(/^translations\.\w\w\./, "")
@@ -0,0 +1,94 @@
1
+ <template>
2
+ <v-card v-if="conf" class="my-2 rounded-0 elevation-0 group-card">
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, readonly }"
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
+ <style lang="scss" scoped>
31
+ .theme--light .group-card {
32
+ border: 1px solid rgba(0, 0, 0, 0.12);
33
+ }
34
+ </style>
35
+ <script>
36
+ export default {
37
+ name: "FormGroup",
38
+ data() {
39
+ return {
40
+ model: {},
41
+ };
42
+ },
43
+ props: {
44
+ // V-model of the object we are editing.
45
+ value: {
46
+ type: Object,
47
+ required: true,
48
+ },
49
+ // Set the current lang to value.
50
+ currentLang: {
51
+ type: String,
52
+ required: false,
53
+ },
54
+ // 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.
55
+ errors: Object,
56
+ // Additional bindings to indrease slots capabilities
57
+ moreSlotBindings: Object,
58
+ // The main configuration that determines the arrangement of the fields in the detail layout.
59
+ conf: {
60
+ type: Object,
61
+ required: true,
62
+ },
63
+ // A list of languages into which the payload needs to be translated.
64
+ languages: {
65
+ type: Array,
66
+ default: () => [],
67
+ },
68
+ // Makes all the fields readonly.
69
+ readonly: Boolean,
70
+ },
71
+ watch: {
72
+ value(val) {
73
+ this.model = val;
74
+ },
75
+ model(val) {
76
+ this.$emit("input", val);
77
+ },
78
+ },
79
+ computed: {
80
+ slotBindings() {
81
+ return {
82
+ model: this.model,
83
+ errors: this.errors,
84
+ currentLang: this.currentLang,
85
+ langs: this.languages,
86
+ ...this.moreSlotBindings,
87
+ };
88
+ },
89
+ },
90
+ created() {
91
+ this.model = this.value;
92
+ },
93
+ };
94
+ </script>
@@ -0,0 +1,139 @@
1
+ <template>
2
+ <v-card v-if="conf" class="tabs-card my-2 rounded-0 elevation-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, readonly }"
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
+ .theme--light .tabs-card {
56
+ border: 1px solid rgba(0, 0, 0, 0.12);
57
+ }
58
+ </style>
59
+ <script>
60
+ import { findPropPaths } from "@mapomodule/utils/helpers/objHelpers";
61
+ import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
62
+
63
+ export default {
64
+ name: "FormTabs",
65
+ data() {
66
+ return {
67
+ model: {},
68
+ tabIndex: 0,
69
+ };
70
+ },
71
+ props: {
72
+ // V-model of the object we are editing.
73
+ value: {
74
+ type: Object,
75
+ required: true,
76
+ },
77
+ // Set the current lang to value.
78
+ currentLang: {
79
+ type: String,
80
+ required: false,
81
+ },
82
+ // Makes all the fields readonly.
83
+ readonly: Boolean,
84
+ // 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.
85
+ errors: Object,
86
+ // Additional bindings to indrease slots capabilities
87
+ moreSlotBindings: Object,
88
+ // The main configuration that determines the arrangement of the fields in the detail layout.
89
+ conf: {
90
+ type: Object,
91
+ required: true,
92
+ },
93
+ // A list of languages into which the payload needs to be translated.
94
+ languages: {
95
+ type: Array,
96
+ default: () => [],
97
+ },
98
+ },
99
+ watch: {
100
+ value(val) {
101
+ this.model = val;
102
+ },
103
+ model(val) {
104
+ this.$emit("input", val);
105
+ },
106
+ },
107
+ computed: {
108
+ slotBindings() {
109
+ return {
110
+ model: this.model,
111
+ errors: this.errors,
112
+ currentLang: this.currentLang,
113
+ langs: this.languages,
114
+ ...this.moreSlotBindings,
115
+ };
116
+ },
117
+ hasTitle() {
118
+ return !!(
119
+ Object.keys({ ...this.$scopedSlots, ...this.$slots }).some((s) =>
120
+ s.startsWith("title")
121
+ ) ||
122
+ this.conf.group.name ||
123
+ this.conf.group.icon
124
+ );
125
+ },
126
+ },
127
+ methods: {
128
+ nameSpacedSlots,
129
+ hasErrors(tab) {
130
+ return findPropPaths(this.errors || {}, ({ val }) =>
131
+ Array.isArray(val)
132
+ ).some((k) => tab.fields.some((f) => k.startsWith(f.value)));
133
+ },
134
+ },
135
+ created() {
136
+ this.model = this.value;
137
+ },
138
+ };
139
+ </script>
File without changes
File without changes
File without changes
File without changes