@gramlot/gramlot 0.3.27 → 0.3.31
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/assets/icons/chart.svg +1 -0
- package/dist/components/audio/__init__.py +13 -0
- package/dist/components/audio/assets/collection.js +3 -0
- package/dist/components/audio/assets/index.js +3 -0
- package/dist/components/audio/commands.json +7 -0
- package/dist/components/audio/grammar.json +335 -0
- package/dist/components/charts/__init__.py +13 -0
- package/dist/components/charts/assets/collection.js +47 -0
- package/dist/components/charts/assets/files/55ea01207028f76d844678511f29fc800f8a1e67a8a0fe80470128677847ad32-echarts-gl.txt +29 -0
- package/dist/components/charts/assets/files/63727832aaf62004a2b249c933e327f3c90caf49e41a72f4bf436edf632cbda8-vega.txt +27 -0
- package/dist/components/charts/assets/files/8c45d9eaf50c2f72dd9c7ab9ef440788ba58a3538484b5c51c1f17d5128752e7-plotly.txt +21 -0
- package/dist/components/charts/assets/files/8f989229699b4fe2f1a0432d0e9edc338a8a911e250e2d1b01ecd770a5f5b1bd-uplot.txt +21 -0
- package/dist/components/charts/assets/files/c8fa058cba98f7f288b5d8fa4116f441d6dacb25b96da859e518c973fff41d0c-claygl.txt +23 -0
- package/dist/components/charts/assets/index.js +3 -0
- package/dist/components/charts/assets/modules/chunk-2CCTLZE7.js +76 -0
- package/dist/components/charts/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/charts/assets/modules/echarts-gl-CXVTZA6G.js +4409 -0
- package/dist/components/charts/assets/modules/plotly.min-4LB7HE7P.js +3596 -0
- package/dist/components/charts/assets/modules/uPlot.esm-5JJNHHRF.js +3 -0
- package/dist/components/charts/assets/modules/uPlot.min-N3E3FA74.js +1 -0
- package/dist/components/charts/assets/modules/vega.module-2QCOVQ3A.js +13 -0
- package/dist/components/charts/commands.json +7 -0
- package/dist/components/charts/grammar.json +1113 -0
- package/dist/components/chat/__init__.py +1 -1
- package/dist/components/chat/assets/collection.js +3 -3
- package/dist/components/chat/assets/index.js +1 -1
- package/dist/components/drawing/__init__.py +15 -0
- package/dist/components/drawing/assets/collection.js +28 -0
- package/dist/components/drawing/assets/index.js +3 -0
- package/dist/components/drawing/commands.json +7 -0
- package/dist/components/drawing/grammar.json +110 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +18 -18
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/{prose-mirror-engine-GMZPJPNN.js → prose-mirror-engine-DQEAEIMV.js} +2 -2
- package/dist/components/editors/grammar.json +150 -0
- package/dist/components/grid/__init__.py +2 -2
- package/dist/components/grid/assets/collection.js +71 -34
- package/dist/components/grid/assets/files/0a1df3a083d0c010560aa342e87959c8c1070e6fd54545741f083f22d0c8b551-fflate.txt +21 -0
- package/dist/components/grid/assets/files/8cf9b31947daf7adb4a7a00a037459e58241af050cd0a603bfcf1756e533f75e-write-excel-file.txt +21 -0
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/assets/modules/browser-LVJHKBBV.js +19 -0
- package/dist/components/grid/assets/modules/chunk-RMRBEYTI.js +1 -0
- package/dist/components/grid/commands.json +42 -1
- package/dist/components/grid/grammar.json +650 -10
- package/dist/components/grouplets/__init__.py +1 -1
- package/dist/components/grouplets/assets/collection.js +3 -3
- package/dist/components/grouplets/assets/index.js +1 -1
- package/dist/components/inputs/__init__.py +3 -2
- package/dist/components/inputs/assets/collection.js +38 -23
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +1533 -321
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +27 -23
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +85 -0
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +11 -11
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +126 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +8 -8
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/vizabi/__init__.py +13 -0
- package/dist/components/vizabi/assets/collection.js +22 -0
- package/dist/components/vizabi/assets/index.js +3 -0
- package/dist/components/vizabi/commands.json +7 -0
- package/dist/components/vizabi/grammar.json +128 -0
- package/dist/gramlot.js +944 -193
- package/dist/gramlot.min.js +85 -53
- package/dist/standard-collections.js +2 -0
- package/package.json +13 -4
- package/src/binding/grid-struct.js +5 -2
- package/src/binding/runtime.js +12 -1
- package/src/bootstrap.js +1 -1
- package/src/builder/gramlot-builder.d.ts +15 -2
- package/src/builder/gramlot-builder.js +116 -8
- package/src/builder/source.js +42 -1
- package/src/components/audio-analysis-session.js +65 -0
- package/src/components/audio.js +44 -0
- package/src/components/bases.js +6 -4
- package/src/components/border-container.js +6 -3
- package/src/components/buttons.js +47 -3
- package/src/components/chart-bar3d-options.js +30 -0
- package/src/components/chart-controls.js +83 -0
- package/src/components/chart-data-view.js +52 -0
- package/src/components/chart-data.js +42 -0
- package/src/components/chart-domains.js +46 -0
- package/src/components/chart-engines/echarts-options.js +50 -0
- package/src/components/chart-engines/echarts.js +82 -0
- package/src/components/chart-engines/index.js +22 -0
- package/src/components/chart-engines/plotly-map.js +34 -0
- package/src/components/chart-engines/plotly-spatial.js +35 -0
- package/src/components/chart-engines/plotly.js +138 -0
- package/src/components/chart-engines/uplot.js +57 -0
- package/src/components/chart-engines/vega.js +101 -0
- package/src/components/chart-fields.js +110 -0
- package/src/components/chart-geographic-options.js +47 -0
- package/src/components/chart-geojson.js +60 -0
- package/src/components/chart-geometry.js +11 -0
- package/src/components/chart-map-anchors.js +24 -0
- package/src/components/chart-map-bar3d-options.js +41 -0
- package/src/components/chart-map-data.js +25 -0
- package/src/components/chart-map-labels.js +8 -0
- package/src/components/chart-map-options.js +20 -0
- package/src/components/chart-pane.js +91 -0
- package/src/components/chart-renderer.js +58 -0
- package/src/components/chart-sample-view.js +32 -0
- package/src/components/chart-spatial-options.js +40 -0
- package/src/components/chart-time.js +84 -0
- package/src/components/chart-timeline.js +70 -0
- package/src/components/chart-types/area.js +2 -0
- package/src/components/chart-types/bar.js +2 -0
- package/src/components/chart-types/bar3D.js +2 -0
- package/src/components/chart-types/donut.js +2 -0
- package/src/components/chart-types/horizontalBar.js +2 -0
- package/src/components/chart-types/index.js +26 -0
- package/src/components/chart-types/line.js +2 -0
- package/src/components/chart-types/line3D.js +2 -0
- package/src/components/chart-types/lines3D.js +2 -0
- package/src/components/chart-types/map.js +2 -0
- package/src/components/chart-types/map3D.js +2 -0
- package/src/components/chart-types/mapBar3D.js +2 -0
- package/src/components/chart-types/pie.js +2 -0
- package/src/components/chart-types/polygons3D.js +2 -0
- package/src/components/chart-types/scatter.js +2 -0
- package/src/components/chart-types/scatter3D.js +2 -0
- package/src/components/chart-types/stackedArea.js +2 -0
- package/src/components/chart-types/stackedBar.js +2 -0
- package/src/components/chart-types/surface.js +2 -0
- package/src/components/charts.js +152 -0
- package/src/components/check-box-text-editor.js +88 -0
- package/src/components/check-box-text.js +193 -0
- package/src/components/check-box-tree.js +62 -0
- package/src/components/choice-editor.js +7 -5
- package/src/components/choice-field-styles.js +14 -0
- package/src/components/choices.js +5 -0
- package/src/components/drawing.js +199 -0
- package/src/components/grid-check-sets.js +98 -0
- package/src/components/grid-column-filters.js +198 -0
- package/src/components/grid-footer.js +120 -0
- package/src/components/grid-formulas.js +403 -0
- package/src/components/grid-grammar.json +131 -2
- package/src/components/grid-header-interaction.js +3 -1
- package/src/components/grid-rows.js +2 -2
- package/src/components/grid-search-box.js +38 -22
- package/src/components/grid-search-styles.js +13 -14
- package/src/components/grid-search.js +8 -1
- package/src/components/grid-selection.js +118 -0
- package/src/components/grid-structure.js +36 -5
- package/src/components/grid-styles.js +37 -1
- package/src/components/grid-tools.js +229 -0
- package/src/components/grid.js +223 -15
- package/src/components/image-uploader.js +2 -2
- package/src/components/inputs.js +19 -10
- package/src/components/labelbox.js +5 -1
- package/src/components/licenses/claygl.txt +23 -0
- package/src/components/licenses/echarts-gl.txt +29 -0
- package/src/components/licenses/fflate.txt +21 -0
- package/src/components/licenses/plotly.txt +21 -0
- package/src/components/licenses/uplot.txt +21 -0
- package/src/components/licenses/vega.txt +27 -0
- package/src/components/licenses/write-excel-file.txt +21 -0
- package/src/components/menus.js +19 -11
- package/src/components/toolbar-overflow.js +12 -8
- package/src/components/tree.js +30 -8
- package/src/components/typed-editor.js +14 -3
- package/src/components/vizabi-session.js +66 -0
- package/src/components/vizabi.js +66 -0
- package/src/components/window-surface.js +20 -9
- package/src/components/windows.js +1 -1
- package/src/editing-session.d.ts +2 -0
- package/src/editing-session.js +35 -3
- package/src/gramlot.d.ts +1 -0
- package/src/gramlot.js +2 -0
- package/src/handlers/device-handler.js +32 -32
- package/src/handlers/source-handler.d.ts +2 -2
- package/src/ide-documents.js +19 -3
- package/src/ide-runtime.d.ts +1 -0
- package/src/ide-runtime.js +45 -31
- package/src/index.d.ts +1 -0
- package/src/renderer/drag-drop.js +1 -0
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +5 -4
- package/src/server/assets.d.ts +3 -0
- package/src/server/assets.js +9 -0
- package/src/server/gramlot-server.d.ts +1 -1
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index.d.ts +1 -1
- package/src/server/index.js +1 -1
- package/src/server/visual-editor.js +17 -17
- package/src/stores/bag-collection-store.js +14 -5
- package/src/stores/bag-collection-view.js +80 -18
- package/src/stores/collection-filter.js +2 -1
- package/src/stores/column-filter.js +49 -0
- package/src/stores/id-set.js +10 -0
- package/src/view/controls.js +8 -0
- package/src/view/html.js +10 -1
- package/src/view/label-menu.js +61 -0
- package/src/view/labelbox.js +15 -2
- package/themes/gramlot-base/theme.css +6 -0
- package/tools/gramlot-tools-inspector.js +169 -505
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramlot/gramlot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
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": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"test": "node --test tests/*.test.js tests/binding-contracts/gramlot-quiet-write.test.mjs tests/upstream-regressions/builder-symbolic-attribute.test.mjs",
|
|
13
|
+
"test": "node --test --test-concurrency=2 tests/*.test.js tests/binding-contracts/gramlot-quiet-write.test.mjs tests/upstream-regressions/builder-symbolic-attribute.test.mjs",
|
|
14
14
|
"build": "node scripts/build-runtime.mjs",
|
|
15
15
|
"test:server": "node --test tests/gramlot-server.test.js",
|
|
16
16
|
"prepack": "node scripts/build-runtime.mjs"
|
|
@@ -41,15 +41,21 @@
|
|
|
41
41
|
"@myriaddreamin/typst.ts": "0.7.0",
|
|
42
42
|
"codemirror-lang-typst": "0.6.0",
|
|
43
43
|
"dompurify": "3.4.17",
|
|
44
|
+
"echarts": "^6.1.0",
|
|
45
|
+
"echarts-gl": "2.1.0",
|
|
44
46
|
"jodit": "4.18.10",
|
|
45
47
|
"markdown-it": "14.3.3",
|
|
48
|
+
"plotly.js-dist-min": "4.2.0",
|
|
46
49
|
"prosemirror-commands": "1.6.2",
|
|
47
50
|
"prosemirror-history": "1.4.1",
|
|
48
51
|
"prosemirror-keymap": "1.2.2",
|
|
49
52
|
"prosemirror-markdown": "1.13.1",
|
|
50
53
|
"prosemirror-model": "1.25.12",
|
|
51
54
|
"prosemirror-state": "1.4.3",
|
|
52
|
-
"prosemirror-view": "1.42.6"
|
|
55
|
+
"prosemirror-view": "1.42.6",
|
|
56
|
+
"uplot": "1.6.32",
|
|
57
|
+
"vega": "6.4.0",
|
|
58
|
+
"write-excel-file": "4.1.1"
|
|
53
59
|
},
|
|
54
60
|
"devDependencies": {
|
|
55
61
|
"c8": "10.1.3",
|
|
@@ -82,7 +88,10 @@
|
|
|
82
88
|
"./mobile-environment": "./src/mobile-environment.js",
|
|
83
89
|
"./chat": "./src/chat.js",
|
|
84
90
|
"./components/chat": "./src/components/chat.js",
|
|
85
|
-
"./components/selection_trial": "./src/experiments/selection-trial.js"
|
|
91
|
+
"./components/selection_trial": "./src/experiments/selection-trial.js",
|
|
92
|
+
"./components/charts": "./src/components/charts.js",
|
|
93
|
+
"./components/drawing": "./src/components/drawing.js",
|
|
94
|
+
"./components/vizabi": "./src/components/vizabi.js"
|
|
86
95
|
},
|
|
87
96
|
"files": [
|
|
88
97
|
"LICENSE",
|
|
@@ -13,7 +13,10 @@ function structureData(source) {
|
|
|
13
13
|
node.builder.validateNode(node);
|
|
14
14
|
if (node.nodeTag !== 'column' || node.staticValue != null) throw new TypeError('grid column must be a scalar declaration');
|
|
15
15
|
const attrs = {tag:'cell'};
|
|
16
|
-
|
|
16
|
+
const keys = ['field', 'name', 'title', 'dtype', 'width', 'align', 'format', 'white_space', 'max_height', 'edit', 'check', 'checked', 'checkedField',
|
|
17
|
+
'formula', 'calculated', 'hidden', 'totalize', 'footer_value', 'footer_format',
|
|
18
|
+
...Object.keys(node.getAttr()).filter(key => key.startsWith('formula_'))];
|
|
19
|
+
for (const key of keys) {
|
|
17
20
|
if (node.getAttr(key) != null) attrs[key] = node.getAttr(key);
|
|
18
21
|
}
|
|
19
22
|
const label = `cell_${attrs.field}`;
|
|
@@ -56,7 +59,7 @@ export function validateGridDeclaration(node) {
|
|
|
56
59
|
export function installGridStruct(node, data) {
|
|
57
60
|
const value = structureData(node.staticValue);
|
|
58
61
|
new GridStructure(value);
|
|
59
|
-
const path = `
|
|
62
|
+
const path = `_gramlot.grid.${crypto.randomUUID().replaceAll('-', '')}.struct`;
|
|
60
63
|
data.setItem(path, value, null, '>', false, true, node);
|
|
61
64
|
node.parentNode.setAttr({structpath: path}, false);
|
|
62
65
|
node.setValue(null, false);
|
package/src/binding/runtime.js
CHANGED
|
@@ -70,6 +70,7 @@ export class BindingRuntime {
|
|
|
70
70
|
get data() { return this.builder.data; }
|
|
71
71
|
/** Resolve a tree store against the selected live root. */
|
|
72
72
|
treeStore(node) {
|
|
73
|
+
if (node.treeStore !== null) return node.treeStore;
|
|
73
74
|
const path = node.getAttr('storepath');
|
|
74
75
|
if (path === '*S' || path.startsWith('*S.')) {
|
|
75
76
|
const root = this.renderer.source.getItem('main');
|
|
@@ -138,7 +139,8 @@ export class BindingRuntime {
|
|
|
138
139
|
const value = bag.node(segment)?.staticValue;
|
|
139
140
|
if (!(value instanceof Bag)) break;
|
|
140
141
|
const store = this.#collectionStores.get(value);
|
|
141
|
-
store?.receiveData(event, index + 1 < event.pathlist.length ? value.node(event.pathlist[index + 1]) : null
|
|
142
|
+
store?.receiveData(event, index + 1 < event.pathlist.length ? value.node(event.pathlist[index + 1]) : null,
|
|
143
|
+
event.pathlist[index + 2] ?? null);
|
|
142
144
|
bag = value;
|
|
143
145
|
}
|
|
144
146
|
this.router.deliver(event);
|
|
@@ -492,6 +494,15 @@ export class NodeBinding {
|
|
|
492
494
|
const component = node._getMeta('gramlot_component');
|
|
493
495
|
for (const [capability, attribute] of [['bagStore', 'storepath'], ['bagStruct', 'structpath']]) {
|
|
494
496
|
if (!component?.[capability]) continue;
|
|
497
|
+
if (capability === 'bagStore' && node.nodeTag === 'tree' && node.treeStore !== null) {
|
|
498
|
+
const store = node.treeStore;
|
|
499
|
+
const subscription = `gramlot-tree-${randomId()}`;
|
|
500
|
+
store.subscribe(subscription, {any: () => {
|
|
501
|
+
if (!this.closed && this.runtime.renderer.attached(node)) this.runtime.renderer.project(node);
|
|
502
|
+
}});
|
|
503
|
+
this.#registrations.push({close: () => store.unsubscribe(subscription, {any: true})});
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
495
506
|
const value = node.getAttr(attribute);
|
|
496
507
|
if (typeof value !== 'string' || !value || /^[\^=]/.test(value) || value.includes('?')) {
|
|
497
508
|
throw new TypeError(`${attribute} requires a plain Bag data path`);
|
package/src/bootstrap.js
CHANGED
|
@@ -86,7 +86,7 @@ export class PageBootstrap {
|
|
|
86
86
|
// Verify the complete graph before activating any component or command.
|
|
87
87
|
for (const collection of collections) collection.register(window);
|
|
88
88
|
app = new Gramlot({...config, document, serverAdapter:this.serverAdapter,
|
|
89
|
-
collections:[...(config.collections ?? []), ...collections
|
|
89
|
+
collections:[...(config.collections ?? []), ...collections]});
|
|
90
90
|
window.removeEventListener('pagehide', pagehide);
|
|
91
91
|
for (const collection of collections) collection.registerCommands(app);
|
|
92
92
|
for (const {logicClass,group,resource} of entries) app.src.logicRegistry.register(logicClass,{group,resource});
|
|
@@ -4,11 +4,24 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import {HtmlBuilder} from '@genrojs/builders';
|
|
7
|
+
import type {Bag} from '@genrojs/bag';
|
|
7
8
|
import type {SourceAttributes, SourceBag, SourceBagNode, ValidateNodeOptions} from '@genrojs/builders';
|
|
8
9
|
import type {GramlotHtmlRenderer} from '../renderer/gramlot-html-renderer.js';
|
|
9
10
|
import type {SourceReference} from '../references.js';
|
|
10
11
|
import type {NameSyntax} from './name-syntax.js';
|
|
11
12
|
|
|
13
|
+
/** Gramlot Source node, with a non-serialized external Bag reference for a tree. */
|
|
14
|
+
export interface GramlotSourceNode extends SourceBagNode {
|
|
15
|
+
/** Existing shared top toolbar of a frameGrid; never creates a second bar. */
|
|
16
|
+
readonly toolbar: GramlotSourceNode;
|
|
17
|
+
readonly treeStore: Bag | null;
|
|
18
|
+
setTreeStore(bag: Bag | null): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface GramlotSourceBag extends SourceBag {
|
|
22
|
+
getNode(path: string | number, isStatic?: boolean, autocreate?: boolean, defaultValue?: unknown): GramlotSourceNode | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
12
25
|
/** Gramlot vocabulary and inert authoring on the shared builder grammar. */
|
|
13
26
|
export class GramlotBuilder extends HtmlBuilder {
|
|
14
27
|
/** The dialect name, `'gramlot'`. */
|
|
@@ -16,7 +29,7 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
16
29
|
static containers: string[];
|
|
17
30
|
/** Build an ordinary framePane containing center.grid; requires layout and grid. */
|
|
18
31
|
frameGrid(parent: SourceBag | SourceBagNode, options: SourceAttributes & {
|
|
19
|
-
storepath: string; rowMode: 'values' | 'attributes'; structpath?: string; searchOn?: boolean | string;
|
|
32
|
+
storepath: string; rowMode: 'values' | 'attributes'; structpath?: string; searchOn?: boolean | string; searchHelp?: boolean; chart?: boolean | string;
|
|
20
33
|
}): SourceBagNode;
|
|
21
34
|
/** Tag prefixes of the parent dialects, from the names of the classes above `GramlotBuilder`. */
|
|
22
35
|
static get dialectPrefixes(): string[];
|
|
@@ -30,7 +43,7 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
30
43
|
/** The binding runtime of the Gramlot page that owns this builder, or null for authoring alone; set by `Gramlot` right after creating the builder. */
|
|
31
44
|
binding: unknown;
|
|
32
45
|
/** The node with `nodeId`; inside a Gramlot page it reads the node ids of the binding runtime. */
|
|
33
|
-
nodeById(nodeId: string):
|
|
46
|
+
nodeById(nodeId: string): GramlotSourceNode;
|
|
34
47
|
/** Load a grammar document into the builder. */
|
|
35
48
|
loadCollection(document: unknown): this;
|
|
36
49
|
/** The schema tag of an authored name, or null; the `gramlot_` prefix and excluded declarations raise. */
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import buttons from '../components/buttons.js';
|
|
8
8
|
import {ComponentCollection} from '../components/registry.js';
|
|
9
9
|
import {Bag} from '@genrojs/bag';
|
|
10
|
-
import {HtmlBuilder, SourceBagNode, sourceTarget} from '@genrojs/builders';
|
|
10
|
+
import {HtmlBuilder, META_ATTRS, SourceBagNode, sourceTarget} from '@genrojs/builders';
|
|
11
11
|
import {toTytx} from '@genrojs/tytx';
|
|
12
12
|
// Loading the Gramlot Source classes adds GramlotBuilderBag to the TYTX subtype
|
|
13
13
|
// dictionary of X, so every GramlotBuilder user can encode and decode it.
|
|
@@ -36,6 +36,36 @@ const DATA_PATH_ATTRIBUTES = {dataSetter: 'destination_path', dataFormula: 'resu
|
|
|
36
36
|
const DATA_INLINE_ATTRIBUTES = {dataFormula: 'formula', dataController: 'script'};
|
|
37
37
|
|
|
38
38
|
/** The P18 violation of a data-element's attributes, or null. */
|
|
39
|
+
// Builder's framework call keywords, accepted by every element.
|
|
40
|
+
const FRAMEWORK_ATTRIBUTES = new Set(['node_label', 'node_position', 'nodeId', 'target_id', 'datapath', 'iterate', 'store', '_tag', '_meta', 'ns']);
|
|
41
|
+
// Export formats of the grid:export command, in menu order, with their captions.
|
|
42
|
+
const EXPORT_FORMATS = {csv:'CSV', json:'JSON', tytx:'TYTX', xml:'XML', xlsx:'Excel'};
|
|
43
|
+
// frameGrid composes these grid attributes itself; its own parameters reach the grid too.
|
|
44
|
+
const FRAME_GRID_COMPOSED = new Set(['node_label', 'frameTarget', 'nodeId']);
|
|
45
|
+
const FRAME_GRID_PARAMETERS = new Set(['storepath', 'rowMode', 'structpath']);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* An element whose `_meta.keywordPattern` is set accepts, besides its declared attributes, only the
|
|
49
|
+
* keywords matching that pattern (grid column `formula_<name>`); the error names the first other one.
|
|
50
|
+
*/
|
|
51
|
+
function keywordPatternError(spec, attrs) {
|
|
52
|
+
const pattern = spec?._meta?.keywordPattern;
|
|
53
|
+
if (!pattern) return null;
|
|
54
|
+
const declared = new Set(spec.attributes.parameters.filter(parameter => !parameter.kind.startsWith('var_')).map(parameter => parameter.name));
|
|
55
|
+
const unknown = Object.keys(attrs).find(name => !declared.has(name) && !FRAMEWORK_ATTRIBUTES.has(name) && !new RegExp(pattern).test(name));
|
|
56
|
+
return unknown === undefined ? null : `unknown attribute '${unknown}'`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** frameGrid `export`: true for every format, false for none, or a comma-separated list such as 'csv,json'. */
|
|
60
|
+
function frameGridExportFormats(exportRows) {
|
|
61
|
+
if (typeof exportRows === 'boolean') return exportRows ? Object.keys(EXPORT_FORMATS) : [];
|
|
62
|
+
if (typeof exportRows !== 'string' || !exportRows.trim()) throw new TypeError('frameGrid export requires a boolean or a list of formats');
|
|
63
|
+
const formats = exportRows.split(',').map(item => item.trim());
|
|
64
|
+
const unknown = formats.find(item => !Object.hasOwn(EXPORT_FORMATS, item));
|
|
65
|
+
if (unknown !== undefined) throw new TypeError(`frameGrid export format '${unknown}' is not one of ${Object.keys(EXPORT_FORMATS).join(', ')}`);
|
|
66
|
+
return formats;
|
|
67
|
+
}
|
|
68
|
+
|
|
39
69
|
function dataElementError(tag, attrs) {
|
|
40
70
|
if (['input', 'textarea', 'select', 'webcomponent'].includes(tag) && pointerTransform(attrs.value)) {
|
|
41
71
|
return "'value' does not accept pointer suffixes; use an ordinary value pointer";
|
|
@@ -80,20 +110,97 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
80
110
|
static { this.defineGrammar(buttons.toDocument()); }
|
|
81
111
|
|
|
82
112
|
/** Compose real Source nodes; frame/grid/menu retain their existing runtime owners. */
|
|
83
|
-
frameGrid(parent, {storepath, rowMode, structpath, searchOn = false,
|
|
113
|
+
frameGrid(parent, {storepath, rowMode, structpath, searchOn = false, searchHelp = false, chart = false,
|
|
114
|
+
export: exportRows = false, printRows = false, advancedTools = false, addrow = false, addrow_defaults = null,
|
|
115
|
+
duprow = false, delrow = false, gridsemaphore = false, ...attrs} = {}) {
|
|
84
116
|
for (const tag of ['framePane', 'grid']) {
|
|
85
117
|
if (!this.schemaTag(tag)) throw new TypeError(`frameGrid requires the ${tag} collection`);
|
|
86
118
|
}
|
|
119
|
+
const chartOptions = {};
|
|
120
|
+
for (const key of Object.keys(attrs)) if (key.startsWith('chart_')) {
|
|
121
|
+
chartOptions[key.slice(6)] = attrs[key]; delete attrs[key];
|
|
122
|
+
}
|
|
123
|
+
const [frameAttrs, routed] = this.frameGridRoute(attrs);
|
|
124
|
+
const twice = Object.keys(routed).find(name => ['storepath', 'rowMode'].includes(name) || name === 'structpath' && structpath != null);
|
|
125
|
+
if (twice !== undefined) throw new TypeError(`frameGrid: '${twice}' is given twice`);
|
|
126
|
+
if (chart !== false) {
|
|
127
|
+
if (chart !== true && (typeof chart !== 'string' || !chart)) throw new TypeError('chart requires a boolean or chart type');
|
|
128
|
+
if (!frameAttrs.datapath) throw new TypeError('A chart frameGrid requires its own datapath');
|
|
129
|
+
if (!this.schemaTag('chartPane')) throw new TypeError('frameGrid requires the chartPane collection');
|
|
130
|
+
if (typeof chart === 'string') chartOptions.chartType = chart;
|
|
131
|
+
} else if (Object.keys(chartOptions).length) throw new TypeError('chart_* options require chart');
|
|
132
|
+
const exportFormats = frameGridExportFormats(exportRows);
|
|
133
|
+
for (const [name, value] of Object.entries({printRows, advancedTools, addrow, duprow, delrow, gridsemaphore})) {
|
|
134
|
+
if (typeof value !== 'boolean') throw new TypeError(`frameGrid ${name} requires a boolean`);
|
|
135
|
+
}
|
|
136
|
+
if (addrow_defaults !== null && (!addrow || typeof addrow_defaults !== 'object' || Array.isArray(addrow_defaults))) {
|
|
137
|
+
throw new TypeError('addrow_defaults requires addrow and a mapping');
|
|
138
|
+
}
|
|
139
|
+
if (gridsemaphore) {
|
|
140
|
+
if (!frameAttrs.datapath) throw new TypeError('A gridsemaphore frameGrid requires its own datapath');
|
|
141
|
+
if (!this.schemaTag('editingStatus')) throw new TypeError('frameGrid requires the editingStatus collection');
|
|
142
|
+
frameAttrs.form = true;
|
|
143
|
+
}
|
|
87
144
|
const gridAttrs = {storepath, rowMode, ...(structpath == null ? {} : {structpath}),
|
|
88
|
-
node_label: 'grid', frameTarget: true, height: '100%', width: '100%'
|
|
145
|
+
node_label: 'grid', frameTarget: true, height: '100%', width: '100%',
|
|
146
|
+
// Legacy frameGrid default: the current row identity at .selectedId of the frame's own datapath.
|
|
147
|
+
...(frameAttrs.datapath ? {selectedId: '^.selectedId'} : {}), ...routed};
|
|
148
|
+
if (chart !== false) gridAttrs.nodeId = randomId();
|
|
89
149
|
this.validateNodeValues('grid', null, gridAttrs);
|
|
90
|
-
if (searchOn !== false) this.validateNodeValues('searchBox', null, {searchOn});
|
|
91
|
-
const frame = parent.framePane(
|
|
150
|
+
if (searchOn !== false) this.validateNodeValues('searchBox', null, {searchOn, searchHelp});
|
|
151
|
+
const frame = parent.framePane(frameAttrs);
|
|
92
152
|
frame.center.grid(gridAttrs);
|
|
93
|
-
|
|
153
|
+
const bar = frame.top.menu({presentation:'bar', node_label:'bar', aria_label:'Grid toolbar', class:'gramlot-grid-toolbar'});
|
|
154
|
+
if (searchOn !== false) bar.menuline({group:true, node_label:'search', class:'gramlot-grid-search'}).searchBox({searchOn, searchHelp});
|
|
155
|
+
if (addrow) bar.menuline({command:'grid:addrow', node_label:'addrow', ...(addrow_defaults === null ? {} : {parameters:{defaults:addrow_defaults}})});
|
|
156
|
+
if (duprow) bar.menuline({command:'grid:duprow', node_label:'duprow'});
|
|
157
|
+
if (delrow) bar.menuline({command:'grid:delrow', node_label:'delrow'});
|
|
158
|
+
const exportMenu = parent => {
|
|
159
|
+
const menu = parent.menuline({caption:'Export', icon:'⇩', labelPosition:'tooltip', node_label:'export'}).menu();
|
|
160
|
+
for (const name of exportFormats) menu.menuline({command:'grid:export', caption:EXPORT_FORMATS[name], parameters:{format:name}, node_label:name});
|
|
161
|
+
};
|
|
162
|
+
if (exportFormats.length) exportMenu(bar);
|
|
163
|
+
if (printRows) bar.menuline({command:'grid:printRows', node_label:'printRows'});
|
|
164
|
+
if (advancedTools) {
|
|
165
|
+
const tools = bar.menuline({caption:'Advanced tools', icon:'…', labelPosition:'tooltip', node_label:'advancedTools'}).menu();
|
|
166
|
+
tools.menuline({command:'grid:lineNumbers', node_label:'lineNumbers'});
|
|
167
|
+
if (exportFormats.length) exportMenu(tools);
|
|
168
|
+
if (printRows) tools.menuline({command:'grid:printRows', node_label:'printRows'});
|
|
169
|
+
}
|
|
170
|
+
if (gridsemaphore) bar.menuline({group:true, node_label:'semaphore'}).editingStatus();
|
|
171
|
+
if (chart !== false) {
|
|
172
|
+
bar.menuline({caption:'Chart', icon:'▥', labelPosition:'tooltip', node_label:'chart', action:"this.SET('._chart.open',true)"});
|
|
173
|
+
const window = frame.center.floatingPane({title:'Chart', open:'^._chart.open', width:'820px', height:'560px',
|
|
174
|
+
movable:true, resizable:true, maximizable:true, node_label:'chartWindow'});
|
|
175
|
+
window.frame.center.chartPane({storepath,rowMode,gridId:gridAttrs.nodeId,configpath:'._chart',
|
|
176
|
+
configDefaults:new Bag(chartOptions),height:'100%'});
|
|
177
|
+
}
|
|
94
178
|
return frame;
|
|
95
179
|
}
|
|
96
180
|
|
|
181
|
+
/** Split frameGrid keywords: unprefixed grid parameters go to the grid, `grid_`/`frame_` force any attribute. */
|
|
182
|
+
frameGridRoute(attrs) {
|
|
183
|
+
const declared = tag => new Set(this.schema[tag].attributes.parameters.filter(parameter => !parameter.kind.startsWith('var_')).map(parameter => parameter.name));
|
|
184
|
+
const source = new Set([...FRAMEWORK_ATTRIBUTES, ...META_ATTRS]);
|
|
185
|
+
const gridNames = declared('grid'), frameNames = declared('framePane');
|
|
186
|
+
const pattern = new RegExp(this.schema.grid._meta.parameterPattern);
|
|
187
|
+
// A name the frame also accepts stays on the frame unless forced with grid_.
|
|
188
|
+
const routed = name => (gridNames.has(name) || pattern.test(name)) && !frameNames.has(name) && !source.has(name)
|
|
189
|
+
&& !FRAME_GRID_COMPOSED.has(name) && !FRAME_GRID_PARAMETERS.has(name);
|
|
190
|
+
const frame = {}, grid = {};
|
|
191
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
192
|
+
let name, target;
|
|
193
|
+
if (key.startsWith('grid_')) {
|
|
194
|
+
name = key.slice('grid_'.length); target = grid;
|
|
195
|
+
if (FRAME_GRID_COMPOSED.has(name)) throw new TypeError(`frameGrid: '${key}' is composed by frameGrid`);
|
|
196
|
+
} else if (key.startsWith('frame_')) { name = key.slice('frame_'.length); target = frame; }
|
|
197
|
+
else { name = key; target = routed(key) ? grid : frame; }
|
|
198
|
+
if (Object.hasOwn(target, name)) throw new TypeError(`frameGrid: '${name}' is given twice`);
|
|
199
|
+
target[name] = value;
|
|
200
|
+
}
|
|
201
|
+
return [frame, grid];
|
|
202
|
+
}
|
|
203
|
+
|
|
97
204
|
/** Tag prefixes of the parent dialects, from the `_name` of the classes above GramlotBuilder. */
|
|
98
205
|
static get dialectPrefixes() {
|
|
99
206
|
const prefixes = [];
|
|
@@ -199,7 +306,7 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
199
306
|
if (tag === 'webcomponent') webcomponentCode(attrs);
|
|
200
307
|
const excluded = excludedAttribute(attrs);
|
|
201
308
|
if (excluded) throw new Error(`${tag}: attribute '${excluded}' is excluded from Gramlot`);
|
|
202
|
-
const error = dataElementError(tag, attrs);
|
|
309
|
+
const error = dataElementError(tag, attrs) ?? keywordPatternError(this.schema[tag], attrs);
|
|
203
310
|
if (error) throw new Error(`${tag}: ${error}`);
|
|
204
311
|
return super.validateNodeValues(tag, value, attrs);
|
|
205
312
|
}
|
|
@@ -212,7 +319,8 @@ export class GramlotBuilder extends HtmlBuilder {
|
|
|
212
319
|
if (node.nodeTag === 'webcomponent') webcomponentCode(options.attrs ?? node.getAttr());
|
|
213
320
|
const excluded = excludedAttribute(options.attrs ?? node.getAttr());
|
|
214
321
|
if (excluded) throw new Error(`${node.nodeTag} '${node.label}': attribute '${excluded}' is excluded from Gramlot`);
|
|
215
|
-
const error = dataElementError(node.nodeTag, options.attrs ?? node.getAttr())
|
|
322
|
+
const error = dataElementError(node.nodeTag, options.attrs ?? node.getAttr())
|
|
323
|
+
?? keywordPatternError(this.schema[node.nodeTag], options.attrs ?? node.getAttr());
|
|
216
324
|
if (error) throw new Error(`${node.nodeTag} '${node.label}': ${error}`);
|
|
217
325
|
return super.validateNode(node, options);
|
|
218
326
|
}
|
package/src/builder/source.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {EditingSession} from '../editing-session.js';
|
|
2
|
-
import {BagCbResolver} from '@genrojs/bag';
|
|
2
|
+
import {Bag, BagCbResolver} from '@genrojs/bag';
|
|
3
3
|
import {SourceBag, SourceBagNode, sourceAttributeItems, wrapSource} from '@genrojs/builders';
|
|
4
4
|
import {fromTytx, getSubtypeDict, setSubtypeDict, toTytx} from '@genrojs/tytx';
|
|
5
5
|
import {pointerTransform, pointerDependencies} from '@genrojs/builders';
|
|
@@ -177,8 +177,42 @@ function isExpression(value) {
|
|
|
177
177
|
* the null path rule (Q7): a read gives null, a write is an error. FIRE writes through
|
|
178
178
|
* setRelativeData too, with the Gramlot reset rules.
|
|
179
179
|
*/
|
|
180
|
+
/**
|
|
181
|
+
* The column formulas of a grid's nested struct, as `[struct.<field>.formula, text]`: the struct is
|
|
182
|
+
* consumed into Data at installation, so its formula texts are activated on the grid node.
|
|
183
|
+
*/
|
|
184
|
+
function structFormulaCode(grid) {
|
|
185
|
+
const items = [];
|
|
186
|
+
const visit = bag => {
|
|
187
|
+
for (const child of bag.getNodes()) {
|
|
188
|
+
if (child.nodeTag === 'column' && typeof child.getAttr('formula') === 'string') {
|
|
189
|
+
items.push([`struct.${child.getAttr('field')}.formula`, child.getAttr('formula')]);
|
|
190
|
+
} else if ((child._getMeta('gridStruct') || child.nodeTag === 'colgroup') && child.staticValue instanceof SourceBag) visit(child.staticValue);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
if (grid.staticValue instanceof SourceBag) visit(grid.staticValue);
|
|
194
|
+
return items;
|
|
195
|
+
}
|
|
196
|
+
|
|
180
197
|
export class GramlotBuilderBagNode extends SourceBagNode {
|
|
181
198
|
#formState = null;
|
|
199
|
+
#treeStore = null;
|
|
200
|
+
|
|
201
|
+
/** An externally owned Bag attached to this tree's Source node. */
|
|
202
|
+
get treeStore() { return this.#treeStore; }
|
|
203
|
+
|
|
204
|
+
setTreeStore(bag) {
|
|
205
|
+
if (this.nodeTag !== 'tree') throw new TypeError('setTreeStore requires a tree Source node');
|
|
206
|
+
if (bag !== null && !(bag instanceof Bag)) throw new TypeError('setTreeStore requires a Bag or null');
|
|
207
|
+
if (bag === this.#treeStore) return;
|
|
208
|
+
this.#treeStore = bag;
|
|
209
|
+
const runtime = this.rootBuilder.binding;
|
|
210
|
+
const binding = runtime?.bindingFor(this);
|
|
211
|
+
if (binding && !binding.closed) {
|
|
212
|
+
binding.rebind();
|
|
213
|
+
if (runtime.renderer.attached(this)) runtime.renderer.project(this);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
182
216
|
/** The local form lifecycle owned by the nearest marked Source ancestor. */
|
|
183
217
|
get formState() {
|
|
184
218
|
for (let owner = this; owner; owner = owner.parentNode) {
|
|
@@ -224,6 +258,12 @@ export class GramlotBuilderBagNode extends SourceBagNode {
|
|
|
224
258
|
}
|
|
225
259
|
return (attrs = {}) => this.builder.wrapSource(this.builder.commandOnNode(this, 'grid', null, attrs));
|
|
226
260
|
}
|
|
261
|
+
get toolbar() {
|
|
262
|
+
if (this.nodeTag !== 'framePane') throw new TypeError('toolbar accessor requires framePane');
|
|
263
|
+
const bar = this.staticValue instanceof SourceBag ? this.staticValue.getNode('top.bar') : null;
|
|
264
|
+
if (!bar || bar.nodeTag !== 'menu') throw new TypeError('This frame has no toolbar');
|
|
265
|
+
return this.builder.wrapSource(bar);
|
|
266
|
+
}
|
|
227
267
|
get top() { return this.frameRegion('top'); }
|
|
228
268
|
get bottom() { return this.frameRegion('bottom'); }
|
|
229
269
|
get left() { return this.frameRegion('left'); }
|
|
@@ -283,6 +323,7 @@ export class GramlotBuilderBagNode extends SourceBagNode {
|
|
|
283
323
|
}
|
|
284
324
|
}
|
|
285
325
|
if (isExpression(this.staticValue) || this.nodeTag === 'script' && typeof this.staticValue === 'string') items.push(['', this.staticValue]);
|
|
326
|
+
if (this._getMeta('gramlot_component')?.bagStruct) items.push(...structFormulaCode(this));
|
|
286
327
|
return items;
|
|
287
328
|
}
|
|
288
329
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Local microphone FFT acquisition; independent of charts, transport and DOM. */
|
|
2
|
+
export function audioAnalysisOptions({fftSize=1024, frameRate=20, minimumDb=-100}={}) {
|
|
3
|
+
if(!Number.isInteger(fftSize)||fftSize<256||fftSize>8192||(fftSize&(fftSize-1)))throw new RangeError('FFT size must be a power of two from 256 to 8192');
|
|
4
|
+
if(!Number.isFinite(frameRate)||frameRate<1||frameRate>30)throw new RangeError('Frame rate must be between 1 and 30');
|
|
5
|
+
if(!Number.isFinite(minimumDb)||minimumDb>=0||minimumDb < -160)throw new RangeError('Minimum dB must be between -160 and 0 (exclusive)');
|
|
6
|
+
return {fftSize,frameRate,minimumDb};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class AudioAnalysisSession {
|
|
10
|
+
#window; #frame; #state; #error; #generation=0; #context; #stream; #source; #analyser; #raf; #last=-Infinity; #ended;
|
|
11
|
+
constructor(window,{frame,state,error}) { this.#window=window;this.#frame=frame;this.#state=state;this.#error=error; }
|
|
12
|
+
configure(options) {
|
|
13
|
+
this.options=audioAnalysisOptions(options);
|
|
14
|
+
if(this.#analyser)this.#analyser.fftSize=this.options.fftSize;
|
|
15
|
+
}
|
|
16
|
+
async start(options) {
|
|
17
|
+
this.configure(options);
|
|
18
|
+
if(this.#context)return;
|
|
19
|
+
const win=this.#window;
|
|
20
|
+
if(!win.isSecureContext||!win.navigator.mediaDevices?.getUserMedia||!win.AudioContext)throw new Error('Microphone analysis requires HTTPS or localhost and Web Audio support');
|
|
21
|
+
const generation=++this.#generation;
|
|
22
|
+
const context=new win.AudioContext();this.#context=context;
|
|
23
|
+
this.#state('requesting');
|
|
24
|
+
try {
|
|
25
|
+
await context.resume();
|
|
26
|
+
if(generation!==this.#generation)return;
|
|
27
|
+
const stream=await win.navigator.mediaDevices.getUserMedia({audio:true,video:false});
|
|
28
|
+
if(generation!==this.#generation){for(const track of stream.getTracks())track.stop();return;}
|
|
29
|
+
this.#stream=stream;
|
|
30
|
+
this.#ended=()=>{void this.stop().then(()=>this.#error(new Error('Microphone capture ended')),error=>this.#error(error));};
|
|
31
|
+
for(const track of stream.getTracks())track.addEventListener('ended',this.#ended);
|
|
32
|
+
this.#source=context.createMediaStreamSource(stream);
|
|
33
|
+
this.#analyser=context.createAnalyser();this.#analyser.fftSize=this.options.fftSize;
|
|
34
|
+
this.#source.connect(this.#analyser); // Never connected to speakers, recorded or uploaded.
|
|
35
|
+
this.#state('running');this.#last=-Infinity;
|
|
36
|
+
const tick=timestamp=>{
|
|
37
|
+
if(generation!==this.#generation)return;
|
|
38
|
+
try {
|
|
39
|
+
if(timestamp-this.#last>=1000/this.options.frameRate) {
|
|
40
|
+
this.#last=timestamp;
|
|
41
|
+
const analyser=this.#analyser;
|
|
42
|
+
const waveform=new Float32Array(analyser.fftSize),spectrum=new Float32Array(analyser.frequencyBinCount);
|
|
43
|
+
analyser.getFloatTimeDomainData(waveform);analyser.getFloatFrequencyData(spectrum);
|
|
44
|
+
this.#frame({waveform,spectrum,sampleRate:context.sampleRate,minimumDb:this.options.minimumDb});
|
|
45
|
+
}
|
|
46
|
+
this.#raf=win.requestAnimationFrame(tick);
|
|
47
|
+
} catch(error) { void this.stop().then(()=>this.#error(error),cleanupError=>this.#error(cleanupError)); }
|
|
48
|
+
};
|
|
49
|
+
this.#raf=win.requestAnimationFrame(tick);
|
|
50
|
+
} catch(error) {
|
|
51
|
+
if(generation!==this.#generation)return;
|
|
52
|
+
await this.stop();throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async stop() {
|
|
56
|
+
const generation=++this.#generation;
|
|
57
|
+
if(this.#raf!=null)this.#window.cancelAnimationFrame(this.#raf);
|
|
58
|
+
this.#raf=null;
|
|
59
|
+
for(const track of this.#stream?.getTracks()??[]) {track.removeEventListener('ended',this.#ended);track.stop();}
|
|
60
|
+
this.#stream=null;this.#source?.disconnect();this.#analyser?.disconnect();this.#source=this.#analyser=null;
|
|
61
|
+
const context=this.#context;this.#context=null;
|
|
62
|
+
if(context&&context.state!=='closed')await context.close();
|
|
63
|
+
if(generation===this.#generation)this.#state('stopped');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {defineCollection,defineComponent} from '@gramlot/gramlot/components';
|
|
2
|
+
import {Container} from './container.js';
|
|
3
|
+
import {AudioAnalysisSession} from './audio-analysis-session.js';
|
|
4
|
+
|
|
5
|
+
export const AudioAnalyser=defineComponent({
|
|
6
|
+
name:'audioAnalyser',tag:'gramlot-audio-analyser',base:Container,sourceContext:true,
|
|
7
|
+
parameters:{running:{dtype:'B',default:false,binding:'twoWay'},fftSize:{dtype:'L',default:1024,binding:'read'},
|
|
8
|
+
frameRate:{dtype:'N',default:20,binding:'read'},minimumDb:{dtype:'N',default:-100,binding:'read'},
|
|
9
|
+
spectrum:{dtype:'X',nullable:true,binding:'twoWay'},waveform:{dtype:'X',nullable:true,binding:'twoWay'},
|
|
10
|
+
sampleRate:{dtype:'N',default:0,binding:'twoWay'},status:{dtype:'T',default:'stopped',binding:'twoWay'},error:{dtype:'T',default:'',binding:'twoWay'}},
|
|
11
|
+
implementation:Base=>class extends Base {
|
|
12
|
+
#context; #session; #active=false; #requested=false; #hide; #configuration;
|
|
13
|
+
setSourceContext(context){this.#context=context;}
|
|
14
|
+
connectedCallback(){
|
|
15
|
+
this.#active=true;this.style.display='none';
|
|
16
|
+
const write=(name,value)=>{if(this.#active)this.#context.writeParameter(name,value);};
|
|
17
|
+
this.#session=new AudioAnalysisSession(this.ownerDocument.defaultView,{
|
|
18
|
+
state:status=>write('status',status),error:error=>this.#failed(error),
|
|
19
|
+
frame:({waveform,spectrum,sampleRate,minimumDb})=>{
|
|
20
|
+
write('sampleRate',sampleRate);
|
|
21
|
+
write('waveform',Array.from(waveform));
|
|
22
|
+
write('spectrum',Array.from(spectrum,value=>Math.max(minimumDb,value)));
|
|
23
|
+
}});
|
|
24
|
+
this.#hide=()=>{this.#requested=false;write('running',false);void this.#session.stop().catch(error=>this.#failed(error));};
|
|
25
|
+
this.ownerDocument.defaultView.addEventListener('pagehide',this.#hide);
|
|
26
|
+
this.#sync();
|
|
27
|
+
}
|
|
28
|
+
projectAttributes(attrs,adapt){const rest=super.projectAttributes(attrs,adapt);if(this.#active)this.#sync();return rest;}
|
|
29
|
+
#failed(error){if(!this.#active)return;this.#requested=false;this.#context.writeParameter('running',false);this.#context.writeParameter('error',error.message);void this.#session.stop().then(()=>{if(this.#active)this.#context.writeParameter('status','error');},cleanupError=>console.error('Audio cleanup failed',cleanupError));}
|
|
30
|
+
#sync(){
|
|
31
|
+
const {running,fftSize,frameRate,minimumDb}=this.parameters;
|
|
32
|
+
try {
|
|
33
|
+
const configuration=JSON.stringify([fftSize,frameRate,minimumDb]);
|
|
34
|
+
if(configuration!==this.#configuration){this.#configuration=configuration;this.#session.configure({fftSize,frameRate,minimumDb});}
|
|
35
|
+
if(running===this.#requested)return;
|
|
36
|
+
this.#requested=running;
|
|
37
|
+
if(running){this.#context.writeParameter('error','');void this.#session.start({fftSize,frameRate,minimumDb}).catch(error=>this.#failed(error));}
|
|
38
|
+
else void this.#session.stop().catch(error=>this.#failed(error));
|
|
39
|
+
}catch(error){this.#failed(error);}
|
|
40
|
+
}
|
|
41
|
+
disconnectedCallback(){this.#active=false;this.#requested=false;this.ownerDocument.defaultView.removeEventListener('pagehide',this.#hide);void this.#session.stop().catch(error=>console.error('Audio analysis cleanup failed',error));}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
export default defineCollection({name:'audio',components:[AudioAnalyser]});
|
package/src/components/bases.js
CHANGED
|
@@ -133,11 +133,13 @@ export function ChoiceGroup(HTMLElement) {
|
|
|
133
133
|
items[next].focus();
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
+
choiceOptions() { return parseChoices(this.parameters.values ?? ""); }
|
|
136
137
|
projectAttributes(attrs, adapt) {
|
|
137
138
|
const rest = super.projectAttributes(attrs, adapt);
|
|
138
|
-
const values = this.
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const values = this.choiceOptions();
|
|
140
|
+
const signature = JSON.stringify(values);
|
|
141
|
+
if (signature !== this.#values) {
|
|
142
|
+
const options = values;
|
|
141
143
|
const retained = new Set();
|
|
142
144
|
let previous = null;
|
|
143
145
|
for (const {id: code, caption} of options) {
|
|
@@ -159,7 +161,7 @@ export function ChoiceGroup(HTMLElement) {
|
|
|
159
161
|
for (const [code, item] of this.#options) if (!retained.has(code)) {
|
|
160
162
|
item.label.remove(); this.#options.delete(code);
|
|
161
163
|
}
|
|
162
|
-
this.#values =
|
|
164
|
+
this.#values = signature;
|
|
163
165
|
}
|
|
164
166
|
const cols = this.parameters.cols;
|
|
165
167
|
if (!Number.isInteger(cols) || cols < 1) throw new TypeError('cols must be a positive integer');
|
|
@@ -462,7 +462,8 @@ export const BorderContainer = defineComponent({
|
|
|
462
462
|
const state = this.#regions.get(side), c = state.config;
|
|
463
463
|
const opposite = {left:'right',right:'left',top:'bottom',bottom:'top'}[side];
|
|
464
464
|
const box = this.control.getBoundingClientRect();
|
|
465
|
-
const
|
|
465
|
+
const centerMin = this.#regions.get('center').config?.min ?? 0;
|
|
466
|
+
const available = Math.max(0, (horizontal(side) ? box.height : box.width) - this.#extent(opposite) - centerMin);
|
|
466
467
|
const size = Math.max(Math.min(c.min, available), Math.min(desired, c.max, available));
|
|
467
468
|
state.size = `${size}px`; this.#render(side);
|
|
468
469
|
c.writeParameter(size);
|
|
@@ -471,11 +472,13 @@ export const BorderContainer = defineComponent({
|
|
|
471
472
|
const state = this.#regions.get(side);
|
|
472
473
|
if (evt.target !== state.separator || !state.config?.splitter || state.closed) return;
|
|
473
474
|
const keys = horizontal(side) ? ['ArrowUp','ArrowDown'] : ['ArrowLeft','ArrowRight'];
|
|
474
|
-
if (!keys.includes(evt.key)) return;
|
|
475
|
+
if (!keys.includes(evt.key) && !['Home', 'End'].includes(evt.key)) return;
|
|
475
476
|
evt.preventDefault();
|
|
476
477
|
const sign = ['left','top'].includes(side) ? 1 : -1;
|
|
477
478
|
const previousSize = this.#extent(side);
|
|
478
|
-
|
|
479
|
+
const desired = evt.key === 'Home' ? state.config.min : evt.key === 'End' ? state.config.max
|
|
480
|
+
: previousSize + (evt.key === keys[0] ? -1 : 1) * sign;
|
|
481
|
+
this.#resize(side, desired);
|
|
479
482
|
this.#commitResize(side, previousSize);
|
|
480
483
|
}
|
|
481
484
|
#startDrag(side, evt) {
|