@gramlot/gramlot 0.2.4 → 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 +287 -132
- package/package.json +4 -4
- package/src/adapters/file-host.d.ts +29 -0
- package/src/adapters/file-host.js +18 -4
- package/src/adapters/host.d.ts +101 -0
- package/src/adapters/host.js +9 -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/binding/inline.js +1 -1
- package/src/binding/logic.js +2 -2
- 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 +8 -0
- package/src/index.d.ts +23 -0
- package/src/index.js +11 -0
- package/src/inout.d.ts +45 -0
- package/src/inout.js +135 -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
package/src/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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';
|
|
11
|
+
// A page module served for its Logic imports @gramlot/gramlot/page; the bootstrap import map points it here.
|
|
12
|
+
export {Page, source} from './adapters/page.js';
|
|
3
13
|
export {GramlotBuilder} from './builder/gramlot-builder.js';
|
|
4
14
|
export {GramlotRenderer} from './renderer/gramlot-renderer.js';
|
|
5
15
|
export {GramlotHtmlRenderer} from './renderer/gramlot-html-renderer.js';
|
|
@@ -7,3 +17,4 @@ export {GramlotSvgRenderer} from './renderer/gramlot-svg-renderer.js';
|
|
|
7
17
|
export {Bag, BagNode} from '@genrojs/bag';
|
|
8
18
|
export {References} from './references.js';
|
|
9
19
|
export {MainTransport} from './transport.js';
|
|
20
|
+
export {InOut} from './inout.js';
|
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
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* @ts-self-types="./inout.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* What the page sends, receives, saves and downloads (`gramlot.inout`).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import {Bag} from '@genrojs/bag';
|
|
8
|
+
|
|
9
|
+
/** The practical length limit of a mailto: URL in mail programs and browsers. */
|
|
10
|
+
export const MAILTO_LIMIT = 2000;
|
|
11
|
+
|
|
12
|
+
/** A leaf value as text: a Date at UTC midnight is a date (TYTX `D`), any other Date a datetime. */
|
|
13
|
+
function leafText(value) {
|
|
14
|
+
if (!(value instanceof Date)) return String(value ?? '');
|
|
15
|
+
const text = value.toISOString();
|
|
16
|
+
return text.endsWith('T00:00:00.000Z') ? text.slice(0, 10) : text;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* What the page sends, receives, saves and downloads: `gramlot.inout` (decisions of 2026-10-03).
|
|
21
|
+
* Every function takes the Data path of a Bag branch; a missing path or a value that is not a Bag
|
|
22
|
+
* raises an Error. Part of the browser runtime, so Python and JavaScript pages use it alike, from
|
|
23
|
+
* inline code or from their Logic.
|
|
24
|
+
*/
|
|
25
|
+
export class InOut {
|
|
26
|
+
constructor(gramlot, document) {
|
|
27
|
+
this.gramlot = gramlot;
|
|
28
|
+
this.document = document;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The Bag at path in the Data. */
|
|
32
|
+
branch(path) {
|
|
33
|
+
const value = this.gramlot.data.getItem(path);
|
|
34
|
+
if (!(value instanceof Bag)) throw new Error(`gramlot.inout: no data Bag at '${path}'`);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One `relative.path: value` line per leaf of the branch at path. */
|
|
39
|
+
mailText(path) {
|
|
40
|
+
const lines = [];
|
|
41
|
+
const walk = (bag, prefix) => {
|
|
42
|
+
for (const node of bag.getNodes()) {
|
|
43
|
+
const label = prefix + node.label;
|
|
44
|
+
if (node.value instanceof Bag) walk(node.value, `${label}.`);
|
|
45
|
+
else lines.push(`${label}: ${leafText(node.value)}`);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
walk(this.branch(path), '');
|
|
49
|
+
return lines.join('\n');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The mailto: URL of sendMail; longer than MAILTO_LIMIT raises an Error. */
|
|
53
|
+
mailtoUrl(path, email) {
|
|
54
|
+
const url = `mailto:${encodeURIComponent(email)}?subject=${encodeURIComponent(this.document.title)}` +
|
|
55
|
+
`&body=${encodeURIComponent(this.mailText(path))}`;
|
|
56
|
+
if (url.length > MAILTO_LIMIT) {
|
|
57
|
+
throw new Error(`gramlot.inout.sendMail: the email of '${path}' is ${url.length} characters long, ` +
|
|
58
|
+
`over the mailto: limit of ${MAILTO_LIMIT}; send it with sendHttp or save it as a file`);
|
|
59
|
+
}
|
|
60
|
+
return url;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Prepare an email to email in the mail program of the user, with the data at path as text lines. */
|
|
64
|
+
sendMail(path, email) {
|
|
65
|
+
this.open(this.mailtoUrl(path, email));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** POST the data at path as a JSON object to url; resolves with the Response, rejects on a status out of 2xx. */
|
|
69
|
+
async sendHttp(path, url) {
|
|
70
|
+
const body = JSON.stringify(this.branch(path).asDict(false, false, true));
|
|
71
|
+
const response = await this.document.defaultView.fetch(url, {
|
|
72
|
+
method: 'POST', headers: {'Content-Type': 'application/json'}, body,
|
|
73
|
+
});
|
|
74
|
+
if (!response.ok) throw new Error(`gramlot.inout.sendHttp: ${url} answered ${response.status}`);
|
|
75
|
+
return response;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Save the data at path as a TYTX file, which restore reads back with its exact types. */
|
|
79
|
+
save(path, filename) {
|
|
80
|
+
this.saveText(this.branch(path).toTytx(), filename, 'application/json');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Read a TYTX file chosen by the user into path; resolves with the restored Bag. Needs a user gesture. */
|
|
84
|
+
restore(path) {
|
|
85
|
+
const input = this.document.createElement('input');
|
|
86
|
+
input.type = 'file';
|
|
87
|
+
input.accept = '.json,application/json';
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
input.addEventListener('change', async () => {
|
|
90
|
+
try {
|
|
91
|
+
const bag = Bag.fromTytx(await input.files[0].text());
|
|
92
|
+
this.gramlot.data.setItem(path, bag);
|
|
93
|
+
resolve(bag);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
reject(new Error(`gramlot.inout.restore: the file is not a saved Gramlot branch: ${error.message}`,
|
|
96
|
+
{cause: error}));
|
|
97
|
+
}
|
|
98
|
+
}, {once: true});
|
|
99
|
+
input.click();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Export the data at path as 'json' (Bag.toJson) or 'xml' (Bag.toXml, inside one root element named
|
|
104
|
+
* after the last segment of path); types become text. */
|
|
105
|
+
download(path, filename, format) {
|
|
106
|
+
if (!['json', 'xml'].includes(format)) {
|
|
107
|
+
throw new Error(`gramlot.inout.download: format '${format}' is not 'json' or 'xml'`);
|
|
108
|
+
}
|
|
109
|
+
const bag = this.branch(path);
|
|
110
|
+
if (format === 'json') {
|
|
111
|
+
this.saveText(bag.toJson(false), filename, 'application/json');
|
|
112
|
+
} else {
|
|
113
|
+
const root = path.split('.').at(-1);
|
|
114
|
+
this.saveText(`<?xml version='1.0' encoding='UTF-8'?>\n<${root}>${bag.toXml()}</${root}>`, filename,
|
|
115
|
+
'application/xml');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Hand text to the browser as a file named filename. */
|
|
120
|
+
saveText(text, filename, type) {
|
|
121
|
+
const window = this.document.defaultView;
|
|
122
|
+
const url = window.URL.createObjectURL(new window.Blob([text], {type}));
|
|
123
|
+
this.open(url, filename);
|
|
124
|
+
// The download reads the Blob after the click returns.
|
|
125
|
+
window.setTimeout(() => window.URL.revokeObjectURL(url), 1000);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Follow url through a link, as a download when filename is given. */
|
|
129
|
+
open(url, filename = null) {
|
|
130
|
+
const link = this.document.createElement('a');
|
|
131
|
+
link.href = url;
|
|
132
|
+
if (filename !== null) link.download = filename;
|
|
133
|
+
link.click();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -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) {
|