PlugOS refactor and other tweaks (#631)

* Prep for in-process plug loading (e.g. for CF workers, Deno Deploy)
* Prototype of fixed in-process loading plugs
* Fix: buttons not to scroll with content
* Better positioning of modal especially on mobile
* Move query caching outside query
* Fix annoying mouse behavior when filter box appears
* Page navigator search tweaks
This commit is contained in:
Zef Hemel
2024-01-15 16:43:12 +01:00
committed by GitHub
parent a9eb252658
commit a2dbf7b3db
65 changed files with 591 additions and 617 deletions
+1 -3
View File
@@ -18,9 +18,7 @@ export async function pageComplete(completeEvent: CompleteEvent) {
completeEvent.linePrefix,
);
const tagToQuery = isInTemplateContext ? "template" : "page";
let allPages: PageMeta[] = await queryObjects<PageMeta>(tagToQuery, {
cacheSecs: 5,
});
let allPages: PageMeta[] = await queryObjects<PageMeta>(tagToQuery, {}, 5);
const prefix = match[1];
if (prefix.startsWith("!")) {
// Federation prefix, let's first see if we're matching anything from federation that is locally synced
+1 -1
View File
@@ -31,6 +31,6 @@ export async function moveToPosCommand() {
await editor.moveCursor(pos);
}
export async function customFlashMessage(_ctx: any, message: string) {
export async function customFlashMessage(_def: any, message: string) {
await editor.flashNotification(message);
}
+1 -4
View File
@@ -43,10 +43,7 @@ export async function anchorComplete(completeEvent: CompleteEvent) {
// "bare" anchor, match any page for completion purposes
filter = undefined;
}
const allAnchors = await queryObjects<AnchorObject>("anchor", {
filter,
cacheSecs: 5,
});
const allAnchors = await queryObjects<AnchorObject>("anchor", { filter }, 5);
return {
from: completeEvent.pos - match[1].length,
options: allAnchors.map((a) => ({
+10 -6
View File
@@ -3,6 +3,7 @@ import { KV, KvKey, KvQuery, ObjectQuery, ObjectValue } from "$sb/types.ts";
import { QueryProviderEvent } from "$sb/app_event.ts";
import { builtins } from "./builtins.ts";
import { AttributeObject, determineType } from "./attributes.ts";
import { ttlCache } from "$sb/lib/memory_cache.ts";
const indexKey = "idx";
const pageKey = "ridx";
@@ -159,15 +160,18 @@ function cleanKey(ref: string, page: string) {
}
}
export async function queryObjects<T>(
export function queryObjects<T>(
tag: string,
query: ObjectQuery,
ttlSecs?: number,
): Promise<ObjectValue<T>[]> {
return (await datastore.query({
...query,
prefix: [indexKey, tag],
distinct: true,
})).map(({ value }) => value);
return ttlCache(query, async () => {
return (await datastore.query({
...query,
prefix: [indexKey, tag],
distinct: true,
})).map(({ value }) => value);
}, ttlSecs);
}
export async function query(
+1 -2
View File
@@ -52,8 +52,7 @@ export async function objectAttributeCompleter(
select: [{ name: "name" }, { name: "attributeType" }, { name: "tag" }, {
name: "readOnly",
}],
cacheSecs: 5,
});
}, 5);
return allAttributes.map((value) => {
return {
name: value.name,
+1 -1
View File
@@ -6,7 +6,7 @@ import { isTemplate } from "$sb/lib/cheap_yaml.ts";
export async function reindexCommand() {
await editor.flashNotification("Performing full page reindex...");
await system.invokeFunction("reindexSpace");
await system.invokeFunction("index.reindexSpace");
await editor.flashNotification("Done with page index!");
}
+7 -1
View File
@@ -1,5 +1,6 @@
import { KV, KvQuery, ObjectQuery, ObjectValue } from "$sb/types.ts";
import { invokeFunction } from "$sb/silverbullet-syscall/system.ts";
import { ttlCache } from "$sb/lib/memory_cache.ts";
export function indexObjects<T>(
page: string,
@@ -21,8 +22,13 @@ export function query(
export function queryObjects<T>(
tag: string,
query: ObjectQuery,
ttlSecs?: number,
): Promise<ObjectValue<T>[]> {
return invokeFunction("index.queryObjects", tag, query);
return ttlCache(
query,
() => invokeFunction("index.queryObjects", tag, query),
ttlSecs, // no-op when undefined
);
}
export function getObjectByRef<T>(
+1 -2
View File
@@ -73,8 +73,7 @@ export async function tagComplete(completeEvent: CompleteEvent) {
filter: ["=", ["attr", "parent"], ["string", parent]],
select: [{ name: "name" }],
distinct: true,
cacheSecs: 5,
});
}, 5);
if (parent === "page") {
// Also add template, even though that would otherwise not appear because has "builtin" as a parent
+6 -6
View File
@@ -9,16 +9,16 @@ import { renderMarkdownToHtml } from "./markdown_render.ts";
Deno.test("Markdown render", async () => {
const system = new System<any>("server");
await system.load(
new URL("../../dist_plug_bundle/_plug/editor.plug.js", import.meta.url),
"editor",
0,
createSandbox,
createSandbox(
new URL("../../dist_plug_bundle/_plug/editor.plug.js", import.meta.url),
),
);
await system.load(
new URL("../../dist_plug_bundle/_plug/tasks.plug.js", import.meta.url),
"tasks",
0,
createSandbox,
createSandbox(
new URL("../../dist_plug_bundle/_plug/tasks.plug.js", import.meta.url),
),
);
const lang = buildMarkdown(loadMarkdownExtensions(system));
const testFile = Deno.readTextFileSync(
+2 -2
View File
@@ -11,8 +11,8 @@ export async function updateMarkdownPreview() {
const text = await editor.getText();
const mdTree = await markdown.parseMarkdown(text);
// const cleanMd = await cleanMarkdown(text);
const css = await asset.readAsset("assets/preview.css");
const js = await asset.readAsset("assets/preview.js");
const css = await asset.readAsset("markdown", "assets/preview.css");
const js = await asset.readAsset("markdown", "assets/preview.js");
await expandCodeWidgets(mdTree, currentPage);
const html = renderMarkdownToHtml(mdTree, {
+1 -3
View File
@@ -9,9 +9,7 @@ export async function completeTaskState(completeEvent: CompleteEvent) {
if (!taskMatch) {
return null;
}
const allStates = await queryObjects<TaskStateObject>("taskstate", {
cacheSecs: 5,
});
const allStates = await queryObjects<TaskStateObject>("taskstate", {}, 5);
const states = [...new Set(allStates.map((s) => s.state))];
return {
+1 -2
View File
@@ -56,8 +56,7 @@ export async function templateSlashComplete(
"boolean",
false,
]]],
cacheSecs: 5,
});
}, 5);
return allTemplates.map((template) => ({
label: template.trigger!,
detail: "template",