@jaetask/toolkit 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +134 -2
- package/dist/fonts/OFL.txt +93 -0
- package/dist/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
- package/dist/forms.d.ts +70 -0
- package/dist/forms.js +56 -0
- package/dist/forms.js.map +1 -0
- package/dist/guard.d.ts +9 -0
- package/dist/guard.js +105 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/link.d.ts +22 -0
- package/dist/link.js +45 -0
- package/dist/link.js.map +1 -0
- package/dist/page.d.ts +122 -0
- package/dist/page.js +108 -0
- package/dist/page.js.map +1 -0
- package/dist/parts.d.ts +83 -0
- package/dist/parts.js +78 -0
- package/dist/parts.js.map +1 -0
- package/dist/shell.d.ts +85 -0
- package/dist/shell.js +143 -0
- package/dist/shell.js.map +1 -0
- package/dist/styles.css +1143 -0
- package/dist/ui.d.ts +26 -0
- package/dist/ui.js +37 -0
- package/dist/ui.js.map +1 -0
- package/package.json +70 -4
- package/skills/ux-flow/SKILL.md +22 -0
- package/skills/ux-flow/ux-flow.svg +14 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Inter ships with the toolkit: `styles.css` loads it from `fonts/` beside it (SIL Open Font License, `fonts/OFL.txt`). Serve or bundle `dist/fonts` with the styles.
|
|
6
|
+
- Six named colours (`blue`, `teal`, `green`, `amber`, `purple`, `pink`) as `--tk-c-*` tokens with light and dark values; `Chip` and `Avatar` take `colour`.
|
|
7
|
+
- `Avatar` takes `emoji`. Its `colour` is now a named colour, not a CSS value, so it needs no inline style.
|
|
8
|
+
- `Board` and `Column`: columns with a title, kind chip and count; a `ListRow` with `dragId` can be dropped on a column with `onDrop`.
|
|
9
|
+
- `ListRow` takes `as`, `dragId`, `blocked` and `blockedLabel`; its body is a `div`. `ListCard` takes `as`.
|
|
10
|
+
- `Thread`, `Comment` (one level of `replies`), `Reactions` and `ActivityRow`.
|
|
11
|
+
- `Tabs` (buttons or links, with counts), `ChipMultiPicker`, `Composer`, `FilterBar` and `SearchInput`, `Facts`, `Notice` (inline or floating), `FileButton` and `Thumbs`, `Inline` for several controls in one `Row`, and `CenteredPage` for pages outside the shell such as sign-in.
|
|
12
|
+
- Nav items take `count`. Groups take `onReorder`: drag a row, or Alt+Up and Alt+Down on a focused row.
|
|
13
|
+
|
|
14
|
+
- Group items take `children`: each expands and collapses on its own with its own button, several can be open at once, and the shell remembers which ones were left open in this browser. `defaultOpen` sets the first state; `current` marks the row as the current page.
|
|
15
|
+
- `AppShell` takes `bottom`: pages that sit at the bottom of the sidebar, above Settings (for example Archive).
|
|
16
|
+
|
|
17
|
+
## 0.1.0
|
|
18
|
+
|
|
19
|
+
- `AppShell`, the page kit, the UI primitives and the tokens in `styles.css`.
|
|
20
|
+
- The ux-flow skill and `toolkit-guard`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jaetask
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jaetask/toolkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One shell and one page kit for every Kit app, so each app looks and works the same: a light grey sidebar with the app's pages and its projects, warm grey sections with one Edit button each, and edit pages with labelled rows, Back, Cancel and Save.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @jaetask/toolkit react react-dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Import the styles once at the app's root. They load Inter from `fonts/` beside `styles.css`, so a bundler picks the fonts up, and an app that serves `dist/styles.css` directly serves `dist/fonts` with it:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import "@jaetask/toolkit/styles.css";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import {
|
|
23
|
+
AppShell,
|
|
24
|
+
EditLink,
|
|
25
|
+
Panel,
|
|
26
|
+
PageBody,
|
|
27
|
+
StatusDot,
|
|
28
|
+
ListCard,
|
|
29
|
+
ListRow,
|
|
30
|
+
} from "@jaetask/toolkit";
|
|
31
|
+
|
|
32
|
+
<AppShell
|
|
33
|
+
app={{ name: "Tasks" }}
|
|
34
|
+
title="Website · Profile"
|
|
35
|
+
nav={[{ href: "/today", label: "Today", icon: <IconSun size={16} />, current: true }]}
|
|
36
|
+
groups={[
|
|
37
|
+
{
|
|
38
|
+
label: "Projects",
|
|
39
|
+
items: projects.map((p) => ({
|
|
40
|
+
id: p.id,
|
|
41
|
+
href: `/p/${p.id}`,
|
|
42
|
+
label: p.name,
|
|
43
|
+
status: p.status,
|
|
44
|
+
})),
|
|
45
|
+
},
|
|
46
|
+
]}
|
|
47
|
+
settingsHref="/settings"
|
|
48
|
+
>
|
|
49
|
+
<PageBody title="Profile" line="What this project is and how its tickets are named.">
|
|
50
|
+
<Panel
|
|
51
|
+
id="identity"
|
|
52
|
+
title="Identity"
|
|
53
|
+
line="The name and prefix every ticket carries."
|
|
54
|
+
action={<EditLink to="/p/web/edit/identity" />}
|
|
55
|
+
>
|
|
56
|
+
…
|
|
57
|
+
</Panel>
|
|
58
|
+
</PageBody>
|
|
59
|
+
</AppShell>;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The edit page that Edit opens:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { EditFrame, Input, Row, useBackTo } from "@jaetask/toolkit";
|
|
66
|
+
|
|
67
|
+
const back = useBackTo("/p/web/profile");
|
|
68
|
+
<EditFrame title="Edit identity" backTo={back} onSave={save}>
|
|
69
|
+
<Row title="Name" line="Shown in the sidebar and on every page." htmlFor="name">
|
|
70
|
+
<Input id="name" value={name} onChange={(e) => setName(e.target.value)} />
|
|
71
|
+
</Row>
|
|
72
|
+
</EditFrame>;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
With a router, pass its link component and location once:
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
<ToolkitProvider link={({ href, ...rest }) => <RouterLink to={href} {...rest} />} location={pathname + search}>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## What is in it
|
|
82
|
+
|
|
83
|
+
| Component | Use |
|
|
84
|
+
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
85
|
+
| `AppShell` | Sidebar (app mark, pages with icons, small-caps groups with status dots, Settings, search, collapse), top bar and page. |
|
|
86
|
+
| `SideSection`, `SideLink` | The sections and links inside the selected group item. |
|
|
87
|
+
| `PageBody` | Page title, one line, the one primary action, then stacked panels. |
|
|
88
|
+
| `Panel` | A section: warm grey, title, one line, at most one action. |
|
|
89
|
+
| `EditLink`, `PageLink`, `PrimaryLink`, `BackLink` | Buttons that open pages; edit links carry `?from=` so the way back returns to the same spot. |
|
|
90
|
+
| `Card`, `Kicker`, `ListCard`, `ListRow`, `EmptyCard`, `Chip` | What goes inside a panel. |
|
|
91
|
+
| `StatusDot`, `Dot` | Grey not started, orange in progress, green done. |
|
|
92
|
+
| `EditFrame`, `Row`, `ChipPicker` | The edit page and its labelled rows. |
|
|
93
|
+
| `Board`, `Column` | Columns with a title, kind chip and count; drag a `ListRow` (with `dragId`) onto a column. |
|
|
94
|
+
| `Thread`, `Comment`, `Reactions`, `ActivityRow` | Comments with one level of replies, emoji reactions, and activity lines with one action. |
|
|
95
|
+
| `Tabs`, `FilterBar`, `SearchInput` | Above a list: views, search and selects. |
|
|
96
|
+
| `ChipMultiPicker`, `Inline`, `FileButton`, `Thumbs` | On an edit page: pick many, several controls in one row, images. |
|
|
97
|
+
| `Composer`, `Facts`, `Notice`, `CenteredPage` | A one-line input with its button, labelled values, the result of the last change, and a page outside the shell such as sign-in. |
|
|
98
|
+
| `Button`, `Input`, `Textarea`, `Select`, `Label`, `ConfirmDelete` | Primitives. `ConfirmDelete` is the only dialog: permanent delete, confirmed by typing the name. |
|
|
99
|
+
|
|
100
|
+
## The ux-flow skill
|
|
101
|
+
|
|
102
|
+
[skills/ux-flow](skills/ux-flow/SKILL.md) is the rule these components follow. Install it in an app:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npx skills add jaetask/toolkit --skill ux-flow
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## toolkit-guard
|
|
109
|
+
|
|
110
|
+
`npx toolkit-guard src` fails when an app hand-builds what the toolkit has:
|
|
111
|
+
|
|
112
|
+
| Rule | Fails when |
|
|
113
|
+
| --------------- | ------------------------------------------------------------------------------------------------------- |
|
|
114
|
+
| `own-kit` | The app defines its own AppShell, Sidebar, Panel, EditFrame, Row, ListRow or another toolkit component. |
|
|
115
|
+
| `no-sheet` | The app imports a sheet or drawer. |
|
|
116
|
+
| `tokens-only` | App code or CSS holds a literal colour instead of a `--tk-` token. |
|
|
117
|
+
| `shell-present` | No file imports `AppShell` from `@jaetask/toolkit`. |
|
|
118
|
+
|
|
119
|
+
A line that must keep a literal ends with the comment `toolkit-guard-allow`.
|
|
120
|
+
|
|
121
|
+
## Colours
|
|
122
|
+
|
|
123
|
+
Six named colours for labels, project colours and avatars: `blue`, `teal`, `green`, `amber`, `purple`, `pink`. Pass the name (`<Chip colour="teal">`), never a CSS value.
|
|
124
|
+
|
|
125
|
+
## Changes
|
|
126
|
+
|
|
127
|
+
Push a branch, never main. A pull request to main opens by itself and merges when the `ci` check passes.
|
|
128
|
+
|
|
129
|
+
## Credit
|
|
130
|
+
|
|
131
|
+
The app shell follows the layout of [agent-native](https://github.com/BuilderIO/agent-native) (MIT, Builder.io).
|
|
132
|
+
|
|
133
|
+
## Licence
|
|
134
|
+
|
|
135
|
+
MIT. Inter is under the SIL Open Font License (`fonts/OFL.txt`).
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter) Inter-Italic[opsz,wght].ttf: Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
Binary file
|
package/dist/forms.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Surface } from "./ui.js";
|
|
3
|
+
export type TabOption<T extends string> = {
|
|
4
|
+
id: T;
|
|
5
|
+
name: string;
|
|
6
|
+
count?: number;
|
|
7
|
+
href?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Tabs above a list. With `href` on each option they are links (the current one marked); without,
|
|
11
|
+
* they are buttons that call onChange.
|
|
12
|
+
*/
|
|
13
|
+
export declare function Tabs<T extends string>({ label, value, options, onChange, }: {
|
|
14
|
+
label: string;
|
|
15
|
+
value: T;
|
|
16
|
+
options: TabOption<T>[];
|
|
17
|
+
onChange?: (value: T) => void;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
19
|
+
/** Pills to pick several values from, on an edit page. */
|
|
20
|
+
export declare function ChipMultiPicker<T extends string>({ label, value, options, onChange, }: {
|
|
21
|
+
label: string;
|
|
22
|
+
value: T[];
|
|
23
|
+
options: {
|
|
24
|
+
id: T;
|
|
25
|
+
name: string;
|
|
26
|
+
}[];
|
|
27
|
+
onChange: (value: T[]) => void;
|
|
28
|
+
}): import("react").JSX.Element;
|
|
29
|
+
/** A one-line input with its button: chat, a quick add, a reply. */
|
|
30
|
+
export declare function Composer({ label, value, onChange, onSubmit, placeholder, button, busy, maxLength, }: {
|
|
31
|
+
label: string;
|
|
32
|
+
value: string;
|
|
33
|
+
onChange: (value: string) => void;
|
|
34
|
+
onSubmit: (value: string) => void;
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
button?: string;
|
|
37
|
+
busy?: boolean;
|
|
38
|
+
maxLength?: number;
|
|
39
|
+
}): import("react").JSX.Element;
|
|
40
|
+
/** The bar above a list: a search box first, then selects and toggles. */
|
|
41
|
+
export declare function FilterBar({ children, label, }: {
|
|
42
|
+
children: ReactNode;
|
|
43
|
+
label?: string;
|
|
44
|
+
}): import("react").JSX.Element;
|
|
45
|
+
/** The search box for a FilterBar. */
|
|
46
|
+
export declare function SearchInput({ value, onChange, label, placeholder, }: {
|
|
47
|
+
value: string;
|
|
48
|
+
onChange: (value: string) => void;
|
|
49
|
+
label?: string;
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
}): import("react").JSX.Element;
|
|
52
|
+
/** A grey button that opens the file picker. */
|
|
53
|
+
export declare function FileButton({ label, onFiles, accept, multiple, disabled, surface, }: {
|
|
54
|
+
label: string;
|
|
55
|
+
onFiles: (files: File[]) => void;
|
|
56
|
+
accept?: string;
|
|
57
|
+
multiple?: boolean;
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
surface?: Surface;
|
|
60
|
+
}): import("react").JSX.Element;
|
|
61
|
+
/** A grid of image thumbnails, each with a Remove button. */
|
|
62
|
+
export declare function Thumbs({ items, onRemove, removeLabel, }: {
|
|
63
|
+
items: {
|
|
64
|
+
id: string;
|
|
65
|
+
src: string;
|
|
66
|
+
alt: string;
|
|
67
|
+
}[];
|
|
68
|
+
onRemove?: (id: string) => void;
|
|
69
|
+
removeLabel?: string;
|
|
70
|
+
}): import("react").JSX.Element;
|
package/dist/forms.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Controls for list views and edit pages: tabs, pick-many chips, the composer, the filter bar,
|
|
3
|
+
// and a file button with a thumbnail grid.
|
|
4
|
+
import { useRef } from "react";
|
|
5
|
+
import { Link } from "./link.js";
|
|
6
|
+
import { Button, Input } from "./ui.js";
|
|
7
|
+
/**
|
|
8
|
+
* Tabs above a list. With `href` on each option they are links (the current one marked); without,
|
|
9
|
+
* they are buttons that call onChange.
|
|
10
|
+
*/
|
|
11
|
+
export function Tabs({ label, value, options, onChange, }) {
|
|
12
|
+
const body = (o) => (_jsxs(_Fragment, { children: [o.name, o.count !== undefined && _jsx("span", { className: "tk-count", children: o.count })] }));
|
|
13
|
+
if (options.every((o) => o.href))
|
|
14
|
+
return (_jsx("nav", { className: "tk-tabs", "aria-label": label, children: options.map((o) => (_jsx(Link, { href: o.href ?? "", className: "tk-tab", "aria-current": o.id === value ? "page" : undefined, children: body(o) }, o.id))) }));
|
|
15
|
+
return (_jsx("div", { className: "tk-tabs", role: "tablist", "aria-label": label, children: options.map((o) => (_jsx("button", { type: "button", role: "tab", className: "tk-tab", "aria-selected": o.id === value, onClick: () => onChange?.(o.id), children: body(o) }, o.id))) }));
|
|
16
|
+
}
|
|
17
|
+
/** Pills to pick several values from, on an edit page. */
|
|
18
|
+
export function ChipMultiPicker({ label, value, options, onChange, }) {
|
|
19
|
+
const on = new Set(value);
|
|
20
|
+
return (
|
|
21
|
+
// biome-ignore lint/a11y/useSemanticElements: a row of toggle pills, not a fieldset of inputs
|
|
22
|
+
_jsx("div", { role: "group", "aria-label": label, className: "tk-chips", children: options.map((o) => (_jsx("button", { type: "button", className: "tk-pick", "aria-pressed": on.has(o.id), onClick: () => onChange(on.has(o.id) ? value.filter((v) => v !== o.id) : [...value, o.id]), children: o.name }, o.id))) }));
|
|
23
|
+
}
|
|
24
|
+
/** A one-line input with its button: chat, a quick add, a reply. */
|
|
25
|
+
export function Composer({ label, value, onChange, onSubmit, placeholder, button = "Send", busy, maxLength, }) {
|
|
26
|
+
const submit = (e) => {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
const text = value.trim();
|
|
29
|
+
if (text && !busy)
|
|
30
|
+
onSubmit(text);
|
|
31
|
+
};
|
|
32
|
+
return (_jsxs("form", { className: "tk-composer", onSubmit: submit, children: [_jsx(Input, { "aria-label": label, value: value, placeholder: placeholder, maxLength: maxLength, onChange: (e) => onChange(e.target.value) }), _jsx(Button, { type: "submit", variant: "primary", disabled: busy || !value.trim(), children: button })] }));
|
|
33
|
+
}
|
|
34
|
+
/** The bar above a list: a search box first, then selects and toggles. */
|
|
35
|
+
export function FilterBar({ children, label = "Filters", }) {
|
|
36
|
+
return (
|
|
37
|
+
// biome-ignore lint/a11y/useSemanticElements: a toolbar of filters, not a form that submits
|
|
38
|
+
_jsx("div", { className: "tk-filter", role: "group", "aria-label": label, children: children }));
|
|
39
|
+
}
|
|
40
|
+
/** The search box for a FilterBar. */
|
|
41
|
+
export function SearchInput({ value, onChange, label = "Search", placeholder = "Search", }) {
|
|
42
|
+
return (_jsx(Input, { type: "search", className: "tk-search", "aria-label": label, placeholder: placeholder, value: value, onChange: (e) => onChange(e.target.value) }));
|
|
43
|
+
}
|
|
44
|
+
/** A grey button that opens the file picker. */
|
|
45
|
+
export function FileButton({ label, onFiles, accept = "image/png,image/jpeg,image/webp", multiple, disabled, surface = "white", }) {
|
|
46
|
+
const ref = useRef(null);
|
|
47
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { surface: surface, disabled: disabled ?? false, onClick: () => ref.current?.click(), children: label }), _jsx("input", { ref: ref, type: "file", hidden: true, accept: accept, multiple: multiple, onChange: (e) => {
|
|
48
|
+
onFiles(Array.from(e.target.files ?? []));
|
|
49
|
+
e.target.value = "";
|
|
50
|
+
} })] }));
|
|
51
|
+
}
|
|
52
|
+
/** A grid of image thumbnails, each with a Remove button. */
|
|
53
|
+
export function Thumbs({ items, onRemove, removeLabel = "Remove", }) {
|
|
54
|
+
return (_jsx("ul", { className: "tk-thumbs", children: items.map((t) => (_jsxs("li", { className: "tk-thumb", children: [_jsx("img", { src: t.src, alt: t.alt, loading: "lazy" }), onRemove && (_jsx("button", { type: "button", className: "tk-thumb-remove", "aria-label": `${removeLabel} ${t.alt}`, onClick: () => onRemove(t.id), children: removeLabel }))] }, t.id))) }));
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=forms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forms.js","sourceRoot":"","sources":["../src/forms.tsx"],"names":[],"mappings":";AAAA,+FAA+F;AAC/F,2CAA2C;AAC3C,OAAO,EAAkC,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAgB,MAAM,SAAS,CAAC;AAItD;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAmB,EACrC,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,GAMT;IACC,MAAM,IAAI,GAAG,CAAC,CAAe,EAAE,EAAE,CAAC,CAChC,8BACG,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,eAAM,SAAS,EAAC,UAAU,YAAE,CAAC,CAAC,KAAK,GAAQ,IACpE,CACJ,CAAC;IACF,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9B,OAAO,CACL,cAAK,SAAS,EAAC,SAAS,gBAAa,KAAK,YACvC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAClB,KAAC,IAAI,IAEH,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE,EAClB,SAAS,EAAC,QAAQ,kBACJ,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,YAEhD,IAAI,CAAC,CAAC,CAAC,IALH,CAAC,CAAC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cAAK,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,EAAC,MAAM,GAAG,EAC7C,QAAQ,IAAI,CACX,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,iBAAiB,gBACf,GAAG,WAAW,IAAI,CAAC,CAAC,GAAG,EAAE,EACrC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,YAE5B,WAAW,GACL,CACV,KAXM,CAAC,CAAC,EAAE,CAYR,CACN,CAAC,GACC,CACN,CAAC;AACJ,CAAC"}
|
package/dist/guard.d.ts
ADDED
package/dist/guard.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// toolkit-guard: fails when an app hand-builds what the toolkit already has.
|
|
3
|
+
// npx toolkit-guard [dir ...] (default: src)
|
|
4
|
+
// A line ending in the comment `toolkit-guard-allow` is skipped, for the rare literal that must stay.
|
|
5
|
+
import { readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
6
|
+
import { extname, join, relative } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
const KIT = [
|
|
9
|
+
"AppShell",
|
|
10
|
+
"Sidebar",
|
|
11
|
+
"PageBody",
|
|
12
|
+
"Panel",
|
|
13
|
+
"EditFrame",
|
|
14
|
+
"EditLink",
|
|
15
|
+
"Row",
|
|
16
|
+
"ListCard",
|
|
17
|
+
"ListRow",
|
|
18
|
+
"EmptyCard",
|
|
19
|
+
"StatusDot",
|
|
20
|
+
"BackLink",
|
|
21
|
+
"ChipPicker",
|
|
22
|
+
];
|
|
23
|
+
const CODE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs"]);
|
|
24
|
+
const STYLE = new Set([".css", ".scss"]);
|
|
25
|
+
const PAGE = new Set([".html"]);
|
|
26
|
+
const SKIP = new Set(["node_modules", "dist", "build", ".git", "coverage"]);
|
|
27
|
+
const ownKit = new RegExp(`\\b(?:function|const|let|class)\\s+(${KIT.join("|")})\\b(?!\\s*=\\s*(?:require|await import))`);
|
|
28
|
+
const sheetImport = /from\s+["'][^"']*(?:sheet|drawer)[^"']*["']|<(?:Sheet|Drawer)[\s>]/i;
|
|
29
|
+
const colour = /(?:^|[\s:("'`,=])(#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3}(?:[0-9a-fA-F]{2})?)?)\b|\b(?:rgba?|hsla?)\(/;
|
|
30
|
+
const shellImport = /import\s*{[^}]*\bAppShell\b[^}]*}\s*from\s*["']@jaetask\/toolkit["']/s;
|
|
31
|
+
function files(dir) {
|
|
32
|
+
let out = [];
|
|
33
|
+
for (const name of readdirSync(dir)) {
|
|
34
|
+
if (SKIP.has(name))
|
|
35
|
+
continue;
|
|
36
|
+
const path = join(dir, name);
|
|
37
|
+
if (statSync(path).isDirectory())
|
|
38
|
+
out = out.concat(files(path));
|
|
39
|
+
else
|
|
40
|
+
out.push(path);
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** Every finding in the given directories. */
|
|
45
|
+
export function check(dirs, root = process.cwd()) {
|
|
46
|
+
const found = [];
|
|
47
|
+
let shell = false;
|
|
48
|
+
for (const file of dirs.flatMap((d) => files(d))) {
|
|
49
|
+
const ext = extname(file);
|
|
50
|
+
if (!CODE.has(ext) && !STYLE.has(ext) && !PAGE.has(ext))
|
|
51
|
+
continue;
|
|
52
|
+
const text = readFileSync(file, "utf8");
|
|
53
|
+
const rel = relative(root, file);
|
|
54
|
+
if (CODE.has(ext) && shellImport.test(text))
|
|
55
|
+
shell = true;
|
|
56
|
+
text.split("\n").forEach((line, i) => {
|
|
57
|
+
if (line.includes("toolkit-guard-allow"))
|
|
58
|
+
return;
|
|
59
|
+
const at = { file: rel, line: i + 1 };
|
|
60
|
+
if (CODE.has(ext)) {
|
|
61
|
+
const kit = ownKit.exec(line);
|
|
62
|
+
if (kit)
|
|
63
|
+
found.push({
|
|
64
|
+
...at,
|
|
65
|
+
rule: "own-kit",
|
|
66
|
+
message: `${kit[1]} is a toolkit component: import it from @jaetask/toolkit.`,
|
|
67
|
+
});
|
|
68
|
+
if (sheetImport.test(line))
|
|
69
|
+
found.push({
|
|
70
|
+
...at,
|
|
71
|
+
rule: "no-sheet",
|
|
72
|
+
message: "Sheets and drawers break ux-flow: open an EditFrame page instead.",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if ((CODE.has(ext) || STYLE.has(ext)) && colour.test(line))
|
|
76
|
+
found.push({
|
|
77
|
+
...at,
|
|
78
|
+
rule: "tokens-only",
|
|
79
|
+
message: "Use a toolkit token (var(--tk-…)) instead of a literal colour.",
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!shell)
|
|
84
|
+
found.push({
|
|
85
|
+
file: dirs.join(", "),
|
|
86
|
+
line: 0,
|
|
87
|
+
rule: "shell-present",
|
|
88
|
+
message: "No page imports AppShell from @jaetask/toolkit: every app opens in the shell.",
|
|
89
|
+
});
|
|
90
|
+
return found;
|
|
91
|
+
}
|
|
92
|
+
const isMain = !!process.argv[1] &&
|
|
93
|
+
realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
94
|
+
if (isMain) {
|
|
95
|
+
const dirs = process.argv.slice(2);
|
|
96
|
+
const found = check(dirs.length ? dirs : ["src"]);
|
|
97
|
+
for (const f of found)
|
|
98
|
+
console.error(`${f.file}:${f.line} ${f.rule} ${f.message}`);
|
|
99
|
+
if (found.length) {
|
|
100
|
+
console.error(`toolkit-guard: ${found.length} finding(s).`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
console.log("toolkit-guard: clean.");
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":";AACA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AAK,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACjF,IAAI,MAAM,EAAE,CAAC;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACrF,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,kBAAkB,KAAK,CAAC,MAAM,cAAc,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { type LinkComponent, type LinkProps, Link, safeFrom, ToolkitProvider, useBackTo, useFromHref, withFrom, } from "./link.js";
|
|
2
|
+
export { BackLink, Card, Chip, ChipPicker, Dot, EditFrame, EditLink, EmptyCard, Kicker, ListCard, ListRow, PageBody, PageLink, Panel, PrimaryLink, type Progress, ROW_DRAG_TYPE, Row, StatusDot, COLOURS, type Colour, } from "./page.js";
|
|
3
|
+
export { ActivityRow, Board, CenteredPage, Column, Comment, Facts, Inline, Notice, type NoticeTone, Reactions, Thread, } from "./parts.js";
|
|
4
|
+
export { ChipMultiPicker, Composer, FileButton, FilterBar, SearchInput, type TabOption, Tabs, Thumbs, } from "./forms.js";
|
|
5
|
+
export { AppShell, Avatar, type Group, type GroupItem, type NavItem, SideLink, SideSection, } from "./shell.js";
|
|
6
|
+
export { Button, type ButtonVariant, ConfirmDelete, cx, Input, Label, Select, type Surface, Textarea, } from "./ui.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Link, safeFrom, ToolkitProvider, useBackTo, useFromHref, withFrom, } from "./link.js";
|
|
2
|
+
export { BackLink, Card, Chip, ChipPicker, Dot, EditFrame, EditLink, EmptyCard, Kicker, ListCard, ListRow, PageBody, PageLink, Panel, PrimaryLink, ROW_DRAG_TYPE, Row, StatusDot, COLOURS, } from "./page.js";
|
|
3
|
+
export { ActivityRow, Board, CenteredPage, Column, Comment, Facts, Inline, Notice, Reactions, Thread, } from "./parts.js";
|
|
4
|
+
export { ChipMultiPicker, Composer, FileButton, FilterBar, SearchInput, Tabs, Thumbs, } from "./forms.js";
|
|
5
|
+
export { AppShell, Avatar, SideLink, SideSection, } from "./shell.js";
|
|
6
|
+
export { Button, ConfirmDelete, cx, Input, Label, Select, Textarea, } from "./ui.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,IAAI,EACJ,QAAQ,EACR,eAAe,EACf,SAAS,EACT,WAAW,EACX,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,GAAG,EACH,SAAS,EACT,QAAQ,EACR,SAAS,EACT,MAAM,EACN,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,WAAW,EAEX,aAAa,EACb,GAAG,EACH,SAAS,EACT,OAAO,GAER,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,WAAW,EACX,KAAK,EACL,YAAY,EACZ,MAAM,EACN,OAAO,EACP,KAAK,EACL,MAAM,EACN,MAAM,EAEN,SAAS,EACT,MAAM,GACP,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,QAAQ,EACR,UAAU,EACV,SAAS,EACT,WAAW,EAEX,IAAI,EACJ,MAAM,GACP,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,QAAQ,EACR,MAAM,EAIN,QAAQ,EACR,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,MAAM,EAEN,aAAa,EACb,EAAE,EACF,KAAK,EACL,KAAK,EACL,MAAM,EAEN,QAAQ,GACT,MAAM,SAAS,CAAC"}
|
package/dist/link.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AnchorHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> & {
|
|
3
|
+
href: string;
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export type LinkComponent = (props: LinkProps) => ReactNode;
|
|
7
|
+
/** Gives the toolkit the app's router: its link component and its current location. */
|
|
8
|
+
export declare function ToolkitProvider({ link, location, children, }: {
|
|
9
|
+
link?: LinkComponent;
|
|
10
|
+
location?: string | (() => string);
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
/** The app's link component. */
|
|
14
|
+
export declare function Link(props: LinkProps): import("react").JSX.Element;
|
|
15
|
+
/** `to` with ?from= set to the given location. */
|
|
16
|
+
export declare function withFrom(to: string, from: string): string;
|
|
17
|
+
/** `to` with ?from= set to the current location. */
|
|
18
|
+
export declare function useFromHref(to: string): string;
|
|
19
|
+
/** A ?from= value that is safe to follow: a same-origin path. */
|
|
20
|
+
export declare function safeFrom(from: string | null | undefined): string | null;
|
|
21
|
+
/** Where an edit page's Back goes: the ?from= path when it is safe, else the fallback. */
|
|
22
|
+
export declare function useBackTo(fallback: string): string;
|
package/dist/link.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Links and the way back. Every link the toolkit draws goes through one Link component, so an app
|
|
3
|
+
// with a router (React Router, TanStack) passes its own, and an app without one gets a plain <a>.
|
|
4
|
+
// Edit links carry ?from= so the edit page's Back, Cancel and Save return to the same spot.
|
|
5
|
+
import { createContext, useContext } from "react";
|
|
6
|
+
const PlainLink = ({ href, children, ...rest }) => (_jsx("a", { href: href, ...rest, children: children }));
|
|
7
|
+
const browserLocation = () => typeof window === "undefined" ? "" : window.location.pathname + window.location.search;
|
|
8
|
+
const RoutingContext = createContext({ link: PlainLink, location: browserLocation });
|
|
9
|
+
/** Gives the toolkit the app's router: its link component and its current location. */
|
|
10
|
+
export function ToolkitProvider({ link, location, children, }) {
|
|
11
|
+
const value = {
|
|
12
|
+
link: link ?? PlainLink,
|
|
13
|
+
location: typeof location === "string" ? () => location : (location ?? browserLocation),
|
|
14
|
+
};
|
|
15
|
+
return _jsx(RoutingContext.Provider, { value: value, children: children });
|
|
16
|
+
}
|
|
17
|
+
/** The app's link component. */
|
|
18
|
+
export function Link(props) {
|
|
19
|
+
const { link: L } = useContext(RoutingContext);
|
|
20
|
+
return _jsx(L, { ...props });
|
|
21
|
+
}
|
|
22
|
+
/** `to` with ?from= set to the given location. */
|
|
23
|
+
export function withFrom(to, from) {
|
|
24
|
+
if (!from)
|
|
25
|
+
return to;
|
|
26
|
+
return `${to}${to.includes("?") ? "&" : "?"}from=${encodeURIComponent(from)}`;
|
|
27
|
+
}
|
|
28
|
+
/** `to` with ?from= set to the current location. */
|
|
29
|
+
export function useFromHref(to) {
|
|
30
|
+
const { location } = useContext(RoutingContext);
|
|
31
|
+
return withFrom(to, location());
|
|
32
|
+
}
|
|
33
|
+
/** A ?from= value that is safe to follow: a same-origin path. */
|
|
34
|
+
export function safeFrom(from) {
|
|
35
|
+
if (!from)
|
|
36
|
+
return null;
|
|
37
|
+
return from.startsWith("/") && !from.startsWith("//") && !from.includes("\\") ? from : null;
|
|
38
|
+
}
|
|
39
|
+
/** Where an edit page's Back goes: the ?from= path when it is safe, else the fallback. */
|
|
40
|
+
export function useBackTo(fallback) {
|
|
41
|
+
const { location } = useContext(RoutingContext);
|
|
42
|
+
const query = location().split("?")[1] ?? "";
|
|
43
|
+
return safeFrom(new URLSearchParams(query).get("from")) ?? fallback;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=link.js.map
|
package/dist/link.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../src/link.tsx"],"names":[],"mappings":";AAAA,kGAAkG;AAClG,kGAAkG;AAClG,4FAA4F;AAC5F,OAAO,EAA6B,aAAa,EAAkB,UAAU,EAAE,MAAM,OAAO,CAAC;AAe7F,MAAM,SAAS,GAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAChE,YAAG,IAAI,EAAE,IAAI,KAAM,IAAI,YACpB,QAAQ,GACP,CACL,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE,CAC3B,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;AAEzF,MAAM,cAAc,GAAG,aAAa,CAAU,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,CAAC;AAE9F,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAAC,EAC9B,IAAI,EACJ,QAAQ,EACR,QAAQ,GAKT;IACC,MAAM,KAAK,GAAY;QACrB,IAAI,EAAE,IAAI,IAAI,SAAS;QACvB,QAAQ,EAAE,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,eAAe,CAAC;KACx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