@gramlot/gramlot 0.3.15 → 0.3.17
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/__init__.py +1 -1
- package/dist/components/editors/assets/collection.js +16162 -11689
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/grammar.json +3 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +134 -179
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +19 -0
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +4643 -3481
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +509 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +306 -94
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +16 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/gramlot.js +2127 -507
- package/dist/gramlot.min.js +95 -40
- package/dist/runtime-notices.json +4 -0
- package/package.json +12 -8
- package/src/binding/device-resolver.js +27 -0
- package/src/binding/error-notifications.js +84 -0
- package/src/binding/remote-resolver.d.ts +18 -0
- package/src/binding/remote.js +11 -4
- package/src/binding/runtime.js +6 -2
- package/src/bootstrap.js +4 -4
- package/src/components/buttons.js +10 -3
- package/src/components/code-mirror-engine.js +14 -4
- package/src/components/code-mirror.js +2 -3
- package/src/components/container.js +1 -1
- package/src/components/date-calendar.js +1 -1
- package/src/components/formlet-labels.js +5 -4
- package/src/components/html-document.js +4 -2
- package/src/components/html-editor.js +2 -2
- package/src/components/jodit-engine.js +72 -11
- package/src/components/labelbox.js +19 -63
- package/src/components/layout.js +31 -19
- package/src/components/markdown-document.js +1 -1
- package/src/components/markdown-editor.js +2 -2
- package/src/components/menus.js +7 -6
- package/src/components/prose-mirror-engine.js +14 -1
- package/src/components/registry.js +2 -0
- package/src/components/selected-container.js +107 -14
- package/src/components/toolbar-overflow.js +9 -8
- package/src/components/transform-pane.js +140 -0
- package/src/components/tray-geometry.js +87 -0
- package/src/components/tray-pane.js +435 -0
- package/src/components/tray-settings.js +62 -0
- package/src/components/tree.js +115 -21
- package/src/components/typed-editor.js +1 -1
- package/src/components/typst-client.js +14 -13
- package/src/components/validation.js +1 -1
- package/src/components/window-surface.js +281 -0
- package/src/components/windows.js +32 -261
- package/src/device-frames.js +195 -0
- package/src/filesystem.d.ts +12 -5
- package/src/filesystem.js +9 -8
- package/src/gramlot.d.ts +3 -1
- package/src/gramlot.js +11 -4
- package/src/handlers/device-handler.d.ts +75 -0
- package/src/handlers/device-handler.js +1037 -0
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +2 -2
- package/src/http-transport.d.ts +3 -3
- package/src/http-transport.js +17 -11
- package/src/ide-documents.js +7 -5
- package/src/ide-runtime.d.ts +14 -3
- package/src/ide-runtime.js +124 -94
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +91 -43
- package/src/index-page-styles.js +1 -1
- package/src/index.d.ts +7 -2
- package/src/index.js +5 -1
- package/src/inout.d.ts +1 -1
- package/src/inout.js +5 -1
- package/src/mobile-environment.d.ts +6 -0
- package/src/mobile-environment.js +52 -0
- package/src/navigation-resolver.d.ts +14 -2
- package/src/renderer/attributes.js +5 -2
- package/src/renderer/drag-drop.js +5 -4
- package/src/renderer/gramlot-renderer.d.ts +13 -2
- package/src/renderer/gramlot-renderer.js +49 -13
- package/src/server/index-page.js +4 -4
- package/src/view/controls.js +48 -23
- package/src/view/html.js +85 -4
- package/src/view/labelbox.js +95 -0
- package/themes/gramlot-base/theme.css +4 -0
- package/themes/mela/theme.css +62 -15
- package/src/date-parser/civil.js +0 -61
- package/src/date-parser/index.d.ts +0 -18
- package/src/date-parser/index.js +0 -196
- package/src/date-parser/locales.js +0 -257
|
@@ -10,6 +10,8 @@ import {Handler} from './handler.js';
|
|
|
10
10
|
|
|
11
11
|
/** The DOM and its correspondence with the Source. */
|
|
12
12
|
export class DomHandler extends Handler {
|
|
13
|
+
/** Navigate the current document to an absolute HTTP(S) URL without credentials. */
|
|
14
|
+
navigate(url: string): void;
|
|
13
15
|
setTouchMode(mode?: 'auto' | 'on' | 'off'): void;
|
|
14
16
|
/** Resolve a node or DOM reference descriptor. */
|
|
15
17
|
reference(descriptor: SourceReference): SourceBagNode | DomElement;
|
|
@@ -15,6 +15,15 @@ export class DomHandler extends Handler {
|
|
|
15
15
|
if (mode === 'auto') root.removeAttribute('data-gramlot-touch');
|
|
16
16
|
else root.setAttribute('data-gramlot-touch', mode);
|
|
17
17
|
}
|
|
18
|
+
/** Navigate the current document to an explicit HTTP(S) URL selected by page policy. */
|
|
19
|
+
navigate(url) {
|
|
20
|
+
if (typeof url !== 'string' || !url) throw new TypeError('Navigation requires an absolute HTTP(S) URL');
|
|
21
|
+
const target = new URL(url);
|
|
22
|
+
if (!['http:', 'https:'].includes(target.protocol) || target.username || target.password) {
|
|
23
|
+
throw new TypeError('Navigation requires an HTTP(S) URL without credentials');
|
|
24
|
+
}
|
|
25
|
+
this.gramlot.src.renderer.destination.ownerDocument.defaultView.location.assign(target.href);
|
|
26
|
+
}
|
|
18
27
|
reference(descriptor) { return this.gramlot.src.renderer.references.resolve(descriptor); }
|
|
19
28
|
/** The Source node of the nearest element generated by the renderer (§4.11bis). */
|
|
20
29
|
getBaseSourceNode(domNode) { return this.gramlot.src.renderer.getBaseSourceNode(domNode); }
|
|
@@ -14,8 +14,8 @@ import {Handler} from './handler.js';
|
|
|
14
14
|
export interface RpcTransport {
|
|
15
15
|
/** Send the request envelope text; resolves with the response envelope text. */
|
|
16
16
|
call(text: string, signal?: AbortSignal): Promise<string>;
|
|
17
|
-
/** Send the close message of the page `pageId` without waiting;
|
|
18
|
-
close(pageId: string
|
|
17
|
+
/** Send the close message of the page `pageId` without waiting; HTTP always uses a beacon. */
|
|
18
|
+
close(pageId: string): void;
|
|
19
19
|
/** Release the transport; called once, after `close`, when the page is disposed. */
|
|
20
20
|
dispose(): void;
|
|
21
21
|
/** True when the transport sends a synchronous call with `callSync`; a transport without it has none. */
|
package/src/http-transport.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export class HttpTransport {
|
|
|
16
16
|
fetcher: Fetcher;
|
|
17
17
|
/** The URL of the page close endpoint. */
|
|
18
18
|
closeUrl: string;
|
|
19
|
-
/** The navigator whose `sendBeacon` sends
|
|
19
|
+
/** The navigator whose `sendBeacon` sends every close request. */
|
|
20
20
|
navigator: BeaconNavigator;
|
|
21
21
|
/** The XMLHttpRequest class of the window, used by `callSync`. */
|
|
22
22
|
XMLHttpRequest: DomXMLHttpRequestClass;
|
|
@@ -29,8 +29,8 @@ export class HttpTransport {
|
|
|
29
29
|
call(text: string, signal?: AbortSignal): Promise<string>;
|
|
30
30
|
/** POST the request envelope text with a synchronous XMLHttpRequest; the response envelope text, or a throw on a non-200 status. Blocks the page while it waits. */
|
|
31
31
|
callSync(text: string): string;
|
|
32
|
-
/** Ask the server to close the page, with a beacon
|
|
33
|
-
close(pageId: string
|
|
32
|
+
/** Ask the server to close the page, with a beacon; delivery failure is ignored, configuration errors propagate. */
|
|
33
|
+
close(pageId: string): void;
|
|
34
34
|
/** Release the transport at the dispose of the page; HTTP holds no connection, so nothing is released. */
|
|
35
35
|
dispose(): void;
|
|
36
36
|
}
|
package/src/http-transport.js
CHANGED
|
@@ -41,18 +41,24 @@ export class HttpTransport {
|
|
|
41
41
|
return request.responseText;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* Queue `{pageId}` as a JSON beacon for every close. A refused or undelivered
|
|
45
|
+
* beacon leaves cleanup to the server TTL; configuration errors remain visible.
|
|
46
46
|
*/
|
|
47
|
-
close(pageId
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
close(pageId) {
|
|
48
|
+
if (typeof this.closeUrl !== 'string' || !this.closeUrl.trim()) {
|
|
49
|
+
throw new TypeError('HttpTransport.closeUrl must be nonempty text');
|
|
50
|
+
}
|
|
51
|
+
if (typeof this.navigator?.sendBeacon !== 'function') {
|
|
52
|
+
throw new TypeError('HttpTransport requires navigator.sendBeacon');
|
|
53
|
+
}
|
|
54
|
+
const body = new Blob([JSON.stringify({pageId})], {type: 'application/json'});
|
|
55
|
+
try {
|
|
56
|
+
this.navigator.sendBeacon(this.closeUrl, body);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// Native beacon rejects malformed/unsupported URLs with TypeError,
|
|
59
|
+
// including errors originating in the page's separate browser realm.
|
|
60
|
+
if (error.name === 'TypeError') throw error;
|
|
61
|
+
// Delivery failure must not prevent local disposal; the server TTL remains.
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
/** Release the transport at the dispose of the page: HTTP holds no connection, so nothing is released. The
|
package/src/ide-documents.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import {Bag} from '@genrojs/bag';
|
|
2
|
+
import {randomId} from './random-id.js';
|
|
2
3
|
|
|
3
4
|
/** UTF-8 identity is safe in Bag paths and keeps distinct roots/files distinct. */
|
|
4
5
|
export const documentKey = (root, path) => 'd_' + [...new TextEncoder().encode(JSON.stringify([root,path]))]
|
|
5
6
|
.map(byte => byte.toString(16).padStart(2,'0')).join('');
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
+
/** Source-owned document requests; drafts and saved baselines are relative Data. */
|
|
8
9
|
export class IdeDocuments {
|
|
9
|
-
constructor(gramlot,
|
|
10
|
-
this.gramlot = gramlot; this.
|
|
10
|
+
constructor(gramlot, source) {
|
|
11
|
+
this.gramlot = gramlot; this.source = source;
|
|
11
12
|
this.pending = new Map(); this.disposed = false;
|
|
12
13
|
}
|
|
14
|
+
get state() { return this.source.getRelativeData('.'); }
|
|
13
15
|
get documents() { return this.state.getItem('documents'); }
|
|
14
16
|
async open(root, path) {
|
|
15
17
|
const key = documentKey(root, path);
|
|
@@ -28,7 +30,7 @@ export class IdeDocuments {
|
|
|
28
30
|
return promise;
|
|
29
31
|
}
|
|
30
32
|
newDocument(language, extension, root = '') {
|
|
31
|
-
const key = `new_${
|
|
33
|
+
const key = `new_${randomId()}`;
|
|
32
34
|
const doc = new Bag();
|
|
33
35
|
for (const [name,value] of Object.entries({language, root, path:`Untitled${extension}`,
|
|
34
36
|
content:'', saved:'', writable:true, busy:false, isNew:true, createHidden:true,
|
|
@@ -38,7 +40,7 @@ export class IdeDocuments {
|
|
|
38
40
|
}
|
|
39
41
|
async create(key) {
|
|
40
42
|
const doc = this.documents.getItem(key);
|
|
41
|
-
if (!doc || !doc.getItem('isNew') || this.pending.has(key)) return false;
|
|
43
|
+
if (!doc || !doc.getItem('isNew') || !doc.getItem('writable') || this.pending.has(key)) return false;
|
|
42
44
|
const root = doc.getItem('saveRoot'), path = doc.getItem('savePath');
|
|
43
45
|
if (doc.getItem('path').endsWith('.typ.py') !== path.endsWith('.typ.py')) {
|
|
44
46
|
throw new Error('The .typ.py extension is required for the Typst Python recipe document type.');
|
package/src/ide-runtime.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type {Bag} from '@genrojs/bag';
|
|
2
|
+
import type {DomElement} from './dom.d.ts';
|
|
1
3
|
import type {SourceBagNode} from '@genrojs/builders';
|
|
2
4
|
import type {Gramlot} from './gramlot.js';
|
|
3
5
|
/** Export as the page's Logic; constructor-free methods are registered by Gramlot. */
|
|
@@ -6,13 +8,22 @@ export class IdeLogic {
|
|
|
6
8
|
fileSystemMount(node:SourceBagNode):void;
|
|
7
9
|
fileSystemOpen(node:SourceBagNode,args:{root:string|null}):Promise<string|null>|undefined;
|
|
8
10
|
ideMount(node:SourceBagNode):void;
|
|
9
|
-
ideOpenWorkspace():void;
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
ideOpenWorkspace(node:SourceBagNode):void;
|
|
12
|
+
ideDocumentState(node:SourceBagNode,key:string):void;
|
|
13
|
+
ideOpenDocument(node:SourceBagNode,root:string,path:string):Promise<void>;
|
|
14
|
+
ideNew(node:SourceBagNode):void;
|
|
15
|
+
ideShowDocument(node:SourceBagNode,key:string):void;
|
|
16
|
+
ideRenderRecipe(node:SourceBagNode,args:{documentKey:string}):Promise<void>;
|
|
17
|
+
ideCancelCreate(node:SourceBagNode,args:{documentKey:string}):void;
|
|
18
|
+
ideCreate(node:SourceBagNode,args:{documentKey:string}):Promise<void>;
|
|
19
|
+
ideSave(node:SourceBagNode,args?:{documentKey?:string|null}):Promise<void>;
|
|
12
20
|
ideRevert(node:SourceBagNode,args:{documentKey:string}):void;
|
|
13
21
|
ideUndo(node:SourceBagNode,args:{documentKey:string}):void;
|
|
14
22
|
ideRedo(node:SourceBagNode,args:{documentKey:string}):void;
|
|
15
23
|
ideHistoryChanged(node:SourceBagNode,args:{canUndo:boolean,canRedo:boolean}):void;
|
|
24
|
+
ideHistoryState(document:Bag):void;
|
|
25
|
+
ideEditor(node:SourceBagNode,documentKey:string):DomElement;
|
|
16
26
|
ideClose(node:SourceBagNode):boolean;
|
|
17
27
|
ideClosed(node:SourceBagNode,args:{pageName:string}):void;
|
|
28
|
+
ideForgetDocument(node:SourceBagNode,key:string,discard?:boolean):void;
|
|
18
29
|
}
|
package/src/ide-runtime.js
CHANGED
|
@@ -1,109 +1,127 @@
|
|
|
1
|
+
import {randomId} from './random-id.js';
|
|
1
2
|
import {sourceTarget} from '@genrojs/builders';
|
|
2
3
|
import {FileSystemLogic} from './filesystem.js';
|
|
3
4
|
import {IdeDocuments, RecentWorkspaces} from './ide-documents.js';
|
|
4
5
|
import {codeMirrorWithOptions} from './components/editor-options.js';
|
|
5
6
|
|
|
7
|
+
/** Resolve the owner through Source ancestry, independently of DOM placement. */
|
|
8
|
+
function ideContext(node) {
|
|
9
|
+
for (let scope = node; scope; scope = scope.parentNode) {
|
|
10
|
+
const context = scope.ideContext;
|
|
11
|
+
if (context) return context;
|
|
12
|
+
}
|
|
13
|
+
throw new Error('IDE operation requires a node inside a mounted IDE');
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
/** Reusable IDE coordination uses Source for panels and Data for all document state. */
|
|
7
17
|
export class IdeLogic {
|
|
8
18
|
fileSystemMount(node) { return FileSystemLogic.prototype.fileSystemMount.call(this,node); }
|
|
9
19
|
fileSystemOpen(node, args) { return FileSystemLogic.prototype.fileSystemOpen.call(this,node,args); }
|
|
10
20
|
ideMount(node) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const browser = this.ideState.getItem('browser');
|
|
21
|
+
const scope = node.parentNode;
|
|
22
|
+
const context = {scope, documents:new IdeDocuments(this.page,scope), requested:0,
|
|
23
|
+
editorPrefix:`ide_${randomId()}`, recent:new RecentWorkspaces(this.page.src.renderer.destination.ownerDocument.defaultView.sessionStorage)};
|
|
24
|
+
Object.defineProperty(scope,'ideContext',{value:context,configurable:true});
|
|
25
|
+
const {documents, recent} = context;
|
|
26
|
+
const state = scope.getRelativeData('.');
|
|
27
|
+
const roots = recent.read();
|
|
28
|
+
state.setItem('recent',recent.choices(roots));
|
|
29
|
+
state.setItem('workspace',roots[0] ?? '');
|
|
30
|
+
const browser = state.getItem('browser');
|
|
22
31
|
browser.subscribe('ide-browser',{any:event => {
|
|
23
32
|
if (event.node === browser.getNode('root')) {
|
|
24
33
|
const root = browser.getItem('root');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
state.setItem('workspace',root);
|
|
35
|
+
state.setItem('recent',recent.choices(recent.remember(root)));
|
|
36
|
+
state.setItem('status',`Workspace: ${root}`);
|
|
28
37
|
} else if (event.node === browser.getNode('selectedPath')) {
|
|
29
38
|
const path = browser.getItem('selectedPath');
|
|
30
39
|
const item = path === null ? null : browser.getItem('store').getNode(path);
|
|
31
|
-
if (item && !item.attr.is_directory) void this.ideOpenDocument(browser.getItem('root'),item.attr.path);
|
|
40
|
+
if (item && !item.attr.is_directory) void this.ideOpenDocument(scope,browser.getItem('root'),item.attr.path);
|
|
32
41
|
}
|
|
33
42
|
}});
|
|
34
|
-
|
|
43
|
+
const documentBag = documents.documents;
|
|
44
|
+
documentBag.subscribe('ide-documents',{any:event => {
|
|
35
45
|
if (!['content','saved','busy','writable','view','isNew','path','root'].includes(event.node.label)) return;
|
|
36
|
-
for (const
|
|
37
|
-
const
|
|
46
|
+
for (const pane of scope.value.getNode('frame.center.tabs').value?.getNodes() ?? []) {
|
|
47
|
+
const key = pane.getAttr('documentKey');
|
|
48
|
+
const doc = documents.documents.getItem(key);
|
|
38
49
|
if (doc) {
|
|
39
|
-
if (event.node === doc.getNode('content'))
|
|
40
|
-
this.ideDocumentState(key);
|
|
41
|
-
pane.setAttr({title:`${
|
|
50
|
+
if (event.node === doc.getNode('content')) documents.invalidateRecipe(key);
|
|
51
|
+
this.ideDocumentState(scope,key);
|
|
52
|
+
pane.setAttr({title:`${documents.dirty(key) ? '● ' : ''}${doc.getItem('path')}`});
|
|
42
53
|
}
|
|
43
54
|
}
|
|
44
55
|
}});
|
|
45
|
-
this.page.src.renderer.onDispose(
|
|
46
|
-
this.ideDisposed = true;
|
|
56
|
+
this.page.src.renderer.onDispose(context.scope,() => {
|
|
47
57
|
browser.unsubscribe('ide-browser',{any:true});
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
documentBag.unsubscribe('ide-documents',{any:true});
|
|
59
|
+
documents.dispose();
|
|
50
60
|
});
|
|
51
61
|
}
|
|
52
|
-
ideOpenWorkspace() {
|
|
53
|
-
const
|
|
54
|
-
|
|
62
|
+
ideOpenWorkspace(node) {
|
|
63
|
+
const context = ideContext(node);
|
|
64
|
+
const state = context.scope.getRelativeData('.');
|
|
65
|
+
const root = state.getItem('workspace');
|
|
66
|
+
if (root && root !== state.getItem('browser.root')) state.setItem('browser.requestedRoot',root);
|
|
55
67
|
}
|
|
56
|
-
ideDocumentState(key) {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
68
|
+
ideDocumentState(node, key) {
|
|
69
|
+
const context = ideContext(node), {documents} = context;
|
|
70
|
+
const doc = documents.documents.getItem(key);
|
|
71
|
+
const disabled = (!documents.dirty(key) && !doc.getItem('isNew')) || doc.getItem('busy');
|
|
59
72
|
doc.setItem('saveDisabled',Boolean(disabled || !doc.getItem('writable')));
|
|
60
|
-
doc.setItem('revertDisabled',Boolean(!
|
|
73
|
+
doc.setItem('revertDisabled',Boolean(!documents.dirty(key) || doc.getItem('busy')));
|
|
61
74
|
doc.setItem('displayPath',doc.getItem('isNew') ? doc.getItem('path') : `${doc.getItem('root')}/${doc.getItem('path')}`);
|
|
62
75
|
doc.setItem('pdfFilename',doc.getItem('path').split('/').at(-1).replace(/\.typ(?:\.py)?$/i,'.pdf'));
|
|
63
76
|
doc.setItem('renderDisabled',Boolean(doc.getItem('busy') || !doc.getItem('writable')));
|
|
64
77
|
this.ideHistoryState(doc);
|
|
65
78
|
}
|
|
66
|
-
async ideOpenDocument(root, path) {
|
|
67
|
-
const
|
|
79
|
+
async ideOpenDocument(node, root, path) {
|
|
80
|
+
const context = ideContext(node), {documents} = context;
|
|
81
|
+
const state = context.scope.getRelativeData('.');
|
|
82
|
+
const requested = ++context.requested;
|
|
68
83
|
try {
|
|
69
|
-
const key = await
|
|
70
|
-
if (key === null ||
|
|
71
|
-
this.ideShowDocument(key);
|
|
72
|
-
if (requested ===
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
const key = await documents.open(root,path);
|
|
85
|
+
if (key === null || documents.disposed) return;
|
|
86
|
+
this.ideShowDocument(node,key);
|
|
87
|
+
if (requested === context.requested) {
|
|
88
|
+
state.setItem('active',key);
|
|
89
|
+
state.setItem('status',`${path}${documents.documents.getItem(key).getItem('writable') ? '' : ' (draft only — Remote Edit is disabled)'}`);
|
|
75
90
|
}
|
|
76
|
-
} catch (error) { if (!
|
|
91
|
+
} catch (error) { if (!documents.disposed) state.setItem('status',error.message); }
|
|
77
92
|
}
|
|
78
|
-
ideNew() {
|
|
79
|
-
const
|
|
93
|
+
ideNew(node) {
|
|
94
|
+
const context = ideContext(node), {documents} = context;
|
|
95
|
+
const state = context.scope.getRelativeData('.');
|
|
96
|
+
const type = state.getItem('newType');
|
|
80
97
|
const language = type === 'typstRecipe' ? 'python' : type;
|
|
81
98
|
const extensions = {typstRecipe:'.typ.py',typst:'.typ',markdown:'.md',html:'.html',python:'.py',javascript:'.js',
|
|
82
99
|
typescript:'.ts',json:'.json',css:'.css',sql:'.sql',xml:'.xml',text:'.txt'};
|
|
83
|
-
const key =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
const key = documents.newDocument(language,extensions[type],state.getItem('workspace'));
|
|
101
|
+
documents.documents.getItem(key).setItem('writable',state.getItem('browser.writable') === true);
|
|
102
|
+
++context.requested;
|
|
103
|
+
this.ideShowDocument(node,key);
|
|
104
|
+
state.setItem('active',key);
|
|
105
|
+
state.setItem('status','New document. Choose directory and name when saving.');
|
|
106
|
+
}
|
|
107
|
+
ideShowDocument(node, key) {
|
|
108
|
+
const context = ideContext(node), {documents} = context;
|
|
109
|
+
const document = documents.documents.getItem(key);
|
|
91
110
|
const path = document.getItem('path');
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
const tabs = context.scope.value.getNode('frame.center.tabs');
|
|
112
|
+
if (!tabs.value?.getNode(key)) {
|
|
113
|
+
const doc = documents.documents.getItem(key);
|
|
94
114
|
const recipe = path.endsWith('.typ.py');
|
|
95
|
-
if (recipe)
|
|
96
|
-
doc.setItem('readonly'
|
|
97
|
-
this.ideDocumentState(key);
|
|
115
|
+
if (recipe) documents.invalidateRecipe(key);
|
|
116
|
+
doc.setItem('readonly',false);
|
|
117
|
+
this.ideDocumentState(node,key);
|
|
98
118
|
doc.setItem('view','code');
|
|
99
119
|
doc.setItem('createHidden',true);
|
|
100
120
|
doc.setItem('undoDisabled',true);
|
|
101
121
|
doc.setItem('redoDisabled',true);
|
|
102
|
-
const tabs = this.ideRoot.value.getNode('frame.center.tabs');
|
|
103
122
|
const pane = sourceTarget(tabs.builder.wrapSource(tabs).contentPane({node_label:key,
|
|
104
123
|
title:path, pageName:key, documentKey:key, closable:true, onClose:'ideClose',
|
|
105
124
|
height:'100%'}));
|
|
106
|
-
this.idePanels.set(key,pane);
|
|
107
125
|
const target = pane.builder.wrapSource(pane).div({display:'flex',flex_direction:'column',height:'100%'});
|
|
108
126
|
const toolbar = target.div({datapath:`.documents.${key}`,display:'flex',align_items:'center',gap:'6px',padding:'4px 12px',
|
|
109
127
|
height:'40px',flex_shrink:0,box_sizing:'border-box',class:'gramlot-ide-document-toolbar',role:'toolbar','aria-label':`Commands for ${path}`});
|
|
@@ -137,9 +155,9 @@ export class IdeLogic {
|
|
|
137
155
|
const views = preview ? editorArea.tabContainer({height:'100%',selectedPage:`^.documents.${key}.view`}) : null;
|
|
138
156
|
const code = preview ? views.contentPane({title:'Code',pageName:'code',height:'100%'}) : editorArea;
|
|
139
157
|
codeMirrorWithOptions(code,{datapath:`.documents.${key}`,value:'^.content',language:doc.getItem('language'),
|
|
140
|
-
height:'100%', readonly:'^.readonly',nodeId
|
|
158
|
+
height:'100%', readonly:'^.readonly',nodeId:`${context.editorPrefix}_editor_${key}`,
|
|
141
159
|
editorView:'code',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
142
|
-
target.dataController({func:'ideSave',documentKey:key,[`
|
|
160
|
+
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_editor_${key}_save`]:true});
|
|
143
161
|
if (typst) views.contentPane({title:'Preview',pageName:'preview',height:'100%'}).typstPreview({value:`^.documents.${key}.content`,filename:`^.documents.${key}.pdfFilename`,height:'100%'});
|
|
144
162
|
if (recipe) {
|
|
145
163
|
const output = views.contentPane({title:'Preview',pageName:'preview',height:'100%',display:'flex',flex_direction:'column'});
|
|
@@ -159,43 +177,51 @@ export class IdeLogic {
|
|
|
159
177
|
...(markdown ? {allowHtml:`^.documents.${key}.allowHtml`} : {})});
|
|
160
178
|
views.contentPane({title:'Rich text',pageName:'rich',height:'100%'})[html ? 'htmlEditor' : 'markdownEditor']({
|
|
161
179
|
datapath:`.documents.${key}`,value:'^.content',readonly:'^.readonly',height:'100%',
|
|
162
|
-
nodeId
|
|
163
|
-
target.dataController({func:'ideSave',documentKey:key,[`
|
|
180
|
+
nodeId:`${context.editorPrefix}_rich_editor_${key}`,editorView:'rich',selfsubscribe_historyChanged:'ideHistoryChanged'});
|
|
181
|
+
target.dataController({func:'ideSave',documentKey:key,[`subscribe_${context.editorPrefix}_rich_editor_${key}_save`]:true});
|
|
164
182
|
}
|
|
165
183
|
}
|
|
166
184
|
}
|
|
167
185
|
async ideRenderRecipe(node, {documentKey}) {
|
|
168
|
-
const
|
|
186
|
+
const context = ideContext(node), {documents} = context;
|
|
187
|
+
const doc = documents.documents.getItem(documentKey);
|
|
169
188
|
doc.setItem('view','preview');
|
|
170
|
-
await
|
|
189
|
+
await documents.renderRecipe(documentKey);
|
|
171
190
|
}
|
|
172
191
|
ideCancelCreate(node, {documentKey}) {
|
|
173
|
-
|
|
192
|
+
const context = ideContext(node), {documents} = context;
|
|
193
|
+
documents.documents.getItem(documentKey).setItem('createHidden',true);
|
|
174
194
|
}
|
|
175
195
|
async ideCreate(node, {documentKey}) {
|
|
176
|
-
|
|
196
|
+
const context = ideContext(node), {documents} = context;
|
|
197
|
+
const state = context.scope.getRelativeData('.');
|
|
198
|
+
state.setItem('status','Creating file…');
|
|
177
199
|
try {
|
|
178
|
-
const saved = await
|
|
179
|
-
if (!
|
|
180
|
-
|
|
181
|
-
const browser =
|
|
182
|
-
if (browser.getItem('root')) await
|
|
200
|
+
const saved = await documents.create(documentKey);
|
|
201
|
+
if (!documents.disposed && saved) {
|
|
202
|
+
state.setItem('status','File created.');
|
|
203
|
+
const browser = state.getItem('browser');
|
|
204
|
+
if (browser.getItem('root')) await context.scope.value.getNode('frame.left.browser').fileSystemController.open(browser.getItem('root'));
|
|
183
205
|
}
|
|
184
|
-
} catch (error) { if (!
|
|
206
|
+
} catch (error) { if (!documents.disposed) state.setItem('status',error.message); }
|
|
185
207
|
}
|
|
186
208
|
async ideSave(node, {documentKey = null} = {}) {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
const
|
|
209
|
+
const context = ideContext(node), {documents} = context;
|
|
210
|
+
const state = context.scope.getRelativeData('.');
|
|
211
|
+
const key = documentKey ?? state.getItem('active');
|
|
212
|
+
if (!key || documents.documents.getItem(key).getItem('saveDisabled')) return;
|
|
213
|
+
const doc = documents.documents.getItem(key);
|
|
190
214
|
if (doc.getItem('isNew')) { doc.setItem('createHidden',false); return; }
|
|
191
|
-
|
|
215
|
+
state.setItem('status','Saving…');
|
|
192
216
|
try {
|
|
193
|
-
const saved = await
|
|
194
|
-
if (!
|
|
195
|
-
} catch (error) { if (!
|
|
217
|
+
const saved = await documents.save(key);
|
|
218
|
+
if (!documents.disposed) state.setItem('status', saved ? 'Saved.' : 'Document is read only or a request is pending.');
|
|
219
|
+
} catch (error) { if (!documents.disposed) state.setItem('status',error.message); }
|
|
196
220
|
}
|
|
197
221
|
ideRevert(node, {documentKey}) {
|
|
198
|
-
|
|
222
|
+
const context = ideContext(node), {documents} = context;
|
|
223
|
+
const state = context.scope.getRelativeData('.');
|
|
224
|
+
if (documents.revert(documentKey)) state.setItem('status','Restored the last saved version.');
|
|
199
225
|
}
|
|
200
226
|
ideHistoryChanged(node, {canUndo,canRedo}) {
|
|
201
227
|
const doc = node.getRelativeData('.');
|
|
@@ -209,30 +235,34 @@ export class IdeLogic {
|
|
|
209
235
|
doc.setItem('undoDisabled',!doc.getItem(`${view}CanUndo`));
|
|
210
236
|
doc.setItem('redoDisabled',!doc.getItem(`${view}CanRedo`));
|
|
211
237
|
}
|
|
212
|
-
ideEditor(documentKey) {
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
238
|
+
ideEditor(node, documentKey) {
|
|
239
|
+
const context = ideContext(node), {documents} = context;
|
|
240
|
+
const rich = documents.documents.getItem(documentKey).getItem('view') === 'rich';
|
|
241
|
+
const editor = this.page.src.binding.nodeIds.get(`${context.editorPrefix}_${rich ? 'rich_' : ''}editor_${documentKey}`);
|
|
242
|
+
return this.page.src.renderer.records.get(editor).element;
|
|
216
243
|
}
|
|
217
|
-
ideUndo(node, {documentKey}) { this.ideEditor(documentKey).undo(); }
|
|
218
|
-
ideRedo(node, {documentKey}) { this.ideEditor(documentKey).redo(); }
|
|
244
|
+
ideUndo(node, {documentKey}) { this.ideEditor(node,documentKey).undo(); }
|
|
245
|
+
ideRedo(node, {documentKey}) { this.ideEditor(node,documentKey).redo(); }
|
|
219
246
|
ideClose(node) {
|
|
247
|
+
const context = ideContext(node), {documents} = context;
|
|
248
|
+
const state = context.scope.getRelativeData('.');
|
|
220
249
|
const key = node.getAttr('documentKey');
|
|
221
|
-
if (!
|
|
222
|
-
|
|
250
|
+
if (!documents.canClose(key)) {
|
|
251
|
+
state.setItem('status','Save or revert your changes before closing. Pending operations must finish first.');
|
|
223
252
|
return false;
|
|
224
253
|
}
|
|
225
254
|
return true;
|
|
226
255
|
}
|
|
227
|
-
ideClosed(node, {pageName}) { this.ideForgetDocument(pageName); }
|
|
228
|
-
ideForgetDocument(key, discard = false) {
|
|
229
|
-
const
|
|
230
|
-
const
|
|
256
|
+
ideClosed(node, {pageName}) { this.ideForgetDocument(node,pageName); }
|
|
257
|
+
ideForgetDocument(node, key, discard = false) {
|
|
258
|
+
const context = ideContext(node), {documents} = context;
|
|
259
|
+
const state = context.scope.getRelativeData('.');
|
|
260
|
+
const document = documents.documents.getItem(key);
|
|
261
|
+
const browser = state.getItem('browser'), selectedPath = browser.getItem('selectedPath');
|
|
231
262
|
const selected = selectedPath === null ? null : browser.getItem('store').getNode(selectedPath);
|
|
232
263
|
if (document && browser.getItem('root') === document.getItem('root') && selected?.attr.path === document.getItem('path')) {
|
|
233
264
|
browser.setItem('selectedPath',null);
|
|
234
265
|
}
|
|
235
|
-
|
|
236
|
-
this.ideDocuments.close(key,discard);
|
|
266
|
+
documents.close(key,discard);
|
|
237
267
|
}
|
|
238
268
|
}
|
|
@@ -4,8 +4,8 @@ export function mountIndexPage(renderer: any, root: any,
|
|
|
4
4
|
onSelection?: (entries: Map<string, IndexEntry>, active: string | null) => void,
|
|
5
5
|
prepareEntry?: (entry: IndexEntry) => void,
|
|
6
6
|
options?: {state?: Bag; createEntry?: (entry: IndexEntry) => Promise<void>;
|
|
7
|
-
onLoad?: (url: string, status:
|
|
8
|
-
export class IndexLogic {indexMount(node: any
|
|
7
|
+
onLoad?: (url: string, status: 'loading' | 'ready' | 'error' | 'cancelled', error?: Error) => void}): {entries: Map<string, IndexEntry>; dispose(): void};
|
|
8
|
+
export class IndexLogic {indexMount(node: any): void;}
|
|
9
9
|
export const THEME_READY: string;
|
|
10
10
|
export const THEME_SET: string;
|
|
11
11
|
export const THEMES: Set<string>;
|