Reapplied all the things
This commit is contained in:
parent
a1a10a1d1f
commit
16bf0d866d
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/silverbullet.iml" filepath="$PROJECT_DIR$/.idea/silverbullet.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
9
.idea/silverbullet.iml
generated
Normal file
9
.idea/silverbullet.iml
generated
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
16
common/syscalls/markdown.ts
Normal file
16
common/syscalls/markdown.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import {SysCallMapping} from "../../plugos/system";
|
||||||
|
import {MarkdownTree, nodeAtPos, parse, render} from "../tree";
|
||||||
|
|
||||||
|
export function markdownSyscalls(): SysCallMapping {
|
||||||
|
return {
|
||||||
|
parse(ctx, text: string): MarkdownTree {
|
||||||
|
return parse(text);
|
||||||
|
},
|
||||||
|
nodeAtPos(ctx, mdTree: MarkdownTree, pos: number): MarkdownTree | null {
|
||||||
|
return nodeAtPos(mdTree, pos);
|
||||||
|
},
|
||||||
|
render(ctx, mdTree: MarkdownTree): string {
|
||||||
|
return render(mdTree);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
26
common/tree.test.ts
Normal file
26
common/tree.test.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import {expect, test} from "@jest/globals";
|
||||||
|
import {nodeAtPos, parse, render} from "./tree";
|
||||||
|
|
||||||
|
const mdTest1 = `
|
||||||
|
# Heading
|
||||||
|
## Sub _heading_ cool
|
||||||
|
|
||||||
|
Hello, this is some **bold** text and *italic*. And [a link](http://zef.me).
|
||||||
|
|
||||||
|
- This is a list
|
||||||
|
- With another item
|
||||||
|
- TODOs:
|
||||||
|
- [ ] A task that's not yet done
|
||||||
|
- [x] Hello
|
||||||
|
- And a _third_ one [[Wiki Page]] yo
|
||||||
|
`;
|
||||||
|
|
||||||
|
test("Run a Node sandbox", async () => {
|
||||||
|
let mdTree = parse(mdTest1);
|
||||||
|
console.log(JSON.stringify(mdTree, null, 2));
|
||||||
|
expect(nodeAtPos(mdTree, 4)!.type).toBe("ATXHeading1");
|
||||||
|
expect(nodeAtPos(mdTree, mdTest1.indexOf("Wiki Page"))!.type).toBe(
|
||||||
|
"WikiLink"
|
||||||
|
);
|
||||||
|
expect(render(mdTree)).toBe(mdTest1);
|
||||||
|
});
|
115
common/tree.ts
Normal file
115
common/tree.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import {SyntaxNode} from "@lezer/common";
|
||||||
|
import wikiMarkdownLang from "../webapp/parser";
|
||||||
|
|
||||||
|
export type MarkdownTree = {
|
||||||
|
type?: string; // undefined === text node
|
||||||
|
from: number;
|
||||||
|
to: number;
|
||||||
|
text?: string;
|
||||||
|
children?: MarkdownTree[];
|
||||||
|
parent?: MarkdownTree;
|
||||||
|
};
|
||||||
|
|
||||||
|
function treeToAST(text: string, n: SyntaxNode): MarkdownTree {
|
||||||
|
let children: MarkdownTree[] = [];
|
||||||
|
let nodeText: string | undefined;
|
||||||
|
let child = n.firstChild;
|
||||||
|
while (child) {
|
||||||
|
children.push(treeToAST(text, child));
|
||||||
|
child = child.nextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (children.length === 0) {
|
||||||
|
children = [
|
||||||
|
{
|
||||||
|
from: n.from,
|
||||||
|
to: n.to,
|
||||||
|
text: text.substring(n.from, n.to),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
let newChildren: MarkdownTree[] | string = [];
|
||||||
|
let index = n.from;
|
||||||
|
for (let child of children) {
|
||||||
|
let s = text.substring(index, child.from);
|
||||||
|
if (s) {
|
||||||
|
newChildren.push({
|
||||||
|
from: index,
|
||||||
|
to: child.from,
|
||||||
|
text: s,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
newChildren.push(child);
|
||||||
|
index = child.to;
|
||||||
|
}
|
||||||
|
let s = text.substring(index, n.to);
|
||||||
|
if (s) {
|
||||||
|
newChildren.push({ from: index, to: n.to, text: s });
|
||||||
|
}
|
||||||
|
children = newChildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
let result: MarkdownTree = {
|
||||||
|
type: n.name,
|
||||||
|
from: n.from,
|
||||||
|
to: n.to,
|
||||||
|
};
|
||||||
|
if (children.length > 0) {
|
||||||
|
result.children = children;
|
||||||
|
}
|
||||||
|
if (nodeText) {
|
||||||
|
result.text = nodeText;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currently unused
|
||||||
|
function addParentPointers(mdTree: MarkdownTree) {
|
||||||
|
if (!mdTree.children) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let child of mdTree.children) {
|
||||||
|
child.parent = mdTree;
|
||||||
|
addParentPointers(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finds non-text node at position
|
||||||
|
export function nodeAtPos(
|
||||||
|
mdTree: MarkdownTree,
|
||||||
|
pos: number
|
||||||
|
): MarkdownTree | null {
|
||||||
|
if (pos < mdTree.from || pos > mdTree.to) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!mdTree.children) {
|
||||||
|
return mdTree;
|
||||||
|
}
|
||||||
|
for (let child of mdTree.children) {
|
||||||
|
let n = nodeAtPos(child, pos);
|
||||||
|
if (n && n.text) {
|
||||||
|
// Got a text node, let's return its parent
|
||||||
|
return mdTree;
|
||||||
|
} else if (n) {
|
||||||
|
// Got it
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turn MarkdownTree back into regular markdown text
|
||||||
|
export function render(mdTree: MarkdownTree): string {
|
||||||
|
let pieces: string[] = [];
|
||||||
|
if (mdTree.text) {
|
||||||
|
return mdTree.text;
|
||||||
|
}
|
||||||
|
for (let child of mdTree.children!) {
|
||||||
|
pieces.push(render(child));
|
||||||
|
}
|
||||||
|
return pieces.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parse(text: string): MarkdownTree {
|
||||||
|
return treeToAST(text, wikiMarkdownLang.parser.parse(text).topNode);
|
||||||
|
}
|
@ -35,7 +35,7 @@
|
|||||||
"context": "node"
|
"context": "node"
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
"source": [],
|
"source": ["common/tree.test.ts"],
|
||||||
"outputFormat": "commonjs",
|
"outputFormat": "commonjs",
|
||||||
"isLibrary": true,
|
"isLibrary": true,
|
||||||
"context": "node"
|
"context": "node"
|
||||||
@ -54,6 +54,9 @@
|
|||||||
"@fortawesome/fontawesome-svg-core": "1.3.0",
|
"@fortawesome/fontawesome-svg-core": "1.3.0",
|
||||||
"@fortawesome/free-solid-svg-icons": "6.0.0",
|
"@fortawesome/free-solid-svg-icons": "6.0.0",
|
||||||
"@fortawesome/react-fontawesome": "0.1.17",
|
"@fortawesome/react-fontawesome": "0.1.17",
|
||||||
|
"@codemirror/highlight": "^0.19.0",
|
||||||
|
"@codemirror/language": "^0.19.0",
|
||||||
|
"@lezer/markdown": "^0.15.0",
|
||||||
"@jest/globals": "^27.5.1",
|
"@jest/globals": "^27.5.1",
|
||||||
"better-sqlite3": "^7.5.0",
|
"better-sqlite3": "^7.5.0",
|
||||||
"body-parser": "^1.19.2",
|
"body-parser": "^1.19.2",
|
||||||
|
17
plugos-silverbullet-syscall/markdown.ts
Normal file
17
plugos-silverbullet-syscall/markdown.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import {syscall} from "./syscall";
|
||||||
|
import type {MarkdownTree} from "../common/tree";
|
||||||
|
|
||||||
|
export async function parse(text: string): Promise<MarkdownTree> {
|
||||||
|
return syscall("markdown.parse", text);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function nodeAtPos(
|
||||||
|
mdTree: MarkdownTree,
|
||||||
|
pos: number
|
||||||
|
): Promise<any | null> {
|
||||||
|
return syscall("markdown.nodeAtPos", mdTree, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function render(mdTree: MarkdownTree): Promise<string> {
|
||||||
|
return syscall("markdown.render", mdTree);
|
||||||
|
}
|
@ -1,16 +1,11 @@
|
|||||||
import {
|
import {flashNotification, getCurrentPage, reloadPage, save,} from "plugos-silverbullet-syscall/editor";
|
||||||
flashNotification,
|
|
||||||
getCurrentPage,
|
|
||||||
reloadPage,
|
|
||||||
save,
|
|
||||||
} from "plugos-silverbullet-syscall/editor";
|
|
||||||
|
|
||||||
import { readPage, writePage } from "plugos-silverbullet-syscall/space";
|
import {readPage, writePage} from "plugos-silverbullet-syscall/space";
|
||||||
import { invokeFunctionOnServer } from "plugos-silverbullet-syscall/system";
|
import {invokeFunctionOnServer} from "plugos-silverbullet-syscall/system";
|
||||||
import { scanPrefixGlobal } from "plugos-silverbullet-syscall";
|
import {scanPrefixGlobal} from "plugos-silverbullet-syscall";
|
||||||
|
|
||||||
export const queryRegex =
|
export const queryRegex =
|
||||||
/(<!--\s*#query\s+(?<table>\w+)\s*(filter\s+["'“”‘’](?<filter>[^"'“”‘’]+)["'“”‘’])?\s*-->)(.+?)(<!--\s*#end\s*-->)/gs;
|
/(<!--\s*#query\s+(?<table>\w+)\s*(filter\s+["'“”‘’](?<filter>[^"'“”‘’]+)["'“”‘’])?\s*(group by\s+(?<groupBy>\w+))?\s*-->)(.+?)(<!--\s*#end\s*-->)/gs;
|
||||||
|
|
||||||
export function whiteOutQueries(text: string): string {
|
export function whiteOutQueries(text: string): string {
|
||||||
return text.replaceAll(queryRegex, (match) =>
|
return text.replaceAll(queryRegex, (match) =>
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import { ClickEvent } from "../../webapp/app_event";
|
import {ClickEvent} from "../../webapp/app_event";
|
||||||
import { updateMaterializedQueriesCommand } from "./materialized_queries";
|
import {updateMaterializedQueriesCommand} from "./materialized_queries";
|
||||||
import {
|
import {
|
||||||
getSyntaxNodeAtPos,
|
getSyntaxNodeAtPos,
|
||||||
getSyntaxNodeUnderCursor,
|
getSyntaxNodeUnderCursor,
|
||||||
navigate as navigateTo,
|
getText,
|
||||||
openUrl,
|
navigate as navigateTo,
|
||||||
|
openUrl,
|
||||||
} from "plugos-silverbullet-syscall/editor";
|
} from "plugos-silverbullet-syscall/editor";
|
||||||
import { taskToggleAtPos } from "../tasks/task";
|
import {taskToggleAtPos} from "../tasks/task";
|
||||||
|
import {nodeAtPos, parse} from "plugos-silverbullet-syscall/markdown";
|
||||||
|
|
||||||
const materializedQueryPrefix = /<!--\s*#query\s+/;
|
const materializedQueryPrefix = /<!--\s*#query\s+/;
|
||||||
|
|
||||||
@ -52,6 +54,9 @@ export async function linkNavigate() {
|
|||||||
export async function clickNavigate(event: ClickEvent) {
|
export async function clickNavigate(event: ClickEvent) {
|
||||||
if (event.ctrlKey || event.metaKey) {
|
if (event.ctrlKey || event.metaKey) {
|
||||||
let syntaxNode = await getSyntaxNodeAtPos(event.pos);
|
let syntaxNode = await getSyntaxNodeAtPos(event.pos);
|
||||||
|
let mdTree = await parse(await getText());
|
||||||
|
let newNode = await nodeAtPos(mdTree, event.pos);
|
||||||
|
console.log("New node", newNode);
|
||||||
await actionClickOrActionEnter(syntaxNode);
|
await actionClickOrActionEnter(syntaxNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
plugs/emoji/emoji.json
Normal file
1
plugs/emoji/emoji.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,19 +1,20 @@
|
|||||||
import express, { Express } from "express";
|
import express, {Express} from "express";
|
||||||
import { SilverBulletHooks } from "../common/manifest";
|
import {SilverBulletHooks} from "../common/manifest";
|
||||||
import { EndpointHook } from "../plugos/hooks/endpoint";
|
import {EndpointHook} from "../plugos/hooks/endpoint";
|
||||||
import { readFile } from "fs/promises";
|
import {readFile} from "fs/promises";
|
||||||
import { System } from "../plugos/system";
|
import {System} from "../plugos/system";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import { DiskStorage, EventedStorage, Storage } from "./disk_storage";
|
import {DiskStorage, EventedStorage, Storage} from "./disk_storage";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import bodyParser from "body-parser";
|
import bodyParser from "body-parser";
|
||||||
import { EventHook } from "../plugos/hooks/event";
|
import {EventHook} from "../plugos/hooks/event";
|
||||||
import spaceSyscalls from "./syscalls/space";
|
import spaceSyscalls from "./syscalls/space";
|
||||||
import { eventSyscalls } from "../plugos/syscalls/event";
|
import {eventSyscalls} from "../plugos/syscalls/event";
|
||||||
import { pageIndexSyscalls } from "./syscalls";
|
import {pageIndexSyscalls} from "./syscalls";
|
||||||
import knex, { Knex } from "knex";
|
import knex, {Knex} from "knex";
|
||||||
import shellSyscalls from "../plugos/syscalls/shell.node";
|
import shellSyscalls from "../plugos/syscalls/shell.node";
|
||||||
import { NodeCronHook } from "../plugos/hooks/node_cron";
|
import {NodeCronHook} from "../plugos/hooks/node_cron";
|
||||||
|
import {markdownSyscalls} from "../common/syscalls/markdown";
|
||||||
|
|
||||||
export class ExpressServer {
|
export class ExpressServer {
|
||||||
app: Express;
|
app: Express;
|
||||||
@ -56,6 +57,7 @@ export class ExpressServer {
|
|||||||
system.registerSyscalls("index", [], pageIndexSyscalls(this.db));
|
system.registerSyscalls("index", [], pageIndexSyscalls(this.db));
|
||||||
system.registerSyscalls("space", [], spaceSyscalls(this.storage));
|
system.registerSyscalls("space", [], spaceSyscalls(this.storage));
|
||||||
system.registerSyscalls("event", [], eventSyscalls(this.eventHook));
|
system.registerSyscalls("event", [], eventSyscalls(this.eventHook));
|
||||||
|
system.registerSyscalls("markdown", [], markdownSyscalls());
|
||||||
system.addHook(new EndpointHook(app, "/_"));
|
system.addHook(new EndpointHook(app, "/_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
|
import {autocompletion, completionKeymap} from "@codemirror/autocomplete";
|
||||||
import { closeBrackets, closeBracketsKeymap } from "@codemirror/closebrackets";
|
import {closeBrackets, closeBracketsKeymap} from "@codemirror/closebrackets";
|
||||||
import { indentWithTab, standardKeymap } from "@codemirror/commands";
|
import {indentWithTab, standardKeymap} from "@codemirror/commands";
|
||||||
import { history, historyKeymap } from "@codemirror/history";
|
import {history, historyKeymap} from "@codemirror/history";
|
||||||
import { bracketMatching } from "@codemirror/matchbrackets";
|
import {bracketMatching} from "@codemirror/matchbrackets";
|
||||||
import { searchKeymap } from "@codemirror/search";
|
import {searchKeymap} from "@codemirror/search";
|
||||||
import { EditorSelection, EditorState } from "@codemirror/state";
|
import {EditorSelection, EditorState} from "@codemirror/state";
|
||||||
import {
|
import {
|
||||||
drawSelection,
|
drawSelection,
|
||||||
dropCursor,
|
dropCursor,
|
||||||
@ -15,36 +15,38 @@ import {
|
|||||||
ViewPlugin,
|
ViewPlugin,
|
||||||
ViewUpdate,
|
ViewUpdate,
|
||||||
} from "@codemirror/view";
|
} from "@codemirror/view";
|
||||||
import React, { useEffect, useReducer } from "react";
|
import React, {useEffect, useReducer} from "react";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import { createSandbox as createIFrameSandbox } from "../plugos/environments/iframe_sandbox";
|
import {createSandbox as createIFrameSandbox} from "../plugos/environments/iframe_sandbox";
|
||||||
import { AppEvent, AppEventDispatcher, ClickEvent } from "./app_event";
|
import {AppEvent, AppEventDispatcher, ClickEvent} from "./app_event";
|
||||||
import * as commands from "./commands";
|
import * as commands from "./commands";
|
||||||
import { CommandPalette } from "./components/command_palette";
|
import {CommandPalette} from "./components/command_palette";
|
||||||
import { PageNavigator } from "./components/page_navigator";
|
import {PageNavigator} from "./components/page_navigator";
|
||||||
import { TopBar } from "./components/top_bar";
|
import {TopBar} from "./components/top_bar";
|
||||||
import { lineWrapper } from "./line_wrapper";
|
import {lineWrapper} from "./line_wrapper";
|
||||||
import { markdown } from "./markdown";
|
import {markdown} from "./markdown";
|
||||||
import { PathPageNavigator } from "./navigator";
|
import {PathPageNavigator} from "./navigator";
|
||||||
import customMarkDown from "./parser";
|
import customMarkDown from "./parser";
|
||||||
import reducer from "./reducer";
|
import reducer from "./reducer";
|
||||||
import { smartQuoteKeymap } from "./smart_quotes";
|
import {smartQuoteKeymap} from "./smart_quotes";
|
||||||
import { Space } from "./space";
|
import {Space} from "./space";
|
||||||
import customMarkdownStyle from "./style";
|
import customMarkdownStyle from "./style";
|
||||||
import editorSyscalls from "./syscalls/editor";
|
import {editorSyscalls} from "./syscalls/editor";
|
||||||
import indexerSyscalls from "./syscalls/indexer";
|
import {indexerSyscalls} from "./syscalls/indexer";
|
||||||
import spaceSyscalls from "./syscalls/space";
|
import {spaceSyscalls} from "./syscalls/space";
|
||||||
import { Action, AppViewState, initialViewState } from "./types";
|
import {Action, AppViewState, initialViewState} from "./types";
|
||||||
import { SilverBulletHooks } from "../common/manifest";
|
import {SilverBulletHooks} from "../common/manifest";
|
||||||
import { safeRun, throttle } from "./util";
|
import {safeRun, throttle} from "./util";
|
||||||
import { System } from "../plugos/system";
|
import {System} from "../plugos/system";
|
||||||
import { EventHook } from "../plugos/hooks/event";
|
import {EventHook} from "../plugos/hooks/event";
|
||||||
import { systemSyscalls } from "./syscalls/system";
|
import {systemSyscalls} from "./syscalls/system";
|
||||||
import { Panel } from "./components/panel";
|
import {Panel} from "./components/panel";
|
||||||
import { CommandHook } from "./hooks/command";
|
import {CommandHook} from "./hooks/command";
|
||||||
import { SlashCommandHook } from "./hooks/slash_command";
|
import {SlashCommandHook} from "./hooks/slash_command";
|
||||||
import { CompleterHook } from "./hooks/completer";
|
import {CompleterHook} from "./hooks/completer";
|
||||||
import { pasteLinkExtension } from "./editor_paste";
|
import {pasteLinkExtension} from "./editor_paste";
|
||||||
|
import {markdownSyscalls} from "../common/syscalls/markdown";
|
||||||
|
|
||||||
|
|
||||||
class PageState {
|
class PageState {
|
||||||
scrollTop: number;
|
scrollTop: number;
|
||||||
@ -112,6 +114,7 @@ export class Editor implements AppEventDispatcher {
|
|||||||
this.system.registerSyscalls("space", [], spaceSyscalls(this));
|
this.system.registerSyscalls("space", [], spaceSyscalls(this));
|
||||||
this.system.registerSyscalls("index", [], indexerSyscalls(this.space));
|
this.system.registerSyscalls("index", [], indexerSyscalls(this.space));
|
||||||
this.system.registerSyscalls("system", [], systemSyscalls(this.space));
|
this.system.registerSyscalls("system", [], systemSyscalls(this.space));
|
||||||
|
this.system.registerSyscalls("markdown", [], markdownSyscalls());
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
@ -37,7 +37,7 @@ body {
|
|||||||
|
|
||||||
#top {
|
#top {
|
||||||
height: 55px;
|
height: 55px;
|
||||||
position: fixed;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
@ -83,7 +83,7 @@ body {
|
|||||||
#editor {
|
#editor {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 55px;
|
top: 55px;
|
||||||
bottom: 0;
|
bottom: 50px;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Editor } from "../editor";
|
import {Editor} from "../editor";
|
||||||
import { syntaxTree } from "@codemirror/language";
|
import {syntaxTree} from "@codemirror/language";
|
||||||
import { Transaction } from "@codemirror/state";
|
import {Transaction} from "@codemirror/state";
|
||||||
import { SysCallMapping } from "../../plugos/system";
|
import {SysCallMapping} from "../../plugos/system";
|
||||||
|
|
||||||
type SyntaxNode = {
|
type SyntaxNode = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -26,79 +26,118 @@ function ensureAnchor(expr: any, start: boolean) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (editor: Editor): SysCallMapping => ({
|
export function editorSyscalls(editor: Editor): SysCallMapping {
|
||||||
getCurrentPage: (): string => {
|
return {
|
||||||
return editor.currentPage!;
|
getCurrentPage: (): string => {
|
||||||
},
|
return editor.currentPage!;
|
||||||
getText: () => {
|
},
|
||||||
return editor.editorView?.state.sliceDoc();
|
getText: () => {
|
||||||
},
|
return editor.editorView?.state.sliceDoc();
|
||||||
getCursor: (): number => {
|
},
|
||||||
return editor.editorView!.state.selection.main.from;
|
getCursor: (): number => {
|
||||||
},
|
return editor.editorView!.state.selection.main.from;
|
||||||
save: async () => {
|
},
|
||||||
return editor.save(true);
|
save: async () => {
|
||||||
},
|
return editor.save(true);
|
||||||
navigate: async (ctx, name: string, pos: number) => {
|
},
|
||||||
await editor.navigate(name, pos);
|
navigate: async (ctx, name: string, pos: number) => {
|
||||||
},
|
await editor.navigate(name, pos);
|
||||||
reloadPage: async (ctx) => {
|
},
|
||||||
await editor.reloadPage();
|
reloadPage: async (ctx) => {
|
||||||
},
|
await editor.reloadPage();
|
||||||
openUrl: async (ctx, url: string) => {
|
},
|
||||||
window.open(url, "_blank")!.focus();
|
openUrl: async (ctx, url: string) => {
|
||||||
},
|
window.open(url, "_blank")!.focus();
|
||||||
flashNotification: (ctx, message: string) => {
|
},
|
||||||
editor.flashNotification(message);
|
flashNotification: (ctx, message: string) => {
|
||||||
},
|
editor.flashNotification(message);
|
||||||
showRhs: (ctx, html: string) => {
|
},
|
||||||
editor.viewDispatch({
|
showRhs: (ctx, html: string) => {
|
||||||
type: "show-rhs",
|
editor.viewDispatch({
|
||||||
html: html,
|
type: "show-rhs",
|
||||||
});
|
html: html,
|
||||||
},
|
});
|
||||||
insertAtPos: (ctx, text: string, pos: number) => {
|
},
|
||||||
editor.editorView!.dispatch({
|
insertAtPos: (ctx, text: string, pos: number) => {
|
||||||
changes: {
|
editor.editorView!.dispatch({
|
||||||
insert: text,
|
changes: {
|
||||||
from: pos,
|
insert: text,
|
||||||
},
|
from: pos,
|
||||||
});
|
},
|
||||||
},
|
});
|
||||||
replaceRange: (ctx, from: number, to: number, text: string) => {
|
},
|
||||||
editor.editorView!.dispatch({
|
replaceRange: (ctx, from: number, to: number, text: string) => {
|
||||||
changes: {
|
editor.editorView!.dispatch({
|
||||||
insert: text,
|
changes: {
|
||||||
from: from,
|
insert: text,
|
||||||
to: to,
|
from: from,
|
||||||
},
|
to: to,
|
||||||
});
|
},
|
||||||
},
|
});
|
||||||
moveCursor: (ctx, pos: number) => {
|
},
|
||||||
editor.editorView!.dispatch({
|
moveCursor: (ctx, pos: number) => {
|
||||||
selection: {
|
editor.editorView!.dispatch({
|
||||||
anchor: pos,
|
selection: {
|
||||||
},
|
anchor: pos,
|
||||||
});
|
},
|
||||||
},
|
});
|
||||||
insertAtCursor: (ctx, text: string) => {
|
},
|
||||||
let editorView = editor.editorView!;
|
insertAtCursor: (ctx, text: string) => {
|
||||||
let from = editorView.state.selection.main.from;
|
let editorView = editor.editorView!;
|
||||||
editorView.dispatch({
|
let from = editorView.state.selection.main.from;
|
||||||
changes: {
|
editorView.dispatch({
|
||||||
insert: text,
|
changes: {
|
||||||
from: from,
|
insert: text,
|
||||||
},
|
from: from,
|
||||||
selection: {
|
},
|
||||||
anchor: from + text.length,
|
selection: {
|
||||||
},
|
anchor: from + text.length,
|
||||||
});
|
},
|
||||||
},
|
});
|
||||||
getSyntaxNodeUnderCursor: (): SyntaxNode | undefined => {
|
},
|
||||||
const editorState = editor.editorView!.state;
|
getSyntaxNodeUnderCursor: (): SyntaxNode | undefined => {
|
||||||
let selection = editorState.selection.main;
|
const editorState = editor.editorView!.state;
|
||||||
if (selection.empty) {
|
let selection = editorState.selection.main;
|
||||||
let node = syntaxTree(editorState).resolveInner(selection.from);
|
if (selection.empty) {
|
||||||
|
let node = syntaxTree(editorState).resolveInner(selection.from);
|
||||||
|
if (node) {
|
||||||
|
return {
|
||||||
|
name: node.name,
|
||||||
|
text: editorState.sliceDoc(node.from, node.to),
|
||||||
|
from: node.from,
|
||||||
|
to: node.to,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getLineUnderCursor: (): string => {
|
||||||
|
const editorState = editor.editorView!.state;
|
||||||
|
let selection = editorState.selection.main;
|
||||||
|
let line = editorState.doc.lineAt(selection.from);
|
||||||
|
return editorState.sliceDoc(line.from, line.to);
|
||||||
|
},
|
||||||
|
matchBefore: (
|
||||||
|
ctx,
|
||||||
|
regexp: string
|
||||||
|
): { from: number; to: number; text: string } | null => {
|
||||||
|
const editorState = editor.editorView!.state;
|
||||||
|
let selection = editorState.selection.main;
|
||||||
|
let from = selection.from;
|
||||||
|
if (selection.empty) {
|
||||||
|
let line = editorState.doc.lineAt(from);
|
||||||
|
let start = Math.max(line.from, from - 250);
|
||||||
|
let str = line.text.slice(start - line.from, from - line.from);
|
||||||
|
let found = str.search(ensureAnchor(new RegExp(regexp), false));
|
||||||
|
// console.log("Line", line, start, str, new RegExp(regexp), found);
|
||||||
|
return found < 0
|
||||||
|
? null
|
||||||
|
: { from: start + found, to: from, text: str.slice(found) };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
getSyntaxNodeAtPos: (ctx, pos: number): SyntaxNode | undefined => {
|
||||||
|
const editorState = editor.editorView!.state;
|
||||||
|
let node = syntaxTree(editorState).resolveInner(pos);
|
||||||
if (node) {
|
if (node) {
|
||||||
return {
|
return {
|
||||||
name: node.name,
|
name: node.name,
|
||||||
@ -107,49 +146,12 @@ export default (editor: Editor): SysCallMapping => ({
|
|||||||
to: node.to,
|
to: node.to,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
dispatch: (ctx, change: Transaction) => {
|
||||||
getLineUnderCursor: (): string => {
|
editor.editorView!.dispatch(change);
|
||||||
const editorState = editor.editorView!.state;
|
},
|
||||||
let selection = editorState.selection.main;
|
prompt: (ctx, message: string, defaultValue = ""): string | null => {
|
||||||
let line = editorState.doc.lineAt(selection.from);
|
return prompt(message, defaultValue);
|
||||||
return editorState.sliceDoc(line.from, line.to);
|
},
|
||||||
},
|
};
|
||||||
matchBefore: (
|
}
|
||||||
ctx,
|
|
||||||
regexp: string
|
|
||||||
): { from: number; to: number; text: string } | null => {
|
|
||||||
const editorState = editor.editorView!.state;
|
|
||||||
let selection = editorState.selection.main;
|
|
||||||
let from = selection.from;
|
|
||||||
if (selection.empty) {
|
|
||||||
let line = editorState.doc.lineAt(from);
|
|
||||||
let start = Math.max(line.from, from - 250);
|
|
||||||
let str = line.text.slice(start - line.from, from - line.from);
|
|
||||||
let found = str.search(ensureAnchor(new RegExp(regexp), false));
|
|
||||||
// console.log("Line", line, start, str, new RegExp(regexp), found);
|
|
||||||
return found < 0
|
|
||||||
? null
|
|
||||||
: { from: start + found, to: from, text: str.slice(found) };
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
getSyntaxNodeAtPos: (ctx, pos: number): SyntaxNode | undefined => {
|
|
||||||
const editorState = editor.editorView!.state;
|
|
||||||
let node = syntaxTree(editorState).resolveInner(pos);
|
|
||||||
if (node) {
|
|
||||||
return {
|
|
||||||
name: node.name,
|
|
||||||
text: editorState.sliceDoc(node.from, node.to),
|
|
||||||
from: node.from,
|
|
||||||
to: node.to,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dispatch: (ctx, change: Transaction) => {
|
|
||||||
editor.editorView!.dispatch(change);
|
|
||||||
},
|
|
||||||
prompt: (ctx, message: string, defaultValue = ""): string | null => {
|
|
||||||
return prompt(message, defaultValue);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Space } from "../space";
|
import {Space} from "../space";
|
||||||
import { SysCallMapping } from "../../plugos/system";
|
import {SysCallMapping} from "../../plugos/system";
|
||||||
import { transportSyscalls } from "../../plugos/syscalls/transport";
|
import {transportSyscalls} from "../../plugos/syscalls/transport";
|
||||||
|
|
||||||
export default function indexerSyscalls(space: Space): SysCallMapping {
|
export function indexerSyscalls(space: Space): SysCallMapping {
|
||||||
return transportSyscalls(
|
return transportSyscalls(
|
||||||
[
|
[
|
||||||
"scanPrefixForPage",
|
"scanPrefixForPage",
|
||||||
|
@ -1,28 +1,30 @@
|
|||||||
import { Editor } from "../editor";
|
import {Editor} from "../editor";
|
||||||
import { SysCallMapping } from "../../plugos/system";
|
import {SysCallMapping} from "../../plugos/system";
|
||||||
import { PageMeta } from "../../common/types";
|
import {PageMeta} from "../../common/types";
|
||||||
|
|
||||||
export default (editor: Editor): SysCallMapping => ({
|
export function spaceSyscalls(editor: Editor): SysCallMapping {
|
||||||
listPages: async (): Promise<PageMeta[]> => {
|
return {
|
||||||
return [...(await editor.space.listPages())];
|
listPages: async (): Promise<PageMeta[]> => {
|
||||||
},
|
return [...(await editor.space.listPages())];
|
||||||
readPage: async (
|
},
|
||||||
ctx,
|
readPage: async (
|
||||||
name: string
|
ctx,
|
||||||
): Promise<{ text: string; meta: PageMeta }> => {
|
name: string
|
||||||
return await editor.space.readPage(name);
|
): Promise<{ text: string; meta: PageMeta }> => {
|
||||||
},
|
return await editor.space.readPage(name);
|
||||||
writePage: async (ctx, name: string, text: string): Promise<PageMeta> => {
|
},
|
||||||
return await editor.space.writePage(name, text);
|
writePage: async (ctx, name: string, text: string): Promise<PageMeta> => {
|
||||||
},
|
return await editor.space.writePage(name, text);
|
||||||
deletePage: async (ctx, name: string) => {
|
},
|
||||||
// If we're deleting the current page, navigate to the start page
|
deletePage: async (ctx, name: string) => {
|
||||||
if (editor.currentPage === name) {
|
// If we're deleting the current page, navigate to the start page
|
||||||
await editor.navigate("start");
|
if (editor.currentPage === name) {
|
||||||
}
|
await editor.navigate("start");
|
||||||
// Remove page from open pages in editor
|
}
|
||||||
editor.openPages.delete(name);
|
// Remove page from open pages in editor
|
||||||
console.log("Deleting page");
|
editor.openPages.delete(name);
|
||||||
await editor.space.deletePage(name);
|
console.log("Deleting page");
|
||||||
},
|
await editor.space.deletePage(name);
|
||||||
});
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user