@gramlot/gramlot 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/editors.js +116527 -0
- package/dist/components/inputs.js +24507 -0
- package/dist/components/layout.js +1402 -0
- package/dist/components/tree.js +24538 -0
- package/dist/components/typst.js +4 -0
- package/dist/gramlot.js +1442 -625
- package/dist/gramlot.min.js +27 -405
- package/dist/runtime-notices.json +208 -0
- package/dist/typst-worker-source.js +4 -0
- package/package.json +36 -3
- package/src/binding/hooks.js +14 -0
- package/src/binding/providers.js +4 -0
- package/src/binding/remote-resolver.js +52 -0
- package/src/binding/remote.js +2 -0
- package/src/binding/router.js +11 -4
- package/src/binding/rpc-resolver.js +14 -93
- package/src/binding/runtime.js +10 -4
- package/src/components/bases.js +1 -0
- package/src/components/border-container.js +46 -23
- package/src/components/buttons.js +3 -0
- package/src/components/choice-editor.js +17 -3
- package/src/components/choices.js +3 -2
- package/src/components/code-mirror-engine.js +91 -0
- package/src/components/code-mirror.js +88 -0
- package/src/components/editor-options.d.ts +9 -0
- package/src/components/editor-options.js +21 -0
- package/src/components/editors.js +10 -0
- package/src/components/html-document.js +56 -0
- package/src/components/html-editor.js +68 -0
- package/src/components/html-preview.js +33 -0
- package/src/components/inputs.js +2 -2
- package/src/components/jodit-engine.js +89 -0
- package/src/components/markdown-codec.js +35 -0
- package/src/components/markdown-document.js +14 -0
- package/src/components/markdown-editor.js +68 -0
- package/src/components/prose-mirror-engine.js +65 -0
- package/src/components/registry.js +6 -4
- package/src/components/tree.js +350 -0
- package/src/components/typst-client.js +38 -0
- package/src/components/typst-preview.js +88 -0
- package/src/components/typst-worker.js +49 -0
- package/src/components/typst.js +4 -0
- package/src/filesystem.d.ts +22 -0
- package/src/filesystem.js +122 -0
- package/src/ide-documents.js +153 -0
- package/src/ide-runtime.d.ts +18 -0
- package/src/ide-runtime.js +238 -0
- package/src/index-page-runtime.d.ts +7 -8
- package/src/index-page-runtime.js +100 -396
- package/src/index.d.ts +7 -1
- package/src/index.js +5 -1
- package/src/navigation-resolver.d.ts +6 -0
- package/src/navigation-resolver.js +60 -0
- package/src/renderer/attributes.js +2 -1
- package/src/renderer/drag-drop-policy.js +48 -0
- package/src/renderer/drag-drop.js +213 -0
- package/src/renderer/drag-preparation.js +33 -0
- package/src/renderer/gramlot-renderer.d.ts +18 -0
- package/src/renderer/gramlot-renderer.js +41 -2
- package/src/server/frame-page.d.ts +12 -0
- package/src/server/frame-page.js +23 -0
- package/src/server/gramlot-server.js +2 -1
- package/src/server/index-page.d.ts +10 -14
- package/src/server/index-page.js +26 -95
- package/src/server/page.d.ts +7 -0
- package/src/server/page.js +5 -0
- package/src/view/button.js +2 -1
- package/src/view/controls.js +7 -11
- package/src/view/events.js +4 -8
- package/src/view/html.js +6 -1
- package/tools/gramlot-tools-inspector.js +16 -9
package/dist/gramlot.js
CHANGED
|
@@ -22157,7 +22157,7 @@ function annotation2(parameter) {
|
|
|
22157
22157
|
});
|
|
22158
22158
|
return alternatives.length === 1 ? alternatives[0] : { kind: "union", items: alternatives };
|
|
22159
22159
|
}
|
|
22160
|
-
function defineComponent({ name, tag: tag2, base, mixins = [], parameters: parameters2 = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, implementation }) {
|
|
22160
|
+
function defineComponent({ name, tag: tag2, base, mixins = [], parameters: parameters2 = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, bagStore = false, dragSource = false, implementation }) {
|
|
22161
22161
|
webcomponentCode({ code: tag2 });
|
|
22162
22162
|
if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError("Invalid component authoring name");
|
|
22163
22163
|
const effective = { ...base.parameters };
|
|
@@ -22177,10 +22177,12 @@ function defineComponent({ name, tag: tag2, base, mixins = [], parameters: param
|
|
|
22177
22177
|
presentationDefaults: Object.freeze([...presentationDefaults]),
|
|
22178
22178
|
dataScope,
|
|
22179
22179
|
command,
|
|
22180
|
+
bagStore,
|
|
22180
22181
|
mixins: Object.freeze([...mixins]),
|
|
22181
22182
|
parameters: freeze(structuredClone(effective)),
|
|
22182
22183
|
childParameters: freeze(structuredClone(childParameters)),
|
|
22183
22184
|
sourceContext,
|
|
22185
|
+
dragSource,
|
|
22184
22186
|
implementation
|
|
22185
22187
|
});
|
|
22186
22188
|
}
|
|
@@ -22239,7 +22241,9 @@ var ComponentCollection = class {
|
|
|
22239
22241
|
dataScope: component.dataScope,
|
|
22240
22242
|
command: component.command,
|
|
22241
22243
|
...Object.keys(component.childParameters).length ? { childParameters: structuredClone(component.childParameters) } : {},
|
|
22242
|
-
...component.sourceContext ? { sourceContext: true } : {}
|
|
22244
|
+
...component.sourceContext ? { sourceContext: true } : {},
|
|
22245
|
+
...component.dragSource ? { dragSource: true } : {},
|
|
22246
|
+
...component.bagStore ? { bagStore: true } : {}
|
|
22243
22247
|
} }
|
|
22244
22248
|
}]))
|
|
22245
22249
|
};
|
|
@@ -22271,10 +22275,11 @@ function projectParameters(element, attrs) {
|
|
|
22271
22275
|
}
|
|
22272
22276
|
|
|
22273
22277
|
// src/components/choices.js
|
|
22274
|
-
function parseChoices(values) {
|
|
22278
|
+
function parseChoices(values, separator = ",") {
|
|
22279
|
+
if (typeof separator !== "string" || !separator) throw new TypeError("separator must be a nonempty string");
|
|
22275
22280
|
if (values === "") return [];
|
|
22276
22281
|
const ids = /* @__PURE__ */ new Set();
|
|
22277
|
-
return values.split(
|
|
22282
|
+
return values.split(separator).map((item) => {
|
|
22278
22283
|
const colon = item.indexOf(":");
|
|
22279
22284
|
const id = colon < 0 ? item : item.slice(0, colon);
|
|
22280
22285
|
const caption = colon < 0 ? item : item.slice(colon + 1);
|
|
@@ -22319,6 +22324,9 @@ function controlElement(HTMLElement) {
|
|
|
22319
22324
|
}
|
|
22320
22325
|
releaseControl() {
|
|
22321
22326
|
}
|
|
22327
|
+
get liveWrites() {
|
|
22328
|
+
return this.control.localName === "textarea" || ["text", "password", "range", "color"].includes(this.control.type);
|
|
22329
|
+
}
|
|
22322
22330
|
validateCandidate(value, accept) {
|
|
22323
22331
|
accept(value);
|
|
22324
22332
|
return { ok: true, value, isCurrent: () => this.pageContext.isActive() };
|
|
@@ -22525,6 +22533,9 @@ function Command(HTMLElement) {
|
|
|
22525
22533
|
min-height:max(var(--gramlot-field-height,28px),var(--gramlot-touch-target,0px));
|
|
22526
22534
|
padding:var(--gramlot-button-padding,.25em .65em);cursor:pointer}
|
|
22527
22535
|
button:hover:not(:disabled){background:var(--gramlot-button-hover,var(--gramlot-field-readonly-background,#eee))}
|
|
22536
|
+
:host(.button--quiet) button{background:transparent;color:var(--gramlot-action,CanvasText);border-color:transparent}
|
|
22537
|
+
:host(.button--quiet) button:hover:not(:disabled){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action-hover,CanvasText);border-color:transparent}
|
|
22538
|
+
button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:2px}
|
|
22528
22539
|
button:disabled{opacity:.55;cursor:not-allowed} .icon:empty{display:none}
|
|
22529
22540
|
.led{display:inline-block;width:.6em;height:.6em;border-radius:50%;background:var(--gramlot-button-led-off,#888)}
|
|
22530
22541
|
[aria-pressed=true] .led{background:var(--gramlot-button-led-on,#2b9a46)}
|
|
@@ -22962,7 +22973,18 @@ var BINDING_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
22962
22973
|
"_cachedRemote",
|
|
22963
22974
|
"_onRemote",
|
|
22964
22975
|
"_onCalling",
|
|
22965
|
-
"onClose"
|
|
22976
|
+
"onClose",
|
|
22977
|
+
"onDrag",
|
|
22978
|
+
"onDrop",
|
|
22979
|
+
"dropTargetCb",
|
|
22980
|
+
"onDragEnd",
|
|
22981
|
+
"dropTarget",
|
|
22982
|
+
"dropTypes",
|
|
22983
|
+
"dragTags",
|
|
22984
|
+
"dropTags",
|
|
22985
|
+
"effectAllowed",
|
|
22986
|
+
"dropEffect",
|
|
22987
|
+
"dragClass"
|
|
22966
22988
|
]);
|
|
22967
22989
|
var BINDING_ATTRIBUTE_PREFIXES = ["default_", "attr_", "fire_", "connect_on", "subscribe_", "selfsubscribe_", "formsubscribe_", "remote_"];
|
|
22968
22990
|
var NATIVE_ATTRIBUTES = {
|
|
@@ -24505,6 +24527,19 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
24505
24527
|
}
|
|
24506
24528
|
};
|
|
24507
24529
|
|
|
24530
|
+
// src/binding/hooks.js
|
|
24531
|
+
function isLogicMethod(handler) {
|
|
24532
|
+
return typeof handler === "string" && !["null", "true", "false"].includes(handler) && /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(handler);
|
|
24533
|
+
}
|
|
24534
|
+
function callLogic(runtime, node, methodName, context) {
|
|
24535
|
+
const { group, method } = runtime.logicRegistry.resolve(methodName, node);
|
|
24536
|
+
return method.call(group, node, context);
|
|
24537
|
+
}
|
|
24538
|
+
function invokeHook(runtime, node, attribute, handler, context, inlineNames = Object.keys(context)) {
|
|
24539
|
+
if (isLogicMethod(handler)) return callLogic(runtime, node, handler, context);
|
|
24540
|
+
return runtime.inlineCompiler.compile(node, attribute, handler, inlineNames)(context);
|
|
24541
|
+
}
|
|
24542
|
+
|
|
24508
24543
|
// src/view/controls.js
|
|
24509
24544
|
var CONTROL_TAGS = /* @__PURE__ */ new Set(["input", "select", "textarea"]);
|
|
24510
24545
|
var REBUILD_ATTRIBUTES = ["type", "multiple", "group"];
|
|
@@ -24712,8 +24747,8 @@ var ComponentControl = class extends ControlAdapter {
|
|
|
24712
24747
|
}
|
|
24713
24748
|
get writeEvent() {
|
|
24714
24749
|
if (this.element.commitOnChange) return "change";
|
|
24715
|
-
const
|
|
24716
|
-
return
|
|
24750
|
+
const live = this.resolved.live ?? this.element.parameters.live;
|
|
24751
|
+
return live && this.element.liveWrites ? "input" : "change";
|
|
24717
24752
|
}
|
|
24718
24753
|
read() {
|
|
24719
24754
|
return this.element.readControlValue();
|
|
@@ -25025,16 +25060,13 @@ var INPUT_CONTROLS = {
|
|
|
25025
25060
|
function componentContext(adapter) {
|
|
25026
25061
|
const { binding, node } = adapter, app = binding.runtime.gramlot;
|
|
25027
25062
|
const invoke = (attribute, code, keywords, expression = false) => {
|
|
25028
|
-
if (!expression
|
|
25029
|
-
const { group, method } = app.src.logicRegistry.resolve(code, node);
|
|
25030
|
-
return method.call(group, node, keywords);
|
|
25031
|
-
}
|
|
25063
|
+
if (!expression) return invokeHook(binding.runtime, node, attribute, code, keywords);
|
|
25032
25064
|
return binding.runtime.inlineCompiler.compile(
|
|
25033
25065
|
node,
|
|
25034
25066
|
attribute,
|
|
25035
25067
|
code,
|
|
25036
25068
|
Object.keys(keywords),
|
|
25037
|
-
|
|
25069
|
+
`return (${code});`
|
|
25038
25070
|
)(keywords);
|
|
25039
25071
|
};
|
|
25040
25072
|
return {
|
|
@@ -25043,11 +25075,9 @@ function componentContext(adapter) {
|
|
|
25043
25075
|
createDecimal,
|
|
25044
25076
|
isDecimal: isDecimal2,
|
|
25045
25077
|
getDecimalLibrary,
|
|
25078
|
+
publish: (topic, payload) => node.publish(topic, payload),
|
|
25046
25079
|
isActive: () => !binding.closed,
|
|
25047
|
-
callLogic: (name, keywords) =>
|
|
25048
|
-
const { group, method } = app.src.logicRegistry.resolve(name, node);
|
|
25049
|
-
return method.call(group, node, keywords);
|
|
25050
|
-
},
|
|
25080
|
+
callLogic: (name, keywords) => callLogic(binding.runtime, node, name, keywords),
|
|
25051
25081
|
format: (value, options) => app.format(value, options),
|
|
25052
25082
|
invoke,
|
|
25053
25083
|
remote: (method, keywords, signal) => app.rpc.call("data", method, keywords, { signal }),
|
|
@@ -25137,8 +25167,9 @@ function domPropertyName(name) {
|
|
|
25137
25167
|
return PROPERTY_NAMES.get(camel.toLowerCase()) ?? camel;
|
|
25138
25168
|
}
|
|
25139
25169
|
var HtmlElement = class {
|
|
25140
|
-
constructor({ metadataAttributes = [], invokeScript = null } = {}) {
|
|
25170
|
+
constructor({ metadataAttributes = [], invokeScript = null, callLogic: callLogic2 = null } = {}) {
|
|
25141
25171
|
this.invokeScript = invokeScript;
|
|
25172
|
+
this.callLogic = callLogic2;
|
|
25142
25173
|
this.metadataAttributes = /* @__PURE__ */ new Set([...META_ATTRS, "_text", ...metadataAttributes]);
|
|
25143
25174
|
}
|
|
25144
25175
|
definition(node) {
|
|
@@ -25186,7 +25217,8 @@ var HtmlElement = class {
|
|
|
25186
25217
|
if (meta.gramlot_component?.sourceContext) {
|
|
25187
25218
|
element.setSourceContext({
|
|
25188
25219
|
publish: (topic, payload) => node.publish(topic, payload),
|
|
25189
|
-
writeParameter: (name, value) => this.writeParameter(node, name, value)
|
|
25220
|
+
writeParameter: (name, value) => this.writeParameter(node, name, value),
|
|
25221
|
+
callLogic: (name, keywords) => this.callLogic(node, name, keywords)
|
|
25190
25222
|
});
|
|
25191
25223
|
}
|
|
25192
25224
|
const text = document.createTextNode(this.text(node));
|
|
@@ -25245,6 +25277,9 @@ var HtmlElement = class {
|
|
|
25245
25277
|
});
|
|
25246
25278
|
}
|
|
25247
25279
|
if (this.definition(node).meta.gramlot_component) {
|
|
25280
|
+
if (this.definition(node).meta.gramlot_component.bagStore) {
|
|
25281
|
+
element.setStoreBag(node.getRelativeData(node.getAttr("storepath")));
|
|
25282
|
+
}
|
|
25248
25283
|
attrs = element.projectAttributes(attrs, adapt);
|
|
25249
25284
|
}
|
|
25250
25285
|
attrs = Object.fromEntries(sourceAttributeItems({ ...attrs, ...renderAttributes }));
|
|
@@ -25432,7 +25467,7 @@ var ButtonBinding = class _ButtonBinding {
|
|
|
25432
25467
|
if (this.binding.closed || this.element.disabled || result === null) return;
|
|
25433
25468
|
const values = { ...read(), ...result };
|
|
25434
25469
|
if (result) values._askResult = result;
|
|
25435
|
-
this.binding.runtime
|
|
25470
|
+
invokeHook(this.binding.runtime, node, "action", node.getAttr("action"), values);
|
|
25436
25471
|
};
|
|
25437
25472
|
const ask = node.getAttr("ask");
|
|
25438
25473
|
const askDialog = this.binding.runtime.askDialog;
|
|
@@ -25463,7 +25498,6 @@ function eventToString(event) {
|
|
|
25463
25498
|
|
|
25464
25499
|
// src/view/events.js
|
|
25465
25500
|
var PREFIX = "connect_on";
|
|
25466
|
-
var NAMED_LOGIC = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/;
|
|
25467
25501
|
var NativeEventBinding = class {
|
|
25468
25502
|
#binding;
|
|
25469
25503
|
#record;
|
|
@@ -25511,11 +25545,7 @@ var NativeEventBinding = class {
|
|
|
25511
25545
|
if (this.binding.closed) return;
|
|
25512
25546
|
const node = this.node;
|
|
25513
25547
|
const runtime = this.binding.runtime;
|
|
25514
|
-
if (
|
|
25515
|
-
const { group, method } = runtime.logicRegistry.resolve(this.handler, node);
|
|
25516
|
-
method.call(group, node, event);
|
|
25517
|
-
return;
|
|
25518
|
-
}
|
|
25548
|
+
if (isLogicMethod(this.handler)) return callLogic(runtime, node, this.handler, event);
|
|
25519
25549
|
runtime.inlineCompiler.compile(node, this.attribute, this.handler, ["event"])({ event });
|
|
25520
25550
|
}
|
|
25521
25551
|
};
|
|
@@ -25600,12 +25630,14 @@ var DataRegistration = class {
|
|
|
25600
25630
|
#recipient;
|
|
25601
25631
|
#order;
|
|
25602
25632
|
#active = true;
|
|
25603
|
-
|
|
25633
|
+
#subtree;
|
|
25634
|
+
constructor(router, { path, attr, recipient, order, subtree = false }) {
|
|
25604
25635
|
this.#router = router;
|
|
25605
25636
|
this.#path = path;
|
|
25606
25637
|
this.#attr = attr;
|
|
25607
25638
|
this.#recipient = recipient;
|
|
25608
25639
|
this.#order = order;
|
|
25640
|
+
this.#subtree = subtree;
|
|
25609
25641
|
}
|
|
25610
25642
|
get router() {
|
|
25611
25643
|
return this.#router;
|
|
@@ -25619,6 +25651,10 @@ var DataRegistration = class {
|
|
|
25619
25651
|
get recipient() {
|
|
25620
25652
|
return this.#recipient;
|
|
25621
25653
|
}
|
|
25654
|
+
/** Store registration: structural, value and attribute events throughout the subtree. */
|
|
25655
|
+
get subtree() {
|
|
25656
|
+
return this.#subtree;
|
|
25657
|
+
}
|
|
25622
25658
|
get active() {
|
|
25623
25659
|
return this.#active;
|
|
25624
25660
|
}
|
|
@@ -25662,8 +25698,10 @@ var DataRouter = class {
|
|
|
25662
25698
|
get size() {
|
|
25663
25699
|
return this.#size;
|
|
25664
25700
|
}
|
|
25665
|
-
/** Register
|
|
25666
|
-
|
|
25701
|
+
/** Register on an absolute Data path, optionally on an attribute.
|
|
25702
|
+
* `subtree` includes descendant attribute events for Bag-backed components.
|
|
25703
|
+
*/
|
|
25704
|
+
register({ path, attr = null, recipient, subtree = false }) {
|
|
25667
25705
|
if (typeof path !== "string" || path === "") throw new TypeError(`A Data registration requires a path: ${path}`);
|
|
25668
25706
|
let route = this.#root;
|
|
25669
25707
|
for (const segment of path.split(".")) {
|
|
@@ -25675,7 +25713,7 @@ var DataRouter = class {
|
|
|
25675
25713
|
route = next;
|
|
25676
25714
|
}
|
|
25677
25715
|
this.#order += 1;
|
|
25678
|
-
const registration = new DataRegistration(this, { path, attr, recipient, order: this.#order });
|
|
25716
|
+
const registration = new DataRegistration(this, { path, attr, recipient, order: this.#order, subtree });
|
|
25679
25717
|
route.registrations.add(registration);
|
|
25680
25718
|
this.#routes.set(registration, route);
|
|
25681
25719
|
this.#size += 1;
|
|
@@ -25757,6 +25795,7 @@ var DataRouter = class {
|
|
|
25757
25795
|
*/
|
|
25758
25796
|
#accepts(registration, level, event) {
|
|
25759
25797
|
const { evt } = event;
|
|
25798
|
+
if (registration.subtree) return level !== "container" || evt !== "upd_attrs";
|
|
25760
25799
|
if (registration.attr === null) {
|
|
25761
25800
|
if (evt === "upd_attrs") return false;
|
|
25762
25801
|
return !(level === "child" && event.fired);
|
|
@@ -25945,65 +25984,24 @@ function branchNodes(branch) {
|
|
|
25945
25984
|
return nodes;
|
|
25946
25985
|
}
|
|
25947
25986
|
|
|
25948
|
-
// src/binding/
|
|
25949
|
-
var
|
|
25987
|
+
// src/binding/remote-resolver.js
|
|
25988
|
+
var RemoteResolver = class extends BagResolver {
|
|
25950
25989
|
static classKwargs = { ...BagResolver.classKwargs, asBag: false };
|
|
25951
|
-
|
|
25952
|
-
...BagResolver.internalParams,
|
|
25953
|
-
"binding",
|
|
25954
|
-
"method",
|
|
25955
|
-
"params",
|
|
25956
|
-
"onCalling",
|
|
25957
|
-
"onError",
|
|
25958
|
-
"sync"
|
|
25959
|
-
]);
|
|
25960
|
-
constructor({ binding, method, params, cacheTime, onCalling = null, onError, sync = false }) {
|
|
25990
|
+
constructor({ cacheTime, onError }) {
|
|
25961
25991
|
super({ cacheTime: cacheTime ?? -1 });
|
|
25962
|
-
this.binding = binding;
|
|
25963
|
-
this.sync = sync;
|
|
25964
|
-
this.method = method;
|
|
25965
|
-
this.params = params;
|
|
25966
|
-
this.onCalling = onCalling;
|
|
25967
25992
|
this.onError = onError;
|
|
25968
25993
|
this.loading = null;
|
|
25969
25994
|
this.loaded = false;
|
|
25970
25995
|
this.writing = false;
|
|
25971
25996
|
}
|
|
25972
|
-
|
|
25973
|
-
|
|
25974
|
-
|
|
25975
|
-
* a read during a load or its write, returns the current value.
|
|
25976
|
-
*/
|
|
25977
|
-
resolve(options = {}) {
|
|
25978
|
-
const { static: isStatic = false } = options;
|
|
25979
|
-
if (isStatic || this.loading || this.writing) return this.cachedValue;
|
|
25980
|
-
if (!this.sync) {
|
|
25981
|
-
if (this.expired) this.refresh();
|
|
25982
|
-
return this.cachedValue;
|
|
25983
|
-
}
|
|
25984
|
-
if (this.expired && !this.binding.node.requests.calling(this.onCalling)) return this.cachedValue;
|
|
25985
|
-
return super.resolve(options);
|
|
25986
|
-
}
|
|
25987
|
-
/** The synchronous call of a `sync` read: BagResolver `resolve` stores the value it returns. */
|
|
25988
|
-
load() {
|
|
25989
|
-
let value;
|
|
25990
|
-
try {
|
|
25991
|
-
value = this.binding.callSync("data", this.method, this.params);
|
|
25992
|
-
} catch (error) {
|
|
25993
|
-
this.onError(error);
|
|
25994
|
-
}
|
|
25995
|
-
this.loaded = true;
|
|
25996
|
-
return value;
|
|
25997
|
+
resolve({ static: isStatic = false } = {}) {
|
|
25998
|
+
if (!isStatic && !this.closed && !this.loading && !this.writing && this.expired) this.refresh();
|
|
25999
|
+
return this.cachedValue;
|
|
25997
26000
|
}
|
|
25998
|
-
/**
|
|
25999
|
-
* Start a load and write its value on the node, with the Data event unless `cacheTime` is 0; returns
|
|
26000
|
-
* `loading`, which settles with the written value, or undefined when nothing was written. A false
|
|
26001
|
-
* `_onCalling` starts no load and returns null.
|
|
26002
|
-
*/
|
|
26003
26001
|
refresh() {
|
|
26004
|
-
|
|
26005
|
-
|
|
26006
|
-
|
|
26002
|
+
if (this.closed) return null;
|
|
26003
|
+
const loading = this.startLoad((request) => this.#load(request));
|
|
26004
|
+
if (loading === null) return null;
|
|
26007
26005
|
const settle = () => {
|
|
26008
26006
|
if (this.loading === loading) this.loading = null;
|
|
26009
26007
|
};
|
|
@@ -26014,10 +26012,12 @@ var RpcResolver = class extends BagResolver {
|
|
|
26014
26012
|
});
|
|
26015
26013
|
return loading;
|
|
26016
26014
|
}
|
|
26017
|
-
|
|
26018
|
-
|
|
26019
|
-
|
|
26020
|
-
|
|
26015
|
+
resolveSync(options) {
|
|
26016
|
+
return super.resolve(options);
|
|
26017
|
+
}
|
|
26018
|
+
prepareValue(value) {
|
|
26019
|
+
return value;
|
|
26020
|
+
}
|
|
26021
26021
|
#fingerprint() {
|
|
26022
26022
|
const kwargs = { ...this._kw };
|
|
26023
26023
|
for (const [name, value] of Object.entries(this.node?.attr ?? {})) {
|
|
@@ -26025,13 +26025,12 @@ var RpcResolver = class extends BagResolver {
|
|
|
26025
26025
|
}
|
|
26026
26026
|
return this._computeEffectiveFingerprint(kwargs);
|
|
26027
26027
|
}
|
|
26028
|
-
/** The asynchronous call of the endpoint with the params given at construction; the read kwargs are not sent. */
|
|
26029
26028
|
async #load(request) {
|
|
26030
|
-
|
|
26031
|
-
if (binding.closed) return void 0;
|
|
26029
|
+
if (this.closed) return void 0;
|
|
26032
26030
|
const fingerprint = this.#fingerprint();
|
|
26033
|
-
const
|
|
26034
|
-
if (
|
|
26031
|
+
const received = await this.loadAsync(request);
|
|
26032
|
+
if (this.closed || request.ignored) return void 0;
|
|
26033
|
+
const value = this.prepareValue(received);
|
|
26035
26034
|
this._lastUpdate = Date.now();
|
|
26036
26035
|
this._lastEffectiveFingerprint = fingerprint;
|
|
26037
26036
|
this.loaded = true;
|
|
@@ -26046,6 +26045,46 @@ var RpcResolver = class extends BagResolver {
|
|
|
26046
26045
|
}
|
|
26047
26046
|
};
|
|
26048
26047
|
|
|
26048
|
+
// src/binding/rpc-resolver.js
|
|
26049
|
+
var RpcResolver = class extends RemoteResolver {
|
|
26050
|
+
static internalParams = /* @__PURE__ */ new Set([...RemoteResolver.internalParams, "binding", "method", "params", "onCalling", "onError", "sync"]);
|
|
26051
|
+
constructor({ binding, method, params, cacheTime, onCalling = null, onError, sync = false }) {
|
|
26052
|
+
super({ cacheTime, onError });
|
|
26053
|
+
this.binding = binding;
|
|
26054
|
+
this.sync = sync;
|
|
26055
|
+
this.method = method;
|
|
26056
|
+
this.params = params;
|
|
26057
|
+
this.onCalling = onCalling;
|
|
26058
|
+
}
|
|
26059
|
+
get closed() {
|
|
26060
|
+
return this.binding.closed;
|
|
26061
|
+
}
|
|
26062
|
+
resolve(options = {}) {
|
|
26063
|
+
if (!this.sync) return super.resolve(options);
|
|
26064
|
+
if (options.static || this.loading || this.writing) return this.cachedValue;
|
|
26065
|
+
if (this.expired && !this.binding.node.requests.calling(this.onCalling)) return this.cachedValue;
|
|
26066
|
+
return super.resolveSync(options);
|
|
26067
|
+
}
|
|
26068
|
+
load() {
|
|
26069
|
+
let value;
|
|
26070
|
+
try {
|
|
26071
|
+
value = this.binding.callSync("data", this.method, this.params);
|
|
26072
|
+
} catch (error) {
|
|
26073
|
+
this.onError(error);
|
|
26074
|
+
}
|
|
26075
|
+
this.loaded = true;
|
|
26076
|
+
return value;
|
|
26077
|
+
}
|
|
26078
|
+
startLoad(perform) {
|
|
26079
|
+
const requests = this.binding.node.requests;
|
|
26080
|
+
if (!requests.calling(this.onCalling)) return null;
|
|
26081
|
+
return requests.submit(this.method, this.params, perform);
|
|
26082
|
+
}
|
|
26083
|
+
loadAsync(request) {
|
|
26084
|
+
return this.binding.call("data", request);
|
|
26085
|
+
}
|
|
26086
|
+
};
|
|
26087
|
+
|
|
26049
26088
|
// src/binding/providers.js
|
|
26050
26089
|
var CONTROL_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
26051
26090
|
"destination_path",
|
|
@@ -26309,6 +26348,9 @@ var Provider = class {
|
|
|
26309
26348
|
...CLICK_FIELDS,
|
|
26310
26349
|
...Object.keys(authorArguments(kwargs))
|
|
26311
26350
|
];
|
|
26351
|
+
if (["_onCalling", "_onResult", "_onError", "_ask_onCancel"].includes(attr)) {
|
|
26352
|
+
return invokeHook(this.binding.runtime, this.node, attr, code, { ...kwargs, _kwargs: kwargs }, names);
|
|
26353
|
+
}
|
|
26312
26354
|
return this.binding.runtime.inlineCompiler.compile(this.node, attr, code, names, source)({ ...kwargs, _kwargs: kwargs });
|
|
26313
26355
|
}
|
|
26314
26356
|
/**
|
|
@@ -26732,6 +26774,7 @@ var RemoteBinding = class {
|
|
|
26732
26774
|
return attrs[name] ?? null;
|
|
26733
26775
|
}
|
|
26734
26776
|
#inline(attr, code, source, params) {
|
|
26777
|
+
if (attr === "_onRemote") return invokeHook(this.binding.runtime, this.node, attr, code, params);
|
|
26735
26778
|
return this.binding.runtime.inlineCompiler.compile(this.node, attr, code, Object.keys(params), source)(params);
|
|
26736
26779
|
}
|
|
26737
26780
|
};
|
|
@@ -27293,6 +27336,14 @@ var NodeBinding = class {
|
|
|
27293
27336
|
if (dataElement && !PROVIDERS[node.nodeTag]) return;
|
|
27294
27337
|
if (!dataElement && typeof node.getAttr("remote") === "string") this.#remote ??= new RemoteBinding(this);
|
|
27295
27338
|
const remoteDependencies = /* @__PURE__ */ new Set();
|
|
27339
|
+
if (node._getMeta("gramlot_component")?.bagStore) {
|
|
27340
|
+
const storepath = node.getAttr("storepath");
|
|
27341
|
+
if (typeof storepath !== "string" || !storepath || /^[\^=]/.test(storepath) || storepath.includes("?")) {
|
|
27342
|
+
throw new TypeError("storepath requires a plain Bag data path");
|
|
27343
|
+
}
|
|
27344
|
+
const path = node.absDatapath(storepath);
|
|
27345
|
+
this.#registrations.push(this.runtime.router.register({ path, recipient: this, subtree: true }));
|
|
27346
|
+
}
|
|
27296
27347
|
const timingDependencies = this.remote ? pointerDependencies(node, node.getAttr("_timing")) : /* @__PURE__ */ new Set();
|
|
27297
27348
|
if (this.remote) for (const [name, raw] of Object.entries(node.getAttr())) {
|
|
27298
27349
|
if (name.startsWith("remote_")) for (const dependency of pointerDependencies(node, raw)) remoteDependencies.add(dependency);
|
|
@@ -27324,10 +27375,7 @@ var NodeBinding = class {
|
|
|
27324
27375
|
if (typeof handler !== "string" || !handler) throw new TypeError(`${name} requires a handler`);
|
|
27325
27376
|
return (payload) => {
|
|
27326
27377
|
if (this.closed) return;
|
|
27327
|
-
if (
|
|
27328
|
-
const { group, method } = this.runtime.logicRegistry.resolve(handler, node);
|
|
27329
|
-
return method.call(group, node, payload);
|
|
27330
|
-
}
|
|
27378
|
+
if (isLogicMethod(handler)) return callLogic(this.runtime, node, handler, payload);
|
|
27331
27379
|
const [, attrs] = node.rootBuilder.runtimeValues(node);
|
|
27332
27380
|
const authored = Object.fromEntries(Object.entries(attrs).filter(([key]) => !key.startsWith("subscribe_") && !key.startsWith("selfsubscribe_")));
|
|
27333
27381
|
const values = { ...this.runtime.renderer.references.resolveArguments(authored), p_0: payload };
|
|
@@ -27420,6 +27468,320 @@ var NodeBinding = class {
|
|
|
27420
27468
|
}
|
|
27421
27469
|
};
|
|
27422
27470
|
|
|
27471
|
+
// src/renderer/drag-preparation.js
|
|
27472
|
+
var DragPreparation = class {
|
|
27473
|
+
constructor(renderer) {
|
|
27474
|
+
this.renderer = renderer;
|
|
27475
|
+
}
|
|
27476
|
+
prepare(sourceNode, event) {
|
|
27477
|
+
const record2 = this.renderer.records.get(sourceNode);
|
|
27478
|
+
if (!record2 || record2.resolved.draggable !== true) return null;
|
|
27479
|
+
const context = sourceNode._getMeta("gramlot_component")?.dragSource ? record2.element.getDragContext(event) : { dragValues: {}, item: void 0, path: void 0 };
|
|
27480
|
+
if (context === null) return null;
|
|
27481
|
+
const { dragValues, item, path } = context;
|
|
27482
|
+
if (record2.resolved.onDrag) {
|
|
27483
|
+
const result = this.renderer.html.callLogic(sourceNode, record2.resolved.onDrag, { dragValues, item, path });
|
|
27484
|
+
if (result && typeof result.then === "function") {
|
|
27485
|
+
throw new TypeError("onDrag must run synchronously");
|
|
27486
|
+
}
|
|
27487
|
+
if (result === false) return null;
|
|
27488
|
+
}
|
|
27489
|
+
assertTransportData(dragValues);
|
|
27490
|
+
const snapshot = Object.fromEntries(Object.entries(dragValues).map(([type, value]) => {
|
|
27491
|
+
if (type.startsWith("text/") || type === "dragTags") {
|
|
27492
|
+
if (typeof value !== "string") throw new TypeError(`${type} drag data must be text`);
|
|
27493
|
+
return [type, value];
|
|
27494
|
+
}
|
|
27495
|
+
return [type, fromTytx(toTytx(value))];
|
|
27496
|
+
}));
|
|
27497
|
+
return { dragValues: snapshot, item, path };
|
|
27498
|
+
}
|
|
27499
|
+
};
|
|
27500
|
+
|
|
27501
|
+
// src/renderer/drag-drop-policy.js
|
|
27502
|
+
var DragDropPolicy = class {
|
|
27503
|
+
static isTarget(attributes) {
|
|
27504
|
+
return attributes.dropTarget === true || Boolean(attributes.dropTargetCb) || Object.entries(attributes).some(([name, value]) => name.startsWith("dropTargetCb_") && Boolean(value));
|
|
27505
|
+
}
|
|
27506
|
+
/** Handler types are already resolved by the dispatcher; no MIME/name encoding is assumed here. */
|
|
27507
|
+
static acceptedTypes(payloadTypes, dropTypes = "", handlerTypes = []) {
|
|
27508
|
+
const patterns = dropTypes.split(",").map((type) => type.trim()).filter(Boolean).map((pattern) => {
|
|
27509
|
+
const literalParts = pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
27510
|
+
return new RegExp(`^${literalParts.join(".*")}$`);
|
|
27511
|
+
});
|
|
27512
|
+
return payloadTypes.filter((type) => type !== "dragTags" && (handlerTypes.includes(type) || patterns.some((pattern) => pattern.test(type))));
|
|
27513
|
+
}
|
|
27514
|
+
static acceptsTags(dragTags = "", dropTags = "") {
|
|
27515
|
+
if (!dropTags.trim()) return true;
|
|
27516
|
+
const tags = new Set(dragTags.split(",").map((tag2) => tag2.trim()).filter(Boolean));
|
|
27517
|
+
if (!tags.size) return false;
|
|
27518
|
+
return dropTags.split(",").some((alternative) => alternative.split(" AND ").every((term) => {
|
|
27519
|
+
term = term.trim();
|
|
27520
|
+
if (!term || term === "!") return false;
|
|
27521
|
+
return term.startsWith("!") ? !tags.has(term.slice(1)) : tags.has(term);
|
|
27522
|
+
}));
|
|
27523
|
+
}
|
|
27524
|
+
static acceptsEffect(effectAllowed = "all", dropEffect = "move") {
|
|
27525
|
+
const effects = {
|
|
27526
|
+
all: ["copy", "move", "link"],
|
|
27527
|
+
none: [],
|
|
27528
|
+
copy: ["copy"],
|
|
27529
|
+
move: ["move"],
|
|
27530
|
+
link: ["link"],
|
|
27531
|
+
copyMove: ["copy", "move"],
|
|
27532
|
+
copyLink: ["copy", "link"],
|
|
27533
|
+
linkMove: ["link", "move"]
|
|
27534
|
+
};
|
|
27535
|
+
if (!Object.hasOwn(effects, effectAllowed)) throw new TypeError(`Invalid effectAllowed: ${effectAllowed}`);
|
|
27536
|
+
if (!["copy", "move", "link"].includes(dropEffect)) throw new TypeError(`Invalid dropEffect: ${dropEffect}`);
|
|
27537
|
+
return effects[effectAllowed].includes(dropEffect);
|
|
27538
|
+
}
|
|
27539
|
+
/** A true result still requires the destination's dynamic callbacks to pass, including at drop. */
|
|
27540
|
+
static evaluate(payloadTypes, dragTags, effectAllowed, target, handlerTypes = []) {
|
|
27541
|
+
const types = this.acceptedTypes(payloadTypes, target.dropTypes, handlerTypes);
|
|
27542
|
+
const dropEffect = target.dropEffect ?? "move";
|
|
27543
|
+
const accepted = this.isTarget(target) && types.length > 0 && this.acceptsTags(dragTags, target.dropTags) && this.acceptsEffect(effectAllowed, dropEffect);
|
|
27544
|
+
return { accepted, types, dropEffect: accepted ? dropEffect : "none" };
|
|
27545
|
+
}
|
|
27546
|
+
};
|
|
27547
|
+
|
|
27548
|
+
// src/renderer/drag-drop.js
|
|
27549
|
+
var EVENTS = ["dragstart", "dragover", "dragleave", "drop", "dragend"];
|
|
27550
|
+
var DragDrop = class {
|
|
27551
|
+
#renderer;
|
|
27552
|
+
#document;
|
|
27553
|
+
#session = null;
|
|
27554
|
+
#feedback = null;
|
|
27555
|
+
#style = null;
|
|
27556
|
+
#hide;
|
|
27557
|
+
constructor(renderer) {
|
|
27558
|
+
this.#renderer = renderer;
|
|
27559
|
+
this.#document = renderer.destination.ownerDocument;
|
|
27560
|
+
for (const name of EVENTS) this.#document.addEventListener(name, this);
|
|
27561
|
+
this.#hide = () => this.#finish("none");
|
|
27562
|
+
this.#document.defaultView.addEventListener("pagehide", this.#hide);
|
|
27563
|
+
}
|
|
27564
|
+
handleEvent(event) {
|
|
27565
|
+
if (event.type === "dragstart") this.#start(event);
|
|
27566
|
+
else if (event.type === "dragend") this.#finish(event.dataTransfer.dropEffect);
|
|
27567
|
+
else if (event.type === "dragleave") this.#clearFeedback();
|
|
27568
|
+
else if (event.type === "dragover") this.#over(event);
|
|
27569
|
+
else if (event.type === "drop") void this.#drop(event);
|
|
27570
|
+
}
|
|
27571
|
+
#record(event, predicate) {
|
|
27572
|
+
for (const element of event.composedPath()) {
|
|
27573
|
+
const record2 = this.#renderer.elements.get(element);
|
|
27574
|
+
if (record2 && predicate(record2.resolved)) return record2;
|
|
27575
|
+
}
|
|
27576
|
+
return null;
|
|
27577
|
+
}
|
|
27578
|
+
#context(record2, event) {
|
|
27579
|
+
return record2.node._getMeta("gramlot_component")?.dragSource ? record2.element.getDragContext(event) : { element: record2.element, item: void 0, path: void 0 };
|
|
27580
|
+
}
|
|
27581
|
+
#start(event) {
|
|
27582
|
+
const record2 = this.#record(event, (attrs) => attrs.draggable === true);
|
|
27583
|
+
if (!record2) return;
|
|
27584
|
+
this.#finish("none");
|
|
27585
|
+
try {
|
|
27586
|
+
const prepared = this.#renderer.prepareDrag(record2.node, event);
|
|
27587
|
+
if (!prepared || !record2.element.isConnected || this.#renderer.records.get(record2.node) !== record2) {
|
|
27588
|
+
event.preventDefault();
|
|
27589
|
+
return;
|
|
27590
|
+
}
|
|
27591
|
+
const context = this.#context(record2, event);
|
|
27592
|
+
if (!context) {
|
|
27593
|
+
event.preventDefault();
|
|
27594
|
+
return;
|
|
27595
|
+
}
|
|
27596
|
+
const wires = new Map(Object.entries(prepared.dragValues).filter(([type]) => type !== "dragTags").map(([type, value]) => [type, type.startsWith("text/") ? value : toTytx(value)]));
|
|
27597
|
+
if (!wires.size) {
|
|
27598
|
+
event.preventDefault();
|
|
27599
|
+
return;
|
|
27600
|
+
}
|
|
27601
|
+
const effectAllowed = record2.resolved.effectAllowed ?? "all";
|
|
27602
|
+
DragDropPolicy.acceptsEffect(effectAllowed, "move");
|
|
27603
|
+
let declaredTags = "";
|
|
27604
|
+
for (let ancestor = record2; ancestor; ancestor = ancestor.parent) {
|
|
27605
|
+
if (ancestor.resolved?.dragTags != null) {
|
|
27606
|
+
declaredTags = ancestor.resolved.dragTags;
|
|
27607
|
+
break;
|
|
27608
|
+
}
|
|
27609
|
+
}
|
|
27610
|
+
const session = this.#session = {
|
|
27611
|
+
record: record2,
|
|
27612
|
+
wires,
|
|
27613
|
+
effectAllowed,
|
|
27614
|
+
phase: "active",
|
|
27615
|
+
tags: [declaredTags, prepared.dragValues.dragTags].filter(Boolean).join(","),
|
|
27616
|
+
endTopic: this.#renderer.binding.gramlot._subscriptions.topicFor(record2.node, "endDrag"),
|
|
27617
|
+
source: {
|
|
27618
|
+
pageId: this.#renderer.binding.gramlot.pageId ?? null,
|
|
27619
|
+
sourcePath: record2.node.fullpath,
|
|
27620
|
+
itemPath: prepared.path ?? null
|
|
27621
|
+
},
|
|
27622
|
+
preview: null,
|
|
27623
|
+
release: null
|
|
27624
|
+
};
|
|
27625
|
+
event.dataTransfer.clearData();
|
|
27626
|
+
for (const [type, wire] of wires) event.dataTransfer.setData(type, wire);
|
|
27627
|
+
event.dataTransfer.effectAllowed = effectAllowed;
|
|
27628
|
+
this.#style = this.#document.createElement("style");
|
|
27629
|
+
this.#style.textContent = ".canBeDropped{outline:2px solid var(--gramlot-brand-blue,#3766b5);outline-offset:-2px}.cannotBeDropped{outline:2px dashed currentColor;outline-offset:-2px}.draggedItem{opacity:.75}";
|
|
27630
|
+
this.#document.head.append(this.#style);
|
|
27631
|
+
this.#preview(session, context.element, event.dataTransfer);
|
|
27632
|
+
session.release = this.#renderer.onDispose(record2.node, () => this.#finish("none"));
|
|
27633
|
+
} catch (error) {
|
|
27634
|
+
event.preventDefault();
|
|
27635
|
+
this.#clearSession();
|
|
27636
|
+
this.#report(error);
|
|
27637
|
+
}
|
|
27638
|
+
}
|
|
27639
|
+
#preview(session, element, transfer) {
|
|
27640
|
+
const preview = element.cloneNode(true);
|
|
27641
|
+
preview.removeAttribute("id");
|
|
27642
|
+
for (const child of preview.querySelectorAll("[id]")) child.removeAttribute("id");
|
|
27643
|
+
preview.setAttribute("aria-hidden", "true");
|
|
27644
|
+
preview.classList.add(...(session.record.resolved.dragClass ?? "draggedItem").split(/\s+/).filter(Boolean));
|
|
27645
|
+
Object.assign(preview.style, {
|
|
27646
|
+
position: "fixed",
|
|
27647
|
+
left: "-10000px",
|
|
27648
|
+
top: "0",
|
|
27649
|
+
width: `${element.getBoundingClientRect().width}px`,
|
|
27650
|
+
pointerEvents: "none"
|
|
27651
|
+
});
|
|
27652
|
+
element.parentNode.append(preview);
|
|
27653
|
+
session.preview = preview;
|
|
27654
|
+
transfer.setDragImage(preview, 0, 0);
|
|
27655
|
+
}
|
|
27656
|
+
#target(event) {
|
|
27657
|
+
const session = this.#session;
|
|
27658
|
+
const record2 = this.#record(event, (attrs) => DragDropPolicy.isTarget(attrs));
|
|
27659
|
+
if (!record2) return null;
|
|
27660
|
+
const row = this.#context(record2, event);
|
|
27661
|
+
if (!row) return { record: record2, element: record2.element, accepted: false };
|
|
27662
|
+
const policy = DragDropPolicy.evaluate([...session.wires.keys()], session.tags, session.effectAllowed, record2.resolved);
|
|
27663
|
+
const dropValues = Object.fromEntries(policy.types.map((type) => [
|
|
27664
|
+
type,
|
|
27665
|
+
type.startsWith("text/") ? session.wires.get(type) : fromTytx(session.wires.get(type))
|
|
27666
|
+
]));
|
|
27667
|
+
const context = {
|
|
27668
|
+
dropValues,
|
|
27669
|
+
item: row.item,
|
|
27670
|
+
path: row.path,
|
|
27671
|
+
source: { ...session.source },
|
|
27672
|
+
selfdrop: record2 === session.record,
|
|
27673
|
+
dropEffect: policy.dropEffect,
|
|
27674
|
+
dataAvailable: true
|
|
27675
|
+
};
|
|
27676
|
+
const accepted = policy.accepted && this.#renderer.checkDropTarget(record2.node, context) && this.#renderer.records.get(record2.node) === record2 && row.element.isConnected;
|
|
27677
|
+
return { record: record2, element: row.element, accepted, context };
|
|
27678
|
+
}
|
|
27679
|
+
#over(event) {
|
|
27680
|
+
if (!this.#session) {
|
|
27681
|
+
if (this.#record(event, (attrs) => DragDropPolicy.isTarget(attrs))) {
|
|
27682
|
+
event.preventDefault();
|
|
27683
|
+
event.dataTransfer.dropEffect = "none";
|
|
27684
|
+
}
|
|
27685
|
+
return;
|
|
27686
|
+
}
|
|
27687
|
+
event.preventDefault();
|
|
27688
|
+
if (this.#session.phase !== "active") {
|
|
27689
|
+
event.dataTransfer.dropEffect = "none";
|
|
27690
|
+
return;
|
|
27691
|
+
}
|
|
27692
|
+
try {
|
|
27693
|
+
const session = this.#session;
|
|
27694
|
+
const target = this.#target(event);
|
|
27695
|
+
if (this.#session !== session) {
|
|
27696
|
+
event.dataTransfer.dropEffect = "none";
|
|
27697
|
+
return;
|
|
27698
|
+
}
|
|
27699
|
+
event.dataTransfer.dropEffect = target?.accepted ? target.context.dropEffect : "none";
|
|
27700
|
+
this.#clearFeedback();
|
|
27701
|
+
if (target) this.#showFeedback(target.element, target.accepted);
|
|
27702
|
+
} catch (error) {
|
|
27703
|
+
event.dataTransfer.dropEffect = "none";
|
|
27704
|
+
if (this.#session) this.#session.phase = "rejected";
|
|
27705
|
+
this.#clearPayload();
|
|
27706
|
+
this.#report(error);
|
|
27707
|
+
}
|
|
27708
|
+
}
|
|
27709
|
+
async #drop(event) {
|
|
27710
|
+
if (!this.#session) {
|
|
27711
|
+
if (this.#record(event, (attrs) => DragDropPolicy.isTarget(attrs))) event.preventDefault();
|
|
27712
|
+
return;
|
|
27713
|
+
}
|
|
27714
|
+
event.preventDefault();
|
|
27715
|
+
if (this.#session.phase !== "active") return;
|
|
27716
|
+
const session = this.#session;
|
|
27717
|
+
try {
|
|
27718
|
+
const target = this.#target(event);
|
|
27719
|
+
if (this.#session !== session) {
|
|
27720
|
+
event.dataTransfer.dropEffect = "none";
|
|
27721
|
+
return;
|
|
27722
|
+
}
|
|
27723
|
+
session.phase = "dropped";
|
|
27724
|
+
this.#clearPayload();
|
|
27725
|
+
if (!target?.accepted) {
|
|
27726
|
+
event.dataTransfer.dropEffect = "none";
|
|
27727
|
+
return;
|
|
27728
|
+
}
|
|
27729
|
+
event.dataTransfer.dropEffect = target.context.dropEffect;
|
|
27730
|
+
target.record.node.publish("onDrop", target.context);
|
|
27731
|
+
await this.#renderer.invokeDrop(target.record.node, target.context);
|
|
27732
|
+
} catch (error) {
|
|
27733
|
+
if (this.#session === session) {
|
|
27734
|
+
session.phase = "rejected";
|
|
27735
|
+
this.#clearPayload();
|
|
27736
|
+
}
|
|
27737
|
+
this.#report(error);
|
|
27738
|
+
}
|
|
27739
|
+
}
|
|
27740
|
+
#showFeedback(element, accepted) {
|
|
27741
|
+
const name = accepted ? "canBeDropped" : "cannotBeDropped";
|
|
27742
|
+
const parts2 = (element.getAttribute("part") ?? "").split(/\s+/).filter(Boolean);
|
|
27743
|
+
this.#feedback = { element, name, hadClass: element.classList.contains(name), hadPart: parts2.includes(name) };
|
|
27744
|
+
element.classList.add(name);
|
|
27745
|
+
if (!parts2.includes(name)) element.setAttribute("part", [...parts2, name].join(" "));
|
|
27746
|
+
}
|
|
27747
|
+
#clearFeedback() {
|
|
27748
|
+
if (!this.#feedback) return;
|
|
27749
|
+
const { element, name, hadClass, hadPart } = this.#feedback;
|
|
27750
|
+
if (!hadClass) element.classList.remove(name);
|
|
27751
|
+
if (!hadPart) element.setAttribute("part", (element.getAttribute("part") ?? "").split(/\s+/).filter((part) => part !== name).join(" "));
|
|
27752
|
+
this.#feedback = null;
|
|
27753
|
+
}
|
|
27754
|
+
#clearPayload() {
|
|
27755
|
+
this.#clearFeedback();
|
|
27756
|
+
if (!this.#session) return;
|
|
27757
|
+
this.#session.preview?.remove();
|
|
27758
|
+
this.#session.preview = null;
|
|
27759
|
+
this.#session.wires.clear();
|
|
27760
|
+
}
|
|
27761
|
+
#clearSession() {
|
|
27762
|
+
const session = this.#session;
|
|
27763
|
+
this.#clearPayload();
|
|
27764
|
+
this.#session = null;
|
|
27765
|
+
session?.release?.();
|
|
27766
|
+
this.#style?.remove();
|
|
27767
|
+
this.#style = null;
|
|
27768
|
+
return session;
|
|
27769
|
+
}
|
|
27770
|
+
#finish(dropEffect) {
|
|
27771
|
+
const session = this.#clearSession();
|
|
27772
|
+
if (!session || this.#renderer.disposed) return;
|
|
27773
|
+
void this.#renderer.endDrag(session.record.node, { source: { ...session.source }, dropEffect }, session.endTopic).catch((error) => this.#report(error));
|
|
27774
|
+
}
|
|
27775
|
+
#report(error) {
|
|
27776
|
+
console.error("Gramlot drag/drop failed:", error);
|
|
27777
|
+
}
|
|
27778
|
+
dispose() {
|
|
27779
|
+
this.#clearSession();
|
|
27780
|
+
for (const name of EVENTS) this.#document.removeEventListener(name, this);
|
|
27781
|
+
this.#document.defaultView.removeEventListener("pagehide", this.#hide);
|
|
27782
|
+
}
|
|
27783
|
+
};
|
|
27784
|
+
|
|
27423
27785
|
// src/renderer/gramlot-renderer.js
|
|
27424
27786
|
var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
27425
27787
|
static renderType = "object";
|
|
@@ -27444,12 +27806,18 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
27444
27806
|
this.destination = destination;
|
|
27445
27807
|
this.html = new HtmlElement({
|
|
27446
27808
|
metadataAttributes: ["__ref"],
|
|
27447
|
-
|
|
27809
|
+
callLogic: (node, name, keywords) => {
|
|
27810
|
+
const { group, method } = binding.gramlot.src.logicRegistry.resolve(name, node);
|
|
27811
|
+
return method.call(group, node, keywords);
|
|
27812
|
+
},
|
|
27813
|
+
invokeScript: (node, name, code, keywords) => invokeHook(
|
|
27814
|
+
binding,
|
|
27448
27815
|
node,
|
|
27449
27816
|
name,
|
|
27450
27817
|
code,
|
|
27818
|
+
keywords,
|
|
27451
27819
|
node.parentNode._getMeta("gramlot_component").childParameters[name].inline
|
|
27452
|
-
)
|
|
27820
|
+
)
|
|
27453
27821
|
});
|
|
27454
27822
|
this.records = /* @__PURE__ */ new Map();
|
|
27455
27823
|
this.references = new References(source);
|
|
@@ -27457,14 +27825,59 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
27457
27825
|
this.building = false;
|
|
27458
27826
|
this.disposed = false;
|
|
27459
27827
|
this.elements = /* @__PURE__ */ new WeakMap();
|
|
27828
|
+
this.dragPreparation = new DragPreparation(this);
|
|
27460
27829
|
this.instanceId = randomId();
|
|
27461
27830
|
this.radioGroups = new RadioGroups(this);
|
|
27831
|
+
this.dragDrop = new DragDrop(this);
|
|
27462
27832
|
this.subscription = `html-source-renderer-${this.instanceId}`;
|
|
27463
27833
|
source.subscribe(this.subscription, { any: (event) => this.receive(event) });
|
|
27464
27834
|
}
|
|
27465
27835
|
get binding() {
|
|
27466
27836
|
return this._binding;
|
|
27467
27837
|
}
|
|
27838
|
+
/** Prepare a local payload snapshot: no DataTransfer writes or native gesture commit. */
|
|
27839
|
+
prepareDrag(node, event) {
|
|
27840
|
+
return this.dragPreparation.prepare(node, event);
|
|
27841
|
+
}
|
|
27842
|
+
/** Dynamic eligibility only; cannot replace the independent type/tag/effect policy. */
|
|
27843
|
+
checkDropTarget(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }) {
|
|
27844
|
+
const record2 = this.records.get(node);
|
|
27845
|
+
if (!record2) return false;
|
|
27846
|
+
if (!record2.resolved.dropTargetCb) return true;
|
|
27847
|
+
const allowed = this.html.callLogic(
|
|
27848
|
+
node,
|
|
27849
|
+
record2.resolved.dropTargetCb,
|
|
27850
|
+
{ dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }
|
|
27851
|
+
);
|
|
27852
|
+
if (typeof allowed !== "boolean") throw new TypeError("dropTargetCb must return a boolean synchronously");
|
|
27853
|
+
return allowed;
|
|
27854
|
+
}
|
|
27855
|
+
/** Invoke only the general action, after acceptance and removal of data handled by typed actions. */
|
|
27856
|
+
async invokeDrop(node, { dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }) {
|
|
27857
|
+
const record2 = this.records.get(node);
|
|
27858
|
+
if (!record2 || !record2.resolved.onDrop || Object.keys(dropValues).length === 0) return;
|
|
27859
|
+
await this.html.callLogic(
|
|
27860
|
+
node,
|
|
27861
|
+
record2.resolved.onDrop,
|
|
27862
|
+
{ dropValues, item, path, source, selfdrop, dropEffect, dataAvailable }
|
|
27863
|
+
);
|
|
27864
|
+
}
|
|
27865
|
+
/** Notify origin completion independently of application-operation success. */
|
|
27866
|
+
async endDrag(node, { source, dropEffect }, topic) {
|
|
27867
|
+
const context = { source, dropEffect }, errors = [];
|
|
27868
|
+
const record2 = this.records.get(node);
|
|
27869
|
+
try {
|
|
27870
|
+
if (record2 && !record2.binding.closed && record2.resolved.onDragEnd) await this.html.callLogic(node, record2.resolved.onDragEnd, context);
|
|
27871
|
+
} catch (error) {
|
|
27872
|
+
errors.push(error);
|
|
27873
|
+
}
|
|
27874
|
+
try {
|
|
27875
|
+
this.binding.gramlot.publish(topic, context);
|
|
27876
|
+
} catch (error) {
|
|
27877
|
+
errors.push(error);
|
|
27878
|
+
}
|
|
27879
|
+
if (errors.length) throw new AggregateError(errors, "Drag completion notification failed");
|
|
27880
|
+
}
|
|
27468
27881
|
/** The page's InlineCompiler: the live renderer evaluates the `==` expressions (S09). */
|
|
27469
27882
|
get inlineCompiler() {
|
|
27470
27883
|
return this.binding.inlineCompiler;
|
|
@@ -28078,6 +28491,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
28078
28491
|
dispose() {
|
|
28079
28492
|
if (this.disposed) return;
|
|
28080
28493
|
this.disposed = true;
|
|
28494
|
+
this.dragDrop.dispose();
|
|
28081
28495
|
this.source.unsubscribe(this.subscription, { any: true });
|
|
28082
28496
|
this.pending.length = 0;
|
|
28083
28497
|
const errors = [];
|
|
@@ -29190,584 +29604,979 @@ var Page = class extends Exposed {
|
|
|
29190
29604
|
}
|
|
29191
29605
|
};
|
|
29192
29606
|
|
|
29193
|
-
// src/server/
|
|
29194
|
-
var
|
|
29195
|
-
static
|
|
29196
|
-
static
|
|
29197
|
-
static shellId = "index";
|
|
29198
|
-
static navigation = [];
|
|
29199
|
-
static css = ["/themes/gramlot-index/theme.css"];
|
|
29607
|
+
// src/server/frame-page.js
|
|
29608
|
+
var FramePage = class extends Page {
|
|
29609
|
+
static shellId = "frame";
|
|
29610
|
+
static datapath = null;
|
|
29200
29611
|
main(root) {
|
|
29201
|
-
const
|
|
29202
|
-
|
|
29203
|
-
|
|
29204
|
-
|
|
29205
|
-
|
|
29206
|
-
|
|
29207
|
-
|
|
29208
|
-
|
|
29209
|
-
for (const family of families) {
|
|
29210
|
-
const category = navigation.li().details({ open: family === families[0] });
|
|
29211
|
-
category.summary({ tabindex: -1 }).a(family.title, {
|
|
29212
|
-
id: `open-${family.key}`,
|
|
29213
|
-
href: `#panel-${family.key}`,
|
|
29214
|
-
class: "index-family",
|
|
29215
|
-
aria_current: null,
|
|
29216
|
-
tabindex: -1
|
|
29217
|
-
});
|
|
29218
|
-
const examplesList = category.ul({ class: "index-list" });
|
|
29219
|
-
for (const example of family.children) {
|
|
29220
|
-
examplesList.li().a(example.title, {
|
|
29221
|
-
id: `open-${example.key}`,
|
|
29222
|
-
href: example.url,
|
|
29223
|
-
aria_current: null,
|
|
29224
|
-
tabindex: -1
|
|
29225
|
-
});
|
|
29226
|
-
}
|
|
29227
|
-
}
|
|
29228
|
-
shell.div({
|
|
29229
|
-
class: "index-divider",
|
|
29230
|
-
id: "index-sidebar-divider",
|
|
29231
|
-
role: "separator",
|
|
29232
|
-
aria_orientation: "vertical",
|
|
29233
|
-
tabindex: 0,
|
|
29234
|
-
aria_label: "Resize sidebar",
|
|
29235
|
-
aria_controls: "index-sidebar",
|
|
29236
|
-
aria_valuemin: 120,
|
|
29237
|
-
aria_valuemax: 460,
|
|
29238
|
-
aria_valuenow: 240
|
|
29239
|
-
});
|
|
29240
|
-
const content = shell.main({ class: "index-main" });
|
|
29241
|
-
const tabs = content.div({ class: "index-tabs", role: "tablist", aria_label: "Open pages" });
|
|
29242
|
-
tabs.html_button("Introduction", {
|
|
29243
|
-
type: "button",
|
|
29244
|
-
role: "tab",
|
|
29245
|
-
id: "tab-intro",
|
|
29246
|
-
aria_controls: "panel-intro",
|
|
29247
|
-
aria_selected: "true",
|
|
29248
|
-
tabindex: -1,
|
|
29249
|
-
hidden: false
|
|
29612
|
+
const shell = root.div({
|
|
29613
|
+
id: this.constructor.shellId,
|
|
29614
|
+
datapath: this.constructor.datapath,
|
|
29615
|
+
class: "frame-page",
|
|
29616
|
+
height: "100vh",
|
|
29617
|
+
display: "flex",
|
|
29618
|
+
flex_direction: "column",
|
|
29619
|
+
min_height: 0
|
|
29250
29620
|
});
|
|
29251
|
-
|
|
29252
|
-
|
|
29253
|
-
|
|
29254
|
-
|
|
29255
|
-
|
|
29256
|
-
id: `tab-${key}`,
|
|
29257
|
-
aria_controls: `panel-${key}`,
|
|
29258
|
-
aria_selected: "false",
|
|
29259
|
-
tabindex: -1,
|
|
29260
|
-
hidden: true
|
|
29261
|
-
});
|
|
29621
|
+
const frame = shell.borderContainer({ node_label: "frame", height: "100%", flex: "1", min_height: 0 });
|
|
29622
|
+
for (const region of ["top", "bottom", "left", "right", "center"]) {
|
|
29623
|
+
if (this[region] !== void 0) {
|
|
29624
|
+
const pane = frame.contentPane({ region, node_label: region });
|
|
29625
|
+
this[region](pane);
|
|
29262
29626
|
}
|
|
29263
29627
|
}
|
|
29264
|
-
const panels = content.div({ class: "index-panels" });
|
|
29265
|
-
const intro = panels.section({
|
|
29266
|
-
id: "panel-intro",
|
|
29267
|
-
class: "index-intro",
|
|
29268
|
-
role: "tabpanel",
|
|
29269
|
-
aria_labelledby: "tab-intro",
|
|
29270
|
-
hidden: false
|
|
29271
|
-
});
|
|
29272
|
-
this.introduction(intro);
|
|
29273
|
-
for (const family of families) {
|
|
29274
|
-
const categoryPanel = panels.section({
|
|
29275
|
-
id: `panel-${family.key}`,
|
|
29276
|
-
class: "index-category",
|
|
29277
|
-
role: "tabpanel",
|
|
29278
|
-
aria_labelledby: `tab-${family.key}`,
|
|
29279
|
-
hidden: true
|
|
29280
|
-
});
|
|
29281
|
-
this.groupPanel(categoryPanel, family);
|
|
29282
|
-
for (const example of family.children) this.panel(panels, example);
|
|
29283
|
-
}
|
|
29284
|
-
const footer = shell.footer({ class: "index-footer" });
|
|
29285
|
-
this.footer(footer);
|
|
29286
29628
|
this.behavior(shell);
|
|
29287
29629
|
}
|
|
29288
|
-
|
|
29630
|
+
center(pane) {
|
|
29631
|
+
}
|
|
29632
|
+
behavior(shell) {
|
|
29633
|
+
}
|
|
29634
|
+
};
|
|
29635
|
+
|
|
29636
|
+
// src/server/index-page.js
|
|
29637
|
+
var IndexPage = class extends FramePage {
|
|
29638
|
+
static title = "Application";
|
|
29639
|
+
static shellId = "index";
|
|
29640
|
+
static datapath = "index";
|
|
29641
|
+
static navigation = null;
|
|
29642
|
+
main(root) {
|
|
29643
|
+
const { navigation, datapath } = this.constructor;
|
|
29644
|
+
if (!(navigation instanceof Bag)) throw new TypeError("IndexPage.navigation must be a Bag");
|
|
29645
|
+
root.dataSetter({ destination_path: `${datapath}.navigation`, value: navigation });
|
|
29646
|
+
root.dataSetter({ destination_path: `${datapath}.navigationSelection`, value: null });
|
|
29647
|
+
root.dataSetter({ destination_path: `${datapath}.active`, value: null });
|
|
29648
|
+
root.dataSetter({ destination_path: `${datapath}.opened`, value: new Bag() });
|
|
29649
|
+
super.main(root);
|
|
29650
|
+
}
|
|
29651
|
+
left(pane) {
|
|
29652
|
+
pane.setAttr({ width: "240px", splitter: true, drawer: true, drawer_label: "Navigation" });
|
|
29653
|
+
pane.tree({
|
|
29654
|
+
node_label: "tree",
|
|
29655
|
+
storepath: `${this.constructor.datapath}.navigation`,
|
|
29656
|
+
labelAttribute: "title",
|
|
29657
|
+
hideValues: true,
|
|
29658
|
+
selectedPath: `^${this.constructor.datapath}.navigationSelection`
|
|
29659
|
+
});
|
|
29660
|
+
}
|
|
29661
|
+
center(pane) {
|
|
29662
|
+
pane.tabContainer({ node_label: "tabs", height: "100%", selectedPage: `^${this.constructor.datapath}.active` });
|
|
29289
29663
|
}
|
|
29290
29664
|
behavior(shell) {
|
|
29291
29665
|
shell.dataController({ func: "indexMount", _onStart: true, shell_id: this.constructor.shellId });
|
|
29292
29666
|
}
|
|
29293
|
-
|
|
29294
|
-
pane.
|
|
29295
|
-
|
|
29296
|
-
|
|
29297
|
-
|
|
29298
|
-
|
|
29299
|
-
|
|
29300
|
-
|
|
29301
|
-
|
|
29302
|
-
|
|
29303
|
-
const appearance = theme.select({ id: "index-appearance", value: "compact" });
|
|
29304
|
-
appearance.option("Base", { value: "base", selected: false });
|
|
29305
|
-
appearance.option("Compact", { value: "compact", selected: true });
|
|
29306
|
-
appearance.option("mimi", { value: "mimi" });
|
|
29307
|
-
appearance.option("joanna", { value: "joanna" });
|
|
29308
|
-
const color = footer.div({ class: "index-theme" });
|
|
29309
|
-
color.html_label("Color mode", { for: "index-theme" });
|
|
29310
|
-
const choices = color.select({ id: "index-theme", value: "light" });
|
|
29311
|
-
choices.option("Light", { value: "light", selected: true });
|
|
29312
|
-
choices.option("Dark", { value: "dark", selected: false });
|
|
29313
|
-
const keyboard = footer.div({ class: "index-keyboard" });
|
|
29314
|
-
const label = keyboard.html_label({ for: "keyboard-navigation" });
|
|
29315
|
-
label.input({ type: "checkbox", id: "keyboard-navigation", checked: false });
|
|
29316
|
-
label.span("Keyboard navigation");
|
|
29317
|
-
if (this.constructor.installable) {
|
|
29318
|
-
const app = footer.details({ class: "index-install" });
|
|
29319
|
-
app.summary("Install app");
|
|
29320
|
-
app.html_button("Install", { type: "button", id: "index-install-button", hidden: true });
|
|
29321
|
-
app.p("", { id: "index-install-status", role: "status" });
|
|
29322
|
-
app.p("Chrome: use Install page as app in the browser menu. Safari on macOS Sonoma or later: File > Add to Dock.");
|
|
29323
|
-
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.");
|
|
29324
|
-
}
|
|
29325
|
-
}
|
|
29326
|
-
panel(parent, item) {
|
|
29327
|
-
const pane = parent.section({
|
|
29328
|
-
id: `panel-${item.key}`,
|
|
29329
|
-
class: "index-panel",
|
|
29330
|
-
role: "tabpanel",
|
|
29331
|
-
aria_labelledby: `tab-${item.key}`,
|
|
29332
|
-
hidden: true
|
|
29667
|
+
index_panel(pane, { selection }) {
|
|
29668
|
+
this.panel(pane, selection.getNode("#0"));
|
|
29669
|
+
}
|
|
29670
|
+
panel(pane, node) {
|
|
29671
|
+
pane.iframe({
|
|
29672
|
+
src: node.attr.url,
|
|
29673
|
+
title: node.attr.title ?? node.label,
|
|
29674
|
+
width: "100%",
|
|
29675
|
+
height: "100%",
|
|
29676
|
+
border: 0
|
|
29333
29677
|
});
|
|
29334
|
-
pane.iframe({ id: `frame-${item.key}`, title: item.title, name: `page-${item.key}` });
|
|
29335
29678
|
}
|
|
29336
29679
|
};
|
|
29337
|
-
|
|
29338
|
-
// src/index-page-styles.js
|
|
29339
|
-
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-tab-height: 24px;\n --gramlot-tab-padding: 3px 10px;\n --gramlot-tab-radius: 3px;\n --gramlot-tab-gap: 2px;\n --gramlot-tab-strip-padding: 3px;\n --gramlot-tab-background: var(--gramlot-background);\n --gramlot-tab-selected-background: var(--gramlot-surface);\n --gramlot-tab-selected-color: var(--gramlot-ink);\n --gramlot-tab-border: var(--gramlot-border);\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-tab-height: 26px;\n --gramlot-tab-padding: 3px 10px;\n --gramlot-tab-radius: 6px;\n --gramlot-tab-gap: 2px;\n --gramlot-tab-strip-padding: 3px;\n --gramlot-tab-background: var(--gramlot-background);\n --gramlot-tab-selected-background: var(--gramlot-surface);\n --gramlot-tab-selected-color: var(--gramlot-ink);\n --gramlot-tab-border: var(--gramlot-border);\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' };
|
|
29340
|
-
|
|
29341
|
-
// src/index-theme.js
|
|
29342
|
-
var THEME_READY = "index:theme-ready";
|
|
29343
|
-
var THEME_SET = "index:theme-set";
|
|
29344
|
-
var THEMES = /* @__PURE__ */ new Set(["light", "dark"]);
|
|
29345
|
-
var APPEARANCES = /* @__PURE__ */ new Set(["base", "compact", "mimi", "joanna"]);
|
|
29680
|
+
IndexPage.registerSource("index_panel");
|
|
29346
29681
|
|
|
29347
29682
|
// src/index-page-runtime.js
|
|
29348
29683
|
function mountIndexPage(renderer, root, onSelection = () => {
|
|
29349
29684
|
}, prepareEntry = () => {
|
|
29350
|
-
}, {
|
|
29351
|
-
|
|
29352
|
-
|
|
29353
|
-
|
|
29354
|
-
|
|
29355
|
-
|
|
29356
|
-
const
|
|
29357
|
-
|
|
29358
|
-
const
|
|
29359
|
-
const
|
|
29360
|
-
const
|
|
29361
|
-
|
|
29362
|
-
const
|
|
29363
|
-
const
|
|
29364
|
-
|
|
29365
|
-
|
|
29366
|
-
|
|
29367
|
-
|
|
29368
|
-
|
|
29369
|
-
|
|
29370
|
-
|
|
29371
|
-
|
|
29372
|
-
if (
|
|
29373
|
-
|
|
29374
|
-
|
|
29375
|
-
|
|
29376
|
-
|
|
29377
|
-
|
|
29378
|
-
|
|
29379
|
-
|
|
29685
|
+
}, {
|
|
29686
|
+
state = root.builder.data.getItem(root.getAttr("datapath")),
|
|
29687
|
+
createEntry = null,
|
|
29688
|
+
onLoad = () => {
|
|
29689
|
+
}
|
|
29690
|
+
} = {}) {
|
|
29691
|
+
const navigation = state.getItem("navigation");
|
|
29692
|
+
if (!(navigation instanceof Bag)) throw new TypeError("IndexPage navigation must be a Bag");
|
|
29693
|
+
const tabs = root.value.getNode("frame.center.tabs");
|
|
29694
|
+
const builder = root.builder;
|
|
29695
|
+
const entries = /* @__PURE__ */ new Map();
|
|
29696
|
+
let disposed = false, selecting = false, sequence = 0, requested = null;
|
|
29697
|
+
const opened = state.getItem("opened");
|
|
29698
|
+
for (const record2 of opened.getNodes()) {
|
|
29699
|
+
const { url, path, title } = record2.attr;
|
|
29700
|
+
const pane = tabs.value.getNode(record2.label);
|
|
29701
|
+
const entry = { url, path, title, pane, node: navigation.getNode(path), loading: false };
|
|
29702
|
+
prepareEntry(entry);
|
|
29703
|
+
entries.set(url, entry);
|
|
29704
|
+
sequence++;
|
|
29705
|
+
}
|
|
29706
|
+
const activate = (entry) => {
|
|
29707
|
+
if (disposed) return;
|
|
29708
|
+
selecting = true;
|
|
29709
|
+
try {
|
|
29710
|
+
state.setItem("active", entry.url);
|
|
29711
|
+
state.setItem("navigationSelection", entry.path);
|
|
29712
|
+
onSelection(entries, entry.url);
|
|
29713
|
+
} finally {
|
|
29714
|
+
selecting = false;
|
|
29715
|
+
}
|
|
29380
29716
|
};
|
|
29381
|
-
|
|
29382
|
-
|
|
29383
|
-
|
|
29384
|
-
|
|
29385
|
-
|
|
29386
|
-
|
|
29387
|
-
|
|
29388
|
-
|
|
29389
|
-
|
|
29390
|
-
|
|
29391
|
-
|
|
29392
|
-
|
|
29393
|
-
|
|
29717
|
+
async function select(path) {
|
|
29718
|
+
const node = navigation.getNode(path);
|
|
29719
|
+
if (!node) throw new Error(`Unknown index navigation path: ${path}`);
|
|
29720
|
+
const url = node.attr.url;
|
|
29721
|
+
if (url == null) return;
|
|
29722
|
+
if (typeof url !== "string" || !url) throw new TypeError("IndexPage URL must be nonempty text");
|
|
29723
|
+
requested = url;
|
|
29724
|
+
let entry = entries.get(url);
|
|
29725
|
+
if (entry) {
|
|
29726
|
+
entry.path = path;
|
|
29727
|
+
activate(entry);
|
|
29728
|
+
return;
|
|
29729
|
+
}
|
|
29730
|
+
while (tabs.value !== null && tabs.value.getNode(`page${sequence}`)) sequence++;
|
|
29731
|
+
const pane = sourceTarget(builder.wrapSource(tabs).contentPane({
|
|
29732
|
+
node_label: `page${sequence++}`,
|
|
29733
|
+
title: node.attr.title ?? node.label,
|
|
29734
|
+
pageName: url,
|
|
29735
|
+
height: "100%"
|
|
29736
|
+
}));
|
|
29737
|
+
const previous = state.getItem("active");
|
|
29738
|
+
entry = { url, path, node, pane, title: node.attr.title ?? node.label, loading: true };
|
|
29739
|
+
entries.set(url, entry);
|
|
29394
29740
|
try {
|
|
29395
|
-
|
|
29396
|
-
|
|
29397
|
-
|
|
29398
|
-
|
|
29399
|
-
|
|
29400
|
-
|
|
29401
|
-
|
|
29402
|
-
|
|
29741
|
+
activate(entry);
|
|
29742
|
+
onLoad(url, "loading");
|
|
29743
|
+
if (createEntry) await createEntry(entry);
|
|
29744
|
+
else {
|
|
29745
|
+
const selection = new Bag();
|
|
29746
|
+
selection.setItem(node.label, null, { ...node.attr });
|
|
29747
|
+
const mounted = await renderer.binding.gramlot.src.remoteSource(pane, "index_panel", { selection });
|
|
29748
|
+
if (!mounted) throw new Error("Panel loading was cancelled");
|
|
29749
|
+
}
|
|
29750
|
+
if (disposed) return;
|
|
29751
|
+
entry.loading = false;
|
|
29752
|
+
opened.setItem(pane.label, null, { url, path: entry.path, title: entry.title });
|
|
29753
|
+
prepareEntry(entry);
|
|
29754
|
+
if (requested === url) {
|
|
29755
|
+
onLoad(url, "ready");
|
|
29756
|
+
activate(entry);
|
|
29757
|
+
}
|
|
29403
29758
|
} catch (error) {
|
|
29404
|
-
|
|
29759
|
+
entries.delete(url);
|
|
29760
|
+
if (opened.getNode(pane.label)) opened.popNode(pane.label);
|
|
29761
|
+
if (pane.parentBag) pane.parentBag.popNode(pane.label);
|
|
29762
|
+
if (!disposed && requested === url) {
|
|
29763
|
+
onLoad(url, "error", error);
|
|
29764
|
+
const restored = entries.get(previous);
|
|
29765
|
+
requested = restored?.url ?? null;
|
|
29766
|
+
if (restored) activate(restored);
|
|
29767
|
+
else {
|
|
29768
|
+
selecting = true;
|
|
29769
|
+
try {
|
|
29770
|
+
state.setItem("active", null);
|
|
29771
|
+
state.setItem("navigationSelection", null);
|
|
29772
|
+
onSelection(entries, null);
|
|
29773
|
+
} finally {
|
|
29774
|
+
selecting = false;
|
|
29775
|
+
}
|
|
29776
|
+
}
|
|
29777
|
+
}
|
|
29405
29778
|
}
|
|
29406
|
-
}
|
|
29407
|
-
const
|
|
29408
|
-
|
|
29409
|
-
|
|
29410
|
-
|
|
29411
|
-
|
|
29412
|
-
|
|
29413
|
-
|
|
29414
|
-
|
|
29415
|
-
|
|
29416
|
-
|
|
29417
|
-
|
|
29418
|
-
|
|
29419
|
-
|
|
29420
|
-
|
|
29421
|
-
const { handle, pointerId } = drag;
|
|
29422
|
-
drag = null;
|
|
29423
|
-
if (!disposed) set(shell, { data_resizing: null });
|
|
29424
|
-
if (handle.hasPointerCapture(pointerId)) handle.releasePointerCapture(pointerId);
|
|
29425
|
-
};
|
|
29779
|
+
}
|
|
29780
|
+
const subscription = `${root.getAttr("id")}-selection`;
|
|
29781
|
+
state.subscribe(subscription, { any: (event) => {
|
|
29782
|
+
if (selecting || disposed) return;
|
|
29783
|
+
if (event.node === state.getNode("navigationSelection")) {
|
|
29784
|
+
const path = state.getItem("navigationSelection");
|
|
29785
|
+
if (path !== null) void select(path);
|
|
29786
|
+
} else if (event.node === state.getNode("active")) {
|
|
29787
|
+
const entry = entries.get(state.getItem("active"));
|
|
29788
|
+
if (entry) {
|
|
29789
|
+
requested = entry.url;
|
|
29790
|
+
activate(entry);
|
|
29791
|
+
}
|
|
29792
|
+
}
|
|
29793
|
+
} });
|
|
29426
29794
|
const dispose = () => {
|
|
29427
29795
|
if (disposed) return;
|
|
29428
29796
|
disposed = true;
|
|
29429
|
-
|
|
29430
|
-
|
|
29431
|
-
|
|
29432
|
-
if (style.parentBag) style.parentBag.popNode(style.label);
|
|
29433
|
-
if (previousTheme == null) document.documentElement.removeAttribute("data-theme");
|
|
29434
|
-
else document.documentElement.setAttribute("data-theme", previousTheme);
|
|
29435
|
-
};
|
|
29436
|
-
const send = (frame) => frame.contentWindow.postMessage({ type: THEME_SET, theme: state.getItem("theme"), appearance: state.getItem("appearance") }, "*");
|
|
29437
|
-
const applyTheme = () => {
|
|
29438
|
-
document.documentElement.setAttribute("data-theme", state.getItem("theme"));
|
|
29439
|
-
style.setValue(appearanceStyles[state.getItem("appearance")]);
|
|
29440
|
-
for (const { frame } of entries.values()) if (frame) send(frame);
|
|
29441
|
-
};
|
|
29442
|
-
const updateInspector = () => onSelection(entries, state.getItem("active"));
|
|
29443
|
-
const updatePanels = () => {
|
|
29444
|
-
if (navigationToggle) {
|
|
29445
|
-
const visible = state.getItem("navigationVisible");
|
|
29446
|
-
set(sidebar, containerLayout ? { drawer: visible ? true : "close" } : { hidden: !visible });
|
|
29447
|
-
if (!containerLayout) set(sidebarHandle, { hidden: !visible });
|
|
29448
|
-
set(navigationToggle, { aria_expanded: String(visible) });
|
|
29449
|
-
set(shell, { data_navigation_hidden: String(!visible) });
|
|
29450
|
-
}
|
|
29451
|
-
if (codeSidebar) {
|
|
29452
|
-
const available = Boolean(entries.get(state.getItem("active"))?.code);
|
|
29453
|
-
const visible = available && state.getItem("codeVisible");
|
|
29454
|
-
set(codeSidebar, containerLayout ? { hidden: !available, drawer: visible ? true : "close" } : { hidden: !visible });
|
|
29455
|
-
if (!containerLayout) set(codeHandle, { hidden: !visible });
|
|
29456
|
-
set(codeToggle, { disabled: !available, aria_expanded: String(visible) });
|
|
29457
|
-
set(shell, { data_code_visible: String(visible) });
|
|
29797
|
+
state.unsubscribe(subscription, { any: true });
|
|
29798
|
+
for (const entry of entries.values()) if (entry.loading && entry.pane.parentBag) {
|
|
29799
|
+
entry.pane.parentBag.popNode(entry.pane.label);
|
|
29458
29800
|
}
|
|
29459
29801
|
};
|
|
29460
|
-
|
|
29461
|
-
|
|
29462
|
-
|
|
29463
|
-
|
|
29464
|
-
|
|
29465
|
-
|
|
29466
|
-
|
|
29467
|
-
|
|
29802
|
+
renderer.onDispose(root, dispose);
|
|
29803
|
+
const active = entries.get(state.getItem("active"));
|
|
29804
|
+
if (active) activate(active);
|
|
29805
|
+
else if (state.getItem("navigationSelection") !== null) void select(state.getItem("navigationSelection"));
|
|
29806
|
+
return { entries, dispose };
|
|
29807
|
+
}
|
|
29808
|
+
var IndexLogic = class {
|
|
29809
|
+
indexMount(node, { shell_id }) {
|
|
29810
|
+
const renderer = this.page.src.renderer;
|
|
29811
|
+
const element = renderer.destination.ownerDocument.getElementById(shell_id);
|
|
29812
|
+
this.index = mountIndexPage(renderer, renderer.elements.get(element).node);
|
|
29813
|
+
}
|
|
29814
|
+
};
|
|
29815
|
+
|
|
29816
|
+
// src/components/editor-options.js
|
|
29817
|
+
function codeMirrorWithOptions(parent, { datapath, value, language = "text", height = "420px", ...attributes }) {
|
|
29818
|
+
if (!datapath) throw new TypeError("codeMirrorWithOptions requires datapath");
|
|
29819
|
+
const pane = parent.borderContainer({ datapath, height, class: "gramlot-editor-options" });
|
|
29820
|
+
const defaults = {
|
|
29821
|
+
language,
|
|
29822
|
+
indentUnit: 4,
|
|
29823
|
+
fontSize: 14,
|
|
29824
|
+
fontFamily: "monospace",
|
|
29825
|
+
lineNumbers: true,
|
|
29826
|
+
lineWrapping: true,
|
|
29827
|
+
folding: true,
|
|
29828
|
+
bracketMatching: true,
|
|
29829
|
+
autoCloseBrackets: true,
|
|
29830
|
+
autoIndent: true,
|
|
29831
|
+
autocompletion: true,
|
|
29832
|
+
highlightActiveLine: true,
|
|
29833
|
+
highlightSelectionMatches: true
|
|
29468
29834
|
};
|
|
29469
|
-
const
|
|
29470
|
-
|
|
29471
|
-
|
|
29472
|
-
|
|
29473
|
-
|
|
29835
|
+
for (const [name, setting] of Object.entries(defaults)) pane.dataSetter({ destination_path: `.settings.${name}`, value: setting });
|
|
29836
|
+
const options = pane.contentPane({
|
|
29837
|
+
region: "right",
|
|
29838
|
+
width: "250px",
|
|
29839
|
+
drawer: "close",
|
|
29840
|
+
drawer_label: "Options",
|
|
29841
|
+
drawer_icon: "\u2699",
|
|
29842
|
+
drawer_minimize: false,
|
|
29843
|
+
padding: "12px",
|
|
29844
|
+
overflow: "auto",
|
|
29845
|
+
class: "gramlot-editor-settings"
|
|
29846
|
+
});
|
|
29847
|
+
options.h3("Editor options");
|
|
29848
|
+
options.filteringSelect({ value: "^.settings.language", lbl: "Language", values: "text:Plain text,python:Python,javascript:JavaScript,typescript:TypeScript,json:JSON,html:HTML,css:CSS,xml:XML,markdown:Markdown,sql:SQL,typst:Typst" });
|
|
29849
|
+
options.numberTextBox({ value: "^.settings.indentUnit", lbl: "Indent spaces", min: 1, max: 16, dtype: "L", validate_notnull: true });
|
|
29850
|
+
options.numberTextBox({ value: "^.settings.fontSize", lbl: "Font size", min: 8, max: 48, dtype: "L", validate_notnull: true });
|
|
29851
|
+
options.textbox({ value: "^.settings.fontFamily", lbl: "Font family" });
|
|
29852
|
+
const labels = {
|
|
29853
|
+
lineNumbers: "Line numbers",
|
|
29854
|
+
lineWrapping: "Wrap lines",
|
|
29855
|
+
folding: "Code folding",
|
|
29856
|
+
bracketMatching: "Match brackets",
|
|
29857
|
+
autoCloseBrackets: "Close brackets and quotes",
|
|
29858
|
+
autoIndent: "Automatic indentation",
|
|
29859
|
+
autocompletion: "Local completion",
|
|
29860
|
+
highlightActiveLine: "Highlight current line",
|
|
29861
|
+
highlightSelectionMatches: "Highlight matching selections"
|
|
29474
29862
|
};
|
|
29475
|
-
|
|
29476
|
-
|
|
29477
|
-
|
|
29478
|
-
|
|
29479
|
-
|
|
29480
|
-
|
|
29481
|
-
|
|
29482
|
-
|
|
29483
|
-
|
|
29484
|
-
|
|
29485
|
-
|
|
29486
|
-
|
|
29487
|
-
|
|
29488
|
-
|
|
29489
|
-
|
|
29490
|
-
|
|
29491
|
-
|
|
29492
|
-
|
|
29493
|
-
|
|
29494
|
-
|
|
29495
|
-
|
|
29496
|
-
|
|
29497
|
-
|
|
29863
|
+
for (const [name, label] of Object.entries(labels)) options.checkbox({ value: `^.settings.${name}`, label, display: "block", margin_top: "8px" });
|
|
29864
|
+
const center = pane.contentPane({ region: "center", min_height: 0 });
|
|
29865
|
+
center.codeMirror({ ...attributes, value, height: "100%", ...Object.fromEntries(Object.keys(defaults).map((name) => [name, `^.settings.${name}`])) });
|
|
29866
|
+
return pane;
|
|
29867
|
+
}
|
|
29868
|
+
|
|
29869
|
+
// src/filesystem.js
|
|
29870
|
+
var DirectoryResolver = class _DirectoryResolver extends RemoteResolver {
|
|
29871
|
+
static internalParams = /* @__PURE__ */ new Set([...RemoteResolver.internalParams, "gramlot", "method", "params", "onError"]);
|
|
29872
|
+
#closed = false;
|
|
29873
|
+
#controller = null;
|
|
29874
|
+
constructor({ gramlot, root, path = "", onError }) {
|
|
29875
|
+
super({ cacheTime: -1, onError });
|
|
29876
|
+
this.gramlot = gramlot;
|
|
29877
|
+
this.method = "directory_tree";
|
|
29878
|
+
this.params = { root, path };
|
|
29879
|
+
this.children = /* @__PURE__ */ new Set();
|
|
29880
|
+
}
|
|
29881
|
+
get closed() {
|
|
29882
|
+
return this.#closed;
|
|
29883
|
+
}
|
|
29884
|
+
startLoad(perform) {
|
|
29885
|
+
if (this.loading) return this.loading;
|
|
29886
|
+
const controller = new AbortController();
|
|
29887
|
+
this.#controller = controller;
|
|
29888
|
+
return perform({ controller, method: this.method, params: this.params, ignored: false });
|
|
29889
|
+
}
|
|
29890
|
+
async loadAsync({ controller, method, params }) {
|
|
29891
|
+
const { signal } = controller;
|
|
29892
|
+
let abort;
|
|
29893
|
+
const cancelled = new Promise((_, reject) => {
|
|
29894
|
+
abort = () => reject(signal.reason);
|
|
29895
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
29896
|
+
});
|
|
29897
|
+
try {
|
|
29898
|
+
const value = await Promise.race([this.gramlot.rpc.call("data", method, params, { signal }), cancelled]);
|
|
29899
|
+
if (signal.aborted) throw signal.reason;
|
|
29900
|
+
return value;
|
|
29901
|
+
} finally {
|
|
29902
|
+
signal.removeEventListener("abort", abort);
|
|
29903
|
+
if (this.#controller === controller) this.#controller = null;
|
|
29904
|
+
}
|
|
29905
|
+
}
|
|
29906
|
+
prepareValue(bag) {
|
|
29907
|
+
if (!(bag instanceof Bag)) throw new TypeError("directory_tree must return a Bag");
|
|
29908
|
+
for (const child of this.children) child.abort();
|
|
29909
|
+
this.children.clear();
|
|
29910
|
+
for (const node of bag.getNodes()) {
|
|
29911
|
+
if (node.attr.is_directory) {
|
|
29912
|
+
const resolver = new _DirectoryResolver({
|
|
29913
|
+
gramlot: this.gramlot,
|
|
29914
|
+
root: this.params.root,
|
|
29915
|
+
path: node.attr.path,
|
|
29916
|
+
onError: this.onError
|
|
29498
29917
|
});
|
|
29918
|
+
this.children.add(resolver);
|
|
29919
|
+
bag.setResolver(node.label, resolver);
|
|
29499
29920
|
}
|
|
29500
|
-
return;
|
|
29501
29921
|
}
|
|
29502
|
-
|
|
29503
|
-
|
|
29922
|
+
return bag;
|
|
29923
|
+
}
|
|
29924
|
+
abort() {
|
|
29925
|
+
this.#closed = true;
|
|
29926
|
+
this.#controller?.abort();
|
|
29927
|
+
for (const child of this.children) child.abort();
|
|
29928
|
+
this.children.clear();
|
|
29929
|
+
}
|
|
29930
|
+
};
|
|
29931
|
+
var FileSystemController = class {
|
|
29932
|
+
constructor(gramlot, state) {
|
|
29933
|
+
this.gramlot = gramlot;
|
|
29934
|
+
this.state = state;
|
|
29935
|
+
this.request = null;
|
|
29936
|
+
this.resolver = null;
|
|
29937
|
+
this.disposed = false;
|
|
29938
|
+
}
|
|
29939
|
+
async open(root) {
|
|
29940
|
+
this.request?.abort();
|
|
29941
|
+
const request = this.request = new AbortController();
|
|
29942
|
+
this.state.setItem("status", "Opening directory\u2026");
|
|
29504
29943
|
try {
|
|
29505
|
-
const
|
|
29506
|
-
|
|
29507
|
-
|
|
29508
|
-
|
|
29509
|
-
|
|
29510
|
-
|
|
29511
|
-
|
|
29512
|
-
|
|
29513
|
-
|
|
29514
|
-
|
|
29515
|
-
|
|
29516
|
-
|
|
29517
|
-
|
|
29518
|
-
|
|
29519
|
-
|
|
29944
|
+
const result = await this.gramlot.rpc.call("data", "workspace_open", { root }, { signal: request.signal });
|
|
29945
|
+
if (this.disposed || request.signal.aborted) return null;
|
|
29946
|
+
const resolver = new DirectoryResolver({
|
|
29947
|
+
gramlot: this.gramlot,
|
|
29948
|
+
root: result.root,
|
|
29949
|
+
onError: (error) => this.state.setItem("status", error.message)
|
|
29950
|
+
});
|
|
29951
|
+
const store = resolver.prepareValue(result.entries);
|
|
29952
|
+
this.resolver?.abort();
|
|
29953
|
+
this.resolver = resolver;
|
|
29954
|
+
this.state.setItem("selectedPath", null);
|
|
29955
|
+
this.state.setItem("store", store);
|
|
29956
|
+
this.state.setItem("root", result.root);
|
|
29957
|
+
this.state.setItem("status", "");
|
|
29958
|
+
return result.root;
|
|
29959
|
+
} catch (error) {
|
|
29960
|
+
if (!this.disposed && !request.signal.aborted) this.state.setItem("status", error.message);
|
|
29961
|
+
return null;
|
|
29520
29962
|
} finally {
|
|
29521
|
-
|
|
29963
|
+
if (this.request === request) this.request = null;
|
|
29522
29964
|
}
|
|
29523
29965
|
}
|
|
29524
|
-
|
|
29525
|
-
|
|
29526
|
-
|
|
29527
|
-
|
|
29528
|
-
|
|
29529
|
-
|
|
29530
|
-
|
|
29531
|
-
|
|
29532
|
-
|
|
29533
|
-
|
|
29534
|
-
|
|
29535
|
-
|
|
29536
|
-
|
|
29537
|
-
|
|
29538
|
-
|
|
29539
|
-
|
|
29540
|
-
|
|
29541
|
-
|
|
29542
|
-
|
|
29543
|
-
|
|
29544
|
-
|
|
29545
|
-
|
|
29546
|
-
|
|
29547
|
-
|
|
29548
|
-
};
|
|
29549
|
-
|
|
29550
|
-
|
|
29551
|
-
|
|
29552
|
-
|
|
29553
|
-
|
|
29554
|
-
|
|
29555
|
-
|
|
29556
|
-
|
|
29557
|
-
|
|
29558
|
-
|
|
29559
|
-
|
|
29560
|
-
|
|
29561
|
-
|
|
29562
|
-
|
|
29563
|
-
|
|
29564
|
-
|
|
29565
|
-
|
|
29566
|
-
|
|
29567
|
-
|
|
29568
|
-
|
|
29569
|
-
|
|
29570
|
-
|
|
29571
|
-
|
|
29572
|
-
|
|
29573
|
-
|
|
29574
|
-
|
|
29575
|
-
|
|
29576
|
-
|
|
29577
|
-
|
|
29578
|
-
|
|
29579
|
-
|
|
29580
|
-
|
|
29581
|
-
|
|
29582
|
-
|
|
29583
|
-
|
|
29584
|
-
|
|
29585
|
-
|
|
29586
|
-
|
|
29587
|
-
}
|
|
29588
|
-
|
|
29589
|
-
|
|
29590
|
-
|
|
29591
|
-
|
|
29592
|
-
|
|
29593
|
-
|
|
29594
|
-
|
|
29595
|
-
|
|
29596
|
-
|
|
29597
|
-
|
|
29598
|
-
|
|
29599
|
-
|
|
29600
|
-
|
|
29601
|
-
|
|
29602
|
-
|
|
29603
|
-
|
|
29604
|
-
|
|
29605
|
-
|
|
29606
|
-
|
|
29607
|
-
|
|
29608
|
-
|
|
29966
|
+
dispose() {
|
|
29967
|
+
this.disposed = true;
|
|
29968
|
+
this.request?.abort();
|
|
29969
|
+
this.resolver?.abort();
|
|
29970
|
+
}
|
|
29971
|
+
};
|
|
29972
|
+
var FileSystemLogic = class {
|
|
29973
|
+
fileSystemMount(node) {
|
|
29974
|
+
this.fileSystems ??= /* @__PURE__ */ new WeakMap();
|
|
29975
|
+
const scope = node.parentNode, state = scope.getRelativeData(".");
|
|
29976
|
+
const controller = new FileSystemController(this.page, state);
|
|
29977
|
+
this.fileSystems.set(state, controller);
|
|
29978
|
+
this.page.src.renderer.onDispose(scope, () => controller.dispose());
|
|
29979
|
+
}
|
|
29980
|
+
fileSystemOpen(node, { root }) {
|
|
29981
|
+
if (root) return this.fileSystems.get(node.getRelativeData(".")).open(root);
|
|
29982
|
+
}
|
|
29983
|
+
};
|
|
29984
|
+
function fileSystemTree(parent, { datapath, ...attributes }) {
|
|
29985
|
+
const pane = parent.div({ datapath, class: "gramlot-filesystem", ...attributes });
|
|
29986
|
+
pane.dataSetter({ destination_path: ".store", value: new Bag() });
|
|
29987
|
+
pane.dataSetter({ destination_path: ".root", value: null });
|
|
29988
|
+
pane.dataSetter({ destination_path: ".requestedRoot", value: null });
|
|
29989
|
+
pane.dataSetter({ destination_path: ".selectedPath", value: null });
|
|
29990
|
+
pane.dataSetter({ destination_path: ".status", value: "" });
|
|
29991
|
+
pane.dataController({ func: "fileSystemMount", _onBuilt: true });
|
|
29992
|
+
pane.dataController({ func: "fileSystemOpen", root: "^.requestedRoot" });
|
|
29993
|
+
pane.tree({
|
|
29994
|
+
storepath: ".store",
|
|
29995
|
+
selectedPath: "^.selectedPath",
|
|
29996
|
+
labelAttribute: "caption",
|
|
29997
|
+
hideValues: true,
|
|
29998
|
+
class: "gramlot-filesystem-tree"
|
|
29999
|
+
});
|
|
30000
|
+
pane.div("^.status", { role: "status", class: "gramlot-filesystem-status" });
|
|
30001
|
+
return pane;
|
|
30002
|
+
}
|
|
30003
|
+
|
|
30004
|
+
// src/ide-documents.js
|
|
30005
|
+
var documentKey = (root, path) => "d_" + [...new TextEncoder().encode(JSON.stringify([root, path]))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
30006
|
+
var IdeDocuments = class {
|
|
30007
|
+
constructor(gramlot, state) {
|
|
30008
|
+
this.gramlot = gramlot;
|
|
30009
|
+
this.state = state;
|
|
30010
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
30011
|
+
this.disposed = false;
|
|
30012
|
+
}
|
|
30013
|
+
get documents() {
|
|
30014
|
+
return this.state.getItem("documents");
|
|
30015
|
+
}
|
|
30016
|
+
async open(root, path) {
|
|
30017
|
+
const key = documentKey(root, path);
|
|
30018
|
+
const existing = this.documents.getNodes().find((node) => !node.value.getItem("isNew") && node.value.getItem("root") === root && node.value.getItem("path") === path);
|
|
30019
|
+
if (existing) return existing.label;
|
|
30020
|
+
if (this.pending.has(key)) return this.pending.get(key).promise;
|
|
30021
|
+
const request = new AbortController();
|
|
30022
|
+
const promise = this.gramlot.rpc.call("data", "document_read", { root, path }, { signal: request.signal }).then((result) => {
|
|
30023
|
+
if (this.disposed || request.signal.aborted) return null;
|
|
30024
|
+
const document = new Bag();
|
|
30025
|
+
for (const [name, value] of Object.entries({ ...result, root, saved: result.content, busy: false })) document.setItem(name, value);
|
|
30026
|
+
this.documents.setItem(key, document);
|
|
30027
|
+
return key;
|
|
30028
|
+
}).finally(() => this.pending.delete(key));
|
|
30029
|
+
this.pending.set(key, { request, promise });
|
|
30030
|
+
return promise;
|
|
30031
|
+
}
|
|
30032
|
+
newDocument(language, extension, root = "") {
|
|
30033
|
+
const key = `new_${crypto.randomUUID().replaceAll("-", "")}`;
|
|
30034
|
+
const doc = new Bag();
|
|
30035
|
+
for (const [name, value] of Object.entries({
|
|
30036
|
+
language,
|
|
30037
|
+
root,
|
|
30038
|
+
path: `Untitled${extension}`,
|
|
30039
|
+
content: "",
|
|
30040
|
+
saved: "",
|
|
30041
|
+
writable: true,
|
|
30042
|
+
busy: false,
|
|
30043
|
+
isNew: true,
|
|
30044
|
+
createHidden: true,
|
|
30045
|
+
saveRoot: root,
|
|
30046
|
+
savePath: `Untitled${extension}`
|
|
30047
|
+
})) doc.setItem(name, value);
|
|
30048
|
+
this.documents.setItem(key, doc);
|
|
30049
|
+
return key;
|
|
30050
|
+
}
|
|
30051
|
+
async create(key) {
|
|
30052
|
+
const doc = this.documents.getItem(key);
|
|
30053
|
+
if (!doc || !doc.getItem("isNew") || this.pending.has(key)) return false;
|
|
30054
|
+
const root = doc.getItem("saveRoot"), path = doc.getItem("savePath");
|
|
30055
|
+
if (doc.getItem("path").endsWith(".typ.py") !== path.endsWith(".typ.py")) {
|
|
30056
|
+
throw new Error("The .typ.py extension is required for the Typst Python recipe document type.");
|
|
30057
|
+
}
|
|
30058
|
+
const content = doc.getItem("content"), request = new AbortController();
|
|
30059
|
+
doc.setItem("busy", true);
|
|
30060
|
+
const promise = this.gramlot.rpc.call(
|
|
30061
|
+
"data",
|
|
30062
|
+
"document_create",
|
|
30063
|
+
{ root, path, content },
|
|
30064
|
+
{ signal: request.signal }
|
|
30065
|
+
).then((result) => {
|
|
30066
|
+
if (this.disposed || request.signal.aborted) return false;
|
|
30067
|
+
doc.setItem("root", result.root);
|
|
30068
|
+
doc.setItem("path", result.path);
|
|
30069
|
+
doc.setItem("revision", result.revision);
|
|
30070
|
+
doc.setItem("saved", content);
|
|
30071
|
+
doc.setItem("isNew", false);
|
|
30072
|
+
doc.setItem("createHidden", true);
|
|
30073
|
+
return true;
|
|
30074
|
+
}).finally(() => {
|
|
30075
|
+
this.pending.delete(key);
|
|
30076
|
+
if (!this.disposed) doc.setItem("busy", false);
|
|
30077
|
+
});
|
|
30078
|
+
this.pending.set(key, { request, promise });
|
|
30079
|
+
return promise;
|
|
30080
|
+
}
|
|
30081
|
+
invalidateRecipe(key) {
|
|
30082
|
+
const doc = this.documents.getItem(key);
|
|
30083
|
+
if (!doc.getItem("path").endsWith(".typ.py")) return;
|
|
30084
|
+
if (doc.getItem("rendering")) this.pending.get(key)?.request.abort();
|
|
30085
|
+
doc.setItem("previewHidden", true);
|
|
30086
|
+
doc.setItem("typstSource", "");
|
|
30087
|
+
doc.setItem("renderStatus", "Generate preview to render the current Python recipe.");
|
|
30088
|
+
}
|
|
30089
|
+
async renderRecipe(key) {
|
|
30090
|
+
const doc = this.documents.getItem(key);
|
|
30091
|
+
if (!doc || !doc.getItem("path").endsWith(".typ.py") || !doc.getItem("writable") || this.pending.has(key)) return false;
|
|
30092
|
+
const content = doc.getItem("content"), request = new AbortController();
|
|
30093
|
+
doc.setItem("busy", true);
|
|
30094
|
+
doc.setItem("rendering", true);
|
|
30095
|
+
doc.setItem("previewHidden", true);
|
|
30096
|
+
doc.setItem("typstSource", "");
|
|
30097
|
+
doc.setItem("renderStatus", "Generating Typst on the server\u2026");
|
|
30098
|
+
const promise = this.gramlot.rpc.call(
|
|
30099
|
+
"data",
|
|
30100
|
+
"document_render_typst",
|
|
30101
|
+
{ content },
|
|
30102
|
+
{ signal: request.signal }
|
|
30103
|
+
).then((result) => {
|
|
30104
|
+
if (this.disposed || request.signal.aborted || doc.getItem("content") !== content) return false;
|
|
30105
|
+
doc.setItem("typstSource", result.source);
|
|
30106
|
+
doc.setItem("previewHidden", false);
|
|
30107
|
+
doc.setItem("renderStatus", "Typst generated from the current recipe.");
|
|
30108
|
+
return true;
|
|
30109
|
+
}).catch((error) => {
|
|
30110
|
+
if (!this.disposed && !request.signal.aborted) doc.setItem("renderStatus", error.message);
|
|
30111
|
+
return false;
|
|
30112
|
+
}).finally(() => {
|
|
30113
|
+
this.pending.delete(key);
|
|
30114
|
+
if (!this.disposed) {
|
|
30115
|
+
doc.setItem("rendering", false);
|
|
30116
|
+
doc.setItem("busy", false);
|
|
29609
30117
|
}
|
|
29610
|
-
const border = shell.querySelector("[data-index-regions]");
|
|
29611
|
-
const handle = gramlot.subscribe(`${node(border).getAttr("nodeId")}_splitter_resize`, ({ region, size }) => {
|
|
29612
|
-
set(region === "left" ? sidebar : codeSidebar, { width: size });
|
|
29613
|
-
state.setItem(region === "left" ? "preferredSidebarWidth" : "preferredCodeWidth", Number.parseFloat(size));
|
|
29614
|
-
savePreferences();
|
|
29615
|
-
});
|
|
29616
|
-
releases.push(() => gramlot.unsubscribe(handle));
|
|
29617
|
-
state.setItem("preferredSidebarWidth", preferences.sidebarWidth);
|
|
29618
|
-
state.setItem("preferredCodeWidth", preferences.codeWidth);
|
|
29619
|
-
}
|
|
29620
|
-
listen(navigationToggle, "click", () => {
|
|
29621
|
-
state.setItem("navigationVisible", !state.getItem("navigationVisible"));
|
|
29622
|
-
updatePanels();
|
|
29623
|
-
savePreferences();
|
|
29624
30118
|
});
|
|
29625
|
-
|
|
29626
|
-
|
|
29627
|
-
|
|
29628
|
-
|
|
30119
|
+
this.pending.set(key, { request, promise });
|
|
30120
|
+
return promise;
|
|
30121
|
+
}
|
|
30122
|
+
dirty(key) {
|
|
30123
|
+
const doc = this.documents.getItem(key);
|
|
30124
|
+
return doc && doc.getItem("content") !== doc.getItem("saved");
|
|
30125
|
+
}
|
|
30126
|
+
async save(key) {
|
|
30127
|
+
const doc = this.documents.getItem(key);
|
|
30128
|
+
if (!doc || doc.getItem("isNew") || !this.dirty(key) || !doc.getItem("writable") || this.pending.has(key)) return false;
|
|
30129
|
+
const content = doc.getItem("content"), request = new AbortController();
|
|
30130
|
+
doc.setItem("busy", true);
|
|
30131
|
+
const promise = this.gramlot.rpc.call("data", "document_save", {
|
|
30132
|
+
root: doc.getItem("root"),
|
|
30133
|
+
path: doc.getItem("path"),
|
|
30134
|
+
content,
|
|
30135
|
+
revision: doc.getItem("revision")
|
|
30136
|
+
}, { signal: request.signal }).then((result) => {
|
|
30137
|
+
if (this.disposed || request.signal.aborted) return false;
|
|
30138
|
+
doc.setItem("revision", result.revision);
|
|
30139
|
+
doc.setItem("saved", content);
|
|
30140
|
+
return true;
|
|
30141
|
+
}).finally(() => {
|
|
30142
|
+
this.pending.delete(key);
|
|
30143
|
+
if (!this.disposed) doc.setItem("busy", false);
|
|
30144
|
+
});
|
|
30145
|
+
this.pending.set(key, { request, promise });
|
|
30146
|
+
return promise;
|
|
30147
|
+
}
|
|
30148
|
+
revert(key) {
|
|
30149
|
+
const doc = this.documents.getItem(key);
|
|
30150
|
+
if (!doc || !this.dirty(key) || this.pending.has(key)) return false;
|
|
30151
|
+
doc.setItem("content", doc.getItem("saved"));
|
|
30152
|
+
return true;
|
|
30153
|
+
}
|
|
30154
|
+
canClose(key, discard = false) {
|
|
30155
|
+
return !this.pending.has(key) && (discard || !this.dirty(key));
|
|
30156
|
+
}
|
|
30157
|
+
close(key, discard = false) {
|
|
30158
|
+
if (!this.canClose(key, discard)) return false;
|
|
30159
|
+
this.documents.popNode(key);
|
|
30160
|
+
if (this.state.getItem("active") === key) this.state.setItem("active", this.documents.getNodes()[0]?.label ?? null);
|
|
30161
|
+
return true;
|
|
30162
|
+
}
|
|
30163
|
+
dispose() {
|
|
30164
|
+
this.disposed = true;
|
|
30165
|
+
for (const { request } of this.pending.values()) request.abort();
|
|
30166
|
+
}
|
|
30167
|
+
};
|
|
30168
|
+
var RecentWorkspaces = class {
|
|
30169
|
+
constructor(storage) {
|
|
30170
|
+
this.storage = storage;
|
|
30171
|
+
this.key = "gramlot.ide.recentWorkspaces";
|
|
30172
|
+
}
|
|
30173
|
+
read() {
|
|
30174
|
+
const stored = this.storage.getItem(this.key);
|
|
30175
|
+
const roots = stored === null ? [] : JSON.parse(stored);
|
|
30176
|
+
if (!Array.isArray(roots) || roots.some((root) => typeof root !== "string" || !root)) throw new TypeError("Invalid recent workspace preference");
|
|
30177
|
+
return roots.slice(0, 6);
|
|
30178
|
+
}
|
|
30179
|
+
remember(root) {
|
|
30180
|
+
const roots = [root, ...this.read().filter((item) => item !== root)].slice(0, 6);
|
|
30181
|
+
this.storage.setItem(this.key, JSON.stringify(roots));
|
|
30182
|
+
return roots;
|
|
30183
|
+
}
|
|
30184
|
+
choices(roots = this.read()) {
|
|
30185
|
+
const bag = new Bag();
|
|
30186
|
+
roots.forEach((root, index) => bag.setItem(`r${index}`, root, { caption: root }));
|
|
30187
|
+
return bag;
|
|
30188
|
+
}
|
|
30189
|
+
};
|
|
30190
|
+
|
|
30191
|
+
// src/ide-runtime.js
|
|
30192
|
+
var IdeLogic = class {
|
|
30193
|
+
fileSystemMount(node) {
|
|
30194
|
+
return FileSystemLogic.prototype.fileSystemMount.call(this, node);
|
|
30195
|
+
}
|
|
30196
|
+
fileSystemOpen(node, args) {
|
|
30197
|
+
return FileSystemLogic.prototype.fileSystemOpen.call(this, node, args);
|
|
30198
|
+
}
|
|
30199
|
+
ideMount(node) {
|
|
30200
|
+
this.ideRoot = node.parentNode;
|
|
30201
|
+
this.ideState = node.getRelativeData(".");
|
|
30202
|
+
this.ideDocuments = new IdeDocuments(this.page, this.ideState);
|
|
30203
|
+
this.idePanels = /* @__PURE__ */ new Map();
|
|
30204
|
+
this.ideDisposed = false;
|
|
30205
|
+
this.ideRequested = 0;
|
|
30206
|
+
this.ideRecent = new RecentWorkspaces(this.page.src.renderer.destination.ownerDocument.defaultView.sessionStorage);
|
|
30207
|
+
const roots = this.ideRecent.read();
|
|
30208
|
+
this.ideState.setItem("recent", this.ideRecent.choices(roots));
|
|
30209
|
+
this.ideState.setItem("workspace", roots[0] ?? "");
|
|
30210
|
+
const browser = this.ideState.getItem("browser");
|
|
30211
|
+
browser.subscribe("ide-browser", { any: (event) => {
|
|
30212
|
+
if (event.node === browser.getNode("root")) {
|
|
30213
|
+
const root = browser.getItem("root");
|
|
30214
|
+
this.ideState.setItem("workspace", root);
|
|
30215
|
+
this.ideState.setItem("recent", this.ideRecent.choices(this.ideRecent.remember(root)));
|
|
30216
|
+
this.ideState.setItem("status", `Workspace: ${root}`);
|
|
30217
|
+
} else if (event.node === browser.getNode("selectedPath")) {
|
|
30218
|
+
const path = browser.getItem("selectedPath");
|
|
30219
|
+
const item = path === null ? null : browser.getItem("store").getNode(path);
|
|
30220
|
+
if (item && !item.attr.is_directory) void this.ideOpenDocument(browser.getItem("root"), item.attr.path);
|
|
30221
|
+
}
|
|
30222
|
+
} });
|
|
30223
|
+
this.ideDocuments.documents.subscribe("ide-documents", { any: (event) => {
|
|
30224
|
+
if (!["content", "saved", "busy", "writable", "view", "isNew", "path", "root"].includes(event.node.label)) return;
|
|
30225
|
+
for (const [key, pane] of this.idePanels) {
|
|
30226
|
+
const doc = this.ideDocuments.documents.getItem(key);
|
|
30227
|
+
if (doc) {
|
|
30228
|
+
if (event.node === doc.getNode("content")) this.ideDocuments.invalidateRecipe(key);
|
|
30229
|
+
this.ideDocumentState(key);
|
|
30230
|
+
pane.setAttr({ title: `${this.ideDocuments.dirty(key) ? "\u25CF " : ""}${doc.getItem("path")}` });
|
|
30231
|
+
}
|
|
30232
|
+
}
|
|
30233
|
+
} });
|
|
30234
|
+
this.page.src.renderer.onDispose(this.ideRoot, () => {
|
|
30235
|
+
this.ideDisposed = true;
|
|
30236
|
+
browser.unsubscribe("ide-browser", { any: true });
|
|
30237
|
+
this.ideDocuments.documents.unsubscribe("ide-documents", { any: true });
|
|
30238
|
+
this.ideDocuments.dispose();
|
|
29629
30239
|
});
|
|
29630
|
-
|
|
29631
|
-
|
|
29632
|
-
|
|
29633
|
-
|
|
29634
|
-
|
|
29635
|
-
|
|
29636
|
-
|
|
29637
|
-
|
|
29638
|
-
|
|
29639
|
-
|
|
29640
|
-
|
|
29641
|
-
|
|
29642
|
-
|
|
29643
|
-
|
|
29644
|
-
|
|
29645
|
-
|
|
29646
|
-
|
|
29647
|
-
|
|
29648
|
-
|
|
29649
|
-
|
|
29650
|
-
|
|
29651
|
-
|
|
29652
|
-
|
|
29653
|
-
|
|
29654
|
-
|
|
29655
|
-
|
|
29656
|
-
|
|
29657
|
-
|
|
29658
|
-
|
|
29659
|
-
|
|
29660
|
-
|
|
29661
|
-
|
|
29662
|
-
|
|
29663
|
-
|
|
29664
|
-
|
|
29665
|
-
|
|
29666
|
-
|
|
30240
|
+
}
|
|
30241
|
+
ideOpenWorkspace() {
|
|
30242
|
+
const root = this.ideState.getItem("workspace");
|
|
30243
|
+
if (root && root !== this.ideState.getItem("browser.root")) this.ideState.setItem("browser.requestedRoot", root);
|
|
30244
|
+
}
|
|
30245
|
+
ideDocumentState(key) {
|
|
30246
|
+
const doc = this.ideDocuments.documents.getItem(key);
|
|
30247
|
+
const disabled = !this.ideDocuments.dirty(key) && !doc.getItem("isNew") || doc.getItem("busy");
|
|
30248
|
+
doc.setItem("saveDisabled", Boolean(disabled || !doc.getItem("writable")));
|
|
30249
|
+
doc.setItem("revertDisabled", Boolean(!this.ideDocuments.dirty(key) || doc.getItem("busy")));
|
|
30250
|
+
doc.setItem("displayPath", doc.getItem("isNew") ? doc.getItem("path") : `${doc.getItem("root")}/${doc.getItem("path")}`);
|
|
30251
|
+
doc.setItem("pdfFilename", doc.getItem("path").split("/").at(-1).replace(/\.typ(?:\.py)?$/i, ".pdf"));
|
|
30252
|
+
doc.setItem("renderDisabled", Boolean(doc.getItem("busy") || !doc.getItem("writable")));
|
|
30253
|
+
this.ideHistoryState(doc);
|
|
30254
|
+
}
|
|
30255
|
+
async ideOpenDocument(root, path) {
|
|
30256
|
+
const requested = ++this.ideRequested;
|
|
30257
|
+
try {
|
|
30258
|
+
const key = await this.ideDocuments.open(root, path);
|
|
30259
|
+
if (key === null || this.ideDisposed) return;
|
|
30260
|
+
this.ideShowDocument(key);
|
|
30261
|
+
if (requested === this.ideRequested) {
|
|
30262
|
+
this.ideState.setItem("active", key);
|
|
30263
|
+
this.ideState.setItem("status", `${path}${this.ideDocuments.documents.getItem(key).getItem("writable") ? "" : " (read only)"}`);
|
|
30264
|
+
}
|
|
30265
|
+
} catch (error) {
|
|
30266
|
+
if (!this.ideDisposed) this.ideState.setItem("status", error.message);
|
|
30267
|
+
}
|
|
30268
|
+
}
|
|
30269
|
+
ideNew() {
|
|
30270
|
+
const type = this.ideState.getItem("newType");
|
|
30271
|
+
const language = type === "typstRecipe" ? "python" : type;
|
|
30272
|
+
const extensions = {
|
|
30273
|
+
typstRecipe: ".typ.py",
|
|
30274
|
+
typst: ".typ",
|
|
30275
|
+
markdown: ".md",
|
|
30276
|
+
html: ".html",
|
|
30277
|
+
python: ".py",
|
|
30278
|
+
javascript: ".js",
|
|
30279
|
+
typescript: ".ts",
|
|
30280
|
+
json: ".json",
|
|
30281
|
+
css: ".css",
|
|
30282
|
+
sql: ".sql",
|
|
30283
|
+
xml: ".xml",
|
|
30284
|
+
text: ".txt"
|
|
30285
|
+
};
|
|
30286
|
+
const key = this.ideDocuments.newDocument(language, extensions[type], this.ideState.getItem("workspace"));
|
|
30287
|
+
++this.ideRequested;
|
|
30288
|
+
this.ideShowDocument(key);
|
|
30289
|
+
this.ideState.setItem("active", key);
|
|
30290
|
+
this.ideState.setItem("status", "New document. Choose directory and name when saving.");
|
|
30291
|
+
}
|
|
30292
|
+
ideShowDocument(key) {
|
|
30293
|
+
const document = this.ideDocuments.documents.getItem(key);
|
|
30294
|
+
const path = document.getItem("path");
|
|
30295
|
+
if (!this.idePanels.has(key)) {
|
|
30296
|
+
const doc = this.ideDocuments.documents.getItem(key);
|
|
30297
|
+
const recipe = path.endsWith(".typ.py");
|
|
30298
|
+
if (recipe) this.ideDocuments.invalidateRecipe(key);
|
|
30299
|
+
doc.setItem("readonly", !doc.getItem("writable"));
|
|
30300
|
+
this.ideDocumentState(key);
|
|
30301
|
+
doc.setItem("view", "code");
|
|
30302
|
+
doc.setItem("createHidden", true);
|
|
30303
|
+
doc.setItem("undoDisabled", true);
|
|
30304
|
+
doc.setItem("redoDisabled", true);
|
|
30305
|
+
const tabs = this.ideRoot.value.getNode("frame.center.tabs");
|
|
30306
|
+
const pane = sourceTarget(tabs.builder.wrapSource(tabs).contentPane({
|
|
30307
|
+
node_label: key,
|
|
30308
|
+
title: path,
|
|
30309
|
+
pageName: key,
|
|
30310
|
+
documentKey: key,
|
|
30311
|
+
closable: true,
|
|
30312
|
+
onClose: "ideClose",
|
|
30313
|
+
height: "100%"
|
|
30314
|
+
}));
|
|
30315
|
+
this.idePanels.set(key, pane);
|
|
30316
|
+
const target = pane.builder.wrapSource(pane).div({ display: "flex", flex_direction: "column", height: "100%" });
|
|
30317
|
+
const toolbar = target.div({
|
|
30318
|
+
datapath: `.documents.${key}`,
|
|
30319
|
+
display: "flex",
|
|
30320
|
+
align_items: "center",
|
|
30321
|
+
gap: "6px",
|
|
30322
|
+
padding: "4px 12px",
|
|
30323
|
+
height: "40px",
|
|
30324
|
+
flex_shrink: 0,
|
|
30325
|
+
box_sizing: "border-box",
|
|
30326
|
+
class: "gramlot-ide-document-toolbar",
|
|
30327
|
+
role: "toolbar",
|
|
30328
|
+
"aria-label": `Commands for ${path}`
|
|
29667
30329
|
});
|
|
29668
|
-
|
|
29669
|
-
|
|
29670
|
-
|
|
29671
|
-
|
|
29672
|
-
|
|
29673
|
-
|
|
29674
|
-
|
|
29675
|
-
|
|
29676
|
-
|
|
29677
|
-
|
|
29678
|
-
|
|
29679
|
-
|
|
29680
|
-
|
|
29681
|
-
|
|
29682
|
-
|
|
29683
|
-
|
|
29684
|
-
|
|
29685
|
-
|
|
29686
|
-
|
|
30330
|
+
for (const [name, path2, label, func] of [
|
|
30331
|
+
["save", "M5 3h12l4 4v14H3V3h2 M7 3v6h10V3 M7 21v-8h10v8", "Save", "ideSave"],
|
|
30332
|
+
["revert", "M3 10a9 9 0 1 1 2 8 M3 4v6h6 M12 7v5l3 2", "Revert to saved", "ideRevert"],
|
|
30333
|
+
["undo", "M9 5 3 11l6 6 M3 11h12a6 6 0 0 1 6 6v2", "Undo", "ideUndo"],
|
|
30334
|
+
["redo", "m15 5 6 6-6 6 M21 11H9a6 6 0 0 0-6 6v2", "Redo", "ideRedo"]
|
|
30335
|
+
]) {
|
|
30336
|
+
const button = toolbar.button({
|
|
30337
|
+
title: label,
|
|
30338
|
+
"aria-label": label,
|
|
30339
|
+
disabled: `^.${name}Disabled`,
|
|
30340
|
+
class: `button--quiet gramlot-ide-${name}`
|
|
30341
|
+
});
|
|
30342
|
+
button.svg({
|
|
30343
|
+
viewBox: "0 0 24 24",
|
|
30344
|
+
width: 18,
|
|
30345
|
+
height: 18,
|
|
30346
|
+
fill: "none",
|
|
30347
|
+
stroke: "currentColor",
|
|
30348
|
+
stroke_width: 1.7,
|
|
30349
|
+
stroke_linecap: "round",
|
|
30350
|
+
stroke_linejoin: "round",
|
|
30351
|
+
"aria-hidden": "true"
|
|
30352
|
+
}).path({ d: path2 });
|
|
30353
|
+
button.dataController({ func, documentKey: key });
|
|
30354
|
+
}
|
|
30355
|
+
if (recipe) toolbar.button("Generate preview", { disabled: "^.renderDisabled", class: "button--quiet" }).dataController({ func: "ideRenderRecipe", documentKey: key });
|
|
30356
|
+
toolbar.div("^.displayPath", {
|
|
30357
|
+
class: "gramlot-ide-document-path",
|
|
30358
|
+
overflow: "hidden",
|
|
30359
|
+
text_overflow: "ellipsis",
|
|
30360
|
+
white_space: "nowrap",
|
|
30361
|
+
min_width: 0,
|
|
30362
|
+
flex: "1"
|
|
29687
30363
|
});
|
|
29688
|
-
|
|
29689
|
-
|
|
29690
|
-
|
|
29691
|
-
|
|
29692
|
-
|
|
29693
|
-
|
|
29694
|
-
|
|
29695
|
-
|
|
30364
|
+
const form = target.div({
|
|
30365
|
+
datapath: `.documents.${key}`,
|
|
30366
|
+
hidden: "^.createHidden",
|
|
30367
|
+
padding: "8px 12px",
|
|
30368
|
+
display: "flex",
|
|
30369
|
+
gap: "8px",
|
|
30370
|
+
align_items: "end",
|
|
30371
|
+
flex_shrink: 0
|
|
29696
30372
|
});
|
|
29697
|
-
|
|
29698
|
-
|
|
29699
|
-
|
|
29700
|
-
|
|
29701
|
-
|
|
29702
|
-
const
|
|
29703
|
-
|
|
29704
|
-
|
|
29705
|
-
|
|
29706
|
-
|
|
30373
|
+
form.textbox({ value: "^.saveRoot", lbl: "Directory", flex: "1", disabled: "^.busy" });
|
|
30374
|
+
form.textbox({ value: "^.savePath", lbl: "File name", flex: "1", disabled: "^.busy" });
|
|
30375
|
+
form.button("Create file", { disabled: "^.busy" }).dataController({ func: "ideCreate", documentKey: key });
|
|
30376
|
+
form.button("Cancel", { disabled: "^.busy", class: "button--quiet" }).dataController({ func: "ideCancelCreate", documentKey: key });
|
|
30377
|
+
const editorArea = target.div({ flex: "1", min_height: 0 });
|
|
30378
|
+
const html = doc.getItem("language") === "html";
|
|
30379
|
+
const markdown = doc.getItem("language") === "markdown";
|
|
30380
|
+
const rich = html || markdown;
|
|
30381
|
+
const typst = doc.getItem("language") === "typst";
|
|
30382
|
+
const preview = rich || typst || recipe;
|
|
30383
|
+
const views = preview ? editorArea.tabContainer({ height: "100%", selectedPage: `^.documents.${key}.view` }) : null;
|
|
30384
|
+
const code = preview ? views.contentPane({ title: "Code", pageName: "code", height: "100%" }) : editorArea;
|
|
30385
|
+
codeMirrorWithOptions(code, {
|
|
30386
|
+
datapath: `.documents.${key}`,
|
|
30387
|
+
value: "^.content",
|
|
30388
|
+
language: doc.getItem("language"),
|
|
30389
|
+
height: "100%",
|
|
30390
|
+
readonly: "^.readonly",
|
|
30391
|
+
nodeId: `editor_${key}`,
|
|
30392
|
+
editorView: "code",
|
|
30393
|
+
selfsubscribe_historyChanged: "ideHistoryChanged"
|
|
29707
30394
|
});
|
|
29708
|
-
|
|
29709
|
-
|
|
29710
|
-
|
|
29711
|
-
|
|
29712
|
-
|
|
29713
|
-
|
|
29714
|
-
|
|
29715
|
-
|
|
29716
|
-
|
|
29717
|
-
|
|
29718
|
-
|
|
29719
|
-
|
|
29720
|
-
|
|
29721
|
-
for (const family of families) listen(family, "toggle", () => set(family, { open: family.open }));
|
|
29722
|
-
listen(keyboard, "change", () => {
|
|
29723
|
-
state.setItem("keyboard", keyboard?.checked ?? false);
|
|
29724
|
-
set(keyboard, { checked: keyboard?.checked ?? false });
|
|
29725
|
-
for (const [key, entry] of entries) {
|
|
29726
|
-
if (entry.open) set(entry.open, { tabindex: keyboard?.checked ?? false ? 0 : -1 });
|
|
29727
|
-
if (!containerLayout) set(entry.tab, { tabindex: (keyboard?.checked ?? false) && key === state.getItem("active") ? 0 : -1 });
|
|
30395
|
+
target.dataController({ func: "ideSave", documentKey: key, [`subscribe_editor_${key}_save`]: true });
|
|
30396
|
+
if (typst) views.contentPane({ title: "Preview", pageName: "preview", height: "100%" }).typstPreview({ value: `^.documents.${key}.content`, filename: `^.documents.${key}.pdfFilename`, height: "100%" });
|
|
30397
|
+
if (recipe) {
|
|
30398
|
+
const output = views.contentPane({ title: "Preview", pageName: "preview", height: "100%", display: "flex", flex_direction: "column" });
|
|
30399
|
+
output.div(`^.documents.${key}.renderStatus`, { role: "status", padding: "8px 12px", white_space: "pre-wrap", overflow: "auto", max_height: "30%" });
|
|
30400
|
+
output.typstPreview({
|
|
30401
|
+
value: `^.documents.${key}.typstSource`,
|
|
30402
|
+
filename: `^.documents.${key}.pdfFilename`,
|
|
30403
|
+
hidden: `^.documents.${key}.previewHidden`,
|
|
30404
|
+
flex: "1",
|
|
30405
|
+
min_height: 0
|
|
30406
|
+
});
|
|
30407
|
+
views.contentPane({ title: "Generated Typst", pageName: "generated", height: "100%" }).codeMirror({ value: `^.documents.${key}.typstSource`, language: "typst", readonly: true, height: "100%" });
|
|
29728
30408
|
}
|
|
29729
|
-
|
|
29730
|
-
|
|
29731
|
-
|
|
29732
|
-
|
|
29733
|
-
|
|
29734
|
-
for (const option of appearance.options) set(option, { selected: option.value === (appearance?.value ?? "compact") });
|
|
29735
|
-
applyTheme();
|
|
29736
|
-
savePreferences();
|
|
29737
|
-
});
|
|
29738
|
-
listen(theme, "change", () => {
|
|
29739
|
-
if (!THEMES.has(theme?.value ?? "light")) throw new Error("Index theme must be light or dark");
|
|
29740
|
-
state.setItem("theme", theme?.value ?? "light");
|
|
29741
|
-
set(theme, { value: theme?.value ?? "light" });
|
|
29742
|
-
for (const option of theme.options) set(option, { selected: option.value === (theme?.value ?? "light") });
|
|
29743
|
-
applyTheme();
|
|
29744
|
-
savePreferences();
|
|
29745
|
-
});
|
|
29746
|
-
listen(window2, "message", (event) => {
|
|
29747
|
-
if (event.data?.type !== THEME_READY) return;
|
|
29748
|
-
for (const { frame } of entries.values()) {
|
|
29749
|
-
if (frame && frame.contentWindow === event.source) {
|
|
29750
|
-
send(frame);
|
|
29751
|
-
updateInspector();
|
|
29752
|
-
break;
|
|
30409
|
+
if (rich) {
|
|
30410
|
+
const previewPane = views.contentPane({ title: "Preview", pageName: "preview", height: "100%", display: "flex", flex_direction: "column" });
|
|
30411
|
+
if (markdown) {
|
|
30412
|
+
doc.setItem("allowHtml", false);
|
|
30413
|
+
previewPane.checkbox({ value: `^.documents.${key}.allowHtml`, label: "Allow embedded HTML", class: "gramlot-ide-allow-html", padding: "8px 12px", flex_shrink: 0 });
|
|
29753
30414
|
}
|
|
30415
|
+
previewPane[html ? "htmlPreview" : "markdownPreview"]({
|
|
30416
|
+
value: `^.documents.${key}.content`,
|
|
30417
|
+
flex: "1",
|
|
30418
|
+
min_height: 0,
|
|
30419
|
+
...markdown ? { allowHtml: `^.documents.${key}.allowHtml` } : {}
|
|
30420
|
+
});
|
|
30421
|
+
views.contentPane({ title: "Rich text", pageName: "rich", height: "100%" })[html ? "htmlEditor" : "markdownEditor"]({
|
|
30422
|
+
datapath: `.documents.${key}`,
|
|
30423
|
+
value: "^.content",
|
|
30424
|
+
readonly: "^.readonly",
|
|
30425
|
+
height: "100%",
|
|
30426
|
+
nodeId: `rich_editor_${key}`,
|
|
30427
|
+
editorView: "rich",
|
|
30428
|
+
selfsubscribe_historyChanged: "ideHistoryChanged"
|
|
30429
|
+
});
|
|
30430
|
+
target.dataController({ func: "ideSave", documentKey: key, [`subscribe_rich_editor_${key}_save`]: true });
|
|
30431
|
+
}
|
|
30432
|
+
}
|
|
30433
|
+
}
|
|
30434
|
+
async ideRenderRecipe(node, { documentKey: documentKey2 }) {
|
|
30435
|
+
const doc = this.ideDocuments.documents.getItem(documentKey2);
|
|
30436
|
+
doc.setItem("view", "preview");
|
|
30437
|
+
await this.ideDocuments.renderRecipe(documentKey2);
|
|
30438
|
+
}
|
|
30439
|
+
ideCancelCreate(node, { documentKey: documentKey2 }) {
|
|
30440
|
+
this.ideDocuments.documents.getItem(documentKey2).setItem("createHidden", true);
|
|
30441
|
+
}
|
|
30442
|
+
async ideCreate(node, { documentKey: documentKey2 }) {
|
|
30443
|
+
this.ideState.setItem("status", "Creating file\u2026");
|
|
30444
|
+
try {
|
|
30445
|
+
const saved = await this.ideDocuments.create(documentKey2);
|
|
30446
|
+
if (!this.ideDisposed && saved) {
|
|
30447
|
+
this.ideState.setItem("status", "File created.");
|
|
30448
|
+
const browser = this.ideState.getItem("browser");
|
|
30449
|
+
if (browser.getItem("root")) await this.fileSystems.get(browser).open(browser.getItem("root"));
|
|
29754
30450
|
}
|
|
30451
|
+
} catch (error) {
|
|
30452
|
+
if (!this.ideDisposed) this.ideState.setItem("status", error.message);
|
|
30453
|
+
}
|
|
30454
|
+
}
|
|
30455
|
+
async ideSave(node, { documentKey: documentKey2 = null } = {}) {
|
|
30456
|
+
const key = documentKey2 ?? this.ideState.getItem("active");
|
|
30457
|
+
if (!key || this.ideDocuments.documents.getItem(key).getItem("saveDisabled")) return;
|
|
30458
|
+
const doc = this.ideDocuments.documents.getItem(key);
|
|
30459
|
+
if (doc.getItem("isNew")) {
|
|
30460
|
+
doc.setItem("createHidden", false);
|
|
30461
|
+
return;
|
|
30462
|
+
}
|
|
30463
|
+
this.ideState.setItem("status", "Saving\u2026");
|
|
30464
|
+
try {
|
|
30465
|
+
const saved = await this.ideDocuments.save(key);
|
|
30466
|
+
if (!this.ideDisposed) this.ideState.setItem("status", saved ? "Saved." : "Document is read only or a request is pending.");
|
|
30467
|
+
} catch (error) {
|
|
30468
|
+
if (!this.ideDisposed) this.ideState.setItem("status", error.message);
|
|
30469
|
+
}
|
|
30470
|
+
}
|
|
30471
|
+
ideRevert(node, { documentKey: documentKey2 }) {
|
|
30472
|
+
if (this.ideDocuments.revert(documentKey2)) this.ideState.setItem("status", "Restored the last saved version.");
|
|
30473
|
+
}
|
|
30474
|
+
ideHistoryChanged(node, { canUndo, canRedo }) {
|
|
30475
|
+
const doc = node.getRelativeData(".");
|
|
30476
|
+
const view = node.getAttr("editorView");
|
|
30477
|
+
doc.setItem(`${view}CanUndo`, canUndo);
|
|
30478
|
+
doc.setItem(`${view}CanRedo`, canRedo);
|
|
30479
|
+
this.ideHistoryState(doc);
|
|
30480
|
+
}
|
|
30481
|
+
ideHistoryState(doc) {
|
|
30482
|
+
const view = doc.getItem("view");
|
|
30483
|
+
doc.setItem("undoDisabled", !doc.getItem(`${view}CanUndo`));
|
|
30484
|
+
doc.setItem("redoDisabled", !doc.getItem(`${view}CanRedo`));
|
|
30485
|
+
}
|
|
30486
|
+
ideEditor(documentKey2) {
|
|
30487
|
+
const rich = this.ideDocuments.documents.getItem(documentKey2).getItem("view") === "rich";
|
|
30488
|
+
const node = this.page.src.binding.nodeIds.get(`${rich ? "rich_" : ""}editor_${documentKey2}`);
|
|
30489
|
+
return this.page.src.renderer.records.get(node).element;
|
|
30490
|
+
}
|
|
30491
|
+
ideUndo(node, { documentKey: documentKey2 }) {
|
|
30492
|
+
this.ideEditor(documentKey2).undo();
|
|
30493
|
+
}
|
|
30494
|
+
ideRedo(node, { documentKey: documentKey2 }) {
|
|
30495
|
+
this.ideEditor(documentKey2).redo();
|
|
30496
|
+
}
|
|
30497
|
+
ideClose(node) {
|
|
30498
|
+
const key = node.getAttr("documentKey");
|
|
30499
|
+
if (!this.ideDocuments.canClose(key)) {
|
|
30500
|
+
this.ideState.setItem("status", "Save or revert your changes before closing. Pending operations must finish first.");
|
|
30501
|
+
return false;
|
|
30502
|
+
}
|
|
30503
|
+
return true;
|
|
30504
|
+
}
|
|
30505
|
+
ideClosed(node, { pageName }) {
|
|
30506
|
+
this.ideForgetDocument(pageName);
|
|
30507
|
+
}
|
|
30508
|
+
ideForgetDocument(key, discard = false) {
|
|
30509
|
+
const document = this.ideDocuments.documents.getItem(key);
|
|
30510
|
+
const browser = this.ideState.getItem("browser"), selectedPath = browser.getItem("selectedPath");
|
|
30511
|
+
const selected = selectedPath === null ? null : browser.getItem("store").getNode(selectedPath);
|
|
30512
|
+
if (document && browser.getItem("root") === document.getItem("root") && selected?.attr.path === document.getItem("path")) {
|
|
30513
|
+
browser.setItem("selectedPath", null);
|
|
30514
|
+
}
|
|
30515
|
+
this.idePanels.delete(key);
|
|
30516
|
+
this.ideDocuments.close(key, discard);
|
|
30517
|
+
}
|
|
30518
|
+
};
|
|
30519
|
+
|
|
30520
|
+
// src/navigation-resolver.js
|
|
30521
|
+
var NavigationResolver = class _NavigationResolver extends RemoteResolver {
|
|
30522
|
+
static internalParams = /* @__PURE__ */ new Set([...RemoteResolver.internalParams, "gramlot", "method", "params", "onError"]);
|
|
30523
|
+
#closed = false;
|
|
30524
|
+
#controller = null;
|
|
30525
|
+
constructor({ gramlot, method, directory, onError }) {
|
|
30526
|
+
super({ cacheTime: -1, onError });
|
|
30527
|
+
this.gramlot = gramlot;
|
|
30528
|
+
this.method = method;
|
|
30529
|
+
this.params = { directory };
|
|
30530
|
+
this.children = /* @__PURE__ */ new Set();
|
|
30531
|
+
}
|
|
30532
|
+
get closed() {
|
|
30533
|
+
return this.#closed;
|
|
30534
|
+
}
|
|
30535
|
+
startLoad(perform) {
|
|
30536
|
+
if (this.loading) return this.loading;
|
|
30537
|
+
const controller = new AbortController();
|
|
30538
|
+
this.#controller = controller;
|
|
30539
|
+
return perform({ controller, method: this.method, params: this.params, ignored: false });
|
|
30540
|
+
}
|
|
30541
|
+
async loadAsync({ controller, method, params }) {
|
|
30542
|
+
const { signal } = controller;
|
|
30543
|
+
let abort;
|
|
30544
|
+
const cancelled = new Promise((_, reject) => {
|
|
30545
|
+
abort = () => reject(signal.reason);
|
|
30546
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
29755
30547
|
});
|
|
29756
|
-
|
|
29757
|
-
|
|
29758
|
-
|
|
29759
|
-
|
|
29760
|
-
|
|
29761
|
-
|
|
29762
|
-
|
|
30548
|
+
try {
|
|
30549
|
+
const value = await Promise.race([this.gramlot.rpc.call("data", method, params, { signal }), cancelled]);
|
|
30550
|
+
if (signal.aborted) throw signal.reason;
|
|
30551
|
+
return value;
|
|
30552
|
+
} finally {
|
|
30553
|
+
signal.removeEventListener("abort", abort);
|
|
30554
|
+
if (this.#controller === controller) this.#controller = null;
|
|
30555
|
+
}
|
|
30556
|
+
}
|
|
30557
|
+
prepareValue(bag) {
|
|
30558
|
+
if (!(bag instanceof Bag)) throw new TypeError("Directory navigation must return a Bag");
|
|
30559
|
+
for (const child of this.children) child.abort();
|
|
30560
|
+
this.children.clear();
|
|
30561
|
+
for (const node of bag.getNodes()) {
|
|
30562
|
+
if (node.attr.directory !== void 0) {
|
|
30563
|
+
const resolver = new _NavigationResolver({
|
|
30564
|
+
gramlot: this.gramlot,
|
|
30565
|
+
method: this.method,
|
|
30566
|
+
directory: node.attr.directory,
|
|
30567
|
+
onError: this.onError
|
|
30568
|
+
});
|
|
30569
|
+
this.children.add(resolver);
|
|
30570
|
+
bag.setResolver(node.label, resolver);
|
|
30571
|
+
}
|
|
30572
|
+
}
|
|
30573
|
+
return bag;
|
|
29763
30574
|
}
|
|
29764
|
-
|
|
29765
|
-
|
|
29766
|
-
|
|
29767
|
-
|
|
29768
|
-
|
|
29769
|
-
const element = renderer.destination.ownerDocument.getElementById(shell_id);
|
|
29770
|
-
this.index = mountIndexPage(renderer, renderer.elements.get(element).node);
|
|
30575
|
+
abort() {
|
|
30576
|
+
this.#closed = true;
|
|
30577
|
+
this.#controller?.abort();
|
|
30578
|
+
for (const child of this.children) child.abort();
|
|
30579
|
+
this.children.clear();
|
|
29771
30580
|
}
|
|
29772
30581
|
};
|
|
29773
30582
|
|
|
@@ -30272,8 +31081,12 @@ function parseDateExpression(text, options = {}) {
|
|
|
30272
31081
|
export {
|
|
30273
31082
|
Bag,
|
|
30274
31083
|
BagNode,
|
|
31084
|
+
DirectoryResolver,
|
|
30275
31085
|
DomHandler,
|
|
30276
31086
|
Exposed,
|
|
31087
|
+
FileSystemController,
|
|
31088
|
+
FileSystemLogic,
|
|
31089
|
+
FramePage,
|
|
30277
31090
|
Gramlot,
|
|
30278
31091
|
GramlotBuilder,
|
|
30279
31092
|
GramlotHtmlRenderer,
|
|
@@ -30281,9 +31094,11 @@ export {
|
|
|
30281
31094
|
GramlotSvgRenderer,
|
|
30282
31095
|
Handler,
|
|
30283
31096
|
HttpTransport,
|
|
31097
|
+
IdeLogic,
|
|
30284
31098
|
InOut,
|
|
30285
31099
|
IndexLogic,
|
|
30286
31100
|
IndexPage,
|
|
31101
|
+
NavigationResolver,
|
|
30287
31102
|
Page,
|
|
30288
31103
|
PageBootstrap,
|
|
30289
31104
|
References,
|
|
@@ -30292,7 +31107,9 @@ export {
|
|
|
30292
31107
|
ServerAdapter,
|
|
30293
31108
|
SourceHandler,
|
|
30294
31109
|
UtilitiesHandler,
|
|
31110
|
+
codeMirrorWithOptions,
|
|
30295
31111
|
createDecimal,
|
|
31112
|
+
fileSystemTree,
|
|
30296
31113
|
mountIndexPage,
|
|
30297
31114
|
parseDateExpression
|
|
30298
31115
|
};
|