@itrocks/list 0.25.1 → 0.27.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 +7 -0
- package/build.d.ts +2 -0
- package/build.js +3 -1
- package/cjs/access.d.ts +16 -0
- package/cjs/access.js +4 -0
- package/cjs/filter-summary.d.ts +10 -0
- package/cjs/filter-summary.html +5 -0
- package/cjs/filter-summary.js +53 -0
- package/cjs/filter.d.ts +5 -1
- package/cjs/filter.js +51 -33
- package/cjs/list.d.ts +3 -1
- package/cjs/list.html +19 -10
- package/cjs/list.js +27 -19
- package/cjs/projection.d.ts +1 -0
- package/cjs/projection.js +4 -0
- package/cjs/search-expression.d.ts +2 -0
- package/cjs/search.d.ts +14 -0
- package/cjs/search.js +41 -0
- package/cjs/session-state.d.ts +6 -0
- package/cjs/session-state.js +7 -1
- package/column-filter.d.ts +1 -0
- package/column-filter.js +26 -0
- package/docs/dependencies.md +5 -0
- package/filter.svg +1 -0
- package/list.css +114 -30
- package/package.json +6 -1
- package/property-select.js +2 -2
- package/search-focus.d.ts +1 -0
- package/search-focus.js +39 -0
- package/search-menu.js +4 -0
- package/toolbar.d.ts +1 -0
- package/toolbar.js +89 -0
package/README.md
CHANGED
|
@@ -30,6 +30,13 @@ JSON payload depending on the requested format.
|
|
|
30
30
|
HTML rendering provides columns, filters, ordered sorting and session preferences. The JSON action exposes
|
|
31
31
|
business objects for API consumers. See the public methods below for their shared contracts.
|
|
32
32
|
|
|
33
|
+
Column filter values use the same text highlight as the toolbar summary.
|
|
34
|
+
After applying column filters, the toolbar shows a decorative filter icon and a read-only summary.
|
|
35
|
+
The summary uses unique single-word column labels when available.
|
|
36
|
+
Applying a search from a column filter returns focus to that field and selects its full value.
|
|
37
|
+
When the toolbar runs out of space, the filter and add-column button move to a second row.
|
|
38
|
+
Use [@itrocks/list-filter](https://github.com/itrocks-ts/list-filter) to make the summary editable.
|
|
39
|
+
|
|
33
40
|
## API
|
|
34
41
|
|
|
35
42
|
### `class List<T extends object = object> extends Action<T>`
|
package/build.d.ts
CHANGED
package/build.js
CHANGED
|
@@ -9,7 +9,9 @@ import { TableFreezeInheritBorder } from '@itrocks/table/freeze/inherit-border.j
|
|
|
9
9
|
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
|
+
import './column-filter.js';
|
|
12
13
|
import './search-menu.js';
|
|
14
|
+
import './toolbar.js';
|
|
13
15
|
build('article[data-action="list"] > form > table.objects', table => {
|
|
14
16
|
let persistedColumns = [...table.querySelectorAll('thead th[data-property]')]
|
|
15
17
|
.map(header => header.dataset.property).join(',');
|
|
@@ -62,7 +64,7 @@ build('article[data-action="list"] > form > table.objects', table => {
|
|
|
62
64
|
}));
|
|
63
65
|
table.addEventListener('click', event => {
|
|
64
66
|
const element = event.target;
|
|
65
|
-
if (!(element instanceof HTMLElement) || element.closest('input, button'))
|
|
67
|
+
if (!(element instanceof HTMLElement) || element.closest('input, button, label'))
|
|
66
68
|
return;
|
|
67
69
|
const cell = element.closest('table, th');
|
|
68
70
|
if (!((cell instanceof HTMLTableCellElement) && cell.classList.contains('select')))
|
package/cjs/access.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Request } from '@itrocks/action-request';
|
|
2
2
|
import type { StateRecord } from '@itrocks/property-select';
|
|
3
|
+
import type { Response } from '@itrocks/request-response';
|
|
4
|
+
import type { ListSearch } from './search';
|
|
3
5
|
export type ListAccess = {
|
|
4
6
|
authorise(path: string): Promise<void>;
|
|
5
7
|
bootstrap?(paths: string[], state: StateRecord): Promise<object>;
|
|
@@ -8,6 +10,13 @@ export type ListAccess = {
|
|
|
8
10
|
export type ListDependencies = {
|
|
9
11
|
access: (request: Request) => Promise<ListAccess>;
|
|
10
12
|
view: (request: Request) => Promise<ListView | undefined>;
|
|
13
|
+
selection?: {
|
|
14
|
+
update: (request: Request) => Promise<Response | undefined>;
|
|
15
|
+
view: (request: Request, search: ListSearch, count: number) => Promise<ListView & {
|
|
16
|
+
footer?: ListView;
|
|
17
|
+
footerSummary?: ListView;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
11
20
|
};
|
|
12
21
|
export type ListView = {
|
|
13
22
|
template: string;
|
|
@@ -16,3 +25,10 @@ export type ListView = {
|
|
|
16
25
|
export declare function listAccess(request: Request): Promise<ListAccess>;
|
|
17
26
|
export declare function listDependsOn(overrides: Partial<ListDependencies>): void;
|
|
18
27
|
export declare function listView(request: Request): Promise<ListView | undefined>;
|
|
28
|
+
export declare function listSelection(): {
|
|
29
|
+
update: (request: Request) => Promise<Response | undefined>;
|
|
30
|
+
view: (request: Request, search: ListSearch, count: number) => Promise<ListView & {
|
|
31
|
+
footer?: ListView;
|
|
32
|
+
footerSummary?: ListView;
|
|
33
|
+
}>;
|
|
34
|
+
} | undefined;
|
package/cjs/access.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.listAccess = listAccess;
|
|
4
4
|
exports.listDependsOn = listDependsOn;
|
|
5
5
|
exports.listView = listView;
|
|
6
|
+
exports.listSelection = listSelection;
|
|
6
7
|
const dependencies = {
|
|
7
8
|
access: async () => ({ authorise: async () => { } }),
|
|
8
9
|
view: async () => undefined
|
|
@@ -16,4 +17,7 @@ function listDependsOn(overrides) {
|
|
|
16
17
|
function listView(request) {
|
|
17
18
|
return dependencies.view(request);
|
|
18
19
|
}
|
|
20
|
+
function listSelection() {
|
|
21
|
+
return dependencies.selection;
|
|
22
|
+
}
|
|
19
23
|
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Type } from '@itrocks/class-type';
|
|
2
|
+
import type { ListView } from './access';
|
|
3
|
+
import type { ListColumn } from './projection';
|
|
4
|
+
export declare function escapeFilterText(text: string): string;
|
|
5
|
+
export declare function filterAliases(type: Type, columns: Iterable<Pick<ListColumn, 'label' | 'name'>>): Map<string, string>;
|
|
6
|
+
export declare function filterEntries(search: Record<string, string>, aliases: ReadonlyMap<string, string>): {
|
|
7
|
+
field: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
export declare function filterSummary(search: Record<string, string>, aliases: ReadonlyMap<string, string>): ListView;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<!--criteria-->
|
|
2
|
+
<span class="list-filter-icon" aria-hidden="true"></span>
|
|
3
|
+
<span aria-label="Active list filters" class="list-filter-text" role="group"
|
|
4
|
+
><!--items--><code>{caption}</code><code class="list-filter-value">{value}</code>{space}<!--end--></span>
|
|
5
|
+
<!--end-->
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeFilterText = escapeFilterText;
|
|
4
|
+
exports.filterAliases = filterAliases;
|
|
5
|
+
exports.filterEntries = filterEntries;
|
|
6
|
+
exports.filterSummary = filterSummary;
|
|
7
|
+
const reflect_path_1 = require("@itrocks/reflect-path");
|
|
8
|
+
const fieldPart = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
|
|
9
|
+
const quotedValue = /[\s"]|^(?:!=|<>|[!=<>]=?)?'/;
|
|
10
|
+
function escapeFilterText(text) {
|
|
11
|
+
return text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
12
|
+
}
|
|
13
|
+
function filterAliases(type, columns) {
|
|
14
|
+
const labels = new Map();
|
|
15
|
+
for (const { label, name } of columns) {
|
|
16
|
+
const alias = label.toLowerCase();
|
|
17
|
+
if (!alias.split('.').every(part => fieldPart.test(part)))
|
|
18
|
+
continue;
|
|
19
|
+
labels.set(alias, [...(labels.get(alias) ?? []), name]);
|
|
20
|
+
}
|
|
21
|
+
const aliases = new Map();
|
|
22
|
+
for (const [alias, names] of labels) {
|
|
23
|
+
if ((names.length !== 1) || (alias === names[0]))
|
|
24
|
+
continue;
|
|
25
|
+
try {
|
|
26
|
+
// A real property path always takes precedence over a translated label.
|
|
27
|
+
(0, reflect_path_1.resolvePropertyPath)(type, alias);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
aliases.set(alias, names[0]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return aliases;
|
|
34
|
+
}
|
|
35
|
+
function filterEntries(search, aliases) {
|
|
36
|
+
const labels = new Map([...aliases].map(([alias, path]) => [path, alias]));
|
|
37
|
+
return Object.entries(search)
|
|
38
|
+
.filter(([, value]) => value !== '')
|
|
39
|
+
.map(([path, value]) => ({
|
|
40
|
+
field: labels.get(path) ?? path,
|
|
41
|
+
value: quotedValue.test(value) ? '"' + value.replace(/[\\"]/g, '\\$&') + '"' : value
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
function filterSummary(search, aliases) {
|
|
45
|
+
const entries = filterEntries(search, aliases);
|
|
46
|
+
const items = entries.map(({ field, value }, index) => ({
|
|
47
|
+
caption: escapeFilterText(field + ':'),
|
|
48
|
+
space: (index + 1 < entries.length) ? ' ' : '',
|
|
49
|
+
value: escapeFilterText(value)
|
|
50
|
+
}));
|
|
51
|
+
return { criteria: items.length ? { items } : undefined, template: './filter-summary.html' };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=filter-summary.js.map
|
package/cjs/filter.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Type } from '@itrocks/class-type';
|
|
2
2
|
import { Request } from '@itrocks/request-response';
|
|
3
3
|
import { Option } from '@itrocks/storage';
|
|
4
|
+
import { SearchType } from '@itrocks/storage';
|
|
4
5
|
import { Columns } from './columns';
|
|
5
6
|
import { Parameter } from './parameter';
|
|
7
|
+
import { SearchExpression } from './search-expression';
|
|
6
8
|
type Search = {
|
|
7
9
|
[property: string]: string;
|
|
8
10
|
};
|
|
@@ -10,7 +12,9 @@ export declare class Filter<T extends object> extends Parameter {
|
|
|
10
12
|
columns: Columns<T>;
|
|
11
13
|
search: Search;
|
|
12
14
|
constructor(columns: Columns<T>);
|
|
13
|
-
|
|
15
|
+
protected columnCondition(type: Type, property: string, value: string): SearchType;
|
|
16
|
+
protected condition(type: Type, property: string, expression: SearchExpression, ancestors?: readonly Type[]): SearchType;
|
|
17
|
+
getParams(request: Request, _type?: Type): void;
|
|
14
18
|
readOptions(options?: Option[]): Option[];
|
|
15
19
|
searchObject(type: Type): any;
|
|
16
20
|
serialize(): Search;
|
package/cjs/filter.js
CHANGED
|
@@ -30,11 +30,23 @@ const operators = {
|
|
|
30
30
|
'>': sql_functions_6.greater,
|
|
31
31
|
'>=': sql_functions_7.greaterOrEqual
|
|
32
32
|
};
|
|
33
|
+
function explicitSearchValue(propertyType, operator, value) {
|
|
34
|
+
if (propertyType === Date)
|
|
35
|
+
return (0, date_search_1.dateSearch)(value, operator === ':' ? '=' : operator);
|
|
36
|
+
if (operator !== ':')
|
|
37
|
+
return operators[operator](value);
|
|
38
|
+
if (propertyType !== String)
|
|
39
|
+
return value;
|
|
40
|
+
return (0, sql_functions_10.like)(value.replace(/[\\%_]/g, '\\$&') + '%');
|
|
41
|
+
}
|
|
33
42
|
function searchValue(propertyType, expression) {
|
|
34
43
|
if (!('value' in expression)) {
|
|
35
44
|
const combine = (expression.operator === 'AND') ? sql_functions_3.and : sql_functions_13.or;
|
|
36
45
|
return combine(...expression.operands.map(operand => searchValue(propertyType, operand) ?? (0, sql_functions_13.or)()));
|
|
37
46
|
}
|
|
47
|
+
if (expression.comparison !== undefined) {
|
|
48
|
+
return explicitSearchValue(propertyType, expression.comparison, expression.value);
|
|
49
|
+
}
|
|
38
50
|
let value = expression.value;
|
|
39
51
|
const alias = value.trim().match(/^(!=|<>|!)?\s*(.+)$/s);
|
|
40
52
|
if (alias && ((0, translate_1.trReverse)(alias[2].toLowerCase()) === 'empty')) {
|
|
@@ -74,7 +86,41 @@ class Filter extends parameter_1.Parameter {
|
|
|
74
86
|
super();
|
|
75
87
|
this.columns = columns;
|
|
76
88
|
}
|
|
77
|
-
|
|
89
|
+
columnCondition(type, property, value) {
|
|
90
|
+
let expression;
|
|
91
|
+
try {
|
|
92
|
+
expression = (0, search_expression_1.searchExpression)(value);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (!(error instanceof SyntaxError))
|
|
96
|
+
throw error;
|
|
97
|
+
return { [property]: (0, sql_functions_13.or)() };
|
|
98
|
+
}
|
|
99
|
+
const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
|
|
100
|
+
if (resolved.target)
|
|
101
|
+
return this.condition(type, property, expression);
|
|
102
|
+
const criterion = searchValue(resolved.property.type.type, expression);
|
|
103
|
+
return (criterion === undefined) ? {} : { [property]: criterion };
|
|
104
|
+
}
|
|
105
|
+
condition(type, property, expression, ancestors = []) {
|
|
106
|
+
const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
|
|
107
|
+
if (!resolved.target) {
|
|
108
|
+
const value = searchValue(resolved.property.type.type, expression);
|
|
109
|
+
return { [property]: value ?? (0, sql_functions_13.or)() };
|
|
110
|
+
}
|
|
111
|
+
if (!('value' in expression)) {
|
|
112
|
+
const operator = (expression.operator === 'AND') ? sql_functions_1.AND : sql_functions_2.OR;
|
|
113
|
+
return { [operator]: expression.operands.map(operand => this.condition(type, property, operand, ancestors)) };
|
|
114
|
+
}
|
|
115
|
+
if (ancestors.includes(resolved.target))
|
|
116
|
+
throw new Error(`Cyclic search representation: ${property}`);
|
|
117
|
+
const branch = [...ancestors, resolved.target];
|
|
118
|
+
return {
|
|
119
|
+
[sql_functions_2.OR]: (0, class_view_1.representativeOf)(resolved.target)
|
|
120
|
+
.map(name => this.condition(type, `${property}.${String(name)}`, expression, branch))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
getParams(request, _type) {
|
|
78
124
|
for (const property of this.columns.map(property => property.name)) {
|
|
79
125
|
this.search[property] ??= '';
|
|
80
126
|
}
|
|
@@ -111,43 +157,15 @@ class Filter extends parameter_1.Parameter {
|
|
|
111
157
|
searchObject(type) {
|
|
112
158
|
const search = {};
|
|
113
159
|
const groups = [];
|
|
114
|
-
const expand = (property, expression, ancestors = []) => {
|
|
115
|
-
const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
|
|
116
|
-
if (!resolved.target) {
|
|
117
|
-
const value = searchValue(resolved.property.type.type, expression);
|
|
118
|
-
return { [property]: value ?? (0, sql_functions_13.or)() };
|
|
119
|
-
}
|
|
120
|
-
if (!('value' in expression)) {
|
|
121
|
-
const operator = (expression.operator === 'AND') ? sql_functions_1.AND : sql_functions_2.OR;
|
|
122
|
-
return { [operator]: expression.operands.map(operand => expand(property, operand, ancestors)) };
|
|
123
|
-
}
|
|
124
|
-
if (ancestors.includes(resolved.target))
|
|
125
|
-
throw new Error(`Cyclic search representation: ${property}`);
|
|
126
|
-
const branch = [...ancestors, resolved.target];
|
|
127
|
-
return {
|
|
128
|
-
[sql_functions_2.OR]: (0, class_view_1.representativeOf)(resolved.target).map(name => expand(`${property}.${String(name)}`, expression, branch))
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
160
|
for (const [property, value] of Object.entries(this.search)) {
|
|
132
161
|
if (value === '')
|
|
133
162
|
continue;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
if (!(error instanceof SyntaxError))
|
|
140
|
-
throw error;
|
|
141
|
-
search[property] = (0, sql_functions_13.or)();
|
|
142
|
-
continue;
|
|
163
|
+
const condition = this.columnCondition(type, property, value);
|
|
164
|
+
if (Object.hasOwn(condition, sql_functions_1.AND) || Object.hasOwn(condition, sql_functions_2.OR)) {
|
|
165
|
+
groups.push(condition);
|
|
143
166
|
}
|
|
144
|
-
const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
|
|
145
|
-
if (resolved.target)
|
|
146
|
-
groups.push(expand(property, expression));
|
|
147
167
|
else {
|
|
148
|
-
|
|
149
|
-
if (criterion !== undefined)
|
|
150
|
-
search[property] = criterion;
|
|
168
|
+
Object.assign(search, condition);
|
|
151
169
|
}
|
|
152
170
|
}
|
|
153
171
|
if (groups.length)
|
package/cjs/list.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Action } from '@itrocks/action';
|
|
2
2
|
import { Request } from '@itrocks/action-request';
|
|
3
3
|
import { SearchType } from '@itrocks/storage';
|
|
4
|
+
import { ListView } from './access';
|
|
4
5
|
import { Columns } from './columns';
|
|
5
6
|
import { Feed } from './feed';
|
|
6
7
|
import { Filter } from './filter';
|
|
7
8
|
import { Sort } from './sort';
|
|
8
|
-
export { listDependsOn } from './access';
|
|
9
|
+
export { listAccess, listDependsOn } from './access';
|
|
9
10
|
export type { ListAccess, ListDependencies, ListView } from './access';
|
|
10
11
|
export declare class List<T extends object = object> extends Action<T> {
|
|
11
12
|
columns: Columns<object>;
|
|
12
13
|
feed: Feed;
|
|
13
14
|
filter: Filter<object>;
|
|
14
15
|
sort: Sort<object>;
|
|
16
|
+
protected filterBar(request: Request<T>): ListView;
|
|
15
17
|
html(request: Request<T>, scope?: SearchType<T>): Promise<import("@itrocks/request-response").Response>;
|
|
16
18
|
json(request: Request<T>, scope?: SearchType<T>): Promise<import("@itrocks/core-responses").JsonResponse>;
|
|
17
19
|
}
|
package/cjs/list.html
CHANGED
|
@@ -19,25 +19,32 @@
|
|
|
19
19
|
<!--view-->{{template}}<!--end-->
|
|
20
20
|
<header>
|
|
21
21
|
<h2>{type.@output.ucFirst} list</h2>
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
<div class="list-toolbar">
|
|
23
|
+
<ul class="general actions">
|
|
24
|
+
<!--generalActions-->
|
|
25
|
+
<li class="{action}">{{template}}</li>
|
|
26
|
+
<!--end-->
|
|
27
|
+
</ul>
|
|
28
|
+
<div class="list-filter">
|
|
29
|
+
<!--filterBar-->{{template}}<!--end-->
|
|
30
|
+
</div>
|
|
31
|
+
<span class="summary">{count} elements</span>
|
|
32
|
+
<button class="add-column" hidden type="button" aria-label="Add column">+</button>
|
|
33
|
+
</div>
|
|
29
34
|
</header>
|
|
30
|
-
<form action="app://(type.@route)/list" autocomplete="off"
|
|
35
|
+
<form action="app://(type.@route)/list" autocomplete="off" data-focus-column="{focusColumn}"
|
|
36
|
+
method="post" target="main">
|
|
37
|
+
<!--filterBar--><!--formFields-->{{template}}<!--end--><!--end-->
|
|
31
38
|
<table class="objects" data-link="{type.@route}">
|
|
32
39
|
<thead>
|
|
33
40
|
<tr class="properties">
|
|
34
|
-
<th class="select" data-freeze
|
|
41
|
+
<th class="select" data-freeze><!--selection-->{{template}}<!--end-->
|
|
35
42
|
<input class="search-submit" title="Search" type="submit" value="Search">
|
|
36
43
|
</th>
|
|
37
44
|
<!--columns-->
|
|
38
45
|
<th data-property="{name}" data-reverse="{?reverse}" data-sort="{?sort}"
|
|
39
46
|
data-sortable="{sortable}">{label}
|
|
40
|
-
<input aria-label="Filter {label}" data-property-filter="{name}" name="search.{field}" value="{
|
|
47
|
+
<input aria-label="Filter {label}" data-property-filter="{name}" name="search.{field}" value="{escapedSearch}">
|
|
41
48
|
</th>
|
|
42
49
|
<!--end-->
|
|
43
50
|
</tr>
|
|
@@ -56,9 +63,11 @@
|
|
|
56
63
|
</div>
|
|
57
64
|
<footer>
|
|
58
65
|
<ul class="selection actions">
|
|
66
|
+
<!--selection--><!--footer-->{{template}}<!--end--><!--end-->
|
|
59
67
|
<!--selectionActions-->
|
|
60
68
|
<li class="{action}">{{template}}</li>
|
|
61
69
|
<!--end-->
|
|
70
|
+
<!--selection--><!--footerSummary-->{{template}}<!--end--><!--end-->
|
|
62
71
|
</ul>
|
|
63
72
|
</footer>
|
|
64
73
|
</form>
|
package/cjs/list.js
CHANGED
|
@@ -34,33 +34,36 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
34
34
|
return useValue ? value : void 0;
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.List = exports.listDependsOn = void 0;
|
|
37
|
+
exports.List = exports.listDependsOn = exports.listAccess = void 0;
|
|
38
38
|
const action_1 = require("@itrocks/action");
|
|
39
39
|
const action_2 = require("@itrocks/action");
|
|
40
40
|
const action_3 = require("@itrocks/action");
|
|
41
41
|
const route_1 = require("@itrocks/route");
|
|
42
42
|
const route_2 = require("@itrocks/route");
|
|
43
|
-
const sql_functions_1 = require("@itrocks/sql-functions");
|
|
44
|
-
const sql_functions_2 = require("@itrocks/sql-functions");
|
|
45
|
-
const sql_functions_3 = require("@itrocks/sql-functions");
|
|
46
43
|
const storage_1 = require("@itrocks/storage");
|
|
47
44
|
const storage_2 = require("@itrocks/storage");
|
|
48
45
|
const storage_3 = require("@itrocks/storage");
|
|
49
46
|
const access_1 = require("./access");
|
|
50
47
|
const access_2 = require("./access");
|
|
48
|
+
const access_3 = require("./access");
|
|
51
49
|
const columns_1 = require("./columns");
|
|
52
50
|
const columns_2 = require("./columns");
|
|
53
51
|
const feed_1 = require("./feed");
|
|
54
52
|
const filter_1 = require("./filter");
|
|
53
|
+
const filter_summary_1 = require("./filter-summary");
|
|
54
|
+
const filter_summary_2 = require("./filter-summary");
|
|
55
55
|
const persist_1 = require("./persist");
|
|
56
56
|
const persist_2 = require("./persist");
|
|
57
57
|
const projection_1 = require("./projection");
|
|
58
|
+
const search_1 = require("./search");
|
|
59
|
+
const search_2 = require("./search");
|
|
58
60
|
const selector_state_1 = require("./selector-state");
|
|
59
61
|
const selector_state_2 = require("./selector-state");
|
|
60
62
|
const session_state_1 = require("./session-state");
|
|
61
63
|
const sort_1 = require("./sort");
|
|
62
|
-
var
|
|
63
|
-
Object.defineProperty(exports, "
|
|
64
|
+
var access_4 = require("./access");
|
|
65
|
+
Object.defineProperty(exports, "listAccess", { enumerable: true, get: function () { return access_4.listAccess; } });
|
|
66
|
+
Object.defineProperty(exports, "listDependsOn", { enumerable: true, get: function () { return access_4.listDependsOn; } });
|
|
64
67
|
let List = (() => {
|
|
65
68
|
let _classDecorators = [(0, action_3.Need)('Store', 'new'), (0, route_1.Route)('/list')];
|
|
66
69
|
let _classDescriptor;
|
|
@@ -80,12 +83,19 @@ let List = (() => {
|
|
|
80
83
|
feed = new feed_1.Feed;
|
|
81
84
|
filter = new filter_1.Filter(this.columns);
|
|
82
85
|
sort = new sort_1.Sort(this.columns);
|
|
86
|
+
filterBar(request) {
|
|
87
|
+
return (0, filter_summary_2.filterSummary)(this.filter.search, (0, filter_summary_1.filterAliases)(request.type, this.columns));
|
|
88
|
+
}
|
|
83
89
|
async html(request, scope) {
|
|
84
90
|
const columns = this.columns;
|
|
85
91
|
const feed = this.feed;
|
|
86
92
|
const filter = this.filter;
|
|
87
93
|
const sort = this.sort;
|
|
88
94
|
const type = request.type;
|
|
95
|
+
const selection = (0, access_2.listSelection)();
|
|
96
|
+
const updated = await selection?.update(request);
|
|
97
|
+
if (updated)
|
|
98
|
+
return updated;
|
|
89
99
|
const prepared = await (0, session_state_1.prepareListSession)(request);
|
|
90
100
|
if (prepared)
|
|
91
101
|
return prepared;
|
|
@@ -103,23 +113,17 @@ let List = (() => {
|
|
|
103
113
|
return this.htmlResponse('', 204);
|
|
104
114
|
}
|
|
105
115
|
feed.getParams(request.request);
|
|
106
|
-
filter.getParams(request.request);
|
|
116
|
+
filter.getParams(request.request, type);
|
|
107
117
|
for (const column of columns)
|
|
108
118
|
column.search = filter.search[column.name] ?? '';
|
|
109
119
|
sort.getParams(request.request, type);
|
|
120
|
+
const activeSearch = await (0, search_2.listSearch)(request, filter, access, scope);
|
|
121
|
+
if ((0, search_1.captureListSearch)(request, activeSearch))
|
|
122
|
+
return this.htmlResponse('', 204);
|
|
110
123
|
if (!batch)
|
|
111
124
|
(0, persist_2.save)(this, request.request, type);
|
|
112
125
|
const options = feed.readOptions(filter.readOptions(sort.readOptions()));
|
|
113
|
-
const
|
|
114
|
-
// Scope values override direct user criteria; logical groups remain cumulative.
|
|
115
|
-
for (const path of Object.keys(scope ?? {})) {
|
|
116
|
-
delete filters[path];
|
|
117
|
-
}
|
|
118
|
-
const search = scope && ((scope[sql_functions_1.AND] !== undefined) || (scope[sql_functions_3.OR] !== undefined))
|
|
119
|
-
? { [sql_functions_1.AND]: [filters, scope] }
|
|
120
|
-
: Object.assign(filters, scope);
|
|
121
|
-
for (const path of (0, sql_functions_2.conditionPaths)(search))
|
|
122
|
-
await access.authorise(path);
|
|
126
|
+
const search = activeSearch.criteria;
|
|
123
127
|
for (const path of Object.keys(sort.sorted ?? {}))
|
|
124
128
|
await access.authorise(path);
|
|
125
129
|
if (batch) {
|
|
@@ -197,10 +201,14 @@ let List = (() => {
|
|
|
197
201
|
const metadata = await access.bootstrap([...columns].map(column => column.name), state.record);
|
|
198
202
|
selectorBootstrap = encodeURIComponent(JSON.stringify({ ...state, ...metadata }));
|
|
199
203
|
}
|
|
204
|
+
const focus = request.request.method === 'POST' ? request.request.data.focusListColumn : undefined;
|
|
205
|
+
const focusColumn = [...columns].find(column => column.field === focus)?.field ?? '';
|
|
200
206
|
return this.htmlTemplateResponse({
|
|
201
|
-
columns, count,
|
|
207
|
+
columns, count, filterBar: this.filterBar(request), focusColumn, generalActions, objects,
|
|
208
|
+
root: access.root, search: filter.search,
|
|
202
209
|
selectionActions, selectorBootstrap, selectorKey: (0, selector_state_2.selectorStateKey)(request), type,
|
|
203
|
-
|
|
210
|
+
selection: selectionActions.length ? await selection?.view(request, activeSearch, count) : undefined,
|
|
211
|
+
view: await (0, access_3.listView)(request)
|
|
204
212
|
}, request, __dirname + '/list.html');
|
|
205
213
|
}
|
|
206
214
|
async json(request, scope) {
|
package/cjs/projection.d.ts
CHANGED
package/cjs/projection.js
CHANGED
|
@@ -22,6 +22,7 @@ const transformer_1 = require("@itrocks/transformer");
|
|
|
22
22
|
const transformer_2 = require("@itrocks/transformer");
|
|
23
23
|
const transformer_3 = require("@itrocks/transformer");
|
|
24
24
|
const transformer_4 = require("@itrocks/transformer");
|
|
25
|
+
const filter_summary_1 = require("./filter-summary");
|
|
25
26
|
const multiple_output_1 = require("./multiple-output");
|
|
26
27
|
const dependencies = {};
|
|
27
28
|
function listRepresentationDependsOn(overrides) {
|
|
@@ -96,6 +97,9 @@ class ListColumn {
|
|
|
96
97
|
if (resolved.target && !this.multiple)
|
|
97
98
|
this.fields = representationFields(resolved.target, [], resolved.property);
|
|
98
99
|
}
|
|
100
|
+
get escapedSearch() {
|
|
101
|
+
return (0, filter_summary_1.escapeFilterText)(this.search);
|
|
102
|
+
}
|
|
99
103
|
async output(cell) {
|
|
100
104
|
if (cell.kind === 'absent')
|
|
101
105
|
return '';
|
package/cjs/search.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Request } from '@itrocks/action-request';
|
|
2
|
+
import type { SearchType } from '@itrocks/storage';
|
|
3
|
+
import type { ListAccess } from './access';
|
|
4
|
+
import type { Filter } from './filter';
|
|
5
|
+
export type ListSearch = {
|
|
6
|
+
criteria: SearchType;
|
|
7
|
+
filters: Record<string, string>;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolveListSearch(request: Request, run: (request: Request) => Promise<unknown>): Promise<ListSearch | undefined>;
|
|
10
|
+
export declare function captureListSearch(request: Request, search: ListSearch): boolean;
|
|
11
|
+
export declare function listSearch<T extends object>(request: Request<T>, filter: Filter<T>, access: ListAccess, scope?: SearchType<T>): Promise<{
|
|
12
|
+
criteria: SearchType<T>;
|
|
13
|
+
filters: Record<string, string>;
|
|
14
|
+
}>;
|
package/cjs/search.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveListSearch = resolveListSearch;
|
|
4
|
+
exports.captureListSearch = captureListSearch;
|
|
5
|
+
exports.listSearch = listSearch;
|
|
6
|
+
const sql_functions_1 = require("@itrocks/sql-functions");
|
|
7
|
+
const sql_functions_2 = require("@itrocks/sql-functions");
|
|
8
|
+
const sql_functions_3 = require("@itrocks/sql-functions");
|
|
9
|
+
// Run the real list action so application scopes and path authorisation also apply to bulk actions.
|
|
10
|
+
const lookups = new WeakMap();
|
|
11
|
+
async function resolveListSearch(request, run) {
|
|
12
|
+
const lookup = {};
|
|
13
|
+
lookups.set(request, lookup);
|
|
14
|
+
try {
|
|
15
|
+
await run(request);
|
|
16
|
+
return lookup.search;
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
lookups.delete(request);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function captureListSearch(request, search) {
|
|
23
|
+
const lookup = lookups.get(request);
|
|
24
|
+
if (!lookup)
|
|
25
|
+
return false;
|
|
26
|
+
lookup.search = search;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
async function listSearch(request, filter, access, scope) {
|
|
30
|
+
const filters = filter.searchObject(request.type);
|
|
31
|
+
// Scope values override direct user criteria; logical groups remain cumulative.
|
|
32
|
+
for (const path of Object.keys(scope ?? {}))
|
|
33
|
+
delete filters[path];
|
|
34
|
+
const criteria = scope && ((scope[sql_functions_1.AND] !== undefined) || (scope[sql_functions_2.OR] !== undefined))
|
|
35
|
+
? (Reflect.ownKeys(filters).length ? { [sql_functions_1.AND]: [filters, scope] } : scope)
|
|
36
|
+
: Object.assign(filters, scope);
|
|
37
|
+
for (const path of (0, sql_functions_3.conditionPaths)(criteria))
|
|
38
|
+
await access.authorise(path);
|
|
39
|
+
return { criteria, filters: filter.search };
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=search.js.map
|
package/cjs/session-state.d.ts
CHANGED
|
@@ -2,9 +2,15 @@ import { Request } from '@itrocks/action-request';
|
|
|
2
2
|
import { Type } from '@itrocks/class-type';
|
|
3
3
|
import { Request as ServerRequest } from '@itrocks/request-response';
|
|
4
4
|
import { Response } from '@itrocks/request-response';
|
|
5
|
+
export type ListQueryState = {
|
|
6
|
+
fields: Record<string, string>;
|
|
7
|
+
syntax?: 'logical';
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
5
10
|
export type ListState = {
|
|
6
11
|
columns?: string[];
|
|
7
12
|
filter?: Record<string, string>;
|
|
13
|
+
listQuery?: ListQueryState;
|
|
8
14
|
sort?: [string, boolean][];
|
|
9
15
|
};
|
|
10
16
|
export type ListSessionDependencies = {
|
package/cjs/session-state.js
CHANGED
|
@@ -16,7 +16,12 @@ function listSessionDependsOn(overrides) {
|
|
|
16
16
|
}
|
|
17
17
|
function listState(request, type) {
|
|
18
18
|
const state = request.session.list?.[(0, route_1.routeOf)(type)] ?? {};
|
|
19
|
-
return structuredClone({
|
|
19
|
+
return structuredClone({
|
|
20
|
+
columns: state.columns,
|
|
21
|
+
filter: state.filter,
|
|
22
|
+
...(state.listQuery ? { listQuery: state.listQuery } : {}),
|
|
23
|
+
sort: state.sort
|
|
24
|
+
});
|
|
20
25
|
}
|
|
21
26
|
function replaceListState(request, type, state) {
|
|
22
27
|
request.session.list ??= {};
|
|
@@ -35,6 +40,7 @@ function comparableListState(state) {
|
|
|
35
40
|
filter: Object.entries(state.filter ?? {})
|
|
36
41
|
.filter(([, value]) => value !== '')
|
|
37
42
|
.sort(([left], [right]) => left.localeCompare(right)),
|
|
43
|
+
listQuery: state.listQuery || undefined,
|
|
38
44
|
sort: state.sort
|
|
39
45
|
});
|
|
40
46
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function highlightColumnFilter(input: HTMLInputElement): void;
|
package/column-filter.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { build } from '@itrocks/build/build.js';
|
|
2
|
+
const bound = new WeakSet();
|
|
3
|
+
const selector = 'article[data-action="list"] > form input[data-property-filter]';
|
|
4
|
+
const measure = document.createElement('canvas').getContext('2d');
|
|
5
|
+
export function highlightColumnFilter(input) {
|
|
6
|
+
input.toggleAttribute('data-filter-value', !!input.value);
|
|
7
|
+
if (!input.value || !measure)
|
|
8
|
+
return;
|
|
9
|
+
measure.font = getComputedStyle(input).font;
|
|
10
|
+
input.style.setProperty('--list-filter-text-width', `${measure.measureText(input.value).width}px`);
|
|
11
|
+
positionHighlight(input);
|
|
12
|
+
}
|
|
13
|
+
function positionHighlight(input) {
|
|
14
|
+
input.style.setProperty('--list-filter-text-offset', `${-Math.abs(input.scrollLeft)}px`);
|
|
15
|
+
}
|
|
16
|
+
build(selector, input => {
|
|
17
|
+
if (!bound.has(input)) {
|
|
18
|
+
bound.add(input);
|
|
19
|
+
input.addEventListener('input', () => highlightColumnFilter(input));
|
|
20
|
+
input.addEventListener('scroll', () => positionHighlight(input));
|
|
21
|
+
}
|
|
22
|
+
highlightColumnFilter(input);
|
|
23
|
+
});
|
|
24
|
+
document.fonts.addEventListener('loadingdone', () => {
|
|
25
|
+
document.querySelectorAll(selector).forEach(highlightColumnFilter);
|
|
26
|
+
});
|
package/docs/dependencies.md
CHANGED
|
@@ -35,3 +35,8 @@ No callback changes the data source, mandatory record scope or path authorisatio
|
|
|
35
35
|
The full list template includes this view inside the article, after applied settings are persisted.
|
|
36
36
|
Feed pages, column JSON and column-only persistence responses do not render this view.
|
|
37
37
|
The host owns the supplied template and its data; the list does not depend on the host's view package.
|
|
38
|
+
|
|
39
|
+
`listDependsOn({ selection })` can supply a header fragment, optional `footer` and `footerSummary` fragments before
|
|
40
|
+
and after the selection actions, and a handler for updates. The view callback receives the request, effective list
|
|
41
|
+
criteria and result count. `resolveListSearch` from `@itrocks/list/search` captures the criteria from the routed HTML
|
|
42
|
+
list action, including its mandatory scope and path authorisation.
|
package/filter.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><path d="M2.25 3h13.5l-5.25 6v4.5l-3 1.5V9z" fill="none" stroke="#444" stroke-linejoin="round" stroke-width="1.5"/></svg>
|
package/list.css
CHANGED
|
@@ -3,15 +3,6 @@ html.column-reorder * {
|
|
|
3
3
|
cursor: grabbing !important;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
main > article[data-action=list] > header {
|
|
7
|
-
position: relative;
|
|
8
|
-
}
|
|
9
|
-
main > article[data-action=list] > header > .summary {
|
|
10
|
-
padding: 13px 10px 12px;
|
|
11
|
-
position: absolute;
|
|
12
|
-
right: 48px;
|
|
13
|
-
white-space: nowrap;
|
|
14
|
-
}
|
|
15
6
|
main > article[data-action=list] > form {
|
|
16
7
|
display: grid;
|
|
17
8
|
grid-template-areas: "table" "footer";
|
|
@@ -52,9 +43,6 @@ table.objects tr td, table.objects tr th {
|
|
|
52
43
|
table.objects tr td:nth-last-child(1 of :not([hidden])), table.objects tr th:nth-last-child(1 of :not([hidden])) {
|
|
53
44
|
border-right: 1px solid #d8d8d8;
|
|
54
45
|
}
|
|
55
|
-
table.objects tr.properties > .select > input[name=select] {
|
|
56
|
-
display: none;
|
|
57
|
-
}
|
|
58
46
|
table.objects > * > tr > .column-reorder {
|
|
59
47
|
--column-reorder-tint: inset 0 0 0 100vmax rgb(0 0 0 / 2%);
|
|
60
48
|
box-shadow: var(--column-reorder-tint);
|
|
@@ -71,6 +59,13 @@ table.objects > * > tr > .column-reorder.removing {
|
|
|
71
59
|
table.objects > * > tr > .column-reorder input {
|
|
72
60
|
box-shadow: var(--column-reorder-tint);
|
|
73
61
|
}
|
|
62
|
+
table.objects > tbody > tr:has(> th.select > input[name=id]:checked) > :is(th, td) {
|
|
63
|
+
background: #edf4ff;
|
|
64
|
+
}
|
|
65
|
+
table.objects > tbody > tr > th.select,
|
|
66
|
+
table.objects > tbody > tr > th.select > input[type=checkbox] {
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
}
|
|
74
69
|
table.objects > tbody > tr > td > ul {
|
|
75
70
|
display: block;
|
|
76
71
|
margin: 0;
|
|
@@ -189,24 +184,6 @@ table.objects > thead + tbody > tr:hover {
|
|
|
189
184
|
border-left: 1px solid #d8d8d8;
|
|
190
185
|
}
|
|
191
186
|
|
|
192
|
-
main > article[data-action=list] > header > .add-column {
|
|
193
|
-
background: white;
|
|
194
|
-
border: 0;
|
|
195
|
-
border-bottom: 1px solid #ccc;
|
|
196
|
-
border-left: 1px solid #ccc;
|
|
197
|
-
border-radius: 0;
|
|
198
|
-
bottom: 0;
|
|
199
|
-
cursor: pointer;
|
|
200
|
-
font-size: 16px;
|
|
201
|
-
position: absolute;
|
|
202
|
-
right: 0;
|
|
203
|
-
top: 0;
|
|
204
|
-
width: 44px;
|
|
205
|
-
}
|
|
206
|
-
main > article[data-action=list] > header > .add-column:hover {
|
|
207
|
-
background-color: #f4f4f4;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
187
|
table.objects > thead > tr.properties > th {
|
|
211
188
|
line-height: 28px;
|
|
212
189
|
padding-block: 0;
|
|
@@ -248,6 +225,18 @@ table.objects > thead > tr.properties > th > input[data-property-filter] {
|
|
|
248
225
|
margin-left: -0.6em;
|
|
249
226
|
width: calc(100% + 1.2em);
|
|
250
227
|
}
|
|
228
|
+
table.objects > thead > tr.properties > th > input[data-property-filter][data-filter-value] {
|
|
229
|
+
background-clip: content-box, border-box;
|
|
230
|
+
background-image: linear-gradient(#d5edff, #d5edff), none;
|
|
231
|
+
background-origin: content-box;
|
|
232
|
+
background-position: left var(--list-filter-text-offset, 0px) center;
|
|
233
|
+
background-repeat: no-repeat;
|
|
234
|
+
background-size: var(--list-filter-text-width, 0px) 1.2em;
|
|
235
|
+
color: #12365b;
|
|
236
|
+
}
|
|
237
|
+
table.objects > thead > tr.properties > th > input[data-property-filter][data-filter-value]:dir(rtl) {
|
|
238
|
+
background-position: right var(--list-filter-text-offset, 0px) center;
|
|
239
|
+
}
|
|
251
240
|
table.objects > thead > tr.properties > th[data-sort] > input[data-property-filter] {
|
|
252
241
|
width: calc(100% + 1.2em + 16px);
|
|
253
242
|
}
|
|
@@ -297,3 +286,98 @@ article[data-action=list] > form > .search-menu > button.reset::before {
|
|
|
297
286
|
article[data-action=list] > form > .search-menu > button:focus-visible, article[data-action=list] > form > .search-menu > button:hover {
|
|
298
287
|
background: #eee;
|
|
299
288
|
}
|
|
289
|
+
|
|
290
|
+
main > article[data-action=list] > header > .list-toolbar {
|
|
291
|
+
align-items: center;
|
|
292
|
+
border-bottom: 1px solid #ccc;
|
|
293
|
+
display: grid;
|
|
294
|
+
gap: 5px;
|
|
295
|
+
grid-template-areas: "actions filter count add";
|
|
296
|
+
grid-template-columns: auto minmax(0, 1fr) auto max-content;
|
|
297
|
+
}
|
|
298
|
+
main > article[data-action=list] > header > .list-toolbar:has(> .add-column[hidden]) {
|
|
299
|
+
grid-template-areas: "actions filter count";
|
|
300
|
+
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
301
|
+
}
|
|
302
|
+
main > article[data-action=list] > header > .list-toolbar[data-filter-row] {
|
|
303
|
+
grid-template-areas: "actions count count" "filter filter add";
|
|
304
|
+
grid-template-columns: minmax(0, 1fr) auto max-content;
|
|
305
|
+
}
|
|
306
|
+
main > article[data-action=list] > header > .list-toolbar[data-filter-row]:has(> .add-column[hidden]) {
|
|
307
|
+
grid-template-areas: "actions count" "filter filter";
|
|
308
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
309
|
+
}
|
|
310
|
+
main > article[data-action=list] > header > .list-toolbar[data-filter-row] > .general.actions {
|
|
311
|
+
flex-wrap: wrap;
|
|
312
|
+
overflow-x: auto;
|
|
313
|
+
}
|
|
314
|
+
main > article[data-action=list] > header > .list-toolbar > .add-column {
|
|
315
|
+
align-self: stretch;
|
|
316
|
+
background: white;
|
|
317
|
+
border: 0;
|
|
318
|
+
border-left: 1px solid #ccc;
|
|
319
|
+
border-radius: 0;
|
|
320
|
+
cursor: pointer;
|
|
321
|
+
font-size: 16px;
|
|
322
|
+
grid-area: add;
|
|
323
|
+
justify-self: end;
|
|
324
|
+
min-width: 44px;
|
|
325
|
+
white-space: nowrap;
|
|
326
|
+
}
|
|
327
|
+
main > article[data-action=list] > header > .list-toolbar > .add-column:hover {
|
|
328
|
+
background-color: #f4f4f4;
|
|
329
|
+
}
|
|
330
|
+
main > article[data-action=list] > header > .list-toolbar > .list-filter {
|
|
331
|
+
grid-area: filter;
|
|
332
|
+
padding-inline: 5px;
|
|
333
|
+
}
|
|
334
|
+
main > article[data-action=list] > header > .list-toolbar > .general.actions {
|
|
335
|
+
border-bottom: 0;
|
|
336
|
+
flex-wrap: nowrap;
|
|
337
|
+
grid-area: actions;
|
|
338
|
+
min-width: 0;
|
|
339
|
+
}
|
|
340
|
+
main > article[data-action=list] > header > .list-toolbar > .general.actions > li {
|
|
341
|
+
flex: none;
|
|
342
|
+
white-space: nowrap;
|
|
343
|
+
}
|
|
344
|
+
main > article[data-action=list] > header > .list-toolbar > .summary {
|
|
345
|
+
grid-area: count;
|
|
346
|
+
justify-self: end;
|
|
347
|
+
padding: 5px 10px;
|
|
348
|
+
white-space: nowrap;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
.list-filter {
|
|
352
|
+
align-items: center;
|
|
353
|
+
display: flex;
|
|
354
|
+
flex: 1;
|
|
355
|
+
gap: 0.4em;
|
|
356
|
+
min-width: 0;
|
|
357
|
+
}
|
|
358
|
+
.list-filter .list-filter-icon {
|
|
359
|
+
background: url("filter.svg") center/contain no-repeat;
|
|
360
|
+
border: 0;
|
|
361
|
+
display: inline-block;
|
|
362
|
+
flex: none;
|
|
363
|
+
height: 18px;
|
|
364
|
+
padding: 0;
|
|
365
|
+
width: 18px;
|
|
366
|
+
}
|
|
367
|
+
.list-filter button.list-filter-icon {
|
|
368
|
+
cursor: pointer;
|
|
369
|
+
}
|
|
370
|
+
.list-filter .list-filter-text {
|
|
371
|
+
border-bottom: 1px dotted #888;
|
|
372
|
+
flex: 1;
|
|
373
|
+
min-width: 0;
|
|
374
|
+
overflow-x: auto;
|
|
375
|
+
white-space: pre;
|
|
376
|
+
}
|
|
377
|
+
.list-filter code {
|
|
378
|
+
font: inherit;
|
|
379
|
+
}
|
|
380
|
+
.list-filter .list-filter-value {
|
|
381
|
+
background: #d5edff;
|
|
382
|
+
color: #12365b;
|
|
383
|
+
}
|
package/package.json
CHANGED
|
@@ -41,9 +41,14 @@
|
|
|
41
41
|
},
|
|
42
42
|
"exports": {
|
|
43
43
|
".": "./cjs/list.js",
|
|
44
|
+
"./column-filter.js": "./column-filter.js",
|
|
45
|
+
"./filter": "./cjs/filter.js",
|
|
46
|
+
"./filter-summary": "./cjs/filter-summary.js",
|
|
44
47
|
"./multiple-output": "./cjs/multiple-output.js",
|
|
48
|
+
"./parameter": "./cjs/parameter.js",
|
|
45
49
|
"./projection": "./cjs/projection.js",
|
|
46
50
|
"./property-select.js": "./property-select.js",
|
|
51
|
+
"./search": "./cjs/search.js",
|
|
47
52
|
"./selector-state": "./cjs/selector-state.js",
|
|
48
53
|
"./selector-state.js": "./selector-state.js",
|
|
49
54
|
"./session-state": "./cjs/session-state.js"
|
|
@@ -97,5 +102,5 @@
|
|
|
97
102
|
"build:front": "tsc -p src/front/tsconfig.json",
|
|
98
103
|
"test": "npm run build:cjs && node --test \"test/**/*.test.mjs\""
|
|
99
104
|
},
|
|
100
|
-
"version": "0.
|
|
105
|
+
"version": "0.27.0"
|
|
101
106
|
}
|
package/property-select.js
CHANGED
|
@@ -20,8 +20,8 @@ export class ListPropertySelect {
|
|
|
20
20
|
constructor(article, options) {
|
|
21
21
|
this.article = article;
|
|
22
22
|
this.options = options;
|
|
23
|
+
this.button = article.querySelector(':scope > header .add-column');
|
|
23
24
|
const content = this.content;
|
|
24
|
-
this.button = article.querySelector('.add-column');
|
|
25
25
|
const initial = article.dataset.selectorBootstrap
|
|
26
26
|
? JSON.parse(decodeURIComponent(article.dataset.selectorBootstrap)) : undefined;
|
|
27
27
|
const translate = (text) => initial?.translations?.[text] ?? text;
|
|
@@ -50,7 +50,7 @@ export class ListPropertySelect {
|
|
|
50
50
|
return (await this.loadColumns([path], this.paths(), signal, true)).get(path);
|
|
51
51
|
}
|
|
52
52
|
async loadColumns(paths, columns, signal, single = false) {
|
|
53
|
-
const form = this.article.querySelector('form');
|
|
53
|
+
const form = this.article.querySelector(':scope > form');
|
|
54
54
|
const table = this.article.querySelector('table.objects');
|
|
55
55
|
const rows = [...table.tBodies[0].rows];
|
|
56
56
|
const ids = rows.map(row => row.querySelector('input[name=id]').value);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function focusedColumn(form: HTMLFormElement): HTMLInputElement | undefined;
|
package/search-focus.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { build } from '@itrocks/build/build.js';
|
|
2
|
+
const bound = new WeakSet();
|
|
3
|
+
export function focusedColumn(form) {
|
|
4
|
+
const active = document.activeElement;
|
|
5
|
+
if (active instanceof HTMLInputElement && active.form === form && active.hasAttribute('data-property-filter')) {
|
|
6
|
+
return active;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
build({
|
|
10
|
+
callback: form => {
|
|
11
|
+
if (bound.has(form))
|
|
12
|
+
return;
|
|
13
|
+
bound.add(form);
|
|
14
|
+
let column;
|
|
15
|
+
form.addEventListener('submit', event => {
|
|
16
|
+
const submitter = event.submitter;
|
|
17
|
+
column = (!submitter || submitter.matches('.search-submit, .search-menu .search'))
|
|
18
|
+
? focusedColumn(form)?.name.slice('search.'.length)
|
|
19
|
+
: undefined;
|
|
20
|
+
}, { capture: true });
|
|
21
|
+
form.addEventListener('formdata', event => {
|
|
22
|
+
if (column) {
|
|
23
|
+
event.formData.set('focusListColumn', column);
|
|
24
|
+
column = undefined;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const field = form.dataset.focusColumn;
|
|
28
|
+
delete form.dataset.focusColumn;
|
|
29
|
+
if (!field)
|
|
30
|
+
return;
|
|
31
|
+
const input = form.elements.namedItem('search.' + field);
|
|
32
|
+
if (!(input instanceof HTMLInputElement))
|
|
33
|
+
return;
|
|
34
|
+
input.focus();
|
|
35
|
+
input.select();
|
|
36
|
+
},
|
|
37
|
+
priority: 2000,
|
|
38
|
+
selector: 'article[data-action="list"] > form'
|
|
39
|
+
});
|
package/search-menu.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { build } from '@itrocks/build/build.js';
|
|
2
|
+
import { focusedColumn } from './search-focus.js';
|
|
2
3
|
const bound = new WeakSet();
|
|
3
4
|
build('article[data-action="list"] > form', form => {
|
|
4
5
|
if (bound.has(form))
|
|
@@ -111,6 +112,9 @@ build('article[data-action="list"] > form', form => {
|
|
|
111
112
|
suppressClick = false;
|
|
112
113
|
if (!event.isPrimary || (event.button !== 0))
|
|
113
114
|
return;
|
|
115
|
+
if (focusedColumn(form)) {
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
}
|
|
114
118
|
pointer = { id: event.pointerId, x: event.clientX, y: event.clientY };
|
|
115
119
|
trigger.setPointerCapture(event.pointerId);
|
|
116
120
|
timer = setTimeout(() => {
|
package/toolbar.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/toolbar.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { build } from '@itrocks/build/build.js';
|
|
2
|
+
const toolbars = new Map();
|
|
3
|
+
function actionsWidth(actions) {
|
|
4
|
+
const items = [...actions.children].filter(item => item.getClientRects().length);
|
|
5
|
+
const style = getComputedStyle(actions);
|
|
6
|
+
return inlineEdges(style)
|
|
7
|
+
+ gapWidth(style, items.length)
|
|
8
|
+
+ items.reduce((width, item) => width + item.getBoundingClientRect().width, 0);
|
|
9
|
+
}
|
|
10
|
+
function filterWidth(filter) {
|
|
11
|
+
const icon = filter.querySelector('.list-filter-icon');
|
|
12
|
+
let width = inlineEdges(getComputedStyle(filter));
|
|
13
|
+
if (!icon)
|
|
14
|
+
return width;
|
|
15
|
+
const text = filter.querySelector('.list-filter-text');
|
|
16
|
+
const row = icon.parentElement;
|
|
17
|
+
width += icon.getBoundingClientRect().width;
|
|
18
|
+
const rowStyle = getComputedStyle(row);
|
|
19
|
+
if (row !== filter) {
|
|
20
|
+
width += inlineEdges(rowStyle);
|
|
21
|
+
}
|
|
22
|
+
if (text) {
|
|
23
|
+
const range = document.createRange();
|
|
24
|
+
range.selectNodeContents(text);
|
|
25
|
+
const textStyle = getComputedStyle(text);
|
|
26
|
+
const contentWidth = range.getBoundingClientRect().width + inlineEdges(textStyle);
|
|
27
|
+
width += gapWidth(rowStyle, 2) + Math.max(contentWidth, pixels(textStyle.minWidth));
|
|
28
|
+
}
|
|
29
|
+
return width;
|
|
30
|
+
}
|
|
31
|
+
function gapWidth(style, items) {
|
|
32
|
+
return Math.max(0, items - 1) * pixels(style.columnGap);
|
|
33
|
+
}
|
|
34
|
+
function inlineEdges(style) {
|
|
35
|
+
return pixels(style.paddingInlineStart) + pixels(style.paddingInlineEnd)
|
|
36
|
+
+ pixels(style.borderInlineStartWidth) + pixels(style.borderInlineEndWidth);
|
|
37
|
+
}
|
|
38
|
+
function pixels(value) {
|
|
39
|
+
return Number.parseFloat(value) || 0;
|
|
40
|
+
}
|
|
41
|
+
function watchToolbar(toolbar) {
|
|
42
|
+
if (toolbars.has(toolbar))
|
|
43
|
+
return;
|
|
44
|
+
const actions = toolbar.querySelector(':scope > .general.actions');
|
|
45
|
+
const add = toolbar.querySelector(':scope > .add-column');
|
|
46
|
+
const count = toolbar.querySelector(':scope > .summary');
|
|
47
|
+
const filter = toolbar.querySelector(':scope > .list-filter');
|
|
48
|
+
const abort = new AbortController();
|
|
49
|
+
let frame;
|
|
50
|
+
function update() {
|
|
51
|
+
frame = undefined;
|
|
52
|
+
const style = getComputedStyle(toolbar);
|
|
53
|
+
const available = toolbar.getBoundingClientRect().width - inlineEdges(style);
|
|
54
|
+
const required = actionsWidth(actions) + filterWidth(filter) + count.getBoundingClientRect().width
|
|
55
|
+
+ add.getBoundingClientRect().width + gapWidth(style, add.hidden ? 3 : 4);
|
|
56
|
+
toolbar.toggleAttribute('data-filter-row', required > available);
|
|
57
|
+
}
|
|
58
|
+
function schedule() {
|
|
59
|
+
frame ??= requestAnimationFrame(update);
|
|
60
|
+
}
|
|
61
|
+
const resize = new ResizeObserver(schedule);
|
|
62
|
+
for (const element of [toolbar, add, count, ...actions.children]) {
|
|
63
|
+
resize.observe(element);
|
|
64
|
+
}
|
|
65
|
+
const mutations = new MutationObserver(schedule);
|
|
66
|
+
mutations.observe(toolbar, { attributeFilter: ['hidden'], characterData: true, childList: true, subtree: true });
|
|
67
|
+
for (const event of ['focusin', 'focusout', 'input']) {
|
|
68
|
+
toolbar.addEventListener(event, schedule, { signal: abort.signal });
|
|
69
|
+
}
|
|
70
|
+
document.fonts.addEventListener('loadingdone', schedule, { signal: abort.signal });
|
|
71
|
+
toolbars.set(toolbar, () => {
|
|
72
|
+
if (frame !== undefined) {
|
|
73
|
+
cancelAnimationFrame(frame);
|
|
74
|
+
}
|
|
75
|
+
abort.abort();
|
|
76
|
+
mutations.disconnect();
|
|
77
|
+
resize.disconnect();
|
|
78
|
+
});
|
|
79
|
+
update();
|
|
80
|
+
}
|
|
81
|
+
build('article[data-action="list"] > header > .list-toolbar', watchToolbar);
|
|
82
|
+
new MutationObserver(() => {
|
|
83
|
+
for (const [toolbar, dispose] of toolbars) {
|
|
84
|
+
if (toolbar.isConnected)
|
|
85
|
+
continue;
|
|
86
|
+
dispose();
|
|
87
|
+
toolbars.delete(toolbar);
|
|
88
|
+
}
|
|
89
|
+
}).observe(document.body, { childList: true, subtree: true });
|