Adding an "enabled" attribute to templates

This commit is contained in:
Zef Hemel
2024-01-11 14:06:24 +01:00
parent 154d9a8ce9
commit 509ece91f0
9 changed files with 43 additions and 11 deletions
+10 -3
View File
@@ -1,4 +1,5 @@
import { editor, space } from "$sb/syscalls.ts";
import { isFederationPath } from "$sb/lib/resolve.ts";
export async function deletePage() {
const pageName = await editor.getCurrentPage();
@@ -13,9 +14,15 @@ export async function deletePage() {
await space.deletePage(pageName);
}
export async function copyPage() {
export async function copyPage(_def: any, predefinedNewName: string) {
const oldName = await editor.getCurrentPage();
const newName = await editor.prompt(`New page title:`, `${oldName} (copy)`);
let suggestedName = predefinedNewName || oldName;
if (isFederationPath(oldName)) {
const pieces = oldName.split("/");
suggestedName = pieces.slice(1).join("/");
}
const newName = await editor.prompt(`Copy to new page:`, suggestedName);
if (!newName) {
return;
@@ -26,7 +33,7 @@ export async function copyPage() {
await space.getPageMeta(newName);
// So when we get to this point, we error out
throw new Error(
`Page ${newName} already exists, cannot rename to existing page.`,
`"${newName}" already exists, cannot copy to existing page.`,
);
} catch (e: any) {
if (e.message === "Not found") {
+1
View File
@@ -84,6 +84,7 @@ export const builtins: Record<string, Record<string, string>> = {
trigger: "string",
where: "string",
priority: "number",
enabled: "boolean",
},
};
+6 -1
View File
@@ -31,7 +31,12 @@ export async function renderTemplateWidgets(side: "top" | "bottom"): Promise<
const allFrontMatterTemplates = await queryObjects<TemplateObject>(
"template",
{
filter: ["=", ["attr", "type"], ["string", `widget:${side}`]],
// where type = "widget:X" and enabled != false
filter: ["and", ["=", ["attr", "type"], ["string", `widget:${side}`]], [
"!=",
["attr", "enabled"],
["boolean", false],
]],
orderBy: [{ expr: ["attr", "priority"], desc: false }],
},
);
+7 -2
View File
@@ -326,12 +326,17 @@ function render(
};
case "CommandLink": {
// Child 0 is CommandLinkMark, child 1 is CommandLinkPage
const commandText = t.children![1].children![0].text!;
const command = t.children![1].children![0].text!;
let commandText = command;
const aliasNode = findNodeOfType(t, "CommandLinkAlias");
if (aliasNode) {
commandText = aliasNode.children![0].text!;
}
return {
name: "button",
attrs: {
"data-onclick": JSON.stringify(["command", commandText]),
"data-onclick": JSON.stringify(["command", command]),
},
body: commandText,
};
+5 -2
View File
@@ -51,8 +51,11 @@ export async function templateSlashComplete(
completeEvent: CompleteEvent,
): Promise<SlashCompletion[]> {
const allTemplates = await queryObjects<TemplateObject>("template", {
// Only return templates that have a trigger
filter: ["attr", "trigger"],
// Only return templates that have a trigger and are not expliclty disabled
filter: ["and", ["attr", "trigger"], ["!=", ["attr", "enabled"], [
"boolean",
false,
]]],
});
return allTemplates.map((template) => ({
label: template.trigger!,