@coreframe/dashboard 0.3.28 → 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 +98 -8
- package/dist/package/app-client.d.ts +4 -3
- package/dist/package/app-client.js +1 -1
- package/dist/package/build.js +2 -2
- package/dist/package/config.d.ts +6 -1
- package/dist/package/shell.css +1611 -204
- package/dist/package/web/dashboard/dashboard.style.js +1 -1
- package/dist/package/web/ui/index.d.ts +1 -1
- package/dist/package/web-shell/index.d.ts +2 -1
- package/dist/package/web-shell/index.js +1 -1
- package/dist/package/web-shell/menu.d.ts +19 -0
- package/dist/package/web-shell/menu.js +1 -0
- package/dist/package/web-shell/shell.d.ts +2 -8
- package/dist/package/web-shell/shell.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,10 +25,43 @@ export default defineConfig({
|
|
|
25
25
|
Removing `diagnostics()` removes the feature's root navigation entry and its runtime operations.
|
|
26
26
|
Plugins are never discovered or installed at runtime.
|
|
27
27
|
|
|
28
|
-
Add app-owned routes at `dashboard/pages/<slug>/route.tsx`. An adjacent `page.yaml` must define
|
|
29
|
-
`icon: settings-gear`) and may define `title
|
|
30
|
-
`
|
|
31
|
-
|
|
28
|
+
Add app-owned routes at `dashboard/pages/<slug>/route.tsx`. An adjacent `page.yaml` must define
|
|
29
|
+
`icon` as a Codicon name (for example, `icon: settings-gear`) and may define `title`, `description`,
|
|
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:
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
icon: settings-gear
|
|
41
|
+
title: Moderation
|
|
42
|
+
layout: standalone
|
|
43
|
+
```
|
|
44
|
+
|
|
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
|
|
62
|
+
the dashboard route, build, authentication, query-client, and error-handling boundaries. Build-time
|
|
63
|
+
composition validates slugs, metadata, route modules, identifiers, and paths before generating the
|
|
64
|
+
React Router route graph and navigation manifest.
|
|
32
65
|
|
|
33
66
|
The generated dashboard does not need route adapters, a document root, a query-client module, or an
|
|
34
67
|
entry file. Keep those defaults in the package unless the dashboard build contract itself must
|
|
@@ -39,15 +72,54 @@ Projects can opt into app-owned customization without copying the default scaffo
|
|
|
39
72
|
|
|
40
73
|
- `dashboard/document.tsx`, referenced as `document` in `dashboard.config.ts`, can provide a custom
|
|
41
74
|
document `Layout` and optional `links` or `meta` exports;
|
|
42
|
-
- `dashboard/styles.css` is loaded after the package stylesheet
|
|
43
|
-
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
|
|
44
77
|
- `vite.config.ts` and `react-router.config.ts` remain small tool-level adapters for build changes.
|
|
45
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
|
+
|
|
46
118
|
## Runtime boundaries
|
|
47
119
|
|
|
48
120
|
The app dashboard uses the same React, React Router framework mode, React Compiler, PandaCSS,
|
|
49
|
-
|
|
50
|
-
Coreframe contributes the
|
|
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
|
|
51
123
|
imposing a page-content component API.
|
|
52
124
|
|
|
53
125
|
Plugin APIs expose named `queries` and `commands`. Queries are `GET` operations and commands are
|
|
@@ -149,6 +221,24 @@ replay once through the app transport. Other response statuses keep their normal
|
|
|
149
221
|
distinct `401` and `403` failures. The dashboard password and plugin `DashboardSuperuser` actor are
|
|
150
222
|
separate from app authentication, and the client does not proxy or translate between them.
|
|
151
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
|
+
|
|
152
242
|
## Built-in diagnostics
|
|
153
243
|
|
|
154
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
|
-
/**
|
|
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; /**
|
|
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};
|
package/dist/package/build.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{getDashboardPluginBuild as e}from"./config.js";import{createRequire as t}from"node:module";import{readFile as n,readdir as r}from"node:fs/promises";import{isAbsolute as i,join as a,resolve as o}from"node:path";import{icons as s}from"@iconify-json/codicon";import{parseDocument as c}from"yaml";import{z as l}from"zod";const u=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u,d=l.string().refine(e=>Object.hasOwn(s.icons,e),`must be a valid Codicon name`),f=l.object({icon:d,title:l.string().trim().min(1,`title must not be empty`).optional(),description:l.string().trim().min(1,`description must not be empty`).optional()}).strict(),p=l.object({id:l.string(),path:l.string(),icon:d,title:l.string(),description:l.string().optional(),routeModule:l.string(),environments:l.array(l.enum([`local`,`deployed`])).optional()}).strict(),m=l.string().trim().min(1,`module reference must not be empty`),h=l.object({path:l.string(),icon:d,title:l.string(),description:l.string().optional(),environments:l.array(l.enum([`local`,`deployed`])).optional()}).strict(),g=l.object({document:m.optional(),plugins:l.array(l.object({id:l.string(),navigation:h,pageModule:m,api:l.unknown().optional()}).strict()).optional()}).strict();async function _(e={}){let t=a(o(e.dashboardDirectory??a(process.cwd(),`dashboard`)),`pages`),i;try{i=await r(t,{withFileTypes:!0})}catch(e){if(F(e)&&e.code===`ENOENT`)return[];throw new w(t,`could not read the pages directory`,e)}let s=i.filter(e=>e.isDirectory()&&!e.name.startsWith(`.`)).sort((e,t)=>P(e.name,t.name));return Promise.all(s.map(async({name:e})=>{let r=a(t,e);M(e,r,`page directory`);let i=a(r,`route.tsx`);try{await n(i)}catch(e){throw F(e)&&e.code===`ENOENT`?new w(i,`missing required React Router route.tsx`):new w(i,`could not read route.tsx`,e)}let o=await T(a(r,`page.yaml`));return{id:e,path:e,icon:o.icon,title:o?.title??N(e),...o?.description?{description:o.description}:{},routeModule:`pages/${e}/route.tsx`}}))}function v(e,t,n={}){let r=n.environment??`local`,i=new Set,a=[],o=A(e);for(let e of o.plugins??[]){if(M(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),i.has(e.id))throw new w(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);i.add(e.id);let t=D(e,`plugin`,r);t&&a.push(t)}let s=t.map(e=>({page:e,normalizedPage:E(e,`app`)})).sort((e,t)=>P(e.normalizedPage.path,t.normalizedPage.path));for(let{page:e,normalizedPage:t}of s)k(e,r)&&a.push(t);return O(a),a}function y(e,t){let n=A(e),r=new Set,i=[];for(let e of n.plugins??[]){if(M(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),r.has(e.id))throw new w(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);if(r.add(e.id),!e.api)continue;let n=j(e,`dashboard API`),a=t===`local`?n.localImplementationModule:n.deployedImplementationModule;a&&i.push({pluginId:e.id,apiModule:n.apiModule,implementationModule:a})}return i}function b(e){let t=[],n=[];for(let[r,i]of e.entries())t.push(`import { api as api${r} } from ${JSON.stringify(i.apiModule)}`,`import { createImplementation as createImplementation${r} } from ${JSON.stringify(i.implementationModule)}`),n.push(`{ api: api${r}, createImplementation: createImplementation${r} }`);return`${t.join(`
|
|
1
|
+
import{getDashboardPluginBuild as e}from"./config.js";import{createRequire as t}from"node:module";import{readFile as n,readdir as r}from"node:fs/promises";import{isAbsolute as i,join as a,resolve as o}from"node:path";import{icons as s}from"@iconify-json/codicon";import{parseDocument as c}from"yaml";import{z as l}from"zod";const u=/^[a-z0-9]+(?:-[a-z0-9]+)*$/u,d=l.string().refine(e=>Object.hasOwn(s.icons,e),`must be a valid Codicon name`),f=l.object({icon:d,title:l.string().trim().min(1,`title must not be empty`).optional(),description:l.string().trim().min(1,`description must not be empty`).optional(),layout:l.enum([`default`,`standalone`]).optional()}).strict(),p=l.object({id:l.string(),path:l.string(),icon:d,title:l.string(),description:l.string().optional(),layout:l.enum([`default`,`standalone`]).optional(),routeModule:l.string(),environments:l.array(l.enum([`local`,`deployed`])).optional()}).strict(),m=l.string().trim().min(1,`module reference must not be empty`),h=l.object({path:l.string(),icon:d,title:l.string(),description:l.string().optional(),environments:l.array(l.enum([`local`,`deployed`])).optional()}).strict(),g=l.object({document:m.optional(),plugins:l.array(l.object({id:l.string(),navigation:h,pageModule:m,api:l.unknown().optional()}).strict()).optional()}).strict();async function _(e={}){let t=a(o(e.dashboardDirectory??a(process.cwd(),`dashboard`)),`pages`),i;try{i=await r(t,{withFileTypes:!0})}catch(e){if(F(e)&&e.code===`ENOENT`)return[];throw new w(t,`could not read the pages directory`,e)}let s=i.filter(e=>e.isDirectory()&&!e.name.startsWith(`.`)).sort((e,t)=>P(e.name,t.name));return Promise.all(s.map(async({name:e})=>{let r=a(t,e);M(e,r,`page directory`);let i=a(r,`route.tsx`);try{await n(i)}catch(e){throw F(e)&&e.code===`ENOENT`?new w(i,`missing required React Router route.tsx`):new w(i,`could not read route.tsx`,e)}let o=await T(a(r,`page.yaml`));return{id:e,path:e,icon:o.icon,title:o?.title??N(e),...o?.description?{description:o.description}:{},...o?.layout?{layout:o.layout}:{},routeModule:`pages/${e}/route.tsx`}}))}function v(e,t,n={}){let r=n.environment??`local`,i=new Set,a=[],o=A(e);for(let e of o.plugins??[]){if(M(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),i.has(e.id))throw new w(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);i.add(e.id);let t=D(e,`plugin`,r);t&&a.push(t)}let s=t.map(e=>({page:e,normalizedPage:E(e,`app`)})).sort((e,t)=>P(e.normalizedPage.path,t.normalizedPage.path));for(let{page:e,normalizedPage:t}of s)k(e,r)&&a.push(t);return O(a),a}function y(e,t){let n=A(e),r=new Set,i=[];for(let e of n.plugins??[]){if(M(e.id,`dashboard.config.ts plugin "${e.id}"`,`plugin id`),r.has(e.id))throw new w(`dashboard.config.ts`,`duplicate plugin id "${e.id}"`);if(r.add(e.id),!e.api)continue;let n=j(e,`dashboard API`),a=t===`local`?n.localImplementationModule:n.deployedImplementationModule;a&&i.push({pluginId:e.id,apiModule:n.apiModule,implementationModule:a})}return i}function b(e){let t=[],n=[];for(let[r,i]of e.entries())t.push(`import { api as api${r} } from ${JSON.stringify(i.apiModule)}`,`import { createImplementation as createImplementation${r} } from ${JSON.stringify(i.implementationModule)}`),n.push(`{ api: api${r}, createImplementation: createImplementation${r} }`);return`${t.join(`
|
|
2
2
|
`)}\n\nexport const dashboardPlugins = [\n${n.map(e=>` ${e},`).join(`
|
|
3
|
-
`)}\n]\n`}function x(e,t){let n=[e.length>0?{index:!0,file:t.indexRoute}:{index:!0,file:t.emptyRoute},...e.map(e=>({id:`dashboard-page-${e.id}`,path:e.path,file:e.routeModule})),...t.notFoundRoute?[{path:`*`,file:t.notFoundRoute}]:[]];return[{id:`dashboard-shell`,file:t.shellRoute,children:n}]}function S(e,t={}){let n=o(t.dashboardDirectory??a(process.cwd(),`dashboard`));return e.map(e=>({...e,routeModule:e.source===`app`?o(n,e.routeModule):C(e.routeModule,t)}))}function C(e,n={}){let r=o(n.dashboardDirectory??a(process.cwd(),`dashboard`)),s=t(a(o(n.projectRoot??a(r,`..`)),`package.json`));if(i(e)||e.startsWith(`.`))return o(r,e);try{return s.resolve(e)}catch(t){throw new w(e,`could not resolve dashboard module`,t)}}var w=class extends Error{file;constructor(e,t,n){super(`${e}: ${t}`,{cause:n}),this.name=`DashboardCompositionError`,this.file=e}};async function T(e){let t;try{t=await n(e,`utf8`)}catch(t){throw F(t)&&t.code===`ENOENT`?new w(e,`missing required page.yaml with a Codicon icon`):new w(e,`could not read page metadata`,t)}let r=c(t,{prettyErrors:!0,strict:!0,uniqueKeys:!0});if(r.errors.length>0)throw new w(e,r.errors[0]?.message??`invalid YAML`);let i=f.safeParse(r.toJS());if(!i.success)throw new w(e,l.prettifyError(i.error));return i.data}function E(e,t,n){let r=t===`plugin`?`dashboard.config.ts plugin "${n??`unknown`}" page "${e.id}"`:e.routeModule,i=p.safeParse(e);if(!i.success)throw new w(r,l.prettifyError(i.error));let a=i.data;M(a.id,r,`page id`),M(a.path,r,`page path`);let o=a.title.trim();if(!o)throw new w(r,`page title must not be empty`);if(!a.routeModule.trim())throw new w(r,`page routeModule must not be empty`);let s=a.description?.trim();if(a.description!==void 0&&!s)throw new w(r,`page description must not be empty`);return{id:a.id,path:a.path,title:o,icon:a.icon,...s?{description:s}:{},routeModule:a.routeModule,source:t,...n?{pluginId:n}:{}}}function D(e,t,n){let r=`dashboard.config.ts plugin "${e.id}"`,i=h.safeParse(e.navigation);if(!i.success)throw new w(r,l.prettifyError(i.error));let a=i.data;if(M(e.id,r,`plugin id`),M(a.path,r,`navigation path`),!a.title.trim())throw new w(r,`navigation title must not be empty`);if(a.description!==void 0&&!a.description.trim())throw new w(r,`navigation description must not be empty`);if(!e.pageModule.trim())throw new w(r,`pageModule must not be empty`);if(!(a.environments&&!a.environments.includes(n))){if(e.api){let t=j(e,`dashboard API`);if(n===`local`&&!t.localImplementationModule||n===`deployed`&&!t.deployedImplementationModule)return}return E({id:e.id,path:a.path,title:a.title,icon:a.icon,...a.description?{description:a.description}:{},routeModule:e.pageModule,...a.environments?{environments:a.environments}:{}},t,e.id)}}function O(e){let t=new Map,n=new Map;for(let r of e){let e=t.get(r.id);if(e)throw new w(r.routeModule,`duplicate page id "${r.id}" also contributed by ${e.routeModule}`);t.set(r.id,r);let i=n.get(r.path);if(i)throw new w(r.routeModule,`duplicate page path "${r.path}" also contributed by ${i.routeModule}`);n.set(r.path,r)}}function k(e,t){return e.environments?e.environments.includes(t):!0}function A(e){let t=g.safeParse(e);if(!t.success)throw new w(`dashboard.config.ts`,l.prettifyError(t.error));return e}function j(t,n){let r=e(t);if(!r)throw new w(`dashboard.config.ts plugin "${t.id}"`,`${n} is missing its package-owned build descriptor`);if(t.api&&t.api.id!==t.id)throw new w(`dashboard.config.ts plugin "${t.id}"`,`API id "${t.api.id}" does not match the plugin id`);for(let e of[`apiModule`,`localImplementationModule`]){let n=r[e];if(typeof n!=`string`||!n.trim())throw new w(`dashboard.config.ts plugin "${t.id}"`,`build descriptor field "${e}" must be a non-empty module reference`)}if(r.deployedImplementationModule!==void 0&&(typeof r.deployedImplementationModule!=`string`||!r.deployedImplementationModule.trim()))throw new w(`dashboard.config.ts plugin "${t.id}"`,`build descriptor field "deployedImplementationModule" must be a non-empty module reference`);return r}function M(e,t,n){if(!u.test(e))throw new w(t,`${n} "${e}" must contain only lowercase letters, numbers, and single hyphens`)}function N(e){let t=e.split(`-`).join(` `);return`${t.charAt(0).toUpperCase()}${t.slice(1)}`}function P(e,t){return e<t?-1:+(e>t)}function F(e){return e instanceof Error&&`code`in e}export{w as DashboardCompositionError,v as composeDashboardManifest,y as composeDashboardPluginTarget,x as composeDashboardRoutes,_ as discoverDashboardPages,b as renderDashboardPluginTargetModule,C as resolveDashboardModuleReference,S as resolveDashboardRouteModules};
|
|
3
|
+
`)}\n]\n`}function x(e,t){let n=[e.length>0?{index:!0,file:t.indexRoute}:{index:!0,file:t.emptyRoute},...e.map(e=>({id:`dashboard-page-${e.id}`,path:e.path,file:e.routeModule})),...t.notFoundRoute?[{path:`*`,file:t.notFoundRoute}]:[]];return[{id:`dashboard-shell`,file:t.shellRoute,children:n}]}function S(e,t={}){let n=o(t.dashboardDirectory??a(process.cwd(),`dashboard`));return e.map(e=>({...e,routeModule:e.source===`app`?o(n,e.routeModule):C(e.routeModule,t)}))}function C(e,n={}){let r=o(n.dashboardDirectory??a(process.cwd(),`dashboard`)),s=t(a(o(n.projectRoot??a(r,`..`)),`package.json`));if(i(e)||e.startsWith(`.`))return o(r,e);try{return s.resolve(e)}catch(t){throw new w(e,`could not resolve dashboard module`,t)}}var w=class extends Error{file;constructor(e,t,n){super(`${e}: ${t}`,{cause:n}),this.name=`DashboardCompositionError`,this.file=e}};async function T(e){let t;try{t=await n(e,`utf8`)}catch(t){throw F(t)&&t.code===`ENOENT`?new w(e,`missing required page.yaml with a Codicon icon`):new w(e,`could not read page metadata`,t)}let r=c(t,{prettyErrors:!0,strict:!0,uniqueKeys:!0});if(r.errors.length>0)throw new w(e,r.errors[0]?.message??`invalid YAML`);let i=f.safeParse(r.toJS());if(!i.success)throw new w(e,l.prettifyError(i.error));return i.data}function E(e,t,n){let r=t===`plugin`?`dashboard.config.ts plugin "${n??`unknown`}" page "${e.id}"`:e.routeModule,i=p.safeParse(e);if(!i.success)throw new w(r,l.prettifyError(i.error));let a=i.data;M(a.id,r,`page id`),M(a.path,r,`page path`);let o=a.title.trim();if(!o)throw new w(r,`page title must not be empty`);if(!a.routeModule.trim())throw new w(r,`page routeModule must not be empty`);let s=a.description?.trim();if(a.description!==void 0&&!s)throw new w(r,`page description must not be empty`);return{id:a.id,path:a.path,title:o,icon:a.icon,...s?{description:s}:{},...a.layout?{layout:a.layout}:{},routeModule:a.routeModule,source:t,...n?{pluginId:n}:{}}}function D(e,t,n){let r=`dashboard.config.ts plugin "${e.id}"`,i=h.safeParse(e.navigation);if(!i.success)throw new w(r,l.prettifyError(i.error));let a=i.data;if(M(e.id,r,`plugin id`),M(a.path,r,`navigation path`),!a.title.trim())throw new w(r,`navigation title must not be empty`);if(a.description!==void 0&&!a.description.trim())throw new w(r,`navigation description must not be empty`);if(!e.pageModule.trim())throw new w(r,`pageModule must not be empty`);if(!(a.environments&&!a.environments.includes(n))){if(e.api){let t=j(e,`dashboard API`);if(n===`local`&&!t.localImplementationModule||n===`deployed`&&!t.deployedImplementationModule)return}return E({id:e.id,path:a.path,title:a.title,icon:a.icon,...a.description?{description:a.description}:{},routeModule:e.pageModule,...a.environments?{environments:a.environments}:{}},t,e.id)}}function O(e){let t=new Map,n=new Map;for(let r of e){let e=t.get(r.id);if(e)throw new w(r.routeModule,`duplicate page id "${r.id}" also contributed by ${e.routeModule}`);t.set(r.id,r);let i=n.get(r.path);if(i)throw new w(r.routeModule,`duplicate page path "${r.path}" also contributed by ${i.routeModule}`);n.set(r.path,r)}}function k(e,t){return e.environments?e.environments.includes(t):!0}function A(e){let t=g.safeParse(e);if(!t.success)throw new w(`dashboard.config.ts`,l.prettifyError(t.error));return e}function j(t,n){let r=e(t);if(!r)throw new w(`dashboard.config.ts plugin "${t.id}"`,`${n} is missing its package-owned build descriptor`);if(t.api&&t.api.id!==t.id)throw new w(`dashboard.config.ts plugin "${t.id}"`,`API id "${t.api.id}" does not match the plugin id`);for(let e of[`apiModule`,`localImplementationModule`]){let n=r[e];if(typeof n!=`string`||!n.trim())throw new w(`dashboard.config.ts plugin "${t.id}"`,`build descriptor field "${e}" must be a non-empty module reference`)}if(r.deployedImplementationModule!==void 0&&(typeof r.deployedImplementationModule!=`string`||!r.deployedImplementationModule.trim()))throw new w(`dashboard.config.ts plugin "${t.id}"`,`build descriptor field "deployedImplementationModule" must be a non-empty module reference`);return r}function M(e,t,n){if(!u.test(e))throw new w(t,`${n} "${e}" must contain only lowercase letters, numbers, and single hyphens`)}function N(e){let t=e.split(`-`).join(` `);return`${t.charAt(0).toUpperCase()}${t.slice(1)}`}function P(e,t){return e<t?-1:+(e>t)}function F(e){return e instanceof Error&&`code`in e}export{w as DashboardCompositionError,v as composeDashboardManifest,y as composeDashboardPluginTarget,x as composeDashboardRoutes,_ as discoverDashboardPages,b as renderDashboardPluginTargetModule,C as resolveDashboardModuleReference,S as resolveDashboardRouteModules};
|
package/dist/package/config.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { DashboardPluginApi } from "./api/contract.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/config.d.ts
|
|
4
4
|
type DashboardEnvironment = "local" | "deployed";
|
|
5
|
+
/** Whether Coreframe places floating navigation or the page owns navigation placement. */
|
|
6
|
+
type DashboardPageLayout = "default" | "standalone";
|
|
5
7
|
interface DashboardPageContribution {
|
|
6
8
|
/** Stable page identity. It must be a lowercase, URL-safe slug. */
|
|
7
9
|
id: string;
|
|
@@ -11,6 +13,8 @@ interface DashboardPageContribution {
|
|
|
11
13
|
/** Codicon name, for example `settings-gear`. */
|
|
12
14
|
icon: string;
|
|
13
15
|
description?: string;
|
|
16
|
+
/** Defaults to floating logo navigation. Standalone pages can place DashboardMenu themselves. */
|
|
17
|
+
layout?: DashboardPageLayout;
|
|
14
18
|
/** React Router framework route module, resolved by the dashboard build. */
|
|
15
19
|
routeModule: string;
|
|
16
20
|
/** Environments where the page can be included. Defaults to both. */
|
|
@@ -63,6 +67,7 @@ interface DashboardPageManifestEntry {
|
|
|
63
67
|
/** Codicon name, for example `settings-gear`. */
|
|
64
68
|
icon: string;
|
|
65
69
|
description?: string;
|
|
70
|
+
layout?: DashboardPageLayout;
|
|
66
71
|
routeModule: string;
|
|
67
72
|
source: "app" | "plugin";
|
|
68
73
|
pluginId?: string;
|
|
@@ -78,4 +83,4 @@ declare function definePlugin<const Plugin extends DashboardPlugin>(plugin: Plug
|
|
|
78
83
|
/** @internal Used by the dashboard build composer to read package-owned target metadata. */
|
|
79
84
|
declare function getDashboardPluginBuild(plugin: DashboardPlugin): DashboardPluginBuild | undefined;
|
|
80
85
|
//#endregion
|
|
81
|
-
export { DashboardConfig, DashboardEnvironment, DashboardPageContribution, DashboardPageManifestEntry, DashboardPlugin, DashboardPluginBuild, DashboardPluginNavigation, defineConfig, definePlugin, getDashboardPluginBuild };
|
|
86
|
+
export { DashboardConfig, DashboardEnvironment, DashboardPageContribution, DashboardPageLayout, DashboardPageManifestEntry, DashboardPlugin, DashboardPluginBuild, DashboardPluginNavigation, defineConfig, definePlugin, getDashboardPluginBuild };
|