@gramlot/gramlot 0.3.8 → 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 +751 -28
- package/dist/gramlot.min.js +27 -24
- package/dist/runtime-notices.json +208 -0
- package/dist/typst-worker-source.js +4 -0
- package/package.json +34 -3
- package/src/binding/hooks.js +14 -0
- package/src/binding/providers.js +4 -0
- package/src/binding/remote.js +2 -0
- package/src/binding/runtime.js +2 -4
- package/src/components/bases.js +1 -0
- 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/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.d.ts +4 -1
- package/src/index.js +4 -1
- package/src/renderer/gramlot-renderer.js +3 -2
- package/src/server/page.d.ts +5 -0
- package/src/server/page.js +4 -0
- package/src/view/button.js +2 -1
- package/src/view/controls.js +7 -11
- package/src/view/events.js +4 -8
package/dist/gramlot.js
CHANGED
|
@@ -22275,10 +22275,11 @@ function projectParameters(element, attrs) {
|
|
|
22275
22275
|
}
|
|
22276
22276
|
|
|
22277
22277
|
// src/components/choices.js
|
|
22278
|
-
function parseChoices(values) {
|
|
22278
|
+
function parseChoices(values, separator = ",") {
|
|
22279
|
+
if (typeof separator !== "string" || !separator) throw new TypeError("separator must be a nonempty string");
|
|
22279
22280
|
if (values === "") return [];
|
|
22280
22281
|
const ids = /* @__PURE__ */ new Set();
|
|
22281
|
-
return values.split(
|
|
22282
|
+
return values.split(separator).map((item) => {
|
|
22282
22283
|
const colon = item.indexOf(":");
|
|
22283
22284
|
const id = colon < 0 ? item : item.slice(0, colon);
|
|
22284
22285
|
const caption = colon < 0 ? item : item.slice(colon + 1);
|
|
@@ -22323,6 +22324,9 @@ function controlElement(HTMLElement) {
|
|
|
22323
22324
|
}
|
|
22324
22325
|
releaseControl() {
|
|
22325
22326
|
}
|
|
22327
|
+
get liveWrites() {
|
|
22328
|
+
return this.control.localName === "textarea" || ["text", "password", "range", "color"].includes(this.control.type);
|
|
22329
|
+
}
|
|
22326
22330
|
validateCandidate(value, accept) {
|
|
22327
22331
|
accept(value);
|
|
22328
22332
|
return { ok: true, value, isCurrent: () => this.pageContext.isActive() };
|
|
@@ -22529,6 +22533,9 @@ function Command(HTMLElement) {
|
|
|
22529
22533
|
min-height:max(var(--gramlot-field-height,28px),var(--gramlot-touch-target,0px));
|
|
22530
22534
|
padding:var(--gramlot-button-padding,.25em .65em);cursor:pointer}
|
|
22531
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}
|
|
22532
22539
|
button:disabled{opacity:.55;cursor:not-allowed} .icon:empty{display:none}
|
|
22533
22540
|
.led{display:inline-block;width:.6em;height:.6em;border-radius:50%;background:var(--gramlot-button-led-off,#888)}
|
|
22534
22541
|
[aria-pressed=true] .led{background:var(--gramlot-button-led-on,#2b9a46)}
|
|
@@ -24520,6 +24527,19 @@ var GramlotBuilder = class _GramlotBuilder extends HtmlBuilder {
|
|
|
24520
24527
|
}
|
|
24521
24528
|
};
|
|
24522
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
|
+
|
|
24523
24543
|
// src/view/controls.js
|
|
24524
24544
|
var CONTROL_TAGS = /* @__PURE__ */ new Set(["input", "select", "textarea"]);
|
|
24525
24545
|
var REBUILD_ATTRIBUTES = ["type", "multiple", "group"];
|
|
@@ -24727,8 +24747,8 @@ var ComponentControl = class extends ControlAdapter {
|
|
|
24727
24747
|
}
|
|
24728
24748
|
get writeEvent() {
|
|
24729
24749
|
if (this.element.commitOnChange) return "change";
|
|
24730
|
-
const
|
|
24731
|
-
return
|
|
24750
|
+
const live = this.resolved.live ?? this.element.parameters.live;
|
|
24751
|
+
return live && this.element.liveWrites ? "input" : "change";
|
|
24732
24752
|
}
|
|
24733
24753
|
read() {
|
|
24734
24754
|
return this.element.readControlValue();
|
|
@@ -25040,16 +25060,13 @@ var INPUT_CONTROLS = {
|
|
|
25040
25060
|
function componentContext(adapter) {
|
|
25041
25061
|
const { binding, node } = adapter, app = binding.runtime.gramlot;
|
|
25042
25062
|
const invoke = (attribute, code, keywords, expression = false) => {
|
|
25043
|
-
if (!expression
|
|
25044
|
-
const { group, method } = app.src.logicRegistry.resolve(code, node);
|
|
25045
|
-
return method.call(group, node, keywords);
|
|
25046
|
-
}
|
|
25063
|
+
if (!expression) return invokeHook(binding.runtime, node, attribute, code, keywords);
|
|
25047
25064
|
return binding.runtime.inlineCompiler.compile(
|
|
25048
25065
|
node,
|
|
25049
25066
|
attribute,
|
|
25050
25067
|
code,
|
|
25051
25068
|
Object.keys(keywords),
|
|
25052
|
-
|
|
25069
|
+
`return (${code});`
|
|
25053
25070
|
)(keywords);
|
|
25054
25071
|
};
|
|
25055
25072
|
return {
|
|
@@ -25058,11 +25075,9 @@ function componentContext(adapter) {
|
|
|
25058
25075
|
createDecimal,
|
|
25059
25076
|
isDecimal: isDecimal2,
|
|
25060
25077
|
getDecimalLibrary,
|
|
25078
|
+
publish: (topic, payload) => node.publish(topic, payload),
|
|
25061
25079
|
isActive: () => !binding.closed,
|
|
25062
|
-
callLogic: (name, keywords) =>
|
|
25063
|
-
const { group, method } = app.src.logicRegistry.resolve(name, node);
|
|
25064
|
-
return method.call(group, node, keywords);
|
|
25065
|
-
},
|
|
25080
|
+
callLogic: (name, keywords) => callLogic(binding.runtime, node, name, keywords),
|
|
25066
25081
|
format: (value, options) => app.format(value, options),
|
|
25067
25082
|
invoke,
|
|
25068
25083
|
remote: (method, keywords, signal) => app.rpc.call("data", method, keywords, { signal }),
|
|
@@ -25152,9 +25167,9 @@ function domPropertyName(name) {
|
|
|
25152
25167
|
return PROPERTY_NAMES.get(camel.toLowerCase()) ?? camel;
|
|
25153
25168
|
}
|
|
25154
25169
|
var HtmlElement = class {
|
|
25155
|
-
constructor({ metadataAttributes = [], invokeScript = null, callLogic = null } = {}) {
|
|
25170
|
+
constructor({ metadataAttributes = [], invokeScript = null, callLogic: callLogic2 = null } = {}) {
|
|
25156
25171
|
this.invokeScript = invokeScript;
|
|
25157
|
-
this.callLogic =
|
|
25172
|
+
this.callLogic = callLogic2;
|
|
25158
25173
|
this.metadataAttributes = /* @__PURE__ */ new Set([...META_ATTRS, "_text", ...metadataAttributes]);
|
|
25159
25174
|
}
|
|
25160
25175
|
definition(node) {
|
|
@@ -25452,7 +25467,7 @@ var ButtonBinding = class _ButtonBinding {
|
|
|
25452
25467
|
if (this.binding.closed || this.element.disabled || result === null) return;
|
|
25453
25468
|
const values = { ...read(), ...result };
|
|
25454
25469
|
if (result) values._askResult = result;
|
|
25455
|
-
this.binding.runtime
|
|
25470
|
+
invokeHook(this.binding.runtime, node, "action", node.getAttr("action"), values);
|
|
25456
25471
|
};
|
|
25457
25472
|
const ask = node.getAttr("ask");
|
|
25458
25473
|
const askDialog = this.binding.runtime.askDialog;
|
|
@@ -25483,7 +25498,6 @@ function eventToString(event) {
|
|
|
25483
25498
|
|
|
25484
25499
|
// src/view/events.js
|
|
25485
25500
|
var PREFIX = "connect_on";
|
|
25486
|
-
var NAMED_LOGIC = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/;
|
|
25487
25501
|
var NativeEventBinding = class {
|
|
25488
25502
|
#binding;
|
|
25489
25503
|
#record;
|
|
@@ -25531,11 +25545,7 @@ var NativeEventBinding = class {
|
|
|
25531
25545
|
if (this.binding.closed) return;
|
|
25532
25546
|
const node = this.node;
|
|
25533
25547
|
const runtime = this.binding.runtime;
|
|
25534
|
-
if (
|
|
25535
|
-
const { group, method } = runtime.logicRegistry.resolve(this.handler, node);
|
|
25536
|
-
method.call(group, node, event);
|
|
25537
|
-
return;
|
|
25538
|
-
}
|
|
25548
|
+
if (isLogicMethod(this.handler)) return callLogic(runtime, node, this.handler, event);
|
|
25539
25549
|
runtime.inlineCompiler.compile(node, this.attribute, this.handler, ["event"])({ event });
|
|
25540
25550
|
}
|
|
25541
25551
|
};
|
|
@@ -26338,6 +26348,9 @@ var Provider = class {
|
|
|
26338
26348
|
...CLICK_FIELDS,
|
|
26339
26349
|
...Object.keys(authorArguments(kwargs))
|
|
26340
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
|
+
}
|
|
26341
26354
|
return this.binding.runtime.inlineCompiler.compile(this.node, attr, code, names, source)({ ...kwargs, _kwargs: kwargs });
|
|
26342
26355
|
}
|
|
26343
26356
|
/**
|
|
@@ -26761,6 +26774,7 @@ var RemoteBinding = class {
|
|
|
26761
26774
|
return attrs[name] ?? null;
|
|
26762
26775
|
}
|
|
26763
26776
|
#inline(attr, code, source, params) {
|
|
26777
|
+
if (attr === "_onRemote") return invokeHook(this.binding.runtime, this.node, attr, code, params);
|
|
26764
26778
|
return this.binding.runtime.inlineCompiler.compile(this.node, attr, code, Object.keys(params), source)(params);
|
|
26765
26779
|
}
|
|
26766
26780
|
};
|
|
@@ -27361,10 +27375,7 @@ var NodeBinding = class {
|
|
|
27361
27375
|
if (typeof handler !== "string" || !handler) throw new TypeError(`${name} requires a handler`);
|
|
27362
27376
|
return (payload) => {
|
|
27363
27377
|
if (this.closed) return;
|
|
27364
|
-
if (
|
|
27365
|
-
const { group, method } = this.runtime.logicRegistry.resolve(handler, node);
|
|
27366
|
-
return method.call(group, node, payload);
|
|
27367
|
-
}
|
|
27378
|
+
if (isLogicMethod(handler)) return callLogic(this.runtime, node, handler, payload);
|
|
27368
27379
|
const [, attrs] = node.rootBuilder.runtimeValues(node);
|
|
27369
27380
|
const authored = Object.fromEntries(Object.entries(attrs).filter(([key]) => !key.startsWith("subscribe_") && !key.startsWith("selfsubscribe_")));
|
|
27370
27381
|
const values = { ...this.runtime.renderer.references.resolveArguments(authored), p_0: payload };
|
|
@@ -27799,12 +27810,14 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
|
|
|
27799
27810
|
const { group, method } = binding.gramlot.src.logicRegistry.resolve(name, node);
|
|
27800
27811
|
return method.call(group, node, keywords);
|
|
27801
27812
|
},
|
|
27802
|
-
invokeScript: (node, name, code, keywords) =>
|
|
27813
|
+
invokeScript: (node, name, code, keywords) => invokeHook(
|
|
27814
|
+
binding,
|
|
27803
27815
|
node,
|
|
27804
27816
|
name,
|
|
27805
27817
|
code,
|
|
27818
|
+
keywords,
|
|
27806
27819
|
node.parentNode._getMeta("gramlot_component").childParameters[name].inline
|
|
27807
|
-
)
|
|
27820
|
+
)
|
|
27808
27821
|
});
|
|
27809
27822
|
this.records = /* @__PURE__ */ new Map();
|
|
27810
27823
|
this.references = new References(source);
|
|
@@ -29800,6 +29813,710 @@ var IndexLogic = class {
|
|
|
29800
29813
|
}
|
|
29801
29814
|
};
|
|
29802
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
|
|
29834
|
+
};
|
|
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"
|
|
29862
|
+
};
|
|
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
|
|
29917
|
+
});
|
|
29918
|
+
this.children.add(resolver);
|
|
29919
|
+
bag.setResolver(node.label, resolver);
|
|
29920
|
+
}
|
|
29921
|
+
}
|
|
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");
|
|
29943
|
+
try {
|
|
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;
|
|
29962
|
+
} finally {
|
|
29963
|
+
if (this.request === request) this.request = null;
|
|
29964
|
+
}
|
|
29965
|
+
}
|
|
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);
|
|
30117
|
+
}
|
|
30118
|
+
});
|
|
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();
|
|
30239
|
+
});
|
|
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}`
|
|
30329
|
+
});
|
|
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"
|
|
30363
|
+
});
|
|
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
|
|
30372
|
+
});
|
|
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"
|
|
30394
|
+
});
|
|
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%" });
|
|
30408
|
+
}
|
|
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 });
|
|
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"));
|
|
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
|
+
|
|
29803
30520
|
// src/navigation-resolver.js
|
|
29804
30521
|
var NavigationResolver = class _NavigationResolver extends RemoteResolver {
|
|
29805
30522
|
static internalParams = /* @__PURE__ */ new Set([...RemoteResolver.internalParams, "gramlot", "method", "params", "onError"]);
|
|
@@ -30364,8 +31081,11 @@ function parseDateExpression(text, options = {}) {
|
|
|
30364
31081
|
export {
|
|
30365
31082
|
Bag,
|
|
30366
31083
|
BagNode,
|
|
31084
|
+
DirectoryResolver,
|
|
30367
31085
|
DomHandler,
|
|
30368
31086
|
Exposed,
|
|
31087
|
+
FileSystemController,
|
|
31088
|
+
FileSystemLogic,
|
|
30369
31089
|
FramePage,
|
|
30370
31090
|
Gramlot,
|
|
30371
31091
|
GramlotBuilder,
|
|
@@ -30374,6 +31094,7 @@ export {
|
|
|
30374
31094
|
GramlotSvgRenderer,
|
|
30375
31095
|
Handler,
|
|
30376
31096
|
HttpTransport,
|
|
31097
|
+
IdeLogic,
|
|
30377
31098
|
InOut,
|
|
30378
31099
|
IndexLogic,
|
|
30379
31100
|
IndexPage,
|
|
@@ -30386,7 +31107,9 @@ export {
|
|
|
30386
31107
|
ServerAdapter,
|
|
30387
31108
|
SourceHandler,
|
|
30388
31109
|
UtilitiesHandler,
|
|
31110
|
+
codeMirrorWithOptions,
|
|
30389
31111
|
createDecimal,
|
|
31112
|
+
fileSystemTree,
|
|
30390
31113
|
mountIndexPage,
|
|
30391
31114
|
parseDateExpression
|
|
30392
31115
|
};
|