@coreframe/dashboard 0.3.29 → 0.3.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,9 +27,14 @@ Plugins are never discovered or installed at runtime.
27
27
 
28
28
  Add app-owned routes at `dashboard/pages/<slug>/route.tsx`. An adjacent `page.yaml` must define
29
29
  `icon` as a Codicon name (for example, `icon: settings-gear`) and may define `title`, `description`,
30
- and `layout`. Plugin navigation also requires `icon`. The sidebar uses the application package name
31
- and `src/assets/favicon.svg`. Set `layout: standalone` when a page owns its full viewport presentation
32
- and should render without the dashboard navigation, heading, or shell spacing.
30
+ and `layout`. Plugin navigation also requires `icon`. Navigation uses the application package name
31
+ and `src/assets/favicon.svg`. By default, a small logo floats in the top-left corner and opens a
32
+ navigation popover on hover, click, or keyboard activation. Pages own their headings, layout, and
33
+ spacing; Coreframe adds no page header or content wrapper. Leave room around the floating logo.
34
+
35
+ Set `layout: standalone` to omit the floating logo. A standalone page may place `DashboardMenu`
36
+ from `@coreframe/dashboard/web` in its own header or layout; it receives the current application and
37
+ page list automatically:
33
38
 
34
39
  ```yaml
35
40
  icon: settings-gear
@@ -37,7 +42,23 @@ title: Moderation
37
42
  layout: standalone
38
43
  ```
39
44
 
40
- Omitting `layout`, or setting it to `default`, retains the standard shell. Standalone pages remain in
45
+ ```tsx
46
+ import { DashboardMenu } from "@coreframe/dashboard/web"
47
+
48
+ export default function Moderation() {
49
+ return (
50
+ <main>
51
+ <header>
52
+ <DashboardMenu />
53
+ <h1>Moderation</h1>
54
+ </header>
55
+ {/* Page content */}
56
+ </main>
57
+ )
58
+ }
59
+ ```
60
+
61
+ Omitting `layout`, or setting it to `default`, retains the floating logo. Standalone pages remain in
41
62
  the dashboard route, build, authentication, query-client, and error-handling boundaries. Build-time
42
63
  composition validates slugs, metadata, route modules, identifiers, and paths before generating the
43
64
  React Router route graph and navigation manifest.
@@ -51,15 +72,54 @@ Projects can opt into app-owned customization without copying the default scaffo
51
72
 
52
73
  - `dashboard/document.tsx`, referenced as `document` in `dashboard.config.ts`, can provide a custom
53
74
  document `Layout` and optional `links` or `meta` exports;
54
- - `dashboard/styles.css` is loaded after the package stylesheet, while `panda.config.ts` remains the
55
- theme and generated-style override; and
75
+ - `dashboard/styles.css` is loaded after the package stylesheet and generated Panda stylesheet,
76
+ while `panda.config.ts` remains the theme and generated-style override; and
56
77
  - `vite.config.ts` and `react-router.config.ts` remain small tool-level adapters for build changes.
57
78
 
79
+ ## Style overrides
80
+
81
+ Keep customization in the project; package styles do not need to be copied or ejected. Styles load
82
+ in this order: the package shell, `dashboard/styled-system/styles.css`, then `dashboard/styles.css`.
83
+ The package stylesheet includes the built-in pages' generated utilities and default tokens.
84
+ Normal unlayered rules in `styles.css` take precedence over layered Panda rules. Shell rules are
85
+ unlayered, so match the relevant selector's specificity when overriding them.
86
+
87
+ The dashboard Panda config includes `coreframeDashboardPreset()` from `@coreframe/panda` and
88
+ generates all dashboard recipe variants because package components select variants at runtime.
89
+ Customize `theme.extend.semanticTokens.colors.dashboard` for shared colors, or
90
+ `theme.extend.recipes` and `theme.extend.slotRecipes` for reusable UI defaults. The color roles are
91
+ `canvas`, `panel`, `ink`, `muted`, `border`, `accent`, `danger`, `info`, `success`, and `warning`.
92
+ The shell consumes the same color tokens, with fallback values when no tokens are generated.
93
+
94
+ For logo placement and targeted menu changes, use the public `.coreframe-dashboard__*` selectors in
95
+ `dashboard/styles.css`, for example:
96
+
97
+ ```css
98
+ .coreframe-dashboard__floating-navigation {
99
+ top: 1.5rem;
100
+ left: 1.5rem;
101
+ }
102
+
103
+ .coreframe-dashboard__navigation-link[aria-current="page"] {
104
+ font-weight: 700;
105
+ }
106
+ ```
107
+
108
+ The logo button exposes `aria-expanded`; navigation links expose `aria-current="page"` for the
109
+ current page. The reusable UI uses Panda recipe classes
110
+ such as `.dashboard-button` and `.dashboard-section__root`.
111
+
112
+ Sculpted source editing applies to supported project-owned static Panda `css({ ... })` sources;
113
+ it does not redirect package styles into project overrides or edit config recipes. Its current
114
+ root-level development endpoints also require separate integration for the dashboard's proxied
115
+ development server. The dashboard Vite config registers the plugin, but the default document does
116
+ not mount its runtime yet. CSS and Panda overrides work independently of Sculpted.
117
+
58
118
  ## Runtime boundaries
59
119
 
60
120
  The app dashboard uses the same React, React Router framework mode, React Compiler, PandaCSS,
61
- Sculpted, Rouzer, Zod, TanStack Query, and Worker conventions as the main Coreframe application.
62
- Coreframe contributes the responsive navigation shell and default client/query runtime without
121
+ Rouzer, Zod, TanStack Query, and Worker conventions as the main Coreframe application.
122
+ Coreframe contributes the logo navigation and default client/query runtime without
63
123
  imposing a page-content component API.
64
124
 
65
125
  Plugin APIs expose named `queries` and `commands`. Queries are `GET` operations and commands are
@@ -161,6 +221,24 @@ replay once through the app transport. Other response statuses keep their normal
161
221
  distinct `401` and `403` failures. The dashboard password and plugin `DashboardSuperuser` actor are
162
222
  separate from app authentication, and the client does not proxy or translate between them.
163
223
 
224
+ If the route tree contains response codecs such as NDJSON, register their client plugins even when
225
+ the page does not call those routes. Rouzer validates codec registration during client construction.
226
+
227
+ ```ts
228
+ import { createDashboardAppClient } from "@coreframe/dashboard/app-client"
229
+ import * as ndjson from "rouzer/ndjson"
230
+
231
+ const { client, session } = createDashboardAppClient(routes, {
232
+ plugins: [ndjson.clientPlugin],
233
+ })
234
+ ```
235
+
236
+ The hosting app must separately register `ndjson.routerPlugin` in its API's `createRouter({ plugins })`
237
+ configuration. Keep its existing authentication middleware, and complete authentication and permission
238
+ checks before returning a stream. NDJSON actions resolve to an `AsyncIterable` of the declared item
239
+ type; the codec does not validate items against a runtime schema. This configuration applies to the
240
+ hosting app's `/api/` routes, independently of the dashboard plugin API.
241
+
164
242
  ## Built-in diagnostics
165
243
 
166
244
  The diagnostics plugin preserves the full local production-readiness inspection and provides a
@@ -1,14 +1,15 @@
1
1
  import { AuthSessionHintStore } from "@coreframe/lib/auth-transport";
2
2
  import { ReactNode } from "react";
3
- import { RouzerClient } from "rouzer";
3
+ import { ClientResponsePlugin, RouzerClient } from "rouzer";
4
4
  import { HttpRouteTree } from "rouzer/http";
5
5
 
6
6
  //#region src/app-client.d.ts
7
7
  /** The authentication states exposed by a dashboard app session. */
8
8
  type DashboardAppSessionStatus = "authenticated" | "checking" | "unauthenticated" | "unknown";
9
- /** The browser-only seams accepted by {@link createDashboardAppClient}. */
9
+ /** Response codecs and browser transport options for {@link createDashboardAppClient}. */
10
10
  type DashboardAppClientOptions = Readonly<{
11
- /** Replaces the browser fetch implementation in focused transport tests. */fetch?: typeof globalThis.fetch; /** Replaces the browser session hint store in focused session tests. */
11
+ /** Replaces the browser fetch implementation in focused transport tests. */fetch?: typeof globalThis.fetch; /** Response codecs required by the route tree, including routes the caller does not invoke. */
12
+ plugins?: readonly ClientResponsePlugin[]; /** Replaces the browser session hint store in focused session tests. */
12
13
  sessionHint?: AuthSessionHintStore;
13
14
  }>;
14
15
  /** The public state of a dashboard app session at one point in time. */
@@ -1 +1 @@
1
- import{createAuthSessionHintStore as e}from"@coreframe/lib/auth-transport";import{createBrowserAuthSessionHintPersistence as t,createBrowserAuthenticatedFetch as n}from"@coreframe/lib/auth-transport/browser";import{useSyncExternalStore as r}from"react";import{createClient as i}from"rouzer";function a(e,t={}){let r=p(),a=m(t.fetch??((e,t)=>globalThis.fetch(e,t)),r),o=t.sessionHint??f(),s=n({appOrigin:r,fetch:a,refreshAccess:()=>a(new URL(`/api/auth/token`,r),{credentials:`include`,method:`POST`}),sessionHint:o});return{client:i({baseURL:new URL(`/api/`,r).href,fetch:s.fetch,headers:{"content-type":`application/json`},onJsonError:h,routes:e}),session:l(s,o)}}function o(e){return r(e.subscribe,e.get,e.get)}function s({children:e,pending:t,session:n,unauthenticated:r,unknown:i}){switch(o(n).status){case`authenticated`:return e;case`checking`:return g(t,n);case`unauthenticated`:return g(r,n);case`unknown`:return g(i,n)}}var c=class extends Error{status;constructor(e){super(`Request failed with status ${e}.`),this.name=`DashboardAppResponseError`,this.status=e}};function l(e,t){let n=u(t.get()),r,i,a=!1;function o(){return n}function s(e,t){let r=d(e,t);r.status===n.status&&r.expiresAt===n.expiresAt||(n=r,l())}let c=new Set;function l(){for(let e of c)e()}function f(e){return c.add(e),()=>c.delete(e)}function p(){i!==void 0&&(clearTimeout(i),i=void 0)}function m(e){p(),i=setTimeout(()=>{i=void 0,t.get(),h()},Math.max(0,e-Date.now()))}function h(){if(a)return;let e=t.get();if(e.status===`authenticated`){s(`authenticated`,e.validUntil),m(e.validUntil);return}if(e.status===`unauthenticated`){s(`unauthenticated`,null),m(e.validUntil);return}p(),s(`checking`,null),g()}function g(){if(a)return Promise.resolve(n);if(t.get().status!==`unknown`)return h(),Promise.resolve(n);if(s(`checking`,null),r)return r;let i=e.refreshAccessToken().then(r=>{if(a)return n;let i=t.get();return i.status===`authenticated`||i.status===`unauthenticated`?h():r?s(`unknown`,null):(e.setUnauthenticated(),h()),n}).catch(()=>{if(!a){let e=t.get();e.status===`authenticated`||e.status===`unauthenticated`?h():s(`unknown`,null)}return n});return r=i,i.then(()=>{r===i&&(r=void 0)}),i}function _(){return a?Promise.resolve(n):(t.invalidate(),g())}let v=t.subscribe(h),y=()=>t.syncFromPersistence(),b=()=>{n.status===`unknown`&&g()};return globalThis.window!==void 0&&(globalThis.addEventListener(`storage`,y),globalThis.addEventListener(`online`,b)),h(),{get expiresAt(){return n.expiresAt},get isPending(){return n.isPending},get status(){return n.status},dispose(){a||(a=!0,p(),v(),globalThis.window!==void 0&&(globalThis.removeEventListener(`storage`,y),globalThis.removeEventListener(`online`,b)))},get:o,refresh:_,subscribe:f}}function u(e){return e.status===`authenticated`?d(`authenticated`,e.validUntil):e.status===`unauthenticated`?d(`unauthenticated`,null):d(`checking`,null)}function d(e,t){return Object.freeze({expiresAt:t,isPending:e!==`authenticated`&&e!==`unauthenticated`,status:e})}function f(){let n=!1;if(globalThis.window!==void 0)try{n=t({key:`coreframe.auth-session-observation.v1`,storage:globalThis.localStorage})}catch{n=!1}return e({persistence:n,unauthenticatedTtlMs:3e5})}function p(){let e=globalThis.location?.origin;if(!e)throw Error(`createDashboardAppClient() requires a browser location.`);let t;try{t=new URL(e)}catch{throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`)}if(t.protocol!==`http:`&&t.protocol!==`https:`)throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`);return t.origin}function m(e,t){return(n,r)=>{if(new URL(n instanceof Request?n.url:n.toString(),t).origin!==t)throw TypeError(`Dashboard app client only allows same-origin requests.`);return e(n,{...r,credentials:`include`})}}async function h(e){throw new c(e.status)}function g(e,t){return typeof e==`function`?e(t):e??null}export{c as DashboardAppResponseError,s as DashboardAppSessionBoundary,a as createDashboardAppClient,o as useDashboardAppSession};
1
+ import{createAuthSessionHintStore as e}from"@coreframe/lib/auth-transport";import{createBrowserAuthSessionHintPersistence as t,createBrowserAuthenticatedFetch as n}from"@coreframe/lib/auth-transport/browser";import{useSyncExternalStore as r}from"react";import{createClient as i}from"rouzer";function a(e,t={}){let r=p(),a=m(t.fetch??((e,t)=>globalThis.fetch(e,t)),r),o=t.sessionHint??f(),s=n({appOrigin:r,fetch:a,refreshAccess:()=>a(new URL(`/api/auth/token`,r),{credentials:`include`,method:`POST`}),sessionHint:o});return{client:i({baseURL:new URL(`/api/`,r).href,fetch:s.fetch,headers:{"content-type":`application/json`},onJsonError:h,plugins:t.plugins,routes:e}),session:l(s,o)}}function o(e){return r(e.subscribe,e.get,e.get)}function s({children:e,pending:t,session:n,unauthenticated:r,unknown:i}){switch(o(n).status){case`authenticated`:return e;case`checking`:return g(t,n);case`unauthenticated`:return g(r,n);case`unknown`:return g(i,n)}}var c=class extends Error{status;constructor(e){super(`Request failed with status ${e}.`),this.name=`DashboardAppResponseError`,this.status=e}};function l(e,t){let n=u(t.get()),r,i,a=!1;function o(){return n}function s(e,t){let r=d(e,t);r.status===n.status&&r.expiresAt===n.expiresAt||(n=r,l())}let c=new Set;function l(){for(let e of c)e()}function f(e){return c.add(e),()=>c.delete(e)}function p(){i!==void 0&&(clearTimeout(i),i=void 0)}function m(e){p(),i=setTimeout(()=>{i=void 0,t.get(),h()},Math.max(0,e-Date.now()))}function h(){if(a)return;let e=t.get();if(e.status===`authenticated`){s(`authenticated`,e.validUntil),m(e.validUntil);return}if(e.status===`unauthenticated`){s(`unauthenticated`,null),m(e.validUntil);return}p(),s(`checking`,null),g()}function g(){if(a)return Promise.resolve(n);if(t.get().status!==`unknown`)return h(),Promise.resolve(n);if(s(`checking`,null),r)return r;let i=e.refreshAccessToken().then(r=>{if(a)return n;let i=t.get();return i.status===`authenticated`||i.status===`unauthenticated`?h():r?s(`unknown`,null):(e.setUnauthenticated(),h()),n}).catch(()=>{if(!a){let e=t.get();e.status===`authenticated`||e.status===`unauthenticated`?h():s(`unknown`,null)}return n});return r=i,i.then(()=>{r===i&&(r=void 0)}),i}function _(){return a?Promise.resolve(n):(t.invalidate(),g())}let v=t.subscribe(h),y=()=>t.syncFromPersistence(),b=()=>{n.status===`unknown`&&g()};return globalThis.window!==void 0&&(globalThis.addEventListener(`storage`,y),globalThis.addEventListener(`online`,b)),h(),{get expiresAt(){return n.expiresAt},get isPending(){return n.isPending},get status(){return n.status},dispose(){a||(a=!0,p(),v(),globalThis.window!==void 0&&(globalThis.removeEventListener(`storage`,y),globalThis.removeEventListener(`online`,b)))},get:o,refresh:_,subscribe:f}}function u(e){return e.status===`authenticated`?d(`authenticated`,e.validUntil):e.status===`unauthenticated`?d(`unauthenticated`,null):d(`checking`,null)}function d(e,t){return Object.freeze({expiresAt:t,isPending:e!==`authenticated`&&e!==`unauthenticated`,status:e})}function f(){let n=!1;if(globalThis.window!==void 0)try{n=t({key:`coreframe.auth-session-observation.v1`,storage:globalThis.localStorage})}catch{n=!1}return e({persistence:n,unauthenticatedTtlMs:3e5})}function p(){let e=globalThis.location?.origin;if(!e)throw Error(`createDashboardAppClient() requires a browser location.`);let t;try{t=new URL(e)}catch{throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`)}if(t.protocol!==`http:`&&t.protocol!==`https:`)throw TypeError(`createDashboardAppClient() requires an HTTP(S) browser origin.`);return t.origin}function m(e,t){return(n,r)=>{if(new URL(n instanceof Request?n.url:n.toString(),t).origin!==t)throw TypeError(`Dashboard app client only allows same-origin requests.`);return e(n,{...r,credentials:`include`})}}async function h(e){throw new c(e.status)}function g(e,t){return typeof e==`function`?e(t):e??null}export{c as DashboardAppResponseError,s as DashboardAppSessionBoundary,a as createDashboardAppClient,o as useDashboardAppSession};
@@ -2,7 +2,7 @@ import { DashboardPluginApi } from "./api/contract.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  type DashboardEnvironment = "local" | "deployed";
5
- /** Presentation supplied around a dashboard page route. */
5
+ /** Whether Coreframe places floating navigation or the page owns navigation placement. */
6
6
  type DashboardPageLayout = "default" | "standalone";
7
7
  interface DashboardPageContribution {
8
8
  /** Stable page identity. It must be a lowercase, URL-safe slug. */
@@ -13,7 +13,7 @@ interface DashboardPageContribution {
13
13
  /** Codicon name, for example `settings-gear`. */
14
14
  icon: string;
15
15
  description?: string;
16
- /** Presentation supplied around the route. Defaults to the dashboard shell. */
16
+ /** Defaults to floating logo navigation. Standalone pages can place DashboardMenu themselves. */
17
17
  layout?: DashboardPageLayout;
18
18
  /** React Router framework route module, resolved by the dashboard build. */
19
19
  routeModule: string;