@iamproperty/components 3.7.1 → 3.7.3
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/assets/css/components/dialog.css +1 -1
- package/assets/css/components/dialog.css.map +1 -1
- package/assets/css/components/pagination.css +1 -1
- package/assets/css/components/pagination.css.map +1 -1
- package/assets/css/components/table.css +1 -1
- package/assets/css/components/table.css.map +1 -1
- package/assets/css/core.min.css +1 -1
- package/assets/css/core.min.css.map +1 -1
- package/assets/css/style.min.css +1 -1
- package/assets/css/style.min.css.map +1 -1
- package/assets/js/components/accordion/accordion.component.min.js +1 -1
- package/assets/js/components/applied-filters/applied-filters.component.min.js +14 -0
- package/assets/js/components/applied-filters/applied-filters.component.min.js.map +1 -0
- package/assets/js/components/card/card.component.min.js +1 -1
- package/assets/js/components/filterlist/filterlist.component.min.js +1 -1
- package/assets/js/components/header/header.component.min.js +1 -1
- package/assets/js/components/pagination/pagination.component.min.js +18 -0
- package/assets/js/components/pagination/pagination.component.min.js.map +1 -0
- package/assets/js/components/table/table.component.js +1 -0
- package/assets/js/components/table/table.component.min.js +13 -13
- package/assets/js/components/table/table.component.min.js.map +1 -1
- package/assets/js/components/tabs/tabs.component.min.js +1 -1
- package/assets/js/dynamic.min.js +1 -1
- package/assets/js/modules/table.js +137 -68
- package/assets/js/scripts.bundle.js +19 -19
- package/assets/js/scripts.bundle.js.map +1 -1
- package/assets/js/scripts.bundle.min.js +2 -2
- package/assets/js/scripts.bundle.min.js.map +1 -1
- package/assets/sass/components/dialog.scss +11 -0
- package/assets/sass/components/pagination.scss +2 -1
- package/assets/sass/components/table.scss +63 -38
- package/assets/ts/components/table/table.component.ts +1 -0
- package/assets/ts/modules/table.ts +147 -69
- package/dist/components.es.js +726 -690
- package/dist/components.umd.js +21 -21
- package/package.json +1 -1
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
// @ts-nocheck
|
|
2
11
|
import { zeroPad, isNumeric, ucfirst } from "./helpers.js";
|
|
3
12
|
import createPaginationButttons from "./pagination.js";
|
|
@@ -30,16 +39,15 @@ export const addDataAttributes = (table) => {
|
|
|
30
39
|
};
|
|
31
40
|
export const getLargestLastColWidth = (table) => {
|
|
32
41
|
let largestWidth = 0;
|
|
33
|
-
Array.from(table.querySelectorAll('tr')).forEach((row, index) => {
|
|
42
|
+
Array.from(table.querySelectorAll('tbody tr')).forEach((row, index) => {
|
|
34
43
|
let htmlStyles = window.getComputedStyle(document.querySelector('html'));
|
|
35
44
|
let lastColChild = row.querySelector(':scope > *:last-child > *:first-child');
|
|
36
45
|
if (lastColChild) {
|
|
46
|
+
lastColChild.classList.add('text-nowrap');
|
|
37
47
|
let responsiveWidth = lastColChild.offsetWidth / parseFloat(htmlStyles.fontSize);
|
|
38
|
-
responsiveWidth += 1.
|
|
48
|
+
responsiveWidth += 1.7;
|
|
39
49
|
largestWidth = largestWidth > responsiveWidth ? largestWidth : responsiveWidth;
|
|
40
50
|
}
|
|
41
|
-
let rowHeight = row.offsetHeight / parseFloat(htmlStyles.fontSize);
|
|
42
|
-
row.style.setProperty("--row-height", `${rowHeight}rem`);
|
|
43
51
|
});
|
|
44
52
|
return largestWidth;
|
|
45
53
|
};
|
|
@@ -191,8 +199,8 @@ export const addFilterEventListeners = (table, form, pagination, wrapper, savedT
|
|
|
191
199
|
let parentForm = mimicInput.closest('form');
|
|
192
200
|
if (!forms.includes(parentForm))
|
|
193
201
|
forms.push(parentForm);
|
|
194
|
-
if (!fields.includes(
|
|
195
|
-
fields.push(
|
|
202
|
+
if (!fields.includes(mimicField))
|
|
203
|
+
fields.push(mimicField);
|
|
196
204
|
});
|
|
197
205
|
});
|
|
198
206
|
// For each form add change listener
|
|
@@ -214,6 +222,14 @@ export const addFilterEventListeners = (table, form, pagination, wrapper, savedT
|
|
|
214
222
|
const event = new Event("force");
|
|
215
223
|
form.dispatchEvent(event);
|
|
216
224
|
}
|
|
225
|
+
// Check for empties
|
|
226
|
+
for (const field of fields) {
|
|
227
|
+
if (!formData.has(field) && parentForm.querySelector(`[name="${field}"]`)) {
|
|
228
|
+
document.querySelector(`[data-mimic="${field}"]`).value = "";
|
|
229
|
+
const event = new Event("force");
|
|
230
|
+
form.dispatchEvent(event);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
217
233
|
};
|
|
218
234
|
parentForm.addEventListener('force', (event) => {
|
|
219
235
|
updateMimicInput();
|
|
@@ -542,76 +558,129 @@ export const makeTableFunctional = function (table, form, pagination, wrapper) {
|
|
|
542
558
|
if (wrapper && wrapper.classList.contains('table--cta')) {
|
|
543
559
|
const largestWidth = getLargestLastColWidth(table);
|
|
544
560
|
wrapper.style.setProperty("--cta-width", `${largestWidth}rem`);
|
|
561
|
+
function outputsize() {
|
|
562
|
+
Array.from(table.querySelectorAll('tr')).forEach((row, index) => {
|
|
563
|
+
let rowHeight = row.offsetHeight;
|
|
564
|
+
row.style.setProperty("--row-height", `${rowHeight}px`);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
new ResizeObserver(outputsize).observe(table);
|
|
545
568
|
}
|
|
546
569
|
};
|
|
547
570
|
export const loadAjaxTable = function (table, form, pagination, wrapper) {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
571
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
572
|
+
const resolvePath = (object, path, defaultValue) => path.split(/[\.\[\]\'\"]/).filter(p => p).reduce((o, p) => o ? o[p] : defaultValue, object);
|
|
573
|
+
let formData = new FormData(form);
|
|
574
|
+
let queryString = new URLSearchParams(formData).toString();
|
|
575
|
+
let columns = table.querySelectorAll('thead tr th');
|
|
576
|
+
let tbody = table.querySelector('tbody');
|
|
577
|
+
let ajaxURL = form.getAttribute('data-ajax');
|
|
578
|
+
wrapper.classList.add('table--loading');
|
|
579
|
+
// Setup controller vars if not already set
|
|
580
|
+
if (!window.controller)
|
|
581
|
+
window.controller = [];
|
|
582
|
+
// Abort if controller already present for this url
|
|
583
|
+
if (window.controller[ajaxURL])
|
|
584
|
+
window.controller[ajaxURL].abort();
|
|
585
|
+
// Create a new controller so it can be aborted if new fetch made
|
|
586
|
+
window.controller[ajaxURL] = new AbortController();
|
|
587
|
+
const { signal } = controller[ajaxURL];
|
|
588
|
+
try {
|
|
589
|
+
yield fetch(ajaxURL + '?' + queryString, {
|
|
590
|
+
signal: signal,
|
|
591
|
+
method: 'get',
|
|
592
|
+
credentials: 'same-origin',
|
|
593
|
+
headers: new Headers({
|
|
594
|
+
'Content-Type': 'application/json',
|
|
595
|
+
Accept: 'application/json',
|
|
596
|
+
'X-Requested-With': 'XMLHttpRequest'
|
|
597
|
+
})
|
|
598
|
+
})
|
|
599
|
+
.then((response) => response.json()).then((response) => {
|
|
600
|
+
let schema = form.hasAttribute('data-schema') ? form.getAttribute('data-schema') : 'data';
|
|
601
|
+
let totalNumberSchema = form.hasAttribute('data-schema-total') ? form.getAttribute('data-schema-total') : 'meta.total';
|
|
602
|
+
let currentPageSchema = form.hasAttribute('data-schema-page') ? form.getAttribute('data-schema-page') : 'meta.current_page';
|
|
603
|
+
let totalNumber = resolvePath(response, totalNumberSchema, 1);
|
|
604
|
+
let currentPage = resolvePath(response, currentPageSchema, 1);
|
|
605
|
+
let data = resolvePath(response, schema);
|
|
606
|
+
let emptyMsg = wrapper.hasAttribute('data-empty-msg') ? wrapper.getAttribute('data-empty-msg') : "No results found";
|
|
607
|
+
if (data) {
|
|
608
|
+
tbody.innerHTML = '';
|
|
609
|
+
data.forEach((row, index) => {
|
|
610
|
+
var table_row = document.createElement('tr');
|
|
611
|
+
columns.forEach((col, index) => {
|
|
612
|
+
let cellOutput = '';
|
|
613
|
+
var table_cell = document.createElement('td');
|
|
614
|
+
// Add some data to help with the mobile layout design
|
|
615
|
+
table_cell.setAttribute('data-label', col.innerText);
|
|
616
|
+
if (col.getAttribute('data-output')) {
|
|
617
|
+
var cellTemplate = col.getAttribute('data-output');
|
|
618
|
+
// Use a regex to replace {var} with actual values from the json data
|
|
619
|
+
cellOutput = cellTemplate.replace(new RegExp(/{(.*?)}/, "gm"), function (matched) { return resolvePath(row, matched.replace('{', '').replace('}', '')); });
|
|
620
|
+
}
|
|
621
|
+
// If an output array is defined then the content is going to made of of multiple values from an array
|
|
622
|
+
if (col.hasAttribute('data-output-array')) {
|
|
623
|
+
var cellTemplate = col.getAttribute('data-output');
|
|
624
|
+
let arrValue = resolvePath(row, cellTemplate.replace('{', '').replace('}', ''));
|
|
625
|
+
cellOutput = "";
|
|
626
|
+
arrValue.forEach((rowValue, i) => {
|
|
627
|
+
let cellTemplateValue = col.getAttribute('data-output-array');
|
|
628
|
+
let cellOutputValue = "";
|
|
629
|
+
// If we need to transform some of the data
|
|
630
|
+
if (col.hasAttribute('data-output-array-property') && col.hasAttribute('data-output-array-transform')) {
|
|
631
|
+
const propertyValue = resolvePath(rowValue, col.getAttribute('data-output-array-property'));
|
|
632
|
+
const transforms = JSON.parse(col.getAttribute('data-output-array-transform'));
|
|
633
|
+
const transformValue = transforms[propertyValue];
|
|
634
|
+
cellOutputValue = cellTemplateValue.replace(`{${col.getAttribute('data-output-array-property')}}`, transformValue);
|
|
635
|
+
}
|
|
636
|
+
cellOutputValue = cellOutputValue.replace(new RegExp(/{(.*?)}/, "gm"), function (matched) { return resolvePath(rowValue, matched.replace('{', '').replace('}', '')); });
|
|
637
|
+
cellOutput += cellOutputValue;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
if (col.hasAttribute('data-transform')) {
|
|
641
|
+
const transforms = JSON.parse(col.getAttribute('data-transform'));
|
|
642
|
+
cellOutput = transforms[cellOutput];
|
|
643
|
+
if (!cellOutput && col.hasAttribute('data-default'))
|
|
644
|
+
cellOutput = col.getAttribute('data-default');
|
|
645
|
+
}
|
|
646
|
+
table_cell.innerHTML = cellOutput;
|
|
647
|
+
table_row.appendChild(table_cell);
|
|
648
|
+
});
|
|
649
|
+
tbody.appendChild(table_row);
|
|
650
|
+
});
|
|
651
|
+
createSearchDataList(table, form);
|
|
652
|
+
// Add data to the pagination
|
|
653
|
+
wrapper.setAttribute('data-total', parseInt(totalNumber));
|
|
654
|
+
wrapper.setAttribute('data-page', parseInt(currentPage));
|
|
655
|
+
wrapper.setAttribute('data-pages', Math.ceil(wrapper.getAttribute('data-total') / wrapper.getAttribute('data-show')));
|
|
656
|
+
makeTableFunctional(table, form, pagination, wrapper);
|
|
657
|
+
createPaginationButttons(wrapper, pagination);
|
|
658
|
+
if (parseInt(totalNumber) == 0) {
|
|
659
|
+
tbody.innerHTML = `<tr><td colspan="100%"><span>${emptyMsg}</span></td></tr>`;
|
|
582
660
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
661
|
+
wrapper.classList.remove('table--loading');
|
|
662
|
+
window.dataLayer = window.dataLayer || [];
|
|
663
|
+
window.dataLayer.push({
|
|
664
|
+
"event": "Ajax table loaded",
|
|
665
|
+
"url": ajaxURL,
|
|
666
|
+
"formData": queryString
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
tbody.innerHTML = '<tr><td colspan="100%"><span>Error loading table</span></td></tr>';
|
|
671
|
+
}
|
|
672
|
+
// Pass post data back to the page
|
|
673
|
+
if (form.hasAttribute('data-ajax-post')) {
|
|
674
|
+
const http = new XMLHttpRequest();
|
|
675
|
+
http.open('GET', `${window.location.href}?ajax=true&${queryString}`);
|
|
676
|
+
http.send();
|
|
677
|
+
}
|
|
593
678
|
});
|
|
594
|
-
createSearchDataList(table, form);
|
|
595
|
-
// Add data to the pagination
|
|
596
|
-
wrapper.setAttribute('data-total', parseInt(totalNumber));
|
|
597
|
-
wrapper.setAttribute('data-page', parseInt(currentPage));
|
|
598
|
-
wrapper.setAttribute('data-pages', Math.ceil(wrapper.getAttribute('data-total') / wrapper.getAttribute('data-show')));
|
|
599
|
-
makeTableFunctional(table, form, pagination, wrapper);
|
|
600
|
-
createPaginationButttons(wrapper, pagination);
|
|
601
|
-
if (response.data.length == 0) {
|
|
602
|
-
tbody.innerHTML = '<tr><td colspan="100%"><span class="h4 m-0">No results found</span></td></tr>';
|
|
603
|
-
}
|
|
604
|
-
wrapper.classList.remove('table--loading');
|
|
605
679
|
}
|
|
606
|
-
|
|
607
|
-
|
|
680
|
+
catch (error) {
|
|
681
|
+
console.log(error);
|
|
608
682
|
}
|
|
609
683
|
});
|
|
610
|
-
if (form.hasAttribute('data-ajax-post')) {
|
|
611
|
-
const http = new XMLHttpRequest();
|
|
612
|
-
http.open('GET', `${window.location.href}?ajax=true&${queryString}`);
|
|
613
|
-
http.send();
|
|
614
|
-
}
|
|
615
684
|
};
|
|
616
685
|
export const formatCell = (format, cellOutput) => {
|
|
617
686
|
switch (format) {
|