@itrocks/list 0.25.1 → 0.26.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/build.js +1 -1
- package/cjs/access.d.ts +16 -0
- package/cjs/access.js +4 -0
- package/cjs/list.html +3 -1
- package/cjs/list.js +15 -16
- package/cjs/search.d.ts +14 -0
- package/cjs/search.js +41 -0
- package/docs/dependencies.md +5 -0
- package/list.css +7 -3
- package/package.json +2 -1
package/build.js
CHANGED
|
@@ -62,7 +62,7 @@ build('article[data-action="list"] > form > table.objects', table => {
|
|
|
62
62
|
}));
|
|
63
63
|
table.addEventListener('click', event => {
|
|
64
64
|
const element = event.target;
|
|
65
|
-
if (!(element instanceof HTMLElement) || element.closest('input, button'))
|
|
65
|
+
if (!(element instanceof HTMLElement) || element.closest('input, button, label'))
|
|
66
66
|
return;
|
|
67
67
|
const cell = element.closest('table, th');
|
|
68
68
|
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
|
package/cjs/list.html
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<table class="objects" data-link="{type.@route}">
|
|
32
32
|
<thead>
|
|
33
33
|
<tr class="properties">
|
|
34
|
-
<th class="select" data-freeze
|
|
34
|
+
<th class="select" data-freeze><!--selection-->{{template}}<!--end-->
|
|
35
35
|
<input class="search-submit" title="Search" type="submit" value="Search">
|
|
36
36
|
</th>
|
|
37
37
|
<!--columns-->
|
|
@@ -56,9 +56,11 @@
|
|
|
56
56
|
</div>
|
|
57
57
|
<footer>
|
|
58
58
|
<ul class="selection actions">
|
|
59
|
+
<!--selection--><!--footer-->{{template}}<!--end--><!--end-->
|
|
59
60
|
<!--selectionActions-->
|
|
60
61
|
<li class="{action}">{{template}}</li>
|
|
61
62
|
<!--end-->
|
|
63
|
+
<!--selection--><!--footerSummary-->{{template}}<!--end--><!--end-->
|
|
62
64
|
</ul>
|
|
63
65
|
</footer>
|
|
64
66
|
</form>
|
package/cjs/list.js
CHANGED
|
@@ -40,14 +40,12 @@ 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");
|
|
@@ -55,12 +53,14 @@ const filter_1 = require("./filter");
|
|
|
55
53
|
const persist_1 = require("./persist");
|
|
56
54
|
const persist_2 = require("./persist");
|
|
57
55
|
const projection_1 = require("./projection");
|
|
56
|
+
const search_1 = require("./search");
|
|
57
|
+
const search_2 = require("./search");
|
|
58
58
|
const selector_state_1 = require("./selector-state");
|
|
59
59
|
const selector_state_2 = require("./selector-state");
|
|
60
60
|
const session_state_1 = require("./session-state");
|
|
61
61
|
const sort_1 = require("./sort");
|
|
62
|
-
var
|
|
63
|
-
Object.defineProperty(exports, "listDependsOn", { enumerable: true, get: function () { return
|
|
62
|
+
var access_4 = require("./access");
|
|
63
|
+
Object.defineProperty(exports, "listDependsOn", { enumerable: true, get: function () { return access_4.listDependsOn; } });
|
|
64
64
|
let List = (() => {
|
|
65
65
|
let _classDecorators = [(0, action_3.Need)('Store', 'new'), (0, route_1.Route)('/list')];
|
|
66
66
|
let _classDescriptor;
|
|
@@ -86,6 +86,10 @@ let List = (() => {
|
|
|
86
86
|
const filter = this.filter;
|
|
87
87
|
const sort = this.sort;
|
|
88
88
|
const type = request.type;
|
|
89
|
+
const selection = (0, access_2.listSelection)();
|
|
90
|
+
const updated = await selection?.update(request);
|
|
91
|
+
if (updated)
|
|
92
|
+
return updated;
|
|
89
93
|
const prepared = await (0, session_state_1.prepareListSession)(request);
|
|
90
94
|
if (prepared)
|
|
91
95
|
return prepared;
|
|
@@ -107,19 +111,13 @@ let List = (() => {
|
|
|
107
111
|
for (const column of columns)
|
|
108
112
|
column.search = filter.search[column.name] ?? '';
|
|
109
113
|
sort.getParams(request.request, type);
|
|
114
|
+
const activeSearch = await (0, search_2.listSearch)(request, filter, access, scope);
|
|
115
|
+
if ((0, search_1.captureListSearch)(request, activeSearch))
|
|
116
|
+
return this.htmlResponse('', 204);
|
|
110
117
|
if (!batch)
|
|
111
118
|
(0, persist_2.save)(this, request.request, type);
|
|
112
119
|
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);
|
|
120
|
+
const search = activeSearch.criteria;
|
|
123
121
|
for (const path of Object.keys(sort.sorted ?? {}))
|
|
124
122
|
await access.authorise(path);
|
|
125
123
|
if (batch) {
|
|
@@ -200,7 +198,8 @@ let List = (() => {
|
|
|
200
198
|
return this.htmlTemplateResponse({
|
|
201
199
|
columns, count, generalActions, objects, root: access.root, search: filter.search,
|
|
202
200
|
selectionActions, selectorBootstrap, selectorKey: (0, selector_state_2.selectorStateKey)(request), type,
|
|
203
|
-
|
|
201
|
+
selection: selectionActions.length ? await selection?.view(request, activeSearch, count) : undefined,
|
|
202
|
+
view: await (0, access_3.listView)(request)
|
|
204
203
|
}, request, __dirname + '/list.html');
|
|
205
204
|
}
|
|
206
205
|
async json(request, scope) {
|
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/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/list.css
CHANGED
|
@@ -52,9 +52,6 @@ table.objects tr td, table.objects tr th {
|
|
|
52
52
|
table.objects tr td:nth-last-child(1 of :not([hidden])), table.objects tr th:nth-last-child(1 of :not([hidden])) {
|
|
53
53
|
border-right: 1px solid #d8d8d8;
|
|
54
54
|
}
|
|
55
|
-
table.objects tr.properties > .select > input[name=select] {
|
|
56
|
-
display: none;
|
|
57
|
-
}
|
|
58
55
|
table.objects > * > tr > .column-reorder {
|
|
59
56
|
--column-reorder-tint: inset 0 0 0 100vmax rgb(0 0 0 / 2%);
|
|
60
57
|
box-shadow: var(--column-reorder-tint);
|
|
@@ -71,6 +68,13 @@ table.objects > * > tr > .column-reorder.removing {
|
|
|
71
68
|
table.objects > * > tr > .column-reorder input {
|
|
72
69
|
box-shadow: var(--column-reorder-tint);
|
|
73
70
|
}
|
|
71
|
+
table.objects > tbody > tr:has(> th.select > input[name=id]:checked) > :is(th, td) {
|
|
72
|
+
background: #edf4ff;
|
|
73
|
+
}
|
|
74
|
+
table.objects > tbody > tr > th.select,
|
|
75
|
+
table.objects > tbody > tr > th.select > input[type=checkbox] {
|
|
76
|
+
cursor: pointer;
|
|
77
|
+
}
|
|
74
78
|
table.objects > tbody > tr > td > ul {
|
|
75
79
|
display: block;
|
|
76
80
|
margin: 0;
|
package/package.json
CHANGED
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"./multiple-output": "./cjs/multiple-output.js",
|
|
45
45
|
"./projection": "./cjs/projection.js",
|
|
46
46
|
"./property-select.js": "./property-select.js",
|
|
47
|
+
"./search": "./cjs/search.js",
|
|
47
48
|
"./selector-state": "./cjs/selector-state.js",
|
|
48
49
|
"./selector-state.js": "./selector-state.js",
|
|
49
50
|
"./session-state": "./cjs/session-state.js"
|
|
@@ -97,5 +98,5 @@
|
|
|
97
98
|
"build:front": "tsc -p src/front/tsconfig.json",
|
|
98
99
|
"test": "npm run build:cjs && node --test \"test/**/*.test.mjs\""
|
|
99
100
|
},
|
|
100
|
-
"version": "0.
|
|
101
|
+
"version": "0.26.0"
|
|
101
102
|
}
|