@mmlogic/components 0.1.30 → 0.3.0

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.
@@ -27,34 +27,32 @@ export class MrdField {
27
27
  render() {
28
28
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
29
29
  const { item, locale, value } = this;
30
- if (item.type === ClientLayoutItemType.RELATION && item.relation) {
31
- const rel = item.relation;
32
- return (h(Host, null, h("mrd-relation-field", { name: rel.name, label: rel.label, required: rel.required, disabled: (_a = rel.disabled) !== null && _a !== void 0 ? _a : false, locale: locale, relatedClass: rel.relatedClass, mostSignificantClass: (_b = rel.mostSignificantClass) !== null && _b !== void 0 ? _b : '', displayType: (_c = rel.displayType) !== null && _c !== void 0 ? _c : ClientLayoutItemRelationDisplayType.SEARCH, editBehavior: (_d = rel.editBehavior) !== null && _d !== void 0 ? _d : null, commonRelation: rel.commonRelation, multiple: (_e = rel.multiple) !== null && _e !== void 0 ? _e : false, dropdownValues: (_f = rel.dropdownValues) !== null && _f !== void 0 ? _f : [], value: value, onMrdChange: this.handleChange, onMrdBlur: this.handleBlur, onMrdSearch: this.handleSearch, onMrdFetchAll: this.handleFetchAll })));
30
+ if (item.type === ClientLayoutItemType.RELATION) {
31
+ return (h(Host, null, h("mrd-relation-field", { name: item.name, label: item.label, required: item.required, disabled: (_a = item.disabled) !== null && _a !== void 0 ? _a : false, locale: locale, relatedClass: item.relatedClass, mostSignificantClass: (_b = item.mostSignificantClass) !== null && _b !== void 0 ? _b : '', displayType: (_c = item.displayType) !== null && _c !== void 0 ? _c : ClientLayoutItemRelationDisplayType.SEARCH, editBehavior: (_d = item.editBehavior) !== null && _d !== void 0 ? _d : null, commonRelation: item.commonRelation, multiple: (_e = item.multiple) !== null && _e !== void 0 ? _e : false, dropdownValues: (_f = item.dropdownValues) !== null && _f !== void 0 ? _f : [], value: value, onMrdChange: this.handleChange, onMrdBlur: this.handleBlur, onMrdSearch: this.handleSearch, onMrdFetchAll: this.handleFetchAll })));
33
32
  }
34
- if (item.type !== ClientLayoutItemType.FIELD || !item.field) {
33
+ if (item.type !== ClientLayoutItemType.FIELD) {
35
34
  return h(Host, null);
36
35
  }
37
- const field = item.field;
38
36
  const commonProps = {
39
- name: field.name,
40
- label: field.label,
41
- required: field.required,
42
- disabled: (_g = field.disabled) !== null && _g !== void 0 ? _g : false,
37
+ name: item.name,
38
+ label: item.label,
39
+ required: item.required,
40
+ disabled: (_g = item.disabled) !== null && _g !== void 0 ? _g : false,
43
41
  locale,
44
42
  onMrdChange: this.handleChange,
45
43
  onMrdBlur: this.handleBlur,
46
44
  };
47
- switch (field.dataType) {
45
+ switch (item.dataType) {
48
46
  case ClientLayoutItemFieldDataType.TEXT:
49
- return (h(Host, null, h("mrd-text-field", Object.assign({}, commonProps, { value: (_h = value) !== null && _h !== void 0 ? _h : '', placeholder: (_j = field.placeholder) !== null && _j !== void 0 ? _j : '' }))));
47
+ return (h(Host, null, h("mrd-text-field", Object.assign({}, commonProps, { value: (_h = value) !== null && _h !== void 0 ? _h : '', placeholder: (_j = item.placeholder) !== null && _j !== void 0 ? _j : '' }))));
50
48
  case ClientLayoutItemFieldDataType.TEXTBLOCK:
51
- return (h(Host, null, h("mrd-textarea-field", Object.assign({}, commonProps, { value: (_k = value) !== null && _k !== void 0 ? _k : '', placeholder: (_l = field.placeholder) !== null && _l !== void 0 ? _l : '' }))));
49
+ return (h(Host, null, h("mrd-textarea-field", Object.assign({}, commonProps, { value: (_k = value) !== null && _k !== void 0 ? _k : '', placeholder: (_l = item.placeholder) !== null && _l !== void 0 ? _l : '' }))));
52
50
  case ClientLayoutItemFieldDataType.INTEGER:
53
51
  case ClientLayoutItemFieldDataType.DECIMAL:
54
52
  case ClientLayoutItemFieldDataType.PERCENTAGE:
55
- return (h(Host, null, h("mrd-number-field", Object.assign({}, commonProps, { value: (_m = value) !== null && _m !== void 0 ? _m : null, dataType: field.dataType, decimalPrecision: (_o = field.decimalPrecision) !== null && _o !== void 0 ? _o : 2, placeholder: (_p = field.placeholder) !== null && _p !== void 0 ? _p : '' }))));
53
+ return (h(Host, null, h("mrd-number-field", Object.assign({}, commonProps, { value: (_m = value) !== null && _m !== void 0 ? _m : null, dataType: item.dataType, decimalPrecision: (_o = item.decimalPrecision) !== null && _o !== void 0 ? _o : 2, placeholder: (_p = item.placeholder) !== null && _p !== void 0 ? _p : '' }))));
56
54
  case ClientLayoutItemFieldDataType.CURRENCY:
57
- return (h(Host, null, h("mrd-currency-field", Object.assign({}, commonProps, { value: (_q = value) !== null && _q !== void 0 ? _q : { amount: null, currency: (_r = field.currencyCode) !== null && _r !== void 0 ? _r : 'EUR' } }))));
55
+ return (h(Host, null, h("mrd-currency-field", Object.assign({}, commonProps, { value: (_q = value) !== null && _q !== void 0 ? _q : { amount: null, currency: (_r = item.currencyCode) !== null && _r !== void 0 ? _r : 'EUR' } }))));
58
56
  case ClientLayoutItemFieldDataType.BOOLEAN:
59
57
  return (h(Host, null, h("mrd-boolean-field", Object.assign({}, commonProps, { value: (_s = value) !== null && _s !== void 0 ? _s : false }))));
60
58
  case ClientLayoutItemFieldDataType.DATE:
@@ -64,17 +62,17 @@ export class MrdField {
64
62
  case ClientLayoutItemFieldDataType.TIME:
65
63
  return (h(Host, null, h("mrd-time-field", Object.assign({}, commonProps, { value: (_v = value) !== null && _v !== void 0 ? _v : '' }))));
66
64
  case ClientLayoutItemFieldDataType.EMAIL:
67
- return (h(Host, null, h("mrd-email-field", Object.assign({}, commonProps, { value: (_w = value) !== null && _w !== void 0 ? _w : '', placeholder: (_x = field.placeholder) !== null && _x !== void 0 ? _x : '' }))));
65
+ return (h(Host, null, h("mrd-email-field", Object.assign({}, commonProps, { value: (_w = value) !== null && _w !== void 0 ? _w : '', placeholder: (_x = item.placeholder) !== null && _x !== void 0 ? _x : '' }))));
68
66
  case ClientLayoutItemFieldDataType.HYPERLINK:
69
- return (h(Host, null, h("mrd-hyperlink-field", Object.assign({}, commonProps, { value: (_y = value) !== null && _y !== void 0 ? _y : '', placeholder: (_z = field.placeholder) !== null && _z !== void 0 ? _z : '' }))));
67
+ return (h(Host, null, h("mrd-hyperlink-field", Object.assign({}, commonProps, { value: (_y = value) !== null && _y !== void 0 ? _y : '', placeholder: (_z = item.placeholder) !== null && _z !== void 0 ? _z : '' }))));
70
68
  case ClientLayoutItemFieldDataType.LIST:
71
- return (h(Host, null, h("mrd-list-field", Object.assign({}, commonProps, { value: (_0 = value) !== null && _0 !== void 0 ? _0 : '', multiple: (_1 = field.multiple) !== null && _1 !== void 0 ? _1 : false, listItems: (_2 = field.listItems) !== null && _2 !== void 0 ? _2 : [] }))));
69
+ return (h(Host, null, h("mrd-list-field", Object.assign({}, commonProps, { value: (_0 = value) !== null && _0 !== void 0 ? _0 : '', multiple: (_1 = item.multiple) !== null && _1 !== void 0 ? _1 : false, listItems: (_2 = item.listItems) !== null && _2 !== void 0 ? _2 : [] }))));
72
70
  case ClientLayoutItemFieldDataType.FILE:
73
- return (h(Host, null, h("mrd-file-field", Object.assign({}, commonProps, { value: value, accept: (_3 = field.accept) !== null && _3 !== void 0 ? _3 : '', maxSize: (_4 = field.maxSize) !== null && _4 !== void 0 ? _4 : 0, onMrdUpload: this.handleUpload }))));
71
+ return (h(Host, null, h("mrd-file-field", Object.assign({}, commonProps, { value: value, accept: (_3 = item.accept) !== null && _3 !== void 0 ? _3 : '', maxSize: (_4 = item.maxSize) !== null && _4 !== void 0 ? _4 : 0, onMrdUpload: this.handleUpload }))));
74
72
  case ClientLayoutItemFieldDataType.IMAGE:
75
- return (h(Host, null, h("mrd-image-field", Object.assign({}, commonProps, { value: value, accept: (_5 = field.accept) !== null && _5 !== void 0 ? _5 : 'image/*', maxSize: (_6 = field.maxSize) !== null && _6 !== void 0 ? _6 : 0, onMrdUpload: this.handleUpload }))));
73
+ return (h(Host, null, h("mrd-image-field", Object.assign({}, commonProps, { value: value, accept: (_5 = item.accept) !== null && _5 !== void 0 ? _5 : 'image/*', maxSize: (_6 = item.maxSize) !== null && _6 !== void 0 ? _6 : 0, onMrdUpload: this.handleUpload }))));
76
74
  case ClientLayoutItemFieldDataType.LONGTEXT:
77
- return (h(Host, null, h("mrd-longtext-field", Object.assign({}, commonProps, { value: (_7 = value) !== null && _7 !== void 0 ? _7 : '', placeholder: (_8 = field.placeholder) !== null && _8 !== void 0 ? _8 : '' }))));
75
+ return (h(Host, null, h("mrd-longtext-field", Object.assign({}, commonProps, { value: (_7 = value) !== null && _7 !== void 0 ? _7 : '', placeholder: (_8 = item.placeholder) !== null && _8 !== void 0 ? _8 : '' }))));
78
76
  case ClientLayoutItemFieldDataType.JSON:
79
77
  return h(Host, null);
80
78
  default:
@@ -45,17 +45,17 @@ export class MrdForm {
45
45
  const newHref = this.getHref(value);
46
46
  if (newHref === prevHref)
47
47
  return;
48
- for (const rel of this.collectDependentDropdowns()) {
49
- if (rel.commonRelation !== name)
48
+ for (const item of this.collectDependentDropdowns()) {
49
+ if (item.commonRelation !== name)
50
50
  continue;
51
51
  // Clear the dependent field's current selection (options have changed)
52
- this.formValues = Object.assign(Object.assign({}, this.formValues), { [rel.name]: null });
52
+ this.formValues = Object.assign(Object.assign({}, this.formValues), { [item.name]: null });
53
53
  this.mrdFetchAll.emit({
54
- name: rel.name,
55
- relatedClass: rel.relatedClass,
56
- mostSignificantClass: rel.mostSignificantClass,
57
- commonRelation: rel.commonRelation,
58
- filter: rel.commonRelation + '_href',
54
+ name: item.name,
55
+ relatedClass: item.relatedClass,
56
+ mostSignificantClass: item.mostSignificantClass,
57
+ commonRelation: item.commonRelation,
58
+ filter: item.commonRelation + '_href',
59
59
  filterValue: newHref, // empty string when dependency was cleared → host should clear the list
60
60
  });
61
61
  }
@@ -130,24 +130,20 @@ export class MrdForm {
130
130
  var _a, _b;
131
131
  const allItems = this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []);
132
132
  // Strategy 1: direct match on mostSignificantClass
133
- const direct = allItems.find(item => {
134
- var _a;
135
- return item.type === ClientLayoutItemType.RELATION &&
136
- ((_a = item.relation) === null || _a === void 0 ? void 0 : _a.mostSignificantClass) === this.referenceClass;
137
- });
138
- if (direct === null || direct === void 0 ? void 0 : direct.relation)
139
- return direct.relation.name;
133
+ const direct = allItems.find(item => item.type === ClientLayoutItemType.RELATION &&
134
+ item.mostSignificantClass === this.referenceClass);
135
+ if (direct === null || direct === void 0 ? void 0 : direct.name)
136
+ return direct.name;
140
137
  // Strategy 2: a DROPDOWN whose commonRelation field was omitted from the layout
141
138
  const layoutRelationNames = new Set(allItems
142
139
  .filter(item => item.type === ClientLayoutItemType.RELATION)
143
- .map(item => item.relation.name));
140
+ .map(item => item.name));
144
141
  for (const item of allItems) {
145
- const rel = item.relation;
146
142
  if (item.type === ClientLayoutItemType.RELATION &&
147
- (rel === null || rel === void 0 ? void 0 : rel.editBehavior) === ClientLayoutItemRelationEditBehavior.DROPDOWN &&
148
- rel.commonRelation &&
149
- !layoutRelationNames.has(rel.commonRelation)) {
150
- return rel.commonRelation;
143
+ item.editBehavior === ClientLayoutItemRelationEditBehavior.DROPDOWN &&
144
+ item.commonRelation &&
145
+ !layoutRelationNames.has(item.commonRelation)) {
146
+ return item.commonRelation;
151
147
  }
152
148
  }
153
149
  return null;
@@ -162,25 +158,21 @@ export class MrdForm {
162
158
  collectDependentDropdowns() {
163
159
  var _a, _b;
164
160
  return this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : [])
165
- .filter(item => {
166
- var _a;
167
- return item.type === ClientLayoutItemType.RELATION &&
168
- ((_a = item.relation) === null || _a === void 0 ? void 0 : _a.editBehavior) === ClientLayoutItemRelationEditBehavior.DROPDOWN &&
169
- !!item.relation.commonRelation;
170
- })
171
- .map(item => item.relation);
161
+ .filter(item => item.type === ClientLayoutItemType.RELATION &&
162
+ item.editBehavior === ClientLayoutItemRelationEditBehavior.DROPDOWN &&
163
+ !!item.commonRelation);
172
164
  }
173
165
  /** Emit mrdFetchAll for every dependent DROPDOWN whose filter value is currently set. */
174
166
  emitDependentFetchAll() {
175
- for (const rel of this.collectDependentDropdowns()) {
176
- const filterValue = this.getHref(this.formValues[rel.commonRelation]);
167
+ for (const item of this.collectDependentDropdowns()) {
168
+ const filterValue = this.getHref(this.formValues[item.commonRelation]);
177
169
  if (filterValue) {
178
170
  this.mrdFetchAll.emit({
179
- name: rel.name,
180
- relatedClass: rel.relatedClass,
181
- mostSignificantClass: rel.mostSignificantClass,
182
- commonRelation: rel.commonRelation,
183
- filter: rel.commonRelation + '_href',
171
+ name: item.name,
172
+ relatedClass: item.relatedClass,
173
+ mostSignificantClass: item.mostSignificantClass,
174
+ commonRelation: item.commonRelation,
175
+ filter: item.commonRelation + '_href',
184
176
  filterValue,
185
177
  });
186
178
  }
@@ -210,15 +202,14 @@ export class MrdForm {
210
202
  return fields;
211
203
  }
212
204
  validate() {
213
- var _a, _b, _c;
205
+ var _a, _b;
214
206
  const newErrors = {};
215
207
  const allFields = this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []);
216
208
  for (const item of allFields) {
217
- const def = (_c = item.field) !== null && _c !== void 0 ? _c : item.relation;
218
- if (!def)
209
+ if (!item.name)
219
210
  continue;
220
- if (def.required && !validateRequired(this.formValues[def.name])) {
221
- newErrors[def.name] = t('required', this.locale);
211
+ if (item.required && !validateRequired(this.formValues[item.name])) {
212
+ newErrors[item.name] = t('required', this.locale);
222
213
  }
223
214
  }
224
215
  this.errors = newErrors;
@@ -266,8 +257,10 @@ export class MrdForm {
266
257
  const payload = {};
267
258
  const allFields = this.collectFields((_b = (_a = this.layout) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []);
268
259
  for (const item of allFields) {
269
- if (item.type === ClientLayoutItemType.FIELD && item.field) {
270
- const name = item.field.name;
260
+ if (!item.name)
261
+ continue;
262
+ const name = item.name;
263
+ if (item.type === ClientLayoutItemType.FIELD) {
271
264
  const value = this.formValues[name];
272
265
  if (value instanceof File)
273
266
  continue;
@@ -277,8 +270,7 @@ export class MrdForm {
277
270
  continue;
278
271
  payload[name] = current;
279
272
  }
280
- else if (item.type === ClientLayoutItemType.RELATION && item.relation) {
281
- const name = item.relation.name;
273
+ else if (item.type === ClientLayoutItemType.RELATION) {
282
274
  const current = this.normalizeRelationValue(this.formValues[name]);
283
275
  const initial = this.normalizeRelationValue(this.initialValues[name]);
284
276
  if (this.deepEqual(current, initial))
@@ -290,14 +282,14 @@ export class MrdForm {
290
282
  }
291
283
  renderItems(items) {
292
284
  return items.map(item => {
293
- var _a, _b, _c, _d;
285
+ var _a;
294
286
  if (item.type === ClientLayoutItemType.SECTION) {
295
287
  return (h("fieldset", { class: "mrd-form__section" }, item.label && h("legend", { class: "mrd-form__section-legend" }, item.label), h("div", { class: "mrd-form__section-body" }, item.items && this.renderItems(item.items))));
296
288
  }
297
289
  if (item.type === ClientLayoutItemType.GROUP) {
298
290
  return (h("div", { class: "mrd-form__group" }, item.label && h("div", { class: "mrd-form__group-label" }, item.label), h("div", { class: "mrd-form__group-body" }, item.items && this.renderItems(item.items))));
299
291
  }
300
- const fieldName = (_d = (_b = (_a = item.field) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (_c = item.relation) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '';
292
+ const fieldName = (_a = item.name) !== null && _a !== void 0 ? _a : '';
301
293
  const fieldValue = this.formValues[fieldName];
302
294
  return (h("div", { class: "mrd-form__field" }, h("mrd-field", { item: item, locale: this.locale, value: fieldValue, onMrdChange: this.handleFieldChange, onMrdBlur: this.handleFieldChange, onMrdSearch: this.handleSearch, onMrdFetchAll: this.handleFetchAll, onMrdUpload: this.handleUpload }), this.errors[fieldName] && (h("span", { class: "mrd-form__field-error" }, this.errors[fieldName]))));
303
295
  });