@mmlogic/components 0.1.17 → 0.1.19
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/dist/cjs/{format-IFzg0q-6.js → format-DExY8_nu.js} +4 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mosterdcomponents.cjs.js +1 -1
- package/dist/cjs/mrd-boolean-field_16.cjs.entry.js +3 -3
- package/dist/cjs/mrd-table.cjs.entry.js +116 -13
- package/dist/collection/components/mrd-form/mrd-form.js +2 -2
- package/dist/collection/components/mrd-table/mrd-table.js +158 -12
- package/dist/collection/components/mrd-table/mrd-table.scss +21 -0
- package/dist/collection/dev/api.js +1 -0
- package/dist/collection/dev/app.js +25 -0
- package/dist/collection/utils/i18n.js +4 -0
- package/dist/components/i18n.js +1 -1
- package/dist/components/mrd-form.js +1 -1
- package/dist/components/mrd-table.js +1 -1
- package/dist/esm/{format-Cc9kQ1j-.js → format-CcRjWvcb.js} +4 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mosterdcomponents.js +1 -1
- package/dist/esm/mrd-boolean-field_16.entry.js +3 -3
- package/dist/esm/mrd-table.entry.js +116 -13
- package/dist/mosterdcomponents/mosterdcomponents.esm.js +1 -1
- package/dist/mosterdcomponents/p-CcRjWvcb.js +1 -0
- package/dist/mosterdcomponents/p-bb91cc6f.entry.js +1 -0
- package/dist/mosterdcomponents/p-c5b058e7.entry.js +1 -0
- package/dist/types/components/mrd-table/mrd-table.d.ts +17 -0
- package/dist/types/components.d.ts +11 -0
- package/dist/types/types/client-layout.d.ts +8 -0
- package/package.json +1 -1
- package/dist/mosterdcomponents/p-829b9b6f.entry.js +0 -1
- package/dist/mosterdcomponents/p-Cc9kQ1j-.js +0 -1
- package/dist/mosterdcomponents/p-a3d8feb8.entry.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { h, Host } from "@stencil/core";
|
|
2
2
|
import { CellRenderer } from "../../utils/cell-renderer";
|
|
3
3
|
import { t } from "../../utils/i18n";
|
|
4
|
+
import { formatNumber, formatPercentage, formatCurrency } from "../../utils/format";
|
|
4
5
|
const BUFFER = 10;
|
|
5
6
|
/** Wacht deze tijd (ms) na het laatste scroll-event voordat pagina's worden
|
|
6
7
|
* aangevraagd. Pagina's die de gebruiker snel voorbij scrollt worden zo geskipt. */
|
|
@@ -58,6 +59,8 @@ export class MrdTable {
|
|
|
58
59
|
this.scrollTop = 0;
|
|
59
60
|
/** Full text shown in the TEXTBLOCK expand modal (null = closed). */
|
|
60
61
|
this.textblockModal = null;
|
|
62
|
+
/** Aggregation totals received from the host via setAggregations(). Null = not yet loaded. */
|
|
63
|
+
this.aggregations = null;
|
|
61
64
|
this.handleScroll = (e) => {
|
|
62
65
|
const scroller = e.currentTarget;
|
|
63
66
|
const scrollTop = scroller.scrollTop;
|
|
@@ -108,6 +111,8 @@ export class MrdTable {
|
|
|
108
111
|
const scroller = this.el.querySelector('.mrd-table__scroll');
|
|
109
112
|
if (scroller)
|
|
110
113
|
scroller.scrollTop = 0;
|
|
114
|
+
this.aggregations = null;
|
|
115
|
+
this.emitLoadAggregations();
|
|
111
116
|
}
|
|
112
117
|
/**
|
|
113
118
|
* Inject the rows for a given page (0-based).
|
|
@@ -128,6 +133,10 @@ export class MrdTable {
|
|
|
128
133
|
next.set(pageNumber, rows);
|
|
129
134
|
this.loadedPages = next;
|
|
130
135
|
}
|
|
136
|
+
/** Inject aggregation totals returned by the /aggregations endpoint. */
|
|
137
|
+
async setAggregations(data) {
|
|
138
|
+
this.aggregations = data;
|
|
139
|
+
}
|
|
131
140
|
// ── Lifecycle ──────────────────────────────────────────────────────────────
|
|
132
141
|
disconnectedCallback() {
|
|
133
142
|
if (this.outsideClickHandler) {
|
|
@@ -166,6 +175,49 @@ export class MrdTable {
|
|
|
166
175
|
return 'RELATION';
|
|
167
176
|
return (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : 'TEXT';
|
|
168
177
|
}
|
|
178
|
+
// ── Aggregation helpers ────────────────────────────────────────────────────
|
|
179
|
+
buildAggregationParams() {
|
|
180
|
+
var _a;
|
|
181
|
+
const groups = { sum: [], avg: [], count: [] };
|
|
182
|
+
for (const col of this.columns) {
|
|
183
|
+
if (col.type !== 'FIELD' || !((_a = col.field) === null || _a === void 0 ? void 0 : _a.aggregate))
|
|
184
|
+
continue;
|
|
185
|
+
const fn = col.field.aggregate.toLowerCase();
|
|
186
|
+
if (fn in groups)
|
|
187
|
+
groups[fn].push(col.field.name);
|
|
188
|
+
}
|
|
189
|
+
const params = {};
|
|
190
|
+
if (groups.sum.length)
|
|
191
|
+
params.sum = groups.sum;
|
|
192
|
+
if (groups.avg.length)
|
|
193
|
+
params.avg = groups.avg;
|
|
194
|
+
if (groups.count.length)
|
|
195
|
+
params.count = groups.count;
|
|
196
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
197
|
+
}
|
|
198
|
+
emitLoadAggregations() {
|
|
199
|
+
const params = this.buildAggregationParams();
|
|
200
|
+
if (params)
|
|
201
|
+
this.mrdLoadAggregations.emit(params);
|
|
202
|
+
}
|
|
203
|
+
renderAggregationValue(col) {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
if (col.type !== 'FIELD' || !((_a = col.field) === null || _a === void 0 ? void 0 : _a.aggregate) || !this.aggregations)
|
|
206
|
+
return '';
|
|
207
|
+
const fn = col.field.aggregate.toLowerCase();
|
|
208
|
+
const val = (_b = this.aggregations[fn]) === null || _b === void 0 ? void 0 : _b[col.field.name];
|
|
209
|
+
if (val == null)
|
|
210
|
+
return '';
|
|
211
|
+
const dt = col.field.dataType;
|
|
212
|
+
if (dt === 'INTEGER')
|
|
213
|
+
return formatNumber(val, this.locale, { maximumFractionDigits: 0 });
|
|
214
|
+
if (dt === 'PERCENTAGE')
|
|
215
|
+
return formatPercentage(val, this.locale);
|
|
216
|
+
if (dt === 'CURRENCY' && col.field.currencyCode)
|
|
217
|
+
return formatCurrency(val, col.field.currencyCode, this.locale);
|
|
218
|
+
return formatNumber(val, this.locale);
|
|
219
|
+
}
|
|
220
|
+
// ── Reset pagination ───────────────────────────────────────────────────────
|
|
169
221
|
/** Reset pagination state and scroll to top (used after sort or filter change). */
|
|
170
222
|
resetPages() {
|
|
171
223
|
if (this.debounceTimer !== null) {
|
|
@@ -286,7 +338,7 @@ export class MrdTable {
|
|
|
286
338
|
// "YYYY-MM-DD" dates so the date inputs show what the user originally entered.
|
|
287
339
|
// If from and to cover the same local day it was an exact-date filter — restore
|
|
288
340
|
// to exact mode so the user sees the single-date input again.
|
|
289
|
-
if (dataType === 'DATETIME' && existing) {
|
|
341
|
+
if (dataType === 'DATETIME' && existing && existing.operator !== 'isEmpty' && existing.operator !== 'isNotEmpty') {
|
|
290
342
|
const display = Object.assign({}, existing);
|
|
291
343
|
if (typeof display.from === 'string' && display.from)
|
|
292
344
|
display.from = this.utcISOToLocalDate(display.from);
|
|
@@ -406,7 +458,7 @@ export class MrdTable {
|
|
|
406
458
|
// Exact date → range covering the full local day (from = midnight, to = next midnight).
|
|
407
459
|
// "to" is always the exclusive end (midnight of the next local day).
|
|
408
460
|
let normalized = Object.assign({}, f);
|
|
409
|
-
if (f.dataType === 'DATETIME') {
|
|
461
|
+
if (f.dataType === 'DATETIME' && f.operator !== 'isEmpty' && f.operator !== 'isNotEmpty') {
|
|
410
462
|
if (typeof normalized.value === 'string' && normalized.value) {
|
|
411
463
|
normalized.from = this.dateLocalToUTCStart(normalized.value);
|
|
412
464
|
normalized.to = this.dateLocalToUTCEndExclusive(normalized.value);
|
|
@@ -429,6 +481,8 @@ export class MrdTable {
|
|
|
429
481
|
this.activeFilters = next;
|
|
430
482
|
this.closeFilterPopup();
|
|
431
483
|
this.mrdFilter.emit({ filters: Array.from(this.activeFilters.values()) });
|
|
484
|
+
this.aggregations = null;
|
|
485
|
+
this.emitLoadAggregations();
|
|
432
486
|
if (this.totalElements > 0) {
|
|
433
487
|
this.resetPages();
|
|
434
488
|
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
@@ -442,6 +496,8 @@ export class MrdTable {
|
|
|
442
496
|
this.activeFilters = next;
|
|
443
497
|
this.closeFilterPopup();
|
|
444
498
|
this.mrdFilter.emit({ filters: Array.from(this.activeFilters.values()) });
|
|
499
|
+
this.aggregations = null;
|
|
500
|
+
this.emitLoadAggregations();
|
|
445
501
|
if (this.totalElements > 0) {
|
|
446
502
|
this.resetPages();
|
|
447
503
|
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
@@ -450,6 +506,8 @@ export class MrdTable {
|
|
|
450
506
|
clearAllFilters() {
|
|
451
507
|
this.activeFilters = new Map();
|
|
452
508
|
this.mrdFilter.emit({ filters: [] });
|
|
509
|
+
this.aggregations = null;
|
|
510
|
+
this.emitLoadAggregations();
|
|
453
511
|
if (this.totalElements > 0) {
|
|
454
512
|
this.resetPages();
|
|
455
513
|
this.emitPagesForWindow(this.renderStart, this.renderEnd);
|
|
@@ -476,11 +534,13 @@ export class MrdTable {
|
|
|
476
534
|
return h("p", { class: "mrd-table__filter-no-support" }, t('filter_no_support', this.locale));
|
|
477
535
|
}
|
|
478
536
|
if (dataType === 'BOOLEAN') {
|
|
537
|
+
const boolOp = pf.operator;
|
|
538
|
+
const noValueOp = boolOp === 'isEmpty' || boolOp === 'isNotEmpty';
|
|
479
539
|
return (h("div", { class: "mrd-table__filter-radio-group" }, [
|
|
480
540
|
{ labelKey: 'filter_all', value: null },
|
|
481
541
|
{ labelKey: 'yes', value: true },
|
|
482
542
|
{ labelKey: 'no', value: false },
|
|
483
|
-
].map(opt => (h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: pf.value === opt.value, onChange: () => this.
|
|
543
|
+
].map(opt => (h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: !noValueOp && pf.value === opt.value, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined, value: opt.value }); } }), t(opt.labelKey, this.locale)))), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: boolOp === 'isEmpty', onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: 'isEmpty', value: undefined }); } }), t('filter_is_empty', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `bf-${this.openFilterCol}`, checked: boolOp === 'isNotEmpty', onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: 'isNotEmpty', value: undefined }); } }), t('filter_is_not_empty', this.locale))));
|
|
484
544
|
}
|
|
485
545
|
if (dataType === 'LIST') {
|
|
486
546
|
const items = (_c = (_b = col.field) === null || _b === void 0 ? void 0 : _b.listItems) !== null && _c !== void 0 ? _c : [];
|
|
@@ -498,17 +558,47 @@ export class MrdTable {
|
|
|
498
558
|
].map(o => h("option", { value: o.val, selected: op === o.val }, t(o.labelKey, this.locale)))), !noInput && (h("input", { type: "text", class: "mrd-table__filter-input", value: String((_f = pf.value) !== null && _f !== void 0 ? _f : ''), placeholder: t('filter_search_value', this.locale), onInput: (e) => this.setPending('value', e.target.value) }))));
|
|
499
559
|
}
|
|
500
560
|
if (NUMERIC_TYPES.has(dataType)) {
|
|
501
|
-
const
|
|
502
|
-
|
|
561
|
+
const numOp = pf.operator;
|
|
562
|
+
const noInput = numOp === 'isEmpty' || numOp === 'isNotEmpty';
|
|
563
|
+
const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
|
|
564
|
+
return (h("div", { class: "mrd-table__filter-editor" }, h("select", { class: "mrd-table__filter-select", onChange: (e) => {
|
|
565
|
+
const val = e.target.value;
|
|
566
|
+
if (val === 'isEmpty' || val === 'isNotEmpty') {
|
|
567
|
+
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
|
|
571
|
+
}
|
|
572
|
+
} }, h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), h("option", { value: "isEmpty", selected: numOp === 'isEmpty' }, t('filter_is_empty', this.locale)), h("option", { value: "isNotEmpty", selected: numOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (h("div", { class: "mrd-table__filter-editor" }, h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `nm-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `nm-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (h("input", { type: "number", class: "mrd-table__filter-input", value: pf.value != null ? String(pf.value) : '', onInput: (e) => this.setPending('value', e.target.value) })) : (h("div", { class: "mrd-table__filter-range" }, h("input", { type: "number", class: "mrd-table__filter-input", placeholder: t('filter_from', this.locale), value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), h("span", { class: "mrd-table__filter-range-sep" }, "\u2013"), h("input", { type: "number", class: "mrd-table__filter-input", placeholder: t('filter_to', this.locale), value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
|
|
503
573
|
}
|
|
504
574
|
if (dataType === 'DATETIME') {
|
|
505
|
-
const
|
|
506
|
-
|
|
575
|
+
const dtOp = pf.operator;
|
|
576
|
+
const noInput = dtOp === 'isEmpty' || dtOp === 'isNotEmpty';
|
|
577
|
+
const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
|
|
578
|
+
return (h("div", { class: "mrd-table__filter-editor" }, h("select", { class: "mrd-table__filter-select", onChange: (e) => {
|
|
579
|
+
const val = e.target.value;
|
|
580
|
+
if (val === 'isEmpty' || val === 'isNotEmpty') {
|
|
581
|
+
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
|
|
582
|
+
}
|
|
583
|
+
else {
|
|
584
|
+
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
|
|
585
|
+
}
|
|
586
|
+
} }, h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), h("option", { value: "isEmpty", selected: dtOp === 'isEmpty' }, t('filter_is_empty', this.locale)), h("option", { value: "isNotEmpty", selected: dtOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (h("div", { class: "mrd-table__filter-editor" }, h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (h("input", { type: "date", class: "mrd-table__filter-input", value: String((_g = pf.value) !== null && _g !== void 0 ? _g : ''), onInput: (e) => this.setPending('value', e.target.value) })) : (h("div", { class: "mrd-table__filter-range mrd-table__filter-range--stacked" }, h("label", { class: "mrd-table__filter-range-label" }, t('filter_from', this.locale)), h("input", { type: "date", class: "mrd-table__filter-input", value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), h("label", { class: "mrd-table__filter-range-label" }, t('filter_to', this.locale)), h("input", { type: "date", class: "mrd-table__filter-input", value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
|
|
507
587
|
}
|
|
508
588
|
if (DATE_TYPES.has(dataType)) {
|
|
509
589
|
const inputType = dataType === 'DATE' ? 'date' : 'time';
|
|
510
|
-
const
|
|
511
|
-
|
|
590
|
+
const dtdOp = pf.operator;
|
|
591
|
+
const noInput = dtdOp === 'isEmpty' || dtdOp === 'isNotEmpty';
|
|
592
|
+
const rangeMode = !noInput && (pf.from !== undefined || pf.to !== undefined);
|
|
593
|
+
return (h("div", { class: "mrd-table__filter-editor" }, h("select", { class: "mrd-table__filter-select", onChange: (e) => {
|
|
594
|
+
const val = e.target.value;
|
|
595
|
+
if (val === 'isEmpty' || val === 'isNotEmpty') {
|
|
596
|
+
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: val, value: undefined, from: undefined, to: undefined });
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
this.pendingFilter = Object.assign(Object.assign({}, pf), { operator: undefined });
|
|
600
|
+
}
|
|
601
|
+
} }, h("option", { value: "", selected: !noInput }, t('filter_has_value', this.locale)), h("option", { value: "isEmpty", selected: dtdOp === 'isEmpty' }, t('filter_is_empty', this.locale)), h("option", { value: "isNotEmpty", selected: dtdOp === 'isNotEmpty' }, t('filter_is_not_empty', this.locale))), !noInput && (h("div", { class: "mrd-table__filter-editor" }, h("div", { class: "mrd-table__filter-radio-group mrd-table__filter-radio-group--inline" }, h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: !rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { from: undefined, to: undefined }); } }), t('filter_exact', this.locale)), h("label", { class: "mrd-table__filter-radio-label" }, h("input", { type: "radio", name: `dt-${this.openFilterCol}`, checked: rangeMode, onChange: () => { this.pendingFilter = Object.assign(Object.assign({}, pf), { value: undefined, from: null, to: null }); } }), t('filter_range', this.locale))), !rangeMode ? (h("input", { type: inputType, class: "mrd-table__filter-input", value: String((_h = pf.value) !== null && _h !== void 0 ? _h : ''), onInput: (e) => this.setPending('value', e.target.value) })) : (h("div", { class: "mrd-table__filter-range" }, h("input", { type: inputType, class: "mrd-table__filter-input", placeholder: t('filter_from', this.locale), value: pf.from != null ? String(pf.from) : '', onInput: (e) => this.setPending('from', e.target.value) }), h("input", { type: inputType, class: "mrd-table__filter-input", placeholder: t('filter_to', this.locale), value: pf.to != null ? String(pf.to) : '', onInput: (e) => this.setPending('to', e.target.value) })))))));
|
|
512
602
|
}
|
|
513
603
|
return null;
|
|
514
604
|
}
|
|
@@ -573,6 +663,19 @@ export class MrdTable {
|
|
|
573
663
|
const value = CellRenderer.render(col, row, this.locale);
|
|
574
664
|
return (h("td", { class: `mrd-table__cell${isNumeric ? ' mrd-table__cell--numeric' : ''}` }, value));
|
|
575
665
|
}
|
|
666
|
+
// ── Render: totals row ────────────────────────────────────────────────────
|
|
667
|
+
renderTotalsRow() {
|
|
668
|
+
if (!this.aggregations)
|
|
669
|
+
return null;
|
|
670
|
+
if (!this.columns.some(c => { var _a; return c.type === 'FIELD' && ((_a = c.field) === null || _a === void 0 ? void 0 : _a.aggregate); }))
|
|
671
|
+
return null;
|
|
672
|
+
return (h("tfoot", null, h("tr", { class: "mrd-table__totals-row" }, this.columns.map(col => {
|
|
673
|
+
var _a, _b;
|
|
674
|
+
const val = this.renderAggregationValue(col);
|
|
675
|
+
const isNumeric = col.type === 'FIELD' && NUMERIC_TYPES.has((_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.dataType) !== null && _b !== void 0 ? _b : '');
|
|
676
|
+
return (h("td", { class: `mrd-table__totals-cell${isNumeric ? ' mrd-table__totals-cell--numeric' : ''}` }, val));
|
|
677
|
+
}))));
|
|
678
|
+
}
|
|
576
679
|
// ── Render ─────────────────────────────────────────────────────────────────
|
|
577
680
|
render() {
|
|
578
681
|
var _a, _b, _c;
|
|
@@ -590,7 +693,7 @@ export class MrdTable {
|
|
|
590
693
|
this.filterMode ? 'mrd-table__header--sortable' : '',
|
|
591
694
|
].filter(Boolean).join(' ');
|
|
592
695
|
return (h("th", { class: cls, onClick: this.filterMode ? (e) => this.handleFilterOpen(col, e) : undefined }, h("span", { class: "mrd-table__header-label" }, (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : ''), isFiltered && this.renderFilterIcon()));
|
|
593
|
-
}))), h("tbody", null, (_b = this.rows) === null || _b === void 0 ? void 0 : _b.map((row, i) => (h("tr", { class: "mrd-table__row mrd-table__row--clickable", style: { background: i % 2 === 0 ? '' : 'var(--mrd-color-neutral-100)' }, onClick: () => this.mrdRowClick.emit(row) }, this.columns.map(col => this.renderCell(col, row))))))), (!this.rows || this.rows.length === 0) && (h("p", { class: "mrd-table__empty" }, t('no_results', this.locale)))), this.renderFooter((_c = this.rows) === null || _c === void 0 ? void 0 : _c.length), this.renderFilterPopup(), this.renderTextblockModal()));
|
|
696
|
+
}))), h("tbody", null, (_b = this.rows) === null || _b === void 0 ? void 0 : _b.map((row, i) => (h("tr", { class: "mrd-table__row mrd-table__row--clickable", style: { background: i % 2 === 0 ? '' : 'var(--mrd-color-neutral-100)' }, onClick: () => this.mrdRowClick.emit(row) }, this.columns.map(col => this.renderCell(col, row)))))), this.renderTotalsRow()), (!this.rows || this.rows.length === 0) && (h("p", { class: "mrd-table__empty" }, t('no_results', this.locale)))), this.renderFooter((_c = this.rows) === null || _c === void 0 ? void 0 : _c.length), this.renderFilterPopup(), this.renderTextblockModal()));
|
|
594
697
|
}
|
|
595
698
|
// ── Paginated / virtual-scroll mode ────────────────────────────────────
|
|
596
699
|
// Derive the authoritative row count from loaded pages:
|
|
@@ -633,7 +736,7 @@ export class MrdTable {
|
|
|
633
736
|
isFiltered ? 'mrd-table__header--filtered' : '',
|
|
634
737
|
].filter(Boolean).join(' ');
|
|
635
738
|
return (h("th", { class: cls, style: this.colWidths[idx] ? { width: `${this.colWidths[idx]}px` } : undefined, onClick: (e) => this.filterMode ? this.handleFilterOpen(col, e) : this.handleSortClick(col) }, h("span", { class: "mrd-table__header-label" }, (_d = (_b = (_a = col.field) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = col.relation) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : ''), isActive && (h("span", { class: "mrd-table__sort-icon", "aria-hidden": "true" }, this.sortDir === 'asc' ? '▲' : '▼')), !isActive && !this.filterMode && (h("span", { class: "mrd-table__sort-icon", "aria-hidden": "true" }, "\u21C5")), isFiltered && this.renderFilterIcon()));
|
|
636
|
-
}))), h("tbody", null, topSpacerHeight > 0 && (h("tr", { class: "mrd-table__spacer", style: { height: `${topSpacerHeight}px` } }, h("td", { colSpan: colCount }))), renderedRows, bottomSpacerHeight > 0 && (h("tr", { class: "mrd-table__spacer", style: { height: `${bottomSpacerHeight}px` } }, h("td", { colSpan: colCount })))))), effectiveTotal === 0 && this.loadedPages.has(0) && (h("p", { class: "mrd-table__empty" }, t('no_results', this.locale))), effectiveTotal > 0 && this.renderFooter(undefined, effectiveTotal), this.renderFilterPopup(), this.renderTextblockModal()));
|
|
739
|
+
}))), h("tbody", null, topSpacerHeight > 0 && (h("tr", { class: "mrd-table__spacer", style: { height: `${topSpacerHeight}px` } }, h("td", { colSpan: colCount }))), renderedRows, bottomSpacerHeight > 0 && (h("tr", { class: "mrd-table__spacer", style: { height: `${bottomSpacerHeight}px` } }, h("td", { colSpan: colCount })))), this.renderTotalsRow())), effectiveTotal === 0 && this.loadedPages.has(0) && (h("p", { class: "mrd-table__empty" }, t('no_results', this.locale))), effectiveTotal > 0 && this.renderFooter(undefined, effectiveTotal), this.renderFilterPopup(), this.renderTextblockModal()));
|
|
637
740
|
}
|
|
638
741
|
renderFilterIcon() {
|
|
639
742
|
return (h("span", { class: "mrd-table__filter-icon", "aria-hidden": "true" }, h("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "currentColor" }, h("path", { d: "M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" }))));
|
|
@@ -867,7 +970,8 @@ export class MrdTable {
|
|
|
867
970
|
"pendingFilter": {},
|
|
868
971
|
"popupPos": {},
|
|
869
972
|
"scrollTop": {},
|
|
870
|
-
"textblockModal": {}
|
|
973
|
+
"textblockModal": {},
|
|
974
|
+
"aggregations": {}
|
|
871
975
|
};
|
|
872
976
|
}
|
|
873
977
|
static get events() {
|
|
@@ -958,6 +1062,21 @@ export class MrdTable {
|
|
|
958
1062
|
"resolved": "{ href: string; fileName: string; }",
|
|
959
1063
|
"references": {}
|
|
960
1064
|
}
|
|
1065
|
+
}, {
|
|
1066
|
+
"method": "mrdLoadAggregations",
|
|
1067
|
+
"name": "mrdLoadAggregations",
|
|
1068
|
+
"bubbles": true,
|
|
1069
|
+
"cancelable": true,
|
|
1070
|
+
"composed": true,
|
|
1071
|
+
"docs": {
|
|
1072
|
+
"tags": [],
|
|
1073
|
+
"text": "Fired when aggregation totals need to be (re-)fetched.\nDetail contains the fields grouped by aggregate function.\nHost calls the /aggregations endpoint and passes the result to setAggregations()."
|
|
1074
|
+
},
|
|
1075
|
+
"complexType": {
|
|
1076
|
+
"original": "{ sum?: string[]; avg?: string[]; count?: string[] }",
|
|
1077
|
+
"resolved": "{ sum?: string[] | undefined; avg?: string[] | undefined; count?: string[] | undefined; }",
|
|
1078
|
+
"references": {}
|
|
1079
|
+
}
|
|
961
1080
|
}];
|
|
962
1081
|
}
|
|
963
1082
|
static get methods() {
|
|
@@ -1011,6 +1130,33 @@ export class MrdTable {
|
|
|
1011
1130
|
"text": "Inject the rows for a given page (0-based).\nCreates a new Map reference so Stencil detects the state change.\n\nWhen the page contains fewer rows than pageSize it is the last page.\nrenderEnd is clamped immediately so no loading-placeholder rows appear\nbeyond the actual data \u2014 without requiring the host to update totalElements.",
|
|
1012
1131
|
"tags": []
|
|
1013
1132
|
}
|
|
1133
|
+
},
|
|
1134
|
+
"setAggregations": {
|
|
1135
|
+
"complexType": {
|
|
1136
|
+
"signature": "(data: AggregationResult) => Promise<void>",
|
|
1137
|
+
"parameters": [{
|
|
1138
|
+
"name": "data",
|
|
1139
|
+
"type": "AggregationResult",
|
|
1140
|
+
"docs": ""
|
|
1141
|
+
}],
|
|
1142
|
+
"references": {
|
|
1143
|
+
"Promise": {
|
|
1144
|
+
"location": "global",
|
|
1145
|
+
"id": "global::Promise"
|
|
1146
|
+
},
|
|
1147
|
+
"AggregationResult": {
|
|
1148
|
+
"location": "import",
|
|
1149
|
+
"path": "../../types/client-layout",
|
|
1150
|
+
"id": "src/types/client-layout.ts::AggregationResult",
|
|
1151
|
+
"referenceLocation": "AggregationResult"
|
|
1152
|
+
}
|
|
1153
|
+
},
|
|
1154
|
+
"return": "Promise<void>"
|
|
1155
|
+
},
|
|
1156
|
+
"docs": {
|
|
1157
|
+
"text": "Inject aggregation totals returned by the /aggregations endpoint.",
|
|
1158
|
+
"tags": []
|
|
1159
|
+
}
|
|
1014
1160
|
}
|
|
1015
1161
|
};
|
|
1016
1162
|
}
|
|
@@ -527,6 +527,27 @@
|
|
|
527
527
|
border-color: var(--mrd-color-primary-dark, var(--mrd-color-primary));
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
+
/* ── Totals row ─────────────────────────────────────────────────────────── */
|
|
531
|
+
.mrd-table__totals-row {
|
|
532
|
+
border-top: 2px solid var(--mrd-border-color);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
.mrd-table__totals-cell {
|
|
536
|
+
position: sticky;
|
|
537
|
+
bottom: 0;
|
|
538
|
+
z-index: 2;
|
|
539
|
+
padding: var(--mrd-space-2) var(--mrd-space-4);
|
|
540
|
+
background: var(--mrd-color-white);
|
|
541
|
+
font-weight: var(--mrd-font-weight-medium);
|
|
542
|
+
font-variant-numeric: tabular-nums;
|
|
543
|
+
white-space: nowrap;
|
|
544
|
+
border-top: 2px solid var(--mrd-border-color);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
.mrd-table__totals-cell--numeric {
|
|
548
|
+
text-align: right;
|
|
549
|
+
}
|
|
550
|
+
|
|
530
551
|
/* ── Pagination footer ─────────────────────────────────────────────────── */
|
|
531
552
|
.mrd-table__footer {
|
|
532
553
|
padding: var(--mrd-space-1) var(--mrd-space-2);
|
|
@@ -252,6 +252,31 @@ function renderTable(columns, totalElements, pageSize, page0Rows, dataHref, defa
|
|
|
252
252
|
_activeFilters = e.detail.filters;
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
+
// Fetch aggregation totals from /aggregations endpoint with same filter params
|
|
256
|
+
table.addEventListener('mrdLoadAggregations', async (e) => {
|
|
257
|
+
const { sum, avg, count } = e.detail;
|
|
258
|
+
try {
|
|
259
|
+
const aggUrl = dataHref.split('?')[0] + '/aggregations';
|
|
260
|
+
const params = new URLSearchParams();
|
|
261
|
+
if (sum?.length) params.set('sum', sum.join(','));
|
|
262
|
+
if (avg?.length) params.set('avg', avg.join(','));
|
|
263
|
+
if (count?.length) params.set('count', count.join(','));
|
|
264
|
+
_activeFilters.forEach(f => {
|
|
265
|
+
if (f.operator === 'isEmpty') { params.set(f.field, ''); return; }
|
|
266
|
+
if (f.operator === 'isNotEmpty') { params.set(f.field + '_notempty', 'true'); return; }
|
|
267
|
+
if (f.values?.length) { params.set(f.field, f.values.join(',')); return; }
|
|
268
|
+
if (f.value != null && f.value !== '') params.set(f.field, String(f.value));
|
|
269
|
+
if (f.from != null && f.from !== '') params.set(f.field + '_from', String(f.from));
|
|
270
|
+
if (f.to != null && f.to !== '') params.set(f.field + '_to', String(f.to));
|
|
271
|
+
});
|
|
272
|
+
const qs = params.toString();
|
|
273
|
+
const result = await apiRequest('GET', qs ? `${aggUrl}?${qs}` : aggUrl, authGetToken());
|
|
274
|
+
if (result.ok) await table.setAggregations(result.body);
|
|
275
|
+
} catch (err) {
|
|
276
|
+
console.error('[mrdLoadAggregations] mislukt', err);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
255
280
|
await table.init();
|
|
256
281
|
await table.setPage(0, page0Rows); // inject pre-fetched page 0 — no extra request
|
|
257
282
|
});
|
|
@@ -42,6 +42,7 @@ const translations = {
|
|
|
42
42
|
filter_contains: 'Bevat',
|
|
43
43
|
filter_starts_with: 'Begint met',
|
|
44
44
|
filter_equals: 'Gelijk aan',
|
|
45
|
+
filter_has_value: 'Heeft waarde',
|
|
45
46
|
filter_is_empty: 'Is leeg',
|
|
46
47
|
filter_is_not_empty: 'Is niet leeg',
|
|
47
48
|
filter_exact: 'Exact',
|
|
@@ -100,6 +101,7 @@ const translations = {
|
|
|
100
101
|
filter_contains: 'Contains',
|
|
101
102
|
filter_starts_with: 'Starts with',
|
|
102
103
|
filter_equals: 'Equals',
|
|
104
|
+
filter_has_value: 'Has value',
|
|
103
105
|
filter_is_empty: 'Is empty',
|
|
104
106
|
filter_is_not_empty: 'Is not empty',
|
|
105
107
|
filter_exact: 'Exact',
|
|
@@ -158,6 +160,7 @@ const translations = {
|
|
|
158
160
|
filter_contains: 'يحتوي على',
|
|
159
161
|
filter_starts_with: 'يبدأ بـ',
|
|
160
162
|
filter_equals: 'يساوي',
|
|
163
|
+
filter_has_value: 'له قيمة',
|
|
161
164
|
filter_is_empty: 'فارغ',
|
|
162
165
|
filter_is_not_empty: 'ليس فارغاً',
|
|
163
166
|
filter_exact: 'دقيق',
|
|
@@ -216,6 +219,7 @@ const translations = {
|
|
|
216
219
|
filter_contains: 'Contient',
|
|
217
220
|
filter_starts_with: 'Commence par',
|
|
218
221
|
filter_equals: 'Égal à',
|
|
222
|
+
filter_has_value: 'A une valeur',
|
|
219
223
|
filter_is_empty: 'Est vide',
|
|
220
224
|
filter_is_not_empty: "N'est pas vide",
|
|
221
225
|
filter_exact: 'Exact',
|
package/dist/components/i18n.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e={nl:{required:"Dit veld is verplicht",select_placeholder:"Selecteer een optie",search_placeholder:"Zoeken...",upload_file:"Bestand uploaden",choose_file:"Bestand kiezen",clear:"Wissen",today:"Vandaag",invalid_email:"Voer een geldig e-mailadres in",invalid_url:"Voer een geldige URL in",invalid_number:"Voer een geldig getal in",drop_file_here:"Sleep bestand hierheen of",browse:"bladeren",file_too_large:"Bestand is te groot",search_results:"Zoekresultaten",no_results:"Geen resultaten gevonden",loading:"Laden...",submit:"Opslaan",cancel:"Annuleren",remove:"Verwijderen",add:"Toevoegen",yes:"Ja",no:"Nee",table_of:"van",download:"Downloaden",table_filter:"Filteren",table_filter_hide:"Filter verbergen",table_filter_active:"actief",table_filter_clear_all:"Alle filters wissen",table_new_record:"Nieuw record",table_export_excel:"Exporteer naar Excel",filter_sorting:"Sortering",filter_ascending:"Oplopend",filter_descending:"Aflopend",filter_section:"Filter",filter_apply:"Toepassen",filter_clear:"Wissen",filter_contains:"Bevat",filter_starts_with:"Begint met",filter_equals:"Gelijk aan",filter_is_empty:"Is leeg",filter_is_not_empty:"Is niet leeg",filter_exact:"Exact",filter_range:"Bereik",filter_from:"Van",filter_to:"Tot",filter_all:"Alle",filter_select_all:"Alles",filter_select_none:"Geen",filter_search_value:"Zoekwaarde...",filter_no_support:"Geen filtering beschikbaar voor dit veldtype.",textblock_show_more:"Meer tonen",close:"Sluiten"},en:{required:"This field is required",select_placeholder:"Select an option",search_placeholder:"Search...",upload_file:"Upload file",choose_file:"Choose file",clear:"Clear",today:"Today",invalid_email:"Please enter a valid email address",invalid_url:"Please enter a valid URL",invalid_number:"Please enter a valid number",drop_file_here:"Drop file here or",browse:"browse",file_too_large:"File is too large",search_results:"Search results",no_results:"No results found",loading:"Loading...",submit:"Save",cancel:"Cancel",remove:"Remove",add:"Add",yes:"Yes",no:"No",table_of:"of",download:"Download",table_filter:"Filter",table_filter_hide:"Hide filter",table_filter_active:"active",table_filter_clear_all:"Clear all filters",table_new_record:"New record",table_export_excel:"Export to Excel",filter_sorting:"Sorting",filter_ascending:"Ascending",filter_descending:"Descending",filter_section:"Filter",filter_apply:"Apply",filter_clear:"Clear",filter_contains:"Contains",filter_starts_with:"Starts with",filter_equals:"Equals",filter_is_empty:"Is empty",filter_is_not_empty:"Is not empty",filter_exact:"Exact",filter_range:"Range",filter_from:"From",filter_to:"To",filter_all:"All",filter_select_all:"All",filter_select_none:"None",filter_search_value:"Search value...",filter_no_support:"Filtering is not available for this field type.",textblock_show_more:"Show more",close:"Close"},ar:{required:"هذا الحقل مطلوب",select_placeholder:"اختر خياراً",search_placeholder:"بحث...",upload_file:"رفع ملف",choose_file:"اختر ملفاً",clear:"مسح",today:"اليوم",invalid_email:"يرجى إدخال عنوان بريد إلكتروني صحيح",invalid_url:"يرجى إدخال رابط صحيح",invalid_number:"يرجى إدخال رقم صحيح",drop_file_here:"اسحب الملف هنا أو",browse:"تصفح",file_too_large:"الملف كبير جداً",search_results:"نتائج البحث",no_results:"لم يتم العثور على نتائج",loading:"جار التحميل...",submit:"حفظ",cancel:"إلغاء",remove:"إزالة",add:"إضافة",yes:"نعم",no:"لا",table_of:"من أصل",download:"تنزيل",table_filter:"تصفية",table_filter_hide:"إخفاء التصفية",table_filter_active:"نشط",table_filter_clear_all:"مسح جميع الفلاتر",table_new_record:"سجل جديد",table_export_excel:"تصدير إلى Excel",filter_sorting:"الترتيب",filter_ascending:"تصاعدي",filter_descending:"تنازلي",filter_section:"تصفية",filter_apply:"تطبيق",filter_clear:"مسح",filter_contains:"يحتوي على",filter_starts_with:"يبدأ بـ",filter_equals:"يساوي",filter_is_empty:"فارغ",filter_is_not_empty:"ليس فارغاً",filter_exact:"دقيق",filter_range:"نطاق",filter_from:"من",filter_to:"إلى",filter_all:"الكل",filter_select_all:"الكل",filter_select_none:"لا شيء",filter_search_value:"قيمة البحث...",filter_no_support:"التصفية غير متاحة لهذا النوع من الحقول.",textblock_show_more:"عرض المزيد",close:"إغلاق"},fr:{required:"Ce champ est obligatoire",select_placeholder:"Sélectionner une option",search_placeholder:"Rechercher...",upload_file:"Télécharger un fichier",choose_file:"Choisir un fichier",clear:"Effacer",today:"Aujourd'hui",invalid_email:"Veuillez saisir une adresse e-mail valide",invalid_url:"Veuillez saisir une URL valide",invalid_number:"Veuillez saisir un nombre valide",drop_file_here:"Déposez le fichier ici ou",browse:"parcourir",file_too_large:"Le fichier est trop volumineux",search_results:"Résultats de recherche",no_results:"Aucun résultat trouvé",loading:"Chargement...",submit:"Enregistrer",cancel:"Annuler",remove:"Supprimer",add:"Ajouter",yes:"Oui",no:"Non",table_of:"sur",download:"Télécharger",table_filter:"Filtrer",table_filter_hide:"Masquer le filtre",table_filter_active:"actif",table_filter_clear_all:"Effacer tous les filtres",table_new_record:"Nouvel enregistrement",table_export_excel:"Exporter vers Excel",filter_sorting:"Tri",filter_ascending:"Croissant",filter_descending:"Décroissant",filter_section:"Filtre",filter_apply:"Appliquer",filter_clear:"Effacer",filter_contains:"Contient",filter_starts_with:"Commence par",filter_equals:"Égal à",filter_is_empty:"Est vide",filter_is_not_empty:"N'est pas vide",filter_exact:"Exact",filter_range:"Plage",filter_from:"De",filter_to:"À",filter_all:"Tous",filter_select_all:"Tous",filter_select_none:"Aucun",filter_search_value:"Valeur de recherche...",filter_no_support:"Le filtrage n'est pas disponible pour ce type de champ.",textblock_show_more:"Voir plus",close:"Fermer"}};function l(l,r){var t,i,a;const _=r.split("-")[0].toLowerCase();return null!==(a=null!==(i=(null!==(t=e[_])&&void 0!==t?t:e.en)[l])&&void 0!==i?i:e.en[l])&&void 0!==a?a:l}export{l as t}
|
|
1
|
+
const e={nl:{required:"Dit veld is verplicht",select_placeholder:"Selecteer een optie",search_placeholder:"Zoeken...",upload_file:"Bestand uploaden",choose_file:"Bestand kiezen",clear:"Wissen",today:"Vandaag",invalid_email:"Voer een geldig e-mailadres in",invalid_url:"Voer een geldige URL in",invalid_number:"Voer een geldig getal in",drop_file_here:"Sleep bestand hierheen of",browse:"bladeren",file_too_large:"Bestand is te groot",search_results:"Zoekresultaten",no_results:"Geen resultaten gevonden",loading:"Laden...",submit:"Opslaan",cancel:"Annuleren",remove:"Verwijderen",add:"Toevoegen",yes:"Ja",no:"Nee",table_of:"van",download:"Downloaden",table_filter:"Filteren",table_filter_hide:"Filter verbergen",table_filter_active:"actief",table_filter_clear_all:"Alle filters wissen",table_new_record:"Nieuw record",table_export_excel:"Exporteer naar Excel",filter_sorting:"Sortering",filter_ascending:"Oplopend",filter_descending:"Aflopend",filter_section:"Filter",filter_apply:"Toepassen",filter_clear:"Wissen",filter_contains:"Bevat",filter_starts_with:"Begint met",filter_equals:"Gelijk aan",filter_has_value:"Heeft waarde",filter_is_empty:"Is leeg",filter_is_not_empty:"Is niet leeg",filter_exact:"Exact",filter_range:"Bereik",filter_from:"Van",filter_to:"Tot",filter_all:"Alle",filter_select_all:"Alles",filter_select_none:"Geen",filter_search_value:"Zoekwaarde...",filter_no_support:"Geen filtering beschikbaar voor dit veldtype.",textblock_show_more:"Meer tonen",close:"Sluiten"},en:{required:"This field is required",select_placeholder:"Select an option",search_placeholder:"Search...",upload_file:"Upload file",choose_file:"Choose file",clear:"Clear",today:"Today",invalid_email:"Please enter a valid email address",invalid_url:"Please enter a valid URL",invalid_number:"Please enter a valid number",drop_file_here:"Drop file here or",browse:"browse",file_too_large:"File is too large",search_results:"Search results",no_results:"No results found",loading:"Loading...",submit:"Save",cancel:"Cancel",remove:"Remove",add:"Add",yes:"Yes",no:"No",table_of:"of",download:"Download",table_filter:"Filter",table_filter_hide:"Hide filter",table_filter_active:"active",table_filter_clear_all:"Clear all filters",table_new_record:"New record",table_export_excel:"Export to Excel",filter_sorting:"Sorting",filter_ascending:"Ascending",filter_descending:"Descending",filter_section:"Filter",filter_apply:"Apply",filter_clear:"Clear",filter_contains:"Contains",filter_starts_with:"Starts with",filter_equals:"Equals",filter_has_value:"Has value",filter_is_empty:"Is empty",filter_is_not_empty:"Is not empty",filter_exact:"Exact",filter_range:"Range",filter_from:"From",filter_to:"To",filter_all:"All",filter_select_all:"All",filter_select_none:"None",filter_search_value:"Search value...",filter_no_support:"Filtering is not available for this field type.",textblock_show_more:"Show more",close:"Close"},ar:{required:"هذا الحقل مطلوب",select_placeholder:"اختر خياراً",search_placeholder:"بحث...",upload_file:"رفع ملف",choose_file:"اختر ملفاً",clear:"مسح",today:"اليوم",invalid_email:"يرجى إدخال عنوان بريد إلكتروني صحيح",invalid_url:"يرجى إدخال رابط صحيح",invalid_number:"يرجى إدخال رقم صحيح",drop_file_here:"اسحب الملف هنا أو",browse:"تصفح",file_too_large:"الملف كبير جداً",search_results:"نتائج البحث",no_results:"لم يتم العثور على نتائج",loading:"جار التحميل...",submit:"حفظ",cancel:"إلغاء",remove:"إزالة",add:"إضافة",yes:"نعم",no:"لا",table_of:"من أصل",download:"تنزيل",table_filter:"تصفية",table_filter_hide:"إخفاء التصفية",table_filter_active:"نشط",table_filter_clear_all:"مسح جميع الفلاتر",table_new_record:"سجل جديد",table_export_excel:"تصدير إلى Excel",filter_sorting:"الترتيب",filter_ascending:"تصاعدي",filter_descending:"تنازلي",filter_section:"تصفية",filter_apply:"تطبيق",filter_clear:"مسح",filter_contains:"يحتوي على",filter_starts_with:"يبدأ بـ",filter_equals:"يساوي",filter_has_value:"له قيمة",filter_is_empty:"فارغ",filter_is_not_empty:"ليس فارغاً",filter_exact:"دقيق",filter_range:"نطاق",filter_from:"من",filter_to:"إلى",filter_all:"الكل",filter_select_all:"الكل",filter_select_none:"لا شيء",filter_search_value:"قيمة البحث...",filter_no_support:"التصفية غير متاحة لهذا النوع من الحقول.",textblock_show_more:"عرض المزيد",close:"إغلاق"},fr:{required:"Ce champ est obligatoire",select_placeholder:"Sélectionner une option",search_placeholder:"Rechercher...",upload_file:"Télécharger un fichier",choose_file:"Choisir un fichier",clear:"Effacer",today:"Aujourd'hui",invalid_email:"Veuillez saisir une adresse e-mail valide",invalid_url:"Veuillez saisir une URL valide",invalid_number:"Veuillez saisir un nombre valide",drop_file_here:"Déposez le fichier ici ou",browse:"parcourir",file_too_large:"Le fichier est trop volumineux",search_results:"Résultats de recherche",no_results:"Aucun résultat trouvé",loading:"Chargement...",submit:"Enregistrer",cancel:"Annuler",remove:"Supprimer",add:"Ajouter",yes:"Oui",no:"Non",table_of:"sur",download:"Télécharger",table_filter:"Filtrer",table_filter_hide:"Masquer le filtre",table_filter_active:"actif",table_filter_clear_all:"Effacer tous les filtres",table_new_record:"Nouvel enregistrement",table_export_excel:"Exporter vers Excel",filter_sorting:"Tri",filter_ascending:"Croissant",filter_descending:"Décroissant",filter_section:"Filtre",filter_apply:"Appliquer",filter_clear:"Effacer",filter_contains:"Contient",filter_starts_with:"Commence par",filter_equals:"Égal à",filter_has_value:"A une valeur",filter_is_empty:"Est vide",filter_is_not_empty:"N'est pas vide",filter_exact:"Exact",filter_range:"Plage",filter_from:"De",filter_to:"À",filter_all:"Tous",filter_select_all:"Tous",filter_select_none:"Aucun",filter_search_value:"Valeur de recherche...",filter_no_support:"Le filtrage n'est pas disponible pour ce type de champ.",textblock_show_more:"Voir plus",close:"Fermer"}};function l(l,r){var t,i,a;const _=r.split("-")[0].toLowerCase();return null!==(a=null!==(i=(null!==(t=e[_])&&void 0!==t?t:e.en)[l])&&void 0!==i?i:e.en[l])&&void 0!==a?a:l}export{l as t}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{proxyCustomElement as r,HTMLElement as e,createEvent as t,h as i,Host as o,transformTag as s}from"@stencil/core/internal/client";import{a as d,d as m}from"./client-layout.js";import{t as l}from"./i18n.js";import{v as a}from"./validation.js";import{d as n}from"./mrd-boolean-field2.js";import{d as c}from"./mrd-currency-field2.js";import{d as f}from"./mrd-date-field2.js";import{d as u}from"./mrd-datetime-field2.js";import{d as h}from"./mrd-email-field2.js";import{d as v}from"./mrd-field2.js";import{d as p}from"./mrd-file-field2.js";import{d as b}from"./mrd-hyperlink-field2.js";import{d as g}from"./mrd-image-field2.js";import{d as _}from"./mrd-list-field2.js";import{d as y}from"./mrd-number-field2.js";import{d as j}from"./mrd-relation-field2.js";import{d as k}from"./mrd-text-field2.js";import{d as x}from"./mrd-textarea-field2.js";import{d as w}from"./mrd-time-field2.js";const O=r(class extends e{constructor(r){super(),!1!==r&&this.__registerHost(),this.mrdSubmit=t(this,"mrdSubmit",7),this.mrdCancel=t(this,"mrdCancel",7),this.mrdSearch=t(this,"mrdSearch",7),this.mrdFetchAll=t(this,"mrdFetchAll",7),this.mrdUpload=t(this,"mrdUpload",7),this.locale=navigator.language,this.values={},this.referenceHref="",this.referenceClass="",this.showCancel=!1,this.formValues={},this.errors={},this.submitted=!1,this.initialValues={},this.handleFieldChange=r=>{const{name:e,value:t}=r.detail,i=this.getHref(this.formValues[e]);this.formValues=Object.assign(Object.assign({},this.formValues),{[e]:t}),this.errors[e]&&(this.errors=Object.assign(Object.assign({},this.errors),{[e]:""}));const o=this.getHref(t);if(o!==i)for(const r of this.collectDependentDropdowns())r.commonRelation===e&&(this.formValues=Object.assign(Object.assign({},this.formValues),{[r.name]:null}),this.mrdFetchAll.emit({name:r.name,relatedClass:r.relatedClass,mostSignificantClass:r.mostSignificantClass,commonRelation:r.commonRelation,filter:r.commonRelation,filterValue:o}))},this.handleSearch=r=>{r.stopPropagation(),this.mrdSearch.emit(r.detail)},this.handleFetchAll=r=>{r.stopPropagation(),this.mrdFetchAll.emit(r.detail)},this.handleUpload=r=>{r.stopPropagation(),this.mrdUpload.emit(r.detail)},this.handleSubmit=r=>{r.preventDefault(),this.submitted=!0,this.validate()&&this.mrdSubmit.emit(this.buildSubmitPayload())}}componentWillLoad(){var r,e;this.initialValues=Object.assign({},null!==(r=this.values)&&void 0!==r?r:{}),this.formValues=Object.assign({},null!==(e=this.values)&&void 0!==e?e:{})}componentDidLoad(){setTimeout((()=>{this.applyReferenceValue(),this.emitDependentFetchAll()}),0)}valuesChanged(r){this.initialValues=Object.assign({},null!=r?r:{}),this.formValues=Object.assign({},null!=r?r:{}),this.applyReferenceValue(),this.errors={},this.submitted=!1,setTimeout((()=>this.emitDependentFetchAll()),0)}applyReferenceValue(){if(!this.referenceHref||!this.referenceClass)return;const r=this.resolveReferenceFieldName();r&&(this.formValues[r]||(this.formValues=Object.assign(Object.assign({},this.formValues),{[r]:this.referenceHref})))}resolveReferenceFieldName(){var r,e;const t=this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]),i=t.find((r=>{var e;return r.type===d.RELATION&&(null===(e=r.relation)||void 0===e?void 0:e.mostSignificantClass)===this.referenceClass}));if(null==i?void 0:i.relation)return i.relation.name;const o=new Set(t.filter((r=>r.type===d.RELATION)).map((r=>r.relation.name)));for(const r of t){const e=r.relation;if(r.type===d.RELATION&&(null==e?void 0:e.editBehavior)===m.DROPDOWN&&e.commonRelation&&!o.has(e.commonRelation))return e.commonRelation}return null}async setFieldValue(r,e){this.formValues=Object.assign(Object.assign({},this.formValues),{[r]:e}),this.errors[r]&&(this.errors=Object.assign(Object.assign({},this.errors),{[r]:""}))}collectDependentDropdowns(){var r,e;return this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]).filter((r=>{var e;return r.type===d.RELATION&&(null===(e=r.relation)||void 0===e?void 0:e.editBehavior)===m.DROPDOWN&&!!r.relation.commonRelation})).map((r=>r.relation))}emitDependentFetchAll(){for(const r of this.collectDependentDropdowns()){const e=this.getHref(this.formValues[r.commonRelation]);e&&this.mrdFetchAll.emit({name:r.name,relatedClass:r.relatedClass,mostSignificantClass:r.mostSignificantClass,commonRelation:r.commonRelation,filter:r.commonRelation,filterValue:e})}}getHref(r){return r?"string"==typeof r?r:"object"==typeof r&&"id"in r?r.id:"":""}collectFields(r){const e=[];for(const t of r)t.type!==d.FIELD&&t.type!==d.RELATION||e.push(t),t.items&&e.push(...this.collectFields(t.items));return e}validate(){var r,e,t;const i={},o=this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]);for(const r of o){const e=null!==(t=r.field)&&void 0!==t?t:r.relation;e&&e.required&&!a(this.formValues[e.name])&&(i[e.name]=l("required",this.locale))}return this.errors=i,0===Object.keys(i).length}normalizeFieldValue(r){return""===r||null==r?null:r}normalizeRelationValue(r){return null==r||""===r?null:"string"==typeof r?r||null:Array.isArray(r)?r.map((r=>"object"==typeof r&&null!==r&&"id"in r?r.id:r+"")):"object"==typeof r&&"id"in r&&r.id||null}deepEqual(r,e){if(r===e)return!0;if(null==r&&null==e)return!0;if(null==r||null==e)return!1;if(Array.isArray(r)&&Array.isArray(e)){if(r.length!==e.length)return!1;const t=[...r].sort(),i=[...e].sort();return JSON.stringify(t)===JSON.stringify(i)}return JSON.stringify(r)===JSON.stringify(e)}buildSubmitPayload(){var r,e;const t={},i=this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]);for(const r of i)if(r.type===d.FIELD&&r.field){const e=r.field.name,i=this.formValues[e];if(i instanceof File)continue;const o=this.normalizeFieldValue(i),s=this.normalizeFieldValue(this.initialValues[e]);if(this.deepEqual(o,s))continue;t[e]=o}else if(r.type===d.RELATION&&r.relation){const e=r.relation.name,i=this.normalizeRelationValue(this.formValues[e]),o=this.normalizeRelationValue(this.initialValues[e]);if(this.deepEqual(i,o))continue;t[e]=i}return t}renderItems(r){return r.map((r=>{var e,t,o,s;if(r.type===d.SECTION)return i("fieldset",{class:"mrd-form__section"},r.label&&i("legend",{class:"mrd-form__section-legend"},r.label),i("div",{class:"mrd-form__section-body"},r.items&&this.renderItems(r.items)));if(r.type===d.GROUP)return i("div",{class:"mrd-form__group"},r.label&&i("div",{class:"mrd-form__group-label"},r.label),i("div",{class:"mrd-form__group-body"},r.items&&this.renderItems(r.items)));const m=null!==(s=null!==(t=null===(e=r.field)||void 0===e?void 0:e.name)&&void 0!==t?t:null===(o=r.relation)||void 0===o?void 0:o.name)&&void 0!==s?s:"";return i("div",{class:"mrd-form__field"},i("mrd-field",{item:r,locale:this.locale,value:this.formValues[m],onMrdChange:this.handleFieldChange,onMrdBlur:this.handleFieldChange,onMrdSearch:this.handleSearch,onMrdFetchAll:this.handleFetchAll,onMrdUpload:this.handleUpload}),this.errors[m]&&i("span",{class:"mrd-form__field-error"},this.errors[m]))}))}render(){if(!this.layout)return i(o,null);const r=this.locale.startsWith("ar")?"rtl":"ltr";return i(o,null,i("form",{class:"mrd-form",dir:r,onSubmit:this.handleSubmit,noValidate:!0},this.layout.title&&i("h2",{class:"mrd-form__title"},this.layout.title),i("div",{class:"mrd-form__body"},this.renderItems(this.layout.items)),i("div",{class:"mrd-form__footer"},i("button",{type:"submit",class:"mrd-form__submit"},l("submit",this.locale)),this.showCancel&&i("button",{type:"button",class:"mrd-form__cancel",onClick:()=>this.mrdCancel.emit()},l("cancel",this.locale)))))}static get watchers(){return{values:[{valuesChanged:0}]}}static get style(){return".sc-mrd-form-h{display:block}.mrd-form.sc-mrd-form{font-family:var(--mrd-font-family);width:100%}.mrd-form__title.sc-mrd-form{font-size:var(--mrd-font-size-2xl);font-weight:var(--mrd-font-weight-bold);color:var(--mrd-color-neutral-900);margin:0 0 var(--mrd-space-6) 0}.mrd-form__body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-5)}.mrd-form__field.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-1)}.mrd-form__field-error.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}.mrd-form__section.sc-mrd-form{border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius-md);padding:var(--mrd-space-4) var(--mrd-space-5);margin:0}.mrd-form__section-legend.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-700);padding:0 var(--mrd-space-2)}.mrd-form__section-body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-4);margin-top:var(--mrd-space-2)}.mrd-form__group.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-2)}.mrd-form__group-label.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-500);text-transform:uppercase;letter-spacing:0.05em}.mrd-form__group-body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-4);padding-left:var(--mrd-space-4);border-left:3px solid var(--mrd-color-neutral-200)}.mrd-form__footer.sc-mrd-form{margin-top:var(--mrd-space-8);padding-top:var(--mrd-space-5);border-top:var(--mrd-border-width) solid var(--mrd-border-color);display:flex;justify-content:flex-end;gap:var(--mrd-space-3)}.mrd-form__submit.sc-mrd-form{display:inline-flex;align-items:center;justify-content:center;height:var(--mrd-input-height);padding:0 var(--mrd-space-6);background-color:var(--mrd-color-primary);color:var(--mrd-color-white);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-medium);border:none;border-radius:var(--mrd-border-radius);cursor:pointer;transition:background-color var(--mrd-transition)}.mrd-form__submit.sc-mrd-form:hover{background-color:var(--mrd-color-primary-hover)}.mrd-form__submit.sc-mrd-form:focus{outline:none;box-shadow:var(--mrd-shadow-focus)}.mrd-form__submit.sc-mrd-form:active{background-color:var(--mrd-color-primary-dark)}.mrd-form__cancel.sc-mrd-form{display:inline-flex;align-items:center;justify-content:center;height:var(--mrd-input-height);padding:0 var(--mrd-space-6);background-color:transparent;color:var(--mrd-color-neutral-600);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-medium);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);cursor:pointer;transition:background-color var(--mrd-transition), color var(--mrd-transition)}.mrd-form__cancel.sc-mrd-form:hover{background-color:var(--mrd-color-neutral-100);color:var(--mrd-color-neutral-800)}.mrd-form__cancel.sc-mrd-form:focus{outline:none;box-shadow:var(--mrd-shadow-focus)}.mrd-form__cancel.sc-mrd-form:active{background-color:var(--mrd-color-neutral-200)}"}},[2,"mrd-form",{layout:[16],locale:[1],values:[16],referenceHref:[1,"reference-href"],referenceClass:[1,"reference-class"],showCancel:[4,"show-cancel"],formValues:[32],errors:[32],submitted:[32],setFieldValue:[64]},void 0,{values:[{valuesChanged:0}]}]),E=O,z=function(){"undefined"!=typeof customElements&&["mrd-form","mrd-boolean-field","mrd-currency-field","mrd-date-field","mrd-datetime-field","mrd-email-field","mrd-field","mrd-file-field","mrd-hyperlink-field","mrd-image-field","mrd-list-field","mrd-number-field","mrd-relation-field","mrd-text-field","mrd-textarea-field","mrd-time-field"].forEach((r=>{switch(r){case"mrd-form":customElements.get(s(r))||customElements.define(s(r),O);break;case"mrd-boolean-field":customElements.get(s(r))||n();break;case"mrd-currency-field":customElements.get(s(r))||c();break;case"mrd-date-field":customElements.get(s(r))||f();break;case"mrd-datetime-field":customElements.get(s(r))||u();break;case"mrd-email-field":customElements.get(s(r))||h();break;case"mrd-field":customElements.get(s(r))||v();break;case"mrd-file-field":customElements.get(s(r))||p();break;case"mrd-hyperlink-field":customElements.get(s(r))||b();break;case"mrd-image-field":customElements.get(s(r))||g();break;case"mrd-list-field":customElements.get(s(r))||_();break;case"mrd-number-field":customElements.get(s(r))||y();break;case"mrd-relation-field":customElements.get(s(r))||j();break;case"mrd-text-field":customElements.get(s(r))||k();break;case"mrd-textarea-field":customElements.get(s(r))||x();break;case"mrd-time-field":customElements.get(s(r))||w()}}))};export{E as MrdForm,z as defineCustomElement}
|
|
1
|
+
import{proxyCustomElement as r,HTMLElement as e,createEvent as t,h as i,Host as o,transformTag as s}from"@stencil/core/internal/client";import{a as d,d as m}from"./client-layout.js";import{t as l}from"./i18n.js";import{v as a}from"./validation.js";import{d as n}from"./mrd-boolean-field2.js";import{d as c}from"./mrd-currency-field2.js";import{d as f}from"./mrd-date-field2.js";import{d as u}from"./mrd-datetime-field2.js";import{d as h}from"./mrd-email-field2.js";import{d as v}from"./mrd-field2.js";import{d as p}from"./mrd-file-field2.js";import{d as b}from"./mrd-hyperlink-field2.js";import{d as _}from"./mrd-image-field2.js";import{d as g}from"./mrd-list-field2.js";import{d as y}from"./mrd-number-field2.js";import{d as j}from"./mrd-relation-field2.js";import{d as k}from"./mrd-text-field2.js";import{d as x}from"./mrd-textarea-field2.js";import{d as w}from"./mrd-time-field2.js";const O=r(class extends e{constructor(r){super(),!1!==r&&this.__registerHost(),this.mrdSubmit=t(this,"mrdSubmit",7),this.mrdCancel=t(this,"mrdCancel",7),this.mrdSearch=t(this,"mrdSearch",7),this.mrdFetchAll=t(this,"mrdFetchAll",7),this.mrdUpload=t(this,"mrdUpload",7),this.locale=navigator.language,this.values={},this.referenceHref="",this.referenceClass="",this.showCancel=!1,this.formValues={},this.errors={},this.submitted=!1,this.initialValues={},this.handleFieldChange=r=>{const{name:e,value:t}=r.detail,i=this.getHref(this.formValues[e]);this.formValues=Object.assign(Object.assign({},this.formValues),{[e]:t}),this.errors[e]&&(this.errors=Object.assign(Object.assign({},this.errors),{[e]:""}));const o=this.getHref(t);if(o!==i)for(const r of this.collectDependentDropdowns())r.commonRelation===e&&(this.formValues=Object.assign(Object.assign({},this.formValues),{[r.name]:null}),this.mrdFetchAll.emit({name:r.name,relatedClass:r.relatedClass,mostSignificantClass:r.mostSignificantClass,commonRelation:r.commonRelation,filter:r.commonRelation+"_href",filterValue:o}))},this.handleSearch=r=>{r.stopPropagation(),this.mrdSearch.emit(r.detail)},this.handleFetchAll=r=>{r.stopPropagation(),this.mrdFetchAll.emit(r.detail)},this.handleUpload=r=>{r.stopPropagation(),this.mrdUpload.emit(r.detail)},this.handleSubmit=r=>{r.preventDefault(),this.submitted=!0,this.validate()&&this.mrdSubmit.emit(this.buildSubmitPayload())}}componentWillLoad(){var r,e;this.initialValues=Object.assign({},null!==(r=this.values)&&void 0!==r?r:{}),this.formValues=Object.assign({},null!==(e=this.values)&&void 0!==e?e:{})}componentDidLoad(){setTimeout((()=>{this.applyReferenceValue(),this.emitDependentFetchAll()}),0)}valuesChanged(r){this.initialValues=Object.assign({},null!=r?r:{}),this.formValues=Object.assign({},null!=r?r:{}),this.applyReferenceValue(),this.errors={},this.submitted=!1,setTimeout((()=>this.emitDependentFetchAll()),0)}applyReferenceValue(){if(!this.referenceHref||!this.referenceClass)return;const r=this.resolveReferenceFieldName();r&&(this.formValues[r]||(this.formValues=Object.assign(Object.assign({},this.formValues),{[r]:this.referenceHref})))}resolveReferenceFieldName(){var r,e;const t=this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]),i=t.find((r=>{var e;return r.type===d.RELATION&&(null===(e=r.relation)||void 0===e?void 0:e.mostSignificantClass)===this.referenceClass}));if(null==i?void 0:i.relation)return i.relation.name;const o=new Set(t.filter((r=>r.type===d.RELATION)).map((r=>r.relation.name)));for(const r of t){const e=r.relation;if(r.type===d.RELATION&&(null==e?void 0:e.editBehavior)===m.DROPDOWN&&e.commonRelation&&!o.has(e.commonRelation))return e.commonRelation}return null}async setFieldValue(r,e){this.formValues=Object.assign(Object.assign({},this.formValues),{[r]:e}),this.errors[r]&&(this.errors=Object.assign(Object.assign({},this.errors),{[r]:""}))}collectDependentDropdowns(){var r,e;return this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]).filter((r=>{var e;return r.type===d.RELATION&&(null===(e=r.relation)||void 0===e?void 0:e.editBehavior)===m.DROPDOWN&&!!r.relation.commonRelation})).map((r=>r.relation))}emitDependentFetchAll(){for(const r of this.collectDependentDropdowns()){const e=this.getHref(this.formValues[r.commonRelation]);e&&this.mrdFetchAll.emit({name:r.name,relatedClass:r.relatedClass,mostSignificantClass:r.mostSignificantClass,commonRelation:r.commonRelation,filter:r.commonRelation+"_href",filterValue:e})}}getHref(r){return r?"string"==typeof r?r:"object"==typeof r&&"id"in r?r.id:"":""}collectFields(r){const e=[];for(const t of r)t.type!==d.FIELD&&t.type!==d.RELATION||e.push(t),t.items&&e.push(...this.collectFields(t.items));return e}validate(){var r,e,t;const i={},o=this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]);for(const r of o){const e=null!==(t=r.field)&&void 0!==t?t:r.relation;e&&e.required&&!a(this.formValues[e.name])&&(i[e.name]=l("required",this.locale))}return this.errors=i,0===Object.keys(i).length}normalizeFieldValue(r){return""===r||null==r?null:r}normalizeRelationValue(r){return null==r||""===r?null:"string"==typeof r?r||null:Array.isArray(r)?r.map((r=>"object"==typeof r&&null!==r&&"id"in r?r.id:r+"")):"object"==typeof r&&"id"in r&&r.id||null}deepEqual(r,e){if(r===e)return!0;if(null==r&&null==e)return!0;if(null==r||null==e)return!1;if(Array.isArray(r)&&Array.isArray(e)){if(r.length!==e.length)return!1;const t=[...r].sort(),i=[...e].sort();return JSON.stringify(t)===JSON.stringify(i)}return JSON.stringify(r)===JSON.stringify(e)}buildSubmitPayload(){var r,e;const t={},i=this.collectFields(null!==(e=null===(r=this.layout)||void 0===r?void 0:r.items)&&void 0!==e?e:[]);for(const r of i)if(r.type===d.FIELD&&r.field){const e=r.field.name,i=this.formValues[e];if(i instanceof File)continue;const o=this.normalizeFieldValue(i),s=this.normalizeFieldValue(this.initialValues[e]);if(this.deepEqual(o,s))continue;t[e]=o}else if(r.type===d.RELATION&&r.relation){const e=r.relation.name,i=this.normalizeRelationValue(this.formValues[e]),o=this.normalizeRelationValue(this.initialValues[e]);if(this.deepEqual(i,o))continue;t[e]=i}return t}renderItems(r){return r.map((r=>{var e,t,o,s;if(r.type===d.SECTION)return i("fieldset",{class:"mrd-form__section"},r.label&&i("legend",{class:"mrd-form__section-legend"},r.label),i("div",{class:"mrd-form__section-body"},r.items&&this.renderItems(r.items)));if(r.type===d.GROUP)return i("div",{class:"mrd-form__group"},r.label&&i("div",{class:"mrd-form__group-label"},r.label),i("div",{class:"mrd-form__group-body"},r.items&&this.renderItems(r.items)));const m=null!==(s=null!==(t=null===(e=r.field)||void 0===e?void 0:e.name)&&void 0!==t?t:null===(o=r.relation)||void 0===o?void 0:o.name)&&void 0!==s?s:"";return i("div",{class:"mrd-form__field"},i("mrd-field",{item:r,locale:this.locale,value:this.formValues[m],onMrdChange:this.handleFieldChange,onMrdBlur:this.handleFieldChange,onMrdSearch:this.handleSearch,onMrdFetchAll:this.handleFetchAll,onMrdUpload:this.handleUpload}),this.errors[m]&&i("span",{class:"mrd-form__field-error"},this.errors[m]))}))}render(){if(!this.layout)return i(o,null);const r=this.locale.startsWith("ar")?"rtl":"ltr";return i(o,null,i("form",{class:"mrd-form",dir:r,onSubmit:this.handleSubmit,noValidate:!0},this.layout.title&&i("h2",{class:"mrd-form__title"},this.layout.title),i("div",{class:"mrd-form__body"},this.renderItems(this.layout.items)),i("div",{class:"mrd-form__footer"},i("button",{type:"submit",class:"mrd-form__submit"},l("submit",this.locale)),this.showCancel&&i("button",{type:"button",class:"mrd-form__cancel",onClick:()=>this.mrdCancel.emit()},l("cancel",this.locale)))))}static get watchers(){return{values:[{valuesChanged:0}]}}static get style(){return".sc-mrd-form-h{display:block}.mrd-form.sc-mrd-form{font-family:var(--mrd-font-family);width:100%}.mrd-form__title.sc-mrd-form{font-size:var(--mrd-font-size-2xl);font-weight:var(--mrd-font-weight-bold);color:var(--mrd-color-neutral-900);margin:0 0 var(--mrd-space-6) 0}.mrd-form__body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-5)}.mrd-form__field.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-1)}.mrd-form__field-error.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-error-font-size);color:var(--mrd-error-color)}.mrd-form__section.sc-mrd-form{border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius-md);padding:var(--mrd-space-4) var(--mrd-space-5);margin:0}.mrd-form__section-legend.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-700);padding:0 var(--mrd-space-2)}.mrd-form__section-body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-4);margin-top:var(--mrd-space-2)}.mrd-form__group.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-2)}.mrd-form__group-label.sc-mrd-form{font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-sm);font-weight:var(--mrd-font-weight-semibold);color:var(--mrd-color-neutral-500);text-transform:uppercase;letter-spacing:0.05em}.mrd-form__group-body.sc-mrd-form{display:flex;flex-direction:column;gap:var(--mrd-space-4);padding-left:var(--mrd-space-4);border-left:3px solid var(--mrd-color-neutral-200)}.mrd-form__footer.sc-mrd-form{margin-top:var(--mrd-space-8);padding-top:var(--mrd-space-5);border-top:var(--mrd-border-width) solid var(--mrd-border-color);display:flex;justify-content:flex-end;gap:var(--mrd-space-3)}.mrd-form__submit.sc-mrd-form{display:inline-flex;align-items:center;justify-content:center;height:var(--mrd-input-height);padding:0 var(--mrd-space-6);background-color:var(--mrd-color-primary);color:var(--mrd-color-white);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-medium);border:none;border-radius:var(--mrd-border-radius);cursor:pointer;transition:background-color var(--mrd-transition)}.mrd-form__submit.sc-mrd-form:hover{background-color:var(--mrd-color-primary-hover)}.mrd-form__submit.sc-mrd-form:focus{outline:none;box-shadow:var(--mrd-shadow-focus)}.mrd-form__submit.sc-mrd-form:active{background-color:var(--mrd-color-primary-dark)}.mrd-form__cancel.sc-mrd-form{display:inline-flex;align-items:center;justify-content:center;height:var(--mrd-input-height);padding:0 var(--mrd-space-6);background-color:transparent;color:var(--mrd-color-neutral-600);font-family:var(--mrd-font-family);font-size:var(--mrd-font-size-base);font-weight:var(--mrd-font-weight-medium);border:var(--mrd-border-width) solid var(--mrd-border-color);border-radius:var(--mrd-border-radius);cursor:pointer;transition:background-color var(--mrd-transition), color var(--mrd-transition)}.mrd-form__cancel.sc-mrd-form:hover{background-color:var(--mrd-color-neutral-100);color:var(--mrd-color-neutral-800)}.mrd-form__cancel.sc-mrd-form:focus{outline:none;box-shadow:var(--mrd-shadow-focus)}.mrd-form__cancel.sc-mrd-form:active{background-color:var(--mrd-color-neutral-200)}"}},[2,"mrd-form",{layout:[16],locale:[1],values:[16],referenceHref:[1,"reference-href"],referenceClass:[1,"reference-class"],showCancel:[4,"show-cancel"],formValues:[32],errors:[32],submitted:[32],setFieldValue:[64]},void 0,{values:[{valuesChanged:0}]}]),E=O,z=function(){"undefined"!=typeof customElements&&["mrd-form","mrd-boolean-field","mrd-currency-field","mrd-date-field","mrd-datetime-field","mrd-email-field","mrd-field","mrd-file-field","mrd-hyperlink-field","mrd-image-field","mrd-list-field","mrd-number-field","mrd-relation-field","mrd-text-field","mrd-textarea-field","mrd-time-field"].forEach((r=>{switch(r){case"mrd-form":customElements.get(s(r))||customElements.define(s(r),O);break;case"mrd-boolean-field":customElements.get(s(r))||n();break;case"mrd-currency-field":customElements.get(s(r))||c();break;case"mrd-date-field":customElements.get(s(r))||f();break;case"mrd-datetime-field":customElements.get(s(r))||u();break;case"mrd-email-field":customElements.get(s(r))||h();break;case"mrd-field":customElements.get(s(r))||v();break;case"mrd-file-field":customElements.get(s(r))||p();break;case"mrd-hyperlink-field":customElements.get(s(r))||b();break;case"mrd-image-field":customElements.get(s(r))||_();break;case"mrd-list-field":customElements.get(s(r))||g();break;case"mrd-number-field":customElements.get(s(r))||y();break;case"mrd-relation-field":customElements.get(s(r))||j();break;case"mrd-text-field":customElements.get(s(r))||k();break;case"mrd-textarea-field":customElements.get(s(r))||x();break;case"mrd-time-field":customElements.get(s(r))||w()}}))};export{E as MrdForm,z as defineCustomElement}
|