@cfast/ui 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +159 -0
- package/package.json +26 -18
- package/LICENSE +0 -21
- package/dist/chunk-755IRYDN.js +0 -941
- package/dist/chunk-7SNK37GF.js +0 -418
- package/dist/chunk-ASMYTWTR.js +0 -356
- package/dist/chunk-B2XXH5V4.js +0 -66
- package/dist/chunk-BQMXYYEV.js +0 -348
- package/dist/chunk-DTKBXCTU.js +0 -211
- package/dist/chunk-EYIBATYR.js +0 -33
- package/dist/chunk-FPZAQ2YQ.js +0 -474
- package/dist/chunk-G2OU4BYC.js +0 -205
- package/dist/chunk-JUNLQJ6H.js +0 -1013
- package/dist/chunk-NRGMW3JA.js +0 -906
- package/dist/chunk-Q6FPL2OJ.js +0 -1086
- package/dist/chunk-QHWAGKNW.js +0 -456
- package/dist/chunk-QZT62CGJ.js +0 -924
- package/dist/chunk-RESL4IJJ.js +0 -112
- package/dist/chunk-UDCWQUTR.js +0 -221
- package/dist/chunk-UE7PZOIJ.js +0 -11
- package/dist/chunk-UTZTHGNE.js +0 -84
- package/dist/chunk-UVRXMOX5.js +0 -439
- package/dist/chunk-XFD3N2D4.js +0 -161
- package/dist/client-CXIHCQtA.d.ts +0 -274
- package/dist/permission-gate-apt9T9Mu.d.ts +0 -1256
- package/dist/types-1bAiH2uK.d.ts +0 -392
- package/dist/types-BX6u5sAd.d.ts +0 -403
- package/dist/types-BpdY7w5l.d.ts +0 -403
- package/dist/types-BrepeVp8.d.ts +0 -403
- package/dist/types-BvAqMZhn.d.ts +0 -403
- package/dist/types-C74nSscq.d.ts +0 -403
- package/dist/types-DD1Cpx8F.d.ts +0 -403
- package/dist/types-DHUhQwJn.d.ts +0 -403
- package/dist/types-DZSJNt_M.d.ts +0 -392
- package/dist/types-DaaJiIjW.d.ts +0 -391
- package/dist/types-LUpWJwps.d.ts +0 -403
- package/dist/types-a7zVU6WE.d.ts +0 -394
- package/dist/types-biJTHMcH.d.ts +0 -403
- package/dist/types-ow_qSEYJ.d.ts +0 -392
- package/dist/types-wnLasZaB.d.ts +0 -1234
package/llms.txt
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# @cfast/ui
|
|
2
|
+
|
|
3
|
+
> Permission-aware UI components for cfast apps: data tables, page shells, typed fields, file uploads, and action feedback -- all wired to the framework.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
Use `@cfast/ui` when building data-driven pages in a cfast app. It sits between your primitive component library (MUI Joy UI) and your application code, providing "smart" components that integrate with `@cfast/db`, `@cfast/actions`, `@cfast/permissions`, `@cfast/pagination`, `@cfast/auth`, and `@cfast/storage`.
|
|
8
|
+
|
|
9
|
+
Import styled components from `@cfast/ui/joy`. Import headless components and hooks from `@cfast/ui`.
|
|
10
|
+
|
|
11
|
+
## Key concepts
|
|
12
|
+
|
|
13
|
+
- **Headless core + UI plugins**: `@cfast/ui` exports hooks and logic. `@cfast/ui/joy` exports Joy UI styled implementations. Custom plugins can provide other UI libraries via `createUIPlugin()`.
|
|
14
|
+
- **Permission-aware**: Components like `ActionButton`, `PermissionGate`, `EmptyState`, sidebar nav items, and `BulkActionBar` automatically hide/disable based on `@cfast/actions` permission status.
|
|
15
|
+
- **Schema-driven**: Pass a Drizzle `table` to `DataTable`, `FilterBar`, `DetailView`, or `useColumnInference()` and columns/fields/filters are inferred from column types.
|
|
16
|
+
- **URL-synced**: `FilterBar` serializes filter state to URL search params. `DataTable` sorting syncs to URL params. Both work with `@cfast/pagination`'s `parseParams()` in loaders.
|
|
17
|
+
|
|
18
|
+
## API Reference
|
|
19
|
+
|
|
20
|
+
### Hooks (from `@cfast/ui`)
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
useActionStatus(descriptor: ClientDescriptor): ActionHookResult
|
|
24
|
+
// Returns { permitted, invisible, pending, submit } for a single action.
|
|
25
|
+
|
|
26
|
+
useToast(): ToastApi
|
|
27
|
+
// Returns { show, success, error, info, warning } methods. Requires <ToastProvider>.
|
|
28
|
+
|
|
29
|
+
useActionToast(descriptor: ClientDescriptor, config: Record<string, { success?: string; error?: string }>): void
|
|
30
|
+
// Auto-shows toasts when action results arrive.
|
|
31
|
+
|
|
32
|
+
useConfirm(): ConfirmFn
|
|
33
|
+
// Returns async (options: ConfirmOptions) => Promise<boolean>. Requires <ConfirmProvider>.
|
|
34
|
+
|
|
35
|
+
useColumnInference(table: Record<string, unknown> | undefined, columns?: string[]): InferredColumn[]
|
|
36
|
+
// Maps Drizzle table columns to TypedField components. Memoized.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Components (from `@cfast/ui/joy`)
|
|
40
|
+
|
|
41
|
+
**Data display:**
|
|
42
|
+
- `DataTable` -- table with sorting, selection, row actions, skeleton loading. Accepts `data` (pagination result), `table` (Drizzle), `columns`, `actions`, `selectable`.
|
|
43
|
+
- `FilterBar` -- URL-synced filters. Accepts `table`, `filters` (array of FilterDef), `searchable`.
|
|
44
|
+
- `ListView` -- full page: title + filters + data table + pagination + empty state + bulk actions.
|
|
45
|
+
- `DetailView` -- read-only detail page for a single record. Auto-lays out TypedFields.
|
|
46
|
+
|
|
47
|
+
**Layout:**
|
|
48
|
+
- `AppShell` -- sidebar + header + content. Sub-components: `AppShellSidebar`, `AppShellHeader`.
|
|
49
|
+
- `PageContainer` -- title + breadcrumb + tabs + action toolbar.
|
|
50
|
+
- `UserMenu` -- header dropdown with avatar, role badge, auth actions.
|
|
51
|
+
- `NavigationProgress` -- thin progress bar during React Router navigation.
|
|
52
|
+
|
|
53
|
+
**Actions & feedback:**
|
|
54
|
+
- `ActionButton` -- permission-aware button wrapping a `@cfast/actions` action. Props: `action`, `input`, `whenForbidden: "hide" | "disable" | "show"`, `confirmation`.
|
|
55
|
+
- `PermissionGate` -- conditional render based on action permissions. Props: `action`, `input`, `fallback`.
|
|
56
|
+
- `ConfirmDialog` -- standalone confirmation dialog.
|
|
57
|
+
- `ToastProvider` -- mount once in root layout for toast notifications.
|
|
58
|
+
- `FormStatus` -- renders success/error/validation from action results.
|
|
59
|
+
- `BulkActionBar` -- toolbar for selected rows with bulk actions.
|
|
60
|
+
|
|
61
|
+
**Files:**
|
|
62
|
+
- `DropZone` -- drag-and-drop upload. Integrates with `@cfast/storage`'s `useUpload()`.
|
|
63
|
+
- `ImagePreview` -- displays image from storage with signed URL handling.
|
|
64
|
+
- `FileList` -- list of uploaded files with download/delete.
|
|
65
|
+
|
|
66
|
+
**Utilities:**
|
|
67
|
+
- `AvatarWithInitials` -- avatar with automatic initials fallback.
|
|
68
|
+
- `RoleBadge` -- colored chip for user role.
|
|
69
|
+
- `ImpersonationBanner` -- persistent banner when impersonating.
|
|
70
|
+
- `EmptyState` -- permission-aware empty state with optional create CTA.
|
|
71
|
+
|
|
72
|
+
### TypedField components (from `@cfast/ui`)
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
DateField, BooleanField, NumberField, TextField,
|
|
76
|
+
EmailField, UrlField, ImageField, FileField,
|
|
77
|
+
RelationField, JsonField
|
|
78
|
+
fieldForColumn(columnMeta): ComponentType // maps Drizzle column type to field
|
|
79
|
+
fieldsForTable(table): Record<string, ComponentType> // field map for whole table
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Plugin API
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
createUIPlugin({ components: { button, tooltip, table, ... } }): UIPlugin
|
|
86
|
+
UIPluginProvider // React provider for custom UI plugins
|
|
87
|
+
useUIPlugin(): UIPlugin
|
|
88
|
+
useComponent(slotName: string): ComponentType
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Usage Examples
|
|
92
|
+
|
|
93
|
+
### Full list page
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { ListView } from "@cfast/ui/joy";
|
|
97
|
+
import { usePagination } from "@cfast/pagination";
|
|
98
|
+
import { posts } from "~/db/schema";
|
|
99
|
+
|
|
100
|
+
function PostsPage() {
|
|
101
|
+
const pagination = usePagination<Post>();
|
|
102
|
+
return (
|
|
103
|
+
<ListView
|
|
104
|
+
title="Blog Posts"
|
|
105
|
+
data={pagination}
|
|
106
|
+
table={posts}
|
|
107
|
+
columns={["title", "author", "published", "createdAt"]}
|
|
108
|
+
actions={composed.client}
|
|
109
|
+
filters={[{ column: "published", type: "select", options: publishedOptions }]}
|
|
110
|
+
searchable={["title", "content"]}
|
|
111
|
+
createAction={createPost.client}
|
|
112
|
+
selectable
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Permission-aware button with confirmation
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { ActionButton } from "@cfast/ui/joy";
|
|
122
|
+
|
|
123
|
+
<ActionButton
|
|
124
|
+
action={deletePost}
|
|
125
|
+
input={{ postId }}
|
|
126
|
+
whenForbidden="disable"
|
|
127
|
+
confirmation="Delete this post?"
|
|
128
|
+
>
|
|
129
|
+
Delete
|
|
130
|
+
</ActionButton>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Auto-toast on action results
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { useActionToast } from "@cfast/ui";
|
|
137
|
+
|
|
138
|
+
useActionToast(composed.client, {
|
|
139
|
+
deletePost: { success: "Post deleted", error: "Failed to delete" },
|
|
140
|
+
publishPost: { success: "Post published" },
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Integration
|
|
145
|
+
|
|
146
|
+
- **@cfast/actions** -- `ActionButton`, `PermissionGate`, `BulkActionBar`, `useActionToast` consume action descriptors.
|
|
147
|
+
- **@cfast/pagination** -- `DataTable` and `ListView` accept pagination hook results. `FilterBar` serializes to URL params that `parseParams()` reads.
|
|
148
|
+
- **@cfast/db** -- Drizzle schema drives column inference, filter type inference, and field type inference.
|
|
149
|
+
- **@cfast/auth** -- `UserMenu` reads `useCurrentUser()`. `ImpersonationBanner` reads impersonation state.
|
|
150
|
+
- **@cfast/storage** -- `DropZone` integrates with `useUpload()`. `ImagePreview`/`FileList` use storage URLs.
|
|
151
|
+
- **@cfast/admin** -- Admin uses `ListView`, `DetailView`, `DataTable`, `FilterBar`, `AppShell`, etc. Admin generates config; UI renders pixels.
|
|
152
|
+
|
|
153
|
+
## Common Mistakes
|
|
154
|
+
|
|
155
|
+
- Importing from `@cfast/ui/joy` on the server -- Joy components are client-only. Use headless exports from `@cfast/ui` for server-safe code.
|
|
156
|
+
- Forgetting `<ToastProvider>` in root layout -- `useToast()` and `useActionToast()` throw without it.
|
|
157
|
+
- Forgetting `<ConfirmProvider>` -- `useConfirm()` and `ActionButton` with `confirmation` need it.
|
|
158
|
+
- Passing raw data arrays to `DataTable` instead of a pagination result from `usePagination()`.
|
|
159
|
+
- Using `whenForbidden="show"` on `ActionButton` when you mean `"disable"` -- `"show"` renders even when forbidden with no visual indicator.
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfast/ui",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Permission-aware React components with UI library plugins",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cfast",
|
|
7
|
+
"cloudflare-workers",
|
|
8
|
+
"react",
|
|
9
|
+
"ui",
|
|
10
|
+
"permissions"
|
|
11
|
+
],
|
|
5
12
|
"license": "MIT",
|
|
6
13
|
"repository": {
|
|
7
14
|
"type": "git",
|
|
@@ -26,12 +33,22 @@
|
|
|
26
33
|
}
|
|
27
34
|
},
|
|
28
35
|
"files": [
|
|
29
|
-
"dist"
|
|
36
|
+
"dist",
|
|
37
|
+
"llms.txt"
|
|
30
38
|
],
|
|
31
39
|
"sideEffects": false,
|
|
32
40
|
"publishConfig": {
|
|
33
41
|
"access": "public"
|
|
34
42
|
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup src/index.ts src/joy.ts src/client.ts --format esm --dts",
|
|
45
|
+
"dev": "tsup src/index.ts src/joy.ts src/client.ts --format esm --dts --watch",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"lint": "eslint src/",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"storybook": "storybook dev -p 6006",
|
|
50
|
+
"build-storybook": "storybook build"
|
|
51
|
+
},
|
|
35
52
|
"peerDependencies": {
|
|
36
53
|
"@mui/joy": ">=5.0.0-beta.0",
|
|
37
54
|
"react": ">=19",
|
|
@@ -48,12 +65,12 @@
|
|
|
48
65
|
}
|
|
49
66
|
},
|
|
50
67
|
"dependencies": {
|
|
51
|
-
"@cfast/actions": "
|
|
52
|
-
"@cfast/
|
|
53
|
-
"@cfast/
|
|
54
|
-
"@cfast/
|
|
55
|
-
"@cfast/
|
|
56
|
-
"@cfast/
|
|
68
|
+
"@cfast/actions": "workspace:*",
|
|
69
|
+
"@cfast/auth": "workspace:*",
|
|
70
|
+
"@cfast/db": "workspace:*",
|
|
71
|
+
"@cfast/pagination": "workspace:*",
|
|
72
|
+
"@cfast/permissions": "workspace:*",
|
|
73
|
+
"@cfast/storage": "workspace:*"
|
|
57
74
|
},
|
|
58
75
|
"devDependencies": {
|
|
59
76
|
"@emotion/react": "^11.14.0",
|
|
@@ -75,14 +92,5 @@
|
|
|
75
92
|
"tsup": "^8",
|
|
76
93
|
"typescript": "^5.7",
|
|
77
94
|
"vitest": "^4.1.0"
|
|
78
|
-
},
|
|
79
|
-
"scripts": {
|
|
80
|
-
"build": "tsup src/index.ts src/joy.ts src/client.ts --format esm --dts",
|
|
81
|
-
"dev": "tsup src/index.ts src/joy.ts src/client.ts --format esm --dts --watch",
|
|
82
|
-
"typecheck": "tsc --noEmit",
|
|
83
|
-
"lint": "eslint src/",
|
|
84
|
-
"test": "vitest run",
|
|
85
|
-
"storybook": "storybook dev -p 6006",
|
|
86
|
-
"build-storybook": "storybook build"
|
|
87
95
|
}
|
|
88
|
-
}
|
|
96
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Daniel Schmidt
|
|
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.
|