@ministryofjustice/frontend 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/moj/all.bundle.js +1549 -1062
  2. package/moj/all.bundle.js.map +1 -1
  3. package/moj/all.bundle.mjs +1845 -1054
  4. package/moj/all.bundle.mjs.map +1 -1
  5. package/moj/all.mjs +7 -90
  6. package/moj/all.mjs.map +1 -1
  7. package/moj/all.scss +1 -0
  8. package/moj/all.scss.map +1 -1
  9. package/moj/common/index.mjs +57 -0
  10. package/moj/common/index.mjs.map +1 -0
  11. package/moj/common/moj-frontend-version.mjs +14 -0
  12. package/moj/common/moj-frontend-version.mjs.map +1 -0
  13. package/moj/components/add-another/add-another.bundle.js +105 -76
  14. package/moj/components/add-another/add-another.bundle.js.map +1 -1
  15. package/moj/components/add-another/add-another.bundle.mjs +222 -71
  16. package/moj/components/add-another/add-another.bundle.mjs.map +1 -1
  17. package/moj/components/add-another/add-another.mjs +103 -72
  18. package/moj/components/add-another/add-another.mjs.map +1 -1
  19. package/moj/components/alert/alert.bundle.js +115 -191
  20. package/moj/components/alert/alert.bundle.js.map +1 -1
  21. package/moj/components/alert/alert.bundle.mjs +354 -186
  22. package/moj/components/alert/alert.bundle.mjs.map +1 -1
  23. package/moj/components/alert/alert.mjs +55 -140
  24. package/moj/components/alert/alert.mjs.map +1 -1
  25. package/moj/components/button-menu/README.md +3 -1
  26. package/moj/components/button-menu/button-menu.bundle.js +91 -120
  27. package/moj/components/button-menu/button-menu.bundle.js.map +1 -1
  28. package/moj/components/button-menu/button-menu.bundle.mjs +329 -114
  29. package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -1
  30. package/moj/components/button-menu/button-menu.mjs +89 -116
  31. package/moj/components/button-menu/button-menu.mjs.map +1 -1
  32. package/moj/components/date-picker/date-picker.bundle.js +174 -154
  33. package/moj/components/date-picker/date-picker.bundle.js.map +1 -1
  34. package/moj/components/date-picker/date-picker.bundle.mjs +411 -147
  35. package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -1
  36. package/moj/components/date-picker/date-picker.mjs +172 -150
  37. package/moj/components/date-picker/date-picker.mjs.map +1 -1
  38. package/moj/components/filter/template.njk +1 -1
  39. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +133 -44
  40. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -1
  41. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +374 -41
  42. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -1
  43. package/moj/components/filter-toggle-button/filter-toggle-button.mjs +131 -40
  44. package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
  45. package/moj/components/form-validator/form-validator.bundle.js +159 -69
  46. package/moj/components/form-validator/form-validator.bundle.js.map +1 -1
  47. package/moj/components/form-validator/form-validator.bundle.mjs +399 -65
  48. package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -1
  49. package/moj/components/form-validator/form-validator.mjs +134 -54
  50. package/moj/components/form-validator/form-validator.mjs.map +1 -1
  51. package/moj/components/multi-file-upload/multi-file-upload.bundle.js +291 -117
  52. package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -1
  53. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +527 -109
  54. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -1
  55. package/moj/components/multi-file-upload/multi-file-upload.mjs +288 -101
  56. package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
  57. package/moj/components/multi-file-upload/template.njk +1 -1
  58. package/moj/components/multi-select/multi-select.bundle.js +106 -41
  59. package/moj/components/multi-select/multi-select.bundle.js.map +1 -1
  60. package/moj/components/multi-select/multi-select.bundle.mjs +346 -37
  61. package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -1
  62. package/moj/components/multi-select/multi-select.mjs +104 -37
  63. package/moj/components/multi-select/multi-select.mjs.map +1 -1
  64. package/moj/components/password-reveal/_password-reveal.scss +3 -1
  65. package/moj/components/password-reveal/_password-reveal.scss.map +1 -1
  66. package/moj/components/password-reveal/password-reveal.bundle.js +32 -29
  67. package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -1
  68. package/moj/components/password-reveal/password-reveal.bundle.mjs +149 -24
  69. package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -1
  70. package/moj/components/password-reveal/password-reveal.mjs +30 -25
  71. package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
  72. package/moj/components/rich-text-editor/README.md +4 -3
  73. package/moj/components/rich-text-editor/rich-text-editor.bundle.js +127 -62
  74. package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -1
  75. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +367 -58
  76. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -1
  77. package/moj/components/rich-text-editor/rich-text-editor.mjs +125 -58
  78. package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
  79. package/moj/components/search-toggle/search-toggle.bundle.js +94 -26
  80. package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -1
  81. package/moj/components/search-toggle/search-toggle.bundle.mjs +334 -22
  82. package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -1
  83. package/moj/components/search-toggle/search-toggle.mjs +92 -22
  84. package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
  85. package/moj/components/sortable-table/sortable-table.bundle.js +151 -83
  86. package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -1
  87. package/moj/components/sortable-table/sortable-table.bundle.mjs +390 -78
  88. package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -1
  89. package/moj/components/sortable-table/sortable-table.mjs +149 -79
  90. package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
  91. package/moj/core/_all.scss +3 -0
  92. package/moj/core/_all.scss.map +1 -0
  93. package/moj/core/_moj-frontend-properties.scss +7 -0
  94. package/moj/core/_moj-frontend-properties.scss.map +1 -0
  95. package/moj/filters/prototype-kit-13-filters.js +4 -3
  96. package/moj/helpers.bundle.js +22 -77
  97. package/moj/helpers.bundle.js.map +1 -1
  98. package/moj/helpers.bundle.mjs +23 -74
  99. package/moj/helpers.bundle.mjs.map +1 -1
  100. package/moj/helpers.mjs +23 -74
  101. package/moj/helpers.mjs.map +1 -1
  102. package/moj/moj-frontend.min.css +1 -1
  103. package/moj/moj-frontend.min.css.map +1 -1
  104. package/moj/moj-frontend.min.js +1 -1
  105. package/moj/moj-frontend.min.js.map +1 -1
  106. package/package.json +1 -1
  107. package/moj/version.bundle.js +0 -12
  108. package/moj/version.bundle.js.map +0 -1
  109. package/moj/version.bundle.mjs +0 -4
  110. package/moj/version.bundle.mjs.map +0 -1
  111. package/moj/version.mjs +0 -4
  112. package/moj/version.mjs.map +0 -1
@@ -1,126 +1,196 @@
1
- class SortableTable {
2
- constructor(params) {
3
- const table = params.table;
4
- const head = table == null ? void 0 : table.querySelector('thead');
5
- const body = table == null ? void 0 : table.querySelector('tbody');
6
- if (!table || !(table instanceof HTMLElement) || !head || !body) {
7
- return this;
8
- }
9
- this.table = table;
10
- this.head = head;
11
- this.body = body;
12
- if (this.table.hasAttribute('data-moj-sortable-table-init')) {
1
+ import { ConfigurableComponent } from 'govuk-frontend';
2
+
3
+ /**
4
+ * @augments {ConfigurableComponent<SortableTableConfig>}
5
+ */
6
+ class SortableTable extends ConfigurableComponent {
7
+ /**
8
+ * @param {Element | null} $root - HTML element to use for sortable table
9
+ * @param {SortableTableConfig} [config] - Sortable table config
10
+ */
11
+ constructor($root, config = {}) {
12
+ super($root, config);
13
+ const $head = $root == null ? void 0 : $root.querySelector('thead');
14
+ const $body = $root == null ? void 0 : $root.querySelector('tbody');
15
+ if (!$head || !$body) {
13
16
  return this;
14
17
  }
15
- this.table.setAttribute('data-moj-sortable-table-init', '');
16
- this.headings = this.head ? Array.from(this.head.querySelectorAll('th')) : [];
17
- this.setupOptions(params);
18
+ this.$head = $head;
19
+ this.$body = $body;
20
+ this.$headings = this.$head ? Array.from(this.$head.querySelectorAll('th')) : [];
18
21
  this.createHeadingButtons();
19
22
  this.createStatusBox();
20
23
  this.initialiseSortedColumn();
21
- this.head.addEventListener('click', this.onSortButtonClick.bind(this));
22
- }
23
- setupOptions(params) {
24
- params = params || {};
25
- this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)';
26
- this.ascendingText = params.ascendingText || 'ascending';
27
- this.descendingText = params.descendingText || 'descending';
24
+ this.$head.addEventListener('click', this.onSortButtonClick.bind(this));
28
25
  }
29
26
  createHeadingButtons() {
30
- for (const heading of this.headings) {
31
- if (heading.hasAttribute('aria-sort')) {
32
- this.createHeadingButton(heading);
27
+ for (const $heading of this.$headings) {
28
+ if ($heading.hasAttribute('aria-sort')) {
29
+ this.createHeadingButton($heading);
33
30
  }
34
31
  }
35
32
  }
36
- createHeadingButton(heading) {
37
- const index = this.headings.indexOf(heading);
38
- const button = document.createElement('button');
39
- button.setAttribute('type', 'button');
40
- button.setAttribute('data-index', `${index}`);
41
- button.textContent = heading.textContent;
42
- heading.textContent = '';
43
- heading.appendChild(button);
33
+
34
+ /**
35
+ * @param {HTMLTableCellElement} $heading
36
+ */
37
+ createHeadingButton($heading) {
38
+ const index = this.$headings.indexOf($heading);
39
+ const $button = document.createElement('button');
40
+ $button.setAttribute('type', 'button');
41
+ $button.setAttribute('data-index', `${index}`);
42
+ $button.textContent = $heading.textContent;
43
+ $heading.textContent = '';
44
+ $heading.appendChild($button);
44
45
  }
45
46
  createStatusBox() {
46
- this.status = document.createElement('div');
47
- this.status.setAttribute('aria-atomic', 'true');
48
- this.status.setAttribute('aria-live', 'polite');
49
- this.status.setAttribute('class', 'govuk-visually-hidden');
50
- this.status.setAttribute('role', 'status');
51
- this.table.insertAdjacentElement('afterend', this.status);
47
+ this.$status = document.createElement('div');
48
+ this.$status.setAttribute('aria-atomic', 'true');
49
+ this.$status.setAttribute('aria-live', 'polite');
50
+ this.$status.setAttribute('class', 'govuk-visually-hidden');
51
+ this.$status.setAttribute('role', 'status');
52
+ this.$root.insertAdjacentElement('afterend', this.$status);
52
53
  }
53
54
  initialiseSortedColumn() {
54
- var _sortButton$getAttrib;
55
- const rows = this.getTableRowsArray();
56
- const heading = this.table.querySelector('th[aria-sort]');
57
- const sortButton = heading == null ? void 0 : heading.querySelector('button');
58
- const sortDirection = heading == null ? void 0 : heading.getAttribute('aria-sort');
59
- const columnNumber = Number.parseInt((_sortButton$getAttrib = sortButton == null ? void 0 : sortButton.getAttribute('data-index')) != null ? _sortButton$getAttrib : '0', 10);
60
- if (!heading || !sortButton || !(sortDirection === 'ascending' || sortDirection === 'descending')) {
55
+ var _$sortButton$getAttri;
56
+ const $rows = this.getTableRowsArray();
57
+ const $heading = this.$root.querySelector('th[aria-sort]');
58
+ const $sortButton = $heading == null ? void 0 : $heading.querySelector('button');
59
+ const sortDirection = $heading == null ? void 0 : $heading.getAttribute('aria-sort');
60
+ const columnNumber = Number.parseInt((_$sortButton$getAttri = $sortButton == null ? void 0 : $sortButton.getAttribute('data-index')) != null ? _$sortButton$getAttri : '0', 10);
61
+ if (!$heading || !$sortButton || !(sortDirection === 'ascending' || sortDirection === 'descending')) {
61
62
  return;
62
63
  }
63
- const sortedRows = this.sort(rows, columnNumber, sortDirection);
64
- this.addRows(sortedRows);
64
+ const $sortedRows = this.sort($rows, columnNumber, sortDirection);
65
+ this.addRows($sortedRows);
65
66
  }
67
+
68
+ /**
69
+ * @param {MouseEvent} event - Click event
70
+ */
66
71
  onSortButtonClick(event) {
67
- var _button$getAttribute;
68
- const button = event.target;
69
- if (!button || !(button instanceof HTMLButtonElement) || !button.parentElement) {
72
+ var _$button$getAttribute;
73
+ const $button = event.target;
74
+ if (!$button || !($button instanceof HTMLButtonElement) || !$button.parentElement) {
70
75
  return;
71
76
  }
72
- const heading = button.parentElement;
73
- const sortDirection = heading.getAttribute('aria-sort');
74
- const columnNumber = Number.parseInt((_button$getAttribute = button == null ? void 0 : button.getAttribute('data-index')) != null ? _button$getAttribute : '0', 10);
77
+ const $heading = $button.parentElement;
78
+ const sortDirection = $heading.getAttribute('aria-sort');
79
+ const columnNumber = Number.parseInt((_$button$getAttribute = $button == null ? void 0 : $button.getAttribute('data-index')) != null ? _$button$getAttribute : '0', 10);
75
80
  const newSortDirection = sortDirection === 'none' || sortDirection === 'descending' ? 'ascending' : 'descending';
76
- const rows = this.getTableRowsArray();
77
- const sortedRows = this.sort(rows, columnNumber, newSortDirection);
78
- this.addRows(sortedRows);
81
+ const $rows = this.getTableRowsArray();
82
+ const $sortedRows = this.sort($rows, columnNumber, newSortDirection);
83
+ this.addRows($sortedRows);
79
84
  this.removeButtonStates();
80
- this.updateButtonState(button, newSortDirection);
85
+ this.updateButtonState($button, newSortDirection);
81
86
  }
82
- updateButtonState(button, direction) {
87
+
88
+ /**
89
+ * @param {HTMLButtonElement} $button
90
+ * @param {string} direction
91
+ */
92
+ updateButtonState($button, direction) {
83
93
  if (!(direction === 'ascending' || direction === 'descending')) {
84
94
  return;
85
95
  }
86
- button.parentElement.setAttribute('aria-sort', direction);
87
- let message = this.statusMessage;
88
- message = message.replace(/%heading%/, button.textContent);
89
- message = message.replace(/%direction%/, this[`${direction}Text`]);
90
- this.status.textContent = message;
96
+ $button.parentElement.setAttribute('aria-sort', direction);
97
+ let message = this.config.statusMessage;
98
+ message = message.replace(/%heading%/, $button.textContent);
99
+ message = message.replace(/%direction%/, this.config[`${direction}Text`]);
100
+ this.$status.textContent = message;
91
101
  }
92
102
  removeButtonStates() {
93
- for (const heading of this.headings) {
94
- heading.setAttribute('aria-sort', 'none');
103
+ for (const $heading of this.$headings) {
104
+ $heading.setAttribute('aria-sort', 'none');
95
105
  }
96
106
  }
97
- addRows(rows) {
98
- for (const row of rows) {
99
- this.body.append(row);
107
+
108
+ /**
109
+ * @param {HTMLTableRowElement[]} $rows
110
+ */
111
+ addRows($rows) {
112
+ for (const $row of $rows) {
113
+ this.$body.append($row);
100
114
  }
101
115
  }
102
116
  getTableRowsArray() {
103
- return Array.from(this.body.querySelectorAll('tr'));
117
+ return Array.from(this.$body.querySelectorAll('tr'));
104
118
  }
105
- sort(rows, columnNumber, sortDirection) {
106
- return rows.sort((rowA, rowB) => {
107
- const tdA = rowA.querySelectorAll('td, th')[columnNumber];
108
- const tdB = rowB.querySelectorAll('td, th')[columnNumber];
109
- if (!tdA || !tdB || !(tdA instanceof HTMLElement) || !(tdB instanceof HTMLElement)) {
119
+
120
+ /**
121
+ * @param {HTMLTableRowElement[]} $rows
122
+ * @param {number} columnNumber
123
+ * @param {string} sortDirection
124
+ */
125
+ sort($rows, columnNumber, sortDirection) {
126
+ return $rows.sort(($rowA, $rowB) => {
127
+ const $tdA = $rowA.querySelectorAll('td, th')[columnNumber];
128
+ const $tdB = $rowB.querySelectorAll('td, th')[columnNumber];
129
+ if (!$tdA || !$tdB || !($tdA instanceof HTMLElement) || !($tdB instanceof HTMLElement)) {
110
130
  return 0;
111
131
  }
112
- const valueA = sortDirection === 'ascending' ? this.getCellValue(tdA) : this.getCellValue(tdB);
113
- const valueB = sortDirection === 'ascending' ? this.getCellValue(tdB) : this.getCellValue(tdA);
132
+ const valueA = sortDirection === 'ascending' ? this.getCellValue($tdA) : this.getCellValue($tdB);
133
+ const valueB = sortDirection === 'ascending' ? this.getCellValue($tdB) : this.getCellValue($tdA);
114
134
  return !(typeof valueA === 'number' && typeof valueB === 'number') ? valueA.toString().localeCompare(valueB.toString()) : valueA - valueB;
115
135
  });
116
136
  }
117
- getCellValue(cell) {
118
- const val = cell.getAttribute('data-sort-value') || cell.innerHTML;
137
+
138
+ /**
139
+ * @param {HTMLElement} $cell
140
+ */
141
+ getCellValue($cell) {
142
+ const val = $cell.getAttribute('data-sort-value') || $cell.innerHTML;
119
143
  const valAsNumber = Number(val);
120
144
  return Number.isFinite(valAsNumber) ? valAsNumber // Exclude invalid numbers, infinity etc
121
145
  : val;
122
146
  }
147
+
148
+ /**
149
+ * Name for the component used when initialising using data-module attributes.
150
+ */
123
151
  }
124
152
 
153
+ /**
154
+ * Sortable table config
155
+ *
156
+ * @typedef {object} SortableTableConfig
157
+ * @property {string} [statusMessage] - Status message
158
+ * @property {string} [ascendingText] - Ascending text
159
+ * @property {string} [descendingText] - Descending text
160
+ */
161
+
162
+ /**
163
+ * @import { Schema } from 'govuk-frontend/dist/govuk/common/configuration.mjs'
164
+ */
165
+ SortableTable.moduleName = 'moj-sortable-table';
166
+ /**
167
+ * Sortable table config
168
+ *
169
+ * @type {SortableTableConfig}
170
+ */
171
+ SortableTable.defaults = Object.freeze({
172
+ statusMessage: 'Sort by %heading% (%direction%)',
173
+ ascendingText: 'ascending',
174
+ descendingText: 'descending'
175
+ });
176
+ /**
177
+ * Sortable table config schema
178
+ *
179
+ * @satisfies {Schema<SortableTableConfig>}
180
+ */
181
+ SortableTable.schema = Object.freeze(/** @type {const} */{
182
+ properties: {
183
+ statusMessage: {
184
+ type: 'string'
185
+ },
186
+ ascendingText: {
187
+ type: 'string'
188
+ },
189
+ descendingText: {
190
+ type: 'string'
191
+ }
192
+ }
193
+ });
194
+
125
195
  export { SortableTable };
126
196
  //# sourceMappingURL=sortable-table.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sortable-table.mjs","sources":["../../../../src/moj/components/sortable-table/sortable-table.mjs"],"sourcesContent":["export class SortableTable {\n constructor(params) {\n const table = params.table\n const head = table?.querySelector('thead')\n const body = table?.querySelector('tbody')\n\n if (!table || !(table instanceof HTMLElement) || !head || !body) {\n return this\n }\n\n this.table = table\n this.head = head\n this.body = body\n\n if (this.table.hasAttribute('data-moj-sortable-table-init')) {\n return this\n }\n\n this.table.setAttribute('data-moj-sortable-table-init', '')\n\n this.headings = this.head\n ? Array.from(this.head.querySelectorAll('th'))\n : []\n\n this.setupOptions(params)\n this.createHeadingButtons()\n this.createStatusBox()\n this.initialiseSortedColumn()\n\n this.head.addEventListener('click', this.onSortButtonClick.bind(this))\n }\n\n setupOptions(params) {\n params = params || {}\n this.statusMessage =\n params.statusMessage || 'Sort by %heading% (%direction%)'\n this.ascendingText = params.ascendingText || 'ascending'\n this.descendingText = params.descendingText || 'descending'\n }\n\n createHeadingButtons() {\n for (const heading of this.headings) {\n if (heading.hasAttribute('aria-sort')) {\n this.createHeadingButton(heading)\n }\n }\n }\n\n createHeadingButton(heading) {\n const index = this.headings.indexOf(heading)\n const button = document.createElement('button')\n\n button.setAttribute('type', 'button')\n button.setAttribute('data-index', `${index}`)\n button.textContent = heading.textContent\n\n heading.textContent = ''\n heading.appendChild(button)\n }\n\n createStatusBox() {\n this.status = document.createElement('div')\n\n this.status.setAttribute('aria-atomic', 'true')\n this.status.setAttribute('aria-live', 'polite')\n this.status.setAttribute('class', 'govuk-visually-hidden')\n this.status.setAttribute('role', 'status')\n\n this.table.insertAdjacentElement('afterend', this.status)\n }\n\n initialiseSortedColumn() {\n const rows = this.getTableRowsArray()\n\n const heading = this.table.querySelector('th[aria-sort]')\n const sortButton = heading?.querySelector('button')\n const sortDirection = heading?.getAttribute('aria-sort')\n const columnNumber = Number.parseInt(\n sortButton?.getAttribute('data-index') ?? '0',\n 10\n )\n\n if (\n !heading ||\n !sortButton ||\n !(sortDirection === 'ascending' || sortDirection === 'descending')\n ) {\n return\n }\n\n const sortedRows = this.sort(rows, columnNumber, sortDirection)\n this.addRows(sortedRows)\n }\n\n onSortButtonClick(event) {\n const button = event.target\n\n if (\n !button ||\n !(button instanceof HTMLButtonElement) ||\n !button.parentElement\n ) {\n return\n }\n\n const heading = button.parentElement\n const sortDirection = heading.getAttribute('aria-sort')\n const columnNumber = Number.parseInt(\n button?.getAttribute('data-index') ?? '0',\n 10\n )\n\n const newSortDirection =\n sortDirection === 'none' || sortDirection === 'descending'\n ? 'ascending'\n : 'descending'\n\n const rows = this.getTableRowsArray()\n const sortedRows = this.sort(rows, columnNumber, newSortDirection)\n\n this.addRows(sortedRows)\n this.removeButtonStates()\n this.updateButtonState(button, newSortDirection)\n }\n\n updateButtonState(button, direction) {\n if (!(direction === 'ascending' || direction === 'descending')) {\n return\n }\n\n button.parentElement.setAttribute('aria-sort', direction)\n let message = this.statusMessage\n message = message.replace(/%heading%/, button.textContent)\n message = message.replace(/%direction%/, this[`${direction}Text`])\n this.status.textContent = message\n }\n\n removeButtonStates() {\n for (const heading of this.headings) {\n heading.setAttribute('aria-sort', 'none')\n }\n }\n\n addRows(rows) {\n for (const row of rows) {\n this.body.append(row)\n }\n }\n\n getTableRowsArray() {\n return Array.from(this.body.querySelectorAll('tr'))\n }\n\n sort(rows, columnNumber, sortDirection) {\n return rows.sort((rowA, rowB) => {\n const tdA = rowA.querySelectorAll('td, th')[columnNumber]\n const tdB = rowB.querySelectorAll('td, th')[columnNumber]\n\n if (\n !tdA ||\n !tdB ||\n !(tdA instanceof HTMLElement) ||\n !(tdB instanceof HTMLElement)\n ) {\n return 0\n }\n\n const valueA =\n sortDirection === 'ascending'\n ? this.getCellValue(tdA)\n : this.getCellValue(tdB)\n\n const valueB =\n sortDirection === 'ascending'\n ? this.getCellValue(tdB)\n : this.getCellValue(tdA)\n\n return !(typeof valueA === 'number' && typeof valueB === 'number')\n ? valueA.toString().localeCompare(valueB.toString())\n : valueA - valueB\n })\n }\n\n getCellValue(cell) {\n const val = cell.getAttribute('data-sort-value') || cell.innerHTML\n const valAsNumber = Number(val)\n\n return Number.isFinite(valAsNumber)\n ? valAsNumber // Exclude invalid numbers, infinity etc\n : val\n }\n}\n"],"names":["SortableTable","constructor","params","table","head","querySelector","body","HTMLElement","hasAttribute","setAttribute","headings","Array","from","querySelectorAll","setupOptions","createHeadingButtons","createStatusBox","initialiseSortedColumn","addEventListener","onSortButtonClick","bind","statusMessage","ascendingText","descendingText","heading","createHeadingButton","index","indexOf","button","document","createElement","textContent","appendChild","status","insertAdjacentElement","_sortButton$getAttrib","rows","getTableRowsArray","sortButton","sortDirection","getAttribute","columnNumber","Number","parseInt","sortedRows","sort","addRows","event","_button$getAttribute","target","HTMLButtonElement","parentElement","newSortDirection","removeButtonStates","updateButtonState","direction","message","replace","row","append","rowA","rowB","tdA","tdB","valueA","getCellValue","valueB","toString","localeCompare","cell","val","innerHTML","valAsNumber","isFinite"],"mappings":"AAAO,MAAMA,aAAa,CAAC;EACzBC,WAAWA,CAACC,MAAM,EAAE;AAClB,IAAA,MAAMC,KAAK,GAAGD,MAAM,CAACC,KAAK;IAC1B,MAAMC,IAAI,GAAGD,KAAK,IAAA,IAAA,GAAA,MAAA,GAALA,KAAK,CAAEE,aAAa,CAAC,OAAO,CAAC;IAC1C,MAAMC,IAAI,GAAGH,KAAK,IAAA,IAAA,GAAA,MAAA,GAALA,KAAK,CAAEE,aAAa,CAAC,OAAO,CAAC;AAE1C,IAAA,IAAI,CAACF,KAAK,IAAI,EAAEA,KAAK,YAAYI,WAAW,CAAC,IAAI,CAACH,IAAI,IAAI,CAACE,IAAI,EAAE;AAC/D,MAAA,OAAO,IAAI;AACb;IAEA,IAAI,CAACH,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACE,IAAI,GAAGA,IAAI;IAEhB,IAAI,IAAI,CAACH,KAAK,CAACK,YAAY,CAAC,8BAA8B,CAAC,EAAE;AAC3D,MAAA,OAAO,IAAI;AACb;IAEA,IAAI,CAACL,KAAK,CAACM,YAAY,CAAC,8BAA8B,EAAE,EAAE,CAAC;IAE3D,IAAI,CAACC,QAAQ,GAAG,IAAI,CAACN,IAAI,GACrBO,KAAK,CAACC,IAAI,CAAC,IAAI,CAACR,IAAI,CAACS,gBAAgB,CAAC,IAAI,CAAC,CAAC,GAC5C,EAAE;AAEN,IAAA,IAAI,CAACC,YAAY,CAACZ,MAAM,CAAC;IACzB,IAAI,CAACa,oBAAoB,EAAE;IAC3B,IAAI,CAACC,eAAe,EAAE;IACtB,IAAI,CAACC,sBAAsB,EAAE;AAE7B,IAAA,IAAI,CAACb,IAAI,CAACc,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAACC,iBAAiB,CAACC,IAAI,CAAC,IAAI,CAAC,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B,YAAY,CAACH,GAAG,CAAC,GACtB,IAAI,CAACG,YAAY,CAACF,GAAG,CAAC;AAE5B,MAAA,MAAMG,MAAM,GACV3B,aAAa,KAAK,WAAW,GACzB,IAAI,CAAC0B,YAAY,CAACF,GAAG,CAAC,GACtB,IAAI,CAACE,YAAY,CAACH,GAAG,CAAC;AAE5B,MAAA,OAAO,EAAE,OAAOE,MAAM,KAAK,QAAQ,IAAI,OAAOE,MAAM,KAAK,QAAQ,CAAC,GAC9DF,MAAM,CAACG,QAAQ,EAAE,CAACC,aAAa,CAACF,MAAM,CAACC,QAAQ,EAAE,CAAC,GAClDH,MAAM,GAAGE,MAAM;AACrB,KAAC,CAAC;AACJ;EAEAD,YAAYA,CAACI,IAAI,EAAE;IACjB,MAAMC,GAAG,GAAGD,IAAI,CAAC7B,YAAY,CAAC,iBAAiB,CAAC,IAAI6B,IAAI,CAACE,SAAS;AAClE,IAAA,MAAMC,WAAW,GAAG9B,MAAM,CAAC4B,GAAG,CAAC;IAE/B,OAAO5B,MAAM,CAAC+B,QAAQ,CAACD,WAAW,CAAC,GAC/BA,WAAW;AAAC,MACZF,GAAG;AACT;AACF;;;;"}
1
+ {"version":3,"file":"sortable-table.mjs","sources":["../../../../src/moj/components/sortable-table/sortable-table.mjs"],"sourcesContent":["import { ConfigurableComponent } from 'govuk-frontend'\n\n/**\n * @augments {ConfigurableComponent<SortableTableConfig>}\n */\nexport class SortableTable extends ConfigurableComponent {\n /**\n * @param {Element | null} $root - HTML element to use for sortable table\n * @param {SortableTableConfig} [config] - Sortable table config\n */\n constructor($root, config = {}) {\n super($root, config)\n\n const $head = $root?.querySelector('thead')\n const $body = $root?.querySelector('tbody')\n\n if (!$head || !$body) {\n return this\n }\n\n this.$head = $head\n this.$body = $body\n\n this.$headings = this.$head\n ? Array.from(this.$head.querySelectorAll('th'))\n : []\n\n this.createHeadingButtons()\n this.createStatusBox()\n this.initialiseSortedColumn()\n\n this.$head.addEventListener('click', this.onSortButtonClick.bind(this))\n }\n\n createHeadingButtons() {\n for (const $heading of this.$headings) {\n if ($heading.hasAttribute('aria-sort')) {\n this.createHeadingButton($heading)\n }\n }\n }\n\n /**\n * @param {HTMLTableCellElement} $heading\n */\n createHeadingButton($heading) {\n const index = this.$headings.indexOf($heading)\n const $button = document.createElement('button')\n\n $button.setAttribute('type', 'button')\n $button.setAttribute('data-index', `${index}`)\n $button.textContent = $heading.textContent\n\n $heading.textContent = ''\n $heading.appendChild($button)\n }\n\n createStatusBox() {\n this.$status = document.createElement('div')\n\n this.$status.setAttribute('aria-atomic', 'true')\n this.$status.setAttribute('aria-live', 'polite')\n this.$status.setAttribute('class', 'govuk-visually-hidden')\n this.$status.setAttribute('role', 'status')\n\n this.$root.insertAdjacentElement('afterend', this.$status)\n }\n\n initialiseSortedColumn() {\n const $rows = this.getTableRowsArray()\n\n const $heading = this.$root.querySelector('th[aria-sort]')\n const $sortButton = $heading?.querySelector('button')\n const sortDirection = $heading?.getAttribute('aria-sort')\n\n const columnNumber = Number.parseInt(\n $sortButton?.getAttribute('data-index') ?? '0',\n 10\n )\n\n if (\n !$heading ||\n !$sortButton ||\n !(sortDirection === 'ascending' || sortDirection === 'descending')\n ) {\n return\n }\n\n const $sortedRows = this.sort($rows, columnNumber, sortDirection)\n this.addRows($sortedRows)\n }\n\n /**\n * @param {MouseEvent} event - Click event\n */\n onSortButtonClick(event) {\n const $button = event.target\n\n if (\n !$button ||\n !($button instanceof HTMLButtonElement) ||\n !$button.parentElement\n ) {\n return\n }\n\n const $heading = $button.parentElement\n const sortDirection = $heading.getAttribute('aria-sort')\n\n const columnNumber = Number.parseInt(\n $button?.getAttribute('data-index') ?? '0',\n 10\n )\n\n const newSortDirection =\n sortDirection === 'none' || sortDirection === 'descending'\n ? 'ascending'\n : 'descending'\n\n const $rows = this.getTableRowsArray()\n const $sortedRows = this.sort($rows, columnNumber, newSortDirection)\n\n this.addRows($sortedRows)\n this.removeButtonStates()\n this.updateButtonState($button, newSortDirection)\n }\n\n /**\n * @param {HTMLButtonElement} $button\n * @param {string} direction\n */\n updateButtonState($button, direction) {\n if (!(direction === 'ascending' || direction === 'descending')) {\n return\n }\n\n $button.parentElement.setAttribute('aria-sort', direction)\n let message = this.config.statusMessage\n message = message.replace(/%heading%/, $button.textContent)\n message = message.replace(/%direction%/, this.config[`${direction}Text`])\n this.$status.textContent = message\n }\n\n removeButtonStates() {\n for (const $heading of this.$headings) {\n $heading.setAttribute('aria-sort', 'none')\n }\n }\n\n /**\n * @param {HTMLTableRowElement[]} $rows\n */\n addRows($rows) {\n for (const $row of $rows) {\n this.$body.append($row)\n }\n }\n\n getTableRowsArray() {\n return Array.from(this.$body.querySelectorAll('tr'))\n }\n\n /**\n * @param {HTMLTableRowElement[]} $rows\n * @param {number} columnNumber\n * @param {string} sortDirection\n */\n sort($rows, columnNumber, sortDirection) {\n return $rows.sort(($rowA, $rowB) => {\n const $tdA = $rowA.querySelectorAll('td, th')[columnNumber]\n const $tdB = $rowB.querySelectorAll('td, th')[columnNumber]\n\n if (\n !$tdA ||\n !$tdB ||\n !($tdA instanceof HTMLElement) ||\n !($tdB instanceof HTMLElement)\n ) {\n return 0\n }\n\n const valueA =\n sortDirection === 'ascending'\n ? this.getCellValue($tdA)\n : this.getCellValue($tdB)\n\n const valueB =\n sortDirection === 'ascending'\n ? this.getCellValue($tdB)\n : this.getCellValue($tdA)\n\n return !(typeof valueA === 'number' && typeof valueB === 'number')\n ? valueA.toString().localeCompare(valueB.toString())\n : valueA - valueB\n })\n }\n\n /**\n * @param {HTMLElement} $cell\n */\n getCellValue($cell) {\n const val = $cell.getAttribute('data-sort-value') || $cell.innerHTML\n const valAsNumber = Number(val)\n\n return Number.isFinite(valAsNumber)\n ? valAsNumber // Exclude invalid numbers, infinity etc\n : val\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'moj-sortable-table'\n\n /**\n * Sortable table config\n *\n * @type {SortableTableConfig}\n */\n static defaults = Object.freeze({\n statusMessage: 'Sort by %heading% (%direction%)',\n ascendingText: 'ascending',\n descendingText: 'descending'\n })\n\n /**\n * Sortable table config schema\n *\n * @satisfies {Schema<SortableTableConfig>}\n */\n static schema = Object.freeze(\n /** @type {const} */ ({\n properties: {\n statusMessage: { type: 'string' },\n ascendingText: { type: 'string' },\n descendingText: { type: 'string' }\n }\n })\n )\n}\n\n/**\n * Sortable table config\n *\n * @typedef {object} SortableTableConfig\n * @property {string} [statusMessage] - Status message\n * @property {string} [ascendingText] - Ascending text\n * @property {string} [descendingText] - Descending text\n */\n\n/**\n * @import { Schema } from 'govuk-frontend/dist/govuk/common/configuration.mjs'\n */\n"],"names":["SortableTable","ConfigurableComponent","constructor","$root","config","$head","querySelector","$body","$headings","Array","from","querySelectorAll","createHeadingButtons","createStatusBox","initialiseSortedColumn","addEventListener","onSortButtonClick","bind","$heading","hasAttribute","createHeadingButton","index","indexOf","$button","document","createElement","setAttribute","textContent","appendChild","$status","insertAdjacentElement","_$sortButton$getAttri","$rows","getTableRowsArray","$sortButton","sortDirection","getAttribute","columnNumber","Number","parseInt","$sortedRows","sort","addRows","event","_$button$getAttribute","target","HTMLButtonElement","parentElement","newSortDirection","removeButtonStates","updateButtonState","direction","message","statusMessage","replace","$row","append","$rowA","$rowB","$tdA","$tdB","HTMLElement","valueA","getCellValue","valueB","toString","localeCompare","$cell","val","innerHTML","valAsNumber","isFinite","moduleName","defaults","Object","freeze","ascendingText","descendingText","schema","properties","type"],"mappings":";;AAEA;AACA;AACA;AACO,MAAMA,aAAa,SAASC,qBAAqB,CAAC;AACvD;AACF;AACA;AACA;AACEC,EAAAA,WAAWA,CAACC,KAAK,EAAEC,MAAM,GAAG,EAAE,EAAE;AAC9B,IAAA,KAAK,CAACD,KAAK,EAAEC,MAAM,CAAC;IAEpB,MAAMC,KAAK,GAAGF,KAAK,IAAA,IAAA,GAAA,MAAA,GAALA,KAAK,CAAEG,aAAa,CAAC,OAAO,CAAC;IAC3C,MAAMC,KAAK,GAAGJ,KAAK,IAAA,I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U,GAAG,oBAAoB;AAExC;AACF;AACA;AACA;AACA;AArNaxE,aAAa,CAsNjByE,QAAQ,GAAGC,MAAM,CAACC,MAAM,CAAC;AAC9BtB,EAAAA,aAAa,EAAE,iCAAiC;AAChDuB,EAAAA,aAAa,EAAE,WAAW;AAC1BC,EAAAA,cAAc,EAAE;AAClB,CAAC,CAAC;AAEF;AACF;AACA;AACA;AACA;AAhOa7E,aAAa,CAiOjB8E,MAAM,GAAGJ,MAAM,CAACC,MAAM,qBACL;AACpBI,EAAAA,UAAU,EAAE;AACV1B,IAAAA,aAAa,EAAE;AAAE2B,MAAAA,IAAI,EAAE;KAAU;AACjCJ,IAAAA,aAAa,EAAE;AAAEI,MAAAA,IAAI,EAAE;KAAU;AACjCH,IAAAA,cAAc,EAAE;AAAEG,MAAAA,IAAI,EAAE;AAAS;AACnC;AACF,CACF,CAAC;;;;"}
@@ -0,0 +1,3 @@
1
+ @forward "moj-frontend-properties";
2
+
3
+ /*# sourceMappingURL=_all.scss.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/moj/core/_all.scss"],"names":[],"mappings":"AAAA,kCAAkC","file":"_all.scss","sourcesContent":["@forward \"moj-frontend-properties\";\n"]}
@@ -0,0 +1,7 @@
1
+ :root {
2
+ // This variable is automatically overwritten during builds and releases.
3
+ // It doesn't need to be updated manually.
4
+ --moj-frontend-version: "5.1.0";
5
+ }
6
+
7
+ /*# sourceMappingURL=_moj-frontend-properties.scss.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/moj/core/_moj-frontend-properties.scss"],"names":[],"mappings":"AAAA;EACE,wEAAwE;EACxE,yCAAyC;EACzC,+BAAqC;AACvC","file":"_moj-frontend-properties.scss","sourcesContent":[":root {\n // This variable is automatically overwritten during builds and releases.\n // It doesn't need to be updated manually.\n --moj-frontend-version: \"development\";\n}\n"]}
@@ -1,9 +1,10 @@
1
+ // @ts-expect-error - No types available
1
2
  const { addFilter } = require('govuk-prototype-kit').views
2
3
 
3
4
  const getAllFilters = require('./all')
4
5
 
5
6
  const allFilters = getAllFilters()
6
7
 
7
- Object.keys(allFilters).forEach((name) => {
8
- addFilter(name, allFilters[name])
9
- })
8
+ for (const [name, filter] of Object.entries(allFilters)) {
9
+ addFilter(name, filter)
10
+ }
@@ -4,43 +4,42 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- function removeAttributeValue(el, attr, value) {
7
+ /**
8
+ * @param {Element} $element - Element to remove attribute value from
9
+ * @param {string} attr - Attribute name
10
+ * @param {string} value - Attribute value
11
+ */
12
+ function removeAttributeValue($element, attr, value) {
8
13
  let re, m;
9
- if (el.getAttribute(attr)) {
10
- if (el.getAttribute(attr) === value) {
11
- el.removeAttribute(attr);
14
+ if ($element.getAttribute(attr)) {
15
+ if ($element.getAttribute(attr) === value) {
16
+ $element.removeAttribute(attr);
12
17
  } else {
13
18
  re = new RegExp(`(^|\\s)${value}(\\s|$)`);
14
- m = el.getAttribute(attr).match(re);
19
+ m = $element.getAttribute(attr).match(re);
15
20
  if (m && m.length === 3) {
16
- el.setAttribute(attr, el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
21
+ $element.setAttribute(attr, $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
17
22
  }
18
23
  }
19
24
  }
20
25
  }
21
- function addAttributeValue(el, attr, value) {
26
+
27
+ /**
28
+ * @param {Element} $element - Element to add attribute value to
29
+ * @param {string} attr - Attribute name
30
+ * @param {string} value - Attribute value
31
+ */
32
+ function addAttributeValue($element, attr, value) {
22
33
  let re;
23
- if (!el.getAttribute(attr)) {
24
- el.setAttribute(attr, value);
34
+ if (!$element.getAttribute(attr)) {
35
+ $element.setAttribute(attr, value);
25
36
  } else {
26
37
  re = new RegExp(`(^|\\s)${value}(\\s|$)`);
27
- if (!re.test(el.getAttribute(attr))) {
28
- el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`);
38
+ if (!re.test($element.getAttribute(attr))) {
39
+ $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`);
29
40
  }
30
41
  }
31
42
  }
32
- function dragAndDropSupported() {
33
- const div = document.createElement('div');
34
- return typeof div.ondrop !== 'undefined';
35
- }
36
- function formDataSupported() {
37
- return typeof FormData === 'function';
38
- }
39
- function fileApiSupported() {
40
- const input = document.createElement('input');
41
- input.type = 'file';
42
- return typeof input.files !== 'undefined';
43
- }
44
43
 
45
44
  /**
46
45
  * Find an elements next sibling
@@ -131,65 +130,11 @@
131
130
  }
132
131
  }
133
132
 
134
- /**
135
- * Move focus to element
136
- *
137
- * Sets tabindex to -1 to make the element programmatically focusable,
138
- * but removes it on blur as the element doesn't need to be focused again.
139
- *
140
- * @param {HTMLElement} $element - HTML element
141
- * @param {object} [options] - Handler options
142
- * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
143
- * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
144
- */
145
- function setFocus($element, options = {}) {
146
- const isFocusable = $element.getAttribute('tabindex');
147
- if (!isFocusable) {
148
- $element.setAttribute('tabindex', '-1');
149
- }
150
-
151
- /**
152
- * Handle element focus
153
- */
154
- function onFocus() {
155
- $element.addEventListener('blur', onBlur, {
156
- once: true
157
- });
158
- }
159
-
160
- /**
161
- * Handle element blur
162
- */
163
- function onBlur() {
164
- if (options.onBlur) {
165
- options.onBlur.call($element);
166
- }
167
- if (!isFocusable) {
168
- $element.removeAttribute('tabindex');
169
- }
170
- }
171
-
172
- // Add listener to reset element on blur, after focus
173
- $element.addEventListener('focus', onFocus, {
174
- once: true
175
- });
176
-
177
- // Focus element
178
- if (options.onBeforeFocus) {
179
- options.onBeforeFocus.call($element);
180
- }
181
- $element.focus();
182
- }
183
-
184
133
  exports.addAttributeValue = addAttributeValue;
185
- exports.dragAndDropSupported = dragAndDropSupported;
186
- exports.fileApiSupported = fileApiSupported;
187
134
  exports.findNearestMatchingElement = findNearestMatchingElement;
188
- exports.formDataSupported = formDataSupported;
189
135
  exports.getNextSibling = getNextSibling;
190
136
  exports.getPreviousSibling = getPreviousSibling;
191
137
  exports.removeAttributeValue = removeAttributeValue;
192
- exports.setFocus = setFocus;
193
138
 
194
139
  }));
195
140
  //# sourceMappingURL=helpers.bundle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.bundle.js","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["export function removeAttributeValue(el, attr, value) {\n let re, m\n if (el.getAttribute(attr)) {\n if (el.getAttribute(attr) === value) {\n el.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = el.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n el.setAttribute(\n attr,\n el.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\nexport function addAttributeValue(el, attr, value) {\n let re\n if (!el.getAttribute(attr)) {\n el.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test(el.getAttribute(attr))) {\n el.setAttribute(attr, `${el.getAttribute(attr)} ${value}`)\n }\n }\n}\n\nexport function dragAndDropSupported() {\n const div = document.createElement('div')\n return typeof div.ondrop !== 'undefined'\n}\n\nexport function formDataSupported() {\n return typeof FormData === 'function'\n}\n\nexport function fileApiSupported() {\n const input = document.createElement('input')\n input.type = 'file'\n return typeof input.files !== 'undefined'\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n\n/**\n * Move focus to element\n *\n * Sets tabindex to -1 to make the element programmatically focusable,\n * but removes it on blur as the element doesn't need to be focused again.\n *\n * @param {HTMLElement} $element - HTML element\n * @param {object} [options] - Handler options\n * @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus\n * @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur\n */\nexport function setFocus($element, options = {}) {\n const isFocusable = $element.getAttribute('tabindex')\n\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1')\n }\n\n /**\n * Handle element focus\n */\n function onFocus() {\n $element.addEventListener('blur', onBlur, { once: true })\n }\n\n /**\n * Handle element blur\n */\n function onBlur() {\n if (options.onBlur) {\n options.onBlur.call($element)\n }\n\n if (!isFocusable) {\n $element.removeAttribute('tabindex')\n }\n }\n\n // Add listener to reset element on blur, after focus\n $element.addEventListener('focus', onFocus, { once: true })\n\n // Focus element\n if (options.onBeforeFocus) {\n options.onBeforeFocus.call($element)\n }\n $element.focus()\n}\n"],"names":["removeAttributeValue","el","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","dragAndDropSupported","div","document","createElement","ondrop","formDataSupported","FormData","fileApiSupported","input","type","files","getNextSibling","$element","selector","HTMLElement","$sibling","nextElementSibling","matches","getPreviousSibling","previousElementSibling","findNearestMatchingElement","$currentElement","parentElement","setFocus","options","isFocusable","onFocus","addEventListener","onBlur","once","call","onBeforeFocus","focus"],"mappings":";;;;;;EAAO,SAASA,oBAAoBA,CAACC,EAAE,EAAEC,IAAI,EAAEC,KAAK,EAAE;IACpD,IAAIC,EAAE,EAAEC,CAAC;EACT,EAAA,IAAIJ,EAAE,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;MACzB,IAAID,EAAE,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;EACnCF,MAAAA,EAAE,CAACM,eAAe,CAACL,IAAI,CAAC;EAC1B,KAAC,MAAM;EACLE,MAAAA,EAAE,GAAG,IAAII,MAAM,CAAC,CAAUL,OAAAA,EAAAA,KAAK,SAAS,CAAC;QACzCE,CAAC,GAAGJ,EAAE,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACO,KAAK,CAACL,EAAE,CAAC;EACnC,MAAA,IAAIC,CAAC,IAAIA,CAAC,CAACK,MAAM,KAAK,CAAC,EAAE;EACvBT,QAAAA,EAAE,CAACU,YAAY,CACbT,IAAI,EACJD,EAAE,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACU,OAAO,CAACR,EAAE,EAAEC,CAAC,CAAC,CAAC,CAAC,IAAIA,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,CAC3D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src/moj/helpers.mjs"],"sourcesContent":["/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n"],"names":["removeAttributeValue","$element","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","getNextSibling","selector","HTMLElement","$sibling","nextElementSibling","matches","getPreviousSibling","previousElementSibling","findNearestMatchingElement","$currentElement","parentElement"],"mappings":";;;;;;EAAA;EACA;EACA;EACA;EACA;EACO,SAASA,oBAAoBA,CAACC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAC1D,IAAIC,EAAE,EAAEC,CAAC;EACT,EAAA,IAAIJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;MAC/B,IAAID,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;EACzCF,MAAAA,QAAQ,CAACM,eAAe,CAACL,IAAI,CAAC;EAChC,KAAC,MAAM;EACLE,MAAAA,EAAE,GAAG,IAAII,MAAM,CAAC,CAAUL,OAAAA,EAAAA,KAAK,SAAS,CAAC;QACzCE,CAAC,GAAGJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACO,KAAK,CAACL,EAAE,CAAC;EACzC,MAAA,IAA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