@itrocks/list 0.29.0 → 0.32.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 +8 -2
- package/build.js +58 -6
- package/cjs/access.d.ts +15 -0
- package/cjs/access.js +4 -0
- package/cjs/column-widths.d.ts +12 -0
- package/cjs/column-widths.js +54 -0
- package/cjs/columns.d.ts +14 -2
- package/cjs/columns.js +44 -9
- package/cjs/filter.d.ts +2 -1
- package/cjs/filter.js +22 -14
- package/cjs/list.d.ts +4 -1
- package/cjs/list.html +4 -2
- package/cjs/list.js +55 -28
- package/cjs/projection.d.ts +5 -2
- package/cjs/projection.js +10 -1
- package/cjs/search.d.ts +2 -1
- package/cjs/search.js +2 -2
- package/cjs/session-state.d.ts +1 -0
- package/cjs/session-state.js +5 -0
- package/docs/dependencies.md +15 -0
- package/list.css +6 -0
- package/package.json +1 -1
- package/cjs/search-expression.d.ts +0 -9
- package/cjs/search-expression.js +0 -93
package/README.md
CHANGED
|
@@ -363,6 +363,12 @@ The same projection is used when reloading the list or adding an individual comp
|
|
|
363
363
|
rendered values, mandatory row scope, partial selection, removal and session restoration. It creates and cleans up
|
|
364
364
|
its own temporary database and server using the existing selector integration recipe.
|
|
365
365
|
|
|
366
|
+
## Column widths
|
|
367
|
+
|
|
368
|
+
Drag the edge of a column heading to set its width. Double-click the same edge to return to automatic sizing.
|
|
369
|
+
List actions can override `canResizeColumns(request)` to disable the gesture while displaying saved widths.
|
|
370
|
+
Only explicit pixel widths are stored in `columnWidths`, by property path. Removing a column clears its width.
|
|
371
|
+
|
|
366
372
|
## Session state integration
|
|
367
373
|
|
|
368
374
|
`@itrocks/list/session-state` exposes the settings independently of rendering:
|
|
@@ -376,8 +382,8 @@ replaceListState(request.request, request.type, settings)
|
|
|
376
382
|
replaceListState(request.request, request.type)
|
|
377
383
|
```
|
|
378
384
|
|
|
379
|
-
`listState(request: ServerRequest, type: Type): ListState` returns a deep copy of columns,
|
|
380
|
-
and ordered sort tuples.
|
|
385
|
+
`listState(request: ServerRequest, type: Type): ListState` returns a deep copy of columns, explicit column widths,
|
|
386
|
+
filters and ordered sort tuples.
|
|
381
387
|
`replaceListState(request, type, state?)` replaces the complete session entry;
|
|
382
388
|
omitting state restores reflected defaults on the next render.
|
|
383
389
|
Neither function queries business rows or changes mandatory scopes.
|
package/build.js
CHANGED
|
@@ -2,6 +2,7 @@ import { build } from '@itrocks/build/build.js';
|
|
|
2
2
|
import { TableColumnAdd } from '@itrocks/table/column-add.js';
|
|
3
3
|
import { TableColumnReorderFreeze } from '@itrocks/table/column-reorder-freeze.js';
|
|
4
4
|
import { TableColumnReorder } from '@itrocks/table/column-reorder.js';
|
|
5
|
+
import { TableColumnResize } from '@itrocks/table/column-resize.js';
|
|
5
6
|
import { TableFeed } from '@itrocks/table/feed.js';
|
|
6
7
|
import { TableFreeze } from '@itrocks/table/freeze.js';
|
|
7
8
|
import { TableFreezeInheritBackground } from '@itrocks/table/freeze/inherit-background.js';
|
|
@@ -13,16 +14,28 @@ import './column-filter.js';
|
|
|
13
14
|
import './search-focus.js';
|
|
14
15
|
import './toolbar.js';
|
|
15
16
|
build('article[data-action="list"] > form > table.objects', table => {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const headers = [...table.querySelectorAll('thead th[data-property]')];
|
|
18
|
+
const persistedWidths = new Map();
|
|
19
|
+
const pendingWidths = new Map();
|
|
20
|
+
let persistedColumns = headers.map(header => header.dataset.property).join(',');
|
|
21
|
+
for (const header of headers) {
|
|
22
|
+
if (header.dataset.columnWidth) {
|
|
23
|
+
persistedWidths.set(header.dataset.property, Number(header.dataset.columnWidth));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
18
26
|
let saving = Promise.resolve();
|
|
19
|
-
const request = (query, signal) => {
|
|
27
|
+
const request = (query, signal, method = 'GET') => {
|
|
20
28
|
const form = table.closest('form');
|
|
21
|
-
const result = saving.then(() => fetch(`${form.action}?${query}`, { keepalive: true, signal }));
|
|
29
|
+
const result = saving.then(() => fetch(`${form.action}?${query}`, { keepalive: true, method, signal }));
|
|
22
30
|
saving = result.then(() => { }, () => { });
|
|
23
31
|
void result.then(response => {
|
|
24
32
|
if (response.ok && query.has('columns') && (query.get('columns') !== persistedColumns)) {
|
|
25
33
|
persistedColumns = query.get('columns');
|
|
34
|
+
const paths = new Set(persistedColumns.split(','));
|
|
35
|
+
for (const path of persistedWidths.keys()) {
|
|
36
|
+
if (!paths.has(path))
|
|
37
|
+
persistedWidths.delete(path);
|
|
38
|
+
}
|
|
26
39
|
table.dispatchEvent(new CustomEvent('itrocks:list-change', { bubbles: true }));
|
|
27
40
|
}
|
|
28
41
|
}, () => { });
|
|
@@ -39,6 +52,45 @@ build('article[data-action="list"] > form > table.objects', table => {
|
|
|
39
52
|
throw new Error('Unable to save columns');
|
|
40
53
|
});
|
|
41
54
|
};
|
|
55
|
+
const saveWidth = (header, width) => {
|
|
56
|
+
const path = header.dataset.property;
|
|
57
|
+
const query = new URLSearchParams({ resizeColumn: path, columnWidth: String(width) });
|
|
58
|
+
const result = request(query, undefined, 'POST');
|
|
59
|
+
pendingWidths.set(path, result);
|
|
60
|
+
void result.then(response => {
|
|
61
|
+
if (response.status !== 204)
|
|
62
|
+
throw new Error('Unable to save column width');
|
|
63
|
+
const previous = persistedWidths.get(path) ?? 'auto';
|
|
64
|
+
if (width === 'auto')
|
|
65
|
+
persistedWidths.delete(path);
|
|
66
|
+
else
|
|
67
|
+
persistedWidths.set(path, width);
|
|
68
|
+
if (width !== previous) {
|
|
69
|
+
table.dispatchEvent(new CustomEvent('itrocks:list-change', { bubbles: true }));
|
|
70
|
+
}
|
|
71
|
+
}).catch(error => {
|
|
72
|
+
if (pendingWidths.get(path) === result) {
|
|
73
|
+
resize.setWidth(header, persistedWidths.get(path) ?? 'auto');
|
|
74
|
+
}
|
|
75
|
+
console.error(error);
|
|
76
|
+
}).finally(() => {
|
|
77
|
+
if (pendingWidths.get(path) === result)
|
|
78
|
+
pendingWidths.delete(path);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const resize = new TableColumnResize({
|
|
82
|
+
identify: header => header.dataset.property,
|
|
83
|
+
isInResizeZone: (header, y) => {
|
|
84
|
+
const filter = header.querySelector(':scope > input[data-property-filter]');
|
|
85
|
+
if (!filter)
|
|
86
|
+
return true;
|
|
87
|
+
const bottom = filter.getBoundingClientRect().top;
|
|
88
|
+
const lineHeight = parseFloat(getComputedStyle(header).lineHeight);
|
|
89
|
+
return (y < bottom) && (!Number.isFinite(lineHeight) || (y >= bottom - lineHeight));
|
|
90
|
+
},
|
|
91
|
+
isResizable: header => table.hasAttribute('data-column-resize') && (header.dataset.property !== undefined),
|
|
92
|
+
onChange: saveWidth
|
|
93
|
+
});
|
|
42
94
|
const tableColumnReorder = new TableColumnReorder({
|
|
43
95
|
isReorderable: header => header.dataset.property !== undefined,
|
|
44
96
|
onRemove: () => saveColumns(),
|
|
@@ -55,8 +107,8 @@ build('article[data-action="list"] > form > table.objects', table => {
|
|
|
55
107
|
const addition = new TableColumnAdd({ identify: header => header.dataset.property });
|
|
56
108
|
const instance = tableByElement(table, {
|
|
57
109
|
plugins: [
|
|
58
|
-
tableColumnReorder, addition, TableColumnReorderFreeze, TableFeed, TableFreeze,
|
|
59
|
-
TableFreezeInheritBorder, tableLink
|
|
110
|
+
tableColumnReorder, resize, addition, TableColumnReorderFreeze, TableFeed, TableFreeze,
|
|
111
|
+
TableFreezeInheritBackground, TableFreezeInheritBorder, tableLink
|
|
60
112
|
]
|
|
61
113
|
});
|
|
62
114
|
table.dispatchEvent(new CustomEvent('itrocks:list-ready', {
|
package/cjs/access.d.ts
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { Request } from '@itrocks/action-request';
|
|
2
|
+
import type { Type } from '@itrocks/class-type';
|
|
2
3
|
import type { StateRecord } from '@itrocks/property-select';
|
|
4
|
+
import type { ResolvedPropertyPath } from '@itrocks/reflect-path';
|
|
3
5
|
import type { Response } from '@itrocks/request-response';
|
|
6
|
+
import type { ProjectionCell } from '@itrocks/storage';
|
|
7
|
+
import type { Sort } from '@itrocks/storage';
|
|
8
|
+
import type { ListColumn } from './projection';
|
|
4
9
|
import type { ListSearch } from './search';
|
|
5
10
|
export type ListAccess = {
|
|
6
11
|
authorise(path: string): Promise<void>;
|
|
7
12
|
bootstrap?(paths: string[], state: StateRecord): Promise<object>;
|
|
8
13
|
root?: string;
|
|
9
14
|
};
|
|
15
|
+
export type ListColumnOutput = (column: ListColumn, cell: ProjectionCell, property: ListColumn['property']) => string | undefined | Promise<string | undefined>;
|
|
16
|
+
export type ListColumnsView = {
|
|
17
|
+
objectFields?: (column: ListColumn) => readonly string[] | undefined;
|
|
18
|
+
output?: ListColumnOutput;
|
|
19
|
+
searchOnOwner?: (property: ResolvedPropertyPath) => boolean;
|
|
20
|
+
sort?: Sort;
|
|
21
|
+
view?: ListView;
|
|
22
|
+
};
|
|
10
23
|
export type ListDependencies = {
|
|
11
24
|
access: (request: Request) => Promise<ListAccess>;
|
|
25
|
+
columnsView?: (type: Type, primarySort?: Readonly<[string, boolean]>) => ListColumnsView | undefined;
|
|
12
26
|
view: (request: Request) => Promise<ListView | undefined>;
|
|
13
27
|
selection?: {
|
|
14
28
|
update: (request: Request) => Promise<Response | undefined>;
|
|
@@ -32,3 +46,4 @@ export declare function listSelection(): {
|
|
|
32
46
|
footerSummary?: ListView;
|
|
33
47
|
}>;
|
|
34
48
|
} | undefined;
|
|
49
|
+
export declare function listColumnsView(type: Type, primarySort?: Readonly<[string, boolean]>): ListColumnsView | undefined;
|
package/cjs/access.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.listAccess = listAccess;
|
|
|
4
4
|
exports.listDependsOn = listDependsOn;
|
|
5
5
|
exports.listView = listView;
|
|
6
6
|
exports.listSelection = listSelection;
|
|
7
|
+
exports.listColumnsView = listColumnsView;
|
|
7
8
|
const dependencies = {
|
|
8
9
|
access: async () => ({ authorise: async () => { } }),
|
|
9
10
|
view: async () => undefined
|
|
@@ -20,4 +21,7 @@ function listView(request) {
|
|
|
20
21
|
function listSelection() {
|
|
21
22
|
return dependencies.selection;
|
|
22
23
|
}
|
|
24
|
+
function listColumnsView(type, primarySort) {
|
|
25
|
+
return dependencies.columnsView?.(type, primarySort);
|
|
26
|
+
}
|
|
23
27
|
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Request } from '@itrocks/request-response';
|
|
2
|
+
import type { Columns } from './columns';
|
|
3
|
+
import { Parameter } from './parameter';
|
|
4
|
+
export declare function isColumnWidth(width: unknown): width is number;
|
|
5
|
+
export declare class ColumnWidths<T extends object> extends Parameter {
|
|
6
|
+
private readonly columns;
|
|
7
|
+
private widths;
|
|
8
|
+
constructor(columns: Columns<T>);
|
|
9
|
+
getParams(request: Request): boolean;
|
|
10
|
+
serialize(): Record<string, number> | undefined;
|
|
11
|
+
unserialize(data: unknown): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColumnWidths = void 0;
|
|
4
|
+
exports.isColumnWidth = isColumnWidth;
|
|
5
|
+
const parameter_1 = require("./parameter");
|
|
6
|
+
function isColumnWidth(width) {
|
|
7
|
+
return (typeof width === 'number') && Number.isSafeInteger(width) && (width > 0);
|
|
8
|
+
}
|
|
9
|
+
class ColumnWidths extends parameter_1.Parameter {
|
|
10
|
+
columns;
|
|
11
|
+
widths = new Map();
|
|
12
|
+
constructor(columns) {
|
|
13
|
+
super();
|
|
14
|
+
this.columns = columns;
|
|
15
|
+
}
|
|
16
|
+
getParams(request) {
|
|
17
|
+
const paths = new Set(this.columns.map(column => column.name));
|
|
18
|
+
const { columnWidth, resizeColumn } = request.data;
|
|
19
|
+
if (resizeColumn !== undefined || columnWidth !== undefined) {
|
|
20
|
+
if ((typeof resizeColumn !== 'string') || !paths.has(resizeColumn))
|
|
21
|
+
return false;
|
|
22
|
+
if (columnWidth === 'auto') {
|
|
23
|
+
this.widths.delete(resizeColumn);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if ((typeof columnWidth !== 'string') || !/^\d+$/.test(columnWidth))
|
|
27
|
+
return false;
|
|
28
|
+
const width = Number(columnWidth);
|
|
29
|
+
if (!isColumnWidth(width))
|
|
30
|
+
return false;
|
|
31
|
+
this.widths.set(resizeColumn, width);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const path of this.widths.keys()) {
|
|
35
|
+
if (!paths.has(path)) {
|
|
36
|
+
this.widths.delete(path);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const column of this.columns) {
|
|
40
|
+
column.width = this.widths.get(column.name);
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
serialize() {
|
|
45
|
+
return this.widths.size ? Object.fromEntries(this.widths) : undefined;
|
|
46
|
+
}
|
|
47
|
+
unserialize(data) {
|
|
48
|
+
this.widths = new Map((data && (typeof data === 'object') && !Array.isArray(data))
|
|
49
|
+
? Object.entries(data).filter((entry) => isColumnWidth(entry[1]))
|
|
50
|
+
: []);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ColumnWidths = ColumnWidths;
|
|
54
|
+
//# sourceMappingURL=column-widths.js.map
|
package/cjs/columns.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Type } from '@itrocks/class-type';
|
|
2
2
|
import { Request } from '@itrocks/request-response';
|
|
3
|
+
import type { Identifier } from '@itrocks/storage';
|
|
3
4
|
import { Option } from '@itrocks/storage';
|
|
4
5
|
import { ProjectionResult } from '@itrocks/storage';
|
|
5
6
|
import { SearchType } from '@itrocks/storage';
|
|
7
|
+
import type { ListAccess } from './access';
|
|
8
|
+
import type { ListColumnOutput } from './access';
|
|
9
|
+
import type { ListColumnsView } from './access';
|
|
6
10
|
import { Parameter } from './parameter';
|
|
7
11
|
import { ListColumn } from './projection';
|
|
12
|
+
type ColumnObject = (column: ListColumn, id: Identifier) => object | undefined;
|
|
8
13
|
export declare class Columns<T extends object> extends Parameter implements Iterable<ListColumn> {
|
|
9
14
|
private configured;
|
|
10
15
|
properties: ListColumn[];
|
|
@@ -12,8 +17,8 @@ export declare class Columns<T extends object> extends Parameter implements Iter
|
|
|
12
17
|
getParams(request: Request, type: Type<T>): void;
|
|
13
18
|
get length(): number;
|
|
14
19
|
map<R>(callback: (value: ListColumn) => R): R[];
|
|
15
|
-
projected(result: ProjectionResult): Promise<{
|
|
16
|
-
id:
|
|
20
|
+
projected(result: ProjectionResult, output?: ListColumnOutput, objectOf?: ColumnObject): Promise<{
|
|
21
|
+
id: Identifier;
|
|
17
22
|
properties: {
|
|
18
23
|
outputOptionalContainer: string;
|
|
19
24
|
}[];
|
|
@@ -24,4 +29,11 @@ export declare class Columns<T extends object> extends Parameter implements Iter
|
|
|
24
29
|
unserialize(data: string[], type: Type<T>): void;
|
|
25
30
|
unshift(property: ListColumn): number;
|
|
26
31
|
}
|
|
32
|
+
export declare function projectColumnOutput<T extends object>(type: Type<T>, source: Columns<T> | readonly ListColumn[], search: SearchType<T>, options: Option[], access: ListAccess, view?: ListColumnsView): Promise<{
|
|
33
|
+
id: Identifier;
|
|
34
|
+
properties: {
|
|
35
|
+
outputOptionalContainer: string;
|
|
36
|
+
}[];
|
|
37
|
+
}[]>;
|
|
27
38
|
export declare function projectColumns<T extends object>(type: Type<T>, columns: readonly ListColumn[], search: SearchType<T>, options: Option[]): Promise<ProjectionResult<T>>;
|
|
39
|
+
export {};
|
package/cjs/columns.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Columns = void 0;
|
|
4
|
+
exports.projectColumnOutput = projectColumnOutput;
|
|
4
5
|
exports.projectColumns = projectColumns;
|
|
5
6
|
const list_properties_1 = require("@itrocks/list-properties");
|
|
6
7
|
const storage_1 = require("@itrocks/storage");
|
|
@@ -42,15 +43,8 @@ class Columns extends parameter_1.Parameter {
|
|
|
42
43
|
map(callback) {
|
|
43
44
|
return this.properties.map(callback);
|
|
44
45
|
}
|
|
45
|
-
async projected(result) {
|
|
46
|
-
|
|
47
|
-
|| (result.columns.length !== this.length)) {
|
|
48
|
-
throw new Error('Projection columns do not match the list');
|
|
49
|
-
}
|
|
50
|
-
return Promise.all(result.rows.map(async (row) => ({
|
|
51
|
-
id: row.rootId,
|
|
52
|
-
properties: await Promise.all(row.cells.map(async (cell, index) => ({ outputOptionalContainer: await this.properties[index].output(cell) })))
|
|
53
|
-
})));
|
|
46
|
+
async projected(result, output, objectOf) {
|
|
47
|
+
return renderProjectedRows(result, this.properties, output, objectOf);
|
|
54
48
|
}
|
|
55
49
|
readOptions(options = new Array) {
|
|
56
50
|
return options;
|
|
@@ -77,6 +71,34 @@ class Columns extends parameter_1.Parameter {
|
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
exports.Columns = Columns;
|
|
74
|
+
async function projectColumnOutput(type, source, search, options, access, view) {
|
|
75
|
+
const columns = [...source];
|
|
76
|
+
const objectColumns = new Set();
|
|
77
|
+
const authorised = new Set();
|
|
78
|
+
for (const column of columns) {
|
|
79
|
+
const fields = view?.objectFields?.(column);
|
|
80
|
+
if (!fields)
|
|
81
|
+
continue;
|
|
82
|
+
objectColumns.add(column);
|
|
83
|
+
for (const field of fields) {
|
|
84
|
+
if (authorised.has(field))
|
|
85
|
+
continue;
|
|
86
|
+
await access.authorise(field);
|
|
87
|
+
authorised.add(field);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const result = await projectColumns(type, columns, search, options);
|
|
91
|
+
const objects = objectColumns.size && result.rows.length
|
|
92
|
+
? await (0, storage_1.dataSource)().search(type, search, [new storage_2.Identifiers(result.rows.map(row => row.rootId))])
|
|
93
|
+
: [];
|
|
94
|
+
const byId = new Map(objects.map(object => [String(object.id), object]));
|
|
95
|
+
const objectOf = objectColumns.size
|
|
96
|
+
? (column, id) => objectColumns.has(column) ? byId.get(String(id)) : undefined
|
|
97
|
+
: undefined;
|
|
98
|
+
return 'projected' in source
|
|
99
|
+
? source.projected(result, view?.output, objectOf)
|
|
100
|
+
: renderProjectedRows(result, columns, view?.output, objectOf);
|
|
101
|
+
}
|
|
80
102
|
async function projectColumns(type, columns, search, options) {
|
|
81
103
|
const singular = columns.filter(column => !column.multiple);
|
|
82
104
|
const selections = singular.map(column => column.selection());
|
|
@@ -163,4 +185,17 @@ async function projectColumns(type, columns, search, options) {
|
|
|
163
185
|
}))
|
|
164
186
|
};
|
|
165
187
|
}
|
|
188
|
+
function renderProjectedRows(result, columns, output, objectOf) {
|
|
189
|
+
if (result.columns.some((column, index) => column.path !== columns[index]?.name)
|
|
190
|
+
|| (result.columns.length !== columns.length)) {
|
|
191
|
+
throw new Error('Projection columns do not match the list');
|
|
192
|
+
}
|
|
193
|
+
return Promise.all(result.rows.map(async (row) => ({
|
|
194
|
+
id: row.rootId,
|
|
195
|
+
properties: await Promise.all(columns.map(async (column, index) => {
|
|
196
|
+
const object = objectOf?.(column, row.rootId);
|
|
197
|
+
return { outputOptionalContainer: await column.output(row.cells[index], output, object) };
|
|
198
|
+
}))
|
|
199
|
+
})));
|
|
200
|
+
}
|
|
166
201
|
//# sourceMappingURL=columns.js.map
|
package/cjs/filter.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Request } from '@itrocks/request-response';
|
|
|
3
3
|
import { Option } from '@itrocks/storage';
|
|
4
4
|
import { SearchType } from '@itrocks/storage';
|
|
5
5
|
import { SearchExpression } from './front/search-expression';
|
|
6
|
+
import type { ListColumnsView } from './access';
|
|
6
7
|
import { Columns } from './columns';
|
|
7
8
|
import { Parameter } from './parameter';
|
|
8
9
|
type Search = {
|
|
@@ -16,7 +17,7 @@ export declare class Filter<T extends object> extends Parameter {
|
|
|
16
17
|
protected condition(type: Type, property: string, expression: SearchExpression, ancestors?: readonly Type[]): SearchType;
|
|
17
18
|
getParams(request: Request, _type?: Type): void;
|
|
18
19
|
readOptions(options?: Option[]): Option[];
|
|
19
|
-
searchObject(type: Type): any;
|
|
20
|
+
searchObject(type: Type, searchOnOwner?: ListColumnsView['searchOnOwner']): any;
|
|
20
21
|
serialize(): Search;
|
|
21
22
|
unserialize(data: Search): void;
|
|
22
23
|
}
|
package/cjs/filter.js
CHANGED
|
@@ -124,35 +124,40 @@ class Filter extends parameter_1.Parameter {
|
|
|
124
124
|
expression = (0, search_expression_2.searchExpression)(value);
|
|
125
125
|
}
|
|
126
126
|
catch (error) {
|
|
127
|
-
if (!(error instanceof SyntaxError))
|
|
127
|
+
if (!(error instanceof SyntaxError)) {
|
|
128
128
|
throw error;
|
|
129
|
-
|
|
129
|
+
}
|
|
130
|
+
return property ? { [property]: (0, sql_functions_15.or)() } : { [sql_functions_2.OR]: [] };
|
|
130
131
|
}
|
|
131
132
|
return this.condition(type, property, expression);
|
|
132
133
|
}
|
|
133
134
|
condition(type, property, expression, ancestors = []) {
|
|
134
|
-
const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
|
|
135
|
-
if (!resolved.target) {
|
|
135
|
+
const resolved = property ? (0, reflect_path_1.resolvePropertyPath)(type, property) : undefined;
|
|
136
|
+
if (resolved && !resolved.target) {
|
|
136
137
|
const value = searchValue(scalarType(resolved.property.type), expression);
|
|
137
|
-
if (value === undefined && !ancestors.length)
|
|
138
|
+
if ((value === undefined) && !ancestors.length) {
|
|
138
139
|
return {};
|
|
140
|
+
}
|
|
139
141
|
return { [property]: value ?? (0, sql_functions_15.or)() };
|
|
140
142
|
}
|
|
141
143
|
if (!('value' in expression)) {
|
|
142
144
|
const operator = (expression.operator === 'AND') ? sql_functions_1.AND : sql_functions_2.OR;
|
|
143
145
|
return { [operator]: expression.operands.map(operand => this.condition(type, property, operand, ancestors)) };
|
|
144
146
|
}
|
|
145
|
-
if (resolved
|
|
147
|
+
if ((resolved?.targetMultiplicity === 'one') && (expression.comparison === undefined)) {
|
|
146
148
|
const empty = emptyCriterion(expression.value);
|
|
147
|
-
if (empty)
|
|
148
|
-
return { [property]: empty === 'empty' ? (0, sql_functions_9.isNull)() : (0, sql_functions_8.isNotNull)() };
|
|
149
|
+
if (empty) {
|
|
150
|
+
return { [property]: (empty === 'empty') ? (0, sql_functions_9.isNull)() : (0, sql_functions_8.isNotNull)() };
|
|
151
|
+
}
|
|
149
152
|
}
|
|
150
|
-
|
|
153
|
+
const target = resolved?.target ?? type;
|
|
154
|
+
if (ancestors.includes(target)) {
|
|
151
155
|
throw new Error(`Cyclic search representation: ${property}`);
|
|
152
|
-
|
|
156
|
+
}
|
|
157
|
+
const branch = [...ancestors, target];
|
|
158
|
+
const prefix = property ? `${property}.` : '';
|
|
153
159
|
return {
|
|
154
|
-
[sql_functions_2.OR]: (0, class_view_1.representativeOf)(
|
|
155
|
-
.map(name => this.condition(type, `${property}.${String(name)}`, expression, branch))
|
|
160
|
+
[sql_functions_2.OR]: (0, class_view_1.representativeOf)(target).map(name => this.condition(type, prefix + String(name), expression, branch))
|
|
156
161
|
};
|
|
157
162
|
}
|
|
158
163
|
getParams(request, _type) {
|
|
@@ -189,13 +194,16 @@ class Filter extends parameter_1.Parameter {
|
|
|
189
194
|
readOptions(options = new Array) {
|
|
190
195
|
return options;
|
|
191
196
|
}
|
|
192
|
-
searchObject(type) {
|
|
197
|
+
searchObject(type, searchOnOwner) {
|
|
193
198
|
const search = {};
|
|
194
199
|
const groups = [];
|
|
195
200
|
for (const [property, value] of Object.entries(this.search)) {
|
|
196
201
|
if (value === '')
|
|
197
202
|
continue;
|
|
198
|
-
const
|
|
203
|
+
const path = searchOnOwner?.((0, reflect_path_1.resolvePropertyPath)(type, property))
|
|
204
|
+
? property.substring(0, property.lastIndexOf('.'))
|
|
205
|
+
: property;
|
|
206
|
+
const condition = this.columnCondition(type, path, value);
|
|
199
207
|
if (Object.hasOwn(condition, sql_functions_1.AND) || Object.hasOwn(condition, sql_functions_2.OR)) {
|
|
200
208
|
groups.push(condition);
|
|
201
209
|
}
|
package/cjs/list.d.ts
CHANGED
|
@@ -2,17 +2,20 @@ import { Action } from '@itrocks/action';
|
|
|
2
2
|
import { Request } from '@itrocks/action-request';
|
|
3
3
|
import { SearchType } from '@itrocks/storage';
|
|
4
4
|
import { ListView } from './access';
|
|
5
|
+
import { ColumnWidths } from './column-widths';
|
|
5
6
|
import { Columns } from './columns';
|
|
6
7
|
import { Feed } from './feed';
|
|
7
8
|
import { Filter } from './filter';
|
|
8
9
|
import { Sort } from './sort';
|
|
9
10
|
export { listAccess, listDependsOn } from './access';
|
|
10
|
-
export type { ListAccess, ListDependencies, ListView } from './access';
|
|
11
|
+
export type { ListAccess, ListColumnOutput, ListColumnsView, ListDependencies, ListView } from './access';
|
|
11
12
|
export declare class List<T extends object = object> extends Action<T> {
|
|
12
13
|
columns: Columns<object>;
|
|
14
|
+
columnWidths: ColumnWidths<object>;
|
|
13
15
|
feed: Feed;
|
|
14
16
|
filter: Filter<object>;
|
|
15
17
|
sort: Sort<object>;
|
|
18
|
+
protected canResizeColumns(_request: Request<T>): boolean;
|
|
16
19
|
protected filterBar(request: Request<T>): ListView;
|
|
17
20
|
html(request: Request<T>, scope?: SearchType<T>): Promise<import("@itrocks/request-response").Response>;
|
|
18
21
|
json(request: Request<T>, scope?: SearchType<T>): Promise<import("@itrocks/core-responses").JsonResponse>;
|
package/cjs/list.html
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<link href="../../action-bar/action.css" rel="stylesheet">
|
|
5
|
+
<link href="../../table/column-resize.css" rel="stylesheet">
|
|
5
6
|
<link href="../../ux-core/css/app.css" rel="stylesheet">
|
|
6
7
|
<link href="../../ux-core/css/article.css" rel="stylesheet">
|
|
7
8
|
<link href="../list.css" rel="stylesheet">
|
|
@@ -17,6 +18,7 @@
|
|
|
17
18
|
<article data-action="list" data-class="{type.name}" data-route="{type.@route}" data-property-root="{?root}"
|
|
18
19
|
data-selector-key="{?selectorKey}" data-selector-bootstrap="{?selectorBootstrap}">
|
|
19
20
|
<!--view-->{{template}}<!--end-->
|
|
21
|
+
<!--columnsView-->{{template}}<!--end-->
|
|
20
22
|
<header>
|
|
21
23
|
<h2>{type.@output.ucFirst} list</h2>
|
|
22
24
|
<div class="list-toolbar">
|
|
@@ -37,7 +39,7 @@
|
|
|
37
39
|
<form action="app://(type.@route)/list" autocomplete="off" data-focus-column="{focusColumn}"
|
|
38
40
|
method="post" target="main">
|
|
39
41
|
<!--filterBar--><!--formFields-->{{template}}<!--end--><!--end-->
|
|
40
|
-
<table class="objects" data-link="{type.@route}">
|
|
42
|
+
<table class="objects" data-column-resize="{?canResize}" data-link="{type.@route}">
|
|
41
43
|
<thead>
|
|
42
44
|
<tr class="properties">
|
|
43
45
|
<th class="select" data-freeze><!--selection-->{{template}}<!--end-->
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
</th>
|
|
46
48
|
<!--columns-->
|
|
47
49
|
<th data-property="{name}" data-reverse="{?reverse}" data-sort="{?sort}"
|
|
48
|
-
data-sortable="{sortable}">{label}
|
|
50
|
+
data-sortable="{sortable}" data-column-width="{?width}">{label}
|
|
49
51
|
<input aria-label="Filter {label}" data-property-filter="{name}" name="search.{field}" value="{escapedSearch}">
|
|
50
52
|
</th>
|
|
51
53
|
<!--end-->
|
package/cjs/list.js
CHANGED
|
@@ -46,6 +46,8 @@ const storage_3 = require("@itrocks/storage");
|
|
|
46
46
|
const access_1 = require("./access");
|
|
47
47
|
const access_2 = require("./access");
|
|
48
48
|
const access_3 = require("./access");
|
|
49
|
+
const access_4 = require("./access");
|
|
50
|
+
const column_widths_1 = require("./column-widths");
|
|
49
51
|
const columns_1 = require("./columns");
|
|
50
52
|
const columns_2 = require("./columns");
|
|
51
53
|
const feed_1 = require("./feed");
|
|
@@ -61,9 +63,9 @@ const selector_state_1 = require("./selector-state");
|
|
|
61
63
|
const selector_state_2 = require("./selector-state");
|
|
62
64
|
const session_state_1 = require("./session-state");
|
|
63
65
|
const sort_1 = require("./sort");
|
|
64
|
-
var
|
|
65
|
-
Object.defineProperty(exports, "listAccess", { enumerable: true, get: function () { return
|
|
66
|
-
Object.defineProperty(exports, "listDependsOn", { enumerable: true, get: function () { return
|
|
66
|
+
var access_5 = require("./access");
|
|
67
|
+
Object.defineProperty(exports, "listAccess", { enumerable: true, get: function () { return access_5.listAccess; } });
|
|
68
|
+
Object.defineProperty(exports, "listDependsOn", { enumerable: true, get: function () { return access_5.listDependsOn; } });
|
|
67
69
|
let List = (() => {
|
|
68
70
|
let _classDecorators = [(0, action_3.Need)('Store', 'new'), (0, route_1.Route)('/list')];
|
|
69
71
|
let _classDescriptor;
|
|
@@ -80,9 +82,13 @@ let List = (() => {
|
|
|
80
82
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
81
83
|
}
|
|
82
84
|
columns = new columns_1.Columns;
|
|
85
|
+
columnWidths = new column_widths_1.ColumnWidths(this.columns);
|
|
83
86
|
feed = new feed_1.Feed;
|
|
84
87
|
filter = new filter_1.Filter(this.columns);
|
|
85
88
|
sort = new sort_1.Sort(this.columns);
|
|
89
|
+
canResizeColumns(_request) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
86
92
|
filterBar(request) {
|
|
87
93
|
return (0, filter_summary_2.filterSummary)(this.filter.search, (0, filter_summary_1.filterAliases)(request.type, this.columns));
|
|
88
94
|
}
|
|
@@ -92,13 +98,14 @@ let List = (() => {
|
|
|
92
98
|
const filter = this.filter;
|
|
93
99
|
const sort = this.sort;
|
|
94
100
|
const type = request.type;
|
|
95
|
-
const selection = (0,
|
|
101
|
+
const selection = (0, access_3.listSelection)();
|
|
96
102
|
const updated = await selection?.update(request);
|
|
97
103
|
if (updated)
|
|
98
104
|
return updated;
|
|
99
105
|
const prepared = await (0, session_state_1.prepareListSession)(request);
|
|
100
106
|
if (prepared)
|
|
101
107
|
return prepared;
|
|
108
|
+
this.columnWidths.unserialize(undefined);
|
|
102
109
|
(0, persist_1.load)(this, request.request, type);
|
|
103
110
|
columns.getParams(request.request, type);
|
|
104
111
|
const access = await (0, access_1.listAccess)(request);
|
|
@@ -107,8 +114,17 @@ let List = (() => {
|
|
|
107
114
|
for (const field of column.fields ?? [])
|
|
108
115
|
await access.authorise(`${column.name}.${field}`);
|
|
109
116
|
}
|
|
117
|
+
const canResize = this.canResizeColumns(request);
|
|
118
|
+
const resizing = ('resizeColumn' in request.request.data) || ('columnWidth' in request.request.data);
|
|
119
|
+
if (resizing && (request.request.method !== 'POST'))
|
|
120
|
+
return this.htmlResponse('', 405);
|
|
121
|
+
if (resizing && !canResize)
|
|
122
|
+
return this.htmlResponse('', 403);
|
|
123
|
+
if (!this.columnWidths.getParams(request.request))
|
|
124
|
+
return this.htmlResponse('', 400);
|
|
110
125
|
const batch = typeof request.request.data.loadColumns === 'string';
|
|
111
|
-
if (request.request.data.columns !== undefined && typeof request.request.data.column !== 'string'
|
|
126
|
+
if (resizing || (request.request.data.columns !== undefined && typeof request.request.data.column !== 'string'
|
|
127
|
+
&& !batch)) {
|
|
112
128
|
(0, persist_2.save)(this, request.request, type);
|
|
113
129
|
return this.htmlResponse('', 204);
|
|
114
130
|
}
|
|
@@ -117,15 +133,18 @@ let List = (() => {
|
|
|
117
133
|
for (const column of columns)
|
|
118
134
|
column.search = filter.search[column.name] ?? '';
|
|
119
135
|
sort.getParams(request.request, type);
|
|
120
|
-
const
|
|
121
|
-
|
|
136
|
+
const columnsView = (0, access_2.listColumnsView)(type, Object.entries(sort.sorted ?? {})[0]);
|
|
137
|
+
const activeSearch = await (0, search_2.listSearch)(request, filter, access, scope, columnsView?.searchOnOwner);
|
|
138
|
+
if ((0, search_1.captureListSearch)(request, activeSearch)) {
|
|
122
139
|
return this.htmlResponse('', 204);
|
|
123
|
-
|
|
140
|
+
}
|
|
141
|
+
if (!batch) {
|
|
124
142
|
(0, persist_2.save)(this, request.request, type);
|
|
125
|
-
|
|
143
|
+
}
|
|
126
144
|
const search = activeSearch.criteria;
|
|
127
|
-
for (const path of Object.keys(sort.sorted ?? {}))
|
|
145
|
+
for (const path of Object.keys(sort.sorted ?? {})) {
|
|
128
146
|
await access.authorise(path);
|
|
147
|
+
}
|
|
129
148
|
if (batch) {
|
|
130
149
|
try {
|
|
131
150
|
const names = request.request.data.loadColumns.split(',').filter(Boolean);
|
|
@@ -140,15 +159,18 @@ let List = (() => {
|
|
|
140
159
|
await access.authorise(`${column.name}.${field}`);
|
|
141
160
|
}
|
|
142
161
|
const ids = request.request.data.rowIds;
|
|
143
|
-
if (typeof ids !== 'string')
|
|
162
|
+
if (typeof ids !== 'string') {
|
|
144
163
|
throw new Error('Visible row identities are required');
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
164
|
+
}
|
|
165
|
+
const rows = requested.length
|
|
166
|
+
? await (0, columns_2.projectColumnOutput)(type, requested, search, [new storage_2.Identifiers(ids ? ids.split(',') : [])], access, columnsView)
|
|
167
|
+
: [];
|
|
168
|
+
const response = requested.map((column, index) => ({
|
|
169
|
+
label: column.label,
|
|
170
|
+
path: column.name,
|
|
171
|
+
sortable: column.sortable,
|
|
172
|
+
rows: rows.map(row => ({ id: row.id, html: row.properties[index].outputOptionalContainer }))
|
|
173
|
+
}));
|
|
152
174
|
(0, persist_2.save)(this, request.request, type);
|
|
153
175
|
return this.jsonResponse({ columns: response });
|
|
154
176
|
}
|
|
@@ -163,17 +185,19 @@ let List = (() => {
|
|
|
163
185
|
const column = new projection_1.ListColumn(type, path);
|
|
164
186
|
for (const field of column.fields ?? [])
|
|
165
187
|
await access.authorise(`${path}.${field}`);
|
|
166
|
-
if (request.request.data.validate === '1')
|
|
188
|
+
if (request.request.data.validate === '1') {
|
|
167
189
|
return this.jsonResponse({ label: column.label, path, sortable: column.sortable });
|
|
190
|
+
}
|
|
168
191
|
const ids = request.request.data.rowIds;
|
|
169
|
-
if (typeof ids !== 'string')
|
|
192
|
+
if (typeof ids !== 'string') {
|
|
170
193
|
throw new Error('Visible row identities are required');
|
|
171
|
-
|
|
194
|
+
}
|
|
195
|
+
const rows = await (0, columns_2.projectColumnOutput)(type, [column], search, [new storage_2.Identifiers(ids ? ids.split(',') : [])], access, columnsView);
|
|
172
196
|
return this.jsonResponse({
|
|
173
|
-
label: column.label,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}))
|
|
197
|
+
label: column.label,
|
|
198
|
+
path,
|
|
199
|
+
sortable: column.sortable,
|
|
200
|
+
rows: rows.map(row => ({ id: row.id, html: row.properties[0].outputOptionalContainer }))
|
|
177
201
|
});
|
|
178
202
|
}
|
|
179
203
|
catch (error) {
|
|
@@ -183,7 +207,9 @@ let List = (() => {
|
|
|
183
207
|
return this.jsonResponse({ error: message }, 400);
|
|
184
208
|
}
|
|
185
209
|
}
|
|
186
|
-
const
|
|
210
|
+
const sortOptions = columnsView?.sort ? [columnsView.sort] : sort.readOptions();
|
|
211
|
+
const options = feed.readOptions(filter.readOptions(sortOptions));
|
|
212
|
+
const objects = await (0, columns_2.projectColumnOutput)(type, columns, search, options, access, columnsView);
|
|
187
213
|
if (feed.offset) {
|
|
188
214
|
return this.htmlTemplateResponse({ objects, type }, request, feed.template);
|
|
189
215
|
}
|
|
@@ -204,11 +230,12 @@ let List = (() => {
|
|
|
204
230
|
const focus = request.request.method === 'POST' ? request.request.data.focusListColumn : undefined;
|
|
205
231
|
const focusColumn = [...columns].find(column => column.field === focus)?.field ?? '';
|
|
206
232
|
return this.htmlTemplateResponse({
|
|
207
|
-
columns, count, filterBar: this.filterBar(request), focusColumn,
|
|
233
|
+
canResize, columns, columnsView: columnsView?.view, count, filterBar: this.filterBar(request), focusColumn,
|
|
234
|
+
generalActions, objects,
|
|
208
235
|
root: access.root, search: filter.search,
|
|
209
236
|
selectionActions, selectorBootstrap, selectorKey: (0, selector_state_2.selectorStateKey)(request), type,
|
|
210
237
|
selection: selectionActions.length ? await selection?.view(request, activeSearch, count) : undefined,
|
|
211
|
-
view: await (0,
|
|
238
|
+
view: await (0, access_4.listView)(request)
|
|
212
239
|
}, request, __dirname + '/list.html');
|
|
213
240
|
}
|
|
214
241
|
async json(request, scope) {
|
package/cjs/projection.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Type } from '@itrocks/class-type';
|
|
2
|
+
import { ReflectPropertyPath } from '@itrocks/reflect-path';
|
|
2
3
|
import { resolvePropertyPath } from '@itrocks/reflect-path';
|
|
3
4
|
import { ProjectionCell } from '@itrocks/storage';
|
|
4
5
|
import { Selection } from '@itrocks/storage';
|
|
6
|
+
import type { ListColumnOutput } from './access';
|
|
5
7
|
type RepresentationProperty = ReturnType<typeof resolvePropertyPath>['property'];
|
|
6
8
|
export type RepresentationDependencies = {
|
|
7
9
|
fields?: (type: Type, ancestors: readonly Type[], property?: RepresentationProperty) => readonly string[] | undefined;
|
|
@@ -22,15 +24,16 @@ export declare class ListColumn {
|
|
|
22
24
|
readonly fields?: readonly string[];
|
|
23
25
|
readonly label: string;
|
|
24
26
|
readonly multiple: boolean;
|
|
25
|
-
readonly property:
|
|
27
|
+
readonly property: ReflectPropertyPath<Record<string, unknown>, string>;
|
|
26
28
|
readonly sortable: boolean;
|
|
27
29
|
readonly target?: Type;
|
|
28
30
|
reverse: boolean;
|
|
29
31
|
search: string;
|
|
30
32
|
sort?: number;
|
|
33
|
+
width?: number;
|
|
31
34
|
constructor(root: Type, name: string);
|
|
32
35
|
get escapedSearch(): string;
|
|
33
|
-
output(cell: ProjectionCell): Promise<string>;
|
|
36
|
+
output(cell: ProjectionCell, output?: ListColumnOutput, object?: object): Promise<string>;
|
|
34
37
|
selection(): Selection;
|
|
35
38
|
sortPaths(): string[];
|
|
36
39
|
}
|
package/cjs/projection.js
CHANGED
|
@@ -57,6 +57,7 @@ class ListColumn {
|
|
|
57
57
|
reverse = false;
|
|
58
58
|
search = '';
|
|
59
59
|
sort;
|
|
60
|
+
width;
|
|
60
61
|
constructor(root, name) {
|
|
61
62
|
this.root = root;
|
|
62
63
|
this.name = name;
|
|
@@ -100,7 +101,15 @@ class ListColumn {
|
|
|
100
101
|
get escapedSearch() {
|
|
101
102
|
return (0, filter_summary_1.escapeFilterText)(this.search);
|
|
102
103
|
}
|
|
103
|
-
async output(cell) {
|
|
104
|
+
async output(cell, output, object) {
|
|
105
|
+
if (output) {
|
|
106
|
+
const property = object
|
|
107
|
+
? new reflect_path_1.ReflectPropertyPath(object, this.name)
|
|
108
|
+
: this.property;
|
|
109
|
+
const rendered = await output(this, cell, property);
|
|
110
|
+
if (rendered !== undefined)
|
|
111
|
+
return rendered;
|
|
112
|
+
}
|
|
104
113
|
if (cell.kind === 'absent')
|
|
105
114
|
return '';
|
|
106
115
|
if (cell.kind === 'unloaded')
|
package/cjs/search.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Request } from '@itrocks/action-request';
|
|
2
2
|
import type { SearchType } from '@itrocks/storage';
|
|
3
3
|
import type { ListAccess } from './access';
|
|
4
|
+
import type { ListColumnsView } from './access';
|
|
4
5
|
import type { Filter } from './filter';
|
|
5
6
|
export type ListSearch = {
|
|
6
7
|
criteria: SearchType;
|
|
@@ -8,7 +9,7 @@ export type ListSearch = {
|
|
|
8
9
|
};
|
|
9
10
|
export declare function resolveListSearch(request: Request, run: (request: Request) => Promise<unknown>): Promise<ListSearch | undefined>;
|
|
10
11
|
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
|
|
12
|
+
export declare function listSearch<T extends object>(request: Request<T>, filter: Filter<T>, access: ListAccess, scope?: SearchType<T>, searchOnOwner?: ListColumnsView['searchOnOwner']): Promise<{
|
|
12
13
|
criteria: SearchType<T>;
|
|
13
14
|
filters: Record<string, string>;
|
|
14
15
|
}>;
|
package/cjs/search.js
CHANGED
|
@@ -26,8 +26,8 @@ function captureListSearch(request, search) {
|
|
|
26
26
|
lookup.search = search;
|
|
27
27
|
return true;
|
|
28
28
|
}
|
|
29
|
-
async function listSearch(request, filter, access, scope) {
|
|
30
|
-
const filters = filter.searchObject(request.type);
|
|
29
|
+
async function listSearch(request, filter, access, scope, searchOnOwner) {
|
|
30
|
+
const filters = filter.searchObject(request.type, searchOnOwner);
|
|
31
31
|
// Scope values override direct user criteria; logical groups remain cumulative.
|
|
32
32
|
for (const path of Object.keys(scope ?? {}))
|
|
33
33
|
delete filters[path];
|
package/cjs/session-state.d.ts
CHANGED
package/cjs/session-state.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.prepareListSession = prepareListSession;
|
|
|
7
7
|
exports.listSessionChanged = listSessionChanged;
|
|
8
8
|
exports.comparableListState = comparableListState;
|
|
9
9
|
const route_1 = require("@itrocks/route");
|
|
10
|
+
const column_widths_1 = require("./column-widths");
|
|
10
11
|
const dependencies = {
|
|
11
12
|
changed: () => { },
|
|
12
13
|
prepare: async () => { }
|
|
@@ -18,6 +19,7 @@ function listState(request, type) {
|
|
|
18
19
|
const state = request.session.list?.[(0, route_1.routeOf)(type)] ?? {};
|
|
19
20
|
return structuredClone({
|
|
20
21
|
columns: state.columns,
|
|
22
|
+
...(state.columnWidths && Object.keys(state.columnWidths).length ? { columnWidths: state.columnWidths } : {}),
|
|
21
23
|
filter: state.filter,
|
|
22
24
|
...(state.listQuery ? { listQuery: state.listQuery } : {}),
|
|
23
25
|
sort: state.sort
|
|
@@ -37,6 +39,9 @@ function listSessionChanged(request, type) {
|
|
|
37
39
|
function comparableListState(state) {
|
|
38
40
|
return JSON.stringify({
|
|
39
41
|
columns: state.columns,
|
|
42
|
+
columnWidths: Object.entries(state.columnWidths ?? {})
|
|
43
|
+
.filter(([path, width]) => (0, column_widths_1.isColumnWidth)(width) && (state.columns?.includes(path) ?? true))
|
|
44
|
+
.sort(([left], [right]) => left.localeCompare(right)),
|
|
40
45
|
filter: Object.entries(state.filter ?? {})
|
|
41
46
|
.filter(([, value]) => value !== '')
|
|
42
47
|
.sort(([left], [right]) => left.localeCompare(right)),
|
package/docs/dependencies.md
CHANGED
|
@@ -40,3 +40,18 @@ The host owns the supplied template and its data; the list does not depend on th
|
|
|
40
40
|
and after the selection actions, and a handler for updates. The view callback receives the request, effective list
|
|
41
41
|
criteria and result count. `resolveListSearch` from `@itrocks/list/search` captures the criteria from the routed HTML
|
|
42
42
|
list action, including its mandatory scope and path authorisation.
|
|
43
|
+
|
|
44
|
+
`listDependsOn({ columnsView })` supplies a renderer for selected cells and an optional view fragment for the full
|
|
45
|
+
list. The callback receives the list type and its first applied sort entry, if any. Its
|
|
46
|
+
`output(column, cell, property)` callback can return HTML, including an empty string, or `undefined` to use the
|
|
47
|
+
standard renderer. It may also return a promise. The third argument is a `ReflectPropertyPath` with the full column
|
|
48
|
+
path and the root class. Return the display dependency paths from `objectFields(column)` to attach the source
|
|
49
|
+
object to that reflection. List authorises the paths before loading objects for the selected row IDs with the
|
|
50
|
+
effective search criteria. Extensions declare the paths whose values they display. The same callback
|
|
51
|
+
applies to the initial list, feed rows, and cells added by the column selector. The optional `view` follows the
|
|
52
|
+
usual `{ template, ...data }` contract. The optional `sort` replaces the storage sort for the initial list and
|
|
53
|
+
feed rows while retaining the applied sort and direction in the interface.
|
|
54
|
+
|
|
55
|
+
With `searchOnOwner(property)`, a column extension can make a filter search the object owning the configured
|
|
56
|
+
property. List applies the same representative matching used for object columns and authorises the resulting
|
|
57
|
+
paths. For a property at the root, the filter searches the listed object.
|
package/list.css
CHANGED
|
@@ -43,6 +43,12 @@ table.objects tr td, table.objects tr th {
|
|
|
43
43
|
table.objects tr td:nth-last-child(1 of :not([hidden])), table.objects tr th:nth-last-child(1 of :not([hidden])) {
|
|
44
44
|
border-right: 1px solid #d8d8d8;
|
|
45
45
|
}
|
|
46
|
+
table.objects > :is(thead, tbody) > tr > :nth-child(1 of th.select:not([hidden]) ~ :not([hidden])) {
|
|
47
|
+
border-left: 1px solid #d8d8d8;
|
|
48
|
+
}
|
|
49
|
+
table.objects > :is(thead, tbody) > tr > :nth-child(1 of th.select:not([hidden]) ~ :not([hidden])) > input[data-property-filter] {
|
|
50
|
+
border-left-width: 0;
|
|
51
|
+
}
|
|
46
52
|
table.objects > * > tr > .column-reorder {
|
|
47
53
|
--column-reorder-tint: inset 0 0 0 100vmax rgb(0 0 0 / 2%);
|
|
48
54
|
box-shadow: var(--column-reorder-tint);
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type SearchComparison = ':' | '=' | '!=' | '<' | '<=' | '>' | '>=';
|
|
2
|
-
export type SearchExpression = {
|
|
3
|
-
comparison?: SearchComparison;
|
|
4
|
-
value: string;
|
|
5
|
-
} | {
|
|
6
|
-
operator: 'AND' | 'OR';
|
|
7
|
-
operands: SearchExpression[];
|
|
8
|
-
};
|
|
9
|
-
export declare function searchExpression(input: string): SearchExpression;
|
package/cjs/search-expression.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.searchExpression = searchExpression;
|
|
4
|
-
function searchExpression(input) {
|
|
5
|
-
// Preserve ordinary input exactly, including spaces used by existing scalar criteria.
|
|
6
|
-
if (!/[,|&+()"\\]/.test(input))
|
|
7
|
-
return { value: input };
|
|
8
|
-
return new SearchParser(input).parse();
|
|
9
|
-
}
|
|
10
|
-
class SearchParser {
|
|
11
|
-
input;
|
|
12
|
-
position = 0;
|
|
13
|
-
constructor(input) {
|
|
14
|
-
this.input = input;
|
|
15
|
-
}
|
|
16
|
-
and() {
|
|
17
|
-
const operands = [this.primary()];
|
|
18
|
-
while (this.take('&+'))
|
|
19
|
-
operands.push(this.primary());
|
|
20
|
-
return (operands.length === 1) ? operands[0] : { operator: 'AND', operands };
|
|
21
|
-
}
|
|
22
|
-
fail(message) {
|
|
23
|
-
throw new SyntaxError(`${message} at position ${this.position + 1}`);
|
|
24
|
-
}
|
|
25
|
-
or() {
|
|
26
|
-
const operands = [this.and()];
|
|
27
|
-
while (this.take(',|'))
|
|
28
|
-
operands.push(this.and());
|
|
29
|
-
return (operands.length === 1) ? operands[0] : { operator: 'OR', operands };
|
|
30
|
-
}
|
|
31
|
-
parse() {
|
|
32
|
-
const expression = this.or();
|
|
33
|
-
this.space();
|
|
34
|
-
if (this.position !== this.input.length)
|
|
35
|
-
this.fail('Unexpected character');
|
|
36
|
-
return expression;
|
|
37
|
-
}
|
|
38
|
-
primary() {
|
|
39
|
-
if (this.take('(')) {
|
|
40
|
-
const expression = this.or();
|
|
41
|
-
if (!this.take(')')) {
|
|
42
|
-
this.fail('Missing closing parenthesis');
|
|
43
|
-
}
|
|
44
|
-
return expression;
|
|
45
|
-
}
|
|
46
|
-
let value = '';
|
|
47
|
-
let length = 0;
|
|
48
|
-
let quoted = false;
|
|
49
|
-
let seen = false;
|
|
50
|
-
while (this.position < this.input.length) {
|
|
51
|
-
const character = this.input[this.position];
|
|
52
|
-
if (!quoted && ',|&+()'.includes(character))
|
|
53
|
-
break;
|
|
54
|
-
this.position++;
|
|
55
|
-
if ((character === '\\')
|
|
56
|
-
&& (this.position < this.input.length)
|
|
57
|
-
&& ',|&+()"\\'.includes(this.input[this.position])) {
|
|
58
|
-
value += this.input[this.position++];
|
|
59
|
-
length = value.length;
|
|
60
|
-
seen = true;
|
|
61
|
-
}
|
|
62
|
-
else if (character === '"') {
|
|
63
|
-
quoted = !quoted;
|
|
64
|
-
seen = true;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
value += character;
|
|
68
|
-
if (quoted || character.trim())
|
|
69
|
-
length = value.length;
|
|
70
|
-
seen ||= !!character.trim();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (quoted)
|
|
74
|
-
this.fail('Unclosed quote');
|
|
75
|
-
if (!seen)
|
|
76
|
-
this.fail('Missing criterion');
|
|
77
|
-
return { value: value.slice(0, length) };
|
|
78
|
-
}
|
|
79
|
-
space() {
|
|
80
|
-
while ((this.position < this.input.length) && /\s/.test(this.input[this.position])) {
|
|
81
|
-
this.position++;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
take(characters) {
|
|
85
|
-
this.space();
|
|
86
|
-
if ((this.position === this.input.length) || !characters.includes(this.input[this.position])) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
this.position++;
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=search-expression.js.map
|