Action button prototype
This commit is contained in:
@@ -42,14 +42,14 @@ functions:
|
||||
path: ./page.ts:linkQueryProvider
|
||||
events:
|
||||
- query:link
|
||||
indexItems:
|
||||
path: "./item.ts:indexItems"
|
||||
events:
|
||||
- page:index
|
||||
itemQueryProvider:
|
||||
path: ./item.ts:queryProvider
|
||||
events:
|
||||
- query:item
|
||||
# indexItems:
|
||||
# path: "./item.ts:indexItems"
|
||||
# events:
|
||||
# - page:index
|
||||
# itemQueryProvider:
|
||||
# path: ./item.ts:queryProvider
|
||||
# events:
|
||||
# - query:item
|
||||
deletePage:
|
||||
path: "./page.ts:deletePage"
|
||||
command:
|
||||
@@ -67,6 +67,9 @@ functions:
|
||||
name: "Page: Rename"
|
||||
mac: Cmd-Alt-r
|
||||
key: Ctrl-Alt-r
|
||||
button:
|
||||
label: "📝"
|
||||
tooltip: "Rename page"
|
||||
pageComplete:
|
||||
path: "./page.ts:pageComplete"
|
||||
events:
|
||||
@@ -99,7 +102,20 @@ functions:
|
||||
path: ./page.ts:parsePageCommand
|
||||
command:
|
||||
name: "Debug: Parse Document"
|
||||
|
||||
insertPageMeta:
|
||||
path: "./page.ts:insertPageMeta"
|
||||
slashCommand:
|
||||
name: meta
|
||||
quickNoteCommand:
|
||||
path: ./template.ts:quickNoteCommand
|
||||
command:
|
||||
name: "Template: Quick Note"
|
||||
key: "Alt-Shift-n"
|
||||
quickTaskCommand:
|
||||
path: ./template.ts:quickTaskCommand
|
||||
command:
|
||||
name: "Template: Quick Task"
|
||||
key: "Alt-Shift-t"
|
||||
instantiateTemplateCommand:
|
||||
path: ./template.ts:instantiateTemplateCommand
|
||||
command:
|
||||
|
||||
@@ -9,8 +9,11 @@ import {
|
||||
import {
|
||||
flashNotification,
|
||||
getCurrentPage,
|
||||
getCursor,
|
||||
getText,
|
||||
insertAtCursor,
|
||||
matchBefore,
|
||||
moveCursor,
|
||||
navigate,
|
||||
prompt,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||
@@ -247,3 +250,9 @@ export async function parsePageCommand() {
|
||||
export async function parsePage(text: string) {
|
||||
console.log("AST", JSON.stringify(await parseMarkdown(text), null, 2));
|
||||
}
|
||||
|
||||
export async function insertPageMeta() {
|
||||
let cursorPos = await getCursor();
|
||||
await insertAtCursor("```meta\n\n```");
|
||||
await moveCursor(cursorPos + 8);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/space";
|
||||
import {
|
||||
filterBox,
|
||||
moveCursor,
|
||||
navigate,
|
||||
prompt,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||
@@ -35,7 +36,7 @@ export async function instantiateTemplateCommand() {
|
||||
let { text } = await readPage(selectedTemplate.name);
|
||||
|
||||
let parseTree = await parseMarkdown(text);
|
||||
let additionalPageMeta = extractMeta(parseTree, true);
|
||||
let additionalPageMeta = extractMeta(parseTree, ["name"]);
|
||||
console.log("Page meta", additionalPageMeta);
|
||||
|
||||
let pageName = await prompt("Name of new page", additionalPageMeta.name);
|
||||
@@ -47,6 +48,7 @@ export async function instantiateTemplateCommand() {
|
||||
await navigate(pageName);
|
||||
}
|
||||
|
||||
// TODO: This should probably be replaced with handlebards somehow?
|
||||
export function replaceTemplateVars(s: string, pageName: string): string {
|
||||
return s.replaceAll(/\{\{([^\}]+)\}\}/g, (match, v) => {
|
||||
switch (v) {
|
||||
@@ -64,3 +66,22 @@ export function replaceTemplateVars(s: string, pageName: string): string {
|
||||
return match;
|
||||
});
|
||||
}
|
||||
|
||||
export async function quickNoteCommand() {
|
||||
let isoDate = new Date().toISOString();
|
||||
let [date, time] = isoDate.split("T");
|
||||
time = time.split(".")[0];
|
||||
let pageName = `📥 ${date} ${time}`;
|
||||
await writePage(pageName, "");
|
||||
await navigate(pageName);
|
||||
}
|
||||
|
||||
export async function quickTaskCommand() {
|
||||
let isoDate = new Date().toISOString();
|
||||
let [date, time] = isoDate.split("T");
|
||||
time = time.split(".")[0];
|
||||
let pageName = `✅ ${date} ${time}`;
|
||||
await writePage(pageName, "* [ ] ");
|
||||
await navigate(pageName);
|
||||
await moveCursor(6);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ functions:
|
||||
events:
|
||||
- query:gh-events
|
||||
queryIssues:
|
||||
path: ./github.ts:queryIssues
|
||||
path: ./github.ts:queryPulls
|
||||
events:
|
||||
- query:gh-issues
|
||||
- query:gh-pulls
|
||||
|
||||
@@ -61,9 +61,13 @@ class GithubApi {
|
||||
);
|
||||
}
|
||||
|
||||
async listIssues(filter: string): Promise<any[]> {
|
||||
async listPulls(
|
||||
repo: string,
|
||||
state: string = "all",
|
||||
sort: string = "updated"
|
||||
): Promise<any[]> {
|
||||
return this.apiCall(
|
||||
`https://api.github.com/issues?q=${encodeURIComponent(filter)}`
|
||||
`https://api.github.com/repos/${repo}/pulls?state=${state}&sort=${sort}&direction=desc&per_page=100`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,27 +130,40 @@ export async function queryEvents({
|
||||
return applyQuery(query, allEvents.map(mapEvent));
|
||||
}
|
||||
|
||||
export async function queryIssues({
|
||||
function mapPull(pull: any): any {
|
||||
// console.log("Pull", Object.keys(pull));
|
||||
return {
|
||||
...pull,
|
||||
username: pull.user.login,
|
||||
// repo: pull.repo.name,
|
||||
createdAt: pull.created_at.split("T")[0],
|
||||
updatedAt: pull.updated_at.split("T")[0],
|
||||
};
|
||||
}
|
||||
|
||||
export async function queryPulls({
|
||||
query,
|
||||
}: QueryProviderEvent): Promise<any[]> {
|
||||
let api = await GithubApi.fromConfig();
|
||||
let filter = query.filter.find((f) => f.prop === "filter");
|
||||
if (!filter) {
|
||||
throw Error("No 'filter' specified, this is mandatory");
|
||||
let repo = query.filter.find((f) => f.prop === "repo");
|
||||
if (!repo) {
|
||||
throw Error("No 'repo' specified, this is mandatory");
|
||||
}
|
||||
let queries: string[] = [];
|
||||
if (filter.op === "=") {
|
||||
queries = [filter.value];
|
||||
} else if (filter.op === "in") {
|
||||
queries = filter.value;
|
||||
query.filter.splice(query.filter.indexOf(repo), 1);
|
||||
let repos: string[] = [];
|
||||
if (repo.op === "=") {
|
||||
repos = [repo.value];
|
||||
} else if (repo.op === "in") {
|
||||
repos = repo.value;
|
||||
} else {
|
||||
throw new Error(`Unsupported operator ${filter.op}`);
|
||||
throw new Error(`Unsupported operator ${repo.op}`);
|
||||
}
|
||||
let allIssues: any[] = [];
|
||||
for (let issuesList of await Promise.all(
|
||||
queries.map((query) => api.listIssues(query))
|
||||
let allPulls: any[] = [];
|
||||
for (let pullList of await Promise.all(
|
||||
repos.map((repo) => api.listPulls(repo, "all", "updated"))
|
||||
)) {
|
||||
allIssues.push(...issuesList);
|
||||
allPulls.push(...pullList);
|
||||
}
|
||||
return allIssues;
|
||||
allPulls = applyQuery(query, allPulls.map(mapPull));
|
||||
return allPulls;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,14 @@ import {
|
||||
ParseTree,
|
||||
replaceNodesMatching,
|
||||
} from "@silverbulletmd/common/tree";
|
||||
import { parse as parseYaml, parseAllDocuments } from "yaml";
|
||||
import {
|
||||
parse as parseYaml,
|
||||
stringify as stringifyYaml,
|
||||
parseAllDocuments,
|
||||
} from "yaml";
|
||||
import type { QueryProviderEvent } from "./engine";
|
||||
import { applyQuery } from "./engine";
|
||||
import { jsonToMDTable, removeQueries } from "./util";
|
||||
import { removeQueries } from "./util";
|
||||
|
||||
export async function indexData({ name, tree }: IndexTreeEvent) {
|
||||
let dataObjects: { key: string; value: Object }[] = [];
|
||||
@@ -58,8 +62,11 @@ export async function indexData({ name, tree }: IndexTreeEvent) {
|
||||
await batchSet(name, dataObjects);
|
||||
}
|
||||
|
||||
export function extractMeta(parseTree: ParseTree, remove = false): any {
|
||||
let data = {};
|
||||
export function extractMeta(
|
||||
parseTree: ParseTree,
|
||||
removeKeys: string[] = []
|
||||
): any {
|
||||
let data: any = {};
|
||||
replaceNodesMatching(parseTree, (t) => {
|
||||
if (t.type !== "FencedCode") {
|
||||
return;
|
||||
@@ -78,7 +85,14 @@ export function extractMeta(parseTree: ParseTree, remove = false): any {
|
||||
}
|
||||
let codeText = codeTextNode.children![0].text!;
|
||||
data = parseYaml(codeText);
|
||||
return remove ? null : undefined;
|
||||
if (removeKeys.length > 0) {
|
||||
let newData = { ...data };
|
||||
for (let key of removeKeys) {
|
||||
delete newData[key];
|
||||
}
|
||||
codeTextNode.children![0].text = stringifyYaml(newData).trim();
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user