@mapomodule/uikit 1.0.0-alpha.2 → 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.
Files changed (49) hide show
  1. package/CHANGELOG.md +370 -0
  2. package/components/Detail/Detail.vue +281 -126
  3. package/components/Detail/DetailField.vue +68 -29
  4. package/components/Detail/DetailLangSwitch.vue +1 -1
  5. package/components/Detail/defaults.js +33 -25
  6. package/components/DropArea.vue +3 -3
  7. package/components/List/List.vue +120 -42
  8. package/components/List/ListActions.vue +56 -17
  9. package/components/List/ListFilters.vue +158 -113
  10. package/components/List/ListHead.vue +30 -12
  11. package/components/List/ListQuickEdit.vue +207 -55
  12. package/components/List/ListTable.vue +292 -77
  13. package/components/Login.vue +14 -5
  14. package/components/MediaManager/MediaEditor.vue +253 -107
  15. package/components/MediaManager/MediaFolders.vue +134 -43
  16. package/components/MediaManager/MediaGallery.vue +56 -52
  17. package/components/MediaManager/MediaManager.vue +127 -83
  18. package/components/MediaManager/MediaManagerDialog.vue +19 -22
  19. package/components/MediaManager/MediaPreview.vue +180 -0
  20. package/components/MediaManager/MediaUploader.vue +35 -32
  21. package/components/SnackBar.vue +3 -4
  22. package/components/ThemeToggle.vue +13 -0
  23. package/components/fields/DateField.vue +9 -3
  24. package/components/fields/FileField.vue +125 -0
  25. package/components/fields/FksField.vue +88 -0
  26. package/components/fields/MediaField.vue +36 -6
  27. package/components/fields/MediaM2mField.vue +8 -3
  28. package/components/fields/Repeater.vue +338 -0
  29. package/components/fields/SeoPreview.vue +89 -0
  30. package/components/fields/{TinyMce → wygEditor}/defaults.js +7 -5
  31. package/components/fields/{TinyMce → wygEditor}/utils/events.js +0 -0
  32. package/components/fields/{TinyMce → wygEditor}/utils/mapomedia.plugin.js +7 -6
  33. package/components/fields/{TinyMce → wygEditor}/utils/script.injector.js +0 -0
  34. package/components/fields/wygEditor/wygEditor.vue +256 -0
  35. package/components/layout/Sidebar/Sidebar.vue +35 -32
  36. package/components/layout/Sidebar/SidebarFooter.vue +42 -46
  37. package/components/layout/Sidebar/SidebarList.vue +13 -14
  38. package/components/layout/Sidebar/SidebarListItem.vue +99 -38
  39. package/components/layout/Sidebar/SidebarProfile.vue +42 -0
  40. package/components/layout/Topbar/Topbar.vue +3 -35
  41. package/components/layout/routebuilder.js +3 -3
  42. package/defaults.js +2 -2
  43. package/layouts/default.vue +20 -18
  44. package/layouts/empty.vue +10 -0
  45. package/package.json +5 -4
  46. package/pages/index.vue +1 -2
  47. package/components/fields/M2mField.vue +0 -95
  48. package/components/fields/TinyMce/TinyMce.vue +0 -177
  49. package/layouts/error.vue +0 -45
@@ -1,13 +1,25 @@
1
1
  <template>
2
- <component :is="is" v-model="model" v-bind="fieldProp"></component>
2
+ <div>
3
+ <span class="mapo-label" :class="`mapo-label-${conf.value}`">{{label}}</span>
4
+ <component :is="is" v-model="model" v-bind="fieldAttrs"></component>
5
+ </div>
3
6
  </template>
4
7
 
8
+ <style>
9
+ .mapo-label {
10
+ display: none;
11
+ }
12
+ </style>
13
+
5
14
  <script>
6
- import TinyMce from "@mapomodule/uikit/components/fields/TinyMce/TinyMce.vue";
15
+ import wygEditor from "@mapomodule/uikit/components/fields/wygEditor/wygEditor.vue";
7
16
  import DateField from "@mapomodule/uikit/components/fields/DateField.vue";
8
- import M2mField from "@mapomodule/uikit/components/fields/M2mField.vue";
17
+ import FksField from "@mapomodule/uikit/components/fields/FksField.vue";
9
18
  import MediaM2mField from "@mapomodule/uikit/components/fields/MediaM2mField.vue";
10
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"
11
23
 
12
24
  import { getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
13
25
  import defaults from "./defaults";
@@ -18,26 +30,29 @@ import defaults from "./defaults";
18
30
  export default {
19
31
  name: "DetailField",
20
32
  components: {
21
- TinyMce,
33
+ wygEditor,
22
34
  DateField,
23
- M2mField,
35
+ FksField,
24
36
  MediaM2mField,
25
- MediaField
37
+ MediaField,
38
+ SeoPreview,
39
+ FileField,
40
+ Repeater,
26
41
  },
27
42
 
28
43
  data() {
29
44
  return {
30
45
  model: null,
31
- fieldsMap: defaults.mapping,
32
- fieldsProps: defaults.props,
33
- fieldsAccess: defaults.accessor
46
+ defaultMap: defaults.mapping,
47
+ defaultAttrs: defaults.props,
48
+ defaultAccess: defaults.accessor,
34
49
  };
35
50
  },
36
51
  props: {
37
52
  // V-model of the payload needed to edit the field value in realtime.
38
53
  value: {
39
54
  type: Object,
40
- required: true
55
+ required: true,
41
56
  },
42
57
  // 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
58
  errors: Object,
@@ -45,18 +60,23 @@ export default {
45
60
  conf: {
46
61
  // [`FieldConfiguration`](/components/detail/Detail/#fieldconfiguration)
47
62
  type: Object,
48
- required: true
49
- }
63
+ required: true,
64
+ },
65
+ langs: {
66
+ type: Array,
67
+ default: () => []
68
+ },
69
+ currentLang: String
50
70
  },
51
71
  watch: {
52
72
  value: {
53
73
  deep: true,
54
74
  handler(val) {
55
75
  this.setModel(val);
56
- }
76
+ },
57
77
  },
58
- conf(newConf, oldConf) {
59
- if (newConf.value !== oldConf.value) {
78
+ "conf.value"(newValue, oldValue) {
79
+ if (newValue !== oldValue) {
60
80
  this.setModel();
61
81
  }
62
82
  },
@@ -70,43 +90,59 @@ export default {
70
90
  // Fired when the v-model changes.
71
91
  // @arg Emits the entire payload modified.
72
92
  this.$emit("input", dump);
73
- }
93
+ },
74
94
  },
75
95
  methods: {
76
96
  setModel(val = this.value) {
77
97
  var model = this.accessor.get({
78
98
  model: { ...val },
79
- val: getPointed({ ...val }, this.conf.value)
99
+ val: getPointed({ ...val }, this.conf.value),
80
100
  });
81
101
  if (val && JSON.stringify(this.model) !== JSON.stringify(model))
82
102
  this.model = model;
83
- }
103
+ },
84
104
  },
85
105
  computed: {
86
106
  accessor() {
87
- let func = function({ val }) {
107
+ let func = function ({ val }) {
88
108
  return val;
89
109
  };
90
110
  return {
91
111
  get: func,
92
112
  set: func,
93
- ...(this.fieldsAccess[this.is] || {}),
94
- ...this.conf.accessor
113
+ ...(this.defaultAccess[this.is] || {}),
114
+ ...this.conf.accessor,
95
115
  };
96
116
  },
97
- fieldProp() {
117
+ fieldAttrs() {
98
118
  return {
99
119
  label: this.label,
100
- errorMessages: getPointed(this.errors || {}, this.conf.value, []),
101
- ...(this.fieldsProps[this.is] || {}),
102
- ...this.conf.attrs
120
+ errorMessages: this.conf.value
121
+ .split(".")
122
+ .map((_, i, a) => a.slice(0, i + 1).join("."))
123
+ .reduce((acc, next) => {
124
+ const error = getPointed(this.errors || {}, next, []);
125
+ if (Array.isArray(error)) {
126
+ acc = [...acc, ...error];
127
+ } else if (typeof error == "string") {
128
+ acc = [...acc, error];
129
+ }
130
+ return acc;
131
+ }, []),
132
+ ...this.defaultAttrs.All,
133
+ ...(this.defaultAttrs[
134
+ this.is.replace(/-./g, (x) => x[1].toUpperCase())
135
+ ] || {}),
136
+ ...this.conf.attrs,
137
+ currentLang: this.currentLang,
138
+ langs: this.langs,
103
139
  };
104
140
  },
105
141
  label() {
106
142
  if (this.conf.label !== undefined) {
107
143
  return this.conf.label;
108
144
  }
109
- const titleCase = string =>
145
+ const titleCase = (string) =>
110
146
  (string && string[0].toUpperCase() + string.slice(1).toLowerCase()) ||
111
147
  "";
112
148
  return titleCase(
@@ -120,10 +156,13 @@ export default {
120
156
  is() {
121
157
  return (
122
158
  this.conf.is ||
123
- (this.conf.type && this.fieldsMap[this.conf.type]) ||
124
- "v-text-field"
159
+ (this.conf.type && this.defaultMap[this.conf.type]) ||
160
+ "vTextField"
125
161
  );
126
- }
162
+ },
163
+ },
164
+ mounted(){
165
+ this.setModel()
127
166
  }
128
167
  };
129
168
  </script>
@@ -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 }}
@@ -1,35 +1,39 @@
1
1
  const mapping = {
2
- text: "v-text-field",
3
- select: "v-select",
4
- date: "date-field",
5
- textarea: "v-textarea",
6
- switch: "v-switch",
7
- slider: "v-slider",
8
- file: "v-file-input",
9
- editor: "tiny-mce",
10
- media: "media-field",
11
- m2m: "m2m-field",
12
- mediaList: "media-m2m-field"
2
+ text: "vTextField",
3
+ select: "vSelect",
4
+ date: "DateField",
5
+ textarea: "vTextarea",
6
+ switch: "vSwitch",
7
+ slider: "vSlider",
8
+ file: "FileField",
9
+ editor: "wygEditor",
10
+ media: "MediaField",
11
+ fks: "FksField",
12
+ m2m: "FksField",
13
+ mediaList: "MediaM2mField",
14
+ seoPreview: "SeoPreview",
15
+ repeater: "Repeater",
13
16
  }
14
17
 
15
18
  const props = {
16
- "v-text-field": {
17
- outlined: true
18
- },
19
- "v-textarea": {
20
- outlined: true
21
- },
22
- "date-field": {
23
- outlined: true
24
- },
25
- "v-select": {
26
- outlined: true,
19
+ vSelect: {
27
20
  itemText: "text",
28
21
  itemValue: "value"
29
22
  },
30
- "v-switch": {
23
+ MediaField: {
24
+ outlined: false
25
+ },
26
+ vSwitch: {
31
27
  inset: true,
32
28
  ripple: false
29
+ },
30
+ FksField:{
31
+ itemValue: "id",
32
+ returnObject: true,
33
+ },
34
+ All : {
35
+ outlined: true,
36
+ class: "rounded-0",
33
37
  }
34
38
  }
35
39
 
@@ -38,11 +42,15 @@ const dateFunc = function ({ val }) {
38
42
  };
39
43
 
40
44
  const accessor = {
41
- "v-date-picker": {
45
+ vDatePicker: {
42
46
  get: dateFunc, set: dateFunc
43
47
  },
44
- "date-field": {
48
+ DateField: {
45
49
  get: dateFunc, set: dateFunc
50
+ },
51
+ SeoPreview: {
52
+ get: ({ val }) => ({ title: "", permalink: "", description: "", ...val }),
53
+ set: ({ val }) => ({ title: "", permalink: "", description: "", ...val })
46
54
  }
47
55
  }
48
56
  export default {
@@ -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>
@@ -3,17 +3,18 @@
3
3
  <ListHead v-bind="$attrs" />
4
4
 
5
5
  <div>
6
- <v-row class="mb-4">
6
+ <v-row class="mb-1">
7
7
  <v-col cols="12" md="4">
8
8
  <ListActions
9
9
  v-bind="$attrs"
10
10
  :crud="crud"
11
- :selection="selection"
11
+ :selection="allSelected ? 'all' : selection"
12
+ :selectionQuery="selectionQuery"
12
13
  @actionCompleted="refresh"
13
14
  />
14
15
  </v-col>
15
- <v-col cols="12" md="8">
16
- <ListFilters v-bind="$attrs" v-model="filters">
16
+ <v-col cols="12" md="8" class="d-flex flex-nowrap justify-end align-center">
17
+ <ListFilters v-bind="$attrs" v-model="filters" :disabled="dragOrderingActive">
17
18
  <template v-for="(_, slot) in $slots" :slot="slot">
18
19
  <!-- @vuese-ignore -->
19
20
  <slot :name="slot"></slot>
@@ -25,15 +26,33 @@
25
26
  </ListFilters>
26
27
  </v-col>
27
28
  </v-row>
28
- </div>
29
- <div v-if="selection.length">
30
- {{ selection.length }} elementi selezionati
29
+ <div class="d-flex justify-end">
30
+ <!-- Overrides counter for selected items. -->
31
+ <slot name="item-counter" v-bind="{ selection, canSelectAll, allSelected, toggleSelectAll }">
32
+ <div v-if="selection" class="caption mr-1 mb-1">
33
+ <b v-if="allSelected">All items selected</b>
34
+ <span v-else-if="selection.length">
35
+ {{ selection.length }} items selected
36
+ <v-btn
37
+ v-if="selection != 'all' && canSelectAll"
38
+ @click="toggleSelectAll"
39
+ outlined
40
+ tile
41
+ x-small
42
+ class="ml-1 d-inline-flex"
43
+ >Select all</v-btn
44
+ >
45
+ </span>
46
+ </div>
47
+ </slot>
48
+ </div>
31
49
  </div>
32
50
  <div>
33
51
  <ListTable
34
52
  v-model="selection"
35
53
  v-bind="{...$attrs, crud, filters}"
36
54
  v-on="$listeners"
55
+ @drag-order-change="setDragOrdering"
37
56
  ref="dtable"
38
57
  >
39
58
  <template v-for="(_, slot) in $slots" :slot="slot">
@@ -54,7 +73,7 @@
54
73
  * The purpose of this component is to provide you with a very quick way to create a page that can show a list of resources retrieved from the server.
55
74
  * A use case example could be "build a page that lists all the products of an ecommerce". <br><br>
56
75
  * This component is a wrapper and is made up of several parts.
57
- * The props and slots of this component are passed to its childs.
76
+ * The props and slots of this component are passed to its childs.
58
77
  * For detailed explanations see [Transparent Wrapping](#transparent-wrapping). <br> <h4>Index:</h4> [[toc]]
59
78
  */
60
79
  export default {
@@ -63,32 +82,56 @@ export default {
63
82
  return {
64
83
  tabActiveStatus: 1,
65
84
  selection: [],
66
- filters: []
85
+ allSelected: false,
86
+ filters: [],
87
+ dragOrderingActive: false
67
88
  };
68
89
  },
69
90
  props: {
70
91
  // The url of the endpoint that provides the data to display. From this url a complete crud (See [this.$mapo.$api.crud](/core/#$api.crud)) will be created.
71
92
  endpoint: {
72
- type: String,
73
- required: true,
93
+ type: String
74
94
  },
95
+ // Add option to select all items in all pages
96
+ canSelectAll: Boolean,
75
97
  },
76
98
  computed: {
77
99
  crud() {
78
100
  return this.$mapo.$api.crud(this.endpoint);
79
101
  },
102
+ selectionQuery() {
103
+ return this.$refs?.dtable?.getHttpParams();
104
+ }
80
105
  },
81
106
  watch: {
82
107
  selection(val) {
108
+ this.allSelected = val == 'all';
83
109
  // Fires when you select some row of the table.
84
- // @arg Emit the list of the selected rows.
110
+ // @arg Emit "all" if all items are selected, else the list of the selected rows.
85
111
  this.$emit("selectionChange", val);
86
112
  },
113
+ filters: {
114
+ deep: true,
115
+ handler(val) {
116
+ // Fires when you change filters options.
117
+ // @arg Emits the same array prop `filters` passed to the component and every filter object inside it contains an `active` array that contains the selected options.
118
+ this.$emit("filtersChange", val);
119
+ }
120
+ }
87
121
  },
88
122
  methods: {
89
123
  refresh() {
90
124
  return this.$refs.dtable.getDataFromApi();
91
125
  },
126
+ toggleSelectAll() {
127
+ return this.$refs?.dtable?.toggleSelectAll();
128
+ },
129
+ setDragOrdering(val){
130
+ this.dragOrderingActive = val;
131
+ if(val){
132
+ this.filters = [];
133
+ }
134
+ }
92
135
  },
93
136
  mounted() {},
94
137
  };
@@ -113,10 +156,7 @@ Each component within it inherits its props and slots.
113
156
  For the list of available prop refer to the documentation of each single part.
114
157
 
115
158
  ### Slots
116
- This component has not individual slots, but reflects down to its parts each assigned slot.
117
-
118
- Each part can be reached with a namespace.
119
-
159
+ Other slots related to sub-components can be reached through these namespaces:
120
160
  - `"filter"` is the namespace of [`ListFilters`](../ListFilters/#slots) slots.
121
161
  - `"dtable"` is the namespace of [`ListTable`](../ListTable/#slots) slots.
122
162
  - `"qedit"` is the namespace of [`ListQuickEdit`](../ListQuickEdit/#slots) slots.
@@ -133,18 +173,27 @@ This is an interactive example. You can play with it but remember that all http
133
173
 
134
174
  ::: demo
135
175
  <template>
136
- <v-app >
137
- <List
176
+ <v-app>
177
+ <div class="d-flex justify-end"><ThemeToggle/></div>
178
+ <List
138
179
  show-select
180
+ title="Sweets archive:"
181
+ lookup="name"
139
182
  :headers="headers"
140
183
  :editFields="editFields"
141
- :filters="availableFilters"
142
- endpoint="api/camomilla/articles"
143
- title="List Example"
144
- addItem
145
- >
146
- </List>
147
- </v-app>
184
+ :filters="availableFilters"
185
+ multi-sort
186
+ can-select-all
187
+ searchable
188
+ :data.sync="desserts"
189
+ :actions="[]"
190
+ drag-reorder
191
+ >
192
+ </List>
193
+ <br>
194
+ <h3> Data: </h3>
195
+ <pre style="background-color: unset">{{ desserts }}</pre>
196
+ </v-app>
148
197
  </template>
149
198
 
150
199
  <script>
@@ -153,37 +202,66 @@ export default {
153
202
  return {
154
203
  headers: [
155
204
  {
156
- text: "ID",
205
+ text: "Dessert (100g serving)",
157
206
  align: "start",
158
207
  sortable: false,
159
- value: "id",
208
+ value: "name",
160
209
  },
161
- { text: "Title", value: "title" },
162
- { text: "Identifier", value: "identifier" },
210
+ { text: "Protein (g)", value: "protein" },
211
+ { text: "Gluten-Free", value: "glutenfree" },
163
212
  { text: "Actions", value: "actions", sortable: false },
164
213
  ],
165
214
  editFields: [
166
- { attrs: { rules:[v => !!v || 'Title is required'] }, value: "title" },
167
- { attrs: { rules:[v => !!v || 'Permalink is required'] }, value: "permalink" },
168
- { attrs: { rules:[v => !!v || 'Identifier is required'] }, value: "identifier" },
215
+ { attrs: { rules: [(v) => !!v || "Name is required"] }, value: "name" },
216
+ { value: "protein" }
169
217
  ],
170
218
  availableFilters: [
171
219
  {
172
- text: "Status",
173
- value: "status",
220
+ text: "Gluten Free",
221
+ value: "glutenfree",
174
222
  choices: [
175
- { text: "Draft", value: "DRF" },
176
- { text: "Published", value: "PUB" },
177
- { text: "Trash", value: "TRS" },
223
+ { text: "Yes", value: true },
224
+ { text: "No", value: false },
178
225
  ],
179
226
  },
227
+ ],
228
+ desserts: [
229
+ {
230
+ name: "Frozen Yogurt",
231
+ protein: 4.0,
232
+ glutenfree: true,
233
+ },
234
+ {
235
+ name: "Ice cream sandwich",
236
+ protein: 4.3,
237
+ glutenfree: false,
238
+ },
180
239
  {
181
- text: "Date",
182
- value: "date",
183
- datepicker: true
240
+ name: "Eclair",
241
+ protein: 6.0,
242
+ glutenfree: false,
243
+ },
244
+ {
245
+ name: "Jelly bean",
246
+ protein: 0.0,
247
+ glutenfree: true,
248
+ },
249
+ {
250
+ name: "Lollipop",
251
+ protein: 0,
252
+ glutenfree: true,
253
+ },
254
+ {
255
+ name: "KitKat",
256
+ protein: 7,
257
+ glutenfree: false,
258
+ },
259
+ {
260
+ name: "KitKat2",
261
+ protein: 77,
262
+ glutenfree: false,
184
263
  },
185
264
  ],
186
-
187
265
  };
188
266
  },
189
267
  };
@@ -191,4 +269,4 @@ export default {
191
269
  :::
192
270
 
193
271
 
194
- </docs>
272
+ </docs>