@itrocks/list 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ ISC License
2
+ Copyright (C) 2024, Baptiste Pillot <baptiste@pillot.fr>
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted, provided that the above
6
+ copyright notice and this permission notice appear in all copies.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13
+ OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14
+ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ [![npm version](https://img.shields.io/npm/v/@itrocks/list?logo=npm)](https://www.npmjs.org/package/@itrocks/list)
2
+ [![npm downloads](https://img.shields.io/npm/dm/@itrocks/list)](https://www.npmjs.org/package/@itrocks/list)
3
+ [![GitHub](https://img.shields.io/github/last-commit/itrocks-ts/list?color=2dba4e&label=commit&logo=github)](https://github.com/itrocks-ts/list)
4
+ [![issues](https://img.shields.io/github/issues/itrocks-ts/list)](https://github.com/itrocks-ts/list/issues)
5
+ [![discord](https://img.shields.io/discord/1314141024020467782?color=7289da&label=discord&logo=discord&logoColor=white)](https://25.re/ditr)
6
+
7
+ # list
8
+
9
+ Generic action-based object list navigation in HTML and JSON.
package/build.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/build.js ADDED
@@ -0,0 +1,36 @@
1
+ import build from '../build/build.js';
2
+ import { xTargetCall } from '../xtarget/xtarget.js';
3
+ import TableFreeze from '../table/freeze.js';
4
+ import TableFreezeInheritBackground from '../table/freeze/inherit-background.js';
5
+ import TableFreezeInheritBorder from '../table/freeze/inherit-border.js';
6
+ import { tableByElement } from '../table/table.js';
7
+ build('article[data-action="list"] > form > table.objects', element => {
8
+ tableByElement(element, { plugins: [TableFreeze, TableFreezeInheritBackground, TableFreezeInheritBorder] });
9
+ element.querySelector(':scope > tbody')?.addEventListener('click', async (event) => {
10
+ const td = event.target;
11
+ if (!(td instanceof HTMLTableCellElement))
12
+ return;
13
+ const tr = td.closest('tr');
14
+ if (!tr)
15
+ return;
16
+ let select = td.closest('.select');
17
+ if (select) {
18
+ const input = select.querySelector('input');
19
+ if (!input)
20
+ return;
21
+ input.click();
22
+ input.focus();
23
+ return;
24
+ }
25
+ const checkBox = tr.querySelector(':scope > th.select > input[name=id]');
26
+ if (!checkBox)
27
+ return;
28
+ const id = checkBox.value;
29
+ if (!id)
30
+ return;
31
+ const form = tr.closest('form');
32
+ if (!form)
33
+ return;
34
+ return xTargetCall(form.getAttribute('action') + '/' + id, 'main');
35
+ });
36
+ });
package/cjs/list.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Action } from '@itrocks/action';
2
+ import { Request } from '@itrocks/action-request';
3
+ export declare class List extends Action {
4
+ html(request: Request): Promise<import("@itrocks/core-responses").HtmlResponse>;
5
+ json(request: Request): Promise<import("@itrocks/core-responses").JsonResponse>;
6
+ }
package/cjs/list.html ADDED
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <link href="../../action-bar/action.css" rel="stylesheet">
5
+ <link href="../../ux-core/css/app.css" rel="stylesheet">
6
+ <link href="../../ux-core/css/article.css" rel="stylesheet">
7
+ <link href="../list.css" rel="stylesheet">
8
+ <meta charset="utf-8">
9
+ <script src="../build.js" type="module"></script>
10
+ <title>{type.@output.ucFirst} list</title>
11
+ </head>
12
+ <body>
13
+ <main>
14
+ <!--BEGIN-->
15
+
16
+ <article data-action="list" data-class="{type.name}" data-route="{type.@route}">
17
+ <header>
18
+ <h2>{type.@output.ucFirst} list</h2>
19
+ <section class="summary">{objects.length} elements</section>
20
+ <ul class="general actions">
21
+ <li class="new"><a href="app://(type.@route)/new" target="main">New</a></li>
22
+ </ul>
23
+ </header>
24
+ <form action="app://(type.@route)" autocomplete="off" method="post" target="main">
25
+ <table class="objects">
26
+ <thead>
27
+ <tr class="properties">
28
+ <th class="select" data-fix><input name="select" type="checkbox" value="all"></th>
29
+ <!--type.%properties.*-->
30
+ <th data-property="{name}">{@display}</th>
31
+ <!--end-->
32
+ </tr>
33
+ </thead>
34
+ <tbody>
35
+ <!--objects-->
36
+ <tr>
37
+ <th class="select"><input name="id" type="checkbox" value="{id}"></th>
38
+ <!--%properties.*-->
39
+ <td>{outputOptionalContainer}</td>
40
+ <!--end-->
41
+ </tr>
42
+ <!--end-->
43
+ </tbody>
44
+ </table>
45
+ <footer>
46
+ <ul class="selection actions">
47
+ <li class="delete">
48
+ <input formaction="app://(type.@route)/delete" formtarget="#notification" type="submit" value="Delete">
49
+ </li>
50
+ </ul>
51
+ </footer>
52
+ </form>
53
+ </article>
54
+
55
+ <!--END-->
56
+ </main>
57
+ </body>
58
+ </html>
package/cjs/list.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.List = void 0;
38
+ const action_1 = require("@itrocks/action");
39
+ const action_2 = require("@itrocks/action");
40
+ const route_1 = require("@itrocks/route");
41
+ const storage_1 = require("@itrocks/storage");
42
+ let List = (() => {
43
+ let _classDecorators = [(0, action_2.Need)('Store', 'new'), (0, route_1.Route)('/list')];
44
+ let _classDescriptor;
45
+ let _classExtraInitializers = [];
46
+ let _classThis;
47
+ let _classSuper = action_1.Action;
48
+ var List = class extends _classSuper {
49
+ static { _classThis = this; }
50
+ static {
51
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
52
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
53
+ List = _classThis = _classDescriptor.value;
54
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
55
+ __runInitializers(_classThis, _classExtraInitializers);
56
+ }
57
+ async html(request) {
58
+ const type = request.type;
59
+ const objects = await (0, storage_1.dataSource)().search(type);
60
+ return this.htmlTemplateResponse({ objects, type }, request, __dirname + '/list.html');
61
+ }
62
+ async json(request) {
63
+ const objects = await (0, storage_1.dataSource)().search(request.type);
64
+ return this.jsonResponse(objects);
65
+ }
66
+ };
67
+ return List = _classThis;
68
+ })();
69
+ exports.List = List;
70
+ //# sourceMappingURL=list.js.map
package/list.css ADDED
@@ -0,0 +1,68 @@
1
+ main > article[data-action=list] {
2
+ display: grid;
3
+ grid-template-areas: "header" "form";
4
+ grid-template-rows: min-content 1fr;
5
+ height: 100%;
6
+ }
7
+ main > article[data-action=list] > header {
8
+ grid-area: header;
9
+ }
10
+ main > article[data-action=list] > header > .summary {
11
+ padding: 13px 10px 12px;
12
+ position: absolute;
13
+ right: 0;
14
+ white-space: nowrap;
15
+ }
16
+ main > article[data-action=list] > form {
17
+ display: grid;
18
+ grid-area: form;
19
+ grid-template-areas: "table" "footer";
20
+ grid-template-rows: 1fr min-content;
21
+ height: 100%;
22
+ overflow: auto;
23
+ }
24
+ main > article[data-action=list] > form > table {
25
+ border-collapse: collapse;
26
+ display: block;
27
+ grid-area: table;
28
+ margin-bottom: -1px;
29
+ overflow-y: auto;
30
+ }
31
+ main > article[data-action=list] > form > table tr > td, main > article[data-action=list] > form > table tr > th {
32
+ border-bottom: 1px solid #d8d8d8;
33
+ border-spacing: 0;
34
+ padding: 0.6em;
35
+ }
36
+ main > article[data-action=list] > form > table tr > td:last-child, main > article[data-action=list] > form > table tr > th:last-child {
37
+ border-right: 1px solid #d8d8d8;
38
+ }
39
+ main > article[data-action=list] > form > table tr > td:not(:first-child), main > article[data-action=list] > form > table tr > th:not(:first-child) {
40
+ cursor: pointer;
41
+ }
42
+ main > article[data-action=list] > form > table > thead > tr > * {
43
+ background: #f8f8f8;
44
+ }
45
+ main > article[data-action=list] > form > table > thead > .properties > .select > input[name=select] {
46
+ display: none;
47
+ }
48
+ main > article[data-action=list] > form > table > tbody > tr:nth-child(even) > * {
49
+ background: #f8f8f8;
50
+ }
51
+ main > article[data-action=list] > form > table > tbody > tr:nth-child(odd) > * {
52
+ background: white;
53
+ }
54
+ main > article[data-action=list] > form > table > tbody > tr > td > ul {
55
+ display: block;
56
+ margin: 0;
57
+ padding: 0;
58
+ }
59
+ main > article[data-action=list] > form > table > tbody > tr > td > ul > li {
60
+ display: inline-block;
61
+ }
62
+ main > article[data-action=list] > form > table > tbody > tr > td > ul > li:not(:first-child):before {
63
+ content: ", ";
64
+ }
65
+ main > article[data-action=list] > form > footer {
66
+ grid-area: footer;
67
+ position: relative;
68
+ }
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "author": {
3
+ "name": "Baptiste Pillot",
4
+ "email": "baptiste@pillot.fr"
5
+ },
6
+ "dependencies": {
7
+ "@itrocks/action": "latest",
8
+ "@itrocks/action-bar": "latest",
9
+ "@itrocks/action-request": "latest",
10
+ "@itrocks/build": "latest",
11
+ "@itrocks/route": "latest",
12
+ "@itrocks/storage": "latest",
13
+ "@itrocks/table": "latest",
14
+ "@itrocks/ux-core": "latest",
15
+ "@itrocks/xtarget": "latest"
16
+ },
17
+ "description": "Generic action-based object list navigation in HTML and JSON",
18
+ "devDependencies": {
19
+ "@itrocks/prepare-module": "latest",
20
+ "@types/node": "^22.9",
21
+ "sass": "^1.83",
22
+ "typescript": "~5.6"
23
+ },
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "exports": "./cjs/list.js",
28
+ "homepage": "https://it.rocks",
29
+ "files": [
30
+ "LICENSE",
31
+ "README.md",
32
+ "cjs/*",
33
+ "*.css",
34
+ "*.d.ts",
35
+ "*.js",
36
+ "!*.map"
37
+ ],
38
+ "keywords": [
39
+ "API",
40
+ "backend",
41
+ "browse",
42
+ "component",
43
+ "display",
44
+ "filter",
45
+ "interactive",
46
+ "json",
47
+ "list",
48
+ "it.rocks",
49
+ "output",
50
+ "responsive",
51
+ "search",
52
+ "select",
53
+ "selection",
54
+ "UI",
55
+ "UX"
56
+ ],
57
+ "license": "ISC",
58
+ "name": "@itrocks/list",
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "git+https://github.com/itrocks-ts/list.git"
62
+ },
63
+ "scripts": {
64
+ "build": "npm run build:cjs && npm run build:css && npm run build:front",
65
+ "build:cjs": "tsc -p tsconfig.cjs.json && cp src/*.html cjs/",
66
+ "build:css": "sass --no-source-map src/list.scss:list.css",
67
+ "build:front": "tsc -p esm/tsconfig.json && npm run prepare",
68
+ "prepare": "prepare-module esm"
69
+ },
70
+ "types": "./cjs/list.d.ts",
71
+ "version": "0.0.1"
72
+ }