@gramlot/gramlot 0.2.20 → 0.3.0
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.js +1343 -303
- package/dist/gramlot.min.js +363 -24
- package/package.json +6 -3
- package/src/binding/ask-dialog.js +2 -2
- package/src/binding/inline.js +3 -10
- package/src/binding/installation.js +2 -1
- package/src/binding/pointer.js +12 -148
- package/src/binding/providers.js +2 -1
- package/src/binding/runtime.js +2 -1
- package/src/bootstrap.d.ts +2 -0
- package/src/bootstrap.js +9 -2
- package/src/builder/gramlot-builder.js +21 -4
- package/src/builder/source.js +11 -10
- package/src/components/bases.js +182 -0
- package/src/components/buttons.js +254 -0
- package/src/components/choice-editor.js +221 -0
- package/src/components/choices.js +13 -0
- package/src/components/date-calendar.js +139 -0
- package/src/components/field-state.js +166 -0
- package/src/components/formlet-labels.js +80 -0
- package/src/components/index.js +5 -0
- package/src/components/inputs.js +196 -0
- package/src/components/labelbox.js +74 -0
- package/src/components/layout.js +190 -0
- package/src/components/parameters.js +6 -0
- package/src/components/popup.js +22 -0
- package/src/components/registry.js +83 -0
- package/src/components/typed-editor.js +260 -0
- package/src/components/validation.js +138 -0
- package/src/format.js +13 -6
- package/src/gramlot.d.ts +5 -1
- package/src/gramlot.js +8 -1
- package/src/handlers/dom-handler.d.ts +1 -0
- package/src/handlers/dom-handler.js +7 -0
- package/src/index-page-runtime.js +78 -30
- package/src/index-page-styles.js +2 -2
- package/src/index-theme.js +1 -1
- package/src/renderer/attributes.js +3 -40
- package/src/renderer/gramlot-html-renderer.js +4 -3
- package/src/renderer/gramlot-renderer.js +62 -4
- package/src/server/gramlot-server.d.ts +3 -0
- package/src/server/gramlot-server.js +9 -3
- package/src/server/index-page.d.ts +1 -0
- package/src/server/index-page.js +8 -3
- package/src/server/page-base.js +1 -0
- package/src/server/page.d.ts +1 -0
- package/src/server/resources.d.ts +2 -0
- package/src/view/button.js +17 -13
- package/src/view/controls.js +152 -4
- package/src/view/html.js +18 -0
- package/themes/gramlot-base/README.md +6 -0
- package/themes/gramlot-base/theme.css +34 -6
- package/themes/gramlot-compact/README.md +6 -0
- package/themes/gramlot-compact/theme.css +8 -4
- package/themes/joanna/README.md +23 -0
- package/themes/joanna/theme.css +89 -0
- package/themes/mimi/README.md +23 -0
- package/themes/mimi/theme.css +89 -0
- package/tools/gramlot-tools-inspector.js +42 -18
- package/tools/inspector-agent.js +8 -4
package/dist/gramlot.js
CHANGED
|
@@ -60,7 +60,7 @@ var require_conventions = __commonJS({
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function freeze2(object, oc) {
|
|
64
64
|
if (oc === void 0) {
|
|
65
65
|
oc = Object;
|
|
66
66
|
}
|
|
@@ -83,7 +83,7 @@ var require_conventions = __commonJS({
|
|
|
83
83
|
}
|
|
84
84
|
return target;
|
|
85
85
|
}
|
|
86
|
-
var HTML_BOOLEAN_ATTRIBUTES =
|
|
86
|
+
var HTML_BOOLEAN_ATTRIBUTES = freeze2({
|
|
87
87
|
allowfullscreen: true,
|
|
88
88
|
async: true,
|
|
89
89
|
autofocus: true,
|
|
@@ -112,7 +112,7 @@ var require_conventions = __commonJS({
|
|
|
112
112
|
function isHTMLBooleanAttribute(name) {
|
|
113
113
|
return hasOwn(HTML_BOOLEAN_ATTRIBUTES, name.toLowerCase());
|
|
114
114
|
}
|
|
115
|
-
var HTML_VOID_ELEMENTS =
|
|
115
|
+
var HTML_VOID_ELEMENTS = freeze2({
|
|
116
116
|
area: true,
|
|
117
117
|
base: true,
|
|
118
118
|
br: true,
|
|
@@ -131,7 +131,7 @@ var require_conventions = __commonJS({
|
|
|
131
131
|
function isHTMLVoidElement(tagName) {
|
|
132
132
|
return hasOwn(HTML_VOID_ELEMENTS, tagName.toLowerCase());
|
|
133
133
|
}
|
|
134
|
-
var HTML_RAW_TEXT_ELEMENTS =
|
|
134
|
+
var HTML_RAW_TEXT_ELEMENTS = freeze2({
|
|
135
135
|
script: false,
|
|
136
136
|
style: false,
|
|
137
137
|
textarea: true,
|
|
@@ -151,7 +151,7 @@ var require_conventions = __commonJS({
|
|
|
151
151
|
function hasDefaultHTMLNamespace(mimeType) {
|
|
152
152
|
return isHTMLMimeType(mimeType) || mimeType === MIME_TYPE.XML_XHTML_APPLICATION;
|
|
153
153
|
}
|
|
154
|
-
var MIME_TYPE =
|
|
154
|
+
var MIME_TYPE = freeze2({
|
|
155
155
|
/**
|
|
156
156
|
* `text/html`, the only mime type that triggers treating an XML document as HTML.
|
|
157
157
|
*
|
|
@@ -204,7 +204,7 @@ var require_conventions = __commonJS({
|
|
|
204
204
|
function isValidMimeType(mimeType) {
|
|
205
205
|
return _MIME_TYPES.indexOf(mimeType) > -1;
|
|
206
206
|
}
|
|
207
|
-
var NAMESPACE =
|
|
207
|
+
var NAMESPACE = freeze2({
|
|
208
208
|
/**
|
|
209
209
|
* The XHTML namespace.
|
|
210
210
|
*
|
|
@@ -232,7 +232,7 @@ var require_conventions = __commonJS({
|
|
|
232
232
|
});
|
|
233
233
|
exports.assign = assign;
|
|
234
234
|
exports.find = find;
|
|
235
|
-
exports.freeze =
|
|
235
|
+
exports.freeze = freeze2;
|
|
236
236
|
exports.HTML_BOOLEAN_ATTRIBUTES = HTML_BOOLEAN_ATTRIBUTES;
|
|
237
237
|
exports.HTML_RAW_TEXT_ELEMENTS = HTML_RAW_TEXT_ELEMENTS;
|
|
238
238
|
exports.HTML_VOID_ELEMENTS = HTML_VOID_ELEMENTS;
|
|
@@ -3286,15 +3286,15 @@ var require_dom = __commonJS({
|
|
|
3286
3286
|
var require_entities = __commonJS({
|
|
3287
3287
|
"node_modules/@xmldom/xmldom/lib/entities.js"(exports) {
|
|
3288
3288
|
"use strict";
|
|
3289
|
-
var
|
|
3290
|
-
exports.XML_ENTITIES =
|
|
3289
|
+
var freeze2 = require_conventions().freeze;
|
|
3290
|
+
exports.XML_ENTITIES = freeze2({
|
|
3291
3291
|
amp: "&",
|
|
3292
3292
|
apos: "'",
|
|
3293
3293
|
gt: ">",
|
|
3294
3294
|
lt: "<",
|
|
3295
3295
|
quot: '"'
|
|
3296
3296
|
});
|
|
3297
|
-
exports.HTML_ENTITIES =
|
|
3297
|
+
exports.HTML_ENTITIES = freeze2({
|
|
3298
3298
|
Aacute: "\xC1",
|
|
3299
3299
|
aacute: "\xE1",
|
|
3300
3300
|
Abreve: "\u0102",
|
|
@@ -6565,6 +6565,160 @@ var HttpTransport = class {
|
|
|
6565
6565
|
}
|
|
6566
6566
|
};
|
|
6567
6567
|
|
|
6568
|
+
// node_modules/@genrojs/builders/src/pointers.js
|
|
6569
|
+
function pointerTransform(value) {
|
|
6570
|
+
if (typeof value !== "string" || !["^", "="].includes(value[0]) || value.startsWith("==")) return null;
|
|
6571
|
+
const index = value.indexOf(":");
|
|
6572
|
+
if (index < 0) return null;
|
|
6573
|
+
const expression = value[index + 1] === "=";
|
|
6574
|
+
return { pointer: value.slice(0, index), expression, body: value.slice(index + (expression ? 2 : 1)) };
|
|
6575
|
+
}
|
|
6576
|
+
var SLOT = /^\{(\??[A-Za-z_][A-Za-z0-9_]*|\?)?\}/;
|
|
6577
|
+
function pointerTemplate(body, read) {
|
|
6578
|
+
let result = "", blocked = false;
|
|
6579
|
+
for (let i = 0; i < body.length; ) {
|
|
6580
|
+
if (body[i] !== "{" && body[i] !== "}") {
|
|
6581
|
+
result += body[i++];
|
|
6582
|
+
continue;
|
|
6583
|
+
}
|
|
6584
|
+
const match = body.slice(i).match(SLOT);
|
|
6585
|
+
if (!match) throw new SyntaxError("Invalid pointer template placeholder");
|
|
6586
|
+
const slot = match[1] ?? "";
|
|
6587
|
+
const optional = slot.startsWith("?");
|
|
6588
|
+
const value = read(optional ? slot.slice(1) : slot);
|
|
6589
|
+
if (value == null || value === "" && !optional) blocked = true;
|
|
6590
|
+
else result += String(value);
|
|
6591
|
+
i += match[0].length;
|
|
6592
|
+
}
|
|
6593
|
+
return blocked ? null : result;
|
|
6594
|
+
}
|
|
6595
|
+
function pointerExpression(body) {
|
|
6596
|
+
const slots = [], identifiers = /* @__PURE__ */ new Set();
|
|
6597
|
+
let text = "", operand = true;
|
|
6598
|
+
for (let i = 0; i < body.length; ) {
|
|
6599
|
+
const start = i, c = body[i];
|
|
6600
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
6601
|
+
i++;
|
|
6602
|
+
while (i < body.length) {
|
|
6603
|
+
if (body[i] === "\\") {
|
|
6604
|
+
i += 2;
|
|
6605
|
+
continue;
|
|
6606
|
+
}
|
|
6607
|
+
if (body[i++] === c) break;
|
|
6608
|
+
}
|
|
6609
|
+
text += body.slice(start, i);
|
|
6610
|
+
operand = false;
|
|
6611
|
+
continue;
|
|
6612
|
+
}
|
|
6613
|
+
if (body.startsWith("//", i)) {
|
|
6614
|
+
i = body.indexOf("\n", i);
|
|
6615
|
+
if (i < 0) i = body.length;
|
|
6616
|
+
text += body.slice(start, i);
|
|
6617
|
+
continue;
|
|
6618
|
+
}
|
|
6619
|
+
if (body.startsWith("/*", i)) {
|
|
6620
|
+
const end = body.indexOf("*/", i + 2);
|
|
6621
|
+
i = end < 0 ? body.length : end + 2;
|
|
6622
|
+
text += body.slice(start, i);
|
|
6623
|
+
continue;
|
|
6624
|
+
}
|
|
6625
|
+
if (c === "/" && operand) {
|
|
6626
|
+
let bracket = false;
|
|
6627
|
+
i++;
|
|
6628
|
+
while (i < body.length) {
|
|
6629
|
+
const current = body[i++];
|
|
6630
|
+
if (current === "\\") {
|
|
6631
|
+
i++;
|
|
6632
|
+
continue;
|
|
6633
|
+
}
|
|
6634
|
+
if (current === "[") bracket = true;
|
|
6635
|
+
else if (current === "]") bracket = false;
|
|
6636
|
+
else if (current === "/" && !bracket) break;
|
|
6637
|
+
}
|
|
6638
|
+
while (/[a-z]/i.test(body[i] ?? "") && i < body.length) i++;
|
|
6639
|
+
text += body.slice(start, i);
|
|
6640
|
+
operand = false;
|
|
6641
|
+
continue;
|
|
6642
|
+
}
|
|
6643
|
+
const slot = c === "{" ? body.slice(i).match(SLOT) : null;
|
|
6644
|
+
if (slot) {
|
|
6645
|
+
const name = slot[1] ?? "";
|
|
6646
|
+
if (name.startsWith("?")) throw new SyntaxError("Optional slots are supported in pointer templates only");
|
|
6647
|
+
text += `_pointerValues[${slots.length}]`;
|
|
6648
|
+
slots.push(name);
|
|
6649
|
+
i += slot[0].length;
|
|
6650
|
+
operand = false;
|
|
6651
|
+
continue;
|
|
6652
|
+
}
|
|
6653
|
+
const word = body.slice(i).match(/^[A-Za-z_$][\w$]*/);
|
|
6654
|
+
if (word) {
|
|
6655
|
+
identifiers.add(word[0]);
|
|
6656
|
+
text += word[0];
|
|
6657
|
+
i += word[0].length;
|
|
6658
|
+
operand = ["return", "typeof", "void", "delete", "new", "in", "instanceof", "yield", "await"].includes(word[0]);
|
|
6659
|
+
continue;
|
|
6660
|
+
}
|
|
6661
|
+
text += c;
|
|
6662
|
+
i++;
|
|
6663
|
+
if (!/\s/.test(c)) operand = /[([{,:;=!?&|+*%~<>\/-]/.test(c);
|
|
6664
|
+
}
|
|
6665
|
+
return { text, slots, identifiers };
|
|
6666
|
+
}
|
|
6667
|
+
function resolvePointerItems(items, current, evaluate = () => null) {
|
|
6668
|
+
const values = /* @__PURE__ */ new Map(), active = [];
|
|
6669
|
+
const resolve = (name) => {
|
|
6670
|
+
if (values.has(name)) return values.get(name);
|
|
6671
|
+
if (!items.has(name)) throw new Error(`Referenced Source attribute '${name}' does not exist`);
|
|
6672
|
+
if (active.includes(name)) throw new Error(`Cyclic attribute dependency: ${[...active, name].join(" -> ")}`);
|
|
6673
|
+
active.push(name);
|
|
6674
|
+
try {
|
|
6675
|
+
const raw = items.get(name);
|
|
6676
|
+
const transform = typeof name === "string" ? pointerTransform(raw) : null;
|
|
6677
|
+
let result = current.get(name);
|
|
6678
|
+
if (transform) {
|
|
6679
|
+
const read = (key) => key ? resolve(key) : current.get(name);
|
|
6680
|
+
if (transform.expression) {
|
|
6681
|
+
const expression = pointerExpression(transform.body);
|
|
6682
|
+
result = evaluate(name, raw, expression, expression.slots.map(read));
|
|
6683
|
+
} else {
|
|
6684
|
+
result = pointerTemplate(transform.body, read);
|
|
6685
|
+
if (current.get(name) == null) result = null;
|
|
6686
|
+
}
|
|
6687
|
+
}
|
|
6688
|
+
values.set(name, result);
|
|
6689
|
+
return result;
|
|
6690
|
+
} finally {
|
|
6691
|
+
active.pop();
|
|
6692
|
+
}
|
|
6693
|
+
};
|
|
6694
|
+
return new Map([...items.keys()].map((name) => [name, resolve(name)]));
|
|
6695
|
+
}
|
|
6696
|
+
function pointerDependencies(node, raw) {
|
|
6697
|
+
const items = new Map([...Object.entries(node.getAttr()), ...node.fixedAttrItems()]);
|
|
6698
|
+
const seen = /* @__PURE__ */ new Set(), active = [];
|
|
6699
|
+
const visit = (value) => {
|
|
6700
|
+
const transform = pointerTransform(value);
|
|
6701
|
+
if (!transform) return;
|
|
6702
|
+
const names = [];
|
|
6703
|
+
if (transform.expression) names.push(...pointerExpression(transform.body).slots);
|
|
6704
|
+
else pointerTemplate(transform.body, (key) => {
|
|
6705
|
+
names.push(key);
|
|
6706
|
+
return "";
|
|
6707
|
+
});
|
|
6708
|
+
for (const name of names.filter(Boolean)) {
|
|
6709
|
+
if (!items.has(name)) throw new Error(`Referenced Source attribute '${name}' does not exist`);
|
|
6710
|
+
if (active.includes(name)) throw new Error(`Cyclic attribute dependency: ${[...active, name].join(" -> ")}`);
|
|
6711
|
+
if (seen.has(name)) continue;
|
|
6712
|
+
active.push(name);
|
|
6713
|
+
visit(items.get(name));
|
|
6714
|
+
active.pop();
|
|
6715
|
+
seen.add(name);
|
|
6716
|
+
}
|
|
6717
|
+
};
|
|
6718
|
+
visit(raw);
|
|
6719
|
+
return seen;
|
|
6720
|
+
}
|
|
6721
|
+
|
|
6568
6722
|
// node_modules/decimal.js/decimal.mjs
|
|
6569
6723
|
/*!
|
|
6570
6724
|
* decimal.js v10.6.0
|
|
@@ -11199,6 +11353,9 @@ function fromQs(data) {
|
|
|
11199
11353
|
// node_modules/@genrojs/tytx/js/src/registry.js
|
|
11200
11354
|
var DecimalClass = DecimalJS || BigJS || Number;
|
|
11201
11355
|
var decimalLibrary = DecimalJS ? "decimal.js" : BigJS ? "big.js" : "number";
|
|
11356
|
+
function getDecimalLibrary() {
|
|
11357
|
+
return decimalLibrary;
|
|
11358
|
+
}
|
|
11202
11359
|
function createDecimal(value) {
|
|
11203
11360
|
return new DecimalClass(value);
|
|
11204
11361
|
}
|
|
@@ -15209,7 +15366,7 @@ var SourceBagNode = class extends BagNode {
|
|
|
15209
15366
|
}
|
|
15210
15367
|
/** Return "^" (reactive), "=" (passive) or null. */
|
|
15211
15368
|
pointerType(v) {
|
|
15212
|
-
if (typeof v === "string" && (v[0] === "^" || v[0] === "=")) {
|
|
15369
|
+
if (typeof v === "string" && (v[0] === "^" || v[0] === "=") && !v.startsWith("==")) {
|
|
15213
15370
|
return v[0];
|
|
15214
15371
|
}
|
|
15215
15372
|
return null;
|
|
@@ -15221,11 +15378,11 @@ var SourceBagNode = class extends BagNode {
|
|
|
15221
15378
|
const result = [];
|
|
15222
15379
|
for (const [attrname, v] of Object.entries(this.getAttr() || {})) {
|
|
15223
15380
|
if (this.pointerType(v) === "^") {
|
|
15224
|
-
result.push([attrname, v]);
|
|
15381
|
+
result.push([attrname, v.split(":", 1)[0]]);
|
|
15225
15382
|
}
|
|
15226
15383
|
}
|
|
15227
15384
|
if (this.pointerType(this.value) === "^") {
|
|
15228
|
-
result.push(["", this.value]);
|
|
15385
|
+
result.push(["", this.value.split(":", 1)[0]]);
|
|
15229
15386
|
}
|
|
15230
15387
|
return result;
|
|
15231
15388
|
}
|
|
@@ -15244,14 +15401,14 @@ var SourceBagNode = class extends BagNode {
|
|
|
15244
15401
|
absDatapath(path) {
|
|
15245
15402
|
const raw = path;
|
|
15246
15403
|
if (this.pointerType(path)) {
|
|
15247
|
-
path = path.slice(1);
|
|
15404
|
+
path = (pointerTransform(path)?.pointer ?? path).slice(1);
|
|
15248
15405
|
}
|
|
15249
15406
|
let attr = null;
|
|
15250
15407
|
if (path.includes("?")) {
|
|
15251
15408
|
[path, attr] = path.split("?", 2);
|
|
15252
15409
|
}
|
|
15253
15410
|
if (path.startsWith("#")) {
|
|
15254
|
-
return this._resolveSymbolicDatapath(path, raw);
|
|
15411
|
+
return this._finalizeAbsPath(this._resolveSymbolicDatapath(path, raw), attr);
|
|
15255
15412
|
}
|
|
15256
15413
|
if (path.startsWith(".")) {
|
|
15257
15414
|
path = this._composeRelativeDatapath(path, raw);
|
|
@@ -15570,13 +15727,31 @@ function pythonRegexPattern(pattern, flags) {
|
|
|
15570
15727
|
}
|
|
15571
15728
|
function annotation(desc, path, nested = false, customTypes = null) {
|
|
15572
15729
|
if (desc === null) return null;
|
|
15573
|
-
exactKeys(desc, ["kind", "module", "name", "origin", "arguments", "items", "values", "base", "metadata", "pattern", "flags", "ge", "le", "gt", "lt", "value"], ["kind"], path);
|
|
15730
|
+
exactKeys(desc, ["kind", "dtype", "module", "name", "origin", "arguments", "items", "values", "base", "metadata", "pattern", "flags", "ge", "le", "gt", "lt", "value"], ["kind"], path);
|
|
15574
15731
|
switch (desc.kind) {
|
|
15575
15732
|
case "custom": {
|
|
15576
15733
|
exactKeys(desc, ["kind", "name"], ["kind", "name"], path);
|
|
15577
15734
|
if (!customTypes) fail(path, "custom references require a catalog; nested catalog references are unsupported");
|
|
15578
15735
|
return customTypes.resolve(desc.name, path);
|
|
15579
15736
|
}
|
|
15737
|
+
case "dtype": {
|
|
15738
|
+
exactKeys(desc, ["kind", "dtype"], ["kind", "dtype"], path);
|
|
15739
|
+
const code = desc.dtype;
|
|
15740
|
+
if (typeof code !== "string") fail(path, "dtype must be a string");
|
|
15741
|
+
const Type = getRegisteredType(code);
|
|
15742
|
+
if (!Type && code !== "NN") fail(path, `unknown dtype '${code}'`);
|
|
15743
|
+
const test = (value) => {
|
|
15744
|
+
if (code === "NN") return value === null;
|
|
15745
|
+
if (code === "N") return isDecimal2(value) && !["NaN", "Infinity", "-Infinity"].includes(value.toString());
|
|
15746
|
+
if (Type === Number) return typeof value === "number" && Number.isFinite(value) && (code !== "L" || Number.isInteger(value));
|
|
15747
|
+
if (Type === String) return typeof value === "string";
|
|
15748
|
+
if (Type === Boolean) return typeof value === "boolean";
|
|
15749
|
+
if (Type === Date) return value instanceof Date && Number.isFinite(value.getTime());
|
|
15750
|
+
if (Type === Object) return plainObject(value) && [Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
15751
|
+
return value instanceof Type;
|
|
15752
|
+
};
|
|
15753
|
+
return { ...desc, test };
|
|
15754
|
+
}
|
|
15580
15755
|
case "any":
|
|
15581
15756
|
return { ...desc, test: (_v) => true };
|
|
15582
15757
|
case "type": {
|
|
@@ -16823,41 +16998,47 @@ var BuilderBase = class _BuilderBase {
|
|
|
16823
16998
|
/** Resolve the pointers/values a node carries → [runtimeValue, runtimeAttrs]. */
|
|
16824
16999
|
runtimeValues(node) {
|
|
16825
17000
|
node.builder.validateCustomTypes(node);
|
|
16826
|
-
const
|
|
17001
|
+
const current = /* @__PURE__ */ new Map();
|
|
16827
17002
|
const carried = {};
|
|
17003
|
+
const items = node.runtimeToEvaluate();
|
|
17004
|
+
const projected = new Set(items.keys());
|
|
17005
|
+
const sourceAttrs = new Map([...Object.entries(node.getAttr()), ...node.fixedAttrItems()]);
|
|
17006
|
+
for (const [key, raw] of [...items]) {
|
|
17007
|
+
if (typeof key !== "string" || !pointerTransform(raw)) continue;
|
|
17008
|
+
for (const name of pointerDependencies(node, raw)) {
|
|
17009
|
+
if (!items.has(name)) items.set(name, sourceAttrs.get(name));
|
|
17010
|
+
}
|
|
17011
|
+
}
|
|
16828
17012
|
const isDataElement = node._getMeta("data_element");
|
|
16829
|
-
for (const [k, v] of
|
|
17013
|
+
for (const [k, v] of items) {
|
|
16830
17014
|
if (v instanceof BagResolver) {
|
|
16831
|
-
|
|
17015
|
+
current.set(k, v.resolve());
|
|
16832
17016
|
continue;
|
|
16833
17017
|
}
|
|
16834
|
-
|
|
16835
|
-
|
|
17018
|
+
const pointer = typeof k === "string" ? pointerTransform(v)?.pointer ?? v : v;
|
|
17019
|
+
if (!node.pointerType(pointer)) {
|
|
17020
|
+
current.set(k, typeof k === "string" && typeof v === "string" && v.startsWith("==") ? null : v);
|
|
16836
17021
|
continue;
|
|
16837
17022
|
}
|
|
16838
|
-
const absPath = node.absDatapath(
|
|
16839
|
-
|
|
17023
|
+
const absPath = node.absDatapath(pointer);
|
|
17024
|
+
current.set(k, this.data.getItem(absPath));
|
|
16840
17025
|
if (!isDataElement && !absPath.includes("?") && k === VALUE) {
|
|
16841
17026
|
const dataNode = this.data.getNode(absPath);
|
|
16842
17027
|
if (dataNode) Object.assign(carried, dataNode.getAttr("_wdg"));
|
|
16843
17028
|
}
|
|
16844
17029
|
}
|
|
16845
|
-
const
|
|
16846
|
-
for (const [k, v] of resolved2) {
|
|
16847
|
-
if (isDataElement || k === VALUE || typeof v !== "string") continue;
|
|
16848
|
-
resolved2.set(k, v.replace(/(\\)?\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g, (token, escaped, name) => {
|
|
16849
|
-
if (escaped) return token.slice(1);
|
|
16850
|
-
if (!resolved2.has(name)) throw new Error(`Unknown template parameter '${name}'`);
|
|
16851
|
-
consumed.add(name);
|
|
16852
|
-
const value = resolved2.get(name);
|
|
16853
|
-
return value === null ? "" : String(value);
|
|
16854
|
-
}));
|
|
16855
|
-
}
|
|
17030
|
+
const resolved2 = resolvePointerItems(items, current, (name, raw, expression, inputs) => this.evaluatePointerExpression(node, name, raw, expression, inputs));
|
|
16856
17031
|
const runtimeValue = resolved2.get(VALUE);
|
|
16857
17032
|
resolved2.delete(VALUE);
|
|
16858
|
-
for (const name of
|
|
17033
|
+
for (const name of resolved2.keys()) if (!projected.has(name)) resolved2.delete(name);
|
|
16859
17034
|
return [runtimeValue, { ...Object.fromEntries(resolved2), ...carried }];
|
|
16860
17035
|
}
|
|
17036
|
+
/** Consumer hook for := expressions. Static builders intentionally return null.
|
|
17037
|
+
* Override using the runtime's compiler/CSP policy. inputs are typed slot values;
|
|
17038
|
+
* expression.text refers to them through _pointerValues, never textual injection. */
|
|
17039
|
+
evaluatePointerExpression(node, name, raw, expression, inputs) {
|
|
17040
|
+
return null;
|
|
17041
|
+
}
|
|
16861
17042
|
/** Stable per-document identity assigned when a renderer requests it. */
|
|
16862
17043
|
targetId(node) {
|
|
16863
17044
|
if (node._targetId) {
|
|
@@ -21878,128 +22059,713 @@ var Handler = class {
|
|
|
21878
22059
|
}
|
|
21879
22060
|
};
|
|
21880
22061
|
|
|
21881
|
-
// src/
|
|
21882
|
-
|
|
21883
|
-
|
|
21884
|
-
|
|
21885
|
-
|
|
21886
|
-
|
|
21887
|
-
|
|
22062
|
+
// src/webcomponent.js
|
|
22063
|
+
var NAME2 = /^[a-z][.0-9_a-z\-\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
|
|
22064
|
+
var RESERVED = /* @__PURE__ */ new Set([
|
|
22065
|
+
"annotation-xml",
|
|
22066
|
+
"color-profile",
|
|
22067
|
+
"font-face",
|
|
22068
|
+
"font-face-src",
|
|
22069
|
+
"font-face-uri",
|
|
22070
|
+
"font-face-format",
|
|
22071
|
+
"font-face-name",
|
|
22072
|
+
"missing-glyph"
|
|
22073
|
+
]);
|
|
22074
|
+
function webcomponentCode(attrs) {
|
|
22075
|
+
const code = attrs.code;
|
|
22076
|
+
if (typeof code !== "string" || NAME2.exec(code)?.[0] !== code || !code.includes("-") || RESERVED.has(code)) {
|
|
22077
|
+
throw new TypeError("webcomponent: code must be a literal custom-element name");
|
|
22078
|
+
}
|
|
22079
|
+
return code;
|
|
21888
22080
|
}
|
|
21889
|
-
|
|
21890
|
-
|
|
21891
|
-
|
|
22081
|
+
|
|
22082
|
+
// src/components/registry.js
|
|
22083
|
+
function freeze(value) {
|
|
22084
|
+
for (const child of Object.values(value)) if (child && typeof child === "object") freeze(child);
|
|
22085
|
+
return Object.freeze(value);
|
|
22086
|
+
}
|
|
22087
|
+
function annotation2(parameter) {
|
|
22088
|
+
if (typeof parameter.dtype !== "string" && !Array.isArray(parameter.dtype)) throw new TypeError("Component parameter requires dtype");
|
|
22089
|
+
const alternatives = (Array.isArray(parameter.dtype) ? parameter.dtype : [parameter.dtype]).map((dtype) => ({ kind: "dtype", dtype }));
|
|
22090
|
+
if (parameter.nullable) alternatives.push({ kind: "dtype", dtype: "NN" });
|
|
22091
|
+
if (parameter.binding && parameter.dtype !== "T") alternatives.push({
|
|
22092
|
+
kind: "annotated",
|
|
22093
|
+
base: { kind: "dtype", dtype: "T" },
|
|
22094
|
+
metadata: [{ kind: "regex", pattern: "^[\\^=].+", flags: 0 }]
|
|
22095
|
+
});
|
|
22096
|
+
return alternatives.length === 1 ? alternatives[0] : { kind: "union", items: alternatives };
|
|
22097
|
+
}
|
|
22098
|
+
function defineComponent({ name, tag: tag2, base, mixins = [], parameters: parameters2 = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, implementation }) {
|
|
22099
|
+
webcomponentCode({ code: tag2 });
|
|
22100
|
+
if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError("Invalid component authoring name");
|
|
22101
|
+
const effective = { ...base.parameters };
|
|
22102
|
+
for (const mixin of mixins) {
|
|
22103
|
+
for (const [key, spec] of Object.entries(mixin.parameters)) {
|
|
22104
|
+
if (Object.hasOwn(effective, key)) throw new Error(`Duplicate mixin parameter: ${key}`);
|
|
22105
|
+
effective[key] = spec;
|
|
22106
|
+
}
|
|
22107
|
+
}
|
|
22108
|
+
Object.assign(effective, parameters2);
|
|
22109
|
+
for (const spec of Object.values(effective)) annotation2(spec);
|
|
22110
|
+
return Object.freeze({
|
|
22111
|
+
name,
|
|
22112
|
+
tag: tag2,
|
|
22113
|
+
base,
|
|
22114
|
+
subTags,
|
|
22115
|
+
presentationDefaults: Object.freeze([...presentationDefaults]),
|
|
22116
|
+
dataScope,
|
|
22117
|
+
command,
|
|
22118
|
+
mixins: Object.freeze([...mixins]),
|
|
22119
|
+
parameters: freeze(structuredClone(effective)),
|
|
22120
|
+
implementation
|
|
22121
|
+
});
|
|
21892
22122
|
}
|
|
21893
|
-
|
|
21894
|
-
|
|
21895
|
-
|
|
21896
|
-
|
|
21897
|
-
|
|
21898
|
-
|
|
22123
|
+
var ComponentCollection = class {
|
|
22124
|
+
#classes = /* @__PURE__ */ new WeakMap();
|
|
22125
|
+
constructor({ name, components }) {
|
|
22126
|
+
this.name = name;
|
|
22127
|
+
this.components = Object.freeze([...components]);
|
|
22128
|
+
const names = /* @__PURE__ */ new Set(), tags = /* @__PURE__ */ new Set();
|
|
22129
|
+
for (const component of components) {
|
|
22130
|
+
if (names.has(component.name.toLowerCase()) || tags.has(component.tag)) {
|
|
22131
|
+
throw new Error(`Duplicate component: ${component.name}`);
|
|
22132
|
+
}
|
|
22133
|
+
names.add(component.name.toLowerCase());
|
|
22134
|
+
tags.add(component.tag);
|
|
21899
22135
|
}
|
|
21900
|
-
const match = body.slice(i).match(SLOT);
|
|
21901
|
-
if (!match) throw new SyntaxError("Invalid pointer template placeholder");
|
|
21902
|
-
const slot = match[1] ?? "";
|
|
21903
|
-
const optional = slot.startsWith("?");
|
|
21904
|
-
const value = read(optional ? slot.slice(1) : slot);
|
|
21905
|
-
if (value == null || value === "" && !optional) blocked = true;
|
|
21906
|
-
else result += String(value);
|
|
21907
|
-
i += match[0].length;
|
|
21908
22136
|
}
|
|
21909
|
-
|
|
22137
|
+
/** Same JSON consumed by Python and JavaScript Builders. */
|
|
22138
|
+
toDocument() {
|
|
22139
|
+
return {
|
|
22140
|
+
document_format: { name: "builder_grammar", version: "1.1" },
|
|
22141
|
+
grammar: { name: this.name, version: null, title: this.name, description: null },
|
|
22142
|
+
abstracts: {},
|
|
22143
|
+
elements: Object.fromEntries(this.components.map((component) => [component.name, {
|
|
22144
|
+
doc: null,
|
|
22145
|
+
sub_tags: component.subTags,
|
|
22146
|
+
parent_tags: null,
|
|
22147
|
+
inherits_from: null,
|
|
22148
|
+
ns: null,
|
|
22149
|
+
node_label: null,
|
|
22150
|
+
collection_key: null,
|
|
22151
|
+
attributes: {
|
|
22152
|
+
parameters: [
|
|
22153
|
+
...Object.entries(component.parameters).map(([name, spec]) => ({
|
|
22154
|
+
name,
|
|
22155
|
+
kind: "keyword_only",
|
|
22156
|
+
role: "attribute",
|
|
22157
|
+
annotation: annotation2(spec),
|
|
22158
|
+
has_default: true,
|
|
22159
|
+
default: spec.default ?? null
|
|
22160
|
+
})),
|
|
22161
|
+
{
|
|
22162
|
+
name: "attr",
|
|
22163
|
+
kind: "var_keyword",
|
|
22164
|
+
role: "attribute",
|
|
22165
|
+
annotation: { kind: "any" },
|
|
22166
|
+
has_default: false
|
|
22167
|
+
}
|
|
22168
|
+
],
|
|
22169
|
+
accepts_var_keyword: true,
|
|
22170
|
+
accepts_var_positional: false
|
|
22171
|
+
},
|
|
22172
|
+
_meta: { render_tag: component.tag, gramlot_component: {
|
|
22173
|
+
parameters: structuredClone(component.parameters),
|
|
22174
|
+
presentationDefaults: [...component.presentationDefaults],
|
|
22175
|
+
dataScope: component.dataScope,
|
|
22176
|
+
command: component.command
|
|
22177
|
+
} }
|
|
22178
|
+
}]))
|
|
22179
|
+
};
|
|
22180
|
+
}
|
|
22181
|
+
/** Register once per document realm, only when the collection is activated. */
|
|
22182
|
+
register(window2) {
|
|
22183
|
+
if (this.#classes.has(window2)) return;
|
|
22184
|
+
const classes2 = [];
|
|
22185
|
+
for (const component of this.components) {
|
|
22186
|
+
if (window2.customElements.get(component.tag)) throw new Error(`Custom element already registered: ${component.tag}`);
|
|
22187
|
+
let Base = component.base(window2.HTMLElement);
|
|
22188
|
+
for (const mixin of component.mixins) Base = mixin(Base);
|
|
22189
|
+
const Class = component.implementation(Base);
|
|
22190
|
+
Object.defineProperty(Class, "gramlotComponent", { value: component });
|
|
22191
|
+
classes2.push([component.tag, Class]);
|
|
22192
|
+
}
|
|
22193
|
+
for (const [tag2, Class] of classes2) window2.customElements.define(tag2, Class);
|
|
22194
|
+
this.#classes.set(window2, classes2);
|
|
22195
|
+
}
|
|
22196
|
+
};
|
|
22197
|
+
function defineCollection(options) {
|
|
22198
|
+
return new ComponentCollection(options);
|
|
21910
22199
|
}
|
|
21911
|
-
|
|
21912
|
-
|
|
21913
|
-
|
|
21914
|
-
|
|
21915
|
-
|
|
21916
|
-
|
|
21917
|
-
|
|
21918
|
-
|
|
21919
|
-
|
|
21920
|
-
|
|
21921
|
-
|
|
21922
|
-
|
|
21923
|
-
|
|
21924
|
-
|
|
21925
|
-
|
|
21926
|
-
|
|
21927
|
-
|
|
22200
|
+
|
|
22201
|
+
// src/components/parameters.js
|
|
22202
|
+
function projectParameters(element, attrs) {
|
|
22203
|
+
element.parameters = Object.fromEntries(Object.entries(element.constructor.gramlotComponent.parameters).map(([name, spec]) => [name, Object.hasOwn(attrs, name) ? attrs[name] : spec.default]));
|
|
22204
|
+
return Object.fromEntries(Object.entries(attrs).filter(([name]) => !Object.hasOwn(element.parameters, name)));
|
|
22205
|
+
}
|
|
22206
|
+
|
|
22207
|
+
// src/components/choices.js
|
|
22208
|
+
function parseChoices(values) {
|
|
22209
|
+
if (values === "") return [];
|
|
22210
|
+
const ids = /* @__PURE__ */ new Set();
|
|
22211
|
+
return values.split(",").map((item) => {
|
|
22212
|
+
const colon = item.indexOf(":");
|
|
22213
|
+
const id = colon < 0 ? item : item.slice(0, colon);
|
|
22214
|
+
const caption = colon < 0 ? item : item.slice(colon + 1);
|
|
22215
|
+
if (!id || ids.has(id)) throw new Error("Invalid or duplicate choice code");
|
|
22216
|
+
ids.add(id);
|
|
22217
|
+
return { id, caption };
|
|
22218
|
+
});
|
|
22219
|
+
}
|
|
22220
|
+
|
|
22221
|
+
// src/components/bases.js
|
|
22222
|
+
function controlElement(HTMLElement) {
|
|
22223
|
+
return class extends HTMLElement {
|
|
22224
|
+
constructor() {
|
|
22225
|
+
super();
|
|
22226
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
22227
|
+
const style = this.ownerDocument.createElement("style");
|
|
22228
|
+
style.textContent = `:host{display:inline-block;font:inherit} *,*::before,*::after{box-sizing:border-box}
|
|
22229
|
+
input,textarea{font:inherit;max-width:100%} .control-box{min-width:0;color:var(--gramlot-ink,CanvasText)}
|
|
22230
|
+
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),textarea{
|
|
22231
|
+
appearance:none;box-sizing:border-box;border:1px solid var(--gramlot-border-control,#7a8798);
|
|
22232
|
+
border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText);
|
|
22233
|
+
min-height:var(--gramlot-field-height,28px);padding:var(--gramlot-field-padding,.25em .5em);font-size:var(--gramlot-field-font-size,1em);line-height:var(--gramlot-field-line-height,inherit)}
|
|
22234
|
+
input:read-only:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),textarea:read-only{
|
|
22235
|
+
background:var(--gramlot-field-readonly-background,Canvas)}
|
|
22236
|
+
input:disabled,textarea:disabled{opacity:.6;cursor:not-allowed}
|
|
22237
|
+
input::placeholder,textarea::placeholder{color:var(--gramlot-text-secondary,GrayText)}
|
|
22238
|
+
input:focus-visible,textarea:focus-visible,button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:1px}
|
|
22239
|
+
input[type=checkbox],input[type=radio],input[type=range]{accent-color:var(--gramlot-brand-blue,Highlight)}
|
|
22240
|
+
input[type=range],input[type=color],button{min-width:var(--gramlot-touch-target,0px);min-height:var(--gramlot-touch-target,0px)}
|
|
22241
|
+
input[type=checkbox],input[type=radio]{min-width:calc(var(--gramlot-touch-target,0px) / 2);min-height:calc(var(--gramlot-touch-target,0px) / 2)}
|
|
22242
|
+
.options{display:grid;gap:.3em .8em} .option{display:flex;align-items:center;gap:.35em;min-width:var(--gramlot-touch-target,0px);min-height:var(--gramlot-touch-target,0px)}
|
|
22243
|
+
.caption:empty{display:none}`;
|
|
22244
|
+
this.controlBox = this.ownerDocument.createElement("div");
|
|
22245
|
+
this.controlBox.className = "control-box";
|
|
22246
|
+
shadow.append(style, this.controlBox);
|
|
22247
|
+
}
|
|
22248
|
+
projectAttributes(attrs) {
|
|
22249
|
+
return projectParameters(this, attrs);
|
|
22250
|
+
}
|
|
22251
|
+
setPageContext(context) {
|
|
22252
|
+
this.pageContext = context;
|
|
22253
|
+
}
|
|
22254
|
+
releaseControl() {
|
|
22255
|
+
}
|
|
22256
|
+
validateCandidate(value, accept) {
|
|
22257
|
+
accept(value);
|
|
22258
|
+
return { ok: true, value, isCurrent: () => this.pageContext.isActive() };
|
|
22259
|
+
}
|
|
22260
|
+
finishValidation() {
|
|
22261
|
+
}
|
|
22262
|
+
validateSelection() {
|
|
22263
|
+
throw new TypeError("validate_select requires a constrained choice editor.");
|
|
22264
|
+
}
|
|
22265
|
+
shouldProjectControlValue() {
|
|
22266
|
+
return true;
|
|
21928
22267
|
}
|
|
21929
|
-
|
|
21930
|
-
|
|
21931
|
-
|
|
21932
|
-
|
|
21933
|
-
|
|
22268
|
+
acceptControlValue() {
|
|
22269
|
+
const value = this.readControlValue();
|
|
22270
|
+
return this.validateCandidate(value, (accepted) => {
|
|
22271
|
+
if (accepted == null && !this.constructor.gramlotComponent.parameters.value.nullable) throw new TypeError("This component requires a non-null value.");
|
|
22272
|
+
if (accepted != null && value != null && typeof accepted !== typeof value) throw new TypeError("Validation must preserve the component value type.");
|
|
22273
|
+
if (!this.sameControlValue(value, accepted)) this.writeControlValue(accepted);
|
|
22274
|
+
});
|
|
21934
22275
|
}
|
|
21935
|
-
|
|
21936
|
-
|
|
21937
|
-
i = end < 0 ? body.length : end + 2;
|
|
21938
|
-
text += body.slice(start, i);
|
|
21939
|
-
continue;
|
|
22276
|
+
sameControlValue(a, b) {
|
|
22277
|
+
return Object.is(a, b);
|
|
21940
22278
|
}
|
|
21941
|
-
|
|
21942
|
-
|
|
21943
|
-
|
|
21944
|
-
|
|
21945
|
-
|
|
21946
|
-
|
|
21947
|
-
|
|
21948
|
-
|
|
22279
|
+
focus(options) {
|
|
22280
|
+
this.control.focus(options);
|
|
22281
|
+
}
|
|
22282
|
+
};
|
|
22283
|
+
}
|
|
22284
|
+
function NativeControl(HTMLElement) {
|
|
22285
|
+
return class extends controlElement(HTMLElement) {
|
|
22286
|
+
constructor() {
|
|
22287
|
+
super();
|
|
22288
|
+
this.control = this.createControl();
|
|
22289
|
+
if (this.control.localName === "textarea" || this.control.localName === "input" && ["text", "password"].includes(this.control.type)) {
|
|
22290
|
+
this.control.setAttribute("autocomplete", "off");
|
|
22291
|
+
this.control.setAttribute("autocorrect", "off");
|
|
22292
|
+
this.control.setAttribute("autocapitalize", "off");
|
|
22293
|
+
this.control.setAttribute("spellcheck", "false");
|
|
22294
|
+
}
|
|
22295
|
+
this.control.id = "control";
|
|
22296
|
+
const option = this.ownerDocument.createElement("label");
|
|
22297
|
+
option.className = "option";
|
|
22298
|
+
this.optionCaption = this.ownerDocument.createElement("span");
|
|
22299
|
+
this.optionCaption.className = "caption";
|
|
22300
|
+
option.append(this.control, this.optionCaption);
|
|
22301
|
+
this.controlBox.append(option);
|
|
22302
|
+
}
|
|
22303
|
+
projectAttributes(attrs, adapt) {
|
|
22304
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
22305
|
+
const { disabled, readonly } = this.parameters;
|
|
22306
|
+
this.control.disabled = Boolean(disabled);
|
|
22307
|
+
this.control.readOnly = Boolean(readonly);
|
|
22308
|
+
for (const [name, spec] of Object.entries(this.constructor.gramlotComponent.parameters)) {
|
|
22309
|
+
if (spec.target === "control") {
|
|
22310
|
+
const value = this.parameters[name] ?? "";
|
|
22311
|
+
if (String(this.control[name]) !== String(value)) this.control[name] = value;
|
|
21949
22312
|
}
|
|
21950
|
-
if (
|
|
21951
|
-
else if (current === "]") bracket = false;
|
|
21952
|
-
else if (current === "/" && !bracket) break;
|
|
22313
|
+
if (spec.target === "optionCaption") this.optionCaption.textContent = this.parameters[name] ?? "";
|
|
21953
22314
|
}
|
|
21954
|
-
|
|
21955
|
-
text += body.slice(start, i);
|
|
21956
|
-
operand = false;
|
|
21957
|
-
continue;
|
|
22315
|
+
return rest;
|
|
21958
22316
|
}
|
|
21959
|
-
|
|
21960
|
-
|
|
21961
|
-
|
|
21962
|
-
|
|
21963
|
-
|
|
21964
|
-
|
|
21965
|
-
|
|
21966
|
-
|
|
21967
|
-
|
|
22317
|
+
};
|
|
22318
|
+
}
|
|
22319
|
+
NativeControl.parameters = {
|
|
22320
|
+
disabled: { dtype: "B", default: false, binding: "read" },
|
|
22321
|
+
readonly: { dtype: "B", default: false, binding: "read" },
|
|
22322
|
+
live: { dtype: "B", default: false, binding: "read" }
|
|
22323
|
+
};
|
|
22324
|
+
function ChoiceGroup(HTMLElement) {
|
|
22325
|
+
return class extends controlElement(HTMLElement) {
|
|
22326
|
+
#options = /* @__PURE__ */ new Map();
|
|
22327
|
+
#values;
|
|
22328
|
+
#value = null;
|
|
22329
|
+
constructor() {
|
|
22330
|
+
super();
|
|
22331
|
+
this.control = this.ownerDocument.createElement("div");
|
|
22332
|
+
this.control.className = "options";
|
|
22333
|
+
this.control.id = "control";
|
|
22334
|
+
this.control.setAttribute("role", this.multiple ? "group" : "radiogroup");
|
|
22335
|
+
this.controlBox.append(this.control);
|
|
22336
|
+
this.control.addEventListener("keydown", (event) => {
|
|
22337
|
+
if (!this.multiple || !["ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
22338
|
+
const items = [...this.control.querySelectorAll("input:not(:disabled)")];
|
|
22339
|
+
const index = items.indexOf(event.target);
|
|
22340
|
+
if (index < 0) return;
|
|
22341
|
+
event.preventDefault();
|
|
22342
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? items.length - 1 : Math.max(0, Math.min(items.length - 1, index + (["ArrowDown", "ArrowRight"].includes(event.key) ? 1 : -1)));
|
|
22343
|
+
items[next].focus();
|
|
22344
|
+
});
|
|
21968
22345
|
}
|
|
21969
|
-
|
|
21970
|
-
|
|
21971
|
-
|
|
21972
|
-
|
|
21973
|
-
|
|
21974
|
-
|
|
21975
|
-
|
|
22346
|
+
projectAttributes(attrs, adapt) {
|
|
22347
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
22348
|
+
const values = this.parameters.values ?? "";
|
|
22349
|
+
if (values !== this.#values) {
|
|
22350
|
+
const options = parseChoices(values);
|
|
22351
|
+
const retained = /* @__PURE__ */ new Set();
|
|
22352
|
+
let previous = null;
|
|
22353
|
+
for (const { id: code, caption } of options) {
|
|
22354
|
+
let item = this.#options.get(code);
|
|
22355
|
+
if (!item) {
|
|
22356
|
+
const label = this.ownerDocument.createElement("label");
|
|
22357
|
+
label.className = "option";
|
|
22358
|
+
const input = this.ownerDocument.createElement("input");
|
|
22359
|
+
input.type = this.choiceType;
|
|
22360
|
+
input.name = "choice";
|
|
22361
|
+
input.value = code;
|
|
22362
|
+
const text = this.ownerDocument.createElement("span");
|
|
22363
|
+
label.append(input, text);
|
|
22364
|
+
item = { label, input, text };
|
|
22365
|
+
this.#options.set(code, item);
|
|
22366
|
+
}
|
|
22367
|
+
item.text.textContent = caption;
|
|
22368
|
+
const expected = previous ? previous.nextSibling : this.control.firstChild;
|
|
22369
|
+
if (expected !== item.label) this.control.insertBefore(item.label, expected);
|
|
22370
|
+
previous = item.label;
|
|
22371
|
+
retained.add(code);
|
|
22372
|
+
}
|
|
22373
|
+
for (const [code, item] of this.#options) if (!retained.has(code)) {
|
|
22374
|
+
item.label.remove();
|
|
22375
|
+
this.#options.delete(code);
|
|
22376
|
+
}
|
|
22377
|
+
this.#values = values;
|
|
22378
|
+
}
|
|
22379
|
+
const cols = this.parameters.cols;
|
|
22380
|
+
if (!Number.isInteger(cols) || cols < 1) throw new TypeError("cols must be a positive integer");
|
|
22381
|
+
this.control.style.gridTemplateColumns = `repeat(${cols}, minmax(0, 1fr))`;
|
|
22382
|
+
this.control.disabled = Boolean(this.parameters.disabled);
|
|
22383
|
+
this.control.readOnly = Boolean(this.parameters.readonly);
|
|
22384
|
+
for (const { input } of this.#options.values()) input.disabled = this.control.disabled || this.control.readOnly;
|
|
22385
|
+
return rest;
|
|
22386
|
+
}
|
|
22387
|
+
readControlValue() {
|
|
22388
|
+
if (this.multiple) {
|
|
22389
|
+
const codes = this.#value ? this.#value.split(",") : [];
|
|
22390
|
+
const selected = codes.filter((code) => !this.#options.has(code) || this.#options.get(code).input.checked);
|
|
22391
|
+
for (const [code, { input }] of this.#options) if (input.checked && !selected.includes(code)) selected.push(code);
|
|
22392
|
+
return selected.join(",") || null;
|
|
22393
|
+
}
|
|
22394
|
+
for (const [code, { input }] of this.#options) if (input.checked) return code;
|
|
22395
|
+
return null;
|
|
21976
22396
|
}
|
|
21977
|
-
|
|
21978
|
-
|
|
21979
|
-
|
|
21980
|
-
|
|
21981
|
-
|
|
22397
|
+
writeControlValue(value) {
|
|
22398
|
+
this.#value = value;
|
|
22399
|
+
const selected = this.multiple ? new Set(value ? value.split(",") : []) : null;
|
|
22400
|
+
for (const [code, { input }] of this.#options) input.checked = this.multiple ? selected.has(code) : code === value;
|
|
22401
|
+
}
|
|
22402
|
+
acceptControlValue() {
|
|
22403
|
+
const value = this.readControlValue();
|
|
22404
|
+
return this.validateCandidate(value, (accepted) => this.writeControlValue(accepted));
|
|
22405
|
+
}
|
|
22406
|
+
focus(options) {
|
|
22407
|
+
const items = [...this.#options.values()];
|
|
22408
|
+
(items.find(({ input }) => input.checked && !input.disabled) ?? items.find(({ input }) => !input.disabled))?.input.focus(options);
|
|
22409
|
+
}
|
|
22410
|
+
};
|
|
21982
22411
|
}
|
|
21983
|
-
|
|
21984
|
-
|
|
21985
|
-
|
|
21986
|
-
|
|
21987
|
-
|
|
21988
|
-
|
|
21989
|
-
|
|
21990
|
-
|
|
21991
|
-
|
|
21992
|
-
|
|
21993
|
-
const
|
|
21994
|
-
|
|
21995
|
-
|
|
21996
|
-
|
|
21997
|
-
|
|
22412
|
+
ChoiceGroup.parameters = {
|
|
22413
|
+
disabled: { dtype: "B", default: false, binding: "read" },
|
|
22414
|
+
readonly: { dtype: "B", default: false, binding: "read" }
|
|
22415
|
+
};
|
|
22416
|
+
|
|
22417
|
+
// src/components/popup.js
|
|
22418
|
+
var VIEWPORT_MARGIN = 8;
|
|
22419
|
+
var ANCHOR_GAP = 3;
|
|
22420
|
+
function positionPopup(popup, anchor, { align = "start", matchWidth = false } = {}) {
|
|
22421
|
+
const view = anchor.ownerDocument.defaultView;
|
|
22422
|
+
const field = anchor.getBoundingClientRect();
|
|
22423
|
+
const availableWidth = Math.max(0, view.innerWidth - 2 * VIEWPORT_MARGIN);
|
|
22424
|
+
popup.style.setProperty("--gramlot-popup-available-width", `${availableWidth}px`);
|
|
22425
|
+
if (matchWidth) popup.style.width = `${Math.min(field.width, availableWidth)}px`;
|
|
22426
|
+
popup.style.removeProperty("--gramlot-popup-available-height");
|
|
22427
|
+
const natural = popup.getBoundingClientRect();
|
|
22428
|
+
const below = Math.max(0, view.innerHeight - VIEWPORT_MARGIN - field.bottom - ANCHOR_GAP);
|
|
22429
|
+
const above = Math.max(0, field.top - VIEWPORT_MARGIN - ANCHOR_GAP);
|
|
22430
|
+
const upwards = natural.height > below && above > below;
|
|
22431
|
+
popup.style.setProperty("--gramlot-popup-available-height", `${upwards ? above : below}px`);
|
|
22432
|
+
const size = popup.getBoundingClientRect();
|
|
22433
|
+
const left = align === "end" ? field.right - size.width : field.left;
|
|
22434
|
+
const top = upwards ? field.top - size.height - ANCHOR_GAP : field.bottom + ANCHOR_GAP;
|
|
22435
|
+
popup.style.left = `${Math.max(VIEWPORT_MARGIN, Math.min(left, view.innerWidth - size.width - VIEWPORT_MARGIN))}px`;
|
|
22436
|
+
popup.style.top = `${Math.max(VIEWPORT_MARGIN, Math.min(top, view.innerHeight - size.height - VIEWPORT_MARGIN))}px`;
|
|
22437
|
+
}
|
|
22438
|
+
|
|
22439
|
+
// src/components/buttons.js
|
|
22440
|
+
function Command(HTMLElement) {
|
|
22441
|
+
return class extends controlElement(HTMLElement) {
|
|
22442
|
+
constructor() {
|
|
22443
|
+
super();
|
|
22444
|
+
const doc = this.ownerDocument;
|
|
22445
|
+
this.control = doc.createElement("button");
|
|
22446
|
+
this.control.type = "button";
|
|
22447
|
+
this.control.id = "control";
|
|
22448
|
+
this.icon = doc.createElement("span");
|
|
22449
|
+
this.icon.className = "icon";
|
|
22450
|
+
this.icon.setAttribute("aria-hidden", "true");
|
|
22451
|
+
this.caption = doc.createElement("slot");
|
|
22452
|
+
this.control.append(this.icon, this.caption);
|
|
22453
|
+
this.controlBox.append(this.control);
|
|
22454
|
+
const style = doc.createElement("style");
|
|
22455
|
+
style.textContent = `:host{vertical-align:middle} .control-box{display:flex;align-items:stretch}
|
|
22456
|
+
button{display:inline-flex;align-items:center;justify-content:center;gap:var(--gramlot-button-gap,.35em);font:inherit;
|
|
22457
|
+
color:var(--gramlot-ink,CanvasText);background:var(--gramlot-button-background,var(--gramlot-field-background,Canvas));
|
|
22458
|
+
border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,4px);
|
|
22459
|
+
min-height:max(var(--gramlot-field-height,28px),var(--gramlot-touch-target,0px));
|
|
22460
|
+
padding:var(--gramlot-button-padding,.25em .65em);cursor:pointer}
|
|
22461
|
+
button:hover:not(:disabled){background:var(--gramlot-button-hover,var(--gramlot-field-readonly-background,#eee))}
|
|
22462
|
+
button:disabled{opacity:.55;cursor:not-allowed} .icon:empty{display:none}
|
|
22463
|
+
.led{display:inline-block;width:.6em;height:.6em;border-radius:50%;background:var(--gramlot-button-led-off,#888)}
|
|
22464
|
+
[aria-pressed=true] .led{background:var(--gramlot-button-led-on,#2b9a46)}
|
|
22465
|
+
.arrow{border-start-start-radius:0;border-end-start-radius:0;border-inline-start:0}
|
|
22466
|
+
.split{border-start-end-radius:0;border-end-end-radius:0}
|
|
22467
|
+
.popup{position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);overflow:auto;
|
|
22468
|
+
max-width:var(--gramlot-popup-available-width);max-height:var(--gramlot-popup-available-height);
|
|
22469
|
+
border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,4px);
|
|
22470
|
+
color:var(--gramlot-ink,CanvasText);background:var(--gramlot-field-background,Canvas);box-shadow:0 3px 12px #0003}
|
|
22471
|
+
:host([role=menuitem]){display:block} :host([role=menuitem]) button{width:100%;justify-content:start;border:0;background:transparent}
|
|
22472
|
+
:host([role=separator]){display:block;border-top:1px solid var(--gramlot-border-control,#888);margin:.25em}
|
|
22473
|
+
:host([role=separator]) button{display:none}`;
|
|
22474
|
+
this.shadowRoot.append(style);
|
|
22475
|
+
}
|
|
22476
|
+
get disabled() {
|
|
22477
|
+
return this.control.disabled;
|
|
22478
|
+
}
|
|
22479
|
+
set disabled(value) {
|
|
22480
|
+
this.control.disabled = Boolean(value);
|
|
22481
|
+
}
|
|
22482
|
+
projectAttributes(attrs, adapt) {
|
|
22483
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
22484
|
+
this.control.disabled = Boolean(this.parameters.disabled);
|
|
22485
|
+
this.control.readOnly = Boolean(this.parameters.readonly);
|
|
22486
|
+
this.icon.textContent = this.parameters.icon ?? "";
|
|
22487
|
+
if (attrs["aria-label"] != null) this.control.setAttribute("aria-label", attrs["aria-label"]);
|
|
22488
|
+
else this.control.removeAttribute("aria-label");
|
|
22489
|
+
return rest;
|
|
22490
|
+
}
|
|
22491
|
+
attachCommand() {
|
|
22492
|
+
}
|
|
22493
|
+
releaseCommand() {
|
|
22494
|
+
}
|
|
22495
|
+
commandTarget() {
|
|
22496
|
+
return this;
|
|
22497
|
+
}
|
|
22498
|
+
prepareCommand() {
|
|
22499
|
+
return !this.disabled;
|
|
22500
|
+
}
|
|
22501
|
+
};
|
|
22502
|
+
}
|
|
22503
|
+
Command.parameters = {
|
|
22504
|
+
disabled: { dtype: "B", default: false, binding: "read" },
|
|
22505
|
+
icon: { dtype: "T", default: "", binding: "read" }
|
|
22506
|
+
};
|
|
22507
|
+
var Button = defineComponent({
|
|
22508
|
+
name: "button",
|
|
22509
|
+
tag: "gramlot-button",
|
|
22510
|
+
base: Command,
|
|
22511
|
+
command: true,
|
|
22512
|
+
subTags: "*",
|
|
22513
|
+
implementation: (Base) => class extends Base {
|
|
21998
22514
|
}
|
|
21999
|
-
|
|
22515
|
+
});
|
|
22516
|
+
var ToggleButton = defineComponent({
|
|
22517
|
+
name: "toggleButton",
|
|
22518
|
+
tag: "gramlot-toggle-button",
|
|
22519
|
+
base: Command,
|
|
22520
|
+
command: true,
|
|
22521
|
+
subTags: "*",
|
|
22522
|
+
parameters: {
|
|
22523
|
+
value: { dtype: "B", default: false, binding: "twoWay" },
|
|
22524
|
+
readonly: { dtype: "B", default: false, binding: "read" }
|
|
22525
|
+
},
|
|
22526
|
+
implementation: (Base) => class extends Base {
|
|
22527
|
+
#value = false;
|
|
22528
|
+
constructor() {
|
|
22529
|
+
super();
|
|
22530
|
+
const led = this.ownerDocument.createElement("span");
|
|
22531
|
+
led.className = "led";
|
|
22532
|
+
led.setAttribute("aria-hidden", "true");
|
|
22533
|
+
this.control.prepend(led);
|
|
22534
|
+
this.writeControlValue(false);
|
|
22535
|
+
}
|
|
22536
|
+
get commitOnChange() {
|
|
22537
|
+
return true;
|
|
22538
|
+
}
|
|
22539
|
+
readControlValue() {
|
|
22540
|
+
return this.#value;
|
|
22541
|
+
}
|
|
22542
|
+
writeControlValue(value) {
|
|
22543
|
+
this.#value = value;
|
|
22544
|
+
this.control.setAttribute("aria-pressed", String(value));
|
|
22545
|
+
}
|
|
22546
|
+
prepareCommand(event) {
|
|
22547
|
+
if (!super.prepareCommand(event) || this.control.readOnly) return false;
|
|
22548
|
+
this.writeControlValue(!this.#value);
|
|
22549
|
+
this.control.dispatchEvent(new this.ownerDocument.defaultView.Event("change"));
|
|
22550
|
+
return true;
|
|
22551
|
+
}
|
|
22552
|
+
}
|
|
22553
|
+
});
|
|
22554
|
+
function MenuContainer(HTMLElement) {
|
|
22555
|
+
return class extends HTMLElement {
|
|
22556
|
+
constructor() {
|
|
22557
|
+
super();
|
|
22558
|
+
this.attachShadow({ mode: "open" }).append(this.ownerDocument.createElement("slot"));
|
|
22559
|
+
}
|
|
22560
|
+
connectedCallback() {
|
|
22561
|
+
this.slot = "menu";
|
|
22562
|
+
this.setAttribute("role", "menu");
|
|
22563
|
+
}
|
|
22564
|
+
projectAttributes(attrs) {
|
|
22565
|
+
return projectParameters(this, attrs);
|
|
22566
|
+
}
|
|
22567
|
+
};
|
|
22000
22568
|
}
|
|
22569
|
+
var Menu = defineComponent({
|
|
22570
|
+
name: "menu",
|
|
22571
|
+
tag: "gramlot-menu",
|
|
22572
|
+
base: MenuContainer,
|
|
22573
|
+
subTags: "menuline",
|
|
22574
|
+
implementation: (Base) => class extends Base {
|
|
22575
|
+
}
|
|
22576
|
+
});
|
|
22577
|
+
var MenuLine = defineComponent({
|
|
22578
|
+
name: "menuline",
|
|
22579
|
+
tag: "gramlot-menu-line",
|
|
22580
|
+
base: Command,
|
|
22581
|
+
command: true,
|
|
22582
|
+
subTags: "*",
|
|
22583
|
+
parameters: { code: { dtype: "T", nullable: true } },
|
|
22584
|
+
implementation: (Base) => class extends Base {
|
|
22585
|
+
attachCommand() {
|
|
22586
|
+
const separator = this.textContent.trim() === "-";
|
|
22587
|
+
if (!separator && !this.parameters.code) throw new TypeError("menuline requires a stable code");
|
|
22588
|
+
this.setAttribute("role", separator ? "separator" : "menuitem");
|
|
22589
|
+
this.control.tabIndex = -1;
|
|
22590
|
+
this.disabled ||= separator;
|
|
22591
|
+
}
|
|
22592
|
+
get disabled() {
|
|
22593
|
+
return super.disabled || Boolean(this.closest("gramlot-drop-down-button")?.parameters.disabled);
|
|
22594
|
+
}
|
|
22595
|
+
set disabled(value) {
|
|
22596
|
+
super.disabled = value;
|
|
22597
|
+
}
|
|
22598
|
+
prepareCommand(event) {
|
|
22599
|
+
if (!super.prepareCommand(event)) return false;
|
|
22600
|
+
this.closest("gramlot-drop-down-button").selectCommand(this, event.shiftKey);
|
|
22601
|
+
return true;
|
|
22602
|
+
}
|
|
22603
|
+
}
|
|
22604
|
+
});
|
|
22605
|
+
var DropDownButton = defineComponent({
|
|
22606
|
+
name: "dropDownButton",
|
|
22607
|
+
tag: "gramlot-drop-down-button",
|
|
22608
|
+
base: Command,
|
|
22609
|
+
command: true,
|
|
22610
|
+
subTags: "*",
|
|
22611
|
+
parameters: { persist: { dtype: "B", default: false } },
|
|
22612
|
+
implementation: (Base) => class extends Base {
|
|
22613
|
+
#selected = null;
|
|
22614
|
+
#observer = null;
|
|
22615
|
+
#viewport = null;
|
|
22616
|
+
#storageKey = null;
|
|
22617
|
+
#popup;
|
|
22618
|
+
#arrow;
|
|
22619
|
+
#chosenCaption;
|
|
22620
|
+
constructor() {
|
|
22621
|
+
super();
|
|
22622
|
+
const doc = this.ownerDocument;
|
|
22623
|
+
this.control.classList.add("split");
|
|
22624
|
+
this.#chosenCaption = doc.createElement("span");
|
|
22625
|
+
this.#chosenCaption.hidden = true;
|
|
22626
|
+
this.control.append(this.#chosenCaption);
|
|
22627
|
+
this.#arrow = doc.createElement("button");
|
|
22628
|
+
this.#arrow.type = "button";
|
|
22629
|
+
this.#arrow.className = "arrow";
|
|
22630
|
+
this.#arrow.textContent = "\u25BE";
|
|
22631
|
+
this.#arrow.setAttribute("aria-label", "Open menu");
|
|
22632
|
+
this.#arrow.setAttribute("aria-haspopup", "menu");
|
|
22633
|
+
this.#arrow.setAttribute("aria-expanded", "false");
|
|
22634
|
+
this.controlBox.append(this.#arrow);
|
|
22635
|
+
this.#popup = doc.createElement("div");
|
|
22636
|
+
this.#popup.className = "popup";
|
|
22637
|
+
this.#popup.id = "menu";
|
|
22638
|
+
this.#popup.setAttribute("popover", "auto");
|
|
22639
|
+
this.#arrow.setAttribute("aria-controls", "menu");
|
|
22640
|
+
const slot = doc.createElement("slot");
|
|
22641
|
+
slot.name = "menu";
|
|
22642
|
+
this.#popup.append(slot);
|
|
22643
|
+
this.shadowRoot.append(this.#popup);
|
|
22644
|
+
this.#arrow.addEventListener("click", (event) => {
|
|
22645
|
+
event.stopPropagation();
|
|
22646
|
+
if (this.#popup.matches(":popover-open")) this.closeMenu();
|
|
22647
|
+
else this.openMenu();
|
|
22648
|
+
});
|
|
22649
|
+
this.#arrow.addEventListener("keydown", (event) => {
|
|
22650
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
22651
|
+
event.preventDefault();
|
|
22652
|
+
this.openMenu(event.key === "ArrowUp");
|
|
22653
|
+
}
|
|
22654
|
+
});
|
|
22655
|
+
this.addEventListener("keydown", (event) => {
|
|
22656
|
+
if (!this.#popup.matches(":popover-open")) return;
|
|
22657
|
+
const items = this.menuItems.filter((item) => !item.disabled);
|
|
22658
|
+
const index = items.indexOf(event.composedPath().find((item) => items.includes(item)));
|
|
22659
|
+
let next;
|
|
22660
|
+
if (event.key === "ArrowDown") next = (index + 1) % items.length;
|
|
22661
|
+
if (event.key === "ArrowUp") next = (index - 1 + items.length) % items.length;
|
|
22662
|
+
if (event.key === "Home") next = 0;
|
|
22663
|
+
if (event.key === "End") next = items.length - 1;
|
|
22664
|
+
if (next !== void 0) {
|
|
22665
|
+
event.preventDefault();
|
|
22666
|
+
items[next]?.focus();
|
|
22667
|
+
}
|
|
22668
|
+
if (event.key === "Escape" || event.key === "Tab") {
|
|
22669
|
+
if (event.key === "Escape") event.preventDefault();
|
|
22670
|
+
this.closeMenu();
|
|
22671
|
+
}
|
|
22672
|
+
});
|
|
22673
|
+
this.#popup.addEventListener("toggle", () => {
|
|
22674
|
+
const open = this.#popup.matches(":popover-open");
|
|
22675
|
+
this.#arrow.setAttribute("aria-expanded", String(open));
|
|
22676
|
+
if (!open) {
|
|
22677
|
+
this.#viewport?.abort();
|
|
22678
|
+
this.#viewport = null;
|
|
22679
|
+
}
|
|
22680
|
+
});
|
|
22681
|
+
}
|
|
22682
|
+
get menuItems() {
|
|
22683
|
+
return [...this.querySelectorAll(":scope > gramlot-menu > gramlot-menu-line")];
|
|
22684
|
+
}
|
|
22685
|
+
projectAttributes(attrs, adapt) {
|
|
22686
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
22687
|
+
this.#arrow.disabled = this.disabled;
|
|
22688
|
+
if (this.disabled && this.#popup.matches(":popover-open")) this.closeMenu();
|
|
22689
|
+
this.#refreshCaption();
|
|
22690
|
+
return rest;
|
|
22691
|
+
}
|
|
22692
|
+
attachCommand() {
|
|
22693
|
+
if (this.parameters.persist) {
|
|
22694
|
+
if (!this.id) throw new TypeError("dropDownButton persist requires an explicit id");
|
|
22695
|
+
this.#storageKey = `gramlot:command:${this.ownerDocument.location.pathname}${this.ownerDocument.location.search}:${this.id}`;
|
|
22696
|
+
try {
|
|
22697
|
+
this.#selected = this.ownerDocument.defaultView.localStorage.getItem(this.#storageKey);
|
|
22698
|
+
} catch {
|
|
22699
|
+
}
|
|
22700
|
+
}
|
|
22701
|
+
this.#refreshCaption();
|
|
22702
|
+
this.#observer = new this.ownerDocument.defaultView.MutationObserver(() => this.#refreshCaption());
|
|
22703
|
+
this.#observer.observe(this, { childList: true, subtree: true, characterData: true });
|
|
22704
|
+
}
|
|
22705
|
+
releaseCommand() {
|
|
22706
|
+
this.#observer?.disconnect();
|
|
22707
|
+
this.#observer = null;
|
|
22708
|
+
this.#viewport?.abort();
|
|
22709
|
+
this.#viewport = null;
|
|
22710
|
+
if (this.#popup.matches(":popover-open")) this.#popup.hidePopover();
|
|
22711
|
+
}
|
|
22712
|
+
commandTarget(event) {
|
|
22713
|
+
if (event?.composedPath().includes(this.#popup)) return null;
|
|
22714
|
+
return this.menuItems.find((item) => item.parameters.code === this.#selected) ?? this;
|
|
22715
|
+
}
|
|
22716
|
+
selectCommand(item, remember) {
|
|
22717
|
+
if (remember) {
|
|
22718
|
+
this.#selected = item.parameters.code;
|
|
22719
|
+
if (this.#storageKey) {
|
|
22720
|
+
try {
|
|
22721
|
+
this.ownerDocument.defaultView.localStorage.setItem(this.#storageKey, this.#selected);
|
|
22722
|
+
} catch {
|
|
22723
|
+
}
|
|
22724
|
+
}
|
|
22725
|
+
this.#refreshCaption();
|
|
22726
|
+
}
|
|
22727
|
+
this.closeMenu();
|
|
22728
|
+
}
|
|
22729
|
+
#refreshCaption() {
|
|
22730
|
+
const codes = this.menuItems.filter((item) => item.parameters.code).map((item) => item.parameters.code);
|
|
22731
|
+
if (new Set(codes).size !== codes.length) throw new TypeError("Dropdown menu codes must be unique");
|
|
22732
|
+
const target = this.commandTarget();
|
|
22733
|
+
const selected = target !== this;
|
|
22734
|
+
this.caption.hidden = selected;
|
|
22735
|
+
this.#chosenCaption.hidden = !selected;
|
|
22736
|
+
this.#chosenCaption.textContent = selected ? target.textContent : "";
|
|
22737
|
+
this.icon.textContent = selected ? target.parameters.icon : this.parameters.icon;
|
|
22738
|
+
}
|
|
22739
|
+
openMenu(last = false) {
|
|
22740
|
+
if (this.disabled) return;
|
|
22741
|
+
const items = this.menuItems.filter((item) => !item.disabled);
|
|
22742
|
+
if (!items.length) return;
|
|
22743
|
+
this.#popup.showPopover();
|
|
22744
|
+
this.#arrow.setAttribute("aria-expanded", "true");
|
|
22745
|
+
const place = () => positionPopup(this.#popup, this.controlBox);
|
|
22746
|
+
place();
|
|
22747
|
+
this.#viewport?.abort();
|
|
22748
|
+
this.#viewport = new this.ownerDocument.defaultView.AbortController();
|
|
22749
|
+
const options = { signal: this.#viewport.signal, capture: true };
|
|
22750
|
+
this.ownerDocument.defaultView.addEventListener("resize", place, options);
|
|
22751
|
+
this.ownerDocument.addEventListener("scroll", place, options);
|
|
22752
|
+
items[last ? items.length - 1 : 0].focus();
|
|
22753
|
+
}
|
|
22754
|
+
closeMenu() {
|
|
22755
|
+
if (!this.#popup.matches(":popover-open")) return;
|
|
22756
|
+
this.#popup.hidePopover();
|
|
22757
|
+
this.#arrow.setAttribute("aria-expanded", "false");
|
|
22758
|
+
this.#viewport?.abort();
|
|
22759
|
+
this.#viewport = null;
|
|
22760
|
+
this.#arrow.focus();
|
|
22761
|
+
}
|
|
22762
|
+
}
|
|
22763
|
+
});
|
|
22764
|
+
var buttons_default = defineCollection({ name: "buttons", components: [Button, ToggleButton, DropDownButton, Menu, MenuLine] });
|
|
22765
|
+
|
|
22766
|
+
// src/binding/pointer.js
|
|
22001
22767
|
function attributeReader(node, items, context = node) {
|
|
22002
|
-
const values = /* @__PURE__ */ new Map(), active = /* @__PURE__ */ new Set()
|
|
22768
|
+
const values = /* @__PURE__ */ new Map(), active = /* @__PURE__ */ new Set();
|
|
22003
22769
|
const compiler = node.rootBuilder.binding?.inlineCompiler;
|
|
22004
22770
|
const current = /* @__PURE__ */ new Map();
|
|
22005
22771
|
for (const [name, raw] of items) {
|
|
@@ -22009,8 +22775,8 @@ function attributeReader(node, items, context = node) {
|
|
|
22009
22775
|
}
|
|
22010
22776
|
const resolve = (name) => {
|
|
22011
22777
|
if (values.has(name)) return values.get(name);
|
|
22012
|
-
if (!items.has(name)) throw
|
|
22013
|
-
if (active.has(name)) throw
|
|
22778
|
+
if (!items.has(name)) throw new Error(`Source attribute '${name}' does not exist`);
|
|
22779
|
+
if (active.has(name)) throw new Error(`cyclic attribute dependency: ${[...active, name].join(" -> ")}`);
|
|
22014
22780
|
active.add(name);
|
|
22015
22781
|
const raw = items.get(name), transform = pointerTransform(raw);
|
|
22016
22782
|
const leading = transform ? current.get(name) : null;
|
|
@@ -22022,9 +22788,9 @@ function attributeReader(node, items, context = node) {
|
|
|
22022
22788
|
try {
|
|
22023
22789
|
if (transform) {
|
|
22024
22790
|
if (transform.expression) {
|
|
22025
|
-
const
|
|
22026
|
-
const inputs = slots.map(read);
|
|
22027
|
-
result =
|
|
22791
|
+
const expression = pointerExpression(transform.body);
|
|
22792
|
+
const inputs = expression.slots.map(read);
|
|
22793
|
+
result = node.rootBuilder.evaluatePointerExpression(node, name, raw, expression, inputs);
|
|
22028
22794
|
} else {
|
|
22029
22795
|
result = pointerTemplate(transform.body, read);
|
|
22030
22796
|
if (leading == null) result = null;
|
|
@@ -22043,13 +22809,6 @@ function attributeReader(node, items, context = node) {
|
|
|
22043
22809
|
)({ ...args, _F: (value, options) => node.rootBuilder.binding.gramlot.format(value, options) }) : null;
|
|
22044
22810
|
} else {
|
|
22045
22811
|
result = current.get(name);
|
|
22046
|
-
if (typeof result === "string" && !node._getMeta("data_element")) {
|
|
22047
|
-
result = result.replace(/(\\)?\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (token, escaped, key) => {
|
|
22048
|
-
if (escaped) return token.slice(1);
|
|
22049
|
-
consumed.add(key);
|
|
22050
|
-
return String(resolve(key) ?? "");
|
|
22051
|
-
});
|
|
22052
|
-
}
|
|
22053
22812
|
}
|
|
22054
22813
|
values.set(name, result);
|
|
22055
22814
|
return result;
|
|
@@ -22057,26 +22816,7 @@ function attributeReader(node, items, context = node) {
|
|
|
22057
22816
|
active.delete(name);
|
|
22058
22817
|
}
|
|
22059
22818
|
};
|
|
22060
|
-
return { resolve
|
|
22061
|
-
}
|
|
22062
|
-
function preparePointerItems(node, items) {
|
|
22063
|
-
const transformed = [...items].filter(([name, raw]) => typeof name === "string" && pointerTransform(raw));
|
|
22064
|
-
if (!transformed.length) return items;
|
|
22065
|
-
const reader = attributeReader(node, items);
|
|
22066
|
-
const results = new Map(transformed.map(([name]) => [name, reader.resolve(name)]));
|
|
22067
|
-
for (const [name, raw] of items) {
|
|
22068
|
-
if (typeof name !== "string" || pointerTransform(raw)) continue;
|
|
22069
|
-
if (raw instanceof BagResolver || node.pointerType(raw)) {
|
|
22070
|
-
const result = reader.current.get(name);
|
|
22071
|
-
items.set(name, new BagCbResolver(() => result));
|
|
22072
|
-
}
|
|
22073
|
-
}
|
|
22074
|
-
for (const [name] of transformed) {
|
|
22075
|
-
const result = results.get(name);
|
|
22076
|
-
items.set(name, new BagCbResolver(() => result));
|
|
22077
|
-
}
|
|
22078
|
-
if (!node._getMeta("data_element")) for (const name of reader.consumed) items.delete(name);
|
|
22079
|
-
return items;
|
|
22819
|
+
return { resolve };
|
|
22080
22820
|
}
|
|
22081
22821
|
function resolvePointerAttribute(node, name, context = node) {
|
|
22082
22822
|
const items = new Map([...Object.entries(node.getAttr()), ...sourceAttributeItems(node.getAttr())]);
|
|
@@ -22088,8 +22828,7 @@ var CODE_ATTRIBUTES = {
|
|
|
22088
22828
|
dataFormula: ["formula", "_if", "_else", "_ask_if", "_ask_onCancel"],
|
|
22089
22829
|
dataController: ["script", "_if", "_else", "_ask_if", "_ask_onCancel"],
|
|
22090
22830
|
dataRpc: ["_ask_if", "_ask_onCancel", "_if", "_else", "_onCalling", "_onResult", "_onError"],
|
|
22091
|
-
dataRemote: ["_if", "_else"]
|
|
22092
|
-
button: ["action", "_ask_if"]
|
|
22831
|
+
dataRemote: ["_if", "_else"]
|
|
22093
22832
|
};
|
|
22094
22833
|
var REMOTE_CONTROLS = ["_cachedRemote", "_if", "_else", "_onRemote"];
|
|
22095
22834
|
var REMOTE_CODE_ATTRIBUTES = ["_if", "_else", "_onRemote"];
|
|
@@ -22112,11 +22851,12 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
22112
22851
|
codeAttributes() {
|
|
22113
22852
|
const own2 = [
|
|
22114
22853
|
...CODE_ATTRIBUTES[this.nodeTag] ?? [],
|
|
22854
|
+
...this._getMeta("gramlot_component")?.command ? ["action", "_ask_if"] : [],
|
|
22115
22855
|
...typeof this.getAttr("remote") === "string" ? REMOTE_CODE_ATTRIBUTES : []
|
|
22116
22856
|
];
|
|
22117
22857
|
const items = [];
|
|
22118
22858
|
for (const [name, value] of Object.entries(this.getAttr() ?? {})) {
|
|
22119
|
-
if (typeof value === "string" && (own2.includes(name) || name.startsWith("connect_on") || name.startsWith("subscribe_") || name.startsWith("selfsubscribe_"))) items.push([name, value]);
|
|
22859
|
+
if (typeof value === "string" && (own2.includes(name) || name === "validate_call" || name === "validate__onResult" || name === "validate_onAccept" || name === "validate_onReject" || /^validate_\w+_if$/.test(name) || name.startsWith("connect_on") || name.startsWith("subscribe_") || name.startsWith("selfsubscribe_"))) items.push([name, value]);
|
|
22120
22860
|
}
|
|
22121
22861
|
for (const attribute of ["ask", "_ask"]) {
|
|
22122
22862
|
const spec = this.getAttr(attribute);
|
|
@@ -22180,11 +22920,6 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
22180
22920
|
publish(topic, payload = {}) {
|
|
22181
22921
|
return this.builder.binding.gramlot._subscriptions.publishNode(this, topic, payload);
|
|
22182
22922
|
}
|
|
22183
|
-
/** Builder's pointerType, except that a string starting with `==` is not a pointer. */
|
|
22184
|
-
pointerType(v) {
|
|
22185
|
-
if (typeof v === "string" && v.startsWith("==")) return null;
|
|
22186
|
-
return super.pointerType(v);
|
|
22187
|
-
}
|
|
22188
22923
|
/** Builder's `^` pointers, except the attributes ending in `_path`, which hold a bare path. */
|
|
22189
22924
|
pointers() {
|
|
22190
22925
|
const datapath = this.getAttr("datapath");
|
|
@@ -22207,12 +22942,15 @@ var GramlotBuilderBagNode = class extends SourceBagNode {
|
|
|
22207
22942
|
if (!this.pointerType(value)) continue;
|
|
22208
22943
|
if (pointerTransform(value)) {
|
|
22209
22944
|
if (typeof name !== "string") throw new Error(`${this.nodeTag} '${this.label}': pointer suffixes belong to attributes; use format/mask for node text`);
|
|
22945
|
+
if (this.absDatapath(value) === null) {
|
|
22946
|
+
items.set(name, new BagCbResolver(() => resolvePointerAttribute(this, name)));
|
|
22947
|
+
}
|
|
22210
22948
|
continue;
|
|
22211
22949
|
}
|
|
22212
22950
|
if (this.#isPathAttribute(name, value)) items.set(name, value.slice(1));
|
|
22213
22951
|
else if (this.absDatapath(value) === null) items.set(name, null);
|
|
22214
22952
|
}
|
|
22215
|
-
return
|
|
22953
|
+
return items;
|
|
22216
22954
|
}
|
|
22217
22955
|
/**
|
|
22218
22956
|
* The value of the attribute `name`; for an attribute ending in `_path` written as a pointer, the
|
|
@@ -22452,8 +23190,9 @@ function inferredType(value) {
|
|
|
22452
23190
|
if (midnight && !epochDay) return "D";
|
|
22453
23191
|
return "DHZ";
|
|
22454
23192
|
}
|
|
23193
|
+
if (isDecimal2(value)) return "N";
|
|
22455
23194
|
if (typeof value === "number") return Number.isInteger(value) ? "L" : "R";
|
|
22456
|
-
throw new TypeError("Formatting requires finite JavaScript numbers or valid Date objects");
|
|
23195
|
+
throw new TypeError("Formatting requires finite JavaScript numbers, TYTX Decimal values or valid Date objects");
|
|
22457
23196
|
}
|
|
22458
23197
|
function temporalText(value, dtype, { pattern = "short", locale, timeZone }) {
|
|
22459
23198
|
if (!["short", "medium", "long", "full"].includes(pattern)) {
|
|
@@ -22509,8 +23248,8 @@ function formatValue(value, options = {}, context = {}) {
|
|
|
22509
23248
|
if (!temporal2 && !["L", "R", "N"].includes(dtype)) throw new RangeError(`Unsupported format dtype: ${dtype}`);
|
|
22510
23249
|
if (temporal2) {
|
|
22511
23250
|
if (!(value instanceof Date) || !Number.isFinite(value.getTime())) throw new TypeError(`${dtype} requires a valid Date object`);
|
|
22512
|
-
} else if (typeof value
|
|
22513
|
-
throw new TypeError(`${dtype} formatting requires finite JavaScript numbers`);
|
|
23251
|
+
} else if (!(typeof value === "number" && Number.isFinite(value)) && !(isDecimal2(value) && !["NaN", "Infinity", "-Infinity"].includes(value.toString()))) {
|
|
23252
|
+
throw new TypeError(`${dtype} formatting requires finite JavaScript numbers or TYTX Decimal values`);
|
|
22514
23253
|
}
|
|
22515
23254
|
if (dtype === "L" && !Number.isInteger(value)) throw new TypeError("L formatting requires an integer");
|
|
22516
23255
|
const { pattern, locale, mask } = options;
|
|
@@ -22524,8 +23263,12 @@ function formatValue(value, options = {}, context = {}) {
|
|
|
22524
23263
|
return applyMask(text2, mask);
|
|
22525
23264
|
}
|
|
22526
23265
|
const { positive, zero, negative } = numericPattern(pattern);
|
|
23266
|
+
const decimal = isDecimal2(value);
|
|
23267
|
+
const zeroValue = decimal ? value.eq(0) : value === 0;
|
|
23268
|
+
const negativeValue = decimal ? value.lt(0) : value < 0;
|
|
23269
|
+
if (decimal && new Intl.NumberFormat("en", { useGrouping: false }).format("9007199254740993") !== "9007199254740993") throw new Error("This browser cannot format Decimal without precision loss");
|
|
22527
23270
|
let text;
|
|
22528
|
-
if (
|
|
23271
|
+
if (zeroValue && zero !== null) {
|
|
22529
23272
|
if (zero === "") return "";
|
|
22530
23273
|
if (zero === "-") text = "-";
|
|
22531
23274
|
else {
|
|
@@ -22533,8 +23276,8 @@ function formatValue(value, options = {}, context = {}) {
|
|
|
22533
23276
|
text = section.prefix + new Intl.NumberFormat(locale, section.intl).format(0) + section.suffix;
|
|
22534
23277
|
}
|
|
22535
23278
|
} else {
|
|
22536
|
-
const affix =
|
|
22537
|
-
const number = value
|
|
23279
|
+
const affix = negativeValue && negative ? negative : positive;
|
|
23280
|
+
const number = decimal ? (negativeValue && negative ? value.abs() : value).toString() : negativeValue && negative ? -value : value === 0 ? 0 : value;
|
|
22538
23281
|
text = affix.prefix + new Intl.NumberFormat(locale, positive.intl).format(number) + affix.suffix;
|
|
22539
23282
|
}
|
|
22540
23283
|
return applyMask(text, mask);
|
|
@@ -22576,7 +23319,6 @@ var NATIVE_ATTRIBUTES = {
|
|
|
22576
23319
|
img: ["width", "height"],
|
|
22577
23320
|
canvas: ["width", "height"]
|
|
22578
23321
|
};
|
|
22579
|
-
var TEMPLATE_REFERENCE = /(?<!\\)\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
22580
23322
|
var DISPLAY_ATTRIBUTES = ["format", "mask", "locale", "timeZone", "places", "dtype"];
|
|
22581
23323
|
var URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src", "formaction", "xlink:href", "xlink_href"]);
|
|
22582
23324
|
function withoutBindingAttributes(attrs) {
|
|
@@ -22615,14 +23357,7 @@ function withDataSrcdocSandbox(node, attrs, prefixes = []) {
|
|
|
22615
23357
|
const declared = Object.fromEntries(sourceAttributeItems(node.getAttr()));
|
|
22616
23358
|
const srcdoc = [...Object.keys(declared), ...Object.keys(attrs)].find((name) => bare(name)[1] === "srcdoc");
|
|
22617
23359
|
if (srcdoc === void 0 || Object.keys(declared).some((name) => bare(name)[1] === "sandbox")) return attrs;
|
|
22618
|
-
|
|
22619
|
-
const raw = declared[name];
|
|
22620
|
-
seen.add(name);
|
|
22621
|
-
return node.pointerType(raw) !== null || isExpression2(raw) || templateParameters(raw).some((param) => Object.hasOwn(declared, param) && !seen.has(param) && fromData(param, seen));
|
|
22622
|
-
};
|
|
22623
|
-
if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc) && fromData(srcdoc, /* @__PURE__ */ new Set()))) {
|
|
22624
|
-
return attrs;
|
|
22625
|
-
}
|
|
23360
|
+
if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc) && (node.pointerType(declared[srcdoc]) !== null || isExpression2(declared[srcdoc])))) return attrs;
|
|
22626
23361
|
const rest = Object.fromEntries(Object.entries(attrs).filter(([name]) => bare(name)[1] !== "sandbox"));
|
|
22627
23362
|
return { [`${bare(srcdoc)[0]}sandbox`]: "", ...rest };
|
|
22628
23363
|
}
|
|
@@ -22679,28 +23414,9 @@ function displayItem(item, attrs, format = null) {
|
|
|
22679
23414
|
}
|
|
22680
23415
|
return [display(item), rest];
|
|
22681
23416
|
}
|
|
22682
|
-
function templateParameters(value) {
|
|
22683
|
-
return typeof value === "string" ? [...value.matchAll(TEMPLATE_REFERENCE)].map(([, name]) => name) : [];
|
|
22684
|
-
}
|
|
22685
23417
|
function isExpression2(value) {
|
|
22686
23418
|
return typeof value === "string" && value.startsWith("==");
|
|
22687
23419
|
}
|
|
22688
|
-
function requireNoExpressionTemplate(node) {
|
|
22689
|
-
if (isExpression2(node.value) && templateParameters(node.value).length) {
|
|
22690
|
-
throw new Error(`${node.nodeTag} '${node.label}': the == node value contains a \${\u2026} template, not accepted in a == expression`);
|
|
22691
|
-
}
|
|
22692
|
-
const attrs = Object.fromEntries(sourceAttributeItems(node.getAttr()));
|
|
22693
|
-
for (const [name, raw] of Object.entries(attrs)) {
|
|
22694
|
-
if (isExpression2(raw) && templateParameters(raw).length) {
|
|
22695
|
-
throw new Error(`${node.nodeTag} '${node.label}': '${name}' contains a \${\u2026} template, not accepted in a == expression`);
|
|
22696
|
-
}
|
|
22697
|
-
for (const param of templateParameters(raw)) {
|
|
22698
|
-
if (isExpression2(attrs[param])) {
|
|
22699
|
-
throw new Error(`${node.nodeTag} '${node.label}': the template of '${name}' uses '${param}', a == expression`);
|
|
22700
|
-
}
|
|
22701
|
-
}
|
|
22702
|
-
}
|
|
22703
|
-
}
|
|
22704
23420
|
|
|
22705
23421
|
// src/renderer/gramlot-svg-renderer.js
|
|
22706
23422
|
var SVG_VOID_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -22777,26 +23493,6 @@ var GramlotSvgRenderer = class extends SvgRenderer {
|
|
|
22777
23493
|
}
|
|
22778
23494
|
};
|
|
22779
23495
|
|
|
22780
|
-
// src/webcomponent.js
|
|
22781
|
-
var NAME2 = /^[a-z][.0-9_a-z\-\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
|
|
22782
|
-
var RESERVED = /* @__PURE__ */ new Set([
|
|
22783
|
-
"annotation-xml",
|
|
22784
|
-
"color-profile",
|
|
22785
|
-
"font-face",
|
|
22786
|
-
"font-face-src",
|
|
22787
|
-
"font-face-uri",
|
|
22788
|
-
"font-face-format",
|
|
22789
|
-
"font-face-name",
|
|
22790
|
-
"missing-glyph"
|
|
22791
|
-
]);
|
|
22792
|
-
function webcomponentCode(attrs) {
|
|
22793
|
-
const code = attrs.code;
|
|
22794
|
-
if (typeof code !== "string" || NAME2.exec(code)?.[0] !== code || !code.includes("-") || RESERVED.has(code)) {
|
|
22795
|
-
throw new TypeError("webcomponent: code must be a literal custom-element name");
|
|
22796
|
-
}
|
|
22797
|
-
return code;
|
|
22798
|
-
}
|
|
22799
|
-
|
|
22800
23496
|
// src/renderer/gramlot-html-renderer.js
|
|
22801
23497
|
var GramlotHtmlRenderer = class extends HtmlRenderer {
|
|
22802
23498
|
// noConvertStyle attributes taken out in _handleMeta, put back after adaptAttrs.
|
|
@@ -22810,6 +23506,7 @@ var GramlotHtmlRenderer = class extends HtmlRenderer {
|
|
|
22810
23506
|
/** HTML nodes (GramlotBuilder, HtmlBuilder) → this renderer; SVG nodes → one GramlotSvgRenderer owned by it. */
|
|
22811
23507
|
getRender(builder) {
|
|
22812
23508
|
if (!this.renders.has(builder)) {
|
|
23509
|
+
builder.evaluatePointerExpression = this.builder.evaluatePointerExpression.bind(this.builder);
|
|
22813
23510
|
if (builder instanceof HtmlBuilder) this.addRender(builder, this);
|
|
22814
23511
|
else if (builder instanceof SvgBuilder) this.addRender(builder, new GramlotSvgRenderer(builder, this));
|
|
22815
23512
|
}
|
|
@@ -22849,10 +23546,9 @@ var GramlotHtmlRenderer = class extends HtmlRenderer {
|
|
|
22849
23546
|
/**
|
|
22850
23547
|
* Step 3 of Q11.2 on the attributes of `node` resolved by runtimeValues, for HTML and SVG nodes: every
|
|
22851
23548
|
* `==` attribute, and a `==` node value, evaluated by the page's InlineCompiler (§4.10); without a
|
|
22852
|
-
* compiler they are null and nothing is written.
|
|
23549
|
+
* compiler they are null and nothing is written.
|
|
22853
23550
|
*/
|
|
22854
23551
|
evaluateExpressions(node, runtimeAttrs) {
|
|
22855
|
-
requireNoExpressionTemplate(node);
|
|
22856
23552
|
const compiler = this.inlineCompiler;
|
|
22857
23553
|
const evaluate = (attr, expr) => compiler ? compiler.compileExpression(node, attr, expr)(runtimeAttrs) : null;
|
|
22858
23554
|
const attrs = { ...runtimeAttrs };
|
|
@@ -23391,7 +24087,7 @@ function dataElementError(tag2, attrs) {
|
|
|
23391
24087
|
if (tag2 === "html_button" && Object.keys(attrs).some((name) => ["action", "ask", "_delay", "fire"].includes(name) || name.startsWith("fire_"))) {
|
|
23392
24088
|
return "plain HTML button: use button for action, ask, fire or _delay";
|
|
23393
24089
|
}
|
|
23394
|
-
if (Object.hasOwn(attrs, "ask") &&
|
|
24090
|
+
if (Object.hasOwn(attrs, "ask") && !["button", "toggleButton", "dropDownButton", "menuline"].includes(tag2)) return "'ask' is supported on buttons";
|
|
23395
24091
|
if (Object.hasOwn(attrs, "_ask") && !["dataController", "dataFormula", "dataRpc"].includes(tag2)) return "'_ask' requires a controller, formula or RPC";
|
|
23396
24092
|
if (["dataSetter", "dataRemote"].includes(tag2) && Object.keys(attrs).some((name) => name.startsWith("subscribe_") || name.startsWith("selfsubscribe_"))) {
|
|
23397
24093
|
return "topic subscriptions are supported on controllers, formulas, RPCs and rendered elements";
|
|
@@ -23421,6 +24117,9 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
23421
24117
|
static {
|
|
23422
24118
|
this.defineGrammar(webcomponent_default);
|
|
23423
24119
|
}
|
|
24120
|
+
static {
|
|
24121
|
+
this.defineGrammar(buttons_default.toDocument());
|
|
24122
|
+
}
|
|
23424
24123
|
/** Tag prefixes of the parent dialects, from the `_name` of the classes above GramlotBuilder. */
|
|
23425
24124
|
static get dialectPrefixes() {
|
|
23426
24125
|
const prefixes = [];
|
|
@@ -23448,6 +24147,10 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
23448
24147
|
set binding(runtime) {
|
|
23449
24148
|
this._binding = runtime;
|
|
23450
24149
|
}
|
|
24150
|
+
/** Builder supplies typed slots; Gramlot owns activation, CSP and page-local _F. */
|
|
24151
|
+
evaluatePointerExpression(node, name, raw, expression, inputs) {
|
|
24152
|
+
return this.binding ? this.binding.inlineCompiler.compilePointerExpression(node, name, raw, expression.text)(inputs) : null;
|
|
24153
|
+
}
|
|
23451
24154
|
/** Builder's nodeById; inside a Gramlot page it reads the node_id map of the BindingRuntime (R06). */
|
|
23452
24155
|
nodeById(nodeId) {
|
|
23453
24156
|
if (!this.binding) return super.nodeById(nodeId);
|
|
@@ -23456,7 +24159,7 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
23456
24159
|
return node.builder.wrapSource(node);
|
|
23457
24160
|
}
|
|
23458
24161
|
loadCollection(document) {
|
|
23459
|
-
this.loadGrammar(document);
|
|
24162
|
+
this.loadGrammar(document instanceof ComponentCollection ? document.toDocument() : document);
|
|
23460
24163
|
return this;
|
|
23461
24164
|
}
|
|
23462
24165
|
/**
|
|
@@ -23491,6 +24194,9 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
23491
24194
|
}
|
|
23492
24195
|
/** Builder's value check, plus the excluded attributes (authoring names the tag). */
|
|
23493
24196
|
validateNodeValues(tag2, value, attrs = {}) {
|
|
24197
|
+
if (this.schema[tag2]?._meta?.gramlot_component && pointerTransform(attrs.value)) {
|
|
24198
|
+
throw new Error("'value' does not accept pointer suffixes");
|
|
24199
|
+
}
|
|
23494
24200
|
if (tag2 === "webcomponent") webcomponentCode(attrs);
|
|
23495
24201
|
const excluded = excludedAttribute(attrs);
|
|
23496
24202
|
if (excluded) throw new Error(`${tag2}: attribute '${excluded}' is excluded from Gramlot 0.2.0`);
|
|
@@ -23500,6 +24206,9 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
23500
24206
|
}
|
|
23501
24207
|
/** Builder's node check, plus the excluded attributes (a Source node names tag and label). */
|
|
23502
24208
|
validateNode(node, options = {}) {
|
|
24209
|
+
if (node._getMeta("gramlot_component") && pointerTransform((options.attrs ?? node.getAttr()).value)) {
|
|
24210
|
+
throw new Error("'value' does not accept pointer suffixes");
|
|
24211
|
+
}
|
|
23503
24212
|
if (node.nodeTag === "webcomponent") webcomponentCode(options.attrs ?? node.getAttr());
|
|
23504
24213
|
const excluded = excludedAttribute(options.attrs ?? node.getAttr());
|
|
23505
24214
|
if (excluded) throw new Error(`${node.nodeTag} '${node.label}': attribute '${excluded}' is excluded from Gramlot 0.2.0`);
|
|
@@ -23518,7 +24227,7 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
23518
24227
|
}
|
|
23519
24228
|
/** Custom elements are outside the native HTML child catalogue, as components are. */
|
|
23520
24229
|
_countsForGrammar(info) {
|
|
23521
|
-
return info !== this.schema.webcomponent && super._countsForGrammar(info);
|
|
24230
|
+
return info === this.schema.button || !info?._meta?.gramlot_component && info !== this.schema.webcomponent && super._countsForGrammar(info);
|
|
23522
24231
|
}
|
|
23523
24232
|
/** Builder's child insertion; a plain object `value` of `dataSetter` becomes `new Bag(value)` (P25). */
|
|
23524
24233
|
setChild(bag, tag2, value, attrs, parentOverride = null) {
|
|
@@ -23588,6 +24297,9 @@ var ControlAdapter = class _ControlAdapter {
|
|
|
23588
24297
|
static liveWrites = false;
|
|
23589
24298
|
// Whether a literal `value` is also written as the default a native form Reset restores.
|
|
23590
24299
|
static writesDefault = true;
|
|
24300
|
+
static preservesUnchangedValue = false;
|
|
24301
|
+
#projectedValue;
|
|
24302
|
+
#hasProjectedValue = false;
|
|
23591
24303
|
#binding;
|
|
23592
24304
|
#record;
|
|
23593
24305
|
#committing = false;
|
|
@@ -23605,6 +24317,10 @@ var ControlAdapter = class _ControlAdapter {
|
|
|
23605
24317
|
*/
|
|
23606
24318
|
static classFor(element, attrs) {
|
|
23607
24319
|
if (element.namespaceURI !== XHTML_NS) return null;
|
|
24320
|
+
if (element.constructor.gramlotComponent) {
|
|
24321
|
+
if (element.constructor.gramlotComponent.parameters.value?.binding !== "twoWay") return null;
|
|
24322
|
+
return element.control.type === "radio" ? ComponentRadioControl : ComponentControl;
|
|
24323
|
+
}
|
|
23608
24324
|
if (element.localName === "textarea") return TextControl;
|
|
23609
24325
|
if (element.localName === "select") return SelectControl;
|
|
23610
24326
|
if (element.localName !== "input") return null;
|
|
@@ -23617,6 +24333,7 @@ var ControlAdapter = class _ControlAdapter {
|
|
|
23617
24333
|
* `attrs` are the attributes of the renderer's resolved projection (`^`, `=` and `==` resolved).
|
|
23618
24334
|
*/
|
|
23619
24335
|
static shape(element, attrs) {
|
|
24336
|
+
if (element?.constructor.gramlotComponent?.parameters.value?.binding === "twoWay" && element.control.type === "radio") return JSON.stringify([attrs.group ?? null]);
|
|
23620
24337
|
if (element?.namespaceURI !== XHTML_NS || !CONTROL_TAGS.has(element.localName)) return null;
|
|
23621
24338
|
return JSON.stringify(REBUILD_ATTRIBUTES.map((name) => attrs[name] ?? null));
|
|
23622
24339
|
}
|
|
@@ -23633,6 +24350,9 @@ var ControlAdapter = class _ControlAdapter {
|
|
|
23633
24350
|
get node() {
|
|
23634
24351
|
return this.binding.node;
|
|
23635
24352
|
}
|
|
24353
|
+
get eventElement() {
|
|
24354
|
+
return this.element;
|
|
24355
|
+
}
|
|
23636
24356
|
/** The attributes of the last resolved projection of the node (`^`, `=` and `==` resolved). */
|
|
23637
24357
|
get resolved() {
|
|
23638
24358
|
return this.#record.resolved;
|
|
@@ -23660,6 +24380,9 @@ var ControlAdapter = class _ControlAdapter {
|
|
|
23660
24380
|
this.#pending = true;
|
|
23661
24381
|
return;
|
|
23662
24382
|
}
|
|
24383
|
+
if (this.constructor.preservesUnchangedValue && this.#hasProjectedValue && this.same(this.#projectedValue, value)) return;
|
|
24384
|
+
this.#projectedValue = value;
|
|
24385
|
+
this.#hasProjectedValue = true;
|
|
23663
24386
|
if (this.#committing && this.same(this.read(), value)) return;
|
|
23664
24387
|
if (this.constructor.writesDefault && !this.node.pointerType(this.node.getAttr("value"))) {
|
|
23665
24388
|
this.writeDefault(value);
|
|
@@ -23696,25 +24419,25 @@ var ControlAdapter = class _ControlAdapter {
|
|
|
23696
24419
|
* input and writes nothing (gate decision 5); a null path raises from the listener (Q7). A closed
|
|
23697
24420
|
* NodeBinding writes nothing (R12).
|
|
23698
24421
|
*/
|
|
23699
|
-
commit(event) {
|
|
24422
|
+
commit(event, value = this.read()) {
|
|
23700
24423
|
if (this.binding.closed) return;
|
|
23701
24424
|
const pointer = this.node.getAttr("value");
|
|
23702
24425
|
if (this.node.pointerType(pointer) !== "^") return;
|
|
23703
24426
|
this.#committing = true;
|
|
23704
24427
|
try {
|
|
23705
|
-
this.node.setRelativeData(pointer.slice(1),
|
|
24428
|
+
this.node.setRelativeData(pointer.slice(1), value);
|
|
23706
24429
|
} finally {
|
|
23707
24430
|
this.#committing = false;
|
|
23708
24431
|
}
|
|
23709
24432
|
}
|
|
23710
24433
|
attach() {
|
|
23711
24434
|
for (const type of ["input", "change", "compositionstart", "compositionend"]) {
|
|
23712
|
-
this.
|
|
24435
|
+
this.eventElement.addEventListener(type, this);
|
|
23713
24436
|
}
|
|
23714
24437
|
}
|
|
23715
24438
|
detach() {
|
|
23716
24439
|
for (const type of ["input", "change", "compositionstart", "compositionend"]) {
|
|
23717
|
-
this.
|
|
24440
|
+
this.eventElement.removeEventListener(type, this);
|
|
23718
24441
|
}
|
|
23719
24442
|
this.#pending = false;
|
|
23720
24443
|
}
|
|
@@ -23744,6 +24467,49 @@ var ControlAdapter = class _ControlAdapter {
|
|
|
23744
24467
|
if (event.type === this.writeEvent) this.commit(event);
|
|
23745
24468
|
}
|
|
23746
24469
|
};
|
|
24470
|
+
var ComponentControl = class extends ControlAdapter {
|
|
24471
|
+
static writesDefault = false;
|
|
24472
|
+
static preservesUnchangedValue = true;
|
|
24473
|
+
get eventElement() {
|
|
24474
|
+
return this.element.control;
|
|
24475
|
+
}
|
|
24476
|
+
attach() {
|
|
24477
|
+
this.element.setPageContext(componentContext(this));
|
|
24478
|
+
super.attach();
|
|
24479
|
+
}
|
|
24480
|
+
project(value, change) {
|
|
24481
|
+
if (this.element.shouldProjectControlValue(value)) super.project(value, change);
|
|
24482
|
+
}
|
|
24483
|
+
same(a, b) {
|
|
24484
|
+
return this.element.sameControlValue(a, b);
|
|
24485
|
+
}
|
|
24486
|
+
detach() {
|
|
24487
|
+
this.element.releaseControl();
|
|
24488
|
+
super.detach();
|
|
24489
|
+
}
|
|
24490
|
+
commit(event) {
|
|
24491
|
+
if (this.binding.closed || this.element.control.disabled || this.element.control.readOnly) return;
|
|
24492
|
+
commitComponent(this.element, this.element.acceptControlValue(), (result) => super.commit(event, result.value));
|
|
24493
|
+
}
|
|
24494
|
+
get writeEvent() {
|
|
24495
|
+
if (this.element.commitOnChange) return "change";
|
|
24496
|
+
const control = this.element.control;
|
|
24497
|
+
return this.live && (control.localName === "textarea" || ["text", "password", "range", "color"].includes(control.type)) ? "input" : "change";
|
|
24498
|
+
}
|
|
24499
|
+
read() {
|
|
24500
|
+
return this.element.readControlValue();
|
|
24501
|
+
}
|
|
24502
|
+
write(value) {
|
|
24503
|
+
this.element.writeControlValue(value);
|
|
24504
|
+
}
|
|
24505
|
+
handleEvent(event) {
|
|
24506
|
+
super.handleEvent(event);
|
|
24507
|
+
if (!event.composed && !this.binding.closed && ["input", "change"].includes(event.type)) {
|
|
24508
|
+
const Event = this.element.ownerDocument.defaultView.Event;
|
|
24509
|
+
this.element.dispatchEvent(new Event(event.type, { bubbles: true, composed: true }));
|
|
24510
|
+
}
|
|
24511
|
+
}
|
|
24512
|
+
};
|
|
23747
24513
|
var TextControl = class extends ControlAdapter {
|
|
23748
24514
|
static liveWrites = true;
|
|
23749
24515
|
};
|
|
@@ -23913,6 +24679,58 @@ var RadioControl = class extends CheckboxControl {
|
|
|
23913
24679
|
}
|
|
23914
24680
|
}
|
|
23915
24681
|
};
|
|
24682
|
+
var ComponentRadioControl = class extends RadioControl {
|
|
24683
|
+
static writesDefault = false;
|
|
24684
|
+
get host() {
|
|
24685
|
+
return super.element;
|
|
24686
|
+
}
|
|
24687
|
+
get element() {
|
|
24688
|
+
return this.host.control;
|
|
24689
|
+
}
|
|
24690
|
+
project(value, change) {
|
|
24691
|
+
if (this.host.shouldProjectControlValue(value)) super.project(value, change);
|
|
24692
|
+
}
|
|
24693
|
+
commit(event) {
|
|
24694
|
+
if (this.binding.closed || this.element.disabled || this.element.readOnly) return;
|
|
24695
|
+
commitComponent(this.host, this.host.acceptControlValue(), () => super.commit(event));
|
|
24696
|
+
}
|
|
24697
|
+
read() {
|
|
24698
|
+
return this.host.readControlValue();
|
|
24699
|
+
}
|
|
24700
|
+
write(value) {
|
|
24701
|
+
this.host.writeControlValue(value);
|
|
24702
|
+
}
|
|
24703
|
+
attach() {
|
|
24704
|
+
this.host.setPageContext(componentContext(this));
|
|
24705
|
+
super.attach();
|
|
24706
|
+
this.element.addEventListener("keydown", this);
|
|
24707
|
+
}
|
|
24708
|
+
detach() {
|
|
24709
|
+
this.host.releaseControl();
|
|
24710
|
+
this.element.removeEventListener("keydown", this);
|
|
24711
|
+
super.detach();
|
|
24712
|
+
}
|
|
24713
|
+
handleEvent(event) {
|
|
24714
|
+
if (this.binding.closed) return;
|
|
24715
|
+
if (event.type === "keydown") {
|
|
24716
|
+
if (this.resolved.group == null || !["ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown"].includes(event.key)) return;
|
|
24717
|
+
const peers = this.groups.peersOf(this.resolved.group, formNode(this.node)).filter((peer) => !peer.binding.closed && !peer.element.disabled);
|
|
24718
|
+
const index = peers.indexOf(this);
|
|
24719
|
+
if (index < 0) return;
|
|
24720
|
+
event.preventDefault();
|
|
24721
|
+
const delta = ["ArrowLeft", "ArrowUp"].includes(event.key) ? -1 : 1;
|
|
24722
|
+
const next = peers[(index + delta + peers.length) % peers.length];
|
|
24723
|
+
next.element.focus();
|
|
24724
|
+
next.element.click();
|
|
24725
|
+
return;
|
|
24726
|
+
}
|
|
24727
|
+
super.handleEvent(event);
|
|
24728
|
+
if (!event.composed && !this.binding.closed && ["input", "change"].includes(event.type)) {
|
|
24729
|
+
const Event = this.host.ownerDocument.defaultView.Event;
|
|
24730
|
+
this.host.dispatchEvent(new Event(event.type, { bubbles: true, composed: true }));
|
|
24731
|
+
}
|
|
24732
|
+
}
|
|
24733
|
+
};
|
|
23916
24734
|
var RadioGroups = class {
|
|
23917
24735
|
#renderer;
|
|
23918
24736
|
#groups = /* @__PURE__ */ new Map();
|
|
@@ -23985,6 +24803,71 @@ var INPUT_CONTROLS = {
|
|
|
23985
24803
|
reset: null,
|
|
23986
24804
|
image: null
|
|
23987
24805
|
};
|
|
24806
|
+
function componentContext(adapter) {
|
|
24807
|
+
const { binding, node } = adapter, app = binding.runtime.gramlot;
|
|
24808
|
+
const invoke = (attribute, code, keywords, expression = false) => {
|
|
24809
|
+
if (!expression && /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(code)) {
|
|
24810
|
+
const { group, method } = app.src.logicRegistry.resolve(code, node);
|
|
24811
|
+
return method.call(group, node, keywords);
|
|
24812
|
+
}
|
|
24813
|
+
return binding.runtime.inlineCompiler.compile(
|
|
24814
|
+
node,
|
|
24815
|
+
attribute,
|
|
24816
|
+
code,
|
|
24817
|
+
Object.keys(keywords),
|
|
24818
|
+
expression ? `return (${code});` : code
|
|
24819
|
+
)(keywords);
|
|
24820
|
+
};
|
|
24821
|
+
return {
|
|
24822
|
+
locale: app.locale,
|
|
24823
|
+
timeZone: app.timeZone,
|
|
24824
|
+
createDecimal,
|
|
24825
|
+
isDecimal: isDecimal2,
|
|
24826
|
+
getDecimalLibrary,
|
|
24827
|
+
isActive: () => !binding.closed,
|
|
24828
|
+
callLogic: (name, keywords) => {
|
|
24829
|
+
const { group, method } = app.src.logicRegistry.resolve(name, node);
|
|
24830
|
+
return method.call(group, node, keywords);
|
|
24831
|
+
},
|
|
24832
|
+
format: (value, options) => app.format(value, options),
|
|
24833
|
+
invoke,
|
|
24834
|
+
remote: (method, keywords, signal) => app.rpc.call("data", method, keywords, { signal }),
|
|
24835
|
+
validationCurrent: () => {
|
|
24836
|
+
const pointer = node.getAttr("value");
|
|
24837
|
+
const path = node.pointerType(pointer) ? node.absDatapath(pointer) : null;
|
|
24838
|
+
return () => !binding.closed && node.getAttr("value") === pointer && (path === null || node.absDatapath(pointer) === path);
|
|
24839
|
+
},
|
|
24840
|
+
finishValidation: ({ ok, result, rules }) => {
|
|
24841
|
+
if (binding.closed) return;
|
|
24842
|
+
if (ok) for (const patch of result.datachanges) node.getRelativeData(".").update(patch);
|
|
24843
|
+
const attribute = ok ? "validate_onAccept" : "validate_onReject";
|
|
24844
|
+
if (rules[attribute]) {
|
|
24845
|
+
const report = (error) => console.error("Validation notification failed:", error);
|
|
24846
|
+
try {
|
|
24847
|
+
const validations = Object.fromEntries(Object.entries(rules).map(([key, value]) => [key.slice(9), value]));
|
|
24848
|
+
const returned = invoke(attribute, rules[attribute], { value: result.value, result, validations, userChange: true });
|
|
24849
|
+
if (returned instanceof Promise) returned.catch(report);
|
|
24850
|
+
} catch (error) {
|
|
24851
|
+
report(error);
|
|
24852
|
+
}
|
|
24853
|
+
}
|
|
24854
|
+
},
|
|
24855
|
+
checkDataPatch: (patch) => {
|
|
24856
|
+
if (!(patch instanceof Bag)) throw new TypeError("Validation data changes must be a Bag.");
|
|
24857
|
+
if (!(node.getRelativeData(".") instanceof Bag)) throw new TypeError("Validation data changes require a Bag datapath.");
|
|
24858
|
+
}
|
|
24859
|
+
};
|
|
24860
|
+
}
|
|
24861
|
+
function commitComponent(host, outcome, commit) {
|
|
24862
|
+
const finish = (result) => {
|
|
24863
|
+
if (result.ok && result.isCurrent()) {
|
|
24864
|
+
commit(result);
|
|
24865
|
+
host.finishValidation(result);
|
|
24866
|
+
}
|
|
24867
|
+
};
|
|
24868
|
+
if (outcome instanceof Promise) outcome.then(finish).catch((error) => console.error("Validation notification failed:", error));
|
|
24869
|
+
else finish(outcome);
|
|
24870
|
+
}
|
|
23988
24871
|
|
|
23989
24872
|
// src/view/html.js
|
|
23990
24873
|
var DEFAULT_TEXT = /* @__PURE__ */ Symbol("source text");
|
|
@@ -24057,6 +24940,7 @@ var HtmlElement = class {
|
|
|
24057
24940
|
throw new TypeError("HTML text must be scalar");
|
|
24058
24941
|
}
|
|
24059
24942
|
for (const [key, value] of Object.entries(node.attr)) {
|
|
24943
|
+
if (key === "value" && this.definition(node).meta.gramlot_component) continue;
|
|
24060
24944
|
if (this.metadataAttributes.has(key) || ["ask", "_ask"].includes(key) || value && typeof value === "object" && Object.hasOwn(value, "$gramlotRef")) continue;
|
|
24061
24945
|
if (value != null && !["string", "number", "boolean"].includes(typeof value)) {
|
|
24062
24946
|
throw new TypeError(`HTML attribute ${key} must be scalar`);
|
|
@@ -24070,6 +24954,15 @@ var HtmlElement = class {
|
|
|
24070
24954
|
const { tag: defaultTag, namespace, meta } = this.definition(node);
|
|
24071
24955
|
tag2 ??= defaultTag;
|
|
24072
24956
|
const element = namespace === XHTML_NS ? document.createElement(tag2) : document.createElementNS(namespace, tag2);
|
|
24957
|
+
if (meta.gramlot_component && element.constructor.gramlotComponent?.tag !== tag2) {
|
|
24958
|
+
throw new Error(`Component collection must be activated before rendering ${tag2}`);
|
|
24959
|
+
}
|
|
24960
|
+
if (meta.gramlot_component?.dataScope) {
|
|
24961
|
+
element.readDataScope = () => {
|
|
24962
|
+
if (!node.getAttr("datapath")) throw new Error("Data scope requires an explicit datapath");
|
|
24963
|
+
return node.getRelativeData(".");
|
|
24964
|
+
};
|
|
24965
|
+
}
|
|
24073
24966
|
const text = document.createTextNode(this.text(node));
|
|
24074
24967
|
if (namespace !== XHTML_NS || !meta.void) element.append(text);
|
|
24075
24968
|
const record2 = { element, text, tag: tag2 };
|
|
@@ -24095,6 +24988,13 @@ var HtmlElement = class {
|
|
|
24095
24988
|
const isHtml = element.namespaceURI === XHTML_NS;
|
|
24096
24989
|
const renderAttributes = this.definition(node).meta.render_attributes ?? {};
|
|
24097
24990
|
const previous = record2.attrs ?? {};
|
|
24991
|
+
if (this.definition(node).meta.gramlot_component) {
|
|
24992
|
+
attrs = element.projectAttributes(attrs, (values) => {
|
|
24993
|
+
requireNoScriptAttributes(node, values, node.builder.constructor.dialectPrefixes);
|
|
24994
|
+
requireStyleClassAttributes(node, values, node.builder.constructor.dialectPrefixes);
|
|
24995
|
+
return node.builder.renderer_html.adaptAttrs(values);
|
|
24996
|
+
});
|
|
24997
|
+
}
|
|
24098
24998
|
attrs = Object.fromEntries(sourceAttributeItems({ ...attrs, ...renderAttributes }));
|
|
24099
24999
|
const controlled = ControlAdapter.classFor(element, attrs) !== null;
|
|
24100
25000
|
if (textValue2 === DEFAULT_TEXT) textValue2 = this.text(node);
|
|
@@ -24203,7 +25103,7 @@ var AskDialog = class {
|
|
|
24203
25103
|
let finished = false;
|
|
24204
25104
|
let release = () => {
|
|
24205
25105
|
};
|
|
24206
|
-
const finish = (confirmed,
|
|
25106
|
+
const finish = (confirmed, failure = null) => {
|
|
24207
25107
|
if (finished) return;
|
|
24208
25108
|
finished = true;
|
|
24209
25109
|
const result = confirmed ? Object.fromEntries(fields.map((field) => [field.name, app.data.getItem(`${id}.${field.name}`)])) : null;
|
|
@@ -24212,7 +25112,7 @@ var AskDialog = class {
|
|
|
24212
25112
|
try {
|
|
24213
25113
|
app.src.source.popNode(id);
|
|
24214
25114
|
if (app.data.getNode(id)) app.data.popNode(id);
|
|
24215
|
-
if (
|
|
25115
|
+
if (failure) reject(failure);
|
|
24216
25116
|
else resolve(result);
|
|
24217
25117
|
} catch (error) {
|
|
24218
25118
|
reject(error);
|
|
@@ -24250,8 +25150,8 @@ var AskDialog = class {
|
|
|
24250
25150
|
else row.input({ ...attrs, type: field.type ?? "text" });
|
|
24251
25151
|
}
|
|
24252
25152
|
const buttons = form.div({ style: "display:flex;justify-content:flex-end;gap:8px;margin-top:16px;" });
|
|
24253
|
-
buttons.
|
|
24254
|
-
buttons.
|
|
25153
|
+
buttons.html_button("Cancel", { type: "button", request: id, connect_onclick: `${page.group}.cancel` });
|
|
25154
|
+
buttons.html_button("Confirm", { type: "submit", autofocus: fields.length === 0 });
|
|
24255
25155
|
app.src.source.setItem(id, app.src.prepareSource(builder.source));
|
|
24256
25156
|
const node = app.src.binding.nodeIds.get(id);
|
|
24257
25157
|
app.dom.getDomNode(node).showModal();
|
|
@@ -24271,7 +25171,7 @@ var ButtonBinding = class _ButtonBinding {
|
|
|
24271
25171
|
/** The binding of a Gramlot button; html_button remains native despite its DOM tag. */
|
|
24272
25172
|
static for(binding, record2) {
|
|
24273
25173
|
const element = record2.element;
|
|
24274
|
-
if (
|
|
25174
|
+
if (!element?.constructor.gramlotComponent?.command) return null;
|
|
24275
25175
|
return new _ButtonBinding(binding, record2);
|
|
24276
25176
|
}
|
|
24277
25177
|
constructor(binding, record2) {
|
|
@@ -24316,6 +25216,8 @@ var ButtonBinding = class _ButtonBinding {
|
|
|
24316
25216
|
/** Check the mechanism, apply R3's `type`, then listen to `click`. */
|
|
24317
25217
|
attach() {
|
|
24318
25218
|
this.refresh();
|
|
25219
|
+
this.element.activateCommand = (event) => this.onClick(event);
|
|
25220
|
+
this.element.attachCommand();
|
|
24319
25221
|
this.element.addEventListener("click", this);
|
|
24320
25222
|
}
|
|
24321
25223
|
/**
|
|
@@ -24330,6 +25232,8 @@ var ButtonBinding = class _ButtonBinding {
|
|
|
24330
25232
|
}
|
|
24331
25233
|
detach() {
|
|
24332
25234
|
this.element.removeEventListener("click", this);
|
|
25235
|
+
this.element.releaseCommand();
|
|
25236
|
+
delete this.element.activateCommand;
|
|
24333
25237
|
this.#cancelDelay?.();
|
|
24334
25238
|
}
|
|
24335
25239
|
handleEvent(event) {
|
|
@@ -24341,7 +25245,14 @@ var ButtonBinding = class _ButtonBinding {
|
|
|
24341
25245
|
* the mechanism. An error propagates from the listener.
|
|
24342
25246
|
*/
|
|
24343
25247
|
onClick(event) {
|
|
24344
|
-
if (this.binding.closed) return;
|
|
25248
|
+
if (this.binding.closed || this.element.disabled) return;
|
|
25249
|
+
const target = this.element.commandTarget(event);
|
|
25250
|
+
if (target === null) return;
|
|
25251
|
+
if (target !== this.element) {
|
|
25252
|
+
event.stopPropagation();
|
|
25253
|
+
return target.activateCommand(event);
|
|
25254
|
+
}
|
|
25255
|
+
if (!this.element.prepareCommand(event)) return;
|
|
24345
25256
|
const mechanism = this.mechanism;
|
|
24346
25257
|
if (!mechanism) return;
|
|
24347
25258
|
event.stopPropagation();
|
|
@@ -24389,7 +25300,7 @@ var ButtonBinding = class _ButtonBinding {
|
|
|
24389
25300
|
return { ...this.binding.runtime.renderer.references.resolveArguments(authored), event, _counter: counter, modifiers };
|
|
24390
25301
|
};
|
|
24391
25302
|
const execute = (result) => {
|
|
24392
|
-
if (this.binding.closed || result === null) return;
|
|
25303
|
+
if (this.binding.closed || this.element.disabled || result === null) return;
|
|
24393
25304
|
const values = { ...read(), ...result };
|
|
24394
25305
|
if (result) values._askResult = result;
|
|
24395
25306
|
this.binding.runtime.inlineCompiler.compile(node, "action", node.getAttr("action"), Object.keys(values))(values);
|
|
@@ -25484,9 +26395,8 @@ var InlineCompiler = class {
|
|
|
25484
26395
|
* The function of the `==` expression `code` of the attribute `attr` of `node` (`''` for the node
|
|
25485
26396
|
* value), as written in the Source: `run(resolved)` evaluates it on the attributes resolved by
|
|
25486
26397
|
* runtimeValues. Its arguments are the
|
|
25487
|
-
* other attributes of the node, except the other `==` (Q11.2)
|
|
25488
|
-
*
|
|
25489
|
-
* itself a template has no value: an expression using it is an error naming both attributes.
|
|
26398
|
+
* other attributes of the node, except the other `==` (Q11.2). Named pointer slots retain
|
|
26399
|
+
* those attributes in the resolved projection; ordinary ${name} strings remain literal.
|
|
25490
26400
|
*/
|
|
25491
26401
|
compileExpression(node, attr, code) {
|
|
25492
26402
|
const expr = code.slice(2);
|
|
@@ -25497,10 +26407,6 @@ var InlineCompiler = class {
|
|
|
25497
26407
|
for (const [name, raw] of items) {
|
|
25498
26408
|
if (Object.hasOwn(resolved2, name)) {
|
|
25499
26409
|
values[name] = resolved2[name];
|
|
25500
|
-
} else if (templateParameters(raw).length) {
|
|
25501
|
-
if (isIdentifier(name) && new RegExp(`(?<![\\w$])${name.replaceAll("$", "\\$")}(?![\\w$])`).test(expr)) {
|
|
25502
|
-
throw new Error(`${node.nodeTag} '${node.label}': '${attr}' uses '${name}', a template consumed by another template, whose value is not available; write a dataFormula`);
|
|
25503
|
-
}
|
|
25504
26410
|
} else {
|
|
25505
26411
|
values[name] = node.pointerType(raw) ? node.getRelativeData(raw) : raw;
|
|
25506
26412
|
}
|
|
@@ -26126,6 +27032,8 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26126
27032
|
#resolvedAttributes = /* @__PURE__ */ new WeakMap();
|
|
26127
27033
|
// The resolved projection that `project` hands to the rebuild of a control whose shape changed.
|
|
26128
27034
|
#rebuildAttributes = /* @__PURE__ */ new WeakMap();
|
|
27035
|
+
// Own presentation defaults, resolved once in their declaring Source scope.
|
|
27036
|
+
#presentationDefaults = /* @__PURE__ */ new WeakMap();
|
|
26129
27037
|
/** The live renderer of one Gramlot page: `binding` is the page's BindingRuntime (§4.3). */
|
|
26130
27038
|
constructor(builder, source, destination, { binding } = {}) {
|
|
26131
27039
|
super(builder);
|
|
@@ -26166,7 +27074,19 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26166
27074
|
* its `==` are evaluated once.
|
|
26167
27075
|
*/
|
|
26168
27076
|
evaluateExpressions(node, runtimeAttrs) {
|
|
26169
|
-
|
|
27077
|
+
let attrs = this.#rebuildAttributes.get(node) ?? super.evaluateExpressions(node, runtimeAttrs);
|
|
27078
|
+
const component = node._getMeta("gramlot_component");
|
|
27079
|
+
if (component?.presentationDefaults.length) {
|
|
27080
|
+
const declared = node.getAttr();
|
|
27081
|
+
this.#presentationDefaults.set(node, Object.fromEntries(Object.entries(attrs).filter(([name]) => Object.hasOwn(declared, name) && component.presentationDefaults.some((prefix) => name.startsWith(prefix)))));
|
|
27082
|
+
}
|
|
27083
|
+
if (component && (component.parameters.value?.binding === "twoWay" || component.presentationDefaults.length)) {
|
|
27084
|
+
const ancestors = [];
|
|
27085
|
+
for (let parent = node.parentNode; parent; parent = parent.parentNode) {
|
|
27086
|
+
if (this.#presentationDefaults.has(parent)) ancestors.unshift(this.#presentationDefaults.get(parent));
|
|
27087
|
+
}
|
|
27088
|
+
attrs = Object.assign({}, ...ancestors, attrs);
|
|
27089
|
+
}
|
|
26170
27090
|
this.#rebuildAttributes.delete(node);
|
|
26171
27091
|
this.#resolvedAttributes.set(node, attrs);
|
|
26172
27092
|
return attrs;
|
|
@@ -26227,12 +27147,14 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26227
27147
|
let attrs = runtimeAttrs;
|
|
26228
27148
|
item = this.expressionValue(node, item);
|
|
26229
27149
|
if (this.getRender(node.builder) === this) {
|
|
26230
|
-
|
|
27150
|
+
attrs = this.restoreNativeAttributes(node, runtimeAttrs);
|
|
27151
|
+
if (!node._getMeta("gramlot_component")) [item, attrs] = displayItem(
|
|
26231
27152
|
item,
|
|
26232
|
-
|
|
27153
|
+
attrs,
|
|
26233
27154
|
(value, options) => this._binding.gramlot.format(value, options)
|
|
26234
27155
|
);
|
|
26235
27156
|
}
|
|
27157
|
+
attrs = this.componentAttributes(node, attrs);
|
|
26236
27158
|
const children = Array.isArray(item) ? item : [];
|
|
26237
27159
|
const text = Array.isArray(item) ? attrs._text : item;
|
|
26238
27160
|
const resolved2 = this.#resolvedAttributes.get(node);
|
|
@@ -26553,6 +27475,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26553
27475
|
const record2 = this.records.get(node);
|
|
26554
27476
|
if (!record2?.element) return;
|
|
26555
27477
|
const renderer = this.getRender(node.builder);
|
|
27478
|
+
const previousDefaults = this.#presentationDefaults.get(node);
|
|
26556
27479
|
const [value, runtimeAttrs] = node.builder.runtimeValues(node);
|
|
26557
27480
|
const [, resolvedAttrs] = renderer._handleMeta(node, runtimeAttrs);
|
|
26558
27481
|
const resolved2 = this.#resolvedAttributes.get(node);
|
|
@@ -26570,20 +27493,52 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26570
27493
|
let attrs = node._getMeta("subbuilder") ? resolvedAttrs : renderer.adaptAttrs(resolvedAttrs);
|
|
26571
27494
|
const branch = node.value instanceof SourceBag;
|
|
26572
27495
|
let text = branch ? [] : this.expressionValue(node, value);
|
|
26573
|
-
if (renderer === this)
|
|
26574
|
-
|
|
26575
|
-
|
|
26576
|
-
|
|
26577
|
-
|
|
27496
|
+
if (renderer === this) {
|
|
27497
|
+
attrs = this.restoreNativeAttributes(node, attrs);
|
|
27498
|
+
if (!node._getMeta("gramlot_component")) [text, attrs] = displayItem(
|
|
27499
|
+
text,
|
|
27500
|
+
attrs,
|
|
27501
|
+
(value2, options) => this._binding.gramlot.format(value2, options)
|
|
27502
|
+
);
|
|
27503
|
+
}
|
|
27504
|
+
attrs = this.componentAttributes(node, attrs);
|
|
26578
27505
|
this.html.update(record2, node, attrs, branch ? attrs._text : text, resolved2.visible ?? null);
|
|
26579
27506
|
this.#projectControl(record2, node, attrs, change);
|
|
26580
27507
|
record2.control?.refresh();
|
|
26581
27508
|
record2.button?.refresh();
|
|
26582
27509
|
this.#connectEvents(record2);
|
|
27510
|
+
const defaults = this.#presentationDefaults.get(node);
|
|
27511
|
+
if (defaults) {
|
|
27512
|
+
const changed = new Set([...Object.keys(previousDefaults ?? {}), ...Object.keys(defaults)].filter((name) => !Object.is(previousDefaults?.[name], defaults[name])));
|
|
27513
|
+
if (changed.size) this.#refreshPresentation(node, changed);
|
|
27514
|
+
}
|
|
26583
27515
|
if (record2.element.localName === "option" || record2.element.localName === "optgroup") {
|
|
26584
27516
|
this.#optionsChanged(record2.parent);
|
|
26585
27517
|
}
|
|
26586
27518
|
}
|
|
27519
|
+
/** Only affected consumers project; nested providers mask their own declared defaults. */
|
|
27520
|
+
#refreshPresentation(parent, changed) {
|
|
27521
|
+
if (!(parent.value instanceof SourceBag)) return;
|
|
27522
|
+
for (const child of parent.value.getNodes()) {
|
|
27523
|
+
const component = child._getMeta("gramlot_component");
|
|
27524
|
+
const declared = child.getAttr();
|
|
27525
|
+
let inherited = changed;
|
|
27526
|
+
if (component?.presentationDefaults.length) {
|
|
27527
|
+
inherited = new Set([...changed].filter((name) => !Object.hasOwn(declared, name)));
|
|
27528
|
+
} else if (component?.parameters.value?.binding === "twoWay" && [...changed].some((name) => !Object.hasOwn(declared, name))) {
|
|
27529
|
+
this.project(child);
|
|
27530
|
+
}
|
|
27531
|
+
if (inherited.size) this.#refreshPresentation(child, inherited);
|
|
27532
|
+
}
|
|
27533
|
+
}
|
|
27534
|
+
/** Component parameters use resolved Source values, before HTML-only filtering (e.g. validate_*). */
|
|
27535
|
+
componentAttributes(node, attrs) {
|
|
27536
|
+
const component = node._getMeta("gramlot_component");
|
|
27537
|
+
if (!component) return attrs;
|
|
27538
|
+
const resolved2 = this.#resolvedAttributes.get(node);
|
|
27539
|
+
const parameters2 = Object.fromEntries([.../* @__PURE__ */ new Set([...Object.keys(component.parameters), ...Object.keys(resolved2).filter((name) => name.startsWith("validate_"))])].filter((name) => Object.hasOwn(resolved2, name)).map((name) => [name, resolved2[name]]));
|
|
27540
|
+
return { ...attrs, ...parameters2 };
|
|
27541
|
+
}
|
|
26587
27542
|
/**
|
|
26588
27543
|
* The resolved `value` to the ControlAdapter of `record` when the node declares a `value`, or declared
|
|
26589
27544
|
* one at the previous projection: its removal shows the control empty once, as html.js did (S10).
|
|
@@ -26713,6 +27668,8 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
26713
27668
|
record2.end?.remove();
|
|
26714
27669
|
record2.parent?.children.delete(node);
|
|
26715
27670
|
this.records.delete(node);
|
|
27671
|
+
this.#resolvedAttributes.delete(node);
|
|
27672
|
+
this.#presentationDefaults.delete(node);
|
|
26716
27673
|
if (errors.length) throw new AggregateError(errors, "Source cleanup failed");
|
|
26717
27674
|
}
|
|
26718
27675
|
dispose() {
|
|
@@ -27093,6 +28050,13 @@ var RpcHandler = class extends Handler {
|
|
|
27093
28050
|
|
|
27094
28051
|
// src/handlers/dom-handler.js
|
|
27095
28052
|
var DomHandler = class extends Handler {
|
|
28053
|
+
/** Size controls for the input device without rebuilding the page. */
|
|
28054
|
+
setTouchMode(mode = "auto") {
|
|
28055
|
+
if (!["auto", "on", "off"].includes(mode)) throw new TypeError(`Invalid touch mode: ${mode}`);
|
|
28056
|
+
const root = this.gramlot.src.renderer.destination.ownerDocument.documentElement;
|
|
28057
|
+
if (mode === "auto") root.removeAttribute("data-gramlot-touch");
|
|
28058
|
+
else root.setAttribute("data-gramlot-touch", mode);
|
|
28059
|
+
}
|
|
27096
28060
|
reference(descriptor) {
|
|
27097
28061
|
return this.gramlot.src.renderer.references.resolve(descriptor);
|
|
27098
28062
|
}
|
|
@@ -27494,10 +28458,16 @@ var Gramlot = class {
|
|
|
27494
28458
|
transport = null,
|
|
27495
28459
|
collections = [],
|
|
27496
28460
|
locale = null,
|
|
27497
|
-
timeZone = null
|
|
28461
|
+
timeZone = null,
|
|
28462
|
+
devices = []
|
|
27498
28463
|
} = {}) {
|
|
28464
|
+
buttons_default.register(document.defaultView);
|
|
28465
|
+
for (const collection of collections) {
|
|
28466
|
+
if (collection instanceof ComponentCollection) collection.register(document.defaultView);
|
|
28467
|
+
}
|
|
27499
28468
|
this.pageId = pageId;
|
|
27500
28469
|
const browserContext = locale == null || timeZone == null ? document.defaultView.Intl.DateTimeFormat().resolvedOptions() : null;
|
|
28470
|
+
this.devices = Object.freeze([...devices]);
|
|
27501
28471
|
this.locale = locale ?? browserContext.locale;
|
|
27502
28472
|
this.timeZone = timeZone ?? browserContext.timeZone;
|
|
27503
28473
|
Object.defineProperty(this, "_subscriptions", { value: new SubscriptionsHandler(this) });
|
|
@@ -27601,7 +28571,7 @@ var PageBootstrap = class {
|
|
|
27601
28571
|
this.closePage();
|
|
27602
28572
|
};
|
|
27603
28573
|
window2.addEventListener("pagehide", pagehide);
|
|
27604
|
-
let entries;
|
|
28574
|
+
let entries, collections;
|
|
27605
28575
|
try {
|
|
27606
28576
|
const settled = await Promise.allSettled(resources.js.map(({ url }) => import(new URL(url, document.baseURI).href)));
|
|
27607
28577
|
if (closed) return null;
|
|
@@ -27613,13 +28583,26 @@ var PageBootstrap = class {
|
|
|
27613
28583
|
return { logicClass: outcome.value.Logic, group, resource: url };
|
|
27614
28584
|
});
|
|
27615
28585
|
LogicRegistry.check(entries);
|
|
28586
|
+
collections = await Promise.all((resources.collections ?? []).map(async (url) => {
|
|
28587
|
+
try {
|
|
28588
|
+
return (await import(new URL(url, document.baseURI).href)).default;
|
|
28589
|
+
} catch (error) {
|
|
28590
|
+
throw new Error(`${url}: collection import failed: ${error.message}`, { cause: error });
|
|
28591
|
+
}
|
|
28592
|
+
}));
|
|
28593
|
+
if (closed) return null;
|
|
28594
|
+
for (const collection of collections) collection.register(window2);
|
|
27616
28595
|
} catch (error) {
|
|
27617
28596
|
this.closePage();
|
|
27618
28597
|
throw error;
|
|
27619
28598
|
} finally {
|
|
27620
28599
|
window2.removeEventListener("pagehide", pagehide);
|
|
27621
28600
|
}
|
|
27622
|
-
const app = new Gramlot({
|
|
28601
|
+
const app = new Gramlot({
|
|
28602
|
+
...config2,
|
|
28603
|
+
document,
|
|
28604
|
+
collections: [...config2.collections ?? [], ...collections.map((collection) => collection.toDocument())]
|
|
28605
|
+
});
|
|
27623
28606
|
for (const { logicClass, group, resource } of entries) app.src.logicRegistry.register(logicClass, { group, resource });
|
|
27624
28607
|
window2.gramlot = app;
|
|
27625
28608
|
await app.start();
|
|
@@ -27653,6 +28636,7 @@ function declare(PageClass, methodName, marker, auth) {
|
|
|
27653
28636
|
}
|
|
27654
28637
|
var Page = class {
|
|
27655
28638
|
static title = "Gramlot";
|
|
28639
|
+
static devices = [];
|
|
27656
28640
|
static locale = null;
|
|
27657
28641
|
static timeZone = null;
|
|
27658
28642
|
static installable = false;
|
|
@@ -27705,6 +28689,7 @@ var IndexPage = class extends Page {
|
|
|
27705
28689
|
main(root) {
|
|
27706
28690
|
const families = this.constructor.navigation;
|
|
27707
28691
|
const shell = root.div({ class: "index-shell", id: this.constructor.shellId });
|
|
28692
|
+
this.header(shell);
|
|
27708
28693
|
const sidebar = shell.aside({ class: "index-sidebar", id: "index-sidebar" });
|
|
27709
28694
|
const brand = sidebar.header();
|
|
27710
28695
|
if (this.constructor.logoUrl) brand.img({ src: this.constructor.logoUrl, alt: this.constructor.title, class: "index-logo" });
|
|
@@ -27743,7 +28728,7 @@ var IndexPage = class extends Page {
|
|
|
27743
28728
|
});
|
|
27744
28729
|
const content = shell.main({ class: "index-main" });
|
|
27745
28730
|
const tabs = content.div({ class: "index-tabs", role: "tablist", aria_label: "Open pages" });
|
|
27746
|
-
tabs.
|
|
28731
|
+
tabs.html_button("Introduction", {
|
|
27747
28732
|
type: "button",
|
|
27748
28733
|
role: "tab",
|
|
27749
28734
|
id: "tab-intro",
|
|
@@ -27754,7 +28739,7 @@ var IndexPage = class extends Page {
|
|
|
27754
28739
|
});
|
|
27755
28740
|
for (const family of families) {
|
|
27756
28741
|
for (const { key, title } of [family, ...family.children]) {
|
|
27757
|
-
tabs.
|
|
28742
|
+
tabs.html_button(title, {
|
|
27758
28743
|
type: "button",
|
|
27759
28744
|
role: "tab",
|
|
27760
28745
|
id: `tab-${key}`,
|
|
@@ -27789,6 +28774,8 @@ var IndexPage = class extends Page {
|
|
|
27789
28774
|
this.footer(footer);
|
|
27790
28775
|
this.behavior(shell);
|
|
27791
28776
|
}
|
|
28777
|
+
header(shell) {
|
|
28778
|
+
}
|
|
27792
28779
|
behavior(shell) {
|
|
27793
28780
|
shell.dataController({ func: "indexMount", _onStart: true, shell_id: this.constructor.shellId });
|
|
27794
28781
|
}
|
|
@@ -27805,6 +28792,8 @@ var IndexPage = class extends Page {
|
|
|
27805
28792
|
const appearance = theme.select({ id: "index-appearance", value: "compact" });
|
|
27806
28793
|
appearance.option("Base", { value: "base", selected: false });
|
|
27807
28794
|
appearance.option("Compact", { value: "compact", selected: true });
|
|
28795
|
+
appearance.option("mimi", { value: "mimi" });
|
|
28796
|
+
appearance.option("joanna", { value: "joanna" });
|
|
27808
28797
|
const color = footer.div({ class: "index-theme" });
|
|
27809
28798
|
color.html_label("Color mode", { for: "index-theme" });
|
|
27810
28799
|
const choices = color.select({ id: "index-theme", value: "light" });
|
|
@@ -27817,7 +28806,7 @@ var IndexPage = class extends Page {
|
|
|
27817
28806
|
if (this.constructor.installable) {
|
|
27818
28807
|
const app = footer.details({ class: "index-install" });
|
|
27819
28808
|
app.summary("Install app");
|
|
27820
|
-
app.
|
|
28809
|
+
app.html_button("Install", { type: "button", id: "index-install-button", hidden: true });
|
|
27821
28810
|
app.p("", { id: "index-install-status", role: "status" });
|
|
27822
28811
|
app.p("Chrome: use Install page as app in the browser menu. Safari on macOS Sonoma or later: File > Add to Dock.");
|
|
27823
28812
|
app.p("Use HTTPS or localhost. For a static export, serve the directory; direct file opening is not installable. Keep the server running for hosted pages.");
|
|
@@ -27836,13 +28825,13 @@ var IndexPage = class extends Page {
|
|
|
27836
28825
|
};
|
|
27837
28826
|
|
|
27838
28827
|
// src/index-page-styles.js
|
|
27839
|
-
var compactStyle = '/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type="color"]) { min-block-size: 28px; }\n :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n';
|
|
28828
|
+
var appearanceStyles = { "base": "", "compact": '/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type="color"]) { min-block-size: 28px; }\n :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n', "mimi": '/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type="color"]) { min-block-size: 28px; }\n :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n\n/* Gramlot adaptation of legacy mimi; load after Base and Compact. */\n@layer gramlot.tokens {\n :root {\n --gramlot-background: #EDEEF0;\n --gramlot-surface: #F5F5F6;\n --gramlot-surface-subtle: #E0E1E3;\n --gramlot-ink: #3C3D40;\n --gramlot-text-secondary: #6B6E72;\n --gramlot-border: #BDBFC2;\n --gramlot-border-control: #9EA0A3;\n --gramlot-navigation: #48494C;\n --gramlot-navigation-text: #FFFFFF;\n --gramlot-action: #0071E3;\n --gramlot-action-hover: #005BBB;\n --gramlot-brand-blue: #0071E3;\n --gramlot-brand-yellow: #9EA0A3;\n --gramlot-selected: #E8F1FC;\n --gramlot-focus-ring: #0071E3;\n --gramlot-field-background: #FFFFFF;\n --gramlot-field-readonly-background: #E0E1E3;\n --gramlot-error: #B3261E;\n --gramlot-error-background: #FFF1F0;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 6%);\n --gramlot-radius-sm: 4px;\n --gramlot-radius: 3px;\n --gramlot-radius-lg: 3px;\n --gramlot-field-height: 18px;\n --gramlot-field-padding: 1px 3px;\n --gramlot-field-line-height: 1.15;\n --gramlot-field-font-size: 1rem;\n --gramlot-label-size: .9em;\n --gramlot-label-gap: 2px;\n --gramlot-label-color: var(--gramlot-text-secondary);\n --gramlot-space-4: 6px;\n --gramlot-font-ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;\n }\n @media (prefers-color-scheme: dark) {\n :root:not([data-theme="light"]) {\n --gramlot-background: #242527;\n --gramlot-surface: #303134;\n --gramlot-surface-subtle: #3C3D40;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #6B6E72;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3C3D40;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n }\n :root[data-theme="dark"] {\n --gramlot-background: #242527;\n --gramlot-surface: #303134;\n --gramlot-surface-subtle: #3C3D40;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #6B6E72;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3C3D40;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n}\n@layer gramlot.base {\n html { font-size: 12px; }\n}\n@layer gramlot.components {\n :where(label) { font-size: var(--gramlot-label-size); font-weight: normal; color: var(--gramlot-label-color); margin-block-end: var(--gramlot-label-gap); }\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) { min-block-size: 24px; padding: 2px 8px; font-weight: 500; }\n}\n@layer gramlot.utilities {\n .card { box-shadow: var(--gramlot-shadow); }\n}\n', "joanna": '/* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */\n@layer gramlot.tokens {\n :root {\n --gramlot-field-height: 28px;\n --gramlot-field-line-height: 1.35;\n --gramlot-field-padding: .25rem .5rem;\n --gramlot-field-font-size: 1rem;\n --gramlot-space-1: .2rem;\n --gramlot-space-2: .4rem;\n --gramlot-space-3: .5rem;\n --gramlot-space-4: .6rem;\n --gramlot-space-6: .9rem;\n --gramlot-space-8: 1.2rem;\n --gramlot-space-12: 1.8rem;\n --gramlot-radius-sm: .25rem;\n --gramlot-radius: .35rem;\n --gramlot-radius-lg: .4rem;\n }\n}\n\n@layer gramlot.base {\n html { font-size: 13px; }\n body { line-height: 1.35; }\n :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }\n h1 { font-size: 1.35rem; }\n h2 { font-size: 1.15rem; }\n h3 { font-size: 1.05rem; }\n pre { padding: .5rem; }\n blockquote { padding-inline-start: .6rem; }\n hr { margin-block: 1rem; }\n}\n\n@layer gramlot.components {\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {\n min-block-size: 28px;\n padding: .25rem .5rem;\n font-size: 1rem;\n line-height: 1.35;\n }\n :where(label) { font-size: .95rem; }\n :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {\n min-block-size: var(--gramlot-field-height);\n padding: var(--gramlot-field-padding);\n font-size: var(--gramlot-field-font-size);\n line-height: var(--gramlot-field-line-height);\n }\n :where(textarea) { min-block-size: 5rem; }\n :where(input[type="color"]) { min-block-size: 28px; }\n :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }\n :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }\n :where(table) { font-size: 1rem; }\n :where(th, td) { padding: .4rem .5rem; }\n :where(details) { padding: .4rem .5rem; }\n :where(details[open] > summary) { margin-block-end: .5rem; }\n :where(dialog) { padding: .75rem; }\n}\n\n@layer gramlot.utilities {\n .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }\n .card { padding: .6rem; box-shadow: none; }\n}\n\n/* Gramlot adaptation of legacy joanna; load after Base and Compact. */\n@layer gramlot.tokens {\n :root {\n --gramlot-background: #F2F2F7;\n --gramlot-surface: #FFFFFF;\n --gramlot-surface-subtle: #F2F2F7;\n --gramlot-ink: #3A3A3C;\n --gramlot-text-secondary: #636366;\n --gramlot-border: #D1D1D6;\n --gramlot-border-control: #AEAEB2;\n --gramlot-navigation: #3A3A3C;\n --gramlot-navigation-text: #FFFFFF;\n --gramlot-action: #007AFF;\n --gramlot-action-hover: #0061CC;\n --gramlot-brand-blue: #007AFF;\n --gramlot-brand-yellow: #AEAEB2;\n --gramlot-selected: #E0EFFF;\n --gramlot-focus-ring: #007AFF;\n --gramlot-field-background: #FFFFFF;\n --gramlot-field-readonly-background: #F2F2F7;\n --gramlot-error: #B3261E;\n --gramlot-error-background: #FFF1F0;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 6%);\n --gramlot-radius-sm: 6px;\n --gramlot-radius: 6px;\n --gramlot-radius-lg: 6px;\n --gramlot-field-height: 20px;\n --gramlot-field-padding: 1px 3px;\n --gramlot-field-line-height: 1.15;\n --gramlot-field-font-size: 1rem;\n --gramlot-label-size: .8em;\n --gramlot-label-gap: 2px;\n --gramlot-label-color: var(--gramlot-text-secondary);\n --gramlot-space-4: 6px;\n --gramlot-font-ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;\n }\n @media (prefers-color-scheme: dark) {\n :root:not([data-theme="light"]) {\n --gramlot-background: #1C1C1E;\n --gramlot-surface: #2C2C2E;\n --gramlot-surface-subtle: #3A3A3C;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #636366;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3A3A3C;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n }\n :root[data-theme="dark"] {\n --gramlot-background: #1C1C1E;\n --gramlot-surface: #2C2C2E;\n --gramlot-surface-subtle: #3A3A3C;\n --gramlot-ink: #F2F2F7;\n --gramlot-text-secondary: #C7C7CC;\n --gramlot-border: #636366;\n --gramlot-border-control: #8E8E93;\n --gramlot-navigation: #1C1C1E;\n --gramlot-action: #78B7FF;\n --gramlot-action-hover: #A6CFFF;\n --gramlot-brand-blue: #3478CA;\n --gramlot-selected: #254163;\n --gramlot-focus-ring: #78B7FF;\n --gramlot-field-background: #202124;\n --gramlot-field-readonly-background: #3A3A3C;\n --gramlot-error: #FFB4AB;\n --gramlot-error-background: #482524;\n --gramlot-shadow: 0 1px 4px rgb(0 0 0 / 20%);\n }\n}\n@layer gramlot.base {\n html { font-size: 13px; }\n}\n@layer gramlot.components {\n :where(label) { font-size: var(--gramlot-label-size); font-weight: normal; color: var(--gramlot-label-color); margin-block-end: var(--gramlot-label-gap); }\n :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) { min-block-size: 26px; padding: 2px 8px; font-weight: 500; }\n}\n@layer gramlot.utilities {\n .card { box-shadow: var(--gramlot-shadow); }\n}\n' };
|
|
27840
28829
|
|
|
27841
28830
|
// src/index-theme.js
|
|
27842
28831
|
var THEME_READY = "index:theme-ready";
|
|
27843
28832
|
var THEME_SET = "index:theme-set";
|
|
27844
28833
|
var THEMES = /* @__PURE__ */ new Set(["light", "dark"]);
|
|
27845
|
-
var APPEARANCES = /* @__PURE__ */ new Set(["base", "compact"]);
|
|
28834
|
+
var APPEARANCES = /* @__PURE__ */ new Set(["base", "compact", "mimi", "joanna"]);
|
|
27846
28835
|
|
|
27847
28836
|
// src/index-page-runtime.js
|
|
27848
28837
|
function mountIndexPage(renderer, root, onSelection = () => {
|
|
@@ -27859,6 +28848,10 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
27859
28848
|
const appearance = byId("index-appearance");
|
|
27860
28849
|
const sidebar = byId("index-sidebar");
|
|
27861
28850
|
const sidebarHandle = byId("index-sidebar-divider");
|
|
28851
|
+
const navigationToggle = byId("index-navigation-toggle");
|
|
28852
|
+
const codeToggle = byId("index-code-toggle");
|
|
28853
|
+
const codeSidebar = byId("index-code");
|
|
28854
|
+
const codeHandle = byId("index-code-divider");
|
|
27862
28855
|
const preferencesKey = `gramlot.${shell.id}.preferences:${window2.location.pathname}`;
|
|
27863
28856
|
let preferences = {};
|
|
27864
28857
|
try {
|
|
@@ -27882,12 +28875,17 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
27882
28875
|
state.setItem("keyboard", keyboard?.checked ?? false);
|
|
27883
28876
|
state.setItem("theme", theme?.value ?? "light");
|
|
27884
28877
|
state.setItem("appearance", appearance?.value ?? "compact");
|
|
28878
|
+
state.setItem("navigationVisible", preferences.navigationVisible !== false);
|
|
28879
|
+
state.setItem("codeVisible", preferences.codeVisible !== false);
|
|
27885
28880
|
const savePreferences = () => {
|
|
27886
28881
|
try {
|
|
27887
28882
|
window2.localStorage.setItem(preferencesKey, JSON.stringify({
|
|
27888
28883
|
theme: state.getItem("theme"),
|
|
27889
28884
|
appearance: state.getItem("appearance"),
|
|
27890
|
-
sidebarWidth: state.getItem("preferredSidebarWidth")
|
|
28885
|
+
sidebarWidth: state.getItem("preferredSidebarWidth"),
|
|
28886
|
+
codeWidth: state.getItem("preferredCodeWidth"),
|
|
28887
|
+
navigationVisible: state.getItem("navigationVisible"),
|
|
28888
|
+
codeVisible: state.getItem("codeVisible")
|
|
27891
28889
|
}));
|
|
27892
28890
|
} catch (error) {
|
|
27893
28891
|
if (error.name !== "SecurityError" && error.name !== "QuotaExceededError") throw error;
|
|
@@ -27895,7 +28893,7 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
27895
28893
|
};
|
|
27896
28894
|
const entries = /* @__PURE__ */ new Map();
|
|
27897
28895
|
const releases = [];
|
|
27898
|
-
const style = root.builder.wrapSource(root.value).style(
|
|
28896
|
+
const style = root.builder.wrapSource(root.value).style(appearanceStyles[appearance?.value ?? "compact"]);
|
|
27899
28897
|
let drag = null;
|
|
27900
28898
|
let disposed = false;
|
|
27901
28899
|
let installPrompt = null;
|
|
@@ -27925,10 +28923,27 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
27925
28923
|
const send = (frame) => frame.contentWindow.postMessage({ type: THEME_SET, theme: state.getItem("theme"), appearance: state.getItem("appearance") }, "*");
|
|
27926
28924
|
const applyTheme = () => {
|
|
27927
28925
|
document.documentElement.setAttribute("data-theme", state.getItem("theme"));
|
|
27928
|
-
style.
|
|
28926
|
+
style.setValue(appearanceStyles[state.getItem("appearance")]);
|
|
27929
28927
|
for (const { frame } of entries.values()) if (frame) send(frame);
|
|
27930
28928
|
};
|
|
27931
28929
|
const updateInspector = () => onSelection(entries, state.getItem("active"));
|
|
28930
|
+
const updatePanels = () => {
|
|
28931
|
+
if (navigationToggle) {
|
|
28932
|
+
const visible = state.getItem("navigationVisible");
|
|
28933
|
+
set(sidebar, { hidden: !visible });
|
|
28934
|
+
set(sidebarHandle, { hidden: !visible });
|
|
28935
|
+
set(navigationToggle, { aria_expanded: String(visible) });
|
|
28936
|
+
set(shell, { data_navigation_hidden: String(!visible) });
|
|
28937
|
+
}
|
|
28938
|
+
if (codeSidebar) {
|
|
28939
|
+
const available = Boolean(entries.get(state.getItem("active"))?.code);
|
|
28940
|
+
const visible = available && state.getItem("codeVisible");
|
|
28941
|
+
set(codeSidebar, { hidden: !visible });
|
|
28942
|
+
set(codeHandle, { hidden: !visible });
|
|
28943
|
+
set(codeToggle, { disabled: !available, aria_expanded: String(visible) });
|
|
28944
|
+
set(shell, { data_code_visible: String(visible) });
|
|
28945
|
+
}
|
|
28946
|
+
};
|
|
27932
28947
|
function select(key) {
|
|
27933
28948
|
const entry = entries.get(key);
|
|
27934
28949
|
if (!opened.getItem(key)) {
|
|
@@ -27941,29 +28956,38 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
27941
28956
|
const active = current === key;
|
|
27942
28957
|
set(item.tab, { aria_selected: String(active), tabindex: active && state.getItem("keyboard") ? 0 : -1 });
|
|
27943
28958
|
set(item.panel, { hidden: !active });
|
|
28959
|
+
if (item.code) set(item.code, { hidden: !active });
|
|
27944
28960
|
if (item.open) set(item.open, { aria_current: active ? "page" : null });
|
|
27945
28961
|
}
|
|
27946
28962
|
state.setItem("active", key);
|
|
28963
|
+
updatePanels();
|
|
27947
28964
|
updateInspector();
|
|
27948
28965
|
}
|
|
27949
|
-
function setRatio(entry, value) {
|
|
27950
|
-
const ratio = Math.max(20, Math.min(80, value));
|
|
27951
|
-
state.setItem(`ratio.${entry.key}`, ratio);
|
|
27952
|
-
set(entry.split, { style: `--split-position: ${ratio}%` });
|
|
27953
|
-
set(entry.handle, { aria_valuenow: ratio });
|
|
27954
|
-
}
|
|
27955
28966
|
const sidebarMaximum = () => Math.max(120, Math.min(460, Math.floor(window2.innerWidth * 0.6)));
|
|
28967
|
+
const applyWidths = () => set(shell, { style: `--sidebar-width: ${state.getItem("sidebarWidth")}px; --code-width: ${state.getItem("codeWidth") ?? 420}px` });
|
|
27956
28968
|
const setSidebarWidth = (value, remember = false) => {
|
|
27957
28969
|
const maximum = sidebarMaximum();
|
|
27958
28970
|
const width = Math.max(120, Math.min(maximum, value));
|
|
27959
28971
|
state.setItem("sidebarWidth", width);
|
|
27960
|
-
|
|
28972
|
+
applyWidths();
|
|
27961
28973
|
set(sidebarHandle, { aria_valuenow: width, aria_valuemax: maximum });
|
|
27962
28974
|
if (remember) {
|
|
27963
28975
|
state.setItem("preferredSidebarWidth", width);
|
|
27964
28976
|
savePreferences();
|
|
27965
28977
|
}
|
|
27966
28978
|
};
|
|
28979
|
+
const codeMaximum = () => Math.max(200, Math.floor(window2.innerWidth * 0.6));
|
|
28980
|
+
const setCodeWidth = (value, remember = false) => {
|
|
28981
|
+
const maximum = codeMaximum();
|
|
28982
|
+
const width = Math.max(200, Math.min(maximum, value));
|
|
28983
|
+
state.setItem("codeWidth", width);
|
|
28984
|
+
applyWidths();
|
|
28985
|
+
set(codeHandle, { aria_valuenow: width, aria_valuemax: maximum });
|
|
28986
|
+
if (remember) {
|
|
28987
|
+
state.setItem("preferredCodeWidth", width);
|
|
28988
|
+
savePreferences();
|
|
28989
|
+
}
|
|
28990
|
+
};
|
|
27967
28991
|
const beginDrag = (handle, event, move) => {
|
|
27968
28992
|
if (event.button !== 0) return;
|
|
27969
28993
|
stopDrag();
|
|
@@ -28008,6 +29032,38 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
28008
29032
|
const width = typeof savedWidth === "number" && Number.isFinite(savedWidth) && savedWidth >= 120 && savedWidth <= 460 ? savedWidth : sidebar.getBoundingClientRect().width || Number(sidebarHandle.getAttribute("aria-valuenow"));
|
|
28009
29033
|
state.setItem("preferredSidebarWidth", width);
|
|
28010
29034
|
setSidebarWidth(width);
|
|
29035
|
+
listen(navigationToggle, "click", () => {
|
|
29036
|
+
state.setItem("navigationVisible", !state.getItem("navigationVisible"));
|
|
29037
|
+
updatePanels();
|
|
29038
|
+
savePreferences();
|
|
29039
|
+
});
|
|
29040
|
+
listen(codeToggle, "click", () => {
|
|
29041
|
+
state.setItem("codeVisible", !state.getItem("codeVisible"));
|
|
29042
|
+
updatePanels();
|
|
29043
|
+
savePreferences();
|
|
29044
|
+
});
|
|
29045
|
+
if (codeHandle) {
|
|
29046
|
+
const saved = preferences.codeWidth;
|
|
29047
|
+
const width2 = typeof saved === "number" && Number.isFinite(saved) && saved >= 200 ? saved : 420;
|
|
29048
|
+
state.setItem("preferredCodeWidth", width2);
|
|
29049
|
+
setCodeWidth(width2);
|
|
29050
|
+
listen(codeHandle, "keydown", (event) => {
|
|
29051
|
+
const current = state.getItem("codeWidth");
|
|
29052
|
+
const value = event.key === "ArrowLeft" ? current + 10 : event.key === "ArrowRight" ? current - 10 : event.key === "Home" ? 200 : event.key === "End" ? codeMaximum() : null;
|
|
29053
|
+
if (value == null) return;
|
|
29054
|
+
event.preventDefault();
|
|
29055
|
+
setCodeWidth(value, true);
|
|
29056
|
+
});
|
|
29057
|
+
listen(codeHandle, "pointerdown", (event) => beginDrag(
|
|
29058
|
+
codeHandle,
|
|
29059
|
+
event,
|
|
29060
|
+
(x) => setCodeWidth(Math.round(shell.getBoundingClientRect().right - x), true)
|
|
29061
|
+
));
|
|
29062
|
+
listen(codeHandle, "lostpointercapture", () => {
|
|
29063
|
+
if (drag?.handle === codeHandle) stopDrag();
|
|
29064
|
+
});
|
|
29065
|
+
listen(window2, "resize", () => setCodeWidth(state.getItem("preferredCodeWidth")));
|
|
29066
|
+
}
|
|
28011
29067
|
listen(sidebarHandle, "keydown", (event) => {
|
|
28012
29068
|
const current = state.getItem("sidebarWidth");
|
|
28013
29069
|
const value = event.key === "ArrowLeft" ? current - 10 : event.key === "ArrowRight" ? current + 10 : event.key === "Home" ? 120 : event.key === "End" ? sidebarMaximum() : null;
|
|
@@ -28030,6 +29086,7 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
28030
29086
|
key,
|
|
28031
29087
|
tab,
|
|
28032
29088
|
panel: byId(`panel-${key}`),
|
|
29089
|
+
code: byId(`codepane-${key}`),
|
|
28033
29090
|
open: key === "intro" ? null : byId(`open-${key}`)
|
|
28034
29091
|
};
|
|
28035
29092
|
entries.set(key, entry);
|
|
@@ -28054,25 +29111,7 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
28054
29111
|
prepareEntry(entry, { byId, node, set, listen });
|
|
28055
29112
|
if (entry.panel.classList.contains("index-category")) continue;
|
|
28056
29113
|
entry.frame = byId(`frame-${key}`);
|
|
28057
|
-
entry.split = byId(`split-${key}`);
|
|
28058
|
-
entry.handle = byId(`divider-${key}`);
|
|
28059
|
-
if (entry.handle) state.setItem(`ratio.${key}`, Number(entry.handle.getAttribute("aria-valuenow")));
|
|
28060
29114
|
listen(entry.frame, "load", () => send(entry.frame));
|
|
28061
|
-
if (!entry.handle) continue;
|
|
28062
|
-
listen(entry.handle, "keydown", (event) => {
|
|
28063
|
-
const current = state.getItem(`ratio.${key}`);
|
|
28064
|
-
const value = event.key === "ArrowLeft" ? current - 5 : event.key === "ArrowRight" ? current + 5 : event.key === "Home" ? 20 : event.key === "End" ? 80 : null;
|
|
28065
|
-
if (value == null) return;
|
|
28066
|
-
event.preventDefault();
|
|
28067
|
-
setRatio(entry, value);
|
|
28068
|
-
});
|
|
28069
|
-
listen(entry.handle, "pointerdown", (event) => beginDrag(entry.handle, event, (x) => {
|
|
28070
|
-
const bounds = entry.split.getBoundingClientRect();
|
|
28071
|
-
if (bounds.width > 0) setRatio(entry, Math.round((x - bounds.left) * 100 / bounds.width));
|
|
28072
|
-
}));
|
|
28073
|
-
listen(entry.handle, "lostpointercapture", () => {
|
|
28074
|
-
if (drag?.handle === entry.handle) stopDrag();
|
|
28075
|
-
});
|
|
28076
29115
|
}
|
|
28077
29116
|
listen(document, "pointermove", (event) => {
|
|
28078
29117
|
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
@@ -28091,7 +29130,7 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
28091
29130
|
}
|
|
28092
29131
|
});
|
|
28093
29132
|
listen(appearance, "change", () => {
|
|
28094
|
-
if (!APPEARANCES.has(appearance?.value ?? "compact")) throw new Error("
|
|
29133
|
+
if (!APPEARANCES.has(appearance?.value ?? "compact")) throw new Error("Unknown index appearance");
|
|
28095
29134
|
state.setItem("appearance", appearance?.value ?? "compact");
|
|
28096
29135
|
set(appearance, { value: appearance?.value ?? "compact" });
|
|
28097
29136
|
for (const option of appearance.options) set(option, { selected: option.value === (appearance?.value ?? "compact") });
|
|
@@ -28117,6 +29156,7 @@ function mountIndexPage(renderer, root, onSelection = () => {
|
|
|
28117
29156
|
}
|
|
28118
29157
|
});
|
|
28119
29158
|
applyTheme();
|
|
29159
|
+
updatePanels();
|
|
28120
29160
|
updateInspector();
|
|
28121
29161
|
renderer.onDispose(root, dispose);
|
|
28122
29162
|
} catch (error) {
|