@gramlot/gramlot 0.2.5 → 0.2.6
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/dist/gramlot.d.ts +8 -0
- package/dist/gramlot.js +20 -1
- package/package.json +4 -4
- package/src/adapters/file-host.d.ts +29 -0
- package/src/adapters/file-host.js +6 -0
- package/src/adapters/host.d.ts +101 -0
- package/src/adapters/host.js +6 -0
- package/src/adapters/index.d.ts +13 -0
- package/src/adapters/index.js +7 -0
- package/src/adapters/page.d.ts +33 -0
- package/src/adapters/page.js +6 -0
- package/src/adapters/resources.d.ts +28 -0
- package/src/adapters/resources.js +3 -0
- package/src/bootstrap.d.ts +48 -0
- package/src/bootstrap.js +6 -0
- package/src/builder/gramlot-builder.d.ts +50 -0
- package/src/builder/gramlot-builder.js +6 -0
- package/src/dom.d.ts +25 -0
- package/src/gramlot.d.ts +99 -0
- package/src/gramlot.js +6 -0
- package/src/index.d.ts +23 -0
- package/src/index.js +8 -0
- package/src/inout.d.ts +45 -0
- package/src/inout.js +6 -0
- package/src/references.d.ts +33 -0
- package/src/references.js +6 -1
- package/src/renderer/gramlot-html-renderer.d.ts +37 -0
- package/src/renderer/gramlot-html-renderer.js +6 -0
- package/src/renderer/gramlot-renderer.d.ts +75 -0
- package/src/renderer/gramlot-renderer.js +6 -0
- package/src/renderer/gramlot-svg-renderer.d.ts +27 -0
- package/src/renderer/gramlot-svg-renderer.js +6 -0
- package/src/transport.d.ts +34 -0
- package/src/transport.js +7 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Gramlot browser runtime as one ES module: the same exports as the `@gramlot/gramlot` entry
|
|
3
|
+
* point (`Gramlot`, `PageBootstrap`, the builder, the renderers, `Bag` and the rest), bundled with
|
|
4
|
+
* its dependencies.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
export * from '../src/index.d.ts';
|
package/dist/gramlot.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/* @ts-self-types="./gramlot.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The Gramlot browser runtime as one ES module: the same exports as the `@gramlot/gramlot` entry
|
|
4
|
+
* point (`Gramlot`, `PageBootstrap`, the builder, the renderers, `Bag` and the rest), bundled with
|
|
5
|
+
* its dependencies.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
1
9
|
var __create = Object.create;
|
|
2
10
|
var __defProp = Object.defineProperty;
|
|
3
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -12832,6 +12840,15 @@ function* serializationNodes(bag, prefix = "") {
|
|
|
12832
12840
|
if (!node.resolver && value instanceof Bag) yield* serializationNodes(value, path);
|
|
12833
12841
|
}
|
|
12834
12842
|
}
|
|
12843
|
+
function xmlDateText(value) {
|
|
12844
|
+
const iso = value.toISOString();
|
|
12845
|
+
const isEpochDate = value.getUTCFullYear() === 1970 && value.getUTCMonth() === 0 && value.getUTCDate() === 1;
|
|
12846
|
+
const isMidnight = value.getUTCHours() === 0 && value.getUTCMinutes() === 0 && value.getUTCSeconds() === 0 && value.getUTCMilliseconds() === 0;
|
|
12847
|
+
if (isMidnight && !isEpochDate) return iso.slice(0, iso.indexOf("T"));
|
|
12848
|
+
const timestamp = iso.replace(/\.000Z$/, "Z");
|
|
12849
|
+
if (isEpochDate && !isMidnight) return timestamp.slice(timestamp.indexOf("T") + 1);
|
|
12850
|
+
return timestamp;
|
|
12851
|
+
}
|
|
12835
12852
|
var Bag = class _Bag {
|
|
12836
12853
|
static tytxSuffix = "X";
|
|
12837
12854
|
/**
|
|
@@ -14592,6 +14609,7 @@ var Bag = class _Bag {
|
|
|
14592
14609
|
* Serialize Bag to XML format.
|
|
14593
14610
|
*
|
|
14594
14611
|
* All values are converted to strings without type information.
|
|
14612
|
+
* Date values use ISO 8601 text in UTC (date, time, or datetime).
|
|
14595
14613
|
* For type-preserving serialization, use toTytx() instead.
|
|
14596
14614
|
*
|
|
14597
14615
|
* @param {Object} [options={}] - Serialization options.
|
|
@@ -14669,7 +14687,8 @@ ${" ".repeat(depth)}</${tag2}>`;
|
|
|
14669
14687
|
}
|
|
14670
14688
|
return `<${tag2}${attrsStr}></${tag2}>`;
|
|
14671
14689
|
}
|
|
14672
|
-
const
|
|
14690
|
+
const scalar = value instanceof Date && !Number.isNaN(value.getTime()) ? xmlDateText(value) : String(value);
|
|
14691
|
+
const text = this._escapeXml(scalar);
|
|
14673
14692
|
return `<${tag2}${attrsStr}>${text}</${tag2}>`;
|
|
14674
14693
|
}
|
|
14675
14694
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramlot/gramlot",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Declarative HTML/SVG interfaces with live data binding, authored in JavaScript or Python.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"prepack": "node scripts/build-runtime.mjs"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@genrojs/bag": ">=0.10.
|
|
20
|
-
"@genrojs/builders": ">=0.4.
|
|
21
|
-
"@genrojs/tytx": ">=0.16.
|
|
19
|
+
"@genrojs/bag": ">=0.10.3",
|
|
20
|
+
"@genrojs/builders": ">=0.4.2",
|
|
21
|
+
"@genrojs/tytx": ">=0.16.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"c8": "10.1.3",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A reference host on one pages folder.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import {Host} from './host.js';
|
|
7
|
+
import type {HostOptions} from './host.js';
|
|
8
|
+
import type {Page} from './page.js';
|
|
9
|
+
import type {Resources} from './resources.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Minimal reference `Host` on one pages folder, with APIs shared by Node.js and Bun. Page path
|
|
13
|
+
* `foo`: the file page `foo.js` first, then the folder page `foo/foo.js`. Beside the page file:
|
|
14
|
+
* `foo.css` and the page logic (the `Logic` export of the page module, or `foo_aux.js`).
|
|
15
|
+
*/
|
|
16
|
+
export class FileHost extends Host {
|
|
17
|
+
/** Create a host on `pagesDir`. */
|
|
18
|
+
constructor(pagesDir: string, options?: HostOptions);
|
|
19
|
+
/** The absolute pages folder. */
|
|
20
|
+
get pagesDir(): string;
|
|
21
|
+
/** Map `a/b` to `a/b.js`, else `a/b/b.js`, below the real pages folder; or raise `PageNotFound`. */
|
|
22
|
+
locatePage(path: string): Promise<string>;
|
|
23
|
+
/** Import the page module of `path` and return its `Page` export. */
|
|
24
|
+
resolvePage(path: string): Promise<typeof Page>;
|
|
25
|
+
/** `Page.css` URLs as written, then the companion CSS and the page logic. */
|
|
26
|
+
resolveResources(path: string, PageClass: typeof Page): Promise<Resources>;
|
|
27
|
+
/** Root-relative URL of a file below the pages folder; a file that leaves the folder raises. */
|
|
28
|
+
url(filename: string): Promise<string>;
|
|
29
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./file-host.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* A reference host on one pages folder.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import {realpath, stat} from 'node:fs/promises';
|
|
2
8
|
import {basename, dirname, extname, isAbsolute, join, relative, resolve, sep} from 'node:path';
|
|
3
9
|
import {pathToFileURL} from 'node:url';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The neutral host: registers pages and builds their Sources, with no HTTP engine.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {Page} from './page.js';
|
|
7
|
+
import type {Resources} from './resources.js';
|
|
8
|
+
|
|
9
|
+
export type {Resources};
|
|
10
|
+
|
|
11
|
+
/** The page is unknown, expired or owned by someone else. */
|
|
12
|
+
export class PageExpired extends Error {}
|
|
13
|
+
/** No page exists for the requested path. */
|
|
14
|
+
export class PageNotFound extends Error {}
|
|
15
|
+
/** An unknown remote Source method, as the Python `SourceNotFound`. */
|
|
16
|
+
export class SourceNotFound extends Error {}
|
|
17
|
+
/** The page registry is full. */
|
|
18
|
+
export class HostCapacity extends Error {}
|
|
19
|
+
|
|
20
|
+
/** The options of a `Host`. */
|
|
21
|
+
export interface HostOptions {
|
|
22
|
+
/** URL of the runtime bundle. */
|
|
23
|
+
runtimeUrl?: string;
|
|
24
|
+
/** URL of the `main` Source endpoint. */
|
|
25
|
+
mainUrl?: string;
|
|
26
|
+
/** URL of the remote Source endpoint. */
|
|
27
|
+
sourceUrl?: string;
|
|
28
|
+
/** URL of the page close endpoint. */
|
|
29
|
+
closeUrl?: string;
|
|
30
|
+
/** Id of the root element of the page. */
|
|
31
|
+
rootId?: string;
|
|
32
|
+
/** Seconds a registered page lives. */
|
|
33
|
+
pageTtl?: number;
|
|
34
|
+
/** Maximum number of registered pages. */
|
|
35
|
+
maxPages?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The result of `registerPage`. */
|
|
39
|
+
export interface RegisteredPage {
|
|
40
|
+
/** The id of the registered page. */
|
|
41
|
+
pageId: string;
|
|
42
|
+
/** The title of the page. */
|
|
43
|
+
title: string;
|
|
44
|
+
/** The resources of the page, in load order. */
|
|
45
|
+
resources: Resources;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The result of `openPage`. */
|
|
49
|
+
export interface OpenedPage {
|
|
50
|
+
/** The id of the registered page. */
|
|
51
|
+
pageId: string;
|
|
52
|
+
/** The bootstrap HTML document. */
|
|
53
|
+
html: string;
|
|
54
|
+
/** The nonce of the inline scripts, for the Content Security Policy. */
|
|
55
|
+
nonce: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Neutral host: no Node or Bun imports and no server startup side effects. The core never
|
|
60
|
+
* searches files: override `resolvePage` and `resolveResources` in concrete integrations.
|
|
61
|
+
*/
|
|
62
|
+
export class Host {
|
|
63
|
+
/** URL of the runtime bundle. */
|
|
64
|
+
runtimeUrl: string;
|
|
65
|
+
/** URL of the `main` Source endpoint. */
|
|
66
|
+
mainUrl: string;
|
|
67
|
+
/** URL of the remote Source endpoint. */
|
|
68
|
+
sourceUrl: string;
|
|
69
|
+
/** URL of the page close endpoint. */
|
|
70
|
+
closeUrl: string;
|
|
71
|
+
/** Id of the root element of the page. */
|
|
72
|
+
rootId: string;
|
|
73
|
+
/** Seconds a registered page lives. */
|
|
74
|
+
pageTtl: number;
|
|
75
|
+
/** Maximum number of registered pages. */
|
|
76
|
+
maxPages: number;
|
|
77
|
+
/** The registered pages by id. */
|
|
78
|
+
pages: Map<string, {PageClass: typeof Page; owner: unknown; expires: number}>;
|
|
79
|
+
/** Create a host. */
|
|
80
|
+
constructor(options?: HostOptions);
|
|
81
|
+
/** The Page class of `path`, or `PageNotFound`. */
|
|
82
|
+
resolvePage(path: string): Promise<typeof Page>;
|
|
83
|
+
/** The resources of the page at `path` in load order and without mount prefix, or `PageNotFound`. */
|
|
84
|
+
resolveResources(path: string, PageClass: typeof Page): Promise<Resources>;
|
|
85
|
+
/** Drop the expired pages. */
|
|
86
|
+
prune(): void;
|
|
87
|
+
/** Register a page independently of its HTTP or Worker transport. */
|
|
88
|
+
registerPage(path: string, options?: {owner?: unknown}): Promise<RegisteredPage>;
|
|
89
|
+
/** Register the page and return its bootstrap; `prefix` is the mount prefix added to root-relative URLs. */
|
|
90
|
+
openPage(path: string, options?: {owner?: unknown; prefix?: string}): Promise<OpenedPage>;
|
|
91
|
+
/** The `main` Source of a registered page, as TYTX text. */
|
|
92
|
+
main(pageId: string, options?: {owner?: unknown}): Promise<string>;
|
|
93
|
+
/** A remote Source of a registered page, as TYTX text; `params` null or omitted is `{}`. */
|
|
94
|
+
source(pageId: string, method: string, params?: Record<string, unknown> | null,
|
|
95
|
+
options?: {owner?: unknown}): Promise<string>;
|
|
96
|
+
/** Build the Source of a page by calling its `main` or a registered Source method. */
|
|
97
|
+
buildSource(pageId: string, method: string | null, params: Record<string, unknown>,
|
|
98
|
+
owner: unknown): Promise<string>;
|
|
99
|
+
/** Forget a registered page when `owner` owns it. */
|
|
100
|
+
closePage(pageId: string, options?: {owner?: unknown}): void;
|
|
101
|
+
}
|
package/src/adapters/host.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./host.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The neutral host: registers pages and builds their Sources, with no HTTP engine.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
2
8
|
import {Page, sourceMethod} from './page.js';
|
|
3
9
|
import {loadOrder} from './resources.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The server entry point of Gramlot: the host-side `Page` and `Host` classes, the file-based
|
|
3
|
+
* reference host and the resource name helpers. It is not part of the browser entry point.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export {Page, source} from './page.js';
|
|
8
|
+
export {Host, PageExpired, PageNotFound, SourceNotFound, HostCapacity} from './host.js';
|
|
9
|
+
export type {HostOptions, OpenedPage, RegisteredPage} from './host.js';
|
|
10
|
+
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
11
|
+
export {FileHost} from './file-host.js';
|
|
12
|
+
export {InvalidResourceName, parseRequires} from './resources.js';
|
|
13
|
+
export type {Resources} from './resources.js';
|
package/src/adapters/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The server entry point of Gramlot: the host-side `Page` and `Host` classes, the file-based
|
|
4
|
+
* reference host and the resource name helpers. It is not part of the browser entry point.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
1
8
|
// Server entry point: deliberately not re-exported by the browser entry point.
|
|
2
9
|
export {Page, source} from './page.js';
|
|
3
10
|
export {Host, PageExpired, PageNotFound, SourceNotFound, HostCapacity} from './host.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side page base class and the `source` registration.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Explicit registration of a remote Source method, equivalent to the Python `@source`.
|
|
10
|
+
* A Source method populates its `root` argument and returns nothing.
|
|
11
|
+
*/
|
|
12
|
+
export function source<T extends Function>(method: T): T;
|
|
13
|
+
|
|
14
|
+
/** The registered Source method `name` of `page`, or null. */
|
|
15
|
+
export function sourceMethod(page: Page, name: string): Function | null;
|
|
16
|
+
|
|
17
|
+
/** Host-side page base; unrelated to browser view components. */
|
|
18
|
+
export class Page {
|
|
19
|
+
/** The title of the page document. */
|
|
20
|
+
static title: string;
|
|
21
|
+
/** CSS URLs of the page. */
|
|
22
|
+
static css: string[];
|
|
23
|
+
/** Comma-separated names of the CSS resources of the page. */
|
|
24
|
+
static css_requires: string;
|
|
25
|
+
/** Comma-separated names of the JS resources of the page. */
|
|
26
|
+
static js_requires: string;
|
|
27
|
+
/** The builder class that authors the Source of the page. */
|
|
28
|
+
static sourceBuilder: typeof GramlotBuilder;
|
|
29
|
+
/** The id of the page, set by the host. */
|
|
30
|
+
pageId?: string;
|
|
31
|
+
/** Populate the `main` Source in `root`; subclasses must implement it. */
|
|
32
|
+
main(root: unknown): void | Promise<void>;
|
|
33
|
+
}
|
package/src/adapters/page.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource names and bootstrap load order; no file lookup and no HTTP engine.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** One segment of a resource or page name. */
|
|
8
|
+
export const SEGMENT: RegExp;
|
|
9
|
+
|
|
10
|
+
/** The Unicode White_Space characters stripped around resource names. */
|
|
11
|
+
export const SPACES: string;
|
|
12
|
+
|
|
13
|
+
/** A page declares its resources in an invalid way. */
|
|
14
|
+
export class InvalidResourceName extends Error {}
|
|
15
|
+
|
|
16
|
+
/** Parse `css_requires` or `js_requires`: comma-separated resource names, without duplicates. */
|
|
17
|
+
export function parseRequires(text: string): string[];
|
|
18
|
+
|
|
19
|
+
/** The CSS and JS resources of a page. */
|
|
20
|
+
export interface Resources {
|
|
21
|
+
/** CSS URLs. */
|
|
22
|
+
css: string[];
|
|
23
|
+
/** JS module URLs with their Logic group. */
|
|
24
|
+
js: {url: string; group: string | null}[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The resources with each URL once, in its last position; one JS URL with two groups raises. */
|
|
28
|
+
export function loadOrder(resources: Resources): Resources;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/* @ts-self-types="./resources.d.ts" */
|
|
1
2
|
/** Resource names and bootstrap load order; no file lookup and no HTTP engine.
|
|
2
3
|
* The Python counterpart is src/gramlot/server/resources.py; both apply the same
|
|
3
4
|
* rules. css_requires/js_requires names are interpreted by a Host with a resource
|
|
4
5
|
* system, not by the core.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
5
8
|
*/
|
|
6
9
|
/** One segment of a resource or page name. */
|
|
7
10
|
export const SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser start of one page.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {DomDocument} from './dom.d.ts';
|
|
7
|
+
import type {Gramlot, GramlotOptions} from './gramlot.js';
|
|
8
|
+
|
|
9
|
+
/** The JavaScript modules and CSS links of a page, in load order and with the mount prefix. */
|
|
10
|
+
export interface PageResources {
|
|
11
|
+
/** CSS stylesheet URLs. */
|
|
12
|
+
css: string[];
|
|
13
|
+
/** JavaScript module URLs, each with its Logic group (null for the page logic). */
|
|
14
|
+
js: {url: string; group: string | null}[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The configuration written by the host into the bootstrap HTML. */
|
|
18
|
+
export interface PageBootstrapOptions {
|
|
19
|
+
/** The options of the `Gramlot` instance, with the page id. */
|
|
20
|
+
config: GramlotOptions;
|
|
21
|
+
/** The resources of the page. */
|
|
22
|
+
resources: PageResources;
|
|
23
|
+
/** The document of the page. */
|
|
24
|
+
document?: DomDocument;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The browser start of one page. The host writes
|
|
29
|
+
* `await new PageBootstrap({config, resources}).run()` into the bootstrap HTML.
|
|
30
|
+
*/
|
|
31
|
+
export class PageBootstrap {
|
|
32
|
+
/** The configuration of the page. */
|
|
33
|
+
config: GramlotOptions;
|
|
34
|
+
/** The resources of the page. */
|
|
35
|
+
resources: PageResources;
|
|
36
|
+
/** The document of the page. */
|
|
37
|
+
document: DomDocument;
|
|
38
|
+
/** Create the bootstrap of one page. */
|
|
39
|
+
constructor(options: PageBootstrapOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Add the CSS links, import all JS modules, check the Logic classes, create the `Gramlot`
|
|
42
|
+
* instance, register the logic and start it. Resolves with the instance, or with null when the
|
|
43
|
+
* page closed during the imports.
|
|
44
|
+
*/
|
|
45
|
+
run(): Promise<Gramlot | null>;
|
|
46
|
+
/** Send the close request of a page that never got its `Gramlot` instance. */
|
|
47
|
+
closePage(): void;
|
|
48
|
+
}
|
package/src/bootstrap.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Gramlot vocabulary and inert authoring on the shared builder grammar.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import {HtmlBuilder} from '@genrojs/builders';
|
|
7
|
+
import type {SourceAttributes, SourceBag, SourceBagNode, ValidateNodeOptions} from '@genrojs/builders';
|
|
8
|
+
import type {GramlotHtmlRenderer} from '../renderer/gramlot-html-renderer.js';
|
|
9
|
+
import type {SourceReference} from '../references.js';
|
|
10
|
+
|
|
11
|
+
/** Gramlot vocabulary and inert authoring on the shared builder grammar. */
|
|
12
|
+
export class GramlotBuilder extends HtmlBuilder {
|
|
13
|
+
/** The dialect name, `'gramlot'`. */
|
|
14
|
+
static _name: string;
|
|
15
|
+
/** Tag prefixes of the parent dialects, from the names of the classes above `GramlotBuilder`. */
|
|
16
|
+
static get dialectPrefixes(): string[];
|
|
17
|
+
/** Create a builder; `collections` are grammar documents loaded into it. */
|
|
18
|
+
constructor(name?: string | null, options?: {collections?: unknown[]});
|
|
19
|
+
/** The binding runtime of the Gramlot page that owns this builder, or null for authoring alone; set by `Gramlot` right after creating the builder. */
|
|
20
|
+
binding: unknown;
|
|
21
|
+
/** The node with `nodeId`; inside a Gramlot page it reads the node ids of the binding runtime. */
|
|
22
|
+
nodeById(nodeId: string): SourceBagNode;
|
|
23
|
+
/** Load a grammar document into the builder. */
|
|
24
|
+
loadCollection(document: unknown): this;
|
|
25
|
+
/** The schema tag of an authored name, or null; the `gramlot_` prefix and excluded declarations raise. */
|
|
26
|
+
schemaTag(name: string): string | null;
|
|
27
|
+
/** An element call from the proxy on a Source Bag. */
|
|
28
|
+
bagCall(bag: SourceBag, tag: string, value?: unknown, attrs?: SourceAttributes): SourceBagNode;
|
|
29
|
+
/** An element call from the proxy on a Source node. */
|
|
30
|
+
commandOnNode(node: SourceBagNode, tag: string, value?: unknown, attrs?: SourceAttributes): SourceBagNode;
|
|
31
|
+
/** Check the value of a node, rejecting the excluded attributes. */
|
|
32
|
+
validateNodeValues(tag: string, value: unknown, attrs?: SourceAttributes): true;
|
|
33
|
+
/** Check a Source node, rejecting the excluded attributes. */
|
|
34
|
+
validateNode(node: SourceBagNode, options?: ValidateNodeOptions): true;
|
|
35
|
+
/** Insert a child; a plain object value of `dataSetter` becomes a Bag. */
|
|
36
|
+
setChild(bag: SourceBag, tag: string, value: unknown, attrs: SourceAttributes,
|
|
37
|
+
parentOverride?: SourceBagNode | null): SourceBagNode;
|
|
38
|
+
/** The string renderer of the Gramlot Source: static render, authoring stays inert. */
|
|
39
|
+
readonly renderer_html: GramlotHtmlRenderer;
|
|
40
|
+
/** Run `setup` on the Data and `main` on the Source root. */
|
|
41
|
+
create(): void;
|
|
42
|
+
/** Browser declarations are not executed by server authoring. */
|
|
43
|
+
computeLogic(): void;
|
|
44
|
+
/** Keep the mixed leading text when a scalar element gains children. */
|
|
45
|
+
promoteNodeValue(node: SourceBagNode, oldValue: unknown, branch: SourceBag): void;
|
|
46
|
+
/** Create a transportable reference descriptor for an authored node. */
|
|
47
|
+
reference(node: SourceBagNode, kind?: 'node' | 'dom'): SourceReference;
|
|
48
|
+
/** The Source encoded as TYTX text. */
|
|
49
|
+
toTytx(): string;
|
|
50
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./gramlot-builder.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The Gramlot vocabulary and inert authoring on the shared builder grammar.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import {Bag} from '@genrojs/bag';
|
|
2
8
|
import {HtmlBuilder, SourceBagNode, sourceTarget} from '@genrojs/builders';
|
|
3
9
|
import {toTytx} from '@genrojs/tytx';
|
package/src/dom.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loose names for the browser DOM objects that Gramlot receives and returns. A JSR package may not
|
|
3
|
+
* reference the `dom` library, so these are typed as `any` here; in a browser they are the objects
|
|
4
|
+
* of the same name.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// deno-lint-ignore no-explicit-any
|
|
10
|
+
/** A browser `Document`. */
|
|
11
|
+
export type DomDocument = any;
|
|
12
|
+
// deno-lint-ignore no-explicit-any
|
|
13
|
+
/** A browser `Element`. */
|
|
14
|
+
export type DomElement = any;
|
|
15
|
+
// deno-lint-ignore no-explicit-any
|
|
16
|
+
/** A browser `Node`. */
|
|
17
|
+
export type DomNode = any;
|
|
18
|
+
// deno-lint-ignore no-explicit-any
|
|
19
|
+
/** A browser `DocumentFragment`. */
|
|
20
|
+
export type DomFragment = any;
|
|
21
|
+
/** The part of a browser `Navigator` that sends the close beacon. */
|
|
22
|
+
export interface BeaconNavigator {
|
|
23
|
+
/** Queue `data` for delivery to `url`; returns false when the browser refuses it. */
|
|
24
|
+
sendBeacon(url: string, data?: unknown): boolean;
|
|
25
|
+
}
|
package/src/gramlot.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One Gramlot page in the browser.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {DomElement, DomDocument, DomNode} from './dom.d.ts';
|
|
7
|
+
import type {Bag} from '@genrojs/bag';
|
|
8
|
+
import type {SourceBag, SourceBagNode} from '@genrojs/builders';
|
|
9
|
+
import type {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
10
|
+
import type {GramlotRenderer} from './renderer/gramlot-renderer.js';
|
|
11
|
+
import type {InOut} from './inout.js';
|
|
12
|
+
import type {SourceReference} from './references.js';
|
|
13
|
+
import type {MainTransport} from './transport.js';
|
|
14
|
+
|
|
15
|
+
/** The options of a `Gramlot` instance. */
|
|
16
|
+
export interface GramlotOptions {
|
|
17
|
+
/** The id of the server page, as registered by the host. */
|
|
18
|
+
pageId?: string;
|
|
19
|
+
/** The URL of the `main` Source endpoint. */
|
|
20
|
+
mainUrl?: string;
|
|
21
|
+
/** The URL of the remote Source endpoint. */
|
|
22
|
+
sourceUrl?: string;
|
|
23
|
+
/** The URL of the page close endpoint. */
|
|
24
|
+
closeUrl?: string;
|
|
25
|
+
/** The id of the root element that receives the page. */
|
|
26
|
+
rootId?: string;
|
|
27
|
+
/** The root element; when null it is looked up by `rootId`. */
|
|
28
|
+
element?: DomElement | null;
|
|
29
|
+
/** The document of the page. */
|
|
30
|
+
document?: DomDocument;
|
|
31
|
+
/** A transport, or `false` for an instance with no server transport. */
|
|
32
|
+
transport?: MainTransport | false | null;
|
|
33
|
+
/** Grammar collections loaded into the builder. */
|
|
34
|
+
collections?: unknown[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The lifecycle state of a `Gramlot` instance. */
|
|
38
|
+
export type GramlotState = 'ready' | 'loading' | 'started' | 'failed' | 'disposed';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* One Gramlot page. The Data root is the builder's, the binding runtime subscribes to it before
|
|
42
|
+
* the renderer observes the Source.
|
|
43
|
+
*/
|
|
44
|
+
export class Gramlot {
|
|
45
|
+
/** The id of the server page. */
|
|
46
|
+
pageId: string | undefined;
|
|
47
|
+
/** The registry of the Logic classes of the page. */
|
|
48
|
+
logicRegistry: unknown;
|
|
49
|
+
/** The builder that owns the Source and the Data. */
|
|
50
|
+
builder: GramlotBuilder;
|
|
51
|
+
/** The binding runtime of the page. */
|
|
52
|
+
binding: unknown;
|
|
53
|
+
/** The Data Bag of the page. */
|
|
54
|
+
data: Bag;
|
|
55
|
+
/** The `gramlot.inout` object: send, receive, save and download Data branches. */
|
|
56
|
+
inout: InOut;
|
|
57
|
+
/** The Source Bag observed by the renderer. */
|
|
58
|
+
source: SourceBag;
|
|
59
|
+
/** The live renderer of the page. */
|
|
60
|
+
renderer: GramlotRenderer;
|
|
61
|
+
/** The server transport, or null. */
|
|
62
|
+
transport: MainTransport | null;
|
|
63
|
+
/** The remote Source requests in progress, by target node. */
|
|
64
|
+
remoteRequests: Map<SourceBagNode, {controller: AbortController}>;
|
|
65
|
+
/** The lifecycle state. */
|
|
66
|
+
state: GramlotState;
|
|
67
|
+
/** The controller aborted on dispose. */
|
|
68
|
+
abort: AbortController;
|
|
69
|
+
/** The pending `start` promise, while loading. */
|
|
70
|
+
loading?: Promise<Gramlot> | null;
|
|
71
|
+
/** Create the page instance; the construction order is the one of the source plan. */
|
|
72
|
+
constructor(options?: GramlotOptions);
|
|
73
|
+
/** Load `main` from the server and mount it; resolves with the instance. */
|
|
74
|
+
start(): Promise<Gramlot>;
|
|
75
|
+
/** Request `main` from the transport and mount it. */
|
|
76
|
+
loadMain(): Promise<Gramlot>;
|
|
77
|
+
/** Start from an embedded typed Source, with the same observed insertion as `main`. */
|
|
78
|
+
startSource(wire: SourceBag | string): Gramlot;
|
|
79
|
+
/** Validate and insert `main` in the Source. */
|
|
80
|
+
mountMainSource(wire: SourceBag | string): Gramlot;
|
|
81
|
+
/**
|
|
82
|
+
* A Source from a SourceBag or a TYTX wire; only Gramlot Source Bags are accepted, before any
|
|
83
|
+
* effect. The received Source activates its inline code.
|
|
84
|
+
*/
|
|
85
|
+
prepareSource(wire: SourceBag | string, builder?: GramlotBuilder): SourceBag;
|
|
86
|
+
/**
|
|
87
|
+
* Replace the children of one Source node with a remote Source, only after the incoming Source
|
|
88
|
+
* validates. Resolves with true when applied, false when superseded or cancelled.
|
|
89
|
+
*/
|
|
90
|
+
remoteSource(target: SourceBagNode, method: string, params?: Record<string, unknown>): Promise<boolean>;
|
|
91
|
+
/** Resolve a node or DOM reference descriptor. */
|
|
92
|
+
reference(descriptor: SourceReference): SourceBagNode | DomElement;
|
|
93
|
+
/** The Source node of the nearest element generated by the renderer. */
|
|
94
|
+
getBaseSourceNode(domNode: DomNode): SourceBagNode | null;
|
|
95
|
+
/** The element built from a Source node, or null. */
|
|
96
|
+
getDomNode(sourceNode: SourceBagNode): DomElement | null;
|
|
97
|
+
/** Dispose the page: abort requests, close bindings and the renderer, and close the server page. */
|
|
98
|
+
dispose(options?: {beacon?: boolean}): void;
|
|
99
|
+
}
|
package/src/gramlot.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./gramlot.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* One Gramlot page in the browser.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import {SourceBag, sourceBagFromTytx} from '@genrojs/builders';
|
|
2
8
|
import {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
3
9
|
import {GramlotBuilderBag} from './builder/source.js';
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser entry point of Gramlot: declarative HTML and SVG interfaces with live data binding.
|
|
3
|
+
* It exports the page instance (`Gramlot`), the bootstrap that starts it, the builder and the
|
|
4
|
+
* renderers, the transport and `gramlot.inout`, and re-exports `Bag` and `BagNode` from the Bag library.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
export {Gramlot} from './gramlot.js';
|
|
9
|
+
export type {GramlotOptions, GramlotState} from './gramlot.js';
|
|
10
|
+
export {PageBootstrap} from './bootstrap.js';
|
|
11
|
+
export type {PageBootstrapOptions, PageResources} from './bootstrap.js';
|
|
12
|
+
export {Page, source} from './adapters/page.js';
|
|
13
|
+
export {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
14
|
+
export {GramlotRenderer} from './renderer/gramlot-renderer.js';
|
|
15
|
+
export {GramlotHtmlRenderer} from './renderer/gramlot-html-renderer.js';
|
|
16
|
+
export {GramlotSvgRenderer} from './renderer/gramlot-svg-renderer.js';
|
|
17
|
+
export {Bag, BagNode} from '@genrojs/bag';
|
|
18
|
+
export {References} from './references.js';
|
|
19
|
+
export type {SourceReference} from './references.js';
|
|
20
|
+
export {MainTransport} from './transport.js';
|
|
21
|
+
export type {Fetcher} from './transport.js';
|
|
22
|
+
export {InOut} from './inout.js';
|
|
23
|
+
export type {BeaconNavigator, DomDocument, DomElement, DomFragment, DomNode} from './dom.d.ts';
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The browser entry point of Gramlot: declarative HTML and SVG interfaces with live data binding.
|
|
4
|
+
* It exports the page instance (`Gramlot`), the bootstrap that starts it, the builder and the
|
|
5
|
+
* renderers, the transport and `gramlot.inout`, and re-exports `Bag` and `BagNode` from the Bag library.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
1
9
|
export {Gramlot} from './gramlot.js';
|
|
2
10
|
export {PageBootstrap} from './bootstrap.js';
|
|
3
11
|
// A page module served for its Logic imports @gramlot/gramlot/page; the bootstrap import map points it here.
|
package/src/inout.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the page sends, receives, saves and downloads (`gramlot.inout`).
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {DomDocument} from './dom.d.ts';
|
|
7
|
+
import type {Bag} from '@genrojs/bag';
|
|
8
|
+
import type {Gramlot} from './gramlot.js';
|
|
9
|
+
|
|
10
|
+
/** The practical length limit of a mailto: URL in mail programs and browsers. */
|
|
11
|
+
export const MAILTO_LIMIT: number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What the page sends, receives, saves and downloads: `gramlot.inout`.
|
|
15
|
+
* Every function takes the Data path of a Bag branch; a missing path or a value that is not a Bag
|
|
16
|
+
* raises an Error.
|
|
17
|
+
*/
|
|
18
|
+
export class InOut {
|
|
19
|
+
/** The page this object belongs to. */
|
|
20
|
+
gramlot: Gramlot;
|
|
21
|
+
/** The document used for links, file inputs and the window. */
|
|
22
|
+
document: DomDocument;
|
|
23
|
+
/** Create the inout object of `gramlot`. */
|
|
24
|
+
constructor(gramlot: Gramlot, document: DomDocument);
|
|
25
|
+
/** The Bag at `path` in the Data. */
|
|
26
|
+
branch(path: string): Bag;
|
|
27
|
+
/** One `relative.path: value` line per leaf of the branch at `path`. */
|
|
28
|
+
mailText(path: string): string;
|
|
29
|
+
/** The mailto: URL of `sendMail`; longer than `MAILTO_LIMIT` raises an Error. */
|
|
30
|
+
mailtoUrl(path: string, email: string): string;
|
|
31
|
+
/** Prepare an email to `email` in the mail program of the user, with the data at `path` as text lines. */
|
|
32
|
+
sendMail(path: string, email: string): void;
|
|
33
|
+
/** POST the data at `path` as a JSON object to `url`; rejects on a status out of 2xx. */
|
|
34
|
+
sendHttp(path: string, url: string): Promise<Response>;
|
|
35
|
+
/** Save the data at `path` as a TYTX file, which `restore` reads back with its exact types. */
|
|
36
|
+
save(path: string, filename: string): void;
|
|
37
|
+
/** Read a TYTX file chosen by the user into `path`; resolves with the restored Bag. Needs a user gesture. */
|
|
38
|
+
restore(path: string): Promise<Bag>;
|
|
39
|
+
/** Export the data at `path` as `'json'` or `'xml'`; types become text. */
|
|
40
|
+
download(path: string, filename: string, format: 'json' | 'xml'): void;
|
|
41
|
+
/** Hand `text` to the browser as a file named `filename`. */
|
|
42
|
+
saveText(text: string, filename: string, type: string): void;
|
|
43
|
+
/** Follow `url` through a link, as a download when `filename` is given. */
|
|
44
|
+
open(url: string, filename?: string | null): void;
|
|
45
|
+
}
|
package/src/inout.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opaque references to mounted Source nodes and their DOM elements.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {DomElement} from './dom.d.ts';
|
|
7
|
+
import type {SourceBag, SourceBagNode} from '@genrojs/builders';
|
|
8
|
+
|
|
9
|
+
/** A transportable descriptor of one Source node, as made by `GramlotBuilder.reference`. */
|
|
10
|
+
export interface SourceReference {
|
|
11
|
+
/** The unique id stored in the `__ref` attribute of the Source node. */
|
|
12
|
+
$gramlotRef: string;
|
|
13
|
+
/** Whether the descriptor resolves to the Source node (`'node'`) or to its DOM element (`'dom'`). */
|
|
14
|
+
kind: 'node' | 'dom';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The table of the references of one mounted Source. */
|
|
18
|
+
export class References {
|
|
19
|
+
/** The mounted entries by reference id. */
|
|
20
|
+
entries: Map<string, {node: SourceBagNode; dom: DomElement}>;
|
|
21
|
+
/** The Source root against which a candidate block is validated, or null. */
|
|
22
|
+
sourceRoot: SourceBag | null;
|
|
23
|
+
/** Create a table for the Source `sourceRoot`. */
|
|
24
|
+
constructor(sourceRoot?: SourceBag | null);
|
|
25
|
+
/** Reject a duplicate reference id in `block`, also against the mounted entries not in `excluded`. */
|
|
26
|
+
validate(block: SourceBag, excluded?: Set<SourceBagNode>): void;
|
|
27
|
+
/** Register the reference of `node`, if it has one, with its DOM `element`. */
|
|
28
|
+
register(node: SourceBagNode, element: DomElement): void;
|
|
29
|
+
/** Remove the reference of `node`. */
|
|
30
|
+
remove(node: SourceBagNode): void;
|
|
31
|
+
/** The Source node or the DOM element a descriptor points to; raises when it is not mounted. */
|
|
32
|
+
resolve(reference: SourceReference): SourceBagNode | DomElement;
|
|
33
|
+
}
|
package/src/references.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/* @ts-self-types="./references.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* Opaque references to mounted Source nodes and their DOM elements.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
2
7
|
import {SourceBag} from '@genrojs/builders';
|
|
3
8
|
|
|
4
9
|
export class References {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The string renderer of a Gramlot Source.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import {HtmlRenderer} from '@genrojs/builders';
|
|
7
|
+
import type {BuilderBase, RendererBase, SourceBagNode} from '@genrojs/builders';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The string renderer of a Gramlot Source. It carries the Gramlot attribute rules on the builder
|
|
11
|
+
* `HtmlRenderer`: style shortcuts, the parent-dialect prefix, DOM names, `_text` as node text and
|
|
12
|
+
* the document wrapper. The live `GramlotRenderer` extends it and replaces only the output.
|
|
13
|
+
*/
|
|
14
|
+
export class GramlotHtmlRenderer extends HtmlRenderer {
|
|
15
|
+
/** The compiler of the `==` expressions: a string renderer has none. */
|
|
16
|
+
get inlineCompiler(): unknown;
|
|
17
|
+
/** HTML nodes render with this renderer; SVG nodes with one `GramlotSvgRenderer` owned by it. */
|
|
18
|
+
getRender(builder: BuilderBase): RendererBase;
|
|
19
|
+
/** Render a node; a data-element renders nothing. */
|
|
20
|
+
render(node: SourceBagNode, opts?: Record<string, unknown>): unknown;
|
|
21
|
+
/** The tag and attributes of a node, with the expressions evaluated and no script attributes. */
|
|
22
|
+
_handleMeta(node: SourceBagNode, runtimeAttrs: Record<string, unknown>): [string, Record<string, unknown>];
|
|
23
|
+
/** Evaluate the `==` attributes and node value through the inline compiler; without one they are null. */
|
|
24
|
+
evaluateExpressions(node: SourceBagNode, runtimeAttrs: Record<string, unknown>): Record<string, unknown>;
|
|
25
|
+
/** The value of the node text, after the `==` evaluation. */
|
|
26
|
+
expressionValue(node: SourceBagNode, item: unknown): unknown;
|
|
27
|
+
/** Put the noConvertStyle attributes of a node back among its attributes. */
|
|
28
|
+
restoreNativeAttributes(node: SourceBagNode, attrs: Record<string, unknown>): Record<string, unknown>;
|
|
29
|
+
/** The attributes with Gramlot style shortcuts, prefixes and DOM names applied. */
|
|
30
|
+
// deno-lint-ignore no-explicit-any
|
|
31
|
+
adaptAttrs(attrs: any): any;
|
|
32
|
+
/** The HTML string of one node. */
|
|
33
|
+
renderedItem(node: SourceBagNode, item: unknown, runtimeAttrs: Record<string, unknown>,
|
|
34
|
+
opts?: Record<string, unknown>): string;
|
|
35
|
+
/** Finish the output; the `doctype` option prepends the doctype and wraps in `<html>` when needed. */
|
|
36
|
+
finalize(result: unknown, target?: unknown, opts?: Record<string, unknown>): string | null;
|
|
37
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./gramlot-html-renderer.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The string renderer of a Gramlot Source.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import {HtmlBuilder, HtmlRenderer, SvgBuilder, sourceAttributeItems} from '@genrojs/builders';
|
|
2
8
|
import {GramlotSvgRenderer} from './gramlot-svg-renderer.js';
|
|
3
9
|
import {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live renderer of a Gramlot page.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {DomElement, DomNode, DomDocument, DomFragment} from '../dom.d.ts';
|
|
7
|
+
import type {SourceBag, SourceBagNode} from '@genrojs/builders';
|
|
8
|
+
import type {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
9
|
+
import type {References} from '../references.js';
|
|
10
|
+
import {GramlotHtmlRenderer} from './gramlot-html-renderer.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Own the live DOM lifecycle driven by typed Source insert, update and delete events.
|
|
14
|
+
* The attribute rules are `GramlotHtmlRenderer`'s; this class replaces its output with DOM elements.
|
|
15
|
+
*/
|
|
16
|
+
export class GramlotRenderer extends GramlotHtmlRenderer {
|
|
17
|
+
/** The renderer output type: DOM objects. */
|
|
18
|
+
static renderType: string;
|
|
19
|
+
/** The observed Source. */
|
|
20
|
+
source: SourceBag;
|
|
21
|
+
/** The element that receives the rendered page. */
|
|
22
|
+
destination: DomElement;
|
|
23
|
+
/** The table of the references of the Source. */
|
|
24
|
+
references: References;
|
|
25
|
+
/** True after `dispose`. */
|
|
26
|
+
disposed: boolean;
|
|
27
|
+
/** The id of this renderer instance, which scopes generated radio names. */
|
|
28
|
+
instanceId: string;
|
|
29
|
+
/** Create the live renderer of one page; `binding` is the binding runtime of the page. */
|
|
30
|
+
constructor(builder: GramlotBuilder, source: SourceBag, destination: DomElement, options?: {binding?: unknown});
|
|
31
|
+
/** The binding runtime of the page. */
|
|
32
|
+
get binding(): unknown;
|
|
33
|
+
/** The inline compiler of the page: the live renderer evaluates the `==` expressions. */
|
|
34
|
+
get inlineCompiler(): unknown;
|
|
35
|
+
/** The resolved projection of a node: runtime values, then the `==` expressions. */
|
|
36
|
+
evaluateExpressions(node: SourceBagNode, runtimeAttrs: Record<string, unknown>): Record<string, unknown>;
|
|
37
|
+
/** Render a node, or a structural Source fragment, to DOM; a data-element renders nothing. */
|
|
38
|
+
render(node: SourceBagNode, opts?: Record<string, unknown>): DomNode | null;
|
|
39
|
+
/** Render a structural Source fragment to a DOM fragment. */
|
|
40
|
+
renderFragment(node: SourceBagNode, opts?: Record<string, unknown>): DomFragment;
|
|
41
|
+
/** Create one detached element for a node (a DOM element; typed `any` because it replaces the string output of the base class). */
|
|
42
|
+
// deno-lint-ignore no-explicit-any
|
|
43
|
+
renderedItem(node: SourceBagNode, item: unknown, runtimeAttrs: Record<string, unknown>,
|
|
44
|
+
opts?: {tag?: string; document?: DomDocument}): any;
|
|
45
|
+
/** Validate a detached candidate Source without changing the observed Source. */
|
|
46
|
+
validateCandidate(block: SourceBag, options?: {replacingNode?: SourceBagNode | null}): void;
|
|
47
|
+
/** Suspend rendering for a mounted branch; the Source keeps changing normally. */
|
|
48
|
+
freeze(node: SourceBagNode): void;
|
|
49
|
+
/** Resume the whole branch and build its current Source once. */
|
|
50
|
+
unfreeze(node: SourceBagNode): void;
|
|
51
|
+
/** Source event intake: queue the event and process the queue in arrival order. */
|
|
52
|
+
receive(event: {evt: string; node: SourceBagNode; [key: string]: unknown}): void;
|
|
53
|
+
/** Whether a node still belongs to the observed Source. */
|
|
54
|
+
attached(node: SourceBagNode): boolean;
|
|
55
|
+
/** Build an inserted node and report the build to the binding runtime. */
|
|
56
|
+
insert(node: SourceBagNode): void;
|
|
57
|
+
/** Build the DOM of a node inside `container`, before `before`. */
|
|
58
|
+
buildNode(node: SourceBagNode, container: DomNode, before?: DomNode | null, parent?: unknown): void;
|
|
59
|
+
/** Set the container of a render record and of its children. */
|
|
60
|
+
assignContainer(record: unknown, container: DomNode): void;
|
|
61
|
+
/** Apply a Source update event to the DOM of a node. */
|
|
62
|
+
update(node: SourceBagNode, event: string): void;
|
|
63
|
+
/** Project the resolved attributes and value of a node on its DOM elements. */
|
|
64
|
+
project(node: SourceBagNode, change?: unknown): void;
|
|
65
|
+
/** The element built from a Source node, or null. */
|
|
66
|
+
getDomNode(sourceNode: SourceBagNode): DomElement | null;
|
|
67
|
+
/** The Source node of the nearest element generated by this renderer, climbing from `domNode`, or null. */
|
|
68
|
+
getBaseSourceNode(domNode: DomNode): SourceBagNode | null;
|
|
69
|
+
/** Register a cleanup callback run when the DOM of a node is removed; returns the function that unregisters it. */
|
|
70
|
+
onDispose(node: SourceBagNode, callback: () => void): () => void;
|
|
71
|
+
/** Remove the DOM of a node and run its cleanup callbacks. */
|
|
72
|
+
remove(node: SourceBagNode): void;
|
|
73
|
+
/** Stop observing the Source and remove all rendered DOM. */
|
|
74
|
+
dispose(): void;
|
|
75
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./gramlot-renderer.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The live renderer of a Gramlot page.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import {BuilderBase, SourceBag, sourceTarget} from '@genrojs/builders';
|
|
2
8
|
import {HtmlElement} from '../view/html.js';
|
|
3
9
|
import {ControlAdapter, RadioGroups, SelectControl} from '../view/controls.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The renderer of the SVG nodes of a Gramlot Source.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import {SvgRenderer} from '@genrojs/builders';
|
|
7
|
+
import type {SourceBagNode} from '@genrojs/builders';
|
|
8
|
+
import type {GramlotHtmlRenderer} from './gramlot-html-renderer.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The renderer of the SVG nodes of a Gramlot Source, owned by a `GramlotHtmlRenderer`.
|
|
12
|
+
* Output: a string under a string owner, the owner's DOM under the live `GramlotRenderer`.
|
|
13
|
+
*/
|
|
14
|
+
export class GramlotSvgRenderer extends SvgRenderer {
|
|
15
|
+
/** Create the renderer of `builder`, owned by `owner`. */
|
|
16
|
+
constructor(builder: unknown, owner: GramlotHtmlRenderer);
|
|
17
|
+
/** The HTML renderer that owns this one. */
|
|
18
|
+
get owner(): GramlotHtmlRenderer;
|
|
19
|
+
/** The tag and attributes of a node, with the expressions evaluated by the owner. */
|
|
20
|
+
_handleMeta(node: SourceBagNode, runtimeAttrs: Record<string, unknown>): [string, Record<string, unknown>];
|
|
21
|
+
/** The attributes with the metadata, binding attributes and null values removed, and Gramlot names. */
|
|
22
|
+
// deno-lint-ignore no-explicit-any
|
|
23
|
+
adaptAttrs(attrs: any): any;
|
|
24
|
+
/** The owner's DOM element under the live renderer; otherwise the SVG string. */
|
|
25
|
+
renderedItem(node: SourceBagNode, item: unknown, runtimeAttrs: Record<string, unknown>,
|
|
26
|
+
opts?: Record<string, unknown>): string;
|
|
27
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./gramlot-svg-renderer.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The renderer of the SVG nodes of a Gramlot Source.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import {SvgRenderer, svgAttributes} from '@genrojs/builders';
|
|
2
8
|
import {
|
|
3
9
|
boundaryAttributes, domNames, requireNoScriptAttributes, textValue, withoutBindingAttributes, withoutNullValues,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main and remote Source transport; application pages do not issue fetch calls.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type {BeaconNavigator} from './dom.d.ts';
|
|
7
|
+
|
|
8
|
+
/** The fetch function used by the transport. */
|
|
9
|
+
export type Fetcher = (input: string, init?: RequestInit) => Promise<Response>;
|
|
10
|
+
|
|
11
|
+
/** The page-to-host transport: loads `main` and remote Sources and closes the server page. */
|
|
12
|
+
export class MainTransport {
|
|
13
|
+
/** The URL of the `main` endpoint. */
|
|
14
|
+
url: string;
|
|
15
|
+
/** The function that sends the requests. */
|
|
16
|
+
fetcher: Fetcher;
|
|
17
|
+
/** The URL of the remote Source endpoint. */
|
|
18
|
+
sourceUrl: string;
|
|
19
|
+
/** The URL of the page close endpoint. */
|
|
20
|
+
closeUrl: string;
|
|
21
|
+
/** The navigator whose `sendBeacon` sends the close request on page hide. */
|
|
22
|
+
navigator: BeaconNavigator;
|
|
23
|
+
/** Create a transport with the endpoint URLs of the page. */
|
|
24
|
+
constructor(url: string, fetcher?: Fetcher, sourceUrl?: string, closeUrl?: string,
|
|
25
|
+
navigator?: BeaconNavigator);
|
|
26
|
+
/** Request the `main` Source of `pageId`; resolves with the TYTX text. */
|
|
27
|
+
main(pageId: string, signal?: AbortSignal): Promise<string>;
|
|
28
|
+
/** Request the remote Source `method` of `pageId` with `params`; resolves with the TYTX text. */
|
|
29
|
+
source(pageId: string, method: string, params: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
|
|
30
|
+
/** POST a JSON payload to `url`; resolves with the response text, rejects on a non-2xx status. */
|
|
31
|
+
request(operation: string, url: string, payload: unknown, signal?: AbortSignal): Promise<string>;
|
|
32
|
+
/** Ask the host to close the page, with a beacon or a best-effort fetch; delivery failure is ignored. */
|
|
33
|
+
close(pageId: string, options?: {beacon?: boolean}): void;
|
|
34
|
+
}
|
package/src/transport.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/* @ts-self-types="./transport.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* Main and remote Source transport; application pages do not issue fetch calls.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/** The page-to-host transport: loads `main` and remote Sources and closes the server page. */
|
|
2
8
|
export class MainTransport {
|
|
3
9
|
constructor(url, fetcher = globalThis.fetch?.bind(globalThis), sourceUrl = '/gramlot/source',
|
|
4
10
|
closeUrl = '/gramlot/close', navigator = globalThis.navigator) {
|