@itrocks/framework 1.4.1 → 1.5.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/app.js +7 -3
- package/cjs/custom-list.d.ts +5 -0
- package/cjs/custom-list.js +70 -0
- package/cjs/dependencies.js +2 -0
- package/cjs/language.js +6 -2
- package/cjs/main.js +7 -4
- package/custom-list.d.ts +1 -0
- package/custom-list.js +37 -0
- package/docs/dependencies.md +30 -0
- package/package.json +3 -1
package/app.js
CHANGED
|
@@ -10,16 +10,17 @@ import { notifications } from '@itrocks/notifications/notifications.js';
|
|
|
10
10
|
import '@itrocks/real-viewport-height/real-viewport-height.js';
|
|
11
11
|
import { XTargetBeginEnd } from '@itrocks/xtarget/begin-end.js';
|
|
12
12
|
import { buildXTarget } from '@itrocks/xtarget/build.js';
|
|
13
|
-
import { XTargetSecureClick } from '@itrocks/xtarget/secure-click.js';
|
|
14
13
|
import { XTargetComposite } from '@itrocks/xtarget/composite.js';
|
|
15
14
|
import { XTargetDefaultTarget } from '@itrocks/xtarget/default-target.js';
|
|
16
|
-
import { XTargetDefaultOptions } from '@itrocks/xtarget/xtarget.js';
|
|
17
15
|
import { XTargetHead } from '@itrocks/xtarget/head.js';
|
|
18
16
|
import { XTargetHeadersSize } from '@itrocks/xtarget/headers-size.js';
|
|
19
17
|
import { XTargetHistory } from '@itrocks/xtarget/history.js';
|
|
20
18
|
import { XTargetHoldOn } from '@itrocks/xtarget/hold-on.js';
|
|
21
19
|
import { XTargetMainTarget } from '@itrocks/xtarget/main-target.js';
|
|
22
20
|
import { XTargetModifier } from '@itrocks/xtarget/modifier.js';
|
|
21
|
+
import { XTargetSecureClick } from '@itrocks/xtarget/secure-click.js';
|
|
22
|
+
import { XTargetDefaultOptions } from '@itrocks/xtarget/xtarget.js';
|
|
23
|
+
import { enhanceListBreadcrumb } from './custom-list.js';
|
|
23
24
|
import './property-select-list.js';
|
|
24
25
|
let selector;
|
|
25
26
|
selector = 'input[data-type=object], ul[data-type=objects] > li > input:not([type=hidden])';
|
|
@@ -33,7 +34,10 @@ build(selector, async (input) => {
|
|
|
33
34
|
(await import('@itrocks/links/links.js')).links(input);
|
|
34
35
|
}
|
|
35
36
|
});
|
|
36
|
-
build('main > * > h2, main > * > header > h2',
|
|
37
|
+
build('main > * > h2, main > * > header > h2', heading => {
|
|
38
|
+
if (!enhanceListBreadcrumb(heading))
|
|
39
|
+
breadcrumb(heading);
|
|
40
|
+
});
|
|
37
41
|
build('button.collapse', button => collapse(button, 'body'));
|
|
38
42
|
build('input[data-type=date]', async (input) => (await import('@itrocks/air-datepicker/air-datepicker.js')).airDatePicker(input));
|
|
39
43
|
build('form', autoFocus);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Request } from '@itrocks/action-request';
|
|
2
|
+
import type { CustomListContext } from '@itrocks/custom-list';
|
|
3
|
+
export declare function bindCustomList(): void;
|
|
4
|
+
export declare function businessModulePath(file: string): string;
|
|
5
|
+
export declare function customListContext(request: Request): Promise<CustomListContext>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bindCustomList = bindCustomList;
|
|
4
|
+
exports.businessModulePath = businessModulePath;
|
|
5
|
+
exports.customListContext = customListContext;
|
|
6
|
+
const app_dir_1 = require("@itrocks/app-dir");
|
|
7
|
+
const class_file_1 = require("@itrocks/class-file");
|
|
8
|
+
const class_view_1 = require("@itrocks/class-view");
|
|
9
|
+
const config_1 = require("@itrocks/config");
|
|
10
|
+
const custom_list_1 = require("@itrocks/custom-list");
|
|
11
|
+
const custom_list_2 = require("@itrocks/custom-list");
|
|
12
|
+
const custom_list_3 = require("@itrocks/custom-list");
|
|
13
|
+
const custom_list_4 = require("@itrocks/custom-list");
|
|
14
|
+
const data_path_1 = require("@itrocks/data-path");
|
|
15
|
+
const list_1 = require("@itrocks/list");
|
|
16
|
+
const session_state_1 = require("@itrocks/list/session-state");
|
|
17
|
+
const session_state_2 = require("@itrocks/list/session-state");
|
|
18
|
+
const session_state_3 = require("@itrocks/list/session-state");
|
|
19
|
+
const request_response_1 = require("@itrocks/request-response");
|
|
20
|
+
const route_1 = require("@itrocks/route");
|
|
21
|
+
const translate_1 = require("@itrocks/translate");
|
|
22
|
+
const node_path_1 = require("node:path");
|
|
23
|
+
function bindCustomList() {
|
|
24
|
+
(0, data_path_1.setDataPath)((0, config_1.configPath)('dataPath', '../data'));
|
|
25
|
+
(0, custom_list_2.customListDependsOn)({
|
|
26
|
+
context: customListContext,
|
|
27
|
+
state: {
|
|
28
|
+
read: request => (0, session_state_2.listState)(request.request, request.type),
|
|
29
|
+
replace: (request, state) => (0, session_state_3.replaceListState)(request.request, request.type, state)
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
(0, list_1.listDependsOn)({ view: request => new custom_list_1.CustomList().breadcrumbView(request) });
|
|
33
|
+
(0, session_state_1.listSessionDependsOn)({
|
|
34
|
+
changed: (request, type) => {
|
|
35
|
+
const key = (0, route_1.routeOf)(type);
|
|
36
|
+
request.session.customLists ??= {};
|
|
37
|
+
request.session.customLists[key] = { ...request.session.customLists[key], modified: true };
|
|
38
|
+
},
|
|
39
|
+
prepare: async (request) => {
|
|
40
|
+
if (typeof request.data.custom !== 'string')
|
|
41
|
+
return;
|
|
42
|
+
const lists = new custom_list_4.CustomLists(await customListContext(request));
|
|
43
|
+
try {
|
|
44
|
+
await lists.load(request, request.data.custom);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (!(error instanceof custom_list_3.CustomListError))
|
|
48
|
+
throw error;
|
|
49
|
+
return new request_response_1.Response((0, translate_1.tr)(error.message), error.status, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function businessModulePath(file) {
|
|
55
|
+
const path = (0, node_path_1.relative)(app_dir_1.appDir, file).replaceAll('\\', '/').replace(/\.(?:[cm]?js|ts)$/, '');
|
|
56
|
+
return path.replace(/^node_modules\//, '');
|
|
57
|
+
}
|
|
58
|
+
async function customListContext(request) {
|
|
59
|
+
const name = (0, translate_1.tr)(await (0, class_view_1.trOutputOf)(request.type) + ' list');
|
|
60
|
+
const user = request.request.session.user;
|
|
61
|
+
return {
|
|
62
|
+
defaultName: name[0].toLocaleUpperCase() + name.slice(1),
|
|
63
|
+
key: request.route,
|
|
64
|
+
modulePath: businessModulePath((0, class_file_1.fileOf)(request.type)),
|
|
65
|
+
user: (user?.id === undefined)
|
|
66
|
+
? undefined
|
|
67
|
+
: { id: String(user.id), name: String(user.login || user.id) }
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=custom-list.js.map
|
package/cjs/dependencies.js
CHANGED
|
@@ -41,6 +41,7 @@ const translate_2 = require("@itrocks/translate");
|
|
|
41
41
|
const date_fns_1 = require("date-fns");
|
|
42
42
|
const node_path_1 = require("node:path");
|
|
43
43
|
const node_path_2 = require("node:path");
|
|
44
|
+
const custom_list_1 = require("./custom-list");
|
|
44
45
|
const language_1 = require("./language");
|
|
45
46
|
const property_select_1 = require("./property-select");
|
|
46
47
|
const sql_projection_1 = require("./sql-projection");
|
|
@@ -92,6 +93,7 @@ function bind() {
|
|
|
92
93
|
: '' + data
|
|
93
94
|
});
|
|
94
95
|
(0, language_1.configureLanguages)();
|
|
96
|
+
(0, custom_list_1.bindCustomList)();
|
|
95
97
|
action_1.Action.prototype.htmlTemplateResponse = async function (data, request, templateFile, statusCode = 200, headers = {}) {
|
|
96
98
|
const containerData = Object.assign(defaultContainerData(request), this);
|
|
97
99
|
const contained = !request.request.headers['xhr-info'] && config_1.config.container?.file;
|
package/cjs/language.js
CHANGED
|
@@ -10,6 +10,7 @@ const translate_1 = require("@itrocks/translate");
|
|
|
10
10
|
const translate_2 = require("@itrocks/translate");
|
|
11
11
|
const translate_3 = require("@itrocks/translate");
|
|
12
12
|
const node_path_1 = require("node:path");
|
|
13
|
+
const node_path_2 = require("node:path");
|
|
13
14
|
let configuration = {
|
|
14
15
|
defaultLanguage: 'en-US',
|
|
15
16
|
supportedLanguages: ['en-US']
|
|
@@ -38,10 +39,13 @@ function configureLanguages() {
|
|
|
38
39
|
(0, translate_1.trInit)(defaultLanguage);
|
|
39
40
|
loading = (async () => {
|
|
40
41
|
// TODO search language files everywhere in application modules, not only into app
|
|
41
|
-
const directories = [
|
|
42
|
+
const directories = [
|
|
43
|
+
(0, node_path_2.join)((0, node_path_1.dirname)(require.resolve('@itrocks/custom-list')), '..'),
|
|
44
|
+
(0, node_path_2.join)(__dirname, '..'), (0, node_path_2.join)(app_dir_1.appDir, 'app'), app_dir_1.appDir
|
|
45
|
+
];
|
|
42
46
|
for (const language of configuration.supportedLanguages) {
|
|
43
47
|
for (const directory of directories) {
|
|
44
|
-
const file = (0,
|
|
48
|
+
const file = (0, node_path_2.join)(directory, language + '.csv');
|
|
45
49
|
await (0, translate_2.trLoad)(file, language);
|
|
46
50
|
}
|
|
47
51
|
}
|
package/cjs/main.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.run = run;
|
|
4
|
-
const action_request_1 = require("@itrocks/action-request");
|
|
5
|
-
const action_request_2 = require("@itrocks/action-request");
|
|
6
4
|
const action_1 = require("@itrocks/action");
|
|
7
5
|
const action_2 = require("@itrocks/action");
|
|
6
|
+
const action_request_1 = require("@itrocks/action-request");
|
|
7
|
+
const action_request_2 = require("@itrocks/action-request");
|
|
8
8
|
const app_dir_1 = require("@itrocks/app-dir");
|
|
9
9
|
const class_type_1 = require("@itrocks/class-type");
|
|
10
10
|
const config_1 = require("@itrocks/config");
|
|
11
|
-
const fastify_file_session_store_1 = require("@itrocks/fastify-file-session-store");
|
|
12
11
|
const fastify_1 = require("@itrocks/fastify");
|
|
12
|
+
const fastify_file_session_store_1 = require("@itrocks/fastify-file-session-store");
|
|
13
13
|
const request_response_1 = require("@itrocks/request-response");
|
|
14
14
|
const route_1 = require("@itrocks/route");
|
|
15
15
|
const session_1 = require("@itrocks/session");
|
|
@@ -37,10 +37,13 @@ function defaultHeader(headers, name, value) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
async function execute(request) {
|
|
40
|
+
// Saved-list reads share the business list's access policy; writes enforce authentication and ownership.
|
|
41
|
+
const accessAction = (request.action === 'custom-list') ? 'list' : request.action;
|
|
40
42
|
// Access control
|
|
41
43
|
if ((config_1.config.access?.free !== '*')
|
|
42
44
|
&& !request.request.session.user
|
|
43
|
-
&& !config_1.config.access?.free?.includes(request.route + '/' + request.action)
|
|
45
|
+
&& !config_1.config.access?.free?.includes(request.route + '/' + request.action)
|
|
46
|
+
&& !config_1.config.access?.free?.includes(request.route + '/' + accessAction)) {
|
|
44
47
|
request.action = 'login';
|
|
45
48
|
request.route = '/user';
|
|
46
49
|
}
|
package/custom-list.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function enhanceListBreadcrumb(heading: HTMLHeadingElement): boolean;
|
package/custom-list.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const pending = new WeakMap();
|
|
2
|
+
let integration;
|
|
3
|
+
export function enhanceListBreadcrumb(heading) {
|
|
4
|
+
const article = heading.closest('main > article[data-route]');
|
|
5
|
+
if (!article || (article.dataset.action !== 'list' && !/\/[0-9,]+$/.test(article.dataset.route)))
|
|
6
|
+
return false;
|
|
7
|
+
const breadcrumb = document.querySelector('ol.breadcrumb');
|
|
8
|
+
const template = article.querySelector('template[data-list-breadcrumb]');
|
|
9
|
+
const rendered = !!template && !!breadcrumb;
|
|
10
|
+
if (rendered) {
|
|
11
|
+
for (const entry of breadcrumb.querySelectorAll('li[data-action=list], li[data-action=custom-list], li[data-action=view]')) {
|
|
12
|
+
entry.remove();
|
|
13
|
+
}
|
|
14
|
+
breadcrumb.append(template.content.cloneNode(true));
|
|
15
|
+
template.remove();
|
|
16
|
+
}
|
|
17
|
+
void (integration ??= import('@itrocks/custom-list/custom-list.js').then(customList => {
|
|
18
|
+
customList.customListBrowserDependsOn({ settled: article => pending.get(article)?.() ?? Promise.resolve() });
|
|
19
|
+
return customList;
|
|
20
|
+
})).then(customList => {
|
|
21
|
+
if (heading.isConnected)
|
|
22
|
+
return customList.updateListBreadcrumb(heading, rendered);
|
|
23
|
+
});
|
|
24
|
+
return rendered;
|
|
25
|
+
}
|
|
26
|
+
document.addEventListener('itrocks:list-change', event => {
|
|
27
|
+
const article = event.target.closest('article');
|
|
28
|
+
if (!article)
|
|
29
|
+
return;
|
|
30
|
+
void integration?.then(customList => customList.markListModified(article.dataset.route));
|
|
31
|
+
});
|
|
32
|
+
document.addEventListener('itrocks:list-ready', event => {
|
|
33
|
+
const article = event.target.closest('article');
|
|
34
|
+
if (!article)
|
|
35
|
+
return;
|
|
36
|
+
pending.set(article, event.detail.settled);
|
|
37
|
+
});
|
package/docs/dependencies.md
CHANGED
|
@@ -44,3 +44,33 @@ and browser use.
|
|
|
44
44
|
[Relationship bindings](sql-relationships.md) map schema/reflection facts to `sql-join`.
|
|
45
45
|
[Projection bindings](sql-projection.md) supply final-owner SQL conversions to MySQL and SQL builders.
|
|
46
46
|
These bindings own persistence metadata; the property metadata provider does not query these adapters.
|
|
47
|
+
|
|
48
|
+
## Saved lists and application data
|
|
49
|
+
|
|
50
|
+
`bindCustomList()` in `src/custom-list.ts` connects [`custom-list`](../../custom-list/README.md) to the
|
|
51
|
+
[`list session port`](../../list/README.md#session-state-integration).
|
|
52
|
+
`context` resolves the translated default label, route key, business module file path and current session user.
|
|
53
|
+
`state.read` and `state.replace` delegate to `listState` and `replaceListState`.
|
|
54
|
+
The list's preparation callback loads explicit `custom` query values before rendering;
|
|
55
|
+
an empty value restores the default. Settings changes mark the active name modified.
|
|
56
|
+
|
|
57
|
+
The browser shell keeps a small context adapter. It imports `@itrocks/custom-list/custom-list.js` on the first list or
|
|
58
|
+
record heading and binds the pending-write dependency. The server includes `CustomList.breadcrumbView(request)`
|
|
59
|
+
through `listDependsOn({ view })`. On list pages the shell applies that template directly, skipping the ordinary
|
|
60
|
+
breadcrumb updater and any follow-up request. Column-only changes update the modified marker locally.
|
|
61
|
+
Record headings use the ordinary breadcrumb updater and its saved-list enrichment.
|
|
62
|
+
Modal behaviour stays in the modal templates' `build.js` dependency; it is not imported by the shell.
|
|
63
|
+
The package itself never imports the framework or binds host dependencies on its own.
|
|
64
|
+
The table's `settled` callback waits for pending column writes before loading or saving settings.
|
|
65
|
+
`itrocks:list-change` refreshes the modification marker after column persistence.
|
|
66
|
+
Anonymous saved-list actions share the business list's configured access policy; file writes additionally enforce
|
|
67
|
+
signed-in user and ownership rules in `custom-list`.
|
|
68
|
+
|
|
69
|
+
[`data-path`](../../data-path/README.md) receives `configPath('dataPath', '../data')` from
|
|
70
|
+
[`config`](../../config/README.md). Relative paths resolve against the declaring YAML file:
|
|
71
|
+
|
|
72
|
+
```yaml
|
|
73
|
+
dataPath: ../data/
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The framework loads `custom-list` translations before its own and application catalogues.
|
package/package.json
CHANGED
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
"@itrocks/config": "latest",
|
|
25
25
|
"@itrocks/contained-auto-width": "latest",
|
|
26
26
|
"@itrocks/core-transformers": "latest",
|
|
27
|
+
"@itrocks/custom-list": "latest",
|
|
28
|
+
"@itrocks/data-path": "latest",
|
|
27
29
|
"@itrocks/decorator": "latest",
|
|
28
30
|
"@itrocks/default-action-workflow": "latest",
|
|
29
31
|
"@itrocks/fastify": "latest",
|
|
@@ -123,5 +125,5 @@
|
|
|
123
125
|
"build:test": "tsc -p test/tsconfig.json",
|
|
124
126
|
"test": "npm run build && npm run build:test && node --test test/*.test.js test/*.test.mjs"
|
|
125
127
|
},
|
|
126
|
-
"version": "1.
|
|
128
|
+
"version": "1.5.0"
|
|
127
129
|
}
|