@itrocks/list 0.27.1 → 0.28.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.
- package/README.md +3 -7
- package/build.d.ts +1 -1
- package/build.js +1 -1
- package/cjs/list.html +3 -8
- package/list.css +37 -49
- package/package.json +1 -1
- package/search-focus.js +15 -1
- package/toolbar.js +10 -3
- package/search-menu.d.ts +0 -1
- package/search-menu.js +0 -140
package/README.md
CHANGED
|
@@ -102,13 +102,9 @@ For `json()`, the scope is passed directly to `dataSource().search()`.
|
|
|
102
102
|
|
|
103
103
|
## Search filters
|
|
104
104
|
|
|
105
|
-
The
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
Reset clears all filters, including saved filters for hidden columns, and reloads the list without changing its sorting
|
|
109
|
-
or column configuration. The menu does not change the selection column's width.
|
|
110
|
-
Arrow Down, the context-menu key or Shift+F10 on the button also opens the menu. Use arrow keys to select an action,
|
|
111
|
-
Enter or Space to activate it, and Escape to close it. Clicking outside dismisses the menu.
|
|
105
|
+
The filter button in the first column submits the column filters, as does Enter in a filter field.
|
|
106
|
+
When the toolbar shows a filter, the reset button appears immediately to its right.
|
|
107
|
+
Reset clears all filters, including saved filters for hidden columns, and reloads the list with its current sorting and columns.
|
|
112
108
|
|
|
113
109
|
HTML list filters interpret the first hyphen as an interval separator. Spaces around the bounds are ignored:
|
|
114
110
|
|
package/build.d.ts
CHANGED
package/build.js
CHANGED
|
@@ -10,7 +10,7 @@ import { TableLink } from '@itrocks/table/link.js';
|
|
|
10
10
|
import { tableByElement } from '@itrocks/table/table.js';
|
|
11
11
|
import { xTargetCall } from '@itrocks/xtarget/xtarget.js';
|
|
12
12
|
import './column-filter.js';
|
|
13
|
-
import './search-
|
|
13
|
+
import './search-focus.js';
|
|
14
14
|
import './toolbar.js';
|
|
15
15
|
build('article[data-action="list"] > form > table.objects', table => {
|
|
16
16
|
let persistedColumns = [...table.querySelectorAll('thead th[data-property]')]
|
package/cjs/list.html
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
</ul>
|
|
28
28
|
<div class="list-filter">
|
|
29
29
|
<!--filterBar-->{{template}}<!--end-->
|
|
30
|
+
<button aria-label="Reset search filters" class="list-filter-reset" title="Reset search filters"
|
|
31
|
+
type="button">×</button>
|
|
30
32
|
</div>
|
|
31
33
|
<div class="summary">{count} elements</div>
|
|
32
34
|
<button class="add-column" hidden type="button" aria-label="Add column">+</button>
|
|
@@ -53,14 +55,7 @@
|
|
|
53
55
|
{./feed.html}
|
|
54
56
|
</tbody>
|
|
55
57
|
</table>
|
|
56
|
-
<
|
|
57
|
-
<button class="search" role="menuitem" tabindex="-1" type="submit">
|
|
58
|
-
Search
|
|
59
|
-
</button>
|
|
60
|
-
<button class="reset" name="reset" role="menuitem" tabindex="-1" type="submit" value="reset">
|
|
61
|
-
Reset search filters
|
|
62
|
-
</button>
|
|
63
|
-
</div>
|
|
58
|
+
<button hidden name="reset" type="submit" value="reset">Reset search filters</button>
|
|
64
59
|
<footer>
|
|
65
60
|
<ul class="selection actions">
|
|
66
61
|
<!--selection--><!--footer-->{{template}}<!--end--><!--end-->
|
package/list.css
CHANGED
|
@@ -211,15 +211,26 @@ table.objects > thead > tr.properties > th > input:not([type=checkbox]) {
|
|
|
211
211
|
width: 100%;
|
|
212
212
|
}
|
|
213
213
|
table.objects > thead > tr.properties > th > input.search-submit {
|
|
214
|
-
background: url("
|
|
214
|
+
background: url("filter.svg") center/18px no-repeat;
|
|
215
215
|
color: transparent;
|
|
216
216
|
cursor: pointer;
|
|
217
217
|
font-size: 0;
|
|
218
218
|
padding: 0;
|
|
219
219
|
touch-action: manipulation;
|
|
220
|
+
-webkit-tap-highlight-color: transparent;
|
|
220
221
|
-webkit-touch-callout: none;
|
|
221
222
|
width: 28px;
|
|
222
223
|
}
|
|
224
|
+
table.objects > thead > tr.properties > th > input.search-submit:hover, table.objects > thead > tr.properties > th > input.search-submit:focus, table.objects > thead > tr.properties > th > input.search-submit:active {
|
|
225
|
+
background-color: #e3e3e3;
|
|
226
|
+
}
|
|
227
|
+
table.objects > thead > tr.properties > th > input.search-submit:focus {
|
|
228
|
+
outline: none;
|
|
229
|
+
}
|
|
230
|
+
table.objects > thead > tr.properties > th > input.search-submit:focus-visible {
|
|
231
|
+
outline: 1px solid #808080;
|
|
232
|
+
outline-offset: -1px;
|
|
233
|
+
}
|
|
223
234
|
table.objects > thead > tr.properties > th > input[data-property-filter] {
|
|
224
235
|
border-left: 1px solid #d8d8d8;
|
|
225
236
|
margin-left: -0.6em;
|
|
@@ -240,53 +251,11 @@ table.objects > thead > tr.properties > th > input[data-property-filter][data-fi
|
|
|
240
251
|
table.objects > thead > tr.properties > th[data-sort] > input[data-property-filter] {
|
|
241
252
|
width: calc(100% + 1.2em + 16px);
|
|
242
253
|
}
|
|
243
|
-
table.objects > thead > tr.properties > th > input:focus {
|
|
254
|
+
table.objects > thead > tr.properties > th > input:focus:not(.search-submit) {
|
|
244
255
|
box-shadow: inset 0 0 0 2px Highlight, var(--column-reorder-tint, 0 0 transparent);
|
|
245
256
|
outline: none;
|
|
246
257
|
}
|
|
247
258
|
|
|
248
|
-
article[data-action=list] > form > .search-menu {
|
|
249
|
-
background: white;
|
|
250
|
-
border: 1px solid #ccc;
|
|
251
|
-
border-radius: 4px;
|
|
252
|
-
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
|
|
253
|
-
color: #333;
|
|
254
|
-
inset: auto;
|
|
255
|
-
margin: 0;
|
|
256
|
-
max-height: calc(100dvh - 8px);
|
|
257
|
-
max-width: calc(100vw - 8px);
|
|
258
|
-
padding: 4px;
|
|
259
|
-
position: fixed;
|
|
260
|
-
}
|
|
261
|
-
article[data-action=list] > form > .search-menu > button {
|
|
262
|
-
align-items: center;
|
|
263
|
-
background: none;
|
|
264
|
-
border: 0;
|
|
265
|
-
border-radius: 2px;
|
|
266
|
-
color: inherit;
|
|
267
|
-
cursor: pointer;
|
|
268
|
-
display: flex;
|
|
269
|
-
font: inherit;
|
|
270
|
-
gap: 10px;
|
|
271
|
-
min-height: 44px;
|
|
272
|
-
padding: 8px 12px;
|
|
273
|
-
text-align: left;
|
|
274
|
-
width: 100%;
|
|
275
|
-
}
|
|
276
|
-
article[data-action=list] > form > .search-menu > button::before {
|
|
277
|
-
background: currentColor;
|
|
278
|
-
content: "";
|
|
279
|
-
flex: 0 0 24px;
|
|
280
|
-
height: 24px;
|
|
281
|
-
mask: url("search.svg") center/contain no-repeat;
|
|
282
|
-
}
|
|
283
|
-
article[data-action=list] > form > .search-menu > button.reset::before {
|
|
284
|
-
mask-image: url("filter-reset.svg");
|
|
285
|
-
}
|
|
286
|
-
article[data-action=list] > form > .search-menu > button:focus-visible, article[data-action=list] > form > .search-menu > button:hover {
|
|
287
|
-
background: #eee;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
259
|
main > article[data-action=list] > header > .list-toolbar {
|
|
291
260
|
--list-toolbar-gap: 5px;
|
|
292
261
|
align-items: center;
|
|
@@ -371,16 +340,35 @@ main > article[data-action=list] > header > .list-toolbar > .summary {
|
|
|
371
340
|
min-width: 0;
|
|
372
341
|
}
|
|
373
342
|
.list-filter .list-filter-icon {
|
|
374
|
-
background: url("filter.svg") center/
|
|
375
|
-
|
|
376
|
-
|
|
343
|
+
background: url("filter.svg") center/18px no-repeat;
|
|
344
|
+
}
|
|
345
|
+
.list-filter span.list-filter-icon {
|
|
377
346
|
flex: none;
|
|
378
347
|
height: 18px;
|
|
379
|
-
padding: 0;
|
|
380
348
|
width: 18px;
|
|
381
349
|
}
|
|
382
|
-
.list-filter button.list-filter-icon {
|
|
350
|
+
.list-filter button.list-filter-icon, .list-filter > .list-filter-reset {
|
|
351
|
+
border: 0;
|
|
352
|
+
border-radius: 2px;
|
|
383
353
|
cursor: pointer;
|
|
354
|
+
flex: none;
|
|
355
|
+
height: 36px;
|
|
356
|
+
padding: 0;
|
|
357
|
+
touch-action: manipulation;
|
|
358
|
+
width: 32px;
|
|
359
|
+
}
|
|
360
|
+
.list-filter button.list-filter-icon:hover, .list-filter > .list-filter-reset:hover {
|
|
361
|
+
background-color: #eee;
|
|
362
|
+
}
|
|
363
|
+
.list-filter > .list-filter-reset {
|
|
364
|
+
background: transparent;
|
|
365
|
+
color: #666;
|
|
366
|
+
display: none;
|
|
367
|
+
font-size: 22px;
|
|
368
|
+
line-height: 1;
|
|
369
|
+
}
|
|
370
|
+
.list-filter:has(.list-filter-text:not([data-filled=false])) > .list-filter-reset {
|
|
371
|
+
display: block;
|
|
384
372
|
}
|
|
385
373
|
.list-filter .list-filter-text {
|
|
386
374
|
border-bottom: 1px dotted #888;
|
package/package.json
CHANGED
package/search-focus.js
CHANGED
|
@@ -12,9 +12,14 @@ build({
|
|
|
12
12
|
return;
|
|
13
13
|
bound.add(form);
|
|
14
14
|
let column;
|
|
15
|
+
form.querySelector('.search-submit')?.addEventListener('pointerdown', event => {
|
|
16
|
+
if (event.isPrimary && event.button === 0 && focusedColumn(form)) {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
15
20
|
form.addEventListener('submit', event => {
|
|
16
21
|
const submitter = event.submitter;
|
|
17
|
-
column = (!submitter || submitter.matches('.search-submit
|
|
22
|
+
column = (!submitter || submitter.matches('.search-submit'))
|
|
18
23
|
? focusedColumn(form)?.name.slice('search.'.length)
|
|
19
24
|
: undefined;
|
|
20
25
|
}, { capture: true });
|
|
@@ -37,3 +42,12 @@ build({
|
|
|
37
42
|
priority: 2000,
|
|
38
43
|
selector: 'article[data-action="list"] > form'
|
|
39
44
|
});
|
|
45
|
+
build('.list-filter > .list-filter-reset', 'click', function () {
|
|
46
|
+
const form = this.closest('article[data-action="list"]')?.querySelector(':scope > form');
|
|
47
|
+
if (!form)
|
|
48
|
+
return;
|
|
49
|
+
const reset = form.querySelector('button[name="reset"]');
|
|
50
|
+
if (reset) {
|
|
51
|
+
form.requestSubmit(reset);
|
|
52
|
+
}
|
|
53
|
+
});
|
package/toolbar.js
CHANGED
|
@@ -14,13 +14,14 @@ function contentWidth(element, style) {
|
|
|
14
14
|
}
|
|
15
15
|
function filterWidth(filter) {
|
|
16
16
|
const icon = filter.querySelector('.list-filter-icon');
|
|
17
|
-
|
|
17
|
+
const filterStyle = getComputedStyle(filter);
|
|
18
|
+
let width = inlineEdges(filterStyle);
|
|
18
19
|
if (!icon)
|
|
19
20
|
return width;
|
|
20
21
|
const text = filter.querySelector('.list-filter-text');
|
|
21
22
|
const row = icon.parentElement;
|
|
22
23
|
width += icon.getBoundingClientRect().width;
|
|
23
|
-
const rowStyle = getComputedStyle(row);
|
|
24
|
+
const rowStyle = row === filter ? filterStyle : getComputedStyle(row);
|
|
24
25
|
if (row !== filter) {
|
|
25
26
|
width += inlineEdges(rowStyle);
|
|
26
27
|
}
|
|
@@ -28,6 +29,10 @@ function filterWidth(filter) {
|
|
|
28
29
|
const textStyle = getComputedStyle(text);
|
|
29
30
|
width += gapWidth(rowStyle, 2) + Math.max(contentWidth(text, textStyle), pixels(textStyle.minWidth));
|
|
30
31
|
}
|
|
32
|
+
const resetWidth = filter.querySelector('.list-filter-reset')?.getBoundingClientRect().width ?? 0;
|
|
33
|
+
if (resetWidth) {
|
|
34
|
+
width += gapWidth(filterStyle, 2) + resetWidth;
|
|
35
|
+
}
|
|
31
36
|
return width;
|
|
32
37
|
}
|
|
33
38
|
function gapWidth(style, items) {
|
|
@@ -66,7 +71,9 @@ function watchToolbar(toolbar) {
|
|
|
66
71
|
resize.observe(element);
|
|
67
72
|
}
|
|
68
73
|
const mutations = new MutationObserver(schedule);
|
|
69
|
-
mutations.observe(toolbar, {
|
|
74
|
+
mutations.observe(toolbar, {
|
|
75
|
+
attributeFilter: ['data-filled', 'hidden'], characterData: true, childList: true, subtree: true
|
|
76
|
+
});
|
|
70
77
|
for (const event of ['focusin', 'focusout', 'input']) {
|
|
71
78
|
toolbar.addEventListener(event, schedule, { signal: abort.signal });
|
|
72
79
|
}
|
package/search-menu.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/search-menu.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { build } from '@itrocks/build/build.js';
|
|
2
|
-
import { focusedColumn } from './search-focus.js';
|
|
3
|
-
const bound = new WeakSet();
|
|
4
|
-
build('article[data-action="list"] > form', form => {
|
|
5
|
-
if (bound.has(form))
|
|
6
|
-
return;
|
|
7
|
-
const trigger = form.querySelector('.search-submit');
|
|
8
|
-
const menu = form.querySelector('.search-menu');
|
|
9
|
-
if (!trigger || !menu)
|
|
10
|
-
return;
|
|
11
|
-
bound.add(form);
|
|
12
|
-
const items = Array.from(menu.querySelectorAll('[role="menuitem"]'));
|
|
13
|
-
let listeners;
|
|
14
|
-
let pointer;
|
|
15
|
-
let suppressClick = false;
|
|
16
|
-
let timer;
|
|
17
|
-
const cancel = () => {
|
|
18
|
-
clearTimeout(timer);
|
|
19
|
-
pointer = undefined;
|
|
20
|
-
};
|
|
21
|
-
const dismiss = () => {
|
|
22
|
-
if (!menu.matches(':popover-open'))
|
|
23
|
-
return;
|
|
24
|
-
menu.hidePopover();
|
|
25
|
-
trigger.setAttribute('aria-expanded', 'false');
|
|
26
|
-
listeners?.abort();
|
|
27
|
-
};
|
|
28
|
-
const close = () => {
|
|
29
|
-
dismiss();
|
|
30
|
-
trigger.focus();
|
|
31
|
-
};
|
|
32
|
-
const open = () => {
|
|
33
|
-
cancel();
|
|
34
|
-
if (!trigger.isConnected || menu.matches(':popover-open'))
|
|
35
|
-
return;
|
|
36
|
-
// A manual popover stays open when the opening right-click or long press is released.
|
|
37
|
-
menu.showPopover();
|
|
38
|
-
const rect = trigger.getBoundingClientRect();
|
|
39
|
-
menu.style.left = `${Math.max(4, Math.min(rect.left, innerWidth - menu.offsetWidth - 4))}px`;
|
|
40
|
-
menu.style.top = `${Math.max(4, rect.bottom + menu.offsetHeight <= innerHeight - 4
|
|
41
|
-
? rect.bottom : rect.top - menu.offsetHeight)}px`;
|
|
42
|
-
trigger.setAttribute('aria-expanded', 'true');
|
|
43
|
-
items[0].focus();
|
|
44
|
-
listeners?.abort();
|
|
45
|
-
listeners = new AbortController();
|
|
46
|
-
const { signal } = listeners;
|
|
47
|
-
document.addEventListener('scroll', close, { capture: true, signal });
|
|
48
|
-
window.addEventListener('resize', close, { signal });
|
|
49
|
-
document.addEventListener('pointerdown', event => {
|
|
50
|
-
if ((event.target instanceof Node) && !menu.contains(event.target) && !trigger.contains(event.target))
|
|
51
|
-
dismiss();
|
|
52
|
-
}, { signal });
|
|
53
|
-
document.addEventListener('keydown', event => {
|
|
54
|
-
if ((event.key !== 'Escape') || event.defaultPrevented)
|
|
55
|
-
return;
|
|
56
|
-
event.preventDefault();
|
|
57
|
-
close();
|
|
58
|
-
}, { signal });
|
|
59
|
-
};
|
|
60
|
-
menu.addEventListener('toggle', () => {
|
|
61
|
-
if (menu.matches(':popover-open'))
|
|
62
|
-
return;
|
|
63
|
-
trigger.setAttribute('aria-expanded', 'false');
|
|
64
|
-
listeners?.abort();
|
|
65
|
-
});
|
|
66
|
-
menu.addEventListener('click', event => {
|
|
67
|
-
if ((event.target instanceof Element) && event.target.closest('button'))
|
|
68
|
-
dismiss();
|
|
69
|
-
});
|
|
70
|
-
menu.addEventListener('keydown', event => {
|
|
71
|
-
const index = items.indexOf(document.activeElement);
|
|
72
|
-
let next;
|
|
73
|
-
switch (event.key) {
|
|
74
|
-
case 'ArrowDown':
|
|
75
|
-
next = (index + 1) % items.length;
|
|
76
|
-
break;
|
|
77
|
-
case 'ArrowUp':
|
|
78
|
-
next = (index + items.length - 1) % items.length;
|
|
79
|
-
break;
|
|
80
|
-
case 'Home':
|
|
81
|
-
next = 0;
|
|
82
|
-
break;
|
|
83
|
-
case 'End':
|
|
84
|
-
next = items.length - 1;
|
|
85
|
-
break;
|
|
86
|
-
case 'Escape':
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
close();
|
|
89
|
-
return;
|
|
90
|
-
case 'Tab':
|
|
91
|
-
close();
|
|
92
|
-
return;
|
|
93
|
-
default: return;
|
|
94
|
-
}
|
|
95
|
-
event.preventDefault();
|
|
96
|
-
items[next].focus();
|
|
97
|
-
});
|
|
98
|
-
trigger.addEventListener('contextmenu', event => {
|
|
99
|
-
event.preventDefault();
|
|
100
|
-
suppressClick = true;
|
|
101
|
-
open();
|
|
102
|
-
});
|
|
103
|
-
trigger.addEventListener('keydown', event => {
|
|
104
|
-
if ((event.key !== 'ArrowDown') && (event.key !== 'ContextMenu')
|
|
105
|
-
&& !((event.key === 'F10') && event.shiftKey))
|
|
106
|
-
return;
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
open();
|
|
109
|
-
});
|
|
110
|
-
trigger.addEventListener('pointerdown', event => {
|
|
111
|
-
cancel();
|
|
112
|
-
suppressClick = false;
|
|
113
|
-
if (!event.isPrimary || (event.button !== 0))
|
|
114
|
-
return;
|
|
115
|
-
if (focusedColumn(form)) {
|
|
116
|
-
event.preventDefault();
|
|
117
|
-
}
|
|
118
|
-
pointer = { id: event.pointerId, x: event.clientX, y: event.clientY };
|
|
119
|
-
trigger.setPointerCapture(event.pointerId);
|
|
120
|
-
timer = setTimeout(() => {
|
|
121
|
-
suppressClick = true;
|
|
122
|
-
open();
|
|
123
|
-
}, 500);
|
|
124
|
-
});
|
|
125
|
-
trigger.addEventListener('pointermove', event => {
|
|
126
|
-
if (pointer && (pointer.id === event.pointerId)
|
|
127
|
-
&& (Math.hypot(event.clientX - pointer.x, event.clientY - pointer.y) > 10)) {
|
|
128
|
-
suppressClick = true;
|
|
129
|
-
cancel();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
for (const type of ['pointercancel', 'pointerup', 'lostpointercapture'])
|
|
133
|
-
trigger.addEventListener(type, cancel);
|
|
134
|
-
trigger.addEventListener('click', event => {
|
|
135
|
-
if (!suppressClick || (event.detail === 0))
|
|
136
|
-
return;
|
|
137
|
-
event.preventDefault();
|
|
138
|
-
event.stopImmediatePropagation();
|
|
139
|
-
}, { capture: true });
|
|
140
|
-
});
|