@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FinchlyProvider, mount } from "./components/provider.js";
|
|
2
|
+
import { AppShell } from "./components/app-shell.js";
|
|
3
|
+
import { Page, PageHeader, SectionHeader } from "./components/page.js";
|
|
4
|
+
import { LinkTabs } from "./components/link-tabs.js";
|
|
5
|
+
import { useHash } from "./lib/hash.js";
|
|
6
|
+
import { SideNav } from "./components/side-nav.js";
|
|
7
|
+
import { addressOf, routeOf, useRoute } from "./lib/route.js";
|
|
8
|
+
import { Panel } from "./components/panel.js";
|
|
9
|
+
import { CellTitle, DataTable } from "./components/data-table.js";
|
|
10
|
+
import { Tag } from "./components/tag.js";
|
|
11
|
+
import { EmptyState, Failure, Loading } from "./components/states.js";
|
|
12
|
+
import { Callout, Copyable, DefinitionList, Muted, Notice, Snippet } from "./components/text.js";
|
|
13
|
+
import { Markdown } from "./components/markdown.js";
|
|
14
|
+
import { Bubble, Step, StepDetail, Thread, Turn } from "./components/conversation.js";
|
|
15
|
+
import { Face, Tile, Tiles } from "./components/tile.js";
|
|
16
|
+
import { ProviderMark } from "./components/provider-mark.js";
|
|
17
|
+
import { Meter, Progress, Row, Rows } from "./components/rows.js";
|
|
18
|
+
import { ColumnChart, ShareBar, Stat, Stats } from "./components/column-chart.js";
|
|
19
|
+
import { PickTile, PickTiles } from "./components/pick-tile.js";
|
|
20
|
+
import { SearchField, Segmented } from "./components/choosing.js";
|
|
21
|
+
import { Composer, Expander } from "./components/composing.js";
|
|
22
|
+
import { LinkButton } from "./components/link-button.js";
|
|
23
|
+
import { Palette } from "./components/palette.js";
|
|
24
|
+
import { ConfirmDialog, DialogBody, FormDialog } from "./components/form-dialog.js";
|
|
25
|
+
import { ask } from "./components/ask.js";
|
|
26
|
+
import { CheckboxField, MultiSelectField, RadioField, SelectField, TextField, TextareaField } from "./components/fields.js";
|
|
27
|
+
import { SuggestField } from "./components/suggest-field.js";
|
|
28
|
+
import { ActionButton } from "./components/action-button.js";
|
|
29
|
+
import { FileButton } from "./components/file-button.js";
|
|
30
|
+
import { toast } from "./components/toast.js";
|
|
31
|
+
import { Button } from "./components/ui/button.js";
|
|
32
|
+
import { Input } from "./components/ui/input.js";
|
|
33
|
+
import { Textarea } from "./components/ui/textarea.js";
|
|
34
|
+
import { Label } from "./components/ui/label.js";
|
|
35
|
+
import { Checkbox } from "./components/ui/checkbox.js";
|
|
36
|
+
import { RadioGroup, RadioGroupItem } from "./components/ui/radio-group.js";
|
|
37
|
+
import { NativeSelect, NativeSelectOptGroup, NativeSelectOption } from "./components/ui/native-select.js";
|
|
38
|
+
import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSet } from "./components/ui/field.js";
|
|
39
|
+
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "./components/ui/dialog.js";
|
|
40
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "./components/ui/dropdown-menu.js";
|
|
41
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./components/ui/tooltip.js";
|
|
42
|
+
import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./components/ui/card.js";
|
|
43
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./components/ui/table.js";
|
|
44
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./components/ui/collapsible.js";
|
|
45
|
+
import { Separator } from "./components/ui/separator.js";
|
|
46
|
+
import { Skeleton } from "./components/ui/skeleton.js";
|
|
47
|
+
import { Spinner } from "./components/ui/spinner.js";
|
|
48
|
+
import { ApiError, core, createApi, explain } from "./lib/api.js";
|
|
49
|
+
import { followEvents, parseEvents, readEvents } from "./lib/events.js";
|
|
50
|
+
import { closeOver, openOver } from "./lib/over.js";
|
|
51
|
+
import { useLauncher } from "./lib/launcher.js";
|
|
52
|
+
import { ago, bytes, hueOf, initials, plural, when } from "./lib/format.js";
|
|
53
|
+
import { MARKS, markLetters, markOf } from "./lib/marks.js";
|
|
54
|
+
import { cn } from "./lib/cn.js";
|
|
55
|
+
import { QueryClient, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
56
|
+
export { ActionButton, ApiError, AppShell, Bubble, Button, Callout, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CellTitle, Checkbox, CheckboxField, Collapsible, CollapsibleContent, CollapsibleTrigger, ColumnChart, Composer, ConfirmDialog, Copyable, DataTable, DefinitionList, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, EmptyState, Expander, Face, Failure, Field, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSet, FileButton, FinchlyProvider, FormDialog, Input, Label, LinkButton, LinkTabs, Loading, MARKS, Markdown, Meter, MultiSelectField, Muted, NativeSelect, NativeSelectOptGroup, NativeSelectOption, Notice, Page, PageHeader, Palette, Panel, PickTile, PickTiles, Progress, ProviderMark, QueryClient, RadioField, RadioGroup, RadioGroupItem, Row, Rows, SearchField, SectionHeader, Segmented, SelectField, Separator, ShareBar, SideNav, Skeleton, Snippet, Spinner, Stat, Stats, Step, StepDetail, SuggestField, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Tag, TextField, Textarea, TextareaField, Thread, Tile, Tiles, Tooltip, TooltipContent, TooltipTrigger, Turn, addressOf, ago, ask, bytes, closeOver, cn, core, createApi, explain, followEvents, hueOf, initials, markLetters, markOf, mount, openOver, parseEvents, plural, readEvents, routeOf, toast, useHash, useInfiniteQuery, useLauncher, useMutation, useQuery, useQueryClient, useRoute, when };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** What the platform said no with: its status, its `error` code and, if it gave one, the detail. */
|
|
2
|
+
export declare class ApiError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly code: string | undefined;
|
|
5
|
+
readonly detail: string | undefined;
|
|
6
|
+
constructor(status: number, code?: string, detail?: string);
|
|
7
|
+
}
|
|
8
|
+
/** Say what went wrong, for a person. */
|
|
9
|
+
export declare function explain(err: unknown): string;
|
|
10
|
+
export interface AskOptions {
|
|
11
|
+
method?: string;
|
|
12
|
+
body?: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** What an API client reaches the world through. Given in a test. */
|
|
15
|
+
export interface World {
|
|
16
|
+
fetch: typeof fetch;
|
|
17
|
+
location: {
|
|
18
|
+
href: string;
|
|
19
|
+
pathname: string;
|
|
20
|
+
search: string;
|
|
21
|
+
hash: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface ApiOptions {
|
|
25
|
+
/** What this API's own refusals mean, by `error` code, where it gives no detail. */
|
|
26
|
+
meanings?: Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a session that has ended sends the person to sign in. So it
|
|
29
|
+
* does, for the API a page is of. False for something asked on the
|
|
30
|
+
* side, of a service that is not the page's own: what it answers to
|
|
31
|
+
* nobody is a refusal like any other, and the page goes on without it.
|
|
32
|
+
*/
|
|
33
|
+
signIn?: boolean;
|
|
34
|
+
world?: World;
|
|
35
|
+
}
|
|
36
|
+
/** Ask an API. Resolves with the JSON it answered, or undefined where it answered with nothing. */
|
|
37
|
+
export type Api = <T = unknown>(path: string, options?: AskOptions) => Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Make the client for one API, at the address the page is on.
|
|
40
|
+
*
|
|
41
|
+
* Rejects with an ApiError where the API said no. Where nobody is signed
|
|
42
|
+
* in any more, the person is sent to sign in and brought back to where
|
|
43
|
+
* they were, and the promise never settles: the page is on its way out.
|
|
44
|
+
*
|
|
45
|
+
* @param base where the API is, such as `/core/api` or `/my-app/api`
|
|
46
|
+
*/
|
|
47
|
+
export declare function createApi(base: string, { meanings, signIn, world }?: ApiOptions): Api;
|
|
48
|
+
/** platform-core's API. */
|
|
49
|
+
export declare const core: Api;
|
package/dist/lib/api.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/lib/api.ts
|
|
2
|
+
/** What the platform said no with: its status, its `error` code and, if it gave one, the detail. */
|
|
3
|
+
var ApiError = class extends Error {
|
|
4
|
+
status;
|
|
5
|
+
code;
|
|
6
|
+
detail;
|
|
7
|
+
constructor(status, code, detail) {
|
|
8
|
+
super(detail ?? code ?? `The platform answered ${status}`);
|
|
9
|
+
this.name = "ApiError";
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.detail = detail;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/** What a refusal means, in words for the person who caused it. */
|
|
16
|
+
var MEANINGS = {
|
|
17
|
+
forbidden: "You do not have the permission this needs.",
|
|
18
|
+
not_found: "That is no longer there.",
|
|
19
|
+
internal_error: "The platform could not do that. It has been logged."
|
|
20
|
+
};
|
|
21
|
+
/** Say what went wrong, for a person. */
|
|
22
|
+
function explain(err) {
|
|
23
|
+
if (err instanceof ApiError) {
|
|
24
|
+
if (err.detail) return err.detail.charAt(0).toUpperCase() + err.detail.slice(1);
|
|
25
|
+
return (err.code && MEANINGS[err.code]) ?? `The platform refused: ${err.code ?? err.status}.`;
|
|
26
|
+
}
|
|
27
|
+
return "The platform could not be reached. Check your connection and try again.";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Make the client for one API, at the address the page is on.
|
|
31
|
+
*
|
|
32
|
+
* Rejects with an ApiError where the API said no. Where nobody is signed
|
|
33
|
+
* in any more, the person is sent to sign in and brought back to where
|
|
34
|
+
* they were, and the promise never settles: the page is on its way out.
|
|
35
|
+
*
|
|
36
|
+
* @param base where the API is, such as `/core/api` or `/my-app/api`
|
|
37
|
+
*/
|
|
38
|
+
function createApi(base, { meanings = {}, signIn = true, world = globalThis } = {}) {
|
|
39
|
+
return async function ask(path, { method = "GET", body } = {}) {
|
|
40
|
+
const response = await world.fetch(`${base}${path}`, {
|
|
41
|
+
method,
|
|
42
|
+
headers: {
|
|
43
|
+
accept: "application/json",
|
|
44
|
+
...body !== void 0 ? { "content-type": "application/json" } : {}
|
|
45
|
+
},
|
|
46
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {},
|
|
47
|
+
credentials: "same-origin"
|
|
48
|
+
});
|
|
49
|
+
if (response.status === 401 && signIn) {
|
|
50
|
+
const here = `${world.location.pathname}${world.location.search}${world.location.hash}`;
|
|
51
|
+
world.location.href = `/_gateway/login?return_to=${encodeURIComponent(here)}`;
|
|
52
|
+
return new Promise(() => {});
|
|
53
|
+
}
|
|
54
|
+
const text = await response.text();
|
|
55
|
+
let answer;
|
|
56
|
+
try {
|
|
57
|
+
answer = text === "" ? void 0 : JSON.parse(text);
|
|
58
|
+
} catch {
|
|
59
|
+
answer = void 0;
|
|
60
|
+
}
|
|
61
|
+
if (!response.ok) throw new ApiError(response.status, answer?.error, answer?.detail ?? (answer?.error ? meanings[answer.error] : void 0));
|
|
62
|
+
return answer;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** platform-core's API. */
|
|
66
|
+
var core = createApi("/core/api", { meanings: {
|
|
67
|
+
email_in_use: "Someone with that email address already exists.",
|
|
68
|
+
name_in_use: "That name is already taken.",
|
|
69
|
+
cannot_change_self: "You cannot do that to your own account.",
|
|
70
|
+
admin_group_is_protected: "The administrators' group cannot be deleted.",
|
|
71
|
+
principal_not_found: "That person or group no longer exists.",
|
|
72
|
+
default_tenant_is_protected: "The platform's own tenant cannot be suspended.",
|
|
73
|
+
core_cannot_be_suspended: "The platform itself cannot be suspended.",
|
|
74
|
+
built_in_service: "A built-in service cannot be removed.",
|
|
75
|
+
built_in: "A built-in service is every tenant's, and cannot be switched on or off.",
|
|
76
|
+
release_not_pending: "That release has already been decided."
|
|
77
|
+
} });
|
|
78
|
+
export { ApiError, core, createApi, explain };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","names":[],"sources":["../../src/lib/api.ts"],"sourcesContent":["// Asking the platform. A page asks from the browser, with the session of\n// whoever is looking, so nothing here holds a secret. This is the only\n// place a page's requests are made: an app makes its own client with\n// createApi() and asks through that.\n\n/** What the platform said no with: its status, its `error` code and, if it gave one, the detail. */\nexport class ApiError extends Error {\n readonly status: number;\n readonly code: string | undefined;\n readonly detail: string | undefined;\n\n constructor(status: number, code?: string, detail?: string) {\n super(detail ?? code ?? `The platform answered ${status}`);\n this.name = \"ApiError\";\n this.status = status;\n this.code = code;\n this.detail = detail;\n }\n}\n\n/** What a refusal means, in words for the person who caused it. */\nconst MEANINGS: Record<string, string> = {\n forbidden: \"You do not have the permission this needs.\",\n not_found: \"That is no longer there.\",\n internal_error: \"The platform could not do that. It has been logged.\",\n};\n\n/** Say what went wrong, for a person. */\nexport function explain(err: unknown): string {\n if (err instanceof ApiError) {\n if (err.detail) return err.detail.charAt(0).toUpperCase() + err.detail.slice(1);\n return (err.code && MEANINGS[err.code]) ?? `The platform refused: ${err.code ?? err.status}.`;\n }\n return \"The platform could not be reached. Check your connection and try again.\";\n}\n\nexport interface AskOptions {\n method?: string;\n body?: unknown;\n}\n\n/** What an API client reaches the world through. Given in a test. */\nexport interface World {\n fetch: typeof fetch;\n location: { href: string; pathname: string; search: string; hash: string };\n}\n\nexport interface ApiOptions {\n /** What this API's own refusals mean, by `error` code, where it gives no detail. */\n meanings?: Record<string, string>;\n /**\n * Whether a session that has ended sends the person to sign in. So it\n * does, for the API a page is of. False for something asked on the\n * side, of a service that is not the page's own: what it answers to\n * nobody is a refusal like any other, and the page goes on without it.\n */\n signIn?: boolean;\n world?: World;\n}\n\n/** Ask an API. Resolves with the JSON it answered, or undefined where it answered with nothing. */\nexport type Api = <T = unknown>(path: string, options?: AskOptions) => Promise<T>;\n\n/**\n * Make the client for one API, at the address the page is on.\n *\n * Rejects with an ApiError where the API said no. Where nobody is signed\n * in any more, the person is sent to sign in and brought back to where\n * they were, and the promise never settles: the page is on its way out.\n *\n * @param base where the API is, such as `/core/api` or `/my-app/api`\n */\nexport function createApi(base: string, { meanings = {}, signIn = true, world = globalThis as unknown as World }: ApiOptions = {}): Api {\n return async function ask<T>(path: string, { method = \"GET\", body }: AskOptions = {}): Promise<T> {\n const response = await world.fetch(`${base}${path}`, {\n method,\n headers: { accept: \"application/json\", ...(body !== undefined ? { \"content-type\": \"application/json\" } : {}) },\n ...(body !== undefined ? { body: JSON.stringify(body) } : {}),\n credentials: \"same-origin\",\n });\n if (response.status === 401 && signIn) {\n const here = `${world.location.pathname}${world.location.search}${world.location.hash}`;\n world.location.href = `/_gateway/login?return_to=${encodeURIComponent(here)}`;\n return new Promise<T>(() => {});\n }\n const text = await response.text();\n let answer: { error?: string; detail?: string } | undefined;\n try {\n answer = text === \"\" ? undefined : JSON.parse(text);\n } catch {\n answer = undefined;\n }\n if (!response.ok) throw new ApiError(response.status, answer?.error, answer?.detail ?? (answer?.error ? meanings[answer.error] : undefined));\n return answer as T;\n };\n}\n\n/** platform-core's API. */\nexport const core: Api = createApi(\"/core/api\", {\n meanings: {\n email_in_use: \"Someone with that email address already exists.\",\n name_in_use: \"That name is already taken.\",\n cannot_change_self: \"You cannot do that to your own account.\",\n admin_group_is_protected: \"The administrators' group cannot be deleted.\",\n principal_not_found: \"That person or group no longer exists.\",\n default_tenant_is_protected: \"The platform's own tenant cannot be suspended.\",\n core_cannot_be_suspended: \"The platform itself cannot be suspended.\",\n built_in_service: \"A built-in service cannot be removed.\",\n built_in: \"A built-in service is every tenant's, and cannot be switched on or off.\",\n release_not_pending: \"That release has already been decided.\",\n },\n});\n"],"mappings":";;AAMA,IAAa,WAAb,cAA8B,MAAM;CAClC;CACA;CACA;CAEA,YAAY,QAAgB,MAAe,QAAiB;EAC1D,MAAM,UAAU,QAAQ,yBAAyB,QAAQ;EACzD,KAAK,OAAO;EACZ,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,SAAS;CAChB;AACF;;AAGA,IAAM,WAAmC;CACvC,WAAW;CACX,WAAW;CACX,gBAAgB;AAClB;;AAGA,SAAgB,QAAQ,KAAsB;CAC5C,IAAI,eAAe,UAAU;EAC3B,IAAI,IAAI,QAAQ,OAAO,IAAI,OAAO,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,IAAI,OAAO,MAAM,CAAC;EAC9E,QAAQ,IAAI,QAAQ,SAAS,IAAI,UAAU,yBAAyB,IAAI,QAAQ,IAAI,OAAO;CAC7F;CACA,OAAO;AACT;;;;;;;;;;AAsCA,SAAgB,UAAU,MAAc,EAAE,WAAW,CAAC,GAAG,SAAS,MAAM,QAAQ,eAA+C,CAAC,GAAQ;CACtI,OAAO,eAAe,IAAO,MAAc,EAAE,SAAS,OAAO,SAAqB,CAAC,GAAe;EAChG,MAAM,WAAW,MAAM,MAAM,MAAM,GAAG,OAAO,QAAQ;GACnD;GACA,SAAS;IAAE,QAAQ;IAAoB,GAAI,SAAS,KAAA,IAAY,EAAE,gBAAgB,mBAAmB,IAAI,CAAC;GAAG;GAC7G,GAAI,SAAS,KAAA,IAAY,EAAE,MAAM,KAAK,UAAU,IAAI,EAAE,IAAI,CAAC;GAC3D,aAAa;EACf,CAAC;EACD,IAAI,SAAS,WAAW,OAAO,QAAQ;GACrC,MAAM,OAAO,GAAG,MAAM,SAAS,WAAW,MAAM,SAAS,SAAS,MAAM,SAAS;GACjF,MAAM,SAAS,OAAO,6BAA6B,mBAAmB,IAAI;GAC1E,OAAO,IAAI,cAAiB,CAAC,CAAC;EAChC;EACA,MAAM,OAAO,MAAM,SAAS,KAAK;EACjC,IAAI;EACJ,IAAI;GACF,SAAS,SAAS,KAAK,KAAA,IAAY,KAAK,MAAM,IAAI;EACpD,QAAQ;GACN,SAAS,KAAA;EACX;EACA,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,SAAS,SAAS,QAAQ,QAAQ,OAAO,QAAQ,WAAW,QAAQ,QAAQ,SAAS,OAAO,SAAS,KAAA,EAAU;EAC3I,OAAO;CACT;AACF;;AAGA,IAAa,OAAY,UAAU,aAAa,EAC9C,UAAU;CACR,cAAc;CACd,aAAa;CACb,oBAAoB;CACpB,0BAA0B;CAC1B,qBAAqB;CACrB,6BAA6B;CAC7B,0BAA0B;CAC1B,kBAAkB;CAClB,UAAU;CACV,qBAAqB;AACvB,EACF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A scale for an axis that starts at nothing: round steps up to at least
|
|
3
|
+
* `max`, about `steps` of them. `[0, 0.5, 1, 1.5, 2]` for 1.7.
|
|
4
|
+
*/
|
|
5
|
+
export declare function niceScale(max: number, steps?: number): number[];
|
|
6
|
+
/**
|
|
7
|
+
* Which marks of a chart are named along its axis: the first, the last,
|
|
8
|
+
* and a few evenly between. Their places in the list.
|
|
9
|
+
*/
|
|
10
|
+
export declare function namedPlaces(count: number, most?: number): number[];
|
|
11
|
+
/** Where a column chart's marks stand, at the width it is drawn at. */
|
|
12
|
+
export interface Columns {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
/** The edges of where the marks are: left and right of it, and the baseline they stand on. */
|
|
16
|
+
left: number;
|
|
17
|
+
right: number;
|
|
18
|
+
top: number;
|
|
19
|
+
base: number;
|
|
20
|
+
/** The width of each mark's place, and of the mark itself: thin, and never wider than a few pixels of air allow. */
|
|
21
|
+
band: number;
|
|
22
|
+
wide: number;
|
|
23
|
+
ticks: number[];
|
|
24
|
+
/** Where a value is, from the top of the drawing. */
|
|
25
|
+
y: (value: number) => number;
|
|
26
|
+
}
|
|
27
|
+
/** Lay out a column chart: `count` marks, the largest of them `max`, in a drawing `width` wide. */
|
|
28
|
+
export declare function columns(width: number, count: number, max: number, height?: number): Columns;
|
|
29
|
+
/**
|
|
30
|
+
* The outline of one column: rounded where it ends, square where it
|
|
31
|
+
* stands on the baseline. Null for a value of nothing, which has no mark.
|
|
32
|
+
*/
|
|
33
|
+
export declare function columnPath(at: Columns, index: number, value: number): string | null;
|
|
34
|
+
/** The place read next with a key: the arrows step, Home and End go to the ends. Null for a key that reads nothing. */
|
|
35
|
+
export declare function stepped(key: string, active: number, count: number): number | null;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/lib/chart.ts
|
|
2
|
+
/**
|
|
3
|
+
* A scale for an axis that starts at nothing: round steps up to at least
|
|
4
|
+
* `max`, about `steps` of them. `[0, 0.5, 1, 1.5, 2]` for 1.7.
|
|
5
|
+
*/
|
|
6
|
+
function niceScale(max, steps = 4) {
|
|
7
|
+
if (!(max > 0)) return [0, 1];
|
|
8
|
+
const rough = max / steps;
|
|
9
|
+
const power = 10 ** Math.floor(Math.log10(rough));
|
|
10
|
+
const step = [
|
|
11
|
+
1,
|
|
12
|
+
2,
|
|
13
|
+
2.5,
|
|
14
|
+
5,
|
|
15
|
+
10
|
|
16
|
+
].map((times) => times * power).find((candidate) => candidate >= rough) ?? 10 * power;
|
|
17
|
+
const ticks = [];
|
|
18
|
+
for (let n = 0; n * step < max + step - 1e-12; n += 1) ticks.push(Number((n * step).toPrecision(12)));
|
|
19
|
+
return ticks;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Which marks of a chart are named along its axis: the first, the last,
|
|
23
|
+
* and a few evenly between. Their places in the list.
|
|
24
|
+
*/
|
|
25
|
+
function namedPlaces(count, most = 6) {
|
|
26
|
+
if (count <= most) return Array.from({ length: count }, (_, index) => index);
|
|
27
|
+
const every = Math.ceil((count - 1) / (most - 1));
|
|
28
|
+
const ticks = [];
|
|
29
|
+
for (let index = count - 1; index >= 0; index -= every) ticks.unshift(index);
|
|
30
|
+
const first = ticks[0] ?? 0;
|
|
31
|
+
if (first !== 0) {
|
|
32
|
+
if (first >= every / 2) ticks.unshift(0);
|
|
33
|
+
else ticks[0] = 0;
|
|
34
|
+
}
|
|
35
|
+
return ticks;
|
|
36
|
+
}
|
|
37
|
+
/** Lay out a column chart: `count` marks, the largest of them `max`, in a drawing `width` wide. */
|
|
38
|
+
function columns(width, count, max, height = 220) {
|
|
39
|
+
const [left, right, above, below] = [
|
|
40
|
+
54,
|
|
41
|
+
8,
|
|
42
|
+
12,
|
|
43
|
+
26
|
|
44
|
+
];
|
|
45
|
+
const plotWidth = Math.max(0, width - left - right);
|
|
46
|
+
const plotHeight = height - above - below;
|
|
47
|
+
const band = count > 0 ? plotWidth / count : plotWidth;
|
|
48
|
+
const ticks = niceScale(Math.max(0, max));
|
|
49
|
+
const highest = ticks.at(-1) ?? 1;
|
|
50
|
+
const base = above + plotHeight;
|
|
51
|
+
return {
|
|
52
|
+
width,
|
|
53
|
+
height,
|
|
54
|
+
left,
|
|
55
|
+
right: width - right,
|
|
56
|
+
top: above,
|
|
57
|
+
base,
|
|
58
|
+
band,
|
|
59
|
+
wide: Math.max(1.5, Math.min(24, band - 2)),
|
|
60
|
+
ticks,
|
|
61
|
+
y: (value) => base - (highest > 0 ? value / highest : 0) * plotHeight
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The outline of one column: rounded where it ends, square where it
|
|
66
|
+
* stands on the baseline. Null for a value of nothing, which has no mark.
|
|
67
|
+
*/
|
|
68
|
+
function columnPath(at, index, value) {
|
|
69
|
+
if (!(value > 0)) return null;
|
|
70
|
+
const x = at.left + index * at.band + (at.band - at.wide) / 2;
|
|
71
|
+
const peak = Math.min(at.y(value), at.base - 1);
|
|
72
|
+
const r = Math.min(4, at.wide / 2, at.base - peak);
|
|
73
|
+
return `M${x},${at.base}V${peak + r}Q${x},${peak} ${x + r},${peak}H${x + at.wide - r}Q${x + at.wide},${peak} ${x + at.wide},${peak + r}V${at.base}Z`;
|
|
74
|
+
}
|
|
75
|
+
/** The place read next with a key: the arrows step, Home and End go to the ends. Null for a key that reads nothing. */
|
|
76
|
+
function stepped(key, active, count) {
|
|
77
|
+
if (count === 0) return null;
|
|
78
|
+
if (key === "Home") return 0;
|
|
79
|
+
if (key === "End") return count - 1;
|
|
80
|
+
const step = key === "ArrowLeft" ? -1 : key === "ArrowRight" ? 1 : null;
|
|
81
|
+
if (step === null) return null;
|
|
82
|
+
return Math.min(count - 1, Math.max(0, (active < 0 ? count - 1 : active) + step));
|
|
83
|
+
}
|
|
84
|
+
export { columnPath, columns, namedPlaces, niceScale, stepped };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.js","names":[],"sources":["../../src/lib/chart.ts"],"sourcesContent":["// What a chart works out without a page: its axis, which of its marks\n// are named along the bottom, and where each mark stands. Kept apart\n// from the component so that it is tested by itself.\n\n/**\n * A scale for an axis that starts at nothing: round steps up to at least\n * `max`, about `steps` of them. `[0, 0.5, 1, 1.5, 2]` for 1.7.\n */\nexport function niceScale(max: number, steps = 4): number[] {\n if (!(max > 0)) return [0, 1];\n const rough = max / steps;\n const power = 10 ** Math.floor(Math.log10(rough));\n const step = [1, 2, 2.5, 5, 10].map((times) => times * power).find((candidate) => candidate >= rough) ?? 10 * power;\n const ticks: number[] = [];\n for (let n = 0; n * step < max + step - 1e-12; n += 1) ticks.push(Number((n * step).toPrecision(12)));\n return ticks;\n}\n\n/**\n * Which marks of a chart are named along its axis: the first, the last,\n * and a few evenly between. Their places in the list.\n */\nexport function namedPlaces(count: number, most = 6): number[] {\n if (count <= most) return Array.from({ length: count }, (_, index) => index);\n const every = Math.ceil((count - 1) / (most - 1));\n const ticks: number[] = [];\n for (let index = count - 1; index >= 0; index -= every) ticks.unshift(index);\n // The first is named too, unless the next one named is too close to it to read.\n const first = ticks[0] ?? 0;\n if (first !== 0) {\n if (first >= every / 2) ticks.unshift(0);\n else ticks[0] = 0;\n }\n return ticks;\n}\n\n/** Where a column chart's marks stand, at the width it is drawn at. */\nexport interface Columns {\n width: number;\n height: number;\n /** The edges of where the marks are: left and right of it, and the baseline they stand on. */\n left: number;\n right: number;\n top: number;\n base: number;\n /** The width of each mark's place, and of the mark itself: thin, and never wider than a few pixels of air allow. */\n band: number;\n wide: number;\n ticks: number[];\n /** Where a value is, from the top of the drawing. */\n y: (value: number) => number;\n}\n\n/** Lay out a column chart: `count` marks, the largest of them `max`, in a drawing `width` wide. */\nexport function columns(width: number, count: number, max: number, height = 220): Columns {\n const [left, right, above, below] = [54, 8, 12, 26];\n const plotWidth = Math.max(0, width - left - right);\n const plotHeight = height - above - below;\n const band = count > 0 ? plotWidth / count : plotWidth;\n const ticks = niceScale(Math.max(0, max));\n const highest = ticks.at(-1) ?? 1;\n const base = above + plotHeight;\n return { width, height, left, right: width - right, top: above, base, band, wide: Math.max(1.5, Math.min(24, band - 2)), ticks, y: (value) => base - (highest > 0 ? value / highest : 0) * plotHeight };\n}\n\n/**\n * The outline of one column: rounded where it ends, square where it\n * stands on the baseline. Null for a value of nothing, which has no mark.\n */\nexport function columnPath(at: Columns, index: number, value: number): string | null {\n if (!(value > 0)) return null;\n const x = at.left + index * at.band + (at.band - at.wide) / 2;\n const peak = Math.min(at.y(value), at.base - 1);\n const r = Math.min(4, at.wide / 2, at.base - peak);\n return `M${x},${at.base}V${peak + r}Q${x},${peak} ${x + r},${peak}H${x + at.wide - r}Q${x + at.wide},${peak} ${x + at.wide},${peak + r}V${at.base}Z`;\n}\n\n/** The place read next with a key: the arrows step, Home and End go to the ends. Null for a key that reads nothing. */\nexport function stepped(key: string, active: number, count: number): number | null {\n if (count === 0) return null;\n if (key === \"Home\") return 0;\n if (key === \"End\") return count - 1;\n const step = key === \"ArrowLeft\" ? -1 : key === \"ArrowRight\" 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AS,IAAI,QAAQ,IAAI,UAAU,IAAI,CAAC;AAClF"}
|
package/dist/lib/cn.d.ts
ADDED
package/dist/lib/cn.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { clsx } from "clsx";
|
|
2
|
+
import { twMerge } from "tailwind-merge";
|
|
3
|
+
// src/lib/cn.ts
|
|
4
|
+
/** Join class names, the later of two that set the same thing winning. */
|
|
5
|
+
function cn(...inputs) {
|
|
6
|
+
return twMerge(clsx(inputs));
|
|
7
|
+
}
|
|
8
|
+
export { cn };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=cn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cn.js","names":[],"sources":["../../src/lib/cn.ts"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\n/** Join class names, the later of two that set the same thing winning. */\nexport function cn(...inputs: ClassValue[]): string {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";;;;AAIA,SAAgB,GAAG,GAAG,QAA8B;CAClD,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Something that happened, as a stream gives it: what kind of thing, and what it says. */
|
|
2
|
+
export interface StreamEvent {
|
|
3
|
+
type: string;
|
|
4
|
+
data: unknown;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The events a stream's text holds, in order. Only what was given an id
|
|
8
|
+
* is one: what a stream says to keep itself open is not. One whose data
|
|
9
|
+
* is not JSON is left out.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseEvents(text: string): StreamEvent[];
|
|
12
|
+
/**
|
|
13
|
+
* A stream of events that is over, read to its end: what happened in
|
|
14
|
+
* something that has finished, which ends its own account of itself.
|
|
15
|
+
* One that somehow does not end is not waited for. Nothing where it
|
|
16
|
+
* cannot be read: what is drawn from it is then drawn without.
|
|
17
|
+
*
|
|
18
|
+
* @param url where the stream is, on this platform
|
|
19
|
+
*/
|
|
20
|
+
export declare function readEvents(url: string, { timeoutMs, world }?: {
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
world?: {
|
|
23
|
+
fetch: typeof fetch;
|
|
24
|
+
};
|
|
25
|
+
}): Promise<StreamEvent[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Follow a stream of events as they happen. Where the connection drops
|
|
28
|
+
* the browser asks again from where it left off: `lost` is called only
|
|
29
|
+
* once it has given up.
|
|
30
|
+
*
|
|
31
|
+
* @param types the kinds of event to be told of
|
|
32
|
+
* @returns the way to stop following
|
|
33
|
+
*/
|
|
34
|
+
export declare function followEvents(url: string, types: string[], on: (event: StreamEvent) => void, lost?: () => void): () => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/lib/events.ts
|
|
2
|
+
/**
|
|
3
|
+
* The events a stream's text holds, in order. Only what was given an id
|
|
4
|
+
* is one: what a stream says to keep itself open is not. One whose data
|
|
5
|
+
* is not JSON is left out.
|
|
6
|
+
*/
|
|
7
|
+
function parseEvents(text) {
|
|
8
|
+
const found = [];
|
|
9
|
+
for (const block of text.replace(/\r\n?/g, "\n").split("\n\n")) {
|
|
10
|
+
const lines = block.split("\n");
|
|
11
|
+
const said = (field) => lines.filter((line) => line.startsWith(`${field}:`)).map((line) => line.slice(field.length + 1).replace(/^ /, ""));
|
|
12
|
+
const [type] = said("event");
|
|
13
|
+
if (said("id").length === 0 || !type) continue;
|
|
14
|
+
try {
|
|
15
|
+
found.push({
|
|
16
|
+
type,
|
|
17
|
+
data: JSON.parse(said("data").join("\n") || "null")
|
|
18
|
+
});
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
return found;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A stream of events that is over, read to its end: what happened in
|
|
25
|
+
* something that has finished, which ends its own account of itself.
|
|
26
|
+
* One that somehow does not end is not waited for. Nothing where it
|
|
27
|
+
* cannot be read: what is drawn from it is then drawn without.
|
|
28
|
+
*
|
|
29
|
+
* @param url where the stream is, on this platform
|
|
30
|
+
*/
|
|
31
|
+
async function readEvents(url, { timeoutMs = 8e3, world = globalThis } = {}) {
|
|
32
|
+
try {
|
|
33
|
+
const response = await world.fetch(url, {
|
|
34
|
+
credentials: "same-origin",
|
|
35
|
+
headers: { accept: "text/event-stream" },
|
|
36
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
37
|
+
});
|
|
38
|
+
return response.ok ? parseEvents(await response.text()) : [];
|
|
39
|
+
} catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Follow a stream of events as they happen. Where the connection drops
|
|
45
|
+
* the browser asks again from where it left off: `lost` is called only
|
|
46
|
+
* once it has given up.
|
|
47
|
+
*
|
|
48
|
+
* @param types the kinds of event to be told of
|
|
49
|
+
* @returns the way to stop following
|
|
50
|
+
*/
|
|
51
|
+
function followEvents(url, types, on, lost = () => {}) {
|
|
52
|
+
const stream = new EventSource(url);
|
|
53
|
+
for (const type of types) stream.addEventListener(type, (event) => {
|
|
54
|
+
let data;
|
|
55
|
+
try {
|
|
56
|
+
data = JSON.parse(event.data);
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
on({
|
|
61
|
+
type,
|
|
62
|
+
data
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
stream.onerror = () => {
|
|
66
|
+
if (stream.readyState === EventSource.CLOSED) lost();
|
|
67
|
+
};
|
|
68
|
+
return () => stream.close();
|
|
69
|
+
}
|
|
70
|
+
export { followEvents, parseEvents, readEvents };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","names":[],"sources":["../../src/lib/events.ts"],"sourcesContent":["// What a service says is happening, as a stream of events: a run's own\n// account of itself, as it goes or read back once it is over.\n\n/** Something that happened, as a stream gives it: what kind of thing, and what it says. */\nexport interface StreamEvent {\n type: string;\n data: unknown;\n}\n\n/**\n * The events a stream's text holds, in order. Only what was given an id\n * is one: what a stream says to keep itself open is not. One whose data\n * is not JSON is left out.\n */\nexport function parseEvents(text: string): StreamEvent[] {\n const found: StreamEvent[] = [];\n for (const block of text.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\\n\")) {\n const lines = block.split(\"\\n\");\n const said = (field: string) => lines.filter((line) => line.startsWith(`${field}:`)).map((line) => line.slice(field.length + 1).replace(/^ /, \"\"));\n const [type] = said(\"event\");\n if (said(\"id\").length === 0 || !type) continue;\n try {\n found.push({ type, data: JSON.parse(said(\"data\").join(\"\\n\") || \"null\") });\n } catch {\n // Not JSON: nothing can be made of it.\n }\n }\n return found;\n}\n\n/**\n * A stream of events that is over, read to its end: what happened in\n * something that has finished, which ends its own account of itself.\n * One that somehow does not end is not waited for. Nothing where it\n * cannot be read: what is drawn from it is then drawn without.\n *\n * @param url where the stream is, on this platform\n */\nexport async function readEvents(url: string, { timeoutMs = 8_000, world = globalThis as unknown as { fetch: typeof fetch } }: { timeoutMs?: number; world?: { fetch: typeof fetch } } = {}): Promise<StreamEvent[]> {\n try {\n const response = await world.fetch(url, { credentials: \"same-origin\", headers: { accept: \"text/event-stream\" }, signal: AbortSignal.timeout(timeoutMs) });\n return response.ok ? parseEvents(await response.text()) : [];\n } catch {\n return [];\n }\n}\n\n/**\n * Follow a stream of events as they happen. Where the connection drops\n * the browser asks again from where it left off: `lost` is called only\n * once it has given up.\n *\n * @param types the kinds of event to be told of\n * @returns the way to stop following\n */\nexport function followEvents(url: string, types: string[], on: (event: StreamEvent) => void, lost: () => void = () => {}): () => void {\n const stream = new EventSource(url);\n for (const type of types) {\n stream.addEventListener(type, (event) => {\n let data: unknown;\n try {\n data = JSON.parse((event as MessageEvent<string>).data);\n } catch {\n return;\n }\n on({ type, data });\n });\n }\n stream.onerror = () => {\n if (stream.readyState === EventSource.CLOSED) lost();\n };\n return () => stream.close();\n}\n"],"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B,CAAC;CAEH,OAAO,gBAAgB;EACrB,IAAI,OAAO,eAAe,YAAY,QAAQ,KAAK;CACrD;CACA,aAAa,OAAO,MAAM;AAC5B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** The letters that stand for a name where it has no picture: up to two, from its first words. */
|
|
2
|
+
export declare function initials(name: string | null | undefined): string;
|
|
3
|
+
/** A colour for a name, the same every time: a hue from 0 to 359. */
|
|
4
|
+
export declare function hueOf(name: string): number;
|
|
5
|
+
type Moment = string | number | Date | null | undefined;
|
|
6
|
+
/** A date and time, as the person's own settings write them. Empty for none. */
|
|
7
|
+
export declare function when(value: Moment, { time }?: {
|
|
8
|
+
time?: boolean;
|
|
9
|
+
}): string;
|
|
10
|
+
/** How long ago, in words: "3 hours ago". Falls back to the date for anything older than a month. */
|
|
11
|
+
export declare function ago(value: Moment, now?: number): string;
|
|
12
|
+
/** A number of bytes, in the unit that reads best. */
|
|
13
|
+
export declare function bytes(value: number | null | undefined): string;
|
|
14
|
+
/** A count with its noun: "1 tool", "3 tools". */
|
|
15
|
+
export declare function plural(count: number, one: string, many?: string): string;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/lib/format.ts
|
|
2
|
+
/** The letters that stand for a name where it has no picture: up to two, from its first words. */
|
|
3
|
+
function initials(name) {
|
|
4
|
+
const words = String(name ?? "").replace(/@.*$/, "").split(/[\s._-]+/).filter(Boolean);
|
|
5
|
+
const first = words[0] ?? "?";
|
|
6
|
+
const second = words[1];
|
|
7
|
+
return (second ? first.charAt(0) + second.charAt(0) : first.slice(0, 2)).toUpperCase();
|
|
8
|
+
}
|
|
9
|
+
/** A colour for a name, the same every time: a hue from 0 to 359. */
|
|
10
|
+
function hueOf(name) {
|
|
11
|
+
let hash = 0;
|
|
12
|
+
for (const character of String(name)) hash = (hash * 31 + (character.codePointAt(0) ?? 0)) % 360;
|
|
13
|
+
return hash;
|
|
14
|
+
}
|
|
15
|
+
/** A date and time, as the person's own settings write them. Empty for none. */
|
|
16
|
+
function when(value, { time = true } = {}) {
|
|
17
|
+
if (!value) return "";
|
|
18
|
+
const date = new Date(value);
|
|
19
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
20
|
+
return date.toLocaleString(void 0, time ? {
|
|
21
|
+
dateStyle: "medium",
|
|
22
|
+
timeStyle: "short"
|
|
23
|
+
} : { dateStyle: "medium" });
|
|
24
|
+
}
|
|
25
|
+
/** How long ago, in words: "3 hours ago". Falls back to the date for anything older than a month. */
|
|
26
|
+
function ago(value, now = Date.now()) {
|
|
27
|
+
if (!value) return "never";
|
|
28
|
+
const then = new Date(value).getTime();
|
|
29
|
+
if (Number.isNaN(then)) return "";
|
|
30
|
+
const seconds = Math.round((now - then) / 1e3);
|
|
31
|
+
if (seconds < 60) return "just now";
|
|
32
|
+
const steps = [
|
|
33
|
+
[60, "minute"],
|
|
34
|
+
[24, "hour"],
|
|
35
|
+
[30, "day"]
|
|
36
|
+
];
|
|
37
|
+
let amount = seconds / 60;
|
|
38
|
+
for (const [per, unit] of steps) {
|
|
39
|
+
if (amount < per) {
|
|
40
|
+
const whole = Math.floor(amount);
|
|
41
|
+
return `${whole} ${unit}${whole === 1 ? "" : "s"} ago`;
|
|
42
|
+
}
|
|
43
|
+
amount /= per;
|
|
44
|
+
}
|
|
45
|
+
return when(value, { time: false });
|
|
46
|
+
}
|
|
47
|
+
/** A number of bytes, in the unit that reads best. */
|
|
48
|
+
function bytes(value) {
|
|
49
|
+
if (value === null || value === void 0) return "";
|
|
50
|
+
const units = [
|
|
51
|
+
"bytes",
|
|
52
|
+
"KB",
|
|
53
|
+
"MB",
|
|
54
|
+
"GB",
|
|
55
|
+
"TB"
|
|
56
|
+
];
|
|
57
|
+
let amount = Number(value);
|
|
58
|
+
let unit = 0;
|
|
59
|
+
while (amount >= 1024 && unit < units.length - 1) {
|
|
60
|
+
amount /= 1024;
|
|
61
|
+
unit += 1;
|
|
62
|
+
}
|
|
63
|
+
return `${unit === 0 ? amount : amount.toFixed(amount < 10 ? 1 : 0)} ${units[unit]}`;
|
|
64
|
+
}
|
|
65
|
+
/** A count with its noun: "1 tool", "3 tools". */
|
|
66
|
+
function plural(count, one, many = `${one}s`) {
|
|
67
|
+
return `${count} ${count === 1 ? one : many}`;
|
|
68
|
+
}
|
|
69
|
+
export { ago, bytes, hueOf, initials, plural, when };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../../src/lib/format.ts"],"sourcesContent":["// Small things about text. Nothing here knows of a page.\n\n/** The letters that stand for a name where it has no picture: up to two, from its first words. */\nexport function initials(name: string | null | undefined): string {\n const words = String(name ?? \"\")\n .replace(/@.*$/, \"\")\n .split(/[\\s._-]+/)\n .filter(Boolean);\n const first = words[0] ?? \"?\";\n const second = words[1];\n const letters = second ? first.charAt(0) + second.charAt(0) : first.slice(0, 2);\n return letters.toUpperCase();\n}\n\n/** A colour for a name, the same every time: a hue from 0 to 359. */\nexport function hueOf(name: string): number {\n let hash = 0;\n for (const character of String(name)) hash = (hash * 31 + (character.codePointAt(0) ?? 0)) % 360;\n return hash;\n}\n\ntype Moment = string | number | Date | null | undefined;\n\n/** A date and time, as the person's own settings write them. Empty for none. */\nexport function when(value: Moment, { time = true }: { time?: boolean } = {}): string {\n if (!value) return \"\";\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) return \"\";\n return date.toLocaleString(undefined, time ? { dateStyle: \"medium\", timeStyle: \"short\" } : { dateStyle: \"medium\" });\n}\n\n/** How long ago, in words: \"3 hours ago\". Falls back to the date for anything older than a month. */\nexport function ago(value: Moment, now: number = Date.now()): string {\n if (!value) return \"never\";\n const then = new Date(value).getTime();\n if (Number.isNaN(then)) return \"\";\n const seconds = Math.round((now - then) / 1000);\n if (seconds < 60) return \"just now\";\n const steps: Array<[number, string]> = [\n [60, \"minute\"],\n [24, \"hour\"],\n [30, \"day\"],\n ];\n let amount = seconds / 60;\n for (const [per, unit] of steps) {\n if (amount < per) {\n const whole = Math.floor(amount);\n return `${whole} ${unit}${whole === 1 ? \"\" : \"s\"} ago`;\n }\n amount /= per;\n }\n return when(value, { time: false });\n}\n\n/** A number of bytes, in the unit that reads best. */\nexport function bytes(value: number | null | undefined): string {\n if (value === null || value === undefined) return \"\";\n const units = [\"bytes\", \"KB\", \"MB\", \"GB\", \"TB\"];\n let amount = Number(value);\n let unit = 0;\n while (amount >= 1024 && unit < units.length - 1) {\n amount /= 1024;\n unit += 1;\n }\n return `${unit === 0 ? amount : amount.toFixed(amount < 10 ? 1 : 0)} ${units[unit]}`;\n}\n\n/** A count with its noun: \"1 tool\", \"3 tools\". */\nexport function plural(count: number, one: string, many: string = `${one}s`): string {\n return `${count} ${count === 1 ? one : many}`;\n}\n"],"mappings":";;AAGA,SAAgB,SAAS,MAAyC;CAChE,MAAM,QAAQ,OAAO,QAAQ,EAAE,CAAC,CAC7B,QAAQ,QAAQ,EAAE,CAAC,CACnB,MAAM,UAAU,CAAC,CACjB,OAAO,OAAO;CACjB,MAAM,QAAQ,MAAM,MAAM;CAC1B,MAAM,SAAS,MAAM;CAErB,QADgB,SAAS,MAAM,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,IAAI,MAAM,MAAM,GAAG,CAAC,EAAA,CAC/D,YAAY;AAC7B;;AAGA,SAAgB,MAAM,MAAsB;CAC1C,IAAI,OAAO;CACX,KAAK,MAAM,aAAa,OAAO,IAAI,GAAG,QAAQ,OAAO,MAAM,UAAU,YAAY,CAAC,KAAK,MAAM;CAC7F,OAAO;AACT;;AAKA,SAAgB,KAAK,OAAe,EAAE,OAAO,SAA6B,CAAC,GAAW;CACpF,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,OAAO,IAAI,KAAK,KAAK;CAC3B,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG,OAAO;CACzC,OAAO,KAAK,eAAe,KAAA,GAAW,OAAO;EAAE,WAAW;EAAU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+
// src/lib/hash.ts
|
|
3
|
+
var subscribe = (listener) => {
|
|
4
|
+
addEventListener("hashchange", listener);
|
|
5
|
+
return () => removeEventListener("hashchange", listener);
|
|
6
|
+
};
|
|
7
|
+
/** What the address has after its `#`, kept up with as it changes. */
|
|
8
|
+
function useHash() {
|
|
9
|
+
return useSyncExternalStore(subscribe, () => location.hash.slice(1), () => "");
|
|
10
|
+
}
|
|
11
|
+
export { useHash };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","names":[],"sources":["../../src/lib/hash.ts"],"sourcesContent":["// Which part of a page is shown, as the address says after its `#`: so\n// that a part can be linked to, and the browser's own way back works.\n\nimport { useSyncExternalStore } from \"react\";\n\nconst subscribe = (listener: () => void) => {\n addEventListener(\"hashchange\", listener);\n return () => removeEventListener(\"hashchange\", listener);\n};\n\n/** What the address has after its `#`, kept up with as it changes. */\nexport function useHash(): string {\n return useSyncExternalStore(\n subscribe,\n () => location.hash.slice(1),\n () => \"\",\n );\n}\n"],"mappings":";;AAKA,IAAM,aAAa,aAAyB;CAC1C,iBAAiB,cAAc,QAAQ;CACvC,aAAa,oBAAoB,cAAc,QAAQ;AACzD;;AAGA,SAAgB,UAAkB;CAChC,OAAO,qBACL,iBACM,SAAS,KAAK,MAAM,CAAC,SACrB,EACR;AACF"}
|