@iamproperty/components 3.7.1 → 3.7.2
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/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/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/table/table.component.min.js +16 -16
- 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 +127 -64
- 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/table.scss +57 -34
- package/assets/ts/modules/table.ts +134 -64
- package/dist/components.es.js +718 -687
- package/dist/components.umd.js +21 -21
- package/package.json +1 -1
|
@@ -58,13 +58,34 @@ thead {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// Error messages
|
|
62
|
+
tr td[colspan="100%"]:first-child:last-child span {
|
|
63
|
+
|
|
64
|
+
max-width: rem(624);
|
|
65
|
+
font-weight: bold;
|
|
66
|
+
padding: 3rem;
|
|
67
|
+
text-align: center;
|
|
68
|
+
display: block;
|
|
69
|
+
color: var(--colour-heading);
|
|
70
|
+
|
|
71
|
+
@include media-breakpoint-up(md) {
|
|
72
|
+
max-width: rem(1048);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
61
76
|
@container (width >= 60em) {
|
|
62
77
|
thead {
|
|
63
78
|
|
|
64
79
|
th {
|
|
65
80
|
white-space: nowrap;
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
min-width: #{$td-mw};
|
|
82
|
+
}
|
|
83
|
+
th.th--mw-md {
|
|
84
|
+
min-width: rem(240);
|
|
85
|
+
}
|
|
86
|
+
th.th--mw-lg {
|
|
87
|
+
min-width: rem(360);
|
|
88
|
+
}
|
|
68
89
|
}
|
|
69
90
|
}
|
|
70
91
|
|
|
@@ -85,24 +106,6 @@ tbody tr {
|
|
|
85
106
|
}
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
/*
|
|
89
|
-
:is(td, th) {
|
|
90
|
-
|
|
91
|
-
border-top: var(--border-width) solid currentColor;
|
|
92
|
-
@include var(border-color,--colour-border);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
&:first-child :is(td, th){
|
|
97
|
-
border-top: var(--border-width) solid currentColor;
|
|
98
|
-
@include var(border-color,--colour-primary);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
&:last-child :is(td, th){
|
|
102
|
-
border-bottom: var(--border-width) solid currentColor;
|
|
103
|
-
@include var(border-color,--colour-border);
|
|
104
|
-
}
|
|
105
|
-
*/
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
.border-0 > table,
|
|
@@ -312,7 +315,7 @@ table.border-0 {
|
|
|
312
315
|
display: none !important;;
|
|
313
316
|
}
|
|
314
317
|
}
|
|
315
|
-
.table--cta:not(.table--fullwidth) tr td:last-child {
|
|
318
|
+
.table--cta:not(.table--fullwidth) tr td:not(:first-child):last-child {
|
|
316
319
|
display: block!important;
|
|
317
320
|
position: static;
|
|
318
321
|
width: 100%;
|
|
@@ -338,22 +341,28 @@ table.border-0 {
|
|
|
338
341
|
--cta-width: 8rem;
|
|
339
342
|
}
|
|
340
343
|
|
|
344
|
+
:is(iam-table).table--loading {
|
|
345
|
+
|
|
346
|
+
--cta-width: 1.5rem!important;
|
|
347
|
+
}
|
|
348
|
+
|
|
341
349
|
:not(iam-table).table--cta {
|
|
342
350
|
|
|
343
351
|
position: relative;
|
|
344
352
|
margin-right: calc(var(--cta-width) - 1.5rem);
|
|
345
|
-
|
|
346
|
-
|
|
347
353
|
}
|
|
348
354
|
|
|
349
355
|
.table--cta .table__wrapper {
|
|
350
356
|
overflow-y: hidden;
|
|
351
357
|
margin-bottom: 0;
|
|
352
358
|
}
|
|
353
|
-
|
|
354
|
-
.table--cta {
|
|
359
|
+
|
|
360
|
+
.table--cta:not(.table--loading):has(tr:first-child td:first-child:last-child) {
|
|
361
|
+
padding-right: calc(var(--wrapper-padding) + 1.5rem);
|
|
362
|
+
}
|
|
363
|
+
.table--cta:not(.table--loading):not(:has(tr:first-child td:first-child:last-child)) {
|
|
355
364
|
|
|
356
|
-
tr > *:last-child {
|
|
365
|
+
tr > *:not(:first-child):last-child {
|
|
357
366
|
|
|
358
367
|
position: absolute;
|
|
359
368
|
left: 100%;
|
|
@@ -367,8 +376,6 @@ table.border-0 {
|
|
|
367
376
|
text-align: right;
|
|
368
377
|
background: linear-gradient(90deg, transparent 0%, var(--colour-canvas-2) 1.25rem);
|
|
369
378
|
|
|
370
|
-
//border-bottom: var(--border-width) solid var(--colour-border);
|
|
371
|
-
|
|
372
379
|
&:after {
|
|
373
380
|
bottom: 0;
|
|
374
381
|
left: 0;
|
|
@@ -384,15 +391,15 @@ table.border-0 {
|
|
|
384
391
|
}
|
|
385
392
|
}
|
|
386
393
|
|
|
387
|
-
tr > th:last-child {
|
|
394
|
+
tr > th:not(:first-child):last-child {
|
|
388
395
|
--colour-border: var(--colour-primary);
|
|
389
396
|
}
|
|
390
397
|
|
|
391
|
-
tbody tr:hover > *:last-child {
|
|
398
|
+
tbody tr:hover > *:not(:first-child):last-child {
|
|
392
399
|
background: linear-gradient(90deg, transparent 0%, var(--hover-background) 1.25rem);
|
|
393
400
|
}
|
|
394
401
|
|
|
395
|
-
thead tr > *:last-child {
|
|
402
|
+
thead tr > *:not(:first-child):last-child {
|
|
396
403
|
margin-top: 1px;
|
|
397
404
|
}
|
|
398
405
|
}
|
|
@@ -470,11 +477,27 @@ table:not(.table--filtered):not(.table--ajax) tbody tr:nth-child(15) ~ tr {
|
|
|
470
477
|
|
|
471
478
|
// Loading via ajax
|
|
472
479
|
.table--loading {
|
|
473
|
-
opacity: 0.8;
|
|
474
480
|
pointer-events: none;
|
|
481
|
+
position: relative;
|
|
475
482
|
|
|
476
|
-
|
|
477
|
-
|
|
483
|
+
table {
|
|
484
|
+
min-height: 20rem;
|
|
485
|
+
opacity: 0.5;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
&::after {
|
|
489
|
+
content: "Loading...";
|
|
490
|
+
position: absolute;
|
|
491
|
+
top: rem(100);
|
|
492
|
+
left: 50%;
|
|
493
|
+
transform: translate(-50%,0);
|
|
494
|
+
font-weight: bold;
|
|
495
|
+
color: var(--colour-heading);
|
|
496
|
+
font-size: 1.5rem;
|
|
497
|
+
text-shadow: 0px 0px 10px var(--colour-canvas-2);
|
|
498
|
+
padding-inline: 2rem;
|
|
499
|
+
text-shadow: 0px 0px 10px var(--colour-canvas-2);
|
|
500
|
+
background: radial-gradient(var(--colour-canvas-2), transparent);
|
|
478
501
|
}
|
|
479
502
|
}
|
|
480
503
|
|
|
@@ -284,8 +284,8 @@ export const addFilterEventListeners = (table, form, pagination, wrapper, savedT
|
|
|
284
284
|
if(!forms.includes(parentForm))
|
|
285
285
|
forms.push(parentForm);
|
|
286
286
|
|
|
287
|
-
if(!fields.includes(
|
|
288
|
-
fields.push(
|
|
287
|
+
if(!fields.includes(mimicField))
|
|
288
|
+
fields.push(mimicField);
|
|
289
289
|
|
|
290
290
|
});
|
|
291
291
|
});
|
|
@@ -297,7 +297,7 @@ export const addFilterEventListeners = (table, form, pagination, wrapper, savedT
|
|
|
297
297
|
const updateMimicInput = function(){
|
|
298
298
|
let mimickedAlready = [];
|
|
299
299
|
let formData = new FormData(parentForm);
|
|
300
|
-
|
|
300
|
+
|
|
301
301
|
let i = 1;
|
|
302
302
|
for (const [key, value] of formData) {
|
|
303
303
|
|
|
@@ -316,6 +316,19 @@ export const addFilterEventListeners = (table, form, pagination, wrapper, savedT
|
|
|
316
316
|
const event = new Event("force");
|
|
317
317
|
form.dispatchEvent(event);
|
|
318
318
|
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
// Check for empties
|
|
322
|
+
for (const field of fields) {
|
|
323
|
+
if(!formData.has(field) && parentForm.querySelector(`[name="${field}"]`)){
|
|
324
|
+
|
|
325
|
+
document.querySelector(`[data-mimic="${field}"]`).value = "";
|
|
326
|
+
|
|
327
|
+
const event = new Event("force");
|
|
328
|
+
form.dispatchEvent(event);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
319
332
|
}
|
|
320
333
|
|
|
321
334
|
parentForm.addEventListener('force', (event) => {
|
|
@@ -770,7 +783,9 @@ export const makeTableFunctional = function(table, form, pagination, wrapper){
|
|
|
770
783
|
}
|
|
771
784
|
}
|
|
772
785
|
|
|
773
|
-
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
export const loadAjaxTable = async function (table, form, pagination, wrapper){
|
|
774
789
|
|
|
775
790
|
const resolvePath = (object, path, defaultValue) => path.split(/[\.\[\]\'\"]/).filter(p => p).reduce((o, p) => o ? o[p] : defaultValue, object);
|
|
776
791
|
|
|
@@ -778,89 +793,144 @@ export const loadAjaxTable = function (table, form, pagination, wrapper){
|
|
|
778
793
|
let queryString = new URLSearchParams(formData).toString();
|
|
779
794
|
let columns = table.querySelectorAll('thead tr th');
|
|
780
795
|
let tbody = table.querySelector('tbody');
|
|
796
|
+
let ajaxURL = form.getAttribute('data-ajax');
|
|
781
797
|
|
|
782
798
|
wrapper.classList.add('table--loading');
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
799
|
+
|
|
800
|
+
// Setup controller vars if not already set
|
|
801
|
+
if(!window.controller)
|
|
802
|
+
window.controller = [];
|
|
803
|
+
|
|
804
|
+
// Abort if controller already present for this url
|
|
805
|
+
if(window.controller[ajaxURL])
|
|
806
|
+
window.controller[ajaxURL].abort();
|
|
807
|
+
|
|
808
|
+
// Create a new controller so it can be aborted if new fetch made
|
|
809
|
+
window.controller[ajaxURL] = new AbortController();
|
|
810
|
+
const { signal } = controller[ajaxURL];
|
|
811
|
+
|
|
812
|
+
try {
|
|
813
|
+
await fetch(ajaxURL+'?'+queryString, {
|
|
814
|
+
signal: signal,
|
|
815
|
+
method: 'get',
|
|
816
|
+
credentials: 'same-origin',
|
|
817
|
+
headers: new Headers({
|
|
818
|
+
'Content-Type': 'application/json',
|
|
819
|
+
Accept: 'application/json',
|
|
820
|
+
'X-Requested-With': 'XMLHttpRequest'
|
|
821
|
+
})
|
|
791
822
|
})
|
|
792
|
-
|
|
823
|
+
.then((response) => response.json()).then((response) => {
|
|
793
824
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
825
|
+
let schema = form.hasAttribute('data-schema') ? form.getAttribute('data-schema') : 'data';
|
|
826
|
+
let totalNumberSchema = form.hasAttribute('data-schema-total') ? form.getAttribute('data-schema-total') : 'meta.total';
|
|
827
|
+
let currentPageSchema = form.hasAttribute('data-schema-page') ? form.getAttribute('data-schema-page') : 'meta.current_page';
|
|
797
828
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
829
|
+
let totalNumber = resolvePath(response, totalNumberSchema, 1);
|
|
830
|
+
let currentPage = resolvePath(response, currentPageSchema, 1);
|
|
831
|
+
let data = resolvePath(response, schema);
|
|
832
|
+
let emptyMsg = wrapper.hasAttribute('data-empty-msg') ? wrapper.getAttribute('data-empty-msg') : "No results found";
|
|
833
|
+
|
|
834
|
+
if (data) {
|
|
803
835
|
|
|
804
|
-
|
|
836
|
+
tbody.innerHTML = '';
|
|
805
837
|
|
|
806
|
-
|
|
838
|
+
data.forEach((row, index) => {
|
|
807
839
|
|
|
808
|
-
|
|
840
|
+
var table_row = document.createElement('tr');
|
|
809
841
|
|
|
810
|
-
|
|
842
|
+
columns.forEach((col, index) => {
|
|
811
843
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
844
|
+
let cellOutput = '';
|
|
845
|
+
var table_cell = document.createElement('td');
|
|
846
|
+
// Add some data to help with the mobile layout design
|
|
847
|
+
table_cell.setAttribute('data-label',col.innerText);
|
|
816
848
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
849
|
+
if(col.getAttribute('data-output')){
|
|
850
|
+
var cellTemplate = col.getAttribute('data-output');
|
|
851
|
+
// Use a regex to replace {var} with actual values from the json data
|
|
852
|
+
cellOutput = cellTemplate.replace( new RegExp(/{(.*?)}/,"gm"), function(matched){ return resolvePath(row, matched.replace('{','').replace('}','')); });
|
|
853
|
+
}
|
|
822
854
|
|
|
823
|
-
|
|
855
|
+
// If an output array is defined then the content is going to made of of multiple values from an array
|
|
856
|
+
if(col.hasAttribute('data-output-array')){
|
|
857
|
+
|
|
858
|
+
var cellTemplate = col.getAttribute('data-output');
|
|
859
|
+
let arrValue = resolvePath(row, cellTemplate.replace('{','').replace('}',''));
|
|
824
860
|
|
|
825
|
-
|
|
826
|
-
|
|
861
|
+
cellOutput = "";
|
|
862
|
+
arrValue.forEach((rowValue, i) => {
|
|
827
863
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
864
|
+
let cellTemplateValue = col.getAttribute('data-output-array');
|
|
865
|
+
let cellOutputValue = "";
|
|
866
|
+
|
|
867
|
+
// If we need to transform some of the data
|
|
868
|
+
if(col.hasAttribute('data-output-array-property') && col.hasAttribute('data-output-array-transform')){
|
|
869
|
+
|
|
870
|
+
const propertyValue = resolvePath(rowValue, col.getAttribute('data-output-array-property'));
|
|
871
|
+
const transforms = JSON.parse(col.getAttribute('data-output-array-transform'));
|
|
872
|
+
const transformValue = transforms[propertyValue];
|
|
831
873
|
|
|
832
|
-
|
|
833
|
-
|
|
874
|
+
cellOutputValue = cellTemplateValue.replace(`{${col.getAttribute('data-output-array-property')}}`,transformValue);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
cellOutputValue = cellOutputValue.replace( new RegExp(/{(.*?)}/,"gm"), function(matched){ return resolvePath(rowValue, matched.replace('{','').replace('}','')); });
|
|
878
|
+
cellOutput += cellOutputValue;
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
if(col.hasAttribute('data-transform')){
|
|
884
|
+
|
|
885
|
+
const transforms = JSON.parse(col.getAttribute('data-transform'));
|
|
886
|
+
cellOutput = transforms[cellOutput];
|
|
887
|
+
|
|
888
|
+
if(!cellOutput && col.hasAttribute('data-default'))
|
|
889
|
+
cellOutput = col.getAttribute('data-default');
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
table_cell.innerHTML = cellOutput;
|
|
893
|
+
table_row.appendChild(table_cell)
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
tbody.appendChild(table_row)
|
|
834
897
|
});
|
|
835
898
|
|
|
836
|
-
|
|
837
|
-
|
|
899
|
+
createSearchDataList(table, form)
|
|
900
|
+
// Add data to the pagination
|
|
901
|
+
wrapper.setAttribute('data-total', parseInt(totalNumber));
|
|
902
|
+
wrapper.setAttribute('data-page', parseInt(currentPage));
|
|
903
|
+
wrapper.setAttribute('data-pages', Math.ceil(wrapper.getAttribute('data-total') / wrapper.getAttribute('data-show')));
|
|
838
904
|
|
|
839
|
-
|
|
840
|
-
|
|
905
|
+
makeTableFunctional(table, form, pagination, wrapper);
|
|
906
|
+
createPaginationButttons(wrapper, pagination);
|
|
841
907
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
908
|
+
if(parseInt(totalNumber) == 0){
|
|
909
|
+
tbody.innerHTML = `<tr><td colspan="100%"><span>${emptyMsg}</span></td></tr>`;
|
|
910
|
+
}
|
|
845
911
|
|
|
846
|
-
|
|
847
|
-
createPaginationButttons(wrapper, pagination);
|
|
912
|
+
wrapper.classList.remove('table--loading');
|
|
848
913
|
|
|
849
|
-
|
|
850
|
-
|
|
914
|
+
window.dataLayer = window.dataLayer || [];
|
|
915
|
+
window.dataLayer.push({
|
|
916
|
+
"event": "Ajax table loaded",
|
|
917
|
+
"url": ajaxURL,
|
|
918
|
+
"formData": queryString
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
tbody.innerHTML = '<tr><td colspan="100%"><span>Error loading table</span></td></tr>';
|
|
851
923
|
}
|
|
852
924
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
http.open('GET', `${window.location.href}?ajax=true&${queryString}`);
|
|
863
|
-
http.send()
|
|
925
|
+
// Pass post data back to the page
|
|
926
|
+
if(form.hasAttribute('data-ajax-post')){
|
|
927
|
+
const http = new XMLHttpRequest()
|
|
928
|
+
http.open('GET', `${window.location.href}?ajax=true&${queryString}`);
|
|
929
|
+
http.send();
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
} catch (error) {
|
|
933
|
+
console.log(error);
|
|
864
934
|
}
|
|
865
935
|
}
|
|
866
936
|
|