@firetail/finchly-ux 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -2
- package/dist/components/action-button.d.ts +12 -0
- package/dist/components/action-button.js +34 -0
- package/dist/components/action-button.js.map +1 -0
- package/dist/components/app-shell.d.ts +18 -0
- package/dist/components/app-shell.js +56 -0
- package/dist/components/app-shell.js.map +1 -0
- package/dist/components/ask.d.ts +37 -0
- package/dist/components/ask.js +73 -0
- package/dist/components/ask.js.map +1 -0
- package/dist/components/bar.d.ts +11 -0
- package/dist/components/bar.js +187 -0
- package/dist/components/bar.js.map +1 -0
- package/dist/components/choosing.d.ts +18 -0
- package/dist/components/choosing.js +68 -0
- package/dist/components/choosing.js.map +1 -0
- package/dist/components/column-chart.d.ts +50 -0
- package/dist/components/column-chart.js +181 -0
- package/dist/components/column-chart.js.map +1 -0
- package/dist/components/composing.d.ts +40 -0
- package/dist/components/composing.js +101 -0
- package/dist/components/composing.js.map +1 -0
- package/dist/components/conversation.d.ts +50 -0
- package/dist/components/conversation.js +116 -0
- package/dist/components/conversation.js.map +1 -0
- package/dist/components/data-table.d.ts +43 -0
- package/dist/components/data-table.js +212 -0
- package/dist/components/data-table.js.map +1 -0
- package/dist/components/fields.d.ts +61 -0
- package/dist/components/fields.js +144 -0
- package/dist/components/fields.js.map +1 -0
- package/dist/components/file-button.d.ts +16 -0
- package/dist/components/file-button.js +39 -0
- package/dist/components/file-button.js.map +1 -0
- package/dist/components/form-dialog.d.ts +51 -0
- package/dist/components/form-dialog.js +113 -0
- package/dist/components/form-dialog.js.map +1 -0
- package/dist/components/link-button.d.ts +5 -0
- package/dist/components/link-button.js +24 -0
- package/dist/components/link-button.js.map +1 -0
- package/dist/components/link-tabs.d.ts +13 -0
- package/dist/components/link-tabs.js +26 -0
- package/dist/components/link-tabs.js.map +1 -0
- package/dist/components/markdown.d.ts +13 -0
- package/dist/components/markdown.js +132 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/page.d.ts +18 -0
- package/dist/components/page.js +45 -0
- package/dist/components/page.js.map +1 -0
- package/dist/components/palette.d.ts +16 -0
- package/dist/components/palette.js +27 -0
- package/dist/components/palette.js.map +1 -0
- package/dist/components/panel.d.ts +12 -0
- package/dist/components/panel.js +30 -0
- package/dist/components/panel.js.map +1 -0
- package/dist/components/pick-tile.d.ts +21 -0
- package/dist/components/pick-tile.js +40 -0
- package/dist/components/pick-tile.js.map +1 -0
- package/dist/components/provider-mark.d.ts +33 -0
- package/dist/components/provider-mark.js +58 -0
- package/dist/components/provider-mark.js.map +1 -0
- package/dist/components/provider.d.ts +17 -0
- package/dist/components/provider.js +39 -0
- package/dist/components/provider.js.map +1 -0
- package/dist/components/rows.d.ts +48 -0
- package/dist/components/rows.js +112 -0
- package/dist/components/rows.js.map +1 -0
- package/dist/components/side-nav.d.ts +23 -0
- package/dist/components/side-nav.js +41 -0
- package/dist/components/side-nav.js.map +1 -0
- package/dist/components/states.d.ts +19 -0
- package/dist/components/states.js +45 -0
- package/dist/components/states.js.map +1 -0
- package/dist/components/suggest-field.d.ts +19 -0
- package/dist/components/suggest-field.js +124 -0
- package/dist/components/suggest-field.js.map +1 -0
- package/dist/components/tag.d.ts +27 -0
- package/dist/components/tag.js +38 -0
- package/dist/components/tag.js.map +1 -0
- package/dist/components/text.d.ts +41 -0
- package/dist/components/text.js +97 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/tile.d.ts +30 -0
- package/dist/components/tile.js +68 -0
- package/dist/components/tile.js.map +1 -0
- package/dist/components/toast.d.ts +10 -0
- package/dist/components/toast.js +38 -0
- package/dist/components/toast.js.map +1 -0
- package/dist/components/ui/alert-dialog.d.ts +18 -0
- package/dist/components/ui/alert.d.ts +10 -0
- package/dist/components/ui/badge.d.ts +7 -0
- package/dist/components/ui/button.d.ts +8 -0
- package/dist/components/ui/button.js +45 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/card.d.ts +11 -0
- package/dist/components/ui/card.js +57 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +3 -0
- package/dist/components/ui/checkbox.js +20 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/collapsible.d.ts +5 -0
- package/dist/components/ui/collapsible.js +24 -0
- package/dist/components/ui/collapsible.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/dialog.js +92 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +29 -0
- package/dist/components/ui/dropdown-menu.js +65 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/empty.d.ts +11 -0
- package/dist/components/ui/field.d.ts +24 -0
- package/dist/components/ui/field.js +89 -0
- package/dist/components/ui/field.js.map +1 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.js +16 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/label.d.ts +3 -0
- package/dist/components/ui/label.js +14 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/native-select.d.ts +8 -0
- package/dist/components/ui/native-select.js +39 -0
- package/dist/components/ui/native-select.js.map +1 -0
- package/dist/components/ui/radio-group.d.ts +5 -0
- package/dist/components/ui/radio-group.js +27 -0
- package/dist/components/ui/radio-group.js.map +1 -0
- package/dist/components/ui/separator.d.ts +3 -0
- package/dist/components/ui/separator.js +15 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/skeleton.js +13 -0
- package/dist/components/ui/skeleton.js.map +1 -0
- package/dist/components/ui/spinner.d.ts +2 -0
- package/dist/components/ui/spinner.js +16 -0
- package/dist/components/ui/spinner.js.map +1 -0
- package/dist/components/ui/table.d.ts +10 -0
- package/dist/components/ui/table.js +53 -0
- package/dist/components/ui/table.js.map +1 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/components/ui/textarea.js +14 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +6 -0
- package/dist/components/ui/tooltip.js +41 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/icons.d.ts +1 -0
- package/dist/icons.js +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +56 -0
- package/dist/lib/api.d.ts +49 -0
- package/dist/lib/api.js +80 -0
- package/dist/lib/api.js.map +1 -0
- package/dist/lib/chart.d.ts +35 -0
- package/dist/lib/chart.js +86 -0
- package/dist/lib/chart.js.map +1 -0
- package/dist/lib/cn.d.ts +3 -0
- package/dist/lib/cn.js +10 -0
- package/dist/lib/cn.js.map +1 -0
- package/dist/lib/events.d.ts +34 -0
- package/dist/lib/events.js +72 -0
- package/dist/lib/events.js.map +1 -0
- package/dist/lib/format.d.ts +16 -0
- package/dist/lib/format.js +71 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/hash.d.ts +2 -0
- package/dist/lib/hash.js +13 -0
- package/dist/lib/hash.js.map +1 -0
- package/dist/lib/launcher.d.ts +54 -0
- package/dist/lib/launcher.js +46 -0
- package/dist/lib/launcher.js.map +1 -0
- package/dist/lib/markdown-inline.d.ts +18 -0
- package/dist/lib/markdown-inline.js +155 -0
- package/dist/lib/markdown-inline.js.map +1 -0
- package/dist/lib/markdown.d.ts +40 -0
- package/dist/lib/markdown.js +198 -0
- package/dist/lib/markdown.js.map +1 -0
- package/dist/lib/marks.d.ts +17 -0
- package/dist/lib/marks.js +54 -0
- package/dist/lib/marks.js.map +1 -0
- package/dist/lib/over.d.ts +26 -0
- package/dist/lib/over.js +38 -0
- package/dist/lib/over.js.map +1 -0
- package/dist/lib/route.d.ts +15 -0
- package/dist/lib/route.js +29 -0
- package/dist/lib/route.js.map +1 -0
- package/dist/lib/table.d.ts +43 -0
- package/dist/lib/table.js +86 -0
- package/dist/lib/table.js.map +1 -0
- package/dist/lib/theme.d.ts +12 -0
- package/dist/lib/theme.js +42 -0
- package/dist/lib/theme.js.map +1 -0
- package/eslint/index.d.ts +8 -0
- package/eslint/index.js +135 -0
- package/eslint/page-imports.js +46 -0
- package/package.json +91 -4
- package/styles/styles.css +221 -0
- package/styles/tokens.css +99 -0
- package/tsconfig.app.json +21 -0
- package/vite/index.d.ts +16 -0
- package/vite/index.js +84 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** An app a person can open. */
|
|
2
|
+
export interface LauncherApp {
|
|
3
|
+
slug: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string | null;
|
|
6
|
+
icon: string | null;
|
|
7
|
+
tags: string[];
|
|
8
|
+
/** Where it is opened, at the address the person is on. */
|
|
9
|
+
path: string;
|
|
10
|
+
}
|
|
11
|
+
/** An agent a person can talk to or set to work. */
|
|
12
|
+
export interface LauncherAgent {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string | null;
|
|
16
|
+
icon: string | null;
|
|
17
|
+
path: string;
|
|
18
|
+
/** The service that hosts the agent, where it is not a service of its own. */
|
|
19
|
+
hostedBy: {
|
|
20
|
+
slug: string;
|
|
21
|
+
name: string;
|
|
22
|
+
} | null;
|
|
23
|
+
}
|
|
24
|
+
/** What platform-core says of the person and what they can open. */
|
|
25
|
+
export interface Launcher {
|
|
26
|
+
user: {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string | null;
|
|
29
|
+
email: string;
|
|
30
|
+
};
|
|
31
|
+
apps: LauncherApp[];
|
|
32
|
+
agents: LauncherAgent[];
|
|
33
|
+
/** Where the admin UI is, for someone who may open it. */
|
|
34
|
+
admin: {
|
|
35
|
+
path: string;
|
|
36
|
+
} | null;
|
|
37
|
+
/** What the platform is called for this tenant, and its logo. */
|
|
38
|
+
brand?: {
|
|
39
|
+
name?: string | null;
|
|
40
|
+
logo?: string | null;
|
|
41
|
+
logoDark?: string | null;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
export declare function useLauncher(): import("@tanstack/react-query").UseQueryResult<Launcher, Error>;
|
|
45
|
+
/**
|
|
46
|
+
* Whether a built-in service with a page of its own can be reached by
|
|
47
|
+
* this person. Each is optional in a deployment, and in a tenant.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useReachable(slug: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Sign out. The gateway answers with where to go next, which is the
|
|
52
|
+
* identity provider's own page. Rejects where it could not.
|
|
53
|
+
*/
|
|
54
|
+
export declare function signOut(): Promise<void>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { core } from "./api.js";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
// src/lib/launcher.ts
|
|
4
|
+
function useLauncher() {
|
|
5
|
+
return useQuery({
|
|
6
|
+
queryKey: ["finchly", "launcher"],
|
|
7
|
+
queryFn: () => core("/me/launcher"),
|
|
8
|
+
staleTime: Infinity
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether a built-in service with a page of its own can be reached by
|
|
13
|
+
* this person. Each is optional in a deployment, and in a tenant.
|
|
14
|
+
*/
|
|
15
|
+
function useReachable(slug) {
|
|
16
|
+
const { data } = useQuery({
|
|
17
|
+
queryKey: [
|
|
18
|
+
"finchly",
|
|
19
|
+
"reachable",
|
|
20
|
+
slug
|
|
21
|
+
],
|
|
22
|
+
queryFn: async () => (await fetch(`/${slug}/api/me/session`, {
|
|
23
|
+
credentials: "same-origin",
|
|
24
|
+
headers: { accept: "application/json" }
|
|
25
|
+
})).ok,
|
|
26
|
+
staleTime: Infinity
|
|
27
|
+
});
|
|
28
|
+
return data === true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sign out. The gateway answers with where to go next, which is the
|
|
32
|
+
* identity provider's own page. Rejects where it could not.
|
|
33
|
+
*/
|
|
34
|
+
async function signOut() {
|
|
35
|
+
const response = await fetch("/_gateway/logout", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
credentials: "same-origin",
|
|
38
|
+
headers: { accept: "application/json" }
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) throw new Error("Sign out failed");
|
|
41
|
+
const result = await response.json();
|
|
42
|
+
location.assign(result.redirect);
|
|
43
|
+
}
|
|
44
|
+
export { signOut, useLauncher, useReachable };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=launcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher.js","names":[],"sources":["../../src/lib/launcher.ts"],"sourcesContent":["// What the person looking can open, and who they are: what the bar across\n// the top is drawn from.\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { core } from \"./api\";\n\n/** An app a person can open. */\nexport interface LauncherApp {\n slug: string;\n name: string;\n description: string | null;\n icon: string | null;\n tags: string[];\n /** Where it is opened, at the address the person is on. */\n path: string;\n}\n\n/** An agent a person can talk to or set to work. */\nexport interface LauncherAgent {\n id: string;\n name: string;\n description: string | null;\n icon: string | null;\n path: string;\n /** The service that hosts the agent, where it is not a service of its own. */\n hostedBy: { slug: string; name: string } | null;\n}\n\n/** What platform-core says of the person and what they can open. */\nexport interface Launcher {\n user: { id: string; name: string | null; email: string };\n apps: LauncherApp[];\n agents: LauncherAgent[];\n /** Where the admin UI is, for someone who may open it. */\n admin: { path: string } | null;\n /** What the platform is called for this tenant, and its logo. */\n brand?: { name?: string | null; logo?: string | null; logoDark?: string | null } | null;\n}\n\nexport function useLauncher() {\n // Asked once for a page, however many of its parts read it: who is looking does not change while they look.\n return useQuery({ queryKey: [\"finchly\", \"launcher\"], queryFn: () => core<Launcher>(\"/me/launcher\"), staleTime: Infinity });\n}\n\n/**\n * Whether a built-in service with a page of its own can be reached by\n * this person. Each is optional in a deployment, and in a tenant.\n */\nexport function useReachable(slug: string): boolean {\n const { data } = useQuery({\n queryKey: [\"finchly\", \"reachable\", slug],\n queryFn: async () => (await fetch(`/${slug}/api/me/session`, { credentials: \"same-origin\", headers: { accept: \"application/json\" } })).ok,\n staleTime: Infinity,\n });\n return data === true;\n}\n\n/**\n * Sign out. The gateway answers with where to go next, which is the\n * identity provider's own page. Rejects where it could not.\n */\nexport async function signOut(): Promise<void> {\n const response = await fetch(\"/_gateway/logout\", { method: \"POST\", credentials: \"same-origin\", headers: { accept: \"application/json\" } });\n if (!response.ok) throw new Error(\"Sign out failed\");\n const result = (await response.json()) as { redirect: string };\n location.assign(result.redirect);\n}\n"],"mappings":";;;AAuCA,SAAgB,cAAc;CAE5B,OAAO,SAAS;EAAE,UAAU,CAAC,WAAW,UAAU;EAAG,eAAe,KAAe,cAAc;EAAG,WAAW;CAAS,CAAC;AAC3H;;;;;AAMA,SAAgB,aAAa,MAAuB;CAClD,MAAM,EAAE,SAAS,SAAS;EACxB,UAAU;GAAC;GAAW;GAAa;EAAI;EACvC,SAAS,aAAa,MAAM,MAAM,IAAI,KAAK,kBAAkB;GAAE,aAAa;GAAe,SAAS,EAAE,QAAQ,mBAAmB;EAAE,CAAC,EAAA,CAAG;EACvI,WAAW;CACb,CAAC;CACD,OAAO,SAAS;AAClB;;;;;AAMA,eAAsB,UAAyB;CAC7C,MAAM,WAAW,MAAM,MAAM,oBAAoB;EAAE,QAAQ;EAAQ,aAAa;EAAe,SAAS,EAAE,QAAQ,mBAAmB;CAAE,CAAC;CACxI,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,iBAAiB;CACnD,MAAM,SAAU,MAAM,SAAS,KAAK;CACpC,SAAS,OAAO,OAAO,QAAQ;AACjC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Words, or something that marks them: emphasis, code, a link, a line break. */
|
|
2
|
+
export type Inline = string | {
|
|
3
|
+
type: "break";
|
|
4
|
+
} | {
|
|
5
|
+
type: "code";
|
|
6
|
+
text: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: "link";
|
|
9
|
+
href: string;
|
|
10
|
+
children: Inline[];
|
|
11
|
+
} | {
|
|
12
|
+
type: "strong" | "em" | "del";
|
|
13
|
+
children: Inline[];
|
|
14
|
+
};
|
|
15
|
+
/** Where a link may lead: the web, or a letter. Anything else is not a link. */
|
|
16
|
+
export declare function safeAddress(value: unknown): string | null;
|
|
17
|
+
/** What a line of text holds: words, and what marks them. */
|
|
18
|
+
export declare function inline(text: string): Inline[];
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// src/lib/markdown-inline.ts
|
|
2
|
+
var ESCAPABLE = /[\\`*_{}[\]()#+\-.!|~<>]/;
|
|
3
|
+
/** Where a link may lead: the web, or a letter. Anything else is not a link. */
|
|
4
|
+
function safeAddress(value) {
|
|
5
|
+
const address = String(value ?? "").trim();
|
|
6
|
+
return /^https?:\/\/[^\s<>"]+$/i.test(address) || /^mailto:[^\s<>"]+$/i.test(address) ? address : null;
|
|
7
|
+
}
|
|
8
|
+
/** A run of backticks, where one begins. */
|
|
9
|
+
var ticks = (text, from) => /^`+/.exec(text.slice(from))?.[0] ?? "`";
|
|
10
|
+
/** Where an emphasis that opened ends: its closing mark, which follows something said. -1 where it never closes. */
|
|
11
|
+
function closes(text, from, mark) {
|
|
12
|
+
for (let j = from; j < text.length; j += 1) {
|
|
13
|
+
if (text[j] === "\\") {
|
|
14
|
+
j += 1;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (text[j] === "`") {
|
|
18
|
+
const run = ticks(text, j);
|
|
19
|
+
const end = text.indexOf(run, j + run.length);
|
|
20
|
+
if (end !== -1) j = end + run.length - 1;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!text.startsWith(mark, j) || j === from || /\s/.test(text[j - 1] ?? "")) continue;
|
|
24
|
+
if (mark.length === 1 && (text[j + 1] === mark || text[j - 1] === mark)) continue;
|
|
25
|
+
if (mark.startsWith("_") && /\w/.test(text[j + mark.length] ?? "")) continue;
|
|
26
|
+
return j;
|
|
27
|
+
}
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
var MARKS = [
|
|
31
|
+
["***", ["strong", "em"]],
|
|
32
|
+
["___", ["strong", "em"]],
|
|
33
|
+
["**", ["strong"]],
|
|
34
|
+
["__", ["strong"]],
|
|
35
|
+
["~~", ["del"]],
|
|
36
|
+
["*", ["em"]],
|
|
37
|
+
["_", ["em"]]
|
|
38
|
+
];
|
|
39
|
+
/** Where the `]` that closes a `[` is, with brackets within it counted. -1 where it is never closed. */
|
|
40
|
+
function closingBracket(text, open) {
|
|
41
|
+
let depth = 0;
|
|
42
|
+
for (let j = open; j < text.length; j += 1) if (text[j] === "\\") j += 1;
|
|
43
|
+
else if (text[j] === "[") depth += 1;
|
|
44
|
+
else if (text[j] === "]" && (depth -= 1) === 0) return j;
|
|
45
|
+
return -1;
|
|
46
|
+
}
|
|
47
|
+
/** An address written out, without what ends the sentence around it, or closes a bracket it did not open. Null where there is none. */
|
|
48
|
+
function writtenOut(text, from) {
|
|
49
|
+
const address = /^https?:\/\/[^\s<>]+/i.exec(text.slice(from));
|
|
50
|
+
if (!address) return null;
|
|
51
|
+
let href = address[0].replace(/[.,;:!?'"*_~]+$/, "");
|
|
52
|
+
while (href.endsWith(")") && href.split("(").length <= href.split(")").length - 1) href = href.slice(0, -1).replace(/[.,;:!?'"*_~]+$/, "");
|
|
53
|
+
return safeAddress(href) && href.length > 8 ? href : null;
|
|
54
|
+
}
|
|
55
|
+
/** What a line of text holds: words, and what marks them. */
|
|
56
|
+
function inline(text) {
|
|
57
|
+
const found = [];
|
|
58
|
+
let words = "";
|
|
59
|
+
const say = (node) => {
|
|
60
|
+
if (words !== "") found.push(words);
|
|
61
|
+
words = "";
|
|
62
|
+
if (node) found.push(node);
|
|
63
|
+
};
|
|
64
|
+
let i = 0;
|
|
65
|
+
scan: while (i < text.length) {
|
|
66
|
+
const ch = text[i] ?? "";
|
|
67
|
+
if (ch === "\\" && i + 1 < text.length && ESCAPABLE.test(text[i + 1] ?? "")) {
|
|
68
|
+
words += text[i + 1];
|
|
69
|
+
i += 2;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (ch === "\n") {
|
|
73
|
+
say({ type: "break" });
|
|
74
|
+
i += 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch === "`") {
|
|
78
|
+
const run = ticks(text, i);
|
|
79
|
+
const end = text.indexOf(run, i + run.length);
|
|
80
|
+
if (end !== -1) {
|
|
81
|
+
const code = text.slice(i + run.length, end).replace(/\n/g, " ");
|
|
82
|
+
say({
|
|
83
|
+
type: "code",
|
|
84
|
+
text: /^ .*[^ ].* $|^ [^ ] $/.test(code) ? code.slice(1, -1) : code
|
|
85
|
+
});
|
|
86
|
+
i = end + run.length;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (ch === "[" || ch === "!" && text[i + 1] === "[") {
|
|
91
|
+
const open = ch === "!" ? i + 1 : i;
|
|
92
|
+
const close = closingBracket(text, open);
|
|
93
|
+
const target = close === -1 ? null : /^\(\s*<?([^\s<>()]*(?:\([^\s<>()]*\)[^\s<>()]*)*)>?(?:\s+(?:"[^"]*"|'[^']*'))?\s*\)/.exec(text.slice(close + 1));
|
|
94
|
+
if (target) {
|
|
95
|
+
const label = text.slice(open + 1, close);
|
|
96
|
+
const href = safeAddress(target[1]);
|
|
97
|
+
const children = inline(label === "" ? target[1] ?? "" : label);
|
|
98
|
+
if (href) say({
|
|
99
|
+
type: "link",
|
|
100
|
+
href,
|
|
101
|
+
children
|
|
102
|
+
});
|
|
103
|
+
else for (const child of children) if (typeof child === "string") words += child;
|
|
104
|
+
else say(child);
|
|
105
|
+
i = close + 1 + target[0].length;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (ch === "<") {
|
|
110
|
+
const address = /^<((?:https?:\/\/|mailto:)[^\s<>]+)>/i.exec(text.slice(i));
|
|
111
|
+
if (address?.[1] && safeAddress(address[1])) {
|
|
112
|
+
say({
|
|
113
|
+
type: "link",
|
|
114
|
+
href: address[1],
|
|
115
|
+
children: [address[1].replace(/^mailto:/i, "")]
|
|
116
|
+
});
|
|
117
|
+
i += address[0].length;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if ((ch === "h" || ch === "H") && !/\w/.test(text[i - 1] ?? "")) {
|
|
122
|
+
const href = writtenOut(text, i);
|
|
123
|
+
if (href) {
|
|
124
|
+
say({
|
|
125
|
+
type: "link",
|
|
126
|
+
href,
|
|
127
|
+
children: [href]
|
|
128
|
+
});
|
|
129
|
+
i += href.length;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (ch === "*" || ch === "_" || ch === "~") for (const [mark, kinds] of MARKS) {
|
|
134
|
+
if (!text.startsWith(mark, i)) continue;
|
|
135
|
+
const after = text[i + mark.length];
|
|
136
|
+
if (after === void 0 || /\s/.test(after)) continue;
|
|
137
|
+
if (mark.startsWith("_") && /\w/.test(text[i - 1] ?? "")) continue;
|
|
138
|
+
const end = closes(text, i + mark.length, mark);
|
|
139
|
+
if (end === -1) continue;
|
|
140
|
+
say(kinds.reduceRight((children, type) => [{
|
|
141
|
+
type,
|
|
142
|
+
children
|
|
143
|
+
}], inline(text.slice(i + mark.length, end)))[0] ?? null);
|
|
144
|
+
i = end + mark.length;
|
|
145
|
+
continue scan;
|
|
146
|
+
}
|
|
147
|
+
words += ch;
|
|
148
|
+
i += 1;
|
|
149
|
+
}
|
|
150
|
+
say(null);
|
|
151
|
+
return found;
|
|
152
|
+
}
|
|
153
|
+
export { inline, safeAddress };
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=markdown-inline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-inline.js","names":[],"sources":["../../src/lib/markdown-inline.ts"],"sourcesContent":["// What a line of Markdown holds: words, and what marks them. A part of\n// reading Markdown into a tree (markdown.ts), which needs no page.\n\n/** Words, or something that marks them: emphasis, code, a link, a line break. */\nexport type Inline = string | { type: \"break\" } | { type: \"code\"; text: string } | { type: \"link\"; href: string; children: Inline[] } | { type: \"strong\" | \"em\" | \"del\"; children: Inline[] };\n\nconst ESCAPABLE = /[\\\\`*_{}[\\]()#+\\-.!|~<>]/;\n\n/** Where a link may lead: the web, or a letter. Anything else is not a link. */\nexport function safeAddress(value: unknown): string | null {\n const address = String(value ?? \"\").trim();\n return /^https?:\\/\\/[^\\s<>\"]+$/i.test(address) || /^mailto:[^\\s<>\"]+$/i.test(address) ? address : null;\n}\n\n/** A run of backticks, where one begins. */\nconst ticks = (text: string, from: number): string => /^`+/.exec(text.slice(from))?.[0] ?? \"`\";\n\n/** Where an emphasis that opened ends: its closing mark, which follows something said. -1 where it never closes. */\nfunction closes(text: string, from: number, mark: string): number {\n for (let j = from; j < text.length; j += 1) {\n if (text[j] === \"\\\\\") {\n j += 1;\n continue;\n }\n // What is within a code span is not a mark.\n if (text[j] === \"`\") {\n const run = ticks(text, j);\n const end = text.indexOf(run, j + run.length);\n if (end !== -1) j = end + run.length - 1;\n continue;\n }\n if (!text.startsWith(mark, j) || j === from || /\\s/.test(text[j - 1] ?? \"\")) continue;\n // A single mark is not half of a double one.\n if (mark.length === 1 && (text[j + 1] === mark || text[j - 1] === mark)) continue;\n // An underscore within a word is part of the word: snake_case is not emphasis.\n if (mark.startsWith(\"_\") && /\\w/.test(text[j + mark.length] ?? \"\")) continue;\n return j;\n }\n return -1;\n}\n\nconst MARKS: Array<[mark: string, kinds: Array<\"strong\" | \"em\" | \"del\">]> = [\n [\"***\", [\"strong\", \"em\"]],\n [\"___\", [\"strong\", \"em\"]],\n [\"**\", [\"strong\"]],\n [\"__\", [\"strong\"]],\n [\"~~\", [\"del\"]],\n [\"*\", [\"em\"]],\n [\"_\", [\"em\"]],\n];\n\n/** Where the `]` that closes a `[` is, with brackets within it counted. -1 where it is never closed. */\nfunction closingBracket(text: string, open: number): number {\n let depth = 0;\n for (let j = open; j < text.length; j += 1) {\n if (text[j] === \"\\\\\") j += 1;\n else if (text[j] === \"[\") depth += 1;\n else if (text[j] === \"]\" && (depth -= 1) === 0) return j;\n }\n return -1;\n}\n\n/** An address written out, without what ends the sentence around it, or closes a bracket it did not open. Null where there is none. */\nfunction writtenOut(text: string, from: number): string | null {\n const address = /^https?:\\/\\/[^\\s<>]+/i.exec(text.slice(from));\n if (!address) return null;\n let href = address[0].replace(/[.,;:!?'\"*_~]+$/, \"\");\n while (href.endsWith(\")\") && href.split(\"(\").length <= href.split(\")\").length - 1) href = href.slice(0, -1).replace(/[.,;:!?'\"*_~]+$/, \"\");\n return safeAddress(href) && href.length > 8 ? href : null;\n}\n\n/** What a line of text holds: words, and what marks them. */\nexport function inline(text: string): Inline[] {\n const found: Inline[] = [];\n let words = \"\";\n const say = (node: Inline | null) => {\n if (words !== \"\") found.push(words);\n words = \"\";\n if (node) found.push(node);\n };\n let i = 0;\n scan: while (i < text.length) {\n const ch = text[i] ?? \"\";\n if (ch === \"\\\\\" && i + 1 < text.length && ESCAPABLE.test(text[i + 1] ?? \"\")) {\n words += text[i + 1];\n i += 2;\n continue;\n }\n if (ch === \"\\n\") {\n say({ type: \"break\" });\n i += 1;\n continue;\n }\n if (ch === \"`\") {\n const run = ticks(text, i);\n const end = text.indexOf(run, i + run.length);\n if (end !== -1) {\n const code = text.slice(i + run.length, end).replace(/\\n/g, \" \");\n say({ type: \"code\", text: /^ .*[^ ].* $|^ [^ ] $/.test(code) ? code.slice(1, -1) : code });\n i = end + run.length;\n continue;\n }\n }\n // [words](address), and : a picture, which is shown as a link to it and never fetched.\n if (ch === \"[\" || (ch === \"!\" && text[i + 1] === \"[\")) {\n const open = ch === \"!\" ? i + 1 : i;\n const close = closingBracket(text, open);\n const target = close === -1 ? null : /^\\(\\s*<?([^\\s<>()]*(?:\\([^\\s<>()]*\\)[^\\s<>()]*)*)>?(?:\\s+(?:\"[^\"]*\"|'[^']*'))?\\s*\\)/.exec(text.slice(close + 1));\n if (target) {\n const label = text.slice(open + 1, close);\n const href = safeAddress(target[1]);\n const children = inline(label === \"\" ? (target[1] ?? \"\") : label);\n // An address that is not one a link may lead to leaves only its words.\n if (href) say({ type: \"link\", href, children });\n else {\n for (const child of children) {\n if (typeof child === \"string\") words += child;\n else say(child);\n }\n }\n i = close + 1 + target[0].length;\n continue;\n }\n }\n if (ch === \"<\") {\n const address = /^<((?:https?:\\/\\/|mailto:)[^\\s<>]+)>/i.exec(text.slice(i));\n if (address?.[1] && safeAddress(address[1])) {\n say({ type: \"link\", href: address[1], children: [address[1].replace(/^mailto:/i, \"\")] });\n i += address[0].length;\n continue;\n }\n }\n // An address written out, where a word could begin.\n if ((ch === \"h\" || ch === \"H\") && !/\\w/.test(text[i - 1] ?? \"\")) {\n const href = writtenOut(text, i);\n if (href) {\n say({ type: \"link\", href, children: [href] });\n i += href.length;\n continue;\n }\n }\n if (ch === \"*\" || ch === \"_\" || ch === \"~\") {\n for (const [mark, kinds] of MARKS) {\n if (!text.startsWith(mark, i)) continue;\n // It opens only before something said, and an underscore only where a word could begin.\n const after = text[i + mark.length];\n if (after === undefined || /\\s/.test(after)) continue;\n if (mark.startsWith(\"_\") && /\\w/.test(text[i - 1] ?? \"\")) continue;\n const end = closes(text, i + mark.length, mark);\n if (end === -1) continue;\n const marked = kinds.reduceRight<Inline[]>((children, type) => [{ type, children }], inline(text.slice(i + mark.length, end)));\n say(marked[0] ?? null);\n i = end + mark.length;\n continue scan;\n }\n }\n words += ch;\n i += 1;\n }\n say(null);\n return found;\n}\n"],"mappings":";AAMA,IAAM,YAAY;;AAGlB,SAAgB,YAAY,OAA+B;CACzD,MAAM,UAAU,OAAO,SAAS,EAAE,CAAC,CAAC,KAAK;CACzC,OAAO,0BAA0B,KAAK,OAAO,KAAK,sBAAsB,KAAK,OAAO,IAAI,UAAU;AACpG;;AAGA,IAAM,SAAS,MAAc,SAAyB,MAAM,KAAK,KAAK,MAAM,IAAI,CAAC,CAAC,GAAG,MAAM;;AAG3F,SAAS,OAAO,MAAc,MAAc,MAAsB;CAChE,KAAK,IAAI,IAAI,MAAM,IAAI,KAA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B,IAAI,UAAU,KAAA,KAAa,KAAK,KAAK,KAAK,GAAG;GAC7C,IAAI,KAAK,WAAW,GAAG,KAAK,KAAK,KAAK,KAAK,IAAI,MAAM,EAAE,GAAG;GAC1D,MAAM,MAAM,OAAO,MAAM,IAAI,KAAK,QAAQ,IAAI;GAC9C,IAAI,QAAQ,IAAI;GAEhB,IADe,MAAM,aAAuB,UAAU,SAAS,CAAC;IAAE;IAAM;GAAS,CAAC,GAAG,OAAO,KAAK,MAAM,IAAI,KAAK,QAAQ,GAAG,CAAC,CACxH,CAAA,CAAO,MAAM,IAAI;GACrB,IAAI,MAAM,KAAK;GACf,SAAS;EACX;EAEF,SAAS;EACT,KAAK;CACP;CACA,IAAI,IAAI;CACR,OAAO;AACT"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Inline } from "./markdown-inline";
|
|
2
|
+
export { safeAddress, type Inline } from "./markdown-inline";
|
|
3
|
+
/** How a column of a table is set. Null where it does not say. */
|
|
4
|
+
export type Align = "left" | "right" | "center" | null;
|
|
5
|
+
/** One thing a text is made of. */
|
|
6
|
+
export type Block = {
|
|
7
|
+
type: "paragraph";
|
|
8
|
+
inline: Inline[];
|
|
9
|
+
} | {
|
|
10
|
+
type: "heading";
|
|
11
|
+
level: number;
|
|
12
|
+
inline: Inline[];
|
|
13
|
+
} | {
|
|
14
|
+
type: "rule";
|
|
15
|
+
} | {
|
|
16
|
+
type: "code";
|
|
17
|
+
language: string | null;
|
|
18
|
+
text: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "quote";
|
|
21
|
+
blocks: Block[];
|
|
22
|
+
} | {
|
|
23
|
+
type: "list";
|
|
24
|
+
ordered: boolean;
|
|
25
|
+
start: number | null;
|
|
26
|
+
items: Array<{
|
|
27
|
+
checked: boolean | null;
|
|
28
|
+
blocks: Block[];
|
|
29
|
+
}>;
|
|
30
|
+
} | {
|
|
31
|
+
type: "table";
|
|
32
|
+
align: Align[];
|
|
33
|
+
head: Inline[][];
|
|
34
|
+
rows: Inline[][][];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Read Markdown into a tree: blocks, each holding what its text is made
|
|
38
|
+
* of. Needs no page, and never gives anything of the text as HTML.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseMarkdown(source: unknown): Block[];
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { inline } from "./markdown-inline.js";
|
|
2
|
+
// src/lib/markdown.ts
|
|
3
|
+
var BLANK = /^\s*$/;
|
|
4
|
+
var FENCE = /^( {0,3})(`{3,}|~{3,})(.*)$/;
|
|
5
|
+
var HEADING = /^ {0,3}(#{1,6})[ \t]+(.*?)[ \t]*#*[ \t]*$/;
|
|
6
|
+
var RULE = /^ {0,3}([-*_])([ \t]*\1){2,}[ \t]*$/;
|
|
7
|
+
var QUOTE = /^ {0,3}>[ \t]?/;
|
|
8
|
+
var ITEM = /^( *)([-*+]|\d{1,9}[.)])[ \t]+(.*)$/;
|
|
9
|
+
var DIVIDER = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*(\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/;
|
|
10
|
+
var indentOf = (line) => line.length - line.trimStart().length;
|
|
11
|
+
/** A line, or nothing where there is none. */
|
|
12
|
+
var lineAt = (lines, i) => lines[i] ?? "";
|
|
13
|
+
/** Whether a table begins at a line: a row with a bar in it, and a divider under it. */
|
|
14
|
+
var tableAt = (lines, i) => lineAt(lines, i).includes("|") && i + 1 < lines.length && DIVIDER.test(lineAt(lines, i + 1)) && lineAt(lines, i + 1).includes("-");
|
|
15
|
+
/** The cells of one row of a table, as text. A `\|` is a bar within a cell. */
|
|
16
|
+
function cells(line) {
|
|
17
|
+
const row = line.trim().replace(/^\|/, "").replace(/\|$/, "");
|
|
18
|
+
const found = [];
|
|
19
|
+
let cell = "";
|
|
20
|
+
for (let i = 0; i < row.length; i += 1) if (row[i] === "\\" && row[i + 1] === "|") {
|
|
21
|
+
cell += "|";
|
|
22
|
+
i += 1;
|
|
23
|
+
} else if (row[i] === "|") {
|
|
24
|
+
found.push(cell.trim());
|
|
25
|
+
cell = "";
|
|
26
|
+
} else cell += row[i];
|
|
27
|
+
found.push(cell.trim());
|
|
28
|
+
return found;
|
|
29
|
+
}
|
|
30
|
+
/** Whether a line begins something that is not a paragraph, and so ends one. */
|
|
31
|
+
function begins(lines, i) {
|
|
32
|
+
const line = lineAt(lines, i);
|
|
33
|
+
return FENCE.test(line) || HEADING.test(line) || RULE.test(line) || QUOTE.test(line) || ITEM.test(line) || tableAt(lines, i);
|
|
34
|
+
}
|
|
35
|
+
/** Where the lines that are not blank go on, from a line. */
|
|
36
|
+
function afterBlanks(lines, from) {
|
|
37
|
+
let next = from;
|
|
38
|
+
while (next < lines.length && BLANK.test(lineAt(lines, next))) next += 1;
|
|
39
|
+
return next;
|
|
40
|
+
}
|
|
41
|
+
/** A list, from its first item. Gives the list and the line after it. */
|
|
42
|
+
function list(lines, at) {
|
|
43
|
+
const first = ITEM.exec(lineAt(lines, at));
|
|
44
|
+
const base = first?.[1]?.length ?? 0;
|
|
45
|
+
const ordered = /\d/.test(first?.[2] ?? "");
|
|
46
|
+
const sibling = (line) => {
|
|
47
|
+
const found = ITEM.exec(line ?? "");
|
|
48
|
+
return found && (found[1] ?? "").length === base && /\d/.test(found[2] ?? "") === ordered && !RULE.test(line ?? "") ? found : null;
|
|
49
|
+
};
|
|
50
|
+
const items = [];
|
|
51
|
+
let i = at;
|
|
52
|
+
while (i < lines.length) {
|
|
53
|
+
const found = sibling(lines[i]);
|
|
54
|
+
if (!found) break;
|
|
55
|
+
const width = base + (found[2] ?? "").length + 1;
|
|
56
|
+
const content = [found[3] ?? ""];
|
|
57
|
+
i += 1;
|
|
58
|
+
while (i < lines.length) {
|
|
59
|
+
const line = lineAt(lines, i);
|
|
60
|
+
if (BLANK.test(line)) {
|
|
61
|
+
const next = afterBlanks(lines, i + 1);
|
|
62
|
+
if (next < lines.length && indentOf(lineAt(lines, next)) > base) {
|
|
63
|
+
content.push("");
|
|
64
|
+
i += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (indentOf(line) <= base) break;
|
|
70
|
+
content.push(line.slice(Math.min(width, indentOf(line))));
|
|
71
|
+
i += 1;
|
|
72
|
+
}
|
|
73
|
+
const task = /^\[([ xX])\][ \t]+/.exec(content[0] ?? "");
|
|
74
|
+
if (task) content[0] = (content[0] ?? "").slice(task[0].length);
|
|
75
|
+
items.push({
|
|
76
|
+
checked: task ? task[1] !== " " : null,
|
|
77
|
+
blocks: blocks(content)
|
|
78
|
+
});
|
|
79
|
+
const next = afterBlanks(lines, i);
|
|
80
|
+
if (next > i && !sibling(lines[next])) break;
|
|
81
|
+
i = next;
|
|
82
|
+
}
|
|
83
|
+
return [{
|
|
84
|
+
type: "list",
|
|
85
|
+
ordered,
|
|
86
|
+
start: ordered ? Number.parseInt(first?.[2] ?? "1", 10) : null,
|
|
87
|
+
items
|
|
88
|
+
}, i];
|
|
89
|
+
}
|
|
90
|
+
/** A table, from its head. Gives the table and the line after it, or null where the divider is not as wide as the head. */
|
|
91
|
+
function table(lines, at) {
|
|
92
|
+
const head = cells(lineAt(lines, at));
|
|
93
|
+
const align = cells(lineAt(lines, at + 1)).map((cell) => /^:-+:$/.test(cell) ? "center" : /-+:$/.test(cell) ? "right" : /^:-+/.test(cell) ? "left" : null);
|
|
94
|
+
if (head.length !== align.length) return null;
|
|
95
|
+
let i = at + 2;
|
|
96
|
+
const rows = [];
|
|
97
|
+
while (i < lines.length && lineAt(lines, i).includes("|") && !BLANK.test(lineAt(lines, i))) {
|
|
98
|
+
const row = cells(lineAt(lines, i));
|
|
99
|
+
rows.push(head.map((_, column) => inline(row[column] ?? "")));
|
|
100
|
+
i += 1;
|
|
101
|
+
}
|
|
102
|
+
return [{
|
|
103
|
+
type: "table",
|
|
104
|
+
align,
|
|
105
|
+
head: head.map((cell) => inline(cell)),
|
|
106
|
+
rows
|
|
107
|
+
}, i];
|
|
108
|
+
}
|
|
109
|
+
/** What a run of lines holds, block by block. */
|
|
110
|
+
function blocks(lines) {
|
|
111
|
+
const found = [];
|
|
112
|
+
let i = 0;
|
|
113
|
+
while (i < lines.length) {
|
|
114
|
+
const line = lineAt(lines, i);
|
|
115
|
+
if (BLANK.test(line)) {
|
|
116
|
+
i += 1;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const fence = FENCE.exec(line);
|
|
120
|
+
const [, margin = "", mark = "", rest = ""] = fence ?? [];
|
|
121
|
+
if (fence && !(mark.startsWith("`") && rest.includes("`"))) {
|
|
122
|
+
const closes = new RegExp(`^ {0,3}${mark[0]}{${mark.length},}[ \\t]*$`);
|
|
123
|
+
const code = [];
|
|
124
|
+
i += 1;
|
|
125
|
+
while (i < lines.length && !closes.test(lineAt(lines, i))) {
|
|
126
|
+
code.push(lineAt(lines, i).slice(Math.min(margin.length, indentOf(lineAt(lines, i)))));
|
|
127
|
+
i += 1;
|
|
128
|
+
}
|
|
129
|
+
i += 1;
|
|
130
|
+
found.push({
|
|
131
|
+
type: "code",
|
|
132
|
+
language: rest.trim().split(/\s+/)[0] || null,
|
|
133
|
+
text: code.join("\n")
|
|
134
|
+
});
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const heading = HEADING.exec(line);
|
|
138
|
+
if (heading) {
|
|
139
|
+
found.push({
|
|
140
|
+
type: "heading",
|
|
141
|
+
level: (heading[1] ?? "#").length,
|
|
142
|
+
inline: inline(heading[2] ?? "")
|
|
143
|
+
});
|
|
144
|
+
i += 1;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (RULE.test(line)) {
|
|
148
|
+
found.push({ type: "rule" });
|
|
149
|
+
i += 1;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (QUOTE.test(line)) {
|
|
153
|
+
const quoted = [];
|
|
154
|
+
while (i < lines.length && QUOTE.test(lineAt(lines, i))) {
|
|
155
|
+
quoted.push(lineAt(lines, i).replace(QUOTE, ""));
|
|
156
|
+
i += 1;
|
|
157
|
+
}
|
|
158
|
+
found.push({
|
|
159
|
+
type: "quote",
|
|
160
|
+
blocks: blocks(quoted)
|
|
161
|
+
});
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const tabled = tableAt(lines, i) ? table(lines, i) : null;
|
|
165
|
+
if (tabled) {
|
|
166
|
+
found.push(tabled[0]);
|
|
167
|
+
i = tabled[1];
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (ITEM.test(line)) {
|
|
171
|
+
const [made, next] = list(lines, i);
|
|
172
|
+
found.push(made);
|
|
173
|
+
i = next;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const text = [line.trim()];
|
|
177
|
+
i += 1;
|
|
178
|
+
while (i < lines.length && !BLANK.test(lineAt(lines, i)) && !begins(lines, i)) {
|
|
179
|
+
text.push(lineAt(lines, i).trim());
|
|
180
|
+
i += 1;
|
|
181
|
+
}
|
|
182
|
+
found.push({
|
|
183
|
+
type: "paragraph",
|
|
184
|
+
inline: inline(text.join("\n"))
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return found;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Read Markdown into a tree: blocks, each holding what its text is made
|
|
191
|
+
* of. Needs no page, and never gives anything of the text as HTML.
|
|
192
|
+
*/
|
|
193
|
+
function parseMarkdown(source) {
|
|
194
|
+
return blocks(String(source ?? "").replace(/\r\n?/g, "\n").split("\n"));
|
|
195
|
+
}
|
|
196
|
+
export { parseMarkdown };
|
|
197
|
+
|
|
198
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","names":[],"sources":["../../src/lib/markdown.ts"],"sourcesContent":["// Markdown, as a model writes it, read into a small tree: headings,\n// lists, tables, code and links.\n//\n// What is read here is whatever a model said, which may be whatever a\n// page or a file told it to say. So nothing of it is ever treated as\n// HTML: it is read into this tree, which needs no page, and drawn\n// element by element (components/markdown.tsx). A link leads only to an\n// http(s) or mailto address, and a picture is never fetched: it is shown\n// as a link, since fetching one would tell its address to whoever chose\n// it.\n//\n// It is read again from the start whenever more of an answer arrives, so\n// what is half written (a code fence not yet closed, a table one row\n// long) is read as far as it goes.\n\nimport { inline, type Inline } from \"./markdown-inline\";\n\nexport { safeAddress, type Inline } from \"./markdown-inline\";\n\n/** How a column of a table is set. Null where it does not say. */\nexport type Align = \"left\" | \"right\" | \"center\" | null;\n\n/** One thing a text is made of. */\nexport type Block =\n | { type: \"paragraph\"; inline: Inline[] }\n | { type: \"heading\"; level: number; inline: Inline[] }\n | { type: \"rule\" }\n | { type: \"code\"; language: string | null; text: string }\n | { type: \"quote\"; blocks: Block[] }\n | { type: \"list\"; ordered: boolean; start: number | null; items: Array<{ checked: boolean | null; blocks: Block[] }> }\n | { type: \"table\"; align: Align[]; head: Inline[][]; rows: Inline[][][] };\n\nconst BLANK = /^\\s*$/;\nconst FENCE = /^( {0,3})(`{3,}|~{3,})(.*)$/;\nconst HEADING = /^ {0,3}(#{1,6})[ \\t]+(.*?)[ \\t]*#*[ \\t]*$/;\nconst RULE = /^ {0,3}([-*_])([ \\t]*\\1){2,}[ \\t]*$/;\nconst QUOTE = /^ {0,3}>[ \\t]?/;\nconst ITEM = /^( *)([-*+]|\\d{1,9}[.)])[ \\t]+(.*)$/;\nconst DIVIDER = /^ {0,3}\\|?[ \\t]*:?-+:?[ \\t]*(\\|[ \\t]*:?-+:?[ \\t]*)*\\|?[ \\t]*$/;\n\nconst indentOf = (line: string): number => line.length - line.trimStart().length;\n/** A line, or nothing where there is none. */\nconst lineAt = (lines: string[], i: number): string => lines[i] ?? \"\";\n/** Whether a table begins at a line: a row with a bar in it, and a divider under it. */\nconst tableAt = (lines: string[], i: number): boolean => lineAt(lines, i).includes(\"|\") && i + 1 < lines.length && DIVIDER.test(lineAt(lines, i + 1)) && lineAt(lines, i + 1).includes(\"-\");\n\n/** The cells of one row of a table, as text. A `\\|` is a bar within a cell. */\nfunction cells(line: string): string[] {\n const row = line.trim().replace(/^\\|/, \"\").replace(/\\|$/, \"\");\n const found: string[] = [];\n let cell = \"\";\n for (let i = 0; i < row.length; i += 1) {\n if (row[i] === \"\\\\\" && row[i + 1] === \"|\") {\n cell += \"|\";\n i += 1;\n } else if (row[i] === \"|\") {\n found.push(cell.trim());\n cell = \"\";\n } else cell += row[i];\n }\n found.push(cell.trim());\n return found;\n}\n\n/** Whether a line begins something that is not a paragraph, and so ends one. */\nfunction begins(lines: string[], i: number): boolean {\n const line = lineAt(lines, i);\n return FENCE.test(line) || HEADING.test(line) || RULE.test(line) || QUOTE.test(line) || ITEM.test(line) || tableAt(lines, i);\n}\n\n/** Where the lines that are not blank go on, from a line. */\nfunction afterBlanks(lines: string[], from: number): number {\n let next = from;\n while (next < lines.length && BLANK.test(lineAt(lines, next))) next += 1;\n return next;\n}\n\n/** A list, from its first item. Gives the list and the line after it. */\nfunction list(lines: string[], at: number): [Block, number] {\n const first = ITEM.exec(lineAt(lines, at));\n const base = first?.[1]?.length ?? 0;\n const ordered = /\\d/.test(first?.[2] ?? \"\");\n const sibling = (line: string | undefined) => {\n const found = ITEM.exec(line ?? \"\");\n return found && (found[1] ?? \"\").length === base && /\\d/.test(found[2] ?? \"\") === ordered && !RULE.test(line ?? \"\") ? found : null;\n };\n const items: Array<{ checked: boolean | null; blocks: Block[] }> = [];\n let i = at;\n while (i < lines.length) {\n const found = sibling(lines[i]);\n if (!found) break;\n // What follows the marker, and whatever is indented under it: more of the item, or a list within it.\n const width = base + (found[2] ?? \"\").length + 1;\n const content = [found[3] ?? \"\"];\n i += 1;\n while (i < lines.length) {\n const line = lineAt(lines, i);\n if (BLANK.test(line)) {\n const next = afterBlanks(lines, i + 1);\n if (next < lines.length && indentOf(lineAt(lines, next)) > base) {\n content.push(\"\");\n i += 1;\n continue;\n }\n break;\n }\n if (indentOf(line) <= base) break;\n content.push(line.slice(Math.min(width, indentOf(line))));\n i += 1;\n }\n const task = /^\\[([ xX])\\][ \\t]+/.exec(content[0] ?? \"\");\n if (task) content[0] = (content[0] ?? \"\").slice(task[0].length);\n items.push({ checked: task ? task[1] !== \" \" : null, blocks: blocks(content) });\n // Items may be set apart by blank lines. A blank line before anything else ends the list.\n const next = afterBlanks(lines, i);\n if (next > i && !sibling(lines[next])) break;\n i = next;\n }\n return [{ type: \"list\", ordered, start: ordered ? Number.parseInt(first?.[2] ?? \"1\", 10) : null, items }, i];\n}\n\n/** A table, from its head. Gives the table and the line after it, or null where the divider is not as wide as the head. */\nfunction table(lines: string[], at: number): [Block, number] | null {\n const head = cells(lineAt(lines, at));\n const align = cells(lineAt(lines, at + 1)).map((cell): Align => (/^:-+:$/.test(cell) ? \"center\" : /-+:$/.test(cell) ? \"right\" : /^:-+/.test(cell) ? \"left\" : null));\n if (head.length !== align.length) return null;\n let i = at + 2;\n const rows: Inline[][][] = [];\n while (i < lines.length && lineAt(lines, i).includes(\"|\") && !BLANK.test(lineAt(lines, i))) {\n const row = cells(lineAt(lines, i));\n // A row is as wide as its table: what is missing is empty, and what is beyond it is left out.\n rows.push(head.map((_, column) => inline(row[column] ?? \"\")));\n i += 1;\n }\n return [{ type: \"table\", align, head: head.map((cell) => inline(cell)), rows }, i];\n}\n\n/** What a run of lines holds, block by block. */\nfunction blocks(lines: string[]): Block[] {\n const found: Block[] = [];\n let i = 0;\n while (i < lines.length) {\n const line = lineAt(lines, i);\n if (BLANK.test(line)) {\n i += 1;\n continue;\n }\n const fence = FENCE.exec(line);\n const [, margin = \"\", mark = \"\", rest = \"\"] = fence ?? [];\n if (fence && !(mark.startsWith(\"`\") && rest.includes(\"`\"))) {\n const closes = new RegExp(`^ {0,3}${mark[0]}{${mark.length},}[ \\\\t]*$`);\n const code: string[] = [];\n i += 1;\n // One that is never closed runs to the end: an answer still being written.\n while (i < lines.length && !closes.test(lineAt(lines, i))) {\n code.push(lineAt(lines, i).slice(Math.min(margin.length, indentOf(lineAt(lines, i)))));\n i += 1;\n }\n i += 1;\n found.push({ type: \"code\", language: rest.trim().split(/\\s+/)[0] || null, text: code.join(\"\\n\") });\n continue;\n }\n const heading = HEADING.exec(line);\n if (heading) {\n found.push({ type: \"heading\", level: (heading[1] ?? \"#\").length, inline: inline(heading[2] ?? \"\") });\n i += 1;\n continue;\n }\n if (RULE.test(line)) {\n found.push({ type: \"rule\" });\n i += 1;\n continue;\n }\n if (QUOTE.test(line)) {\n const quoted: string[] = [];\n while (i < lines.length && QUOTE.test(lineAt(lines, i))) {\n quoted.push(lineAt(lines, i).replace(QUOTE, \"\"));\n i += 1;\n }\n found.push({ type: \"quote\", blocks: blocks(quoted) });\n continue;\n }\n const tabled = tableAt(lines, i) ? table(lines, i) : null;\n if (tabled) {\n found.push(tabled[0]);\n i = tabled[1];\n continue;\n }\n if (ITEM.test(line)) {\n const [made, next] = list(lines, i);\n found.push(made);\n i = next;\n continue;\n }\n const text = [line.trim()];\n i += 1;\n while (i < lines.length && !BLANK.test(lineAt(lines, i)) && !begins(lines, i)) {\n text.push(lineAt(lines, i).trim());\n i += 1;\n }\n found.push({ type: \"paragraph\", inline: inline(text.join(\"\\n\")) });\n }\n return found;\n}\n\n/**\n * Read Markdown into a tree: blocks, each holding what its text is made\n * of. Needs no page, and never gives anything of the text as HTML.\n */\nexport function parseMarkdown(source: unknown): Block[] {\n return blocks(String(source ?? \"\").replace(/\\r\\n?/g, \"\\n\").split(\"\\n\"));\n}\n"],"mappings":";;AAgCA,IAAM,QAAQ;AACd,IAAM,QAAQ;AACd,IAAM,UAAU;AAChB,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,OAAO;AACb,IAAM,UAAU;AAEhB,IAAM,YAAY,SAAyB,KAAK,SAAS,KAAK,UAAU,CAAC,CAAC;;AAE1E,IAAM,UAAU,OAAiB,MAAsB,MAAM,MAAM;;AAEnE,IAAM,WAAW,OAAiB,MAAuB,OAAO,OAAO,CAAC,CAAC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,CAAC;GAClC,MAAM,KAAK,IAAI;GACf,IAAI;GACJ;EACF;EACA,MAAM,OAAO,CAAC,KAAK,KAAK,CAAC;EACzB,KAAK;EACL,OAAO,IAAI,MAAM,UAAU,CAAC,MAAM,KAAK,OAAO,OAAO,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,GAAG;GAC7E,KAAK,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;GACjC,KAAK;EACP;EACA,MAAM,KAAK;GAAE,MAAM;GAAa,QAAQ,OAAO,KAAK,KAAK,IAAI,CAAC;EAAE,CAAC;CACnE;CACA,OAAO;AACT;;;;;AAMA,SAAgB,cAAc,QAA0B;CACtD,OAAO,OAAO,OAAO,UAAU,EAAE,CAAC,CAAC,QAAQ,UAAU,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC;AACxE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which mark stands for what: a kind of connection of the platform's
|
|
3
|
+
* (spec/connectors.md), a provider of the toolbox's tools, or an MCP
|
|
4
|
+
* server the platform knows of, by its id. The marks are kept by the
|
|
5
|
+
* platform's connections, at notification-service/static/logos/<mark>.svg,
|
|
6
|
+
* each in its own colour. One that is not here is shown by its initials.
|
|
7
|
+
*
|
|
8
|
+
* This is where a mark is added. A test (test/marks.test.ts) holds it to
|
|
9
|
+
* what there is to connect: every provider of the toolbox's tools, every
|
|
10
|
+
* server the platform knows of and every kind of connection has a mark,
|
|
11
|
+
* or is named there as having none.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MARKS: Readonly<Record<string, string>>;
|
|
14
|
+
/** Where the mark for something is kept, or null where there is none. */
|
|
15
|
+
export declare function markOf(id: string | null | undefined): string | null;
|
|
16
|
+
/** The letters that stand for something that has no mark: its words' first letters, three at most, or the first two of one word. */
|
|
17
|
+
export declare function markLetters(name: string | null | undefined): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/lib/marks.ts
|
|
2
|
+
/**
|
|
3
|
+
* Which mark stands for what: a kind of connection of the platform's
|
|
4
|
+
* (spec/connectors.md), a provider of the toolbox's tools, or an MCP
|
|
5
|
+
* server the platform knows of, by its id. The marks are kept by the
|
|
6
|
+
* platform's connections, at notification-service/static/logos/<mark>.svg,
|
|
7
|
+
* each in its own colour. One that is not here is shown by its initials.
|
|
8
|
+
*
|
|
9
|
+
* This is where a mark is added. A test (test/marks.test.ts) holds it to
|
|
10
|
+
* what there is to connect: every provider of the toolbox's tools, every
|
|
11
|
+
* server the platform knows of and every kind of connection has a mark,
|
|
12
|
+
* or is named there as having none.
|
|
13
|
+
*/
|
|
14
|
+
var MARKS = Object.freeze({
|
|
15
|
+
github: "github",
|
|
16
|
+
hubspot: "hubspot",
|
|
17
|
+
"hubspot-crm": "hubspot-crm",
|
|
18
|
+
anthropic: "anthropic",
|
|
19
|
+
openai: "openai",
|
|
20
|
+
atlassian: "atlassian",
|
|
21
|
+
"atlassian-mcp": "atlassian",
|
|
22
|
+
"google-workspace": "google-workspace",
|
|
23
|
+
tailscale: "tailscale",
|
|
24
|
+
auth0: "auth0",
|
|
25
|
+
airtable: "airtable",
|
|
26
|
+
slack: "slack",
|
|
27
|
+
"slack-mcp": "slack",
|
|
28
|
+
msteams: "msteams",
|
|
29
|
+
azure: "azure",
|
|
30
|
+
cloudflare: "cloudflare",
|
|
31
|
+
"cloudflare-docs": "cloudflare",
|
|
32
|
+
aws: "aws",
|
|
33
|
+
"aws-sts": "aws",
|
|
34
|
+
"aws-agentcore": "aws",
|
|
35
|
+
"aws-knowledge": "aws",
|
|
36
|
+
"aws-bedrock": "aws",
|
|
37
|
+
"azure-ai-foundry": "azure",
|
|
38
|
+
"brave-search": "brave",
|
|
39
|
+
tavily: "tavily",
|
|
40
|
+
apollo: "apollo",
|
|
41
|
+
"apollo-mcp": "apollo"
|
|
42
|
+
});
|
|
43
|
+
/** Where the mark for something is kept, or null where there is none. */
|
|
44
|
+
function markOf(id) {
|
|
45
|
+
return typeof id === "string" && Object.hasOwn(MARKS, id) ? `/notification-service/static/logos/${MARKS[id]}.svg` : null;
|
|
46
|
+
}
|
|
47
|
+
/** The letters that stand for something that has no mark: its words' first letters, three at most, or the first two of one word. */
|
|
48
|
+
function markLetters(name) {
|
|
49
|
+
const words = String(name ?? "").replace(/[^A-Za-z0-9 ]/g, " ").trim().split(/\s+/).filter(Boolean);
|
|
50
|
+
return (words.length > 1 ? words.slice(0, 3).map((word) => word.charAt(0)).join("") : (words[0] ?? "?").slice(0, 2)).toUpperCase();
|
|
51
|
+
}
|
|
52
|
+
export { MARKS, markLetters, markOf };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=marks.js.map
|