@itrocks/list 0.0.15 → 0.0.17

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 CHANGED
@@ -1,11 +1,14 @@
1
1
  import { build } from '../build/build.js';
2
2
  import { xTargetCall } from '../xtarget/xtarget.js';
3
+ import { TableFeed } from '../table/feed.js';
3
4
  import { TableFreeze } from '../table/freeze.js';
4
5
  import { TableFreezeInheritBackground } from '../table/freeze/inherit-background.js';
5
6
  import { TableFreezeInheritBorder } from '../table/freeze/inherit-border.js';
6
7
  import { tableByElement } from '../table/table.js';
7
8
  build('article[data-action="list"] > form > table.objects', element => {
8
- tableByElement(element, { plugins: [TableFreeze, TableFreezeInheritBackground, TableFreezeInheritBorder] });
9
+ tableByElement(element, {
10
+ plugins: [TableFeed, TableFreeze, TableFreezeInheritBackground, TableFreezeInheritBorder]
11
+ });
9
12
  element.querySelector(':scope > tbody')?.addEventListener('click', async (event) => {
10
13
  const td = event.target;
11
14
  if (!(td instanceof HTMLTableCellElement))
package/cjs/feed.html ADDED
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head><title>list feed</title></head>
4
+ <body>
5
+ <table class="objects">
6
+ <!--BEGIN-->
7
+
8
+ <!--objects-->
9
+ <tr>
10
+ <th class="select"><input name="id" type="checkbox" value="{id}"></th>
11
+ <!--%listProperties-->
12
+ <td>{outputOptionalContainer}</td>
13
+ <!--end-->
14
+ </tr>
15
+ <!--end-->
16
+
17
+ <!--END-->
18
+ </table>
19
+ </body>
20
+ </html>
package/cjs/list.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Action } from '@itrocks/action';
2
2
  import { Request } from '@itrocks/action-request';
3
3
  export declare class List<T extends object = object> extends Action<T> {
4
+ lineHeight: number;
4
5
  html(request: Request<T>): Promise<import("@itrocks/core-responses").HtmlResponse>;
5
6
  json(request: Request<T>): Promise<import("@itrocks/core-responses").JsonResponse>;
6
7
  }
package/cjs/list.html CHANGED
@@ -17,7 +17,7 @@
17
17
  <article data-action="list" data-class="{type.name}" data-route="{type.@route}">
18
18
  <header>
19
19
  <h2>{type.@output.ucFirst} list</h2>
20
- <section class="summary">{objects.length} elements</section>
20
+ <section class="summary">{count} elements</section>
21
21
  <ul class="general actions">
22
22
  <!--generalActions-->
23
23
  <li class="{action}">{{template}}</li>
@@ -26,7 +26,7 @@
26
26
  </header>
27
27
  <form action="app://(type.@route)" autocomplete="off" method="post" target="main">
28
28
  <table class="objects">
29
- <thead>
29
+ <thead>
30
30
  <tr class="properties">
31
31
  <th class="select" data-fix><input name="select" type="checkbox" value="all"></th>
32
32
  <!--type.%listProperties-->
@@ -35,14 +35,7 @@
35
35
  </tr>
36
36
  </thead>
37
37
  <tbody>
38
- <!--objects-->
39
- <tr>
40
- <th class="select"><input name="id" type="checkbox" value="{id}"></th>
41
- <!--%listProperties-->
42
- <td>{outputOptionalContainer}</td>
43
- <!--end-->
44
- </tr>
45
- <!--end-->
38
+ {./feed.html}
46
39
  </tbody>
47
40
  </table>
48
41
  <footer>
package/cjs/list.js CHANGED
@@ -42,6 +42,7 @@ const route_1 = require("@itrocks/route");
42
42
  const route_2 = require("@itrocks/route");
43
43
  const storage_1 = require("@itrocks/storage");
44
44
  const storage_2 = require("@itrocks/storage");
45
+ const storage_3 = require("@itrocks/storage");
45
46
  let List = (() => {
46
47
  let _classDecorators = [(0, action_3.Need)('Store', 'new'), (0, route_1.Route)('/list')];
47
48
  let _classDescriptor;
@@ -57,17 +58,28 @@ let List = (() => {
57
58
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
59
  __runInitializers(_classThis, _classExtraInitializers);
59
60
  }
61
+ lineHeight = 30;
60
62
  async html(request) {
63
+ const header = request.request.headers['xhr-info'];
64
+ const xhrInfo = header ? JSON.parse(header) : {};
65
+ const limit = xhrInfo.targetHeight
66
+ ? Math.ceil(xhrInfo.targetHeight / this.lineHeight)
67
+ : +(request.request.headers['xhr-visible-rows'] ?? 50);
68
+ const offset = request.request.data.offset;
61
69
  const type = request.type;
62
- const objects = await (0, storage_1.dataSource)().readAll(type, storage_2.Sort);
70
+ const objects = await (0, storage_1.dataSource)().readAll(type, [new storage_2.Limit(limit, +offset), storage_3.Sort]);
71
+ if (offset !== undefined) {
72
+ return this.htmlTemplateResponse({ objects, type }, request, __dirname + '/feed.html');
73
+ }
74
+ const count = await (0, storage_1.dataSource)().count(type);
75
+ const route = (0, route_2.routeOf)(this);
63
76
  const generalActions = [];
64
77
  const selectionActions = [];
65
- const route = (0, route_2.routeOf)(this);
66
78
  for (const action of (0, action_2.getActions)(type, route.slice(route.lastIndexOf('/') + 1))) {
67
79
  const actions = (action.need === 'object') ? selectionActions : generalActions;
68
80
  actions.push(action);
69
81
  }
70
- return this.htmlTemplateResponse({ generalActions, objects, selectionActions, type }, request, __dirname + '/list.html');
82
+ return this.htmlTemplateResponse({ count, generalActions, objects, selectionActions, type }, request, __dirname + '/list.html');
71
83
  }
72
84
  async json(request) {
73
85
  const objects = await (0, storage_1.dataSource)().search(request.type);
package/package.json CHANGED
@@ -63,5 +63,5 @@
63
63
  "build:front": "tsc -p esm/tsconfig.json && ../prepare-module/prepare-module.js esm"
64
64
  },
65
65
  "types": "./cjs/list.d.ts",
66
- "version": "0.0.15"
66
+ "version": "0.0.17"
67
67
  }