@mapomodule/uikit 1.0.0-alpha.28 → 1.0.0-alpha.29

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,24 @@
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.29](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.28...v1.0.0-alpha.29) (2022-09-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **form-field:** debounce the entire setter not only emitter to preserve the most fresh data from parents components ([31449e2](https://github.com/lotrekagency/mapo/commit/31449e2f759de23e993ef7679c8c5bf515dd347f))
12
+
13
+
14
+ ### Performance Improvements
15
+
16
+ * **detail:** remove unused console logs ([3bef461](https://github.com/lotrekagency/mapo/commit/3bef461828ef1c6e076929776b1e4e76c224a67e))
17
+ * **form:** move translations logic to from field to prevent field config manipulations and reduce rendering cycles ([06038ef](https://github.com/lotrekagency/mapo/commit/06038ef00654e85b43aa628891d4662f2b18c1c3))
18
+ * **form:** prevent inputs if value has no changes and defer inputs if not immediate flag on form ([e3da2d8](https://github.com/lotrekagency/mapo/commit/e3da2d8265d275cfe63bbdaa382f2ab4fed1f91f))
19
+
20
+
21
+
22
+
23
+
6
24
  # [1.0.0-alpha.28](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.27...v1.0.0-alpha.28) (2022-09-01)
7
25
 
8
26
 
@@ -278,7 +278,6 @@ export default {
278
278
  model(val) {
279
279
  // Fired when the v-model changes.
280
280
  // @arg Emits the entire payload modified.
281
- console.log(val, "model")
282
281
  this.$emit("input", val);
283
282
  },
284
283
  lang(val) {
@@ -287,7 +286,6 @@ export default {
287
286
  }
288
287
  },
289
288
  value(val) {
290
- console.log(val, "value")
291
289
  if (val) {
292
290
  this.model = val;
293
291
  }
@@ -83,15 +83,13 @@
83
83
  <script>
84
84
  import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
85
85
  import { slugify, titleCase } from "@mapomodule/utils/helpers/formatters";
86
- import { deepClone } from "@mapomodule/utils/helpers/objHelpers";
87
86
  import { debounce } from "@mapomodule/utils/helpers/debounce";
88
87
 
89
88
  export default {
90
89
  name: "Form",
91
90
  data() {
92
91
  return {
93
- model: {},
94
- internalFields: []
92
+ model: this.value,
95
93
  };
96
94
  },
97
95
  props: {
@@ -122,19 +120,20 @@ export default {
122
120
  type: Array,
123
121
  default: () => [],
124
122
  },
123
+ // Removes debounce from the emitter.
124
+ immediate: Boolean
125
125
  },
126
126
  watch: {
127
127
  value(val) {
128
- this.model = val;
129
- this.initLang();
128
+ if (JSON.stringify(this.model) !== JSON.stringify(val)){
129
+ this.model = val;
130
+ this.initLang();
131
+ }
130
132
  },
131
133
  model(val) {
132
- if (this.value !== val)
133
- this.debouncedEmit("input", val);
134
+ if (JSON.stringify(this.value) !== JSON.stringify(val))
135
+ this.immediate ? this.$emit("input", val) : this.debouncedEmit("input", val);
134
136
  },
135
- fields(val){
136
- this.internalFields = this.cloneFields(val)
137
- }
138
137
  },
139
138
  methods: {
140
139
  debouncedEmit: debounce(function (...args) {
@@ -150,14 +149,9 @@ export default {
150
149
  }
151
150
  },
152
151
  parseConf(field, i) {
153
- const conf = typeof field === "string" ? { value: field } : field;
152
+ const conf = typeof field === "string" ? { value: field } : { ...field };
154
153
  conf.value = conf.value || "";
155
- conf.value = conf.value.replace(new RegExp(`^translations\.(${this.languages.join("|")})\.?`), "");
156
154
  conf.slotName = `fields.${conf.value || i}`;
157
- if (this.currentLang && !field.synci18n) {
158
- const base = `translations.${this.currentLang}`;
159
- conf.value = (conf.value && `${base}.${conf.value}`) || base;
160
- }
161
155
  if (this.isReadonly) {
162
156
  conf.attrs = { ...conf.attrs, readonly: true };
163
157
  }
@@ -203,10 +197,6 @@ export default {
203
197
  }
204
198
  return true
205
199
  },
206
- cloneFields(fields){
207
- return process.browser ? deepClone(fields) : fields
208
- }
209
-
210
200
  },
211
201
  computed: {
212
202
  slotBindings() {
@@ -219,12 +209,10 @@ export default {
219
209
  };
220
210
  },
221
211
  computedFields() {
222
- return this.mapConf(this.internalFields);
212
+ return this.mapConf(this.fields);
223
213
  },
224
214
  },
225
215
  created(){
226
- this.internalFields = this.cloneFields(this.fields)
227
- this.model = this.value
228
216
  this.initLang();
229
217
  }
230
218
  };
@@ -92,16 +92,26 @@ export default {
92
92
  this.setModel(val);
93
93
  },
94
94
  },
95
- "conf.value"(newValue, oldValue) {
95
+ kpointed(newValue, oldValue) {
96
96
  if (newValue !== oldValue) {
97
97
  this.setModel();
98
98
  }
99
99
  },
100
100
  model(val) {
101
+ var model = this.extractValue(val);
102
+ if (JSON.stringify(val) !== JSON.stringify(model))
103
+ this.debouncedSetValue(val);
104
+ },
105
+ },
106
+ methods: {
107
+ debouncedSetValue: debounce(function (...args) {
108
+ this.setValue(...args);
109
+ }, 300),
110
+ setValue(val){
101
111
  const dump = { ...this.value }; // since we cannot directly edit a prop
102
112
  setPointed(
103
113
  dump,
104
- this.conf.value,
114
+ this.kpointed,
105
115
  this.accessor.set({ model: dump, val })
106
116
  );
107
117
  if (typeof this.conf.onChange == "function")
@@ -110,28 +120,35 @@ export default {
110
120
  model: dump,
111
121
  currentLang: this.currentLang,
112
122
  languages: this.langs,
113
- conf: this.conf
123
+ conf: this.conf,
124
+ kpointed: this.kpointed
114
125
  })
115
126
 
116
127
  // Fired when the v-model changes.
117
128
  // @arg Emits the entire payload modified.
118
- this.debouncedEmit("input", dump);
129
+ this.$emit("input", dump);
119
130
  },
120
- },
121
- methods: {
122
- debouncedEmit: debounce(function (...args) {
123
- this.$emit(...args);
124
- }, 300),
125
- setModel(val = this.value) {
126
- var model = this.accessor.get({
131
+ extractValue(val = this.value){
132
+ return this.accessor.get({
127
133
  model: { ...val },
128
- val: getPointed({ ...val }, this.conf.value),
134
+ val: getPointed({ ...val }, this.kpointed),
129
135
  });
136
+ },
137
+ setModel(val = this.value) {
138
+ var model = this.extractValue(val)
130
139
  if (val && JSON.stringify(this.model) !== JSON.stringify(model))
131
140
  this.model = model;
132
141
  },
133
142
  },
134
143
  computed: {
144
+ kpointed(){
145
+ let kpointed = this.conf.value
146
+ if (this.currentLang && !this.conf.synci18n) {
147
+ const base = `translations.${this.currentLang}`;
148
+ kpointed = kpointed ? `${base}.${kpointed}` : base;
149
+ }
150
+ return kpointed;
151
+ },
135
152
  accessor() {
136
153
  let func = function ({ val }) {
137
154
  return val;
@@ -146,7 +163,7 @@ export default {
146
163
  fieldAttrs() {
147
164
  return {
148
165
  label: this.label,
149
- errorMessages: this.conf.value
166
+ errorMessages: this.kpointed
150
167
  .split(".")
151
168
  .map((_, i, a) => a.slice(0, i + 1).join("."))
152
169
  .reduce((acc, next) => {
@@ -14,6 +14,7 @@
14
14
  v-bind="{ currentLang, errors, languages, readonly }"
15
15
  :fields="conf.fields"
16
16
  :moreSlotBindings="slotBindings"
17
+ immediate
17
18
  >
18
19
  <template v-for="(_, slot) in $slots" :slot="slot">
19
20
  <!-- @vuese-ignore -->
@@ -24,6 +24,7 @@
24
24
  v-bind="{ currentLang, errors, languages, readonly }"
25
25
  :fields="tab.fields"
26
26
  :moreSlotBindings="slotBindings"
27
+ immediate
27
28
  >
28
29
  <template
29
30
  v-for="slot in nameSpacedSlots($slots, `tab.${tab.tab.slug}.`)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "1.0.0-alpha.28",
3
+ "version": "1.0.0-alpha.29",
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>",
@@ -15,5 +15,5 @@
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "gitHead": "5d5b4490d8025f6f2740eed7a4c3b31ab58ec2c6"
18
+ "gitHead": "2a60a65a7baa45b0961ca2efb750828ad4a3d218"
19
19
  }