@firetail/finchly-ux 0.0.0-stage → 0.1.1
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 +56 -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/README.md
CHANGED
|
@@ -1,3 +1,268 @@
|
|
|
1
|
-
#
|
|
1
|
+
# finchly-ux
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The components every page of the platform, and of the apps that run on
|
|
4
|
+
it, is built from: React, TypeScript, Tailwind and
|
|
5
|
+
[shadcn/ui](https://ui.shadcn.com). With them come the build and the
|
|
6
|
+
checks, so that a page is built and held to the same rules whoever
|
|
7
|
+
writes it.
|
|
8
|
+
|
|
9
|
+
An agent writing a page starts from the skills:
|
|
10
|
+
[`.claude/skills/finchly-app`](https://github.com/FireTail-io/finchly/blob/main/.claude/skills/finchly-app/SKILL.md) to
|
|
11
|
+
make one, and
|
|
12
|
+
[`.claude/skills/finchly-ux`](https://github.com/FireTail-io/finchly/blob/main/.claude/skills/finchly-ux/SKILL.md) for
|
|
13
|
+
the conventions. Why it is built this way is in
|
|
14
|
+
[ADR 0010](https://github.com/FireTail-io/finchly/blob/main/docs/adr/0010-pages-are-built-on-finchly-ux.md).
|
|
15
|
+
|
|
16
|
+
## Installing
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
npm install @firetail/finchly-ux react react-dom
|
|
20
|
+
npm install -D vite eslint typescript
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
An app needs nothing else to build and check a page: Tailwind, the Vite
|
|
24
|
+
plugins and the lint rules come with the package. Its configuration is a
|
|
25
|
+
line each:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// vite.config.ts
|
|
29
|
+
import { finchlyApp } from "@firetail/finchly-ux/vite";
|
|
30
|
+
export default finchlyApp({ slug: "my-app" });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// eslint.config.js
|
|
35
|
+
import { app } from "@firetail/finchly-ux/eslint";
|
|
36
|
+
export default app();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
// tsconfig.json
|
|
41
|
+
{ "extends": "@firetail/finchly-ux/tsconfig.app.json", "include": ["src"] }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| Part | What it is |
|
|
45
|
+
|---|---|
|
|
46
|
+
| [src/index.ts](src/index.ts) | Everything a page may import. Nothing else in the package is for a page |
|
|
47
|
+
| [src/icons.ts](src/icons.ts) | The icons, as `@firetail/finchly-ux/icons` |
|
|
48
|
+
| [styles/styles.css](styles/styles.css) | The one stylesheet: Tailwind, with the platform's tokens as its only colours |
|
|
49
|
+
| [styles/tokens.css](styles/tokens.css) | The tokens themselves, which a tenant's theme says again. See [spec/theme.md](https://github.com/FireTail-io/finchly/blob/main/spec/theme.md) |
|
|
50
|
+
| [src/components/ui](src/components/ui) | shadcn/ui's components, as `npm run add` brought them in |
|
|
51
|
+
| [src/components](src/components) | What the platform's pages are made of, built on those |
|
|
52
|
+
| [vite](vite/index.js) | How a page is built: `finchlyApp()` is an app's whole Vite configuration |
|
|
53
|
+
| [eslint](eslint/index.js) | The checks a page passes: `app()` for a page, `library()` for this package |
|
|
54
|
+
|
|
55
|
+
## A page
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
// web/src/main.tsx
|
|
59
|
+
import "@firetail/finchly-ux/styles.css";
|
|
60
|
+
import { AppShell, mount } from "@firetail/finchly-ux";
|
|
61
|
+
import { Keys } from "./keys/Keys";
|
|
62
|
+
|
|
63
|
+
mount(
|
|
64
|
+
<AppShell>
|
|
65
|
+
<Keys />
|
|
66
|
+
</AppShell>,
|
|
67
|
+
);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
[services/mcp-gateway/web](https://github.com/FireTail-io/finchly/tree/main/services/mcp-gateway/web) is a whole one,
|
|
71
|
+
served by a service built on the SDK. [dashboard/web](https://github.com/FireTail-io/finchly/tree/main/dashboard/web)
|
|
72
|
+
is another, served by [ui/server.mjs](https://github.com/FireTail-io/finchly/blob/main/ui/server.mjs), and
|
|
73
|
+
[services/schedule-service/web](https://github.com/FireTail-io/finchly/tree/main/services/schedule-service/web) a
|
|
74
|
+
third, served by a Python service: the largest form so far.
|
|
75
|
+
[services/toolbox/web](https://github.com/FireTail-io/finchly/tree/main/services/toolbox/web) is the one with the most
|
|
76
|
+
to ask: its flows are chains of dialogs, each written with `ask()`.
|
|
77
|
+
|
|
78
|
+
Icons are lucide's, by name, from `@firetail/finchly-ux/icons`:
|
|
79
|
+
`import { StarIcon } from "@firetail/finchly-ux/icons"`.
|
|
80
|
+
|
|
81
|
+
## What there is
|
|
82
|
+
|
|
83
|
+
Imported from `@firetail/finchly-ux`. A test holds this list to
|
|
84
|
+
[src/index.ts](src/index.ts): what is exported and not here fails it.
|
|
85
|
+
|
|
86
|
+
### Starting a page, and what is around it
|
|
87
|
+
|
|
88
|
+
| | |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `mount` | Draw the page into `#root`, with everything a component needs around it. An entry's one call |
|
|
91
|
+
| `AppShell` | The bar across the top and the page below it. `current` says which of the bar's places the page is. `side` is a `SideNav`, for a page with many sections. `fill` is for a page that is one thing going on, such as a conversation: it is as tall as the window, and what is long scrolls within it |
|
|
92
|
+
| `Page` | Where a page's content goes. AppShell has one: used alone, with `narrow`, for a page with no bar that asks one thing |
|
|
93
|
+
| `PageHeader` | The page's title, a line about it (`lede`), and what can be done (`actions`) |
|
|
94
|
+
| `SideNav` (`SideItem`) | The sections of a page that has many, in groups down its side, given to `AppShell` as its `side`. A row across the top on a narrow screen |
|
|
95
|
+
| `useRoute`, `routeOf`, `addressOf` (`Route`) | Sections with addresses of their own: `#/users/abc` is the section `users` and the thing `abc` in it |
|
|
96
|
+
| `LinkTabs`, `useHash` | The parts of a page as links, each with an address of its own (`#delivery`), and which of them the address names |
|
|
97
|
+
| `SectionHeader` | The title of a part of a page, with a `count`, and a `mark` before it to tell one kind of part from another |
|
|
98
|
+
| `FinchlyProvider` | What `mount` puts around a page. Used directly only in a test |
|
|
99
|
+
|
|
100
|
+
### What a page is made of
|
|
101
|
+
|
|
102
|
+
| | |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `Panel` | A titled box, with `actions` in its head. `flush` for a table or a list of rows. `main` where it is the whole page |
|
|
105
|
+
| `DataTable` | What a tenant has, as a table: `rows`, `columns`, and `empty` in a few words. A column that is `false` is left out. Its type is `Column`: `text` is what a column says where its cell is more than words, and `time` when, where it says a time. Any titled column sorts; from eight rows it has one search, a choice for a column that says one of a few things, and a range of dates. On a phone each row is a card. `search={false}` or `controls={false}` for a page that does that itself |
|
|
106
|
+
| `CellTitle` | A cell's main line with a fainter one beneath |
|
|
107
|
+
| `Tag` | A word about a thing's state. Its `tone` (a `Tone`) is `neutral`, `ok`, `warn`, `danger`, `accent` or `agent`. `title` says what the word stands for, and `remove` gives it a way to be taken away, for one of several things a thing holds |
|
|
108
|
+
| `EmptyState` | Where there is nothing: a `title` of a few words, and no more |
|
|
109
|
+
| `Loading` | While the page waits |
|
|
110
|
+
| `Failure` | Where something could not be loaded: says the `error` in words |
|
|
111
|
+
| `Notice` | Something to read before going on: `neutral`, `warn` or `danger` |
|
|
112
|
+
| `Callout` | Something to see to before anything else on the page, with the way to (`action`) |
|
|
113
|
+
| `Tiles`, `Tile` | What a person can open, as tiles: a face, a name, a line about it, a few words beneath (`meta`), and something to do in its corner (`action`). `agent` for an agent |
|
|
114
|
+
| `Face` | The face of a thing with no image: its own picture (an emoji), or its letters in a colour of its own |
|
|
115
|
+
| `ColumnChart` (`ChartPoint`) | One measure over time: a thin column for each point, which says its figure under the pointer and with the arrow keys. Put a table of the figures beside it |
|
|
116
|
+
| `Stats`, `Stat` | Headline figures side by side. `lead` is the one a page leads with |
|
|
117
|
+
| `ShareBar` | How much one thing is beside the largest of its kind, for a column of a table that breaks a total down |
|
|
118
|
+
| `Rows`, `Row` | Things a tenant has, one to a row: its name, a line about it, and at its side its state and what can be done with it. `body` is what it says or holds, in the page's own ink: a message's words, something to open and read. For a `flush` Panel |
|
|
119
|
+
| `Meter` | How much of something limited has been used: a bar, with words beneath |
|
|
120
|
+
| `Progress` | How far something has got: a bar that fills as it is done |
|
|
121
|
+
| `PickTiles`, `PickTile` | Things to choose one of by pressing it: a mark, a name, a word beneath |
|
|
122
|
+
| `ProviderMark` | The mark of what something is connected to, or is to be: its logo, or its initials where none is kept. What is to be connected or switched on is always shown with it, beside its name |
|
|
123
|
+
| `Copyable` | Something to copy, with the button that copies it |
|
|
124
|
+
| `Snippet` | Lines of code or configuration. `wrap` for what is read and not typed: lines are folded, and what is long is scrolled |
|
|
125
|
+
| `Markdown` | What a model wrote, shown as text is: headings, lists, tables, code and links. Never as HTML: a link leads only to the web or a letter, and a picture is shown as a link, not fetched |
|
|
126
|
+
| `Thread`, `Turn`, `Bubble` | A conversation: what was said, one thing under another, each turn a question and what came of it. `follow` keeps the latest in sight as more arrives |
|
|
127
|
+
| `Step`, `StepDetail` | Something done on the way to an answer, such as a tool that was called: it opens to show what it was given and what came back |
|
|
128
|
+
| `DefinitionList` | Pairs of a name and what it is |
|
|
129
|
+
| `Muted` | A line that matters less. `small` for smaller |
|
|
130
|
+
| `LinkButton` | A link that looks like a button: for going somewhere |
|
|
131
|
+
| `Palette` | A part of a page drawn in a palette of its own, from the platform's tokens: a look seen before it is chosen |
|
|
132
|
+
|
|
133
|
+
### Asking the person
|
|
134
|
+
|
|
135
|
+
| | |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `FormDialog` | A dialog with fields. `submit` is given their values (`FormValues`), by name; what it rejects with is shown and the dialog stays open. `onDone` has the answer. `size="lg"` for a long form, which scrolls. It cannot be left while it is saving |
|
|
138
|
+
| `ConfirmDialog` | Asks before something that cannot be undone |
|
|
139
|
+
| `ask` | Ask in a dialog and wait for the answer: `const made = await ask({ title, body, action, submit })`, which is `undefined` where the person backed out. For what takes several dialogs in turn. Its options are an `Asked` |
|
|
140
|
+
| `DialogBody` | What a dialog holds between its title and its buttons, scrolled where it does not fit: for a dialog a page lays out itself, from `Dialog` and its parts |
|
|
141
|
+
| `TextField` | A labelled input, with a `hint` |
|
|
142
|
+
| `SelectField` | A labelled choice of one from a few |
|
|
143
|
+
| `MultiSelectField` | A labelled choice of any number from a list |
|
|
144
|
+
| `TextareaField`, `CheckboxField` | A labelled box for several lines; something that is so or is not |
|
|
145
|
+
| `RadioField` | A labelled choice of one from a few, all in sight, each with a line about it. One that cannot be chosen says why |
|
|
146
|
+
| `SuggestField` | A labelled box that can be typed in, with what is usual offered beneath to choose from |
|
|
147
|
+
| `ActionButton` | A button for what takes a moment and needs no dialog: it says it is working, and says if it could not be done |
|
|
148
|
+
| `FileButton` | A button that chooses a file from the person's device, and gives it to the page. Several at once with `onFiles` |
|
|
149
|
+
| `toast` | Say something briefly: `toast("Key revoked")`, or `{ danger: true }` |
|
|
150
|
+
| `SearchField` | The box a list is narrowed from. With `shortcut`, "/" goes to it |
|
|
151
|
+
| `Segmented` | A choice of one from a few, all in sight: which list is shown, or how |
|
|
152
|
+
| `Composer` | One box to write in, with what to start from beneath (`footer`) and the way to send it. Enter sends. What goes with the words is drawn under them (`attached`), and a file pasted there is given to the page (`onFiles`) |
|
|
153
|
+
| `Expander` | A part of a page that is closed until asked for. What is in it is kept while it is closed |
|
|
154
|
+
|
|
155
|
+
### shadcn/ui's own
|
|
156
|
+
|
|
157
|
+
For what the above does not cover. Each is as
|
|
158
|
+
[shadcn documents it](https://ui.shadcn.com/docs/components), on
|
|
159
|
+
[Base UI](https://base-ui.com).
|
|
160
|
+
|
|
161
|
+
`Button` · `Input` · `Textarea` · `Label` · `Checkbox` · `RadioGroup`,
|
|
162
|
+
`RadioGroupItem` · `NativeSelect`,
|
|
163
|
+
`NativeSelectOption`, `NativeSelectOptGroup` · `Field`, `FieldLabel`,
|
|
164
|
+
`FieldDescription`, `FieldError`, `FieldGroup`, `FieldSet`, `FieldLegend`
|
|
165
|
+
· `Dialog`, `DialogTrigger`, `DialogContent`, `DialogHeader`,
|
|
166
|
+
`DialogTitle`, `DialogDescription`, `DialogFooter`, `DialogClose` ·
|
|
167
|
+
`DropdownMenu`, `DropdownMenuTrigger`, `DropdownMenuContent`,
|
|
168
|
+
`DropdownMenuItem`, `DropdownMenuLabel`, `DropdownMenuSeparator`,
|
|
169
|
+
`DropdownMenuGroup` · `Collapsible`, `CollapsibleTrigger`,
|
|
170
|
+
`CollapsibleContent` · `Tooltip`, `TooltipTrigger`, `TooltipContent` ·
|
|
171
|
+
`Card`, `CardHeader`, `CardTitle`, `CardDescription`, `CardAction`,
|
|
172
|
+
`CardContent`, `CardFooter` · `Table`, `TableHeader`, `TableBody`,
|
|
173
|
+
`TableRow`, `TableHead`, `TableCell` · `Separator` · `Skeleton` ·
|
|
174
|
+
`Spinner`
|
|
175
|
+
|
|
176
|
+
### Asking the platform
|
|
177
|
+
|
|
178
|
+
| | |
|
|
179
|
+
|---|---|
|
|
180
|
+
| `createApi` | Make the client for an API: `createApi("/my-app/api", { meanings })`. It is an `Api`, asked with `AskOptions`. A session that has ended sends the person to sign in and brings them back: `signIn: false` for something asked on the side, of a service that is not the page's own, which is then only refused |
|
|
181
|
+
| `core` | platform-core's API, `/core/api` |
|
|
182
|
+
| `ApiError` | What a refusal rejects with: `status`, `code`, `detail` |
|
|
183
|
+
| `explain` | Say what went wrong, for a person |
|
|
184
|
+
| `readEvents`, `followEvents` | A service's stream of events (`StreamEvent`): read to its end where it is over, or followed as it happens. `parseEvents` reads one from text |
|
|
185
|
+
| `openOver`, `closeOver` | A page of this platform opened in a window over the one the person is on, to connect something, and closed from there once it is done. It is given no way back |
|
|
186
|
+
| `useQuery`, `useInfiniteQuery`, `useMutation`, `useQueryClient`, `QueryClient` | [TanStack Query](https://tanstack.com/query), which a page loads and changes things through. `useInfiniteQuery` for a list that is loaded a part at a time |
|
|
187
|
+
| `useLauncher` | Who is looking and what they can open (a `Launcher`, of `LauncherApp`s and `LauncherAgent`s). Asked once for a page |
|
|
188
|
+
|
|
189
|
+
### Small things
|
|
190
|
+
|
|
191
|
+
| | |
|
|
192
|
+
|---|---|
|
|
193
|
+
| `when`, `ago` | A date, and how long ago |
|
|
194
|
+
| `bytes`, `plural`, `initials` | A size, a count with its noun, the letters for a name |
|
|
195
|
+
| `hueOf` | A colour for a name, the same every time |
|
|
196
|
+
| `MARKS`, `markOf`, `markLetters` | Which logo stands for what, where it is kept, and the initials of what has none. This is where a mark is added: a test holds it to everything there is to connect |
|
|
197
|
+
| `cn` | Join class names |
|
|
198
|
+
|
|
199
|
+
## Colours
|
|
200
|
+
|
|
201
|
+
A class's colour is one of these names and no other. Tailwind's own
|
|
202
|
+
palette is not there: `bg-red-500` is not a class, and the checks say so.
|
|
203
|
+
Each name is one of the platform's tokens, which a tenant's theme can
|
|
204
|
+
change, so a page drawn in these is drawn in its tenant's look, light or
|
|
205
|
+
dark, with nothing more said. There is no `dark:`.
|
|
206
|
+
|
|
207
|
+
| Class name | Token | For |
|
|
208
|
+
|---|---|---|
|
|
209
|
+
| `background`, `foreground` | `--paper`, `--ink` | The page, and what is written on it |
|
|
210
|
+
| `card`, `popover` | `--surface` | What stands on the page |
|
|
211
|
+
| `muted`, `secondary` | `--surface-sunk` | What is set into it |
|
|
212
|
+
| `muted-foreground` | `--ink-soft` | What matters less |
|
|
213
|
+
| `faint` | `--ink-faint` | What matters least |
|
|
214
|
+
| `primary`, `primary-foreground` | `--accent`, `--accent-ink` | The tenant's accent: what goes ahead, links |
|
|
215
|
+
| `accent` | `--accent-soft` | The ground of what is hovered or chosen |
|
|
216
|
+
| `destructive`, `destructive-soft` | `--danger`, `--danger-soft` | What cannot be undone, what went wrong |
|
|
217
|
+
| `success`, `success-soft` | `--ok`, `--ok-soft` | What works |
|
|
218
|
+
| `warning`, `warning-soft` | `--warn`, `--warn-soft` | What to be careful of |
|
|
219
|
+
| `agent`, `agent-soft` | `--agent`, `--agent-soft` | What is an agent's |
|
|
220
|
+
| `border`, `input`, `ring` | `--line`, `--line-strong`, `--accent` | Edges, and what has focus |
|
|
221
|
+
|
|
222
|
+
## Adding a component
|
|
223
|
+
|
|
224
|
+
What a page needs and this lacks is added here, never in the page.
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
npm run add -- popover
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
brings shadcn's in and makes it fit ([scripts/add-component.mjs](scripts/add-component.mjs)
|
|
231
|
+
says how). Then export it from [src/index.ts](src/index.ts), list it
|
|
232
|
+
above, and run the checks. Where the platform's pages share a pattern
|
|
233
|
+
built from several (a table with its row actions, a dialog that asks),
|
|
234
|
+
write that once in [src/components](src/components) and give it a test.
|
|
235
|
+
|
|
236
|
+
Base UI is beneath shadcn's components, not Radix, because the platform's
|
|
237
|
+
pages take no inline `<style>` ([ui/server.mjs](https://github.com/FireTail-io/finchly/blob/main/ui/server.mjs) has the
|
|
238
|
+
policy) and Base UI can be told to write none. `FinchlyProvider` tells
|
|
239
|
+
it.
|
|
240
|
+
|
|
241
|
+
## Checks
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
npm run lint # this package, held to library()
|
|
245
|
+
npm run typecheck
|
|
246
|
+
npm run build # dist: the modules and their types, as npm has them
|
|
247
|
+
npm test
|
|
248
|
+
npm run check # all four, as CI runs them
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
A component is only known to pass the platform's content security policy
|
|
252
|
+
once a page that uses it has been run in a browser under it: the tests
|
|
253
|
+
here run without one. The platform's repository does that for every page
|
|
254
|
+
built on this package (`npm run test:pages` there), and holds the tokens
|
|
255
|
+
and marks here to what the platform serves.
|
|
256
|
+
|
|
257
|
+
## Releasing
|
|
258
|
+
|
|
259
|
+
Work is done on `dev`. A version is published to npm by pushing its tag:
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
git tag v0.1.0 && git push origin v0.1.0
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
[release.yml](.github/workflows/release.yml) checks the package and
|
|
266
|
+
publishes it, as `latest`, or as `next` for a version with a suffix
|
|
267
|
+
(`v0.2.0-rc.1`). The version in `package.json` is a placeholder: the tag
|
|
268
|
+
is the version.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
import { Button } from "./ui/button";
|
|
3
|
+
/**
|
|
4
|
+
* A button that does something that takes a moment: it cannot be pressed
|
|
5
|
+
* again until it is done, says that it is working, and tells the person
|
|
6
|
+
* if it could not be done. For what needs no dialog: refresh, pause,
|
|
7
|
+
* load more.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ActionButton({ run, children, working, ...button }: {
|
|
10
|
+
run: () => Promise<unknown>;
|
|
11
|
+
working?: string;
|
|
12
|
+
} & Omit<ComponentProps<typeof Button>, "onClick">): import("react").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { explain } from "../lib/api.js";
|
|
2
|
+
import { toast } from "./toast.js";
|
|
3
|
+
import { Button } from "./ui/button.js";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/components/action-button.tsx
|
|
7
|
+
/**
|
|
8
|
+
* A button that does something that takes a moment: it cannot be pressed
|
|
9
|
+
* again until it is done, says that it is working, and tells the person
|
|
10
|
+
* if it could not be done. For what needs no dialog: refresh, pause,
|
|
11
|
+
* load more.
|
|
12
|
+
*/
|
|
13
|
+
function ActionButton({ run, children, working = "Working…", ...button }) {
|
|
14
|
+
const [busy, setBusy] = useState(false);
|
|
15
|
+
const go = async () => {
|
|
16
|
+
setBusy(true);
|
|
17
|
+
try {
|
|
18
|
+
await run();
|
|
19
|
+
} catch (err) {
|
|
20
|
+
toast(explain(err), { danger: true });
|
|
21
|
+
} finally {
|
|
22
|
+
setBusy(false);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
26
|
+
...button,
|
|
27
|
+
disabled: busy || button.disabled,
|
|
28
|
+
onClick: () => void go(),
|
|
29
|
+
children: busy ? working : children
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export { ActionButton };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=action-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-button.js","names":[],"sources":["../../src/components/action-button.tsx"],"sourcesContent":["import { useState, type ComponentProps } from \"react\";\nimport { explain } from \"../lib/api\";\nimport { toast } from \"./toast\";\nimport { Button } from \"./ui/button\";\n\n/**\n * A button that does something that takes a moment: it cannot be pressed\n * again until it is done, says that it is working, and tells the person\n * if it could not be done. For what needs no dialog: refresh, pause,\n * load more.\n */\nexport function ActionButton({ run, children, working = \"Working…\", ...button }: { run: () => Promise<unknown>; working?: string } & Omit<ComponentProps<typeof Button>, \"onClick\">) {\n const [busy, setBusy] = useState(false);\n const go = async () => {\n setBusy(true);\n try {\n await run();\n } catch (err) {\n toast(explain(err), { danger: true });\n } finally {\n setBusy(false);\n }\n };\n return (\n <Button {...button} disabled={busy || button.disabled} onClick={() => void go()}>\n {busy ? working : children}\n </Button>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,aAAa,EAAE,KAAK,UAAU,UAAU,YAAY,GAAG,UAA8G;CACnL,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CACtC,MAAM,KAAK,YAAY;EACrB,QAAQ,IAAI;EACZ,IAAI;GACF,MAAM,IAAI;EACZ,SAAS,KAAK;GACZ,MAAM,QAAQ,GAAG,GAAG,EAAE,QAAQ,KAAK,CAAC;EACtC,UAAU;GACR,QAAQ,KAAK;EACf;CACF;CACA,OACE,oBAAC,QAAD;EAAQ,GAAI;EAAQ,UAAU,QAAQ,OAAO;EAAU,eAAe,KAAK,GAAG;EAC3E,UAAA,OAAO,UAAU;CACZ,CAAA;AAEZ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* What every page of the platform is inside: the bar across the top, and
|
|
4
|
+
* the page's own content below it. The content is drawn once the platform
|
|
5
|
+
* has said who is looking.
|
|
6
|
+
*
|
|
7
|
+
* @param current which of the bar's places this page is, where it is one: `dashboard`, `admin`, `schedules` or `tools`
|
|
8
|
+
* @param side for a page with many sections: its SideNav, drawn down the side of the content, and across the top of it
|
|
9
|
+
* on a narrow screen
|
|
10
|
+
* @param fill for a page that is one thing going on, such as a conversation: it is as tall as the window and no
|
|
11
|
+
* taller, so that what is written stays in sight, and what is long scrolls within the page and not with it
|
|
12
|
+
*/
|
|
13
|
+
export declare function AppShell({ current, side, fill, children }: {
|
|
14
|
+
current?: string;
|
|
15
|
+
side?: ReactNode;
|
|
16
|
+
fill?: boolean;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ApiError } from "../lib/api.js";
|
|
2
|
+
import { useLauncher } from "../lib/launcher.js";
|
|
3
|
+
import { Bar } from "./bar.js";
|
|
4
|
+
import { Page } from "./page.js";
|
|
5
|
+
import { EmptyState, Failure, Loading } from "./states.js";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/components/app-shell.tsx
|
|
8
|
+
/**
|
|
9
|
+
* What every page of the platform is inside: the bar across the top, and
|
|
10
|
+
* the page's own content below it. The content is drawn once the platform
|
|
11
|
+
* has said who is looking.
|
|
12
|
+
*
|
|
13
|
+
* @param current which of the bar's places this page is, where it is one: `dashboard`, `admin`, `schedules` or `tools`
|
|
14
|
+
* @param side for a page with many sections: its SideNav, drawn down the side of the content, and across the top of it
|
|
15
|
+
* on a narrow screen
|
|
16
|
+
* @param fill for a page that is one thing going on, such as a conversation: it is as tall as the window and no
|
|
17
|
+
* taller, so that what is written stays in sight, and what is long scrolls within the page and not with it
|
|
18
|
+
*/
|
|
19
|
+
function AppShell({ current, side, fill = false, children }) {
|
|
20
|
+
const launcher = useLauncher();
|
|
21
|
+
if (launcher.isPending) return /* @__PURE__ */ jsx(Loading, {});
|
|
22
|
+
if (launcher.isError) {
|
|
23
|
+
const refused = launcher.error instanceof ApiError && launcher.error.status === 403;
|
|
24
|
+
return /* @__PURE__ */ jsx(Page, { children: refused ? /* @__PURE__ */ jsx(EmptyState, {
|
|
25
|
+
title: "Your account cannot be used here",
|
|
26
|
+
children: "It may not have been set up yet, or it may have been disabled. Ask whoever administers this platform."
|
|
27
|
+
}) : /* @__PURE__ */ jsx(Failure, {
|
|
28
|
+
title: "This page could not be loaded",
|
|
29
|
+
error: launcher.error
|
|
30
|
+
}) });
|
|
31
|
+
}
|
|
32
|
+
if (fill) return /* @__PURE__ */ jsxs("div", {
|
|
33
|
+
"data-slot": "filled",
|
|
34
|
+
className: "flex h-dvh min-h-0 flex-col overflow-hidden",
|
|
35
|
+
children: [/* @__PURE__ */ jsx(Bar, {
|
|
36
|
+
current,
|
|
37
|
+
launcher: launcher.data
|
|
38
|
+
}), /* @__PURE__ */ jsx("main", {
|
|
39
|
+
className: "mx-auto flex min-h-0 w-full max-w-6xl flex-1 flex-col gap-3 px-5 pt-4.5 pb-4 short:gap-2 short:py-2",
|
|
40
|
+
children
|
|
41
|
+
})]
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Bar, {
|
|
44
|
+
current,
|
|
45
|
+
launcher: launcher.data
|
|
46
|
+
}), side ? /* @__PURE__ */ jsxs("div", {
|
|
47
|
+
className: "mx-auto grid max-w-7xl grid-cols-[minmax(0,1fr)] gap-4.5 px-5 pt-4 pb-20 md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 md:pt-7",
|
|
48
|
+
children: [side, /* @__PURE__ */ jsx("main", {
|
|
49
|
+
className: "grid min-w-0 content-start gap-4.5",
|
|
50
|
+
children
|
|
51
|
+
})]
|
|
52
|
+
}) : /* @__PURE__ */ jsx(Page, { children })] });
|
|
53
|
+
}
|
|
54
|
+
export { AppShell };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=app-shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-shell.js","names":["_Fragment"],"sources":["../../src/components/app-shell.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { ApiError } from \"../lib/api\";\nimport { useLauncher } from \"../lib/launcher\";\nimport { Bar } from \"./bar\";\nimport { Page } from \"./page\";\nimport { EmptyState, Failure, Loading } from \"./states\";\n\n/**\n * What every page of the platform is inside: the bar across the top, and\n * the page's own content below it. The content is drawn once the platform\n * has said who is looking.\n *\n * @param current which of the bar's places this page is, where it is one: `dashboard`, `admin`, `schedules` or `tools`\n * @param side for a page with many sections: its SideNav, drawn down the side of the content, and across the top of it\n * on a narrow screen\n * @param fill for a page that is one thing going on, such as a conversation: it is as tall as the window and no\n * taller, so that what is written stays in sight, and what is long scrolls within the page and not with it\n */\nexport function AppShell({ current, side, fill = false, children }: { current?: string; side?: ReactNode; fill?: boolean; children: ReactNode }) {\n const launcher = useLauncher();\n if (launcher.isPending) return <Loading />;\n if (launcher.isError) {\n // Signed in at the identity provider, and not an active user here.\n const refused = launcher.error instanceof ApiError && launcher.error.status === 403;\n return (\n <Page>\n {refused ? (\n <EmptyState title=\"Your account cannot be used here\">It may not have been set up yet, or it may have been disabled. Ask whoever administers this platform.</EmptyState>\n ) : (\n <Failure title=\"This page could not be loaded\" error={launcher.error} />\n )}\n </Page>\n );\n }\n if (fill) {\n return (\n <div data-slot=\"filled\" className=\"flex h-dvh min-h-0 flex-col overflow-hidden\">\n <Bar current={current} launcher={launcher.data} />\n <main className=\"mx-auto flex min-h-0 w-full max-w-6xl flex-1 flex-col gap-3 px-5 pt-4.5 pb-4 short:gap-2 short:py-2\">{children}</main>\n </div>\n );\n }\n return (\n <>\n <Bar current={current} launcher={launcher.data} />\n {side ? (\n <div className=\"mx-auto grid max-w-7xl grid-cols-[minmax(0,1fr)] gap-4.5 px-5 pt-4 pb-20 md:grid-cols-[13.5rem_minmax(0,1fr)] md:gap-8 md:pt-7\">\n {side}\n <main className=\"grid min-w-0 content-start gap-4.5\">{children}</main>\n </div>\n ) : (\n <Page>{children}</Page>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,SAAS,EAAE,SAAS,MAAM,OAAO,OAAO,YAAyF;CAC/I,MAAM,WAAW,YAAY;CAC7B,IAAI,SAAS,WAAW,OAAO,oBAAC,SAAD,CAAU,CAAA;CACzC,IAAI,SAAS,SAAS;EAEpB,MAAM,UAAU,SAAS,iBAAiB,YAAY,SAAS,MAAM,WAAW;EAChF,OACE,oBAAC,MAAD,EAAA,UACG,UACC,oBAAC,YAAD;GAAY,OAAM;GAAmC,UAAA;EAAiH,CAAA,IAEtK,oBAAC,SAAD;GAAS,OAAM;GAAgC,OAAO,SAAS;EAAQ,CAAA,EAErE,CAAA;CAEV;CACA,IAAI,MACF,OACE,qBAAC,OAAD;EAAK,aAAU;EAAS,WAAU;EAAlC,UAAA,CACE,oBAAC,KAAD;GAAc;GAAS,UAAU,SAAS;EAAO,CAAA,GACjD,oBAAC,QAAD;GAAM,WAAU;GAAuG;EAAe,CAAA,CACnI;;CAGT,OACE,qBAAAA,UAAA,EAAA,UAAA,CACE,oBAAC,KAAD;EAAc;EAAS,UAAU,SAAS;CAAO,CAAA,GAChD,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,MACD,oBAAC,QAAD;GAAM,WAAU;GAAsC;EAAe,CAAA,CAClE;CAEL,CAAA,IAAA,oBAAC,MAAD,EAAO,SAAe,CAAA,CAExB,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type FormValues } from "./form-dialog";
|
|
3
|
+
/** What a dialog holds. A function is given the way to close it with an answer, for something that is chosen and not sent. */
|
|
4
|
+
type Body<Result> = ReactNode | ((done: (result: Result) => void) => ReactNode);
|
|
5
|
+
export interface Asked<Result> {
|
|
6
|
+
title: string;
|
|
7
|
+
description?: ReactNode;
|
|
8
|
+
body?: Body<Result>;
|
|
9
|
+
/** The label of the button that goes ahead, and what it says while it is being done. */
|
|
10
|
+
action?: string;
|
|
11
|
+
busyAction?: string;
|
|
12
|
+
/** Whether going ahead cannot be undone. */
|
|
13
|
+
danger?: boolean;
|
|
14
|
+
size?: "default" | "lg";
|
|
15
|
+
/**
|
|
16
|
+
* Called when the person goes ahead, with what the fields hold by name.
|
|
17
|
+
* What it rejects with is shown in the dialog, which stays open. Left
|
|
18
|
+
* out, the dialog has one button, which closes it.
|
|
19
|
+
*/
|
|
20
|
+
submit?: (values: FormValues) => Promise<Result>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Ask the person something in a dialog, and wait for the answer. For
|
|
24
|
+
* what takes several dialogs in turn, each depending on the last: choose
|
|
25
|
+
* a provider, then what it signs in with, then what to call it.
|
|
26
|
+
*
|
|
27
|
+
* Resolves with what `submit` resolved with, or what the body closed it
|
|
28
|
+
* with, and with `undefined` where the person backed out. A `submit` that
|
|
29
|
+
* resolves with nothing counts as `true`, so that done is never mistaken
|
|
30
|
+
* for backed out.
|
|
31
|
+
*
|
|
32
|
+
* One dialog that stands alone on a page is a `FormDialog`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function ask<Result = true>(options: Asked<Result>): Promise<Result | undefined>;
|
|
35
|
+
/** Where what is asked with ask() is drawn. FinchlyProvider has one: a page does not add its own. */
|
|
36
|
+
export declare function AskHost(): import("react").JSX.Element[];
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { FormDialog } from "./form-dialog.js";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/ask.tsx
|
|
5
|
+
/** How long a dialog that has been answered stays drawn, on its way closed. */
|
|
6
|
+
var LEAVING_MS = 400;
|
|
7
|
+
var requests = [];
|
|
8
|
+
var made = 0;
|
|
9
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
10
|
+
var changed = () => {
|
|
11
|
+
requests = [...requests];
|
|
12
|
+
for (const listener of listeners) listener();
|
|
13
|
+
};
|
|
14
|
+
var subscribe = (listener) => {
|
|
15
|
+
listeners.add(listener);
|
|
16
|
+
return () => {
|
|
17
|
+
listeners.delete(listener);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Ask the person something in a dialog, and wait for the answer. For
|
|
22
|
+
* what takes several dialogs in turn, each depending on the last: choose
|
|
23
|
+
* a provider, then what it signs in with, then what to call it.
|
|
24
|
+
*
|
|
25
|
+
* Resolves with what `submit` resolved with, or what the body closed it
|
|
26
|
+
* with, and with `undefined` where the person backed out. A `submit` that
|
|
27
|
+
* resolves with nothing counts as `true`, so that done is never mistaken
|
|
28
|
+
* for backed out.
|
|
29
|
+
*
|
|
30
|
+
* One dialog that stands alone on a page is a `FormDialog`.
|
|
31
|
+
*/
|
|
32
|
+
function ask(options) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
const request = {
|
|
35
|
+
id: made += 1,
|
|
36
|
+
options,
|
|
37
|
+
open: true,
|
|
38
|
+
settle(result) {
|
|
39
|
+
if (!request.open) return;
|
|
40
|
+
request.open = false;
|
|
41
|
+
changed();
|
|
42
|
+
resolve(result);
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
requests = requests.filter((other) => other !== request);
|
|
45
|
+
changed();
|
|
46
|
+
}, LEAVING_MS);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
requests.push(request);
|
|
50
|
+
changed();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function Asking({ request }) {
|
|
54
|
+
const { body, submit, ...rest } = request.options;
|
|
55
|
+
return /* @__PURE__ */ jsx(FormDialog, {
|
|
56
|
+
...rest,
|
|
57
|
+
open: request.open,
|
|
58
|
+
onClose: () => request.settle(void 0),
|
|
59
|
+
submit: submit ? async (values) => {
|
|
60
|
+
const result = await submit(values);
|
|
61
|
+
request.settle(result === void 0 ? true : result);
|
|
62
|
+
return result;
|
|
63
|
+
} : void 0,
|
|
64
|
+
children: typeof body === "function" ? body((result) => request.settle(result)) : body
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Where what is asked with ask() is drawn. FinchlyProvider has one: a page does not add its own. */
|
|
68
|
+
function AskHost() {
|
|
69
|
+
return useSyncExternalStore(subscribe, () => requests).map((request) => /* @__PURE__ */ jsx(Asking, { request }, request.id));
|
|
70
|
+
}
|
|
71
|
+
export { AskHost, ask };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=ask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.js","names":[],"sources":["../../src/components/ask.tsx"],"sourcesContent":["import { useSyncExternalStore, type ReactNode } from \"react\";\nimport { FormDialog, type FormValues } from \"./form-dialog\";\n\n/** What a dialog holds. A function is given the way to close it with an answer, for something that is chosen and not sent. */\ntype Body<Result> = ReactNode | ((done: (result: Result) => void) => ReactNode);\n\nexport interface Asked<Result> {\n title: string;\n description?: ReactNode;\n body?: Body<Result>;\n /** The label of the button that goes ahead, and what it says while it is being done. */\n action?: string;\n busyAction?: string;\n /** Whether going ahead cannot be undone. */\n danger?: boolean;\n size?: \"default\" | \"lg\";\n /**\n * Called when the person goes ahead, with what the fields hold by name.\n * What it rejects with is shown in the dialog, which stays open. Left\n * out, the dialog has one button, which closes it.\n */\n submit?: (values: FormValues) => Promise<Result>;\n}\n\ninterface Request {\n id: number;\n options: Asked<unknown>;\n open: boolean;\n settle: (result: unknown) => void;\n}\n\n/** How long a dialog that has been answered stays drawn, on its way closed. */\nconst LEAVING_MS = 400;\n\nlet requests: Request[] = [];\nlet made = 0;\nconst listeners = new Set<() => void>();\nconst changed = () => {\n requests = [...requests];\n for (const listener of listeners) listener();\n};\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n};\n\n/**\n * Ask the person something in a dialog, and wait for the answer. For\n * what takes several dialogs in turn, each depending on the last: choose\n * a provider, then what it signs in with, then what to call it.\n *\n * Resolves with what `submit` resolved with, or what the body closed it\n * with, and with `undefined` where the person backed out. A `submit` that\n * resolves with nothing counts as `true`, so that done is never mistaken\n * for backed out.\n *\n * One dialog that stands alone on a page is a `FormDialog`.\n */\nexport function ask<Result = true>(options: Asked<Result>): Promise<Result | undefined> {\n return new Promise((resolve) => {\n const request: Request = {\n id: (made += 1),\n options: options as Asked<unknown>,\n open: true,\n settle(result) {\n if (!request.open) return;\n request.open = false;\n changed();\n resolve(result as Result | undefined);\n // It is closed, not taken away while it is open: it goes once it has had time to close.\n setTimeout(() => {\n requests = requests.filter((other) => other !== request);\n changed();\n }, LEAVING_MS);\n },\n };\n requests.push(request);\n changed();\n });\n}\n\nfunction Asking({ request }: { request: Request }) {\n const { body, submit, ...rest } = request.options;\n return (\n <FormDialog\n {...rest}\n open={request.open}\n onClose={() => request.settle(undefined)}\n submit={\n submit\n ? async (values) => {\n const result = await submit(values);\n request.settle(result === undefined ? true : result);\n return result;\n }\n : undefined\n }\n >\n {typeof body === \"function\" ? body((result) => request.settle(result)) : body}\n </FormDialog>\n );\n}\n\n/** Where what is asked with ask() is drawn. FinchlyProvider has one: a page does not add its own. */\nexport function AskHost() {\n const all = useSyncExternalStore(subscribe, () => requests);\n return all.map((request) => <Asking key={request.id} request={request} />);\n}\n"],"mappings":";;;;;AAgCA,IAAM,aAAa;AAEnB,IAAI,WAAsB,CAAC;AAC3B,IAAI,OAAO;AACX,IAAM,4BAAY,IAAI,IAAgB;AACtC,IAAM,gBAAgB;CACpB,WAAW,CAAC,GAAG,QAAQ;CACvB,KAAK,MAAM,YAAY,WAAW,SAAS;AAC7C;AACA,IAAM,aAAa,aAAyB;CAC1C,UAAU,IAAI,QAAQ;CACtB,aAAa;EACX,UAAU,OAAO,QAAQ;CAC3B;AACF;;;;;;;;;;;;;AAcA,SAAgB,IAAmB,SAAqD;CACtF,OAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,UAAmB;GACvB,IAAK,QAAQ;GACJ;GACT,MAAM;GACN,OAAO,QAAQ;IACb,IAAI,CAAC,QAAQ,MAAM;IACnB,QAAQ,OAAO;IACf,QAAQ;IACR,QAAQ,MAA4B;IAEpC,iBAAiB;KACf,WAAW,SAAS,QAAQ,UAAU,UAAU,OAAO;KACvD,QAAQ;IACV,GAAG,UAAU;GACf;EACF;EACA,SAAS,KAAK,OAAO;EACrB,QAAQ;CACV,CAAC;AACH;AAEA,SAAS,OAAO,EAAE,WAAiC;CACjD,MAAM,EAAE,MAAM,QAAQ,GAAG,SAAS,QAAQ;CAC1C,OACE,oBAAC,YAAD;EACE,GAAI;EACJ,MAAM,QAAQ;EACd,eAAe,QAAQ,OAAO,KAAA,CAAS;EACvC,QACE,SACI,OAAO,WAAW;GAChB,MAAM,SAAS,MAAM,OAAO,MAAM;GAClC,QAAQ,OAAO,WAAW,KAAA,IAAY,OAAO,MAAM;GACnD,OAAO;EACT,IACA,KAAA;EAGL,UAAA,OAAO,SAAS,aAAa,MAAM,WAAW,QAAQ,OAAO,MAAM,CAAC,IAAI;CAC/D,CAAA;AAEhB;;AAGA,SAAgB,UAAU;CAExB,OADY,qBAAqB,iBAAiB,QAC3C,CAAA,CAAI,KAAK,YAAY,oBAAC,QAAD,EAAkC,QAAU,GAA/B,QAAQ,EAAuB,CAAC;AAC3E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Launcher } from "../lib/launcher";
|
|
2
|
+
/**
|
|
3
|
+
* The bar every page has: the platform's mark, where a person can go, who
|
|
4
|
+
* they are, and the way out. AppShell draws it: a page does not.
|
|
5
|
+
*
|
|
6
|
+
* @param current which of the bar's places this page is: `dashboard`, `admin`, `schedules`, `tools`, or none of them
|
|
7
|
+
*/
|
|
8
|
+
export declare function Bar({ current, launcher }: {
|
|
9
|
+
current?: string;
|
|
10
|
+
launcher: Launcher;
|
|
11
|
+
}): import("react").JSX.Element;
|