@gramlot/gramlot-examples 0.2.7 → 0.2.9
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/README.md +2 -2
- package/package.json +2 -2
- package/src/gramlot_examples/gallery/dist/frame.js +1 -1
- package/src/gramlot_examples/gallery/dist/gallery.js +1 -1
- package/src/gramlot_examples/index.js +1 -1
- package/src/gramlot_examples/pages/README.md +1 -1
- package/src/gramlot_examples/pages/binding/08_freeze.js +3 -3
- package/src/gramlot_examples/pages/controllers/03_named_logic.js +1 -1
- package/src/gramlot_examples/pages/controllers/03_named_logic.md +1 -1
- package/src/gramlot_examples/pages/controllers/07_events.md +1 -1
- package/src/gramlot_examples/pages/controllers/08_end_to_end.js +3 -3
- package/src/gramlot_examples/pages/html_svg/10_cards_with_icons.js +1 -1
- package/src/gramlot_examples/pages/html_svg/13_live_source.js +9 -9
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install @gramlot/gramlot-examples
|
|
|
12
12
|
[](https://pypi.org/project/gramlot-examples/)
|
|
13
13
|
[](https://www.npmjs.com/package/@gramlot/gramlot-examples)
|
|
14
14
|
|
|
15
|
-
Current release: 0.2.
|
|
15
|
+
Current release: 0.2.9.
|
|
16
16
|
|
|
17
17
|
The repositories of the family are described in
|
|
18
18
|
[The Gramlot family](https://github.com/gramlot-org/gramlot/blob/main/docs/public/055-family.md)
|
|
@@ -37,7 +37,7 @@ Each `NN_name.js` exports `Page` and `Logic`; the Python page `NN_name.py` takes
|
|
|
37
37
|
The gallery page lists the families and opens each example beside its README and
|
|
38
38
|
source. `build_gallery` (Python) and `buildGallery` (JavaScript) return its routes and
|
|
39
39
|
static assets; each environment (`gramlot-py-server`, `gramlot-js-server`) serves the
|
|
40
|
-
gallery with its own
|
|
40
|
+
gallery with its own server and can add its own catalogue. Guide:
|
|
41
41
|
[GE-010](https://github.com/gramlot-org/gramlot-examples/blob/main/docs/010-gallery.md).
|
|
42
42
|
|
|
43
43
|
```sh
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramlot/gramlot-examples",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Gramlot example pages, the gallery page and its catalogue.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"prepack": "node scripts/build-browser.mjs"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@gramlot/gramlot": ">=0.2.
|
|
17
|
+
"@gramlot/gramlot": ">=0.2.12"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@genrojs/bag": ">=0.10.1",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
// src/gramlot_examples/gallery/browser/frame-entry.js
|
|
21
21
|
var script = document.currentScript;
|
|
22
22
|
queueMicrotask(() => {
|
|
23
|
-
const renderer = window.gramlot.renderer;
|
|
23
|
+
const renderer = window.gramlot.src.renderer;
|
|
24
24
|
const record = renderer.elements.get(script);
|
|
25
25
|
if (!record || renderer.disposed || renderer.records.get(record.node) !== record) return;
|
|
26
26
|
mountFrameTheme(renderer, record.node);
|
|
@@ -21253,7 +21253,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
|
|
|
21253
21253
|
// src/gramlot_examples/gallery/browser/entry.js
|
|
21254
21254
|
var script = document.currentScript;
|
|
21255
21255
|
queueMicrotask(() => {
|
|
21256
|
-
const renderer = window.gramlot.renderer;
|
|
21256
|
+
const renderer = window.gramlot.src.renderer;
|
|
21257
21257
|
const record = renderer.elements.get(script.parentElement);
|
|
21258
21258
|
if (!record || renderer.disposed || renderer.records.get(record.node) !== record) return;
|
|
21259
21259
|
mountGallery(renderer, record.node);
|
|
@@ -37,7 +37,7 @@ function readCatalog(catalog, pages, common) {
|
|
|
37
37
|
* Each item of `catalogs` is a pair `[catalog.json, pages folder]` of one environment.
|
|
38
38
|
* `routes` maps each key to its JavaScript page, its same-name stylesheet and its logic
|
|
39
39
|
* module: `NN_name_aux.js`, else `NN_name.js`, the page module itself, whose `Logic` export
|
|
40
|
-
* the
|
|
40
|
+
* the server takes (the server throws when both hold a `Logic`). `assets` maps each URL to its
|
|
41
41
|
* file and media type. Nothing is written or served here.
|
|
42
42
|
*/
|
|
43
43
|
export function buildGallery({catalogs = []} = {}) {
|
|
@@ -14,7 +14,7 @@ JavaScript, in three families:
|
|
|
14
14
|
Each example is a file page: `NN_name.py`, its JavaScript equivalent `NN_name.js`,
|
|
15
15
|
its README `NN_name.md`, and where needed a same-name stylesheet `NN_name.css`.
|
|
16
16
|
`NN_name.js` exports `Page` and `Logic`: the JavaScript page uses both, the Python
|
|
17
|
-
page takes `Logic` from it. The pages use only what the core `
|
|
17
|
+
page takes `Logic` from it. The pages use only what the core `GramlotFileServer` serves:
|
|
18
18
|
`Page.css`, the same-name stylesheet and the `Logic` of the page module. The gallery
|
|
19
19
|
adds its own files: the frame script, a staged `<key>_aux.js` per example and its
|
|
20
20
|
assets ([GE-010 §025](https://github.com/gramlot-org/gramlot-examples/blob/main/docs/010-gallery.md#ge-010-025)).
|
|
@@ -28,11 +28,11 @@ export class Page extends BasePage {
|
|
|
28
28
|
/** Logic of 08_freeze.py and 08_freeze.js: each button's nested controller calls one method. */
|
|
29
29
|
export class Logic {
|
|
30
30
|
sourceNode(nodeId) {
|
|
31
|
-
return this.page.source.getNodeByAttr('node_id', nodeId);
|
|
31
|
+
return this.page.src.source.getNodeByAttr('node_id', nodeId);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
freeze(node) {
|
|
35
|
-
this.page.renderer.freeze(this.sourceNode('board'));
|
|
35
|
+
this.page.src.renderer.freeze(this.sourceNode('board'));
|
|
36
36
|
node.SET('.frozen', true);
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -47,7 +47,7 @@ export class Logic {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
thaw(node) {
|
|
50
|
-
this.page.renderer.unfreeze(this.sourceNode('board'));
|
|
50
|
+
this.page.src.renderer.unfreeze(this.sourceNode('board'));
|
|
51
51
|
node.SET('.frozen', false);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -28,7 +28,7 @@ export class Page extends BasePage {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Logic of 03_named_logic.py and 03_named_logic.js. The
|
|
31
|
+
* Logic of 03_named_logic.py and 03_named_logic.js. The core GramlotFileServer serves this module as the
|
|
32
32
|
* root group of the page logic: `func='finalPrice'` names the method below.
|
|
33
33
|
*/
|
|
34
34
|
export class Logic {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 03 · Named logic
|
|
2
2
|
|
|
3
|
-
The code of this page lives in `class Logic`, which `03_named_logic.js` exports beside `Page`. The
|
|
3
|
+
The code of this page lives in `class Logic`, which `03_named_logic.js` exports beside `Page`. The core GramlotFileServer serves that module as the page logic for the JavaScript page and for the Python page `03_named_logic.py` alike.
|
|
4
4
|
|
|
5
5
|
- `func='finalPrice'` names a method of `Logic`. A formula method receives one object with the resolved parameters and returns the result: 10% off from the `threshold`.
|
|
6
6
|
- A controller method receives its Source node and the parameters. `node.SET('.changes', …)` writes relative to the node's context.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- The value is inline code with `this` = the declaring node and the parameter `event`. `this.SET('.path', …)` writes relative to the node's context.
|
|
6
6
|
- The handler runs with the declaring node also when the event hits a descendant: a click on a chip reaches the section's handler, and `event.target` names the chip.
|
|
7
|
-
- A value of dotted names, such as `gui.focused`, is named logic of a `js_requires` group instead. `js_requires` needs a
|
|
7
|
+
- A value of dotted names, such as `gui.focused`, is named logic of a `js_requires` group instead. `js_requires` needs a server with a resource system: the core `GramlotFileServer` and the current adapters have none and raise an error for any name, so this page uses inline code. The resource system comes with genro-kajenn, part of Genro.
|
|
8
8
|
- Removing the node removes its listeners.
|
|
9
9
|
|
|
10
10
|
**Try it:** Click the green chip, type a word, then add `connect_onfocus` to the field.
|
|
@@ -58,7 +58,7 @@ export class Page extends BasePage {
|
|
|
58
58
|
/** Logic of 08_end_to_end.py and 08_end_to_end.js: the named logic of the story. */
|
|
59
59
|
export class Logic {
|
|
60
60
|
sourceNode(nodeId) {
|
|
61
|
-
return this.page.source.getNodeByAttr('node_id', nodeId);
|
|
61
|
+
return this.page.src.source.getNodeByAttr('node_id', nodeId);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/** Controller of the total: the circle turns red above 10. */
|
|
@@ -73,7 +73,7 @@ export class Logic {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
freeze() {
|
|
76
|
-
this.page.renderer.freeze(this.sourceNode('later'));
|
|
76
|
+
this.page.src.renderer.freeze(this.sourceNode('later'));
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
removeNote() {
|
|
@@ -83,6 +83,6 @@ export class Logic {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
thaw() {
|
|
86
|
-
this.page.renderer.unfreeze(this.sourceNode('later'));
|
|
86
|
+
this.page.src.renderer.unfreeze(this.sourceNode('later'));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -18,7 +18,7 @@ export class Page extends BasePage {
|
|
|
18
18
|
for (const [title, description, kind] of CARDS) {
|
|
19
19
|
const card = cards.article({node_label: kind, class: 'card stack'});
|
|
20
20
|
card.button('×', {type: 'button', class: 'card-remove', aria_label: `Remove ${title}`,
|
|
21
|
-
connect_onclick: `window.gramlot.builder.source.getItem('main.page.cards').popNode('${kind}')`});
|
|
21
|
+
connect_onclick: `window.gramlot.src.builder.source.getItem('main.page.cards').popNode('${kind}')`});
|
|
22
22
|
const icon = card.svg({viewBox: '0 0 64 64', width: 64, height: 64, aria_hidden: 'true'});
|
|
23
23
|
this.icon(icon, kind);
|
|
24
24
|
card.h2(title);
|
|
@@ -2,21 +2,21 @@ import {Page as BasePage} from '@gramlot/gramlot/page';
|
|
|
2
2
|
|
|
3
3
|
// These browser actions change Source, never DOM elements.
|
|
4
4
|
const ACTIONS = {
|
|
5
|
-
"add": "window.gramlot.builder.wrapSource(window.gramlot.source.getNode('main.page.work.items')).li('A new item', {class: 'card'})",
|
|
6
|
-
"remove": "const items = window.gramlot.source.getItem('main.page.work.items'); const last = items.getNodes().at(-1); if (last) items.popNode(last.label)",
|
|
7
|
-
"clear": "window.gramlot.source.getItem('main.page.work.items').clear()",
|
|
8
|
-
"rename": "window.gramlot.source.getNode('main.page.heading').setValue('Source is alive!')",
|
|
9
|
-
"color": "window.gramlot.source.getNode('main.page.motion.scene.ball').setAttr({fill: 'var(--gramlot-warning)'})",
|
|
10
|
-
"stop": "window.gramlot.source.getItem('main.page').popNode('motion')"
|
|
5
|
+
"add": "window.gramlot.src.builder.wrapSource(window.gramlot.src.source.getNode('main.page.work.items')).li('A new item', {class: 'card'})",
|
|
6
|
+
"remove": "const items = window.gramlot.src.source.getItem('main.page.work.items'); const last = items.getNodes().at(-1); if (last) items.popNode(last.label)",
|
|
7
|
+
"clear": "window.gramlot.src.source.getItem('main.page.work.items').clear()",
|
|
8
|
+
"rename": "window.gramlot.src.source.getNode('main.page.heading').setValue('Source is alive!')",
|
|
9
|
+
"color": "window.gramlot.src.source.getNode('main.page.motion.scene.ball').setAttr({fill: 'var(--gramlot-warning)'})",
|
|
10
|
+
"stop": "window.gramlot.src.source.getItem('main.page').popNode('motion')"
|
|
11
11
|
};
|
|
12
12
|
const ANIMATION = `queueMicrotask(() => {
|
|
13
13
|
const app = window.gramlot;
|
|
14
|
-
const motion = app.source.getNode('main.page.motion');
|
|
15
|
-
const ball = app.source.getNode('main.page.motion.scene.ball');
|
|
14
|
+
const motion = app.src.source.getNode('main.page.motion');
|
|
15
|
+
const ball = app.src.source.getNode('main.page.motion.scene.ball');
|
|
16
16
|
const timer = setInterval(() => {
|
|
17
17
|
ball.setAttr({cx: 160 + 110 * Math.sin(performance.now() / 700)});
|
|
18
18
|
}, 50);
|
|
19
|
-
app.renderer.onDispose(motion, () => clearInterval(timer));
|
|
19
|
+
app.src.renderer.onDispose(motion, () => clearInterval(timer));
|
|
20
20
|
});`;
|
|
21
21
|
|
|
22
22
|
export class Page extends BasePage {
|