lint cleanup
parent
169f4ba302
commit
64e116f75e
|
@ -33,7 +33,7 @@ jobs:
|
||||||
- name: Setup Deno
|
- name: Setup Deno
|
||||||
uses: denoland/setup-deno@v1
|
uses: denoland/setup-deno@v1
|
||||||
with:
|
with:
|
||||||
deno-version: v1.44
|
deno-version: v1.45
|
||||||
|
|
||||||
- name: Run bundle build
|
- name: Run bundle build
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -13,7 +13,7 @@ jobs:
|
||||||
- name: Setup Deno
|
- name: Setup Deno
|
||||||
uses: denoland/setup-deno@v1
|
uses: denoland/setup-deno@v1
|
||||||
with:
|
with:
|
||||||
deno-version: v1.44
|
deno-version: v1.45
|
||||||
- name: Run build
|
- name: Run build
|
||||||
run: deno task build
|
run: deno task build
|
||||||
- name: Bundle
|
- name: Bundle
|
||||||
|
|
|
@ -16,7 +16,7 @@ jobs:
|
||||||
- name: Setup Deno
|
- name: Setup Deno
|
||||||
uses: denoland/setup-deno@v1
|
uses: denoland/setup-deno@v1
|
||||||
with:
|
with:
|
||||||
deno-version: v1.44
|
deno-version: v1.45
|
||||||
|
|
||||||
- name: Build bundles
|
- name: Build bundles
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -20,7 +20,7 @@ jobs:
|
||||||
- name: Setup Deno
|
- name: Setup Deno
|
||||||
uses: denoland/setup-deno@v1
|
uses: denoland/setup-deno@v1
|
||||||
with:
|
with:
|
||||||
deno-version: v1.44
|
deno-version: v1.45
|
||||||
|
|
||||||
- name: Run build
|
- name: Run build
|
||||||
run: deno task build
|
run: deno task build
|
||||||
|
@ -28,5 +28,11 @@ jobs:
|
||||||
- name: Run type check
|
- name: Run type check
|
||||||
run: deno task check
|
run: deno task check
|
||||||
|
|
||||||
|
- name: Run lint
|
||||||
|
run: deno task lint
|
||||||
|
|
||||||
|
- name: Run benchmarks
|
||||||
|
run: deno task bench
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: deno task test --trace-ops
|
run: deno task test --trace-ops
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
|
import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
|
||||||
import { compileManifest } from "../compile.ts";
|
import { compileManifest } from "../compile.ts";
|
||||||
import * as esbuild from "esbuild";
|
import * as esbuild from "esbuild";
|
||||||
import assets from "../../dist/plug_asset_bundle.json" assert { type: "json" };
|
import assets from "../../dist/plug_asset_bundle.json" with { type: "json" };
|
||||||
import { assertEquals } from "$std/testing/asserts.ts";
|
import { assertEquals } from "$std/testing/asserts.ts";
|
||||||
import { dirname, join } from "$std/path/mod.ts";
|
import { dirname, join } from "$std/path/mod.ts";
|
||||||
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
|
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
|
||||||
|
|
|
@ -35,11 +35,11 @@ Deno.test("Test parser", () => {
|
||||||
const links = collectNodesOfType(tree, "WikiLink");
|
const links = collectNodesOfType(tree, "WikiLink");
|
||||||
assertEquals(links.length, 2);
|
assertEquals(links.length, 2);
|
||||||
const nameNode = findNodeOfType(links[0], "WikiLinkPage");
|
const nameNode = findNodeOfType(links[0], "WikiLinkPage");
|
||||||
assertEquals(nameNode?.children![0].text, "wiki link");
|
assertEquals(nameNode!.children![0].text, "wiki link");
|
||||||
|
|
||||||
// Check if alias is parsed properly
|
// Check if alias is parsed properly
|
||||||
const aliasNode = findNodeOfType(links[1], "WikiLinkAlias");
|
const aliasNode = findNodeOfType(links[1], "WikiLinkAlias");
|
||||||
assertEquals(aliasNode?.children![0].text, "alias");
|
assertEquals(aliasNode!.children![0].text, "alias");
|
||||||
|
|
||||||
// Find frontmatter
|
// Find frontmatter
|
||||||
let node = findNodeOfType(tree, "FrontMatter");
|
let node = findNodeOfType(tree, "FrontMatter");
|
||||||
|
@ -65,19 +65,19 @@ Deno.test("Test inline attribute syntax", () => {
|
||||||
// console.log("Attribute parsed", JSON.stringify(tree, null, 2));
|
// console.log("Attribute parsed", JSON.stringify(tree, null, 2));
|
||||||
const attributes = collectNodesOfType(tree, "Attribute");
|
const attributes = collectNodesOfType(tree, "Attribute");
|
||||||
let nameNode = findNodeOfType(attributes[0], "AttributeName");
|
let nameNode = findNodeOfType(attributes[0], "AttributeName");
|
||||||
assertEquals(nameNode?.children![0].text, "age");
|
assertEquals(nameNode!.children![0].text, "age");
|
||||||
let valueNode = findNodeOfType(attributes[0], "AttributeValue");
|
let valueNode = findNodeOfType(attributes[0], "AttributeValue");
|
||||||
assertEquals(valueNode?.children![0].text, "100");
|
assertEquals(valueNode!.children![0].text, "100");
|
||||||
|
|
||||||
nameNode = findNodeOfType(attributes[1], "AttributeName");
|
nameNode = findNodeOfType(attributes[1], "AttributeName");
|
||||||
assertEquals(nameNode?.children![0].text, "age");
|
assertEquals(nameNode!.children![0].text, "age");
|
||||||
valueNode = findNodeOfType(attributes[1], "AttributeValue");
|
valueNode = findNodeOfType(attributes[1], "AttributeValue");
|
||||||
assertEquals(valueNode?.children![0].text, "200");
|
assertEquals(valueNode!.children![0].text, "200");
|
||||||
|
|
||||||
nameNode = findNodeOfType(attributes[2], "AttributeName");
|
nameNode = findNodeOfType(attributes[2], "AttributeName");
|
||||||
assertEquals(nameNode?.children![0].text, "array");
|
assertEquals(nameNode!.children![0].text, "array");
|
||||||
valueNode = findNodeOfType(attributes[2], "AttributeValue");
|
valueNode = findNodeOfType(attributes[2], "AttributeValue");
|
||||||
assertEquals(valueNode?.children![0].text, "[1, 2, 3]");
|
assertEquals(valueNode!.children![0].text, "[1, 2, 3]");
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test("Test template directive parsing", () => {
|
Deno.test("Test template directive parsing", () => {
|
||||||
|
|
|
@ -21,7 +21,7 @@ function parseRow(
|
||||||
offset = 0,
|
offset = 0,
|
||||||
) {
|
) {
|
||||||
let count = 0, first = true, cellStart = -1, cellEnd = -1, esc = false;
|
let count = 0, first = true, cellStart = -1, cellEnd = -1, esc = false;
|
||||||
let parseCell = () => {
|
const parseCell = () => {
|
||||||
elts!.push(
|
elts!.push(
|
||||||
cx.elt(
|
cx.elt(
|
||||||
"TableCell",
|
"TableCell",
|
||||||
|
@ -37,7 +37,7 @@ function parseRow(
|
||||||
|
|
||||||
let inWikilink = false;
|
let inWikilink = false;
|
||||||
for (let i = startI; i < line.length; i++) {
|
for (let i = startI; i < line.length; i++) {
|
||||||
let next = line.charCodeAt(i);
|
const next = line.charCodeAt(i);
|
||||||
if (next === 91 /* '[' */ && line.charAt(i + 1) === "[") {
|
if (next === 91 /* '[' */ && line.charAt(i + 1) === "[") {
|
||||||
inWikilink = true;
|
inWikilink = true;
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -68,7 +68,7 @@ function parseRow(
|
||||||
|
|
||||||
function hasPipe(str: string, start: number) {
|
function hasPipe(str: string, start: number) {
|
||||||
for (let i = start; i < str.length; i++) {
|
for (let i = start; i < str.length; i++) {
|
||||||
let next = str.charCodeAt(i);
|
const next = str.charCodeAt(i);
|
||||||
if (next == 124 /* '|' */) return true;
|
if (next == 124 /* '|' */) return true;
|
||||||
if (next == 92 /* '\\' */) i++;
|
if (next == 92 /* '\\' */) i++;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ class TableParser implements LeafBlockParser {
|
||||||
(line.next == 45 || line.next == 58 || line.next == 124 /* '-:|' */) &&
|
(line.next == 45 || line.next == 58 || line.next == 124 /* '-:|' */) &&
|
||||||
delimiterLine.test(lineText = line.text.slice(line.pos))
|
delimiterLine.test(lineText = line.text.slice(line.pos))
|
||||||
) {
|
) {
|
||||||
let firstRow: Element[] = [],
|
const firstRow: Element[] = [],
|
||||||
firstCount = parseRow(cx, leaf.content, 0, firstRow, leaf.start);
|
firstCount = parseRow(cx, leaf.content, 0, firstRow, leaf.start);
|
||||||
if (firstCount == parseRow(cx, lineText, line.pos)) {
|
if (firstCount == parseRow(cx, lineText, line.pos)) {
|
||||||
this.rows = [
|
this.rows = [
|
||||||
|
@ -110,7 +110,7 @@ class TableParser implements LeafBlockParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this.rows) { // Line after the second
|
} else if (this.rows) { // Line after the second
|
||||||
let content: Element[] = [];
|
const content: Element[] = [];
|
||||||
parseRow(cx, line.text, line.pos, content, cx.lineStart);
|
parseRow(cx, line.text, line.pos, content, cx.lineStart);
|
||||||
this.rows.push(
|
this.rows.push(
|
||||||
cx.elt(
|
cx.elt(
|
||||||
|
@ -167,7 +167,7 @@ export const Table: MarkdownConfig = {
|
||||||
!hasPipe(line.text, line.basePos)
|
!hasPipe(line.text, line.basePos)
|
||||||
) return false;
|
) return false;
|
||||||
// @ts-ignore: internal
|
// @ts-ignore: internal
|
||||||
let next = cx.scanLine(cx.absoluteLineEnd + 1).text;
|
const next = cx.scanLine(cx.absoluteLineEnd + 1).text;
|
||||||
return delimiterLine.test(next) &&
|
return delimiterLine.test(next) &&
|
||||||
parseRow(cx, line.text, line.basePos) ==
|
parseRow(cx, line.text, line.basePos) ==
|
||||||
parseRow(cx, next, line.basePos);
|
parseRow(cx, next, line.basePos);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { ScriptEnvironment } from "./space_script.ts";
|
import { ScriptEnvironment } from "./space_script.ts";
|
||||||
|
|
||||||
Deno.test("Space script", async () => {
|
Deno.test("Space script", () => {
|
||||||
const env = new ScriptEnvironment();
|
const env = new ScriptEnvironment();
|
||||||
env.evalScript(
|
env.evalScript(
|
||||||
`
|
`
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
// deno-lint-ignore-file no-unreachable
|
||||||
import { S3SpacePrimitives } from "./s3_space_primitives.ts";
|
import { S3SpacePrimitives } from "./s3_space_primitives.ts";
|
||||||
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
|
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
|
||||||
import { testSpacePrimitives } from "$common/spaces/space_primitives.test.ts";
|
import { testSpacePrimitives } from "$common/spaces/space_primitives.test.ts";
|
||||||
|
|
||||||
Deno.test("s3_space_primitives", async () => {
|
Deno.test("s3_space_primitives", async () => {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
accessKey: Deno.env.get("AWS_ACCESS_KEY_ID")!,
|
accessKey: Deno.env.get("AWS_ACCESS_KEY_ID")!,
|
||||||
secretKey: Deno.env.get("AWS_SECRET_ACCESS_KEY")!,
|
secretKey: Deno.env.get("AWS_SECRET_ACCESS_KEY")!,
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
"install": "deno install -g -f --unstable-kv --unstable-worker-options -A --import-map deno.json silverbullet.ts",
|
"install": "deno install -g -f --unstable-kv --unstable-worker-options -A --import-map deno.json silverbullet.ts",
|
||||||
|
|
||||||
"check": "find . -name '*.ts*' | xargs deno check",
|
"check": "find . -name '*.ts*' | xargs deno check",
|
||||||
|
"lint": "deno lint",
|
||||||
"test": "deno test -A --unstable-kv --unstable-worker-options",
|
"test": "deno test -A --unstable-kv --unstable-worker-options",
|
||||||
"bench": "deno bench",
|
"bench": "deno bench",
|
||||||
|
|
||||||
|
@ -30,7 +31,10 @@
|
||||||
"lint": {
|
"lint": {
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist",
|
"dist",
|
||||||
"dist_bundle"
|
"dist_client_bundle",
|
||||||
|
"dist_plug_bundle",
|
||||||
|
"cmd/test_space",
|
||||||
|
"cmd/test/test_space"
|
||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"exclude": ["no-explicit-any"]
|
"exclude": ["no-explicit-any"]
|
||||||
|
|
|
@ -35,8 +35,8 @@ Deno.test("Batch test", async () => {
|
||||||
return batch.map((e) => e * 2);
|
return batch.map((e) => e * 2);
|
||||||
}, 9);
|
}, 9);
|
||||||
assertEquals(multiplied, elements.map((e) => e * 2));
|
assertEquals(multiplied, elements.map((e) => e * 2));
|
||||||
const multiplied2 = await batchRequests(elements, async (batch) => {
|
const multiplied2 = await batchRequests(elements, (batch) => {
|
||||||
return batch.map((e) => e * 2);
|
return Promise.resolve(batch.map((e) => e * 2));
|
||||||
}, 10000);
|
}, 10000);
|
||||||
assertEquals(multiplied2, elements.map((e) => e * 2));
|
assertEquals(multiplied2, elements.map((e) => e * 2));
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
import { KV, KvKey } from "../../plug-api/types.ts";
|
|
||||||
import { KvPrimitives, KvQueryOptions } from "./kv_primitives.ts";
|
|
||||||
import { createClient, DynamoDBClient } from "../deps_server.ts";
|
|
||||||
|
|
||||||
export type AwsOptions = {
|
|
||||||
accessKey: string;
|
|
||||||
secretKey: string;
|
|
||||||
region: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const keySeparator = "\0";
|
|
||||||
|
|
||||||
const batchReadSize = 100;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start of an implementation, to be continued at some point
|
|
||||||
*/
|
|
||||||
|
|
||||||
export class DynamoDBKvPrimitives implements KvPrimitives {
|
|
||||||
client: DynamoDBClient;
|
|
||||||
partitionKey: string;
|
|
||||||
tableName: string;
|
|
||||||
|
|
||||||
constructor(tableName: string, partitionKey: string, options: AwsOptions) {
|
|
||||||
this.tableName = tableName;
|
|
||||||
this.partitionKey = partitionKey;
|
|
||||||
this.client = createClient({
|
|
||||||
credentials: {
|
|
||||||
accessKeyId: options.accessKey,
|
|
||||||
secretAccessKey: options.secretKey,
|
|
||||||
},
|
|
||||||
region: options.region,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
batchGet(keys: KvKey[]): Promise<any[]> {
|
|
||||||
const allResults: any[] = [];
|
|
||||||
const promises: Promise<any>[] = [];
|
|
||||||
for (let i = 0; i < keys.length; i += batchReadSize) {
|
|
||||||
const batch = keys.slice(i, i + batchReadSize);
|
|
||||||
promises.push(
|
|
||||||
this.client.batchGetItem(
|
|
||||||
{
|
|
||||||
RequestItems: {
|
|
||||||
[this.tableName]: {
|
|
||||||
Keys: batch.map((key) => ({
|
|
||||||
pk: this.partitionKey,
|
|
||||||
sk: key.join(keySeparator),
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
batchSet(entries: KV[]): Promise<void> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
batchDelete(keys: KvKey[]): Promise<void> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
query(options: KvQueryOptions): AsyncIterableIterator<KV> {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
close(): void {
|
|
||||||
throw new Error("Method not implemented.");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -34,14 +34,6 @@ http://zef.plus
|
||||||
- And a _third_ one [[Wiki Page]] yo
|
- And a _third_ one [[Wiki Page]] yo
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const mdTest2 = `
|
|
||||||
Hello
|
|
||||||
|
|
||||||
* Item 1
|
|
||||||
*
|
|
||||||
|
|
||||||
Sup`;
|
|
||||||
|
|
||||||
const mdTest3 = `
|
const mdTest3 = `
|
||||||
\`\`\`yaml
|
\`\`\`yaml
|
||||||
name: something
|
name: something
|
||||||
|
@ -74,7 +66,7 @@ Deno.test("Test parsing", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// console.log(JSON.stringify(mdTree, null, 2));
|
// console.log(JSON.stringify(mdTree, null, 2));
|
||||||
let mdTree3 = parse(extendedMarkdownLanguage, mdTest3);
|
parse(extendedMarkdownLanguage, mdTest3);
|
||||||
// console.log(JSON.stringify(mdTree3, null, 2));
|
// console.log(JSON.stringify(mdTree3, null, 2));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ async function actionClickOrActionEnter(
|
||||||
case "CommandLink": {
|
case "CommandLink": {
|
||||||
const commandName = mdTree.children![1]!.children![0].text!;
|
const commandName = mdTree.children![1]!.children![0].text!;
|
||||||
const argsNode = findNodeOfType(mdTree, "CommandLinkArgs");
|
const argsNode = findNodeOfType(mdTree, "CommandLinkArgs");
|
||||||
const argsText = argsNode?.children![0]?.text;
|
const argsText = argsNode?.children?.[0]?.text;
|
||||||
// Assume the arguments are can be parsed as the innards of a valid JSON list
|
// Assume the arguments are can be parsed as the innards of a valid JSON list
|
||||||
try {
|
try {
|
||||||
const args = argsText ? JSON.parse(`[${argsText}]`) : [];
|
const args = argsText ? JSON.parse(`[${argsText}]`) : [];
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// Generates emoji.json from emoji-data.txt
|
// Generates emoji.json from emoji-data.txt
|
||||||
const emojiRe = /#\s([^\s]+)\s+E[^\s]+\s+(.+)$/;
|
const emojiRe = /#\s([^\s]+)\s+E[^\s]+\s+(.+)$/;
|
||||||
|
|
||||||
let text = Deno.readTextFileSync("emoji-data.txt");
|
const text = Deno.readTextFileSync("emoji-data.txt");
|
||||||
const lines = text.split("\n").filter((line) => !line.startsWith("#"));
|
const lines = text.split("\n").filter((line) => !line.startsWith("#"));
|
||||||
|
|
||||||
const emojis: string[] = [];
|
const emojis: string[] = [];
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
let match = emojiRe.exec(line);
|
const match = emojiRe.exec(line);
|
||||||
if (match) {
|
if (match) {
|
||||||
const emoji = match[1];
|
const emoji = match[1];
|
||||||
const name = match[2].toLowerCase().replaceAll(/\W+/g, "_");
|
const name = match[2].toLowerCase().replaceAll(/\W+/g, "_");
|
||||||
|
|
|
@ -149,37 +149,17 @@ function errorResult(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function writeFile(
|
export function writeFile(
|
||||||
name: string,
|
_name: string,
|
||||||
data: Uint8Array,
|
_data: Uint8Array,
|
||||||
): Promise<FileMeta> {
|
): Promise<FileMeta> {
|
||||||
throw new Error("Writing federation file, not yet supported");
|
throw new Error("Writing federation file, not yet supported");
|
||||||
// const url = resolveFederated(name);
|
|
||||||
// console.log("Writing federation file", url);
|
|
||||||
|
|
||||||
// const r = await nativeFetch(url, {
|
|
||||||
// method: "PUT",
|
|
||||||
// body: data,
|
|
||||||
// });
|
|
||||||
// const fileMeta = await responseToFileMeta(r, name);
|
|
||||||
// if (!r.ok) {
|
|
||||||
// throw new Error("Could not write file");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return fileMeta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteFile(
|
export function deleteFile(
|
||||||
name: string,
|
_name: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
throw new Error("Writing federation file, not yet supported");
|
throw new Error("Writing federation file, not yet supported");
|
||||||
|
|
||||||
// console.log("Deleting federation file", name);
|
|
||||||
// const url = resolveFederated(name);
|
|
||||||
// const r = await nativeFetch(url, { method: "DELETE" });
|
|
||||||
// if (!r.ok) {
|
|
||||||
// throw Error("Failed to delete file");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFileMeta(name: string): Promise<FileMeta> {
|
export async function getFileMeta(name: string): Promise<FileMeta> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { editor, space, system } from "$sb/syscalls.ts";
|
import { editor, space } from "$sb/syscalls.ts";
|
||||||
import { validatePageName } from "$sb/lib/page_ref.ts";
|
import { validatePageName } from "$sb/lib/page_ref.ts";
|
||||||
import { getBackLinks, LinkObject } from "./page_links.ts";
|
import { getBackLinks, LinkObject } from "./page_links.ts";
|
||||||
import { queryObjects } from "./api.ts";
|
import { queryObjects } from "./api.ts";
|
||||||
|
|
|
@ -20,7 +20,7 @@ function htmlEscape(s: string): string {
|
||||||
let oldS = s;
|
let oldS = s;
|
||||||
do {
|
do {
|
||||||
oldS = s;
|
oldS = s;
|
||||||
s = s.replace(/ /g, " ");
|
s = s.replace(/ {2}/g, " ");
|
||||||
} while (s !== oldS);
|
} while (s !== oldS);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { System } from "../../lib/plugos/system.ts";
|
||||||
import { createSandbox } from "../../lib/plugos/sandboxes/deno_worker_sandbox.ts";
|
import { createSandbox } from "../../lib/plugos/sandboxes/deno_worker_sandbox.ts";
|
||||||
import { renderMarkdownToHtml } from "./markdown_render.ts";
|
import { renderMarkdownToHtml } from "./markdown_render.ts";
|
||||||
import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts";
|
import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts";
|
||||||
|
import { assertEquals } from "$std/testing/asserts.ts";
|
||||||
|
|
||||||
Deno.test("Markdown render", async () => {
|
Deno.test("Markdown render", async () => {
|
||||||
const system = new System<any>("server");
|
const system = new System<any>("server");
|
||||||
|
@ -38,10 +39,10 @@ Deno.test("Smart hard break test", () => {
|
||||||
failOnUnknown: true,
|
failOnUnknown: true,
|
||||||
smartHardBreak: true,
|
smartHardBreak: true,
|
||||||
});
|
});
|
||||||
// assertEquals(
|
assertEquals(
|
||||||
// html,
|
html,
|
||||||
// `<span class="p"><strong>Hello</strong><br><em>world!</em></span>`,
|
`<span class="p"><strong>Hello</strong><br><em>world!</em></span>`,
|
||||||
// );
|
);
|
||||||
|
|
||||||
const example2 = `This is going to be a text. With a new line.
|
const example2 = `This is going to be a text. With a new line.
|
||||||
|
|
||||||
|
|
|
@ -343,14 +343,14 @@ export class HttpServer {
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO: This should probably be a POST request
|
// TODO: This should probably be a POST request
|
||||||
this.app.get("/.logout", async (c) => {
|
this.app.get("/.logout", (c) => {
|
||||||
const url = new URL(c.req.url);
|
const url = new URL(c.req.url);
|
||||||
deleteCookie(c, authCookieName(url.host));
|
deleteCookie(c, authCookieName(url.host));
|
||||||
|
|
||||||
return c.redirect("/.auth");
|
return c.redirect("/.auth");
|
||||||
});
|
});
|
||||||
|
|
||||||
this.app.get("/.auth", async (c) => {
|
this.app.get("/.auth", (c) => {
|
||||||
const html = this.clientAssetBundle.readTextFileSync(".client/auth.html");
|
const html = this.clientAssetBundle.readTextFileSync(".client/auth.html");
|
||||||
|
|
||||||
return c.html(html);
|
return c.html(html);
|
||||||
|
@ -402,7 +402,7 @@ export class HttpServer {
|
||||||
return c.redirect("/.auth?error=1");
|
return c.redirect("/.auth?error=1");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
).all(async (c) => {
|
).all((c) => {
|
||||||
return c.redirect("/.auth");
|
return c.redirect("/.auth");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { safeRun } from "../lib/async.ts";
|
import { safeRun } from "../lib/async.ts";
|
||||||
import { Client } from "./client.ts";
|
import { Client } from "./client.ts";
|
||||||
|
|
||||||
const syncMode = window.silverBulletConfig.syncOnly ||
|
const syncMode = globalThis.silverBulletConfig.syncOnly ||
|
||||||
!!localStorage.getItem("syncMode");
|
!!localStorage.getItem("syncMode");
|
||||||
|
|
||||||
safeRun(async () => {
|
safeRun(async () => {
|
||||||
|
@ -19,7 +19,8 @@ safeRun(async () => {
|
||||||
syncMode,
|
syncMode,
|
||||||
window.silverBulletConfig.readOnly,
|
window.silverBulletConfig.readOnly,
|
||||||
);
|
);
|
||||||
window.client = client;
|
// @ts-ignore: on purpose
|
||||||
|
globalThis.client = client;
|
||||||
await client.init();
|
await client.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ if (navigator.serviceWorker) {
|
||||||
navigator.serviceWorker.ready.then((registration) => {
|
navigator.serviceWorker.ready.then((registration) => {
|
||||||
registration.active!.postMessage({
|
registration.active!.postMessage({
|
||||||
type: "config",
|
type: "config",
|
||||||
config: window.silverBulletConfig,
|
config: globalThis.silverBulletConfig,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,16 +70,15 @@ const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
|
||||||
const autoSaveInterval = 1000;
|
const autoSaveInterval = 1000;
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
// deno-lint-ignore no-var
|
||||||
// Injected via index.html
|
var silverBulletConfig: {
|
||||||
silverBulletConfig: {
|
|
||||||
spaceFolderPath: string;
|
spaceFolderPath: string;
|
||||||
syncOnly: boolean;
|
syncOnly: boolean;
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
enableSpaceScript: boolean;
|
enableSpaceScript: boolean;
|
||||||
};
|
};
|
||||||
client: Client;
|
// deno-lint-ignore no-var
|
||||||
}
|
var client: Client;
|
||||||
}
|
}
|
||||||
|
|
||||||
type WidgetCacheItem = {
|
type WidgetCacheItem = {
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { EditorState } from "@codemirror/state";
|
||||||
import { syntaxTree } from "@codemirror/language";
|
import { syntaxTree } from "@codemirror/language";
|
||||||
import { Decoration } from "@codemirror/view";
|
import { Decoration } from "@codemirror/view";
|
||||||
import { SyntaxNodeRef } from "@lezer/common";
|
import { SyntaxNodeRef } from "@lezer/common";
|
||||||
import { Client } from "../client.ts";
|
|
||||||
import { decoratorStateField, isCursorInRange } from "./util.ts";
|
import { decoratorStateField, isCursorInRange } from "./util.ts";
|
||||||
|
|
||||||
const ADMONITION_REGEX =
|
const ADMONITION_REGEX =
|
||||||
|
@ -57,7 +56,7 @@ function extractAdmonitionFields(rawText: string): AdmonitionFields | null {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function admonitionPlugin(editor: Client) {
|
export function admonitionPlugin() {
|
||||||
return decoratorStateField((state: EditorState) => {
|
return decoratorStateField((state: EditorState) => {
|
||||||
const widgets: any[] = [];
|
const widgets: any[] = [];
|
||||||
|
|
||||||
|
@ -77,8 +76,7 @@ export function admonitionPlugin(editor: Client) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { preSpaces, admonitionType, postSyntax, postSpaces } =
|
const { preSpaces, admonitionType, postSyntax } = extractedFields;
|
||||||
extractedFields;
|
|
||||||
|
|
||||||
// A blockquote is actually rendered as many divs, one per line.
|
// A blockquote is actually rendered as many divs, one per line.
|
||||||
// We need to keep track of the `from` offsets here, so we can attach css
|
// We need to keep track of the `from` offsets here, so we can attach css
|
||||||
|
|
|
@ -19,7 +19,7 @@ export function cleanModePlugins(client: Client) {
|
||||||
return [
|
return [
|
||||||
linkPlugin(client),
|
linkPlugin(client),
|
||||||
blockquotePlugin(),
|
blockquotePlugin(),
|
||||||
admonitionPlugin(client),
|
admonitionPlugin(),
|
||||||
hideMarksPlugin(),
|
hideMarksPlugin(),
|
||||||
hideHeaderMarkPlugin(),
|
hideHeaderMarkPlugin(),
|
||||||
cleanBlockPlugin(),
|
cleanBlockPlugin(),
|
||||||
|
|
|
@ -162,7 +162,6 @@ export function AlwaysShownModal({
|
||||||
return (
|
return (
|
||||||
<dialog
|
<dialog
|
||||||
className="sb-modal-box"
|
className="sb-modal-box"
|
||||||
// @ts-ignore
|
|
||||||
onCancel={(e: Event) => {
|
onCancel={(e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onCancel?.();
|
onCancel?.();
|
||||||
|
|
|
@ -164,7 +164,10 @@ export function FilterList({
|
||||||
// Operate on the highlighted option, ignoring prompt
|
// Operate on the highlighted option, ignoring prompt
|
||||||
const option = matchingOptions[selectedOption].name;
|
const option = matchingOptions[selectedOption].name;
|
||||||
// Get the folder it's nested in, keeping the trailing /
|
// Get the folder it's nested in, keeping the trailing /
|
||||||
const folderPath = option.slice(0, option.lastIndexOf("/") + 1);
|
const folderPath = option.slice(
|
||||||
|
0,
|
||||||
|
option.lastIndexOf("/") + 1,
|
||||||
|
);
|
||||||
// If the option wasn't in a folder, make it a folder
|
// If the option wasn't in a folder, make it a folder
|
||||||
setText(folderPath !== "" ? folderPath : option + "/");
|
setText(folderPath !== "" ? folderPath : option + "/");
|
||||||
return true;
|
return true;
|
||||||
|
@ -194,7 +197,7 @@ export function FilterList({
|
||||||
className={selectedOption === idx
|
className={selectedOption === idx
|
||||||
? "sb-selected-option"
|
? "sb-selected-option"
|
||||||
: "sb-option"}
|
: "sb-option"}
|
||||||
onMouseMove={(e) => {
|
onMouseMove={() => {
|
||||||
if (selectedOption !== idx) {
|
if (selectedOption !== idx) {
|
||||||
setSelectionOption(idx);
|
setSelectionOption(idx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ export function MiniEditor(
|
||||||
...standardKeymap,
|
...standardKeymap,
|
||||||
...historyKeymap,
|
...historyKeymap,
|
||||||
...completionKeymap,
|
...completionKeymap,
|
||||||
...createCommandKeyBindings(window.client),
|
...createCommandKeyBindings(globalThis.client),
|
||||||
]),
|
]),
|
||||||
EditorView.domEventHandlers({
|
EditorView.domEventHandlers({
|
||||||
click: (e) => {
|
click: (e) => {
|
||||||
|
@ -253,7 +253,7 @@ export function MiniEditor(
|
||||||
onBlurred = true;
|
onBlurred = true;
|
||||||
if (callbacksRef.current!.onBlur) {
|
if (callbacksRef.current!.onBlur) {
|
||||||
Promise.resolve(callbacksRef.current!.onBlur(view.state.sliceDoc()))
|
Promise.resolve(callbacksRef.current!.onBlur(view.state.sliceDoc()))
|
||||||
.catch((e) => {
|
.catch(() => {
|
||||||
// Reset the state
|
// Reset the state
|
||||||
view.setState(buildEditorState());
|
view.setState(buildEditorState());
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,6 @@ export function TopBar({
|
||||||
unsavedChanges,
|
unsavedChanges,
|
||||||
syncFailures,
|
syncFailures,
|
||||||
isLoading,
|
isLoading,
|
||||||
isMobile,
|
|
||||||
notifications,
|
notifications,
|
||||||
onRename,
|
onRename,
|
||||||
actionButtons,
|
actionButtons,
|
||||||
|
@ -36,7 +35,6 @@ export function TopBar({
|
||||||
unsavedChanges: boolean;
|
unsavedChanges: boolean;
|
||||||
syncFailures: number;
|
syncFailures: number;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isMobile: boolean;
|
|
||||||
notifications: Notification[];
|
notifications: Notification[];
|
||||||
darkMode: boolean;
|
darkMode: boolean;
|
||||||
vimMode: boolean;
|
vimMode: boolean;
|
||||||
|
|
|
@ -202,7 +202,6 @@ export class MainUI {
|
||||||
syncFailures={viewState.syncFailures}
|
syncFailures={viewState.syncFailures}
|
||||||
unsavedChanges={viewState.unsavedChanges}
|
unsavedChanges={viewState.unsavedChanges}
|
||||||
isLoading={viewState.isLoading}
|
isLoading={viewState.isLoading}
|
||||||
isMobile={viewState.isMobile}
|
|
||||||
vimMode={viewState.uiOptions.vimMode}
|
vimMode={viewState.uiOptions.vimMode}
|
||||||
darkMode={viewState.uiOptions.darkMode}
|
darkMode={viewState.uiOptions.darkMode}
|
||||||
progressPerc={viewState.progressPerc}
|
progressPerc={viewState.progressPerc}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { PageRef, parsePageRef } from "../plug-api/lib/page_ref.ts";
|
||||||
import { Client } from "./client.ts";
|
import { Client } from "./client.ts";
|
||||||
import { cleanPageRef } from "$sb/lib/resolve.ts";
|
import { cleanPageRef } from "$sb/lib/resolve.ts";
|
||||||
import { renderTheTemplate } from "$common/syscalls/template.ts";
|
import { renderTheTemplate } from "$common/syscalls/template.ts";
|
||||||
import { builtinFunctions } from "../lib/builtin_query_functions.ts";
|
|
||||||
import { safeRun } from "../lib/async.ts";
|
import { safeRun } from "../lib/async.ts";
|
||||||
|
|
||||||
export type PageState = PageRef & {
|
export type PageState = PageRef & {
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default function reducer(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
case "page-loaded": {
|
case "page-loaded": {
|
||||||
const mouseDetected = window.matchMedia("(pointer:fine)").matches;
|
const mouseDetected = globalThis.matchMedia("(pointer:fine)").matches;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
|
|
@ -71,7 +71,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
||||||
},
|
},
|
||||||
"editor.openUrl": (_ctx, url: string, existingWindow = false) => {
|
"editor.openUrl": (_ctx, url: string, existingWindow = false) => {
|
||||||
if (!existingWindow) {
|
if (!existingWindow) {
|
||||||
const win = window.open(url, "_blank");
|
const win = globalThis.open(url, "_blank");
|
||||||
if (win) {
|
if (win) {
|
||||||
win.focus();
|
win.focus();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue