copilotz 1.0.0-rc.51 → 1.0.0-rc.52
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/AGENTS.md +4 -4
- package/CHANGELOG.md +88 -0
- package/README.md +2 -2
- package/hosts/web/export.d.ts +16 -0
- package/hosts/web/export.js +16 -0
- package/hosts/web/head.d.ts +10 -0
- package/hosts/web/head.js +65 -0
- package/hosts/web/mod.d.ts +33 -1
- package/hosts/web/mod.js +39 -1
- package/hosts/web/pt-br/toolkit.js +55 -0
- package/hosts/web/route-page.d.ts +53 -0
- package/hosts/web/route-page.js +83 -0
- package/hosts/web/server.d.ts +1 -0
- package/hosts/web/server.js +2 -59
- package/hosts/web/style.d.ts +13 -5
- package/hosts/web/style.js +23 -4
- package/hosts/web/table-address.d.ts +31 -0
- package/hosts/web/table-address.js +71 -0
- package/hosts/web/theme/css.d.ts +5 -4
- package/hosts/web/theme/css.js +6 -4
- package/hosts/web/theme/default.d.ts +5 -0
- package/hosts/web/theme/default.js +12 -0
- package/hosts/web/theme/icon.js +1 -1
- package/hosts/web/theme/picture.d.ts +5 -1
- package/hosts/web/theme/picture.js +6 -2
- package/hosts/web/toolkit/anchor.d.ts +2 -2
- package/hosts/web/toolkit/anchor.js +6 -4
- package/hosts/web/toolkit/app-bar.d.ts +55 -0
- package/hosts/web/toolkit/app-bar.js +109 -0
- package/hosts/web/toolkit/autocomplete.d.ts +10 -2
- package/hosts/web/toolkit/autocomplete.js +22 -12
- package/hosts/web/toolkit/badge.d.ts +3 -1
- package/hosts/web/toolkit/badge.js +4 -3
- package/hosts/web/toolkit/barcode.d.ts +29 -0
- package/hosts/web/toolkit/barcode.js +22 -0
- package/hosts/web/toolkit/button.d.ts +19 -9
- package/hosts/web/toolkit/button.js +57 -31
- package/hosts/web/toolkit/calendar.d.ts +56 -0
- package/hosts/web/toolkit/calendar.js +199 -0
- package/hosts/web/toolkit/card.d.ts +22 -2
- package/hosts/web/toolkit/card.js +23 -7
- package/hosts/web/toolkit/checkbox.d.ts +3 -1
- package/hosts/web/toolkit/checkbox.js +7 -5
- package/hosts/web/toolkit/chip.js +3 -3
- package/hosts/web/toolkit/code128.d.ts +44 -0
- package/hosts/web/toolkit/code128.js +212 -0
- package/hosts/web/toolkit/data-table.d.ts +92 -0
- package/hosts/web/toolkit/data-table.js +268 -0
- package/hosts/web/toolkit/date-picker.d.ts +88 -0
- package/hosts/web/toolkit/date-picker.js +173 -0
- package/hosts/web/toolkit/date-time-picker.d.ts +66 -0
- package/hosts/web/toolkit/date-time-picker.js +164 -0
- package/hosts/web/toolkit/dates.d.ts +132 -0
- package/hosts/web/toolkit/dates.js +348 -0
- package/hosts/web/toolkit/detail-list.js +6 -4
- package/hosts/web/toolkit/dialog.d.ts +13 -2
- package/hosts/web/toolkit/dialog.js +34 -16
- package/hosts/web/toolkit/drawer.js +1 -1
- package/hosts/web/toolkit/empty-state.js +5 -4
- package/hosts/web/toolkit/export.d.ts +72 -0
- package/hosts/web/toolkit/export.js +185 -0
- package/hosts/web/toolkit/field.d.ts +25 -3
- package/hosts/web/toolkit/field.js +57 -14
- package/hosts/web/toolkit/file-input.d.ts +40 -0
- package/hosts/web/toolkit/file-input.js +124 -0
- package/hosts/web/toolkit/files.d.ts +20 -0
- package/hosts/web/toolkit/files.js +31 -0
- package/hosts/web/toolkit/form-submit.d.ts +29 -0
- package/hosts/web/toolkit/form-submit.js +38 -0
- package/hosts/web/toolkit/form.d.ts +65 -0
- package/hosts/web/toolkit/form.js +94 -0
- package/hosts/web/toolkit/grid.d.ts +44 -0
- package/hosts/web/toolkit/grid.js +66 -0
- package/hosts/web/toolkit/icon-button.d.ts +5 -3
- package/hosts/web/toolkit/icon-button.js +16 -11
- package/hosts/web/toolkit/icon.d.ts +31 -3
- package/hosts/web/toolkit/icon.js +37 -3
- package/hosts/web/toolkit/input.d.ts +25 -7
- package/hosts/web/toolkit/input.js +70 -24
- package/hosts/web/toolkit/list-group.d.ts +47 -0
- package/hosts/web/toolkit/list-group.js +51 -0
- package/hosts/web/toolkit/live-clock.d.ts +31 -0
- package/hosts/web/toolkit/live-clock.js +55 -0
- package/hosts/web/toolkit/logo.js +1 -1
- package/hosts/web/toolkit/menu.d.ts +13 -5
- package/hosts/web/toolkit/menu.js +24 -12
- package/hosts/web/toolkit/modal.d.ts +6 -3
- package/hosts/web/toolkit/modal.js +8 -4
- package/hosts/web/toolkit/nav-item.d.ts +2 -2
- package/hosts/web/toolkit/nav-item.js +2 -2
- package/hosts/web/toolkit/notice.d.ts +5 -3
- package/hosts/web/toolkit/notice.js +5 -4
- package/hosts/web/toolkit/page.js +9 -7
- package/hosts/web/toolkit/pagination.d.ts +23 -0
- package/hosts/web/toolkit/pagination.js +55 -0
- package/hosts/web/toolkit/pdf.d.ts +81 -0
- package/hosts/web/toolkit/pdf.js +392 -0
- package/hosts/web/toolkit/picker.d.ts +59 -0
- package/hosts/web/toolkit/picker.js +150 -0
- package/hosts/web/toolkit/popover.d.ts +4 -0
- package/hosts/web/toolkit/popover.js +10 -7
- package/hosts/web/toolkit/print.d.ts +31 -0
- package/hosts/web/toolkit/print.js +28 -0
- package/hosts/web/toolkit/radio.d.ts +18 -0
- package/hosts/web/toolkit/radio.js +23 -0
- package/hosts/web/toolkit/rail-item.d.ts +2 -2
- package/hosts/web/toolkit/rail-item.js +2 -2
- package/hosts/web/toolkit/rows-editor.d.ts +53 -0
- package/hosts/web/toolkit/rows-editor.js +120 -0
- package/hosts/web/toolkit/rows.d.ts +36 -0
- package/hosts/web/toolkit/rows.js +66 -0
- package/hosts/web/toolkit/select.d.ts +3 -1
- package/hosts/web/toolkit/select.js +20 -8
- package/hosts/web/toolkit/sheet.d.ts +5 -2
- package/hosts/web/toolkit/sheet.js +1 -1
- package/hosts/web/toolkit/shortcuts.d.ts +72 -0
- package/hosts/web/toolkit/shortcuts.js +195 -0
- package/hosts/web/toolkit/space.d.ts +6 -0
- package/hosts/web/toolkit/space.js +21 -0
- package/hosts/web/toolkit/split.d.ts +31 -0
- package/hosts/web/toolkit/split.js +25 -0
- package/hosts/web/toolkit/stack.d.ts +48 -0
- package/hosts/web/toolkit/stack.js +61 -0
- package/hosts/web/toolkit/switch.d.ts +30 -0
- package/hosts/web/toolkit/switch.js +41 -0
- package/hosts/web/toolkit/table.d.ts +102 -0
- package/hosts/web/toolkit/table.js +102 -0
- package/hosts/web/toolkit/tabs.d.ts +12 -4
- package/hosts/web/toolkit/tabs.js +32 -15
- package/hosts/web/toolkit/tags-input.d.ts +25 -0
- package/hosts/web/toolkit/tags-input.js +90 -0
- package/hosts/web/toolkit/tags.d.ts +10 -0
- package/hosts/web/toolkit/tags.js +18 -0
- package/hosts/web/toolkit/text.d.ts +36 -0
- package/hosts/web/toolkit/text.js +55 -0
- package/hosts/web/toolkit/textarea.js +14 -5
- package/hosts/web/toolkit/tile-grid.d.ts +31 -0
- package/hosts/web/toolkit/tile-grid.js +43 -0
- package/hosts/web/toolkit/toast-state.d.ts +49 -0
- package/hosts/web/toolkit/toast-state.js +84 -0
- package/hosts/web/toolkit/toast.d.ts +30 -0
- package/hosts/web/toolkit/toast.js +117 -0
- package/hosts/web/toolkit/toolbar.d.ts +26 -0
- package/hosts/web/toolkit/toolbar.js +17 -0
- package/hosts/web/toolkit/tooltip.d.ts +4 -2
- package/hosts/web/toolkit/tooltip.js +7 -4
- package/hosts/web/toolkit/words.d.ts +1 -1
- package/hosts/web/toolkit/words.js +66 -0
- package/hosts/web/toolkit/zip.d.ts +18 -0
- package/hosts/web/toolkit/zip.js +91 -0
- package/package.json +5 -1
- package/plugins/access/spaces/views/web/words.d.ts +1 -1
- package/plugins/agents/chat/collections/file.d.ts +1 -1
- package/plugins/agents/chat/collections/thread.d.ts +1 -1
- package/plugins/agents/chat/views/web/words.d.ts +1 -1
- package/plugins/billing/usage/views/web/words.d.ts +1 -1
- package/plugins/compute/computers/program/version.d.ts +1 -1
- package/plugins/compute/computers/program/version.js +1 -1
- package/plugins/compute/computers/program/workloads/search.d.ts +1 -1
- package/plugins/compute/computers/resources/downloads.js +1 -1
- package/plugins/interfaces/web/shared/style.d.ts +2 -2
- package/plugins/interfaces/web/shared/style.js +9 -1
- package/plugins/interfaces/web/views/frame.js +2 -2
- package/runtime/observe.js +14 -1
package/AGENTS.md
CHANGED
|
@@ -4,7 +4,7 @@ A guide for coding agents (Claude Code, Codex, Cursor, Gemini) building an app w
|
|
|
4
4
|
it whole before you write code. The last section is for work on Copilotz itself.
|
|
5
5
|
|
|
6
6
|
It ships in the package (`node_modules/copilotz/AGENTS.md`, and `@copilotz/copilotz` on JSR) and
|
|
7
|
-
goes with `copilotz@1.0.0-rc.
|
|
7
|
+
goes with `copilotz@1.0.0-rc.52`. Every docs page is Markdown at
|
|
8
8
|
`https://copilotz.com/docs/<slug>.md`, and https://copilotz.com/llms.txt lists them all. When you're
|
|
9
9
|
unsure of a name, fetch its page or read the package's types (`node_modules/copilotz/**/*.d.ts`).
|
|
10
10
|
Don't guess.
|
|
@@ -64,12 +64,12 @@ There's no project generator. Set a project up as the docs' courses do, on Node
|
|
|
64
64
|
```sh
|
|
65
65
|
mkdir my-app && cd my-app
|
|
66
66
|
npm init -y && npm pkg set type=module
|
|
67
|
-
npm install copilotz@1.0.0-rc.
|
|
67
|
+
npm install copilotz@1.0.0-rc.52 react@19 react-dom@19
|
|
68
68
|
npm install -D typescript @types/node @types/react @types/react-dom esbuild
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Pin the version: npm's `latest` tag still points at an early release candidate. On Deno, run
|
|
72
|
-
`deno add jsr:@copilotz/copilotz` and map `"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.
|
|
72
|
+
`deno add jsr:@copilotz/copilotz` and map `"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.52"` in
|
|
73
73
|
`deno.json`, so imports read the same.
|
|
74
74
|
|
|
75
75
|
Node runs `.ts` files as they are, so there's no build step. It doesn't run `.tsx`: tests that load
|
|
@@ -108,7 +108,7 @@ line `@AGENTS.md` (Claude Code reads `CLAUDE.md`, and follows the import). Keep
|
|
|
108
108
|
```markdown
|
|
109
109
|
# AGENTS.md
|
|
110
110
|
|
|
111
|
-
This app runs on Copilotz (copilotz@1.0.0-rc.
|
|
111
|
+
This app runs on Copilotz (copilotz@1.0.0-rc.52). Read node_modules/copilotz/AGENTS.md first;
|
|
112
112
|
https://copilotz.com/llms.txt lists the docs, as Markdown.
|
|
113
113
|
|
|
114
114
|
- `npm test` runs every test offline, with a scripted model: run it after each change.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
+
## 1.0.0-rc.52 — 2026-11-16
|
|
2
|
+
|
|
3
|
+
The web toolkit becomes a whole app's: what rebuilding a point of sale on Copilotz asked of it, in
|
|
4
|
+
Copilotz's own look. A screen is made of the toolkit's pieces and writes no CSS. Its look is the
|
|
5
|
+
app's theme, down to each piece's sizes. [The web toolkit](docs/guides/the-web-toolkit.md) is the
|
|
6
|
+
new guide to all of it.
|
|
7
|
+
|
|
8
|
+
**Breaking, in small ways:**
|
|
9
|
+
|
|
10
|
+
- **`Card`'s `title` is its heading** (a node), no longer the HTML attribute. No caller passed one.
|
|
11
|
+
- **The popover's width variable is `--popover-width`**, a token like any other (it was
|
|
12
|
+
`--copilotz-popover-width`).
|
|
13
|
+
- **A small `Select` is 36px tall**, as a small `Input` is, so fields side by side line up (it was
|
|
14
|
+
34px).
|
|
15
|
+
- **`ctx.show` after a View returned throws**, saying to show the View in the View's body or with
|
|
16
|
+
`LazyView`. A component that rendered later and called it got a part that never loaded.
|
|
17
|
+
- **An `Input` with an addon** puts its `className` on the group.
|
|
18
|
+
|
|
19
|
+
**A look from the theme alone:**
|
|
20
|
+
|
|
21
|
+
- **`theme.tokens`**: tokens the same on light and dark screens (sizes, paddings, radii, weights),
|
|
22
|
+
merged token by token as `light` and `dark` are.
|
|
23
|
+
- **Every piece's look is tokens**: its sizes, paddings, radii, fonts and own colours
|
|
24
|
+
(`button-height`, `table-stripe`, `dialog-head-background`…), each with Copilotz's value as its
|
|
25
|
+
default. The guide lists all 546, and a test keeps the list whole. `className` stays as an escape
|
|
26
|
+
hatch.
|
|
27
|
+
- **The toolkit's styles stay over the page's base** wherever React puts them in the page (a page
|
|
28
|
+
served without the web host had its buttons' text in the base's colour).
|
|
29
|
+
|
|
30
|
+
**Laying a screen out:** `Stack` (with `Spacer` and `Divider`), `Grid` and `GridItem`, `Toolbar`,
|
|
31
|
+
`Split` (a main column beside an aside that stays in view: a register's cart and its summary),
|
|
32
|
+
`ListGroup`, `Text` and `Heading`, on one spacing scale (`space-xs` to `space-2xl`). `Card` takes a
|
|
33
|
+
heading: `title`, `icon`, `action`. Grids and splits stack by their own width, not the window's.
|
|
34
|
+
|
|
35
|
+
**Forms:**
|
|
36
|
+
|
|
37
|
+
- **`Button`**: `success`, `info` and `warning` variants, an `xs` size, and `block`.
|
|
38
|
+
- **`Input`**: `addon` and `addonEnd`, segments joined outside the box (words, an icon, a button, a
|
|
39
|
+
switch).
|
|
40
|
+
- **`Field`**: `required`, a control as its child with `htmlFor`, and `layout="row"`, the label in a
|
|
41
|
+
column beside its control, aligned on its text.
|
|
42
|
+
- **New**: `Radio`; `Switch`, with words on and off if wanted; `TagsInput`; `Picker` and
|
|
43
|
+
`MultiPicker`, a choice the app draws, with `search` for a long list; `FileInput`, the browser's
|
|
44
|
+
file field drawn as the toolkit's, files dropped on it too; `RowsEditor`, a list of records edited
|
|
45
|
+
as one form, a row of fields each.
|
|
46
|
+
- **`Form` with parts**: each part joins its save with `useFormSubmit`, another plugin's View shown
|
|
47
|
+
inside it too, handing values up or stopping the save with its reason.
|
|
48
|
+
- **`Dialog`**: `placement="top"`, and `focus="dialog"` not to focus its first field.
|
|
49
|
+
- `className` on `Menu` and `Autocomplete`, `justified` tabs, and tooltips at the `start` side.
|
|
50
|
+
|
|
51
|
+
**Tables:** `DataTable` lists rows with a toolbar (the screen's actions, a search box that folds
|
|
52
|
+
case and accents, a column chooser, an export menu), headers that sort, rows to tick, details under
|
|
53
|
+
a row, and pages. It pages rows it's given, or shows a page its View asked for, with the state kept
|
|
54
|
+
in the address (`tableAddress(where, 25)`, `tableState`, `tableQuery`). `Pagination` stands on its
|
|
55
|
+
own. Its files: CSV (with a BOM, and guarded against formulas), a real `.xlsx`, PDF, JSON, XML, TXT,
|
|
56
|
+
SQL and the HTML `.xls`, with no dependency; `exportFile` makes them on a server too.
|
|
57
|
+
|
|
58
|
+
**Dates:** `DateRangePicker` (presets beside two months), `DatePicker` and `Calendar`, a keyboard
|
|
59
|
+
grid. Days are `YYYY-MM-DD` in the app's time zone (`todayIn`), in the app's format (a pattern or a
|
|
60
|
+
function), with month and weekday names in the page's language. `rangePresets` builds the presets by
|
|
61
|
+
key, a fiscal year's included. `DateTimePicker` picks a day and a time of it. `LiveClock` shows the
|
|
62
|
+
time now in a format and a time zone.
|
|
63
|
+
|
|
64
|
+
**An app's own bars:** `AppBar` (the brand, the places with their icons, the current one marked),
|
|
65
|
+
`TopBar` (a thin strip: a clock, the company, the person), and `TileGrid`, a home page's places.
|
|
66
|
+
**`toast()`** says a few seconds' word over the page from anywhere; the shell shows them, and an app
|
|
67
|
+
without it renders `<Toasts />`.
|
|
68
|
+
|
|
69
|
+
**Icons:** every piece that takes an icon takes an app's own too: `<Icon drawing={…} />` (its paths,
|
|
70
|
+
`rule: "evenodd"` for glyphs drawn that way) or `<Icon src="…" />`.
|
|
71
|
+
|
|
72
|
+
**Shortcuts and printing:** `useShortcuts` binds keys to a screen's commands, waiting while a dialog
|
|
73
|
+
is open or someone types; `shortcutLabel` says them. A printed page leaves out the shell's frame and
|
|
74
|
+
what only works on a screen (bars, toolbars, toasts, buttons); `NoPrint` and `PrintOnly` mark an
|
|
75
|
+
app's own parts.
|
|
76
|
+
|
|
77
|
+
**Documents:** `documentPdf` draws a document as a PDF (text, lines, rectangles, barcodes; A4,
|
|
78
|
+
letter, or a receipt's width) on a server too, and `Barcode` draws Code 128.
|
|
79
|
+
**`copilotz/web/export`** has the toolkit's files without React: the tables' formats, `documentPdf`,
|
|
80
|
+
and Code 128's bars.
|
|
81
|
+
|
|
82
|
+
**A route's own page:** `routePage(runtime, { title, body })`, from `copilotz/web/server`, answers a
|
|
83
|
+
page made with the toolkit, in the app's theme and words: an import screen before anyone signs in, a
|
|
84
|
+
password reset.
|
|
85
|
+
|
|
86
|
+
**Words:** the new pieces' words are the app's to change (`toolkit.*`), and Brazilian Portuguese
|
|
87
|
+
says them all.
|
|
88
|
+
|
|
1
89
|
## 1.0.0-rc.51 — 2026-11-16
|
|
2
90
|
|
|
3
91
|
**Phones.**
|
package/README.md
CHANGED
|
@@ -152,7 +152,7 @@ ana sees: Tue 10:00, Wed 15:00
|
|
|
152
152
|
```sh
|
|
153
153
|
npm install copilotz@next # Node 24+ (npm, pnpm, yarn)
|
|
154
154
|
bun add copilotz@next # Bun
|
|
155
|
-
deno add jsr:@copilotz/copilotz@^1.0.0-rc.
|
|
155
|
+
deno add jsr:@copilotz/copilotz@^1.0.0-rc.52 # Deno 2.9+ (or `deno add npm:copilotz@next`)
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Until 1.0, the release candidates are on npm's `next` tag, and a plain `npm install copilotz` or
|
|
@@ -166,7 +166,7 @@ OPENAI_API_KEY=sk-… node salon.ts # or bun salon.ts, or deno run -A salon.t
|
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
On Deno, map the name `copilotz` in `deno.json`
|
|
169
|
-
(`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.
|
|
169
|
+
(`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.52"`) so the imports read the same everywhere.
|
|
170
170
|
Copilotz runs on Node 24+, Deno 2.9+ and Bun, and it's built on web standards for Cloudflare Workers
|
|
171
171
|
and the browser.
|
|
172
172
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web toolkit's files, without React or a page: on a server too. A table
|
|
3
|
+
* as CSV, a workbook (`.xlsx`), a PDF, JSON, XML, TXT or SQL (`exportFile`);
|
|
4
|
+
* a document drawn as a PDF (`documentPdf`: a receipt, an invoice); and Code
|
|
5
|
+
* 128's bars (`bars`), for an e-mailed invoice or a receipt made where no
|
|
6
|
+
* browser is. In a page, `copilotz/web` has the same, and `download` saves a
|
|
7
|
+
* file.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { documentPdf, exportFile } from "copilotz/web/export";
|
|
11
|
+
* const { file, type, content } = exportFile("xlsx", { headers: ["Item", "Price"], rows: [["Café", 4.5]] }, "items");
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export { EXPORT_FORMATS, exportFile, type ExportFormat, type ExportOptions, type Sheet, toCsv, toExcel, toJson, toPdf, toSql, toXlsx, toXml, } from "./toolkit/export.js";
|
|
15
|
+
export { documentPdf, type Drawn, type PageSize, type PdfFont, type PdfOptions, tablePdf, textWidth, wrapText, } from "./toolkit/pdf.js";
|
|
16
|
+
export { bars, code128 } from "./toolkit/code128.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web toolkit's files, without React or a page: on a server too. A table
|
|
3
|
+
* as CSV, a workbook (`.xlsx`), a PDF, JSON, XML, TXT or SQL (`exportFile`);
|
|
4
|
+
* a document drawn as a PDF (`documentPdf`: a receipt, an invoice); and Code
|
|
5
|
+
* 128's bars (`bars`), for an e-mailed invoice or a receipt made where no
|
|
6
|
+
* browser is. In a page, `copilotz/web` has the same, and `download` saves a
|
|
7
|
+
* file.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { documentPdf, exportFile } from "copilotz/web/export";
|
|
11
|
+
* const { file, type, content } = exportFile("xlsx", { headers: ["Item", "Price"], rows: [["Café", 4.5]] }, "items");
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export { EXPORT_FORMATS, exportFile, toCsv, toExcel, toJson, toPdf, toSql, toXlsx, toXml, } from "./toolkit/export.js";
|
|
15
|
+
export { documentPdf, tablePdf, textWidth, wrapText, } from "./toolkit/pdf.js";
|
|
16
|
+
export { bars, code128 } from "./toolkit/code128.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Theme } from "./theme/default.js";
|
|
2
|
+
/**
|
|
3
|
+
* The theme in the page's head: its variables and the page's base (the host
|
|
4
|
+
* replaces them), its icons and colour, and its fonts: the stylesheet and
|
|
5
|
+
* the files it preloads, fetched now (Google's connected to early) and
|
|
6
|
+
* applied by the host, so the first paint never waits on them.
|
|
7
|
+
*/
|
|
8
|
+
export declare const look: (theme: Theme | undefined) => string;
|
|
9
|
+
/** Text that can't end the attribute it goes in. */
|
|
10
|
+
export declare const quoted: (text: string) => string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The head of a page the server makes: the app's theme in it (its
|
|
3
|
+
* variables and the page's base, its icons and colour, its fonts), shared by
|
|
4
|
+
* the app's page (`webPage`, server.ts) and a route's own (route-page.ts).
|
|
5
|
+
*/
|
|
6
|
+
import { BASE } from "./style.js";
|
|
7
|
+
import { fontsOf, fromGoogle, plainColour, preloadsOf, themeCss } from "./theme/css.js";
|
|
8
|
+
import { HOST_ASSETS } from "./theme/files/mod.js";
|
|
9
|
+
import { ownPath } from "./theme/own-path.js";
|
|
10
|
+
import { pictureOf } from "./theme/picture.js";
|
|
11
|
+
/** The page's icons: the mark (as the host draws it, or the image it is) and the theme's PNG. */
|
|
12
|
+
const icons = (theme) => {
|
|
13
|
+
const mark = pictureOf(theme.logo?.mark);
|
|
14
|
+
const png = ownPath(theme.logo?.icon);
|
|
15
|
+
return [
|
|
16
|
+
...(png ? [`<link rel="icon" href="${png}" type="image/png" sizes="180x180">`] : []),
|
|
17
|
+
...(typeof mark === "string"
|
|
18
|
+
? [`<link rel="icon" href="${mark}">`]
|
|
19
|
+
: mark
|
|
20
|
+
? [`<link rel="icon" href="${HOST_ASSETS}icon.svg" type="image/svg+xml">`]
|
|
21
|
+
: []),
|
|
22
|
+
...(png ? [`<link rel="apple-touch-icon" href="${png}">`] : []),
|
|
23
|
+
];
|
|
24
|
+
};
|
|
25
|
+
/** The browser's colour around the page: each scheme's background, when it's a plain colour. */
|
|
26
|
+
const colours = (theme, dark) => {
|
|
27
|
+
const light = plainColour(theme.light?.background);
|
|
28
|
+
const night = dark ? plainColour(theme.dark?.background) : undefined;
|
|
29
|
+
if (!night)
|
|
30
|
+
return light ? [`<meta name="theme-color" content="${light}">`] : [];
|
|
31
|
+
return [
|
|
32
|
+
...(light
|
|
33
|
+
? [`<meta name="theme-color" content="${light}" media="(prefers-color-scheme: light)">`]
|
|
34
|
+
: []),
|
|
35
|
+
`<meta name="theme-color" content="${night}" media="(prefers-color-scheme: dark)">`,
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The theme in the page's head: its variables and the page's base (the host
|
|
40
|
+
* replaces them), its icons and colour, and its fonts: the stylesheet and
|
|
41
|
+
* the files it preloads, fetched now (Google's connected to early) and
|
|
42
|
+
* applied by the host, so the first paint never waits on them.
|
|
43
|
+
*/
|
|
44
|
+
export const look = (theme) => {
|
|
45
|
+
if (!theme)
|
|
46
|
+
return "";
|
|
47
|
+
const fonts = fontsOf(theme);
|
|
48
|
+
const css = `${themeCss(theme)}\n${BASE}`.replaceAll("<", "\\3c ");
|
|
49
|
+
const dark = Object.values(theme.dark ?? {}).some((value) => value !== null);
|
|
50
|
+
return [
|
|
51
|
+
`<meta name="color-scheme" content="${dark ? "light dark" : "light"}">`,
|
|
52
|
+
...colours(theme, dark),
|
|
53
|
+
...icons(theme),
|
|
54
|
+
`<style id="copilotz-first-paint">${css}</style>`,
|
|
55
|
+
...(fonts && fromGoogle(fonts)
|
|
56
|
+
? ['<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>']
|
|
57
|
+
: []),
|
|
58
|
+
...(fonts ? [`<link rel="preload" href="${fonts}" as="style">`] : []),
|
|
59
|
+
...preloadsOf(theme).map(({ href, type }) => `<link rel="preload" href="${href}" as="font" type="${type}" crossorigin>`),
|
|
60
|
+
"",
|
|
61
|
+
].join("\n");
|
|
62
|
+
};
|
|
63
|
+
/** Text that can't end the attribute it goes in. */
|
|
64
|
+
export const quoted = (text) => text.replaceAll("&", "&").replaceAll('"', """)
|
|
65
|
+
.replaceAll("<", "<");
|
package/hosts/web/mod.d.ts
CHANGED
|
@@ -29,12 +29,19 @@ export { Textarea } from "./toolkit/textarea.js";
|
|
|
29
29
|
export { type Control, Field } from "./toolkit/field.js";
|
|
30
30
|
export { Select } from "./toolkit/select.js";
|
|
31
31
|
export { Checkbox } from "./toolkit/checkbox.js";
|
|
32
|
+
export { Radio } from "./toolkit/radio.js";
|
|
33
|
+
export { Switch } from "./toolkit/switch.js";
|
|
34
|
+
export { TagsInput } from "./toolkit/tags-input.js";
|
|
35
|
+
export { MultiPicker, Picker, type PickerOption } from "./toolkit/picker.js";
|
|
36
|
+
export { FileInput } from "./toolkit/file-input.js";
|
|
37
|
+
export { RowsEditor } from "./toolkit/rows-editor.js";
|
|
38
|
+
export { Form, type PartAnswer, type PartSubmit, useFormState, useFormSubmit, } from "./toolkit/form.js";
|
|
32
39
|
export { Autocomplete, type AutocompleteOption, optionId } from "./toolkit/autocomplete.js";
|
|
33
40
|
export { Card } from "./toolkit/card.js";
|
|
34
41
|
export { Badge, type Tone } from "./toolkit/badge.js";
|
|
35
42
|
export { Chip } from "./toolkit/chip.js";
|
|
36
43
|
export { Avatar } from "./toolkit/avatar.js";
|
|
37
|
-
export { Icon, type IconName, ICONS } from "./toolkit/icon.js";
|
|
44
|
+
export { Icon, type IconLike, type IconName, iconOf, ICONS } from "./toolkit/icon.js";
|
|
38
45
|
export { Logo } from "./toolkit/logo.js";
|
|
39
46
|
export { Menu, type MenuItem, type MenuTrigger } from "./toolkit/menu.js";
|
|
40
47
|
export { Popover, type PopoverTrigger } from "./toolkit/popover.js";
|
|
@@ -45,6 +52,31 @@ export { NavItem } from "./toolkit/nav-item.js";
|
|
|
45
52
|
export { RailItem, type RailItemProps } from "./toolkit/rail-item.js";
|
|
46
53
|
export { ResizeHandle } from "./toolkit/resize-handle.js";
|
|
47
54
|
export { Tooltip } from "./toolkit/tooltip.js";
|
|
55
|
+
export { type Space } from "./toolkit/space.js";
|
|
56
|
+
export { type Align, Divider, type Justify, Spacer, Stack } from "./toolkit/stack.js";
|
|
57
|
+
export { Grid, GridItem } from "./toolkit/grid.js";
|
|
58
|
+
export { Toolbar } from "./toolkit/toolbar.js";
|
|
59
|
+
export { Split } from "./toolkit/split.js";
|
|
60
|
+
export { ListGroup, type ListGroupItem } from "./toolkit/list-group.js";
|
|
61
|
+
export { Heading, Text, type TextTone } from "./toolkit/text.js";
|
|
62
|
+
export { AppBar, type AppBarItem, TopBar } from "./toolkit/app-bar.js";
|
|
63
|
+
export { type Tile, TileGrid } from "./toolkit/tile-grid.js";
|
|
64
|
+
export { DataTable, type ExportChoice } from "./toolkit/data-table.js";
|
|
65
|
+
export { Pagination } from "./toolkit/pagination.js";
|
|
66
|
+
export { type Column, type Key as RowKey, PAGE_SIZES, type TableState, tableView, } from "./toolkit/table.js";
|
|
67
|
+
export { tableAddress, tableQuery, tableState } from "./table-address.js";
|
|
68
|
+
export { download, EXPORT_FORMATS, exportFile, type ExportFormat, type ExportOptions, type Sheet, toCsv, toExcel, toJson, toPdf, toSql, toXlsx, toXml, } from "./toolkit/export.js";
|
|
69
|
+
export { documentPdf, type Drawn, type PageSize, type PdfFont, type PdfOptions, tablePdf, textWidth, wrapText, } from "./toolkit/pdf.js";
|
|
70
|
+
export { Calendar, type CalendarValue, type DayFormat, formatDay } from "./toolkit/calendar.js";
|
|
71
|
+
export { DatePicker, DateRangePicker, type RangePreset, rangePresets, STANDARD_PRESETS, } from "./toolkit/date-picker.js";
|
|
72
|
+
export { addDays, addMonths, clampDayTime, type DateRange, type DayTime, formatPattern, isDay, isDayTime, nowIn, type Preset, presetRange, todayIn, } from "./toolkit/dates.js";
|
|
73
|
+
export { DateTimePicker, type DayTimeFormat, formatDayTime } from "./toolkit/date-time-picker.js";
|
|
74
|
+
export { LiveClock } from "./toolkit/live-clock.js";
|
|
75
|
+
export { dismissToast, toast, type ToastOptions, type ToastPlacement, Toasts, type ToastTone, } from "./toolkit/toast.js";
|
|
76
|
+
export { type Binding, shortcutLabel, useShortcuts } from "./toolkit/shortcuts.js";
|
|
77
|
+
export { NoPrint, PrintOnly } from "./toolkit/print.js";
|
|
78
|
+
export { Barcode } from "./toolkit/barcode.js";
|
|
79
|
+
export { bars, code128 } from "./toolkit/code128.js";
|
|
48
80
|
export { Page } from "./toolkit/page.js";
|
|
49
81
|
export { type Detail, DetailList } from "./toolkit/detail-list.js";
|
|
50
82
|
export { DetailValue } from "./toolkit/detail-value.js";
|
package/hosts/web/mod.js
CHANGED
|
@@ -35,13 +35,21 @@ export { Textarea } from "./toolkit/textarea.js";
|
|
|
35
35
|
export { Field } from "./toolkit/field.js";
|
|
36
36
|
export { Select } from "./toolkit/select.js";
|
|
37
37
|
export { Checkbox } from "./toolkit/checkbox.js";
|
|
38
|
+
export { Radio } from "./toolkit/radio.js";
|
|
39
|
+
export { Switch } from "./toolkit/switch.js";
|
|
40
|
+
export { TagsInput } from "./toolkit/tags-input.js";
|
|
41
|
+
export { MultiPicker, Picker } from "./toolkit/picker.js";
|
|
42
|
+
export { FileInput } from "./toolkit/file-input.js";
|
|
43
|
+
export { RowsEditor } from "./toolkit/rows-editor.js";
|
|
44
|
+
// Forms whose parts (another plugin's View too) take part in one save.
|
|
45
|
+
export { Form, useFormState, useFormSubmit, } from "./toolkit/form.js";
|
|
38
46
|
export { Autocomplete, optionId } from "./toolkit/autocomplete.js";
|
|
39
47
|
// Surfaces and labels.
|
|
40
48
|
export { Card } from "./toolkit/card.js";
|
|
41
49
|
export { Badge } from "./toolkit/badge.js";
|
|
42
50
|
export { Chip } from "./toolkit/chip.js";
|
|
43
51
|
export { Avatar } from "./toolkit/avatar.js";
|
|
44
|
-
export { Icon, ICONS } from "./toolkit/icon.js";
|
|
52
|
+
export { Icon, iconOf, ICONS } from "./toolkit/icon.js";
|
|
45
53
|
export { Logo } from "./toolkit/logo.js";
|
|
46
54
|
// Overlays and navigation.
|
|
47
55
|
export { Menu } from "./toolkit/menu.js";
|
|
@@ -53,6 +61,36 @@ export { NavItem } from "./toolkit/nav-item.js";
|
|
|
53
61
|
export { RailItem } from "./toolkit/rail-item.js";
|
|
54
62
|
export { ResizeHandle } from "./toolkit/resize-handle.js";
|
|
55
63
|
export { Tooltip } from "./toolkit/tooltip.js";
|
|
64
|
+
export { Divider, Spacer, Stack } from "./toolkit/stack.js";
|
|
65
|
+
export { Grid, GridItem } from "./toolkit/grid.js";
|
|
66
|
+
export { Toolbar } from "./toolkit/toolbar.js";
|
|
67
|
+
export { Split } from "./toolkit/split.js";
|
|
68
|
+
export { ListGroup } from "./toolkit/list-group.js";
|
|
69
|
+
export { Heading, Text } from "./toolkit/text.js";
|
|
70
|
+
// An app's own bars and home, without the Copilotz shell.
|
|
71
|
+
export { AppBar, TopBar } from "./toolkit/app-bar.js";
|
|
72
|
+
export { TileGrid } from "./toolkit/tile-grid.js";
|
|
73
|
+
// Tables: rows to read, find and act on, their pages, and their files.
|
|
74
|
+
export { DataTable } from "./toolkit/data-table.js";
|
|
75
|
+
export { Pagination } from "./toolkit/pagination.js";
|
|
76
|
+
export { PAGE_SIZES, tableView, } from "./toolkit/table.js";
|
|
77
|
+
export { tableAddress, tableQuery, tableState } from "./table-address.js";
|
|
78
|
+
export { download, EXPORT_FORMATS, exportFile, toCsv, toExcel, toJson, toPdf, toSql, toXlsx, toXml, } from "./toolkit/export.js";
|
|
79
|
+
export { documentPdf, tablePdf, textWidth, wrapText, } from "./toolkit/pdf.js";
|
|
80
|
+
// Dates: days as `YYYY-MM-DD`, in the app's format and time zone.
|
|
81
|
+
export { Calendar, formatDay } from "./toolkit/calendar.js";
|
|
82
|
+
export { DatePicker, DateRangePicker, rangePresets, STANDARD_PRESETS, } from "./toolkit/date-picker.js";
|
|
83
|
+
export { addDays, addMonths, clampDayTime, formatPattern, isDay, isDayTime, nowIn, presetRange, todayIn, } from "./toolkit/dates.js";
|
|
84
|
+
export { DateTimePicker, formatDayTime } from "./toolkit/date-time-picker.js";
|
|
85
|
+
export { LiveClock } from "./toolkit/live-clock.js";
|
|
86
|
+
// Telling: a few seconds' word over the page.
|
|
87
|
+
export { dismissToast, toast, Toasts, } from "./toolkit/toast.js";
|
|
88
|
+
// A screen's keyboard shortcuts, and what a printed page leaves out.
|
|
89
|
+
export { shortcutLabel, useShortcuts } from "./toolkit/shortcuts.js";
|
|
90
|
+
export { NoPrint, PrintOnly } from "./toolkit/print.js";
|
|
91
|
+
// Barcodes: Code 128, drawn, and as bars for a document made elsewhere.
|
|
92
|
+
export { Barcode } from "./toolkit/barcode.js";
|
|
93
|
+
export { bars, code128 } from "./toolkit/code128.js";
|
|
56
94
|
// Pages and details.
|
|
57
95
|
export { Page } from "./toolkit/page.js";
|
|
58
96
|
export { DetailList } from "./toolkit/detail-list.js";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export const toolkit = {
|
|
2
|
+
"toolkit.addRow": "Adicionar uma linha",
|
|
3
|
+
"toolkit.addRowAfter": "Adicionar uma linha depois da linha {row}",
|
|
4
|
+
"toolkit.allTime": "Todo o período",
|
|
5
|
+
"toolkit.apply": "Aplicar",
|
|
2
6
|
"toolkit.audio": "Áudio",
|
|
3
7
|
"toolkit.audioFailed": "Não foi possível carregar: {label}. Tente de novo",
|
|
4
8
|
"toolkit.audioLabel": "{label}, {length}",
|
|
@@ -9,12 +13,25 @@ export const toolkit = {
|
|
|
9
13
|
"toolkit.audioPosition": "{label}: posição",
|
|
10
14
|
"toolkit.audioProgress": "{at} de {length}",
|
|
11
15
|
"toolkit.cancel": "Cancelar",
|
|
16
|
+
"toolkit.changeFile": "Trocar",
|
|
17
|
+
"toolkit.chooseDate": "Escolher uma data",
|
|
18
|
+
"toolkit.chooseDates": "Escolher as datas",
|
|
19
|
+
"toolkit.chooseDateTime": "Escolher data e hora",
|
|
20
|
+
"toolkit.chooseFile": "Escolher um arquivo",
|
|
21
|
+
"toolkit.chooseFiles": "Escolher arquivos",
|
|
22
|
+
"toolkit.chosen": { one: "{count} escolhido", other: "{count} escolhidos" },
|
|
12
23
|
"toolkit.close": "Fechar",
|
|
24
|
+
"toolkit.columns": "Colunas",
|
|
13
25
|
"toolkit.copied": "Copiado",
|
|
14
26
|
"toolkit.copy": "Copiar",
|
|
15
27
|
"toolkit.copyCode": "Copiar código",
|
|
16
28
|
"toolkit.copyId": "Copiar ID",
|
|
29
|
+
"toolkit.customRange": "Período personalizado",
|
|
17
30
|
"toolkit.done": "Concluído",
|
|
31
|
+
"toolkit.dropFiles": "Solte os arquivos aqui",
|
|
32
|
+
"toolkit.export": "Exportar",
|
|
33
|
+
"toolkit.files": { one: "{count} arquivo", other: "{count} arquivos" },
|
|
34
|
+
"toolkit.hideDetails": "Ocultar detalhes",
|
|
18
35
|
"toolkit.hoursAgo": { one: "há {count} hora", other: "há {count} horas" },
|
|
19
36
|
"toolkit.hoursShort": "{count} h",
|
|
20
37
|
"toolkit.inHours": { one: "em {count} hora", other: "em {count} horas" },
|
|
@@ -23,17 +40,49 @@ export const toolkit = {
|
|
|
23
40
|
"toolkit.inMinutesShort": "em {count} min",
|
|
24
41
|
"toolkit.items": { one: "{count} item", other: "{count} itens" },
|
|
25
42
|
"toolkit.justNow": "agora mesmo",
|
|
43
|
+
"toolkit.last30Days": "Últimos 30 dias",
|
|
44
|
+
"toolkit.last7Days": "Últimos 7 dias",
|
|
45
|
+
"toolkit.lastFiscalYear": "Ano fiscal passado",
|
|
46
|
+
"toolkit.lastMonth": "Mês passado",
|
|
47
|
+
"toolkit.lastYear": "Ano passado",
|
|
48
|
+
"toolkit.loadingRows": "Carregando…",
|
|
26
49
|
"toolkit.mathLoading": "Carregando a fórmula",
|
|
27
50
|
"toolkit.mathPending": "Ainda sendo escrita",
|
|
28
51
|
"toolkit.minutesAgo": { one: "há {count} minuto", other: "há {count} minutos" },
|
|
29
52
|
"toolkit.minutesShort": "{count} min",
|
|
53
|
+
"toolkit.navigation": "Navegação",
|
|
54
|
+
"toolkit.nextMonth": "Próximo mês",
|
|
55
|
+
"toolkit.nextPage": "Próxima página",
|
|
30
56
|
"toolkit.no": "Não",
|
|
57
|
+
"toolkit.noMatches": "Nada corresponde a “{text}”",
|
|
58
|
+
"toolkit.noneChosen": "Nenhum escolhido",
|
|
59
|
+
"toolkit.noRows": "Nada para mostrar",
|
|
60
|
+
"toolkit.notifications": "Notificações",
|
|
61
|
+
"toolkit.notSaved": "Não foi salvo. Tente de novo.",
|
|
31
62
|
"toolkit.now": "agora",
|
|
63
|
+
"toolkit.page": "Página {page}",
|
|
64
|
+
"toolkit.pages": "Páginas",
|
|
65
|
+
"toolkit.previousMonth": "Mês anterior",
|
|
66
|
+
"toolkit.previousPage": "Página anterior",
|
|
67
|
+
"toolkit.print": "Imprimir",
|
|
68
|
+
"toolkit.removeFile": "Remover",
|
|
69
|
+
"toolkit.removeRow": "Remover a linha {row}",
|
|
70
|
+
"toolkit.removeTag": "Remover {tag}",
|
|
71
|
+
"toolkit.required": "obrigatório",
|
|
72
|
+
"toolkit.row": "Linha {row}",
|
|
73
|
+
"toolkit.rowsPerPage": "{size} linhas por página",
|
|
74
|
+
"toolkit.sameMonthLastYear": "Este mês, no ano passado",
|
|
75
|
+
"toolkit.sameMonthToDateLastYear": "Este mês até hoje, no ano passado",
|
|
32
76
|
"toolkit.save": "Salvar",
|
|
77
|
+
"toolkit.search": "Buscar",
|
|
78
|
+
"toolkit.selectAll": "Selecionar todas as linhas",
|
|
79
|
+
"toolkit.selectRow": "Selecionar esta linha",
|
|
80
|
+
"toolkit.showDetails": "Mostrar detalhes",
|
|
33
81
|
"toolkit.showEarlierLines": {
|
|
34
82
|
one: "Mostrar {count} linha anterior",
|
|
35
83
|
other: "Mostrar {count} linhas anteriores",
|
|
36
84
|
},
|
|
85
|
+
"toolkit.showingRows": "Mostrando {from} a {to} de {total} linhas",
|
|
37
86
|
"toolkit.showLess": "Mostrar menos",
|
|
38
87
|
"toolkit.showMore": "Mostrar mais",
|
|
39
88
|
"toolkit.showMoreLines": {
|
|
@@ -45,6 +94,12 @@ export const toolkit = {
|
|
|
45
94
|
"toolkit.terminalFailed": "Verifique sua conexão e tente de novo.",
|
|
46
95
|
"toolkit.terminalFailedTitle": "O terminal não carregou",
|
|
47
96
|
"toolkit.terminalOpening": "Abrindo o terminal…",
|
|
97
|
+
"toolkit.thisFiscalYear": "Este ano fiscal",
|
|
98
|
+
"toolkit.thisMonth": "Este mês",
|
|
99
|
+
"toolkit.thisYear": "Este ano",
|
|
100
|
+
"toolkit.time": "Hora",
|
|
101
|
+
"toolkit.today": "Hoje",
|
|
102
|
+
"toolkit.todayLastYear": "Hoje, no ano passado",
|
|
48
103
|
"toolkit.toDo": "A fazer",
|
|
49
104
|
"toolkit.tomorrow": "Amanhã",
|
|
50
105
|
"toolkit.tryAgain": "Tentar de novo",
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A page a route makes on the server, in the app's look: a sign-in form of
|
|
3
|
+
* the app's own, a printable receipt, a link's landing page. Its head is the
|
|
4
|
+
* app's page's (the theme's variables and the page's base, its icons, its
|
|
5
|
+
* colour and fonts: see head.ts), and its body is React, made with the
|
|
6
|
+
* toolkit (`Button`, `Input`, `Card`…), whose pieces bring their own styles,
|
|
7
|
+
* and said in the app's words (its `words` resource).
|
|
8
|
+
*
|
|
9
|
+
* It's HTML only: no script runs in it, so what works is what HTML does by
|
|
10
|
+
* itself, links and forms that post. The route decides its status and
|
|
11
|
+
* headers; the page is never kept (`no-store`) unless they say otherwise.
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* routes: {
|
|
15
|
+
* "/login": (request, { runtime }) =>
|
|
16
|
+
* routePage(runtime, {
|
|
17
|
+
* title: "Sign in",
|
|
18
|
+
* body: (
|
|
19
|
+
* <form method="post" action="/login">
|
|
20
|
+
* <Input name="username" aria-label="Username" />
|
|
21
|
+
* <Button type="submit" variant="primary">Go</Button>
|
|
22
|
+
* </form>
|
|
23
|
+
* ),
|
|
24
|
+
* }),
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { type ReactNode } from "react";
|
|
29
|
+
import { type Resources } from "../../runtime/mod.js";
|
|
30
|
+
/** What a route's page is. */
|
|
31
|
+
export type RoutePageOptions = {
|
|
32
|
+
/** The page's title (the browser's tab). */
|
|
33
|
+
title: string;
|
|
34
|
+
/** What it shows: React, the toolkit's pieces among it. */
|
|
35
|
+
body: ReactNode;
|
|
36
|
+
/** Its status: 200 unless said (a refused sign-in may say 401). */
|
|
37
|
+
status?: number;
|
|
38
|
+
/** Its language, the app's page's (`page.lang`) unless said. */
|
|
39
|
+
lang?: string;
|
|
40
|
+
/** Headers of its own, over the page's. */
|
|
41
|
+
headers?: HeadersInit;
|
|
42
|
+
};
|
|
43
|
+
/** The runtime a route is handed: what it describes is the app's resources. */
|
|
44
|
+
type Described = {
|
|
45
|
+
describe(): {
|
|
46
|
+
resources: Resources;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/** The page's HTML, for an app's resources. */
|
|
50
|
+
export declare function routePageHtml(resources: Resources, options: RoutePageOptions): string;
|
|
51
|
+
/** The page as a route's answer. */
|
|
52
|
+
export declare function routePage(runtime: Described, options: RoutePageOptions): Response;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A page a route makes on the server, in the app's look: a sign-in form of
|
|
3
|
+
* the app's own, a printable receipt, a link's landing page. Its head is the
|
|
4
|
+
* app's page's (the theme's variables and the page's base, its icons, its
|
|
5
|
+
* colour and fonts: see head.ts), and its body is React, made with the
|
|
6
|
+
* toolkit (`Button`, `Input`, `Card`…), whose pieces bring their own styles,
|
|
7
|
+
* and said in the app's words (its `words` resource).
|
|
8
|
+
*
|
|
9
|
+
* It's HTML only: no script runs in it, so what works is what HTML does by
|
|
10
|
+
* itself, links and forms that post. The route decides its status and
|
|
11
|
+
* headers; the page is never kept (`no-store`) unless they say otherwise.
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* routes: {
|
|
15
|
+
* "/login": (request, { runtime }) =>
|
|
16
|
+
* routePage(runtime, {
|
|
17
|
+
* title: "Sign in",
|
|
18
|
+
* body: (
|
|
19
|
+
* <form method="post" action="/login">
|
|
20
|
+
* <Input name="username" aria-label="Username" />
|
|
21
|
+
* <Button type="submit" variant="primary">Go</Button>
|
|
22
|
+
* </form>
|
|
23
|
+
* ),
|
|
24
|
+
* }),
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { createElement, Fragment } from "react";
|
|
29
|
+
import { renderToString } from "react-dom/server";
|
|
30
|
+
import { definePlugin } from "../../runtime/mod.js";
|
|
31
|
+
import { look, quoted } from "./head.js";
|
|
32
|
+
import { fontsOf, themeOf } from "./theme/css.js";
|
|
33
|
+
import { setWords, wordsOf } from "./words.js";
|
|
34
|
+
/** The app's words, as the browser's page has them. */
|
|
35
|
+
const wordsFrom = (resources) => wordsOf([
|
|
36
|
+
definePlugin({ name: "route-page-words", resources: { words: resources.words ?? {} } }),
|
|
37
|
+
]);
|
|
38
|
+
/** The page's HTML, for an app's resources. */
|
|
39
|
+
export function routePageHtml(resources, options) {
|
|
40
|
+
const theme = resources.theme ?? themeOf([]);
|
|
41
|
+
const page = resources.page;
|
|
42
|
+
const lang = options.lang ?? page?.lang ?? "en";
|
|
43
|
+
const fonts = fontsOf(theme);
|
|
44
|
+
// The app's words while it's drawn: the render is synchronous, so no other page sees them.
|
|
45
|
+
const restore = setWords(wordsFrom(resources));
|
|
46
|
+
let markup;
|
|
47
|
+
try {
|
|
48
|
+
markup = renderToString(createElement(Fragment, null, options.body));
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
restore();
|
|
52
|
+
}
|
|
53
|
+
// The toolkit's styles (React writes each once, ahead of what uses it) go in the head.
|
|
54
|
+
const styles = [];
|
|
55
|
+
const body = markup.replace(/<style data-precedence="[^"]*"[^>]*>[\s\S]*?<\/style>/g, (style) => {
|
|
56
|
+
styles.push(style);
|
|
57
|
+
return "";
|
|
58
|
+
});
|
|
59
|
+
return `<!doctype html>
|
|
60
|
+
<html lang="${quoted(lang)}">
|
|
61
|
+
<head>
|
|
62
|
+
<meta charset="utf-8">
|
|
63
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
64
|
+
${look(theme)}${fonts ? `<link rel="stylesheet" href="${fonts}">\n` : ""}${styles.map((style) => `${style}\n`).join("")}<title>${quoted(options.title)}</title>
|
|
65
|
+
</head>
|
|
66
|
+
<body>
|
|
67
|
+
${body}
|
|
68
|
+
</body>
|
|
69
|
+
</html>`;
|
|
70
|
+
}
|
|
71
|
+
/** The page as a route's answer. */
|
|
72
|
+
export function routePage(runtime, options) {
|
|
73
|
+
const headers = new Headers({
|
|
74
|
+
"content-type": "text/html; charset=utf-8",
|
|
75
|
+
"cache-control": "no-store",
|
|
76
|
+
});
|
|
77
|
+
for (const [name, value] of new Headers(options.headers))
|
|
78
|
+
headers.set(name, value);
|
|
79
|
+
return new Response(routePageHtml(runtime.describe().resources, options), {
|
|
80
|
+
status: options.status ?? 200,
|
|
81
|
+
headers,
|
|
82
|
+
});
|
|
83
|
+
}
|
package/hosts/web/server.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ import { type Plugin } from "../../runtime/mod.js";
|
|
|
41
41
|
import { type Asset } from "./assets.js";
|
|
42
42
|
export type { Asset };
|
|
43
43
|
export { type SnapshotOptions, type Widgets, widgetsOf, type WidgetsOptions } from "./widgets.js";
|
|
44
|
+
export { routePage, routePageHtml, type RoutePageOptions } from "./route-page.js";
|
|
44
45
|
/**
|
|
45
46
|
* Bundled code: its files by name (`deno bundle --code-splitting --outdir`'s),
|
|
46
47
|
* the entry and the chunks it imports by relative path, and which one the
|