@coreframe/dashboard 0.4.0 → 0.4.2

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
@@ -29,13 +29,35 @@ at runtime.
29
29
  Add app-owned routes at `dashboard/pages/<slug>/route.tsx`. An adjacent `page.yaml` must define
30
30
  `icon` as a Tabler name (for example, `icon: settings`) and may define `title`, `description`,
31
31
  and `layout`. Plugin navigation also requires `icon`. Navigation uses `src/assets/favicon.svg` for
32
- the logo and omits the project slug. With multiple pages, a small logo floats in the top-left corner and opens a
33
- navigation popover on hover, click, or keyboard activation. Pages own their headings, layout, and
34
- spacing; Coreframe adds no page header or content wrapper. Leave room around the floating logo.
35
- The logo and menu are omitted when the dashboard has at most one page, including project-placed menus.
32
+ the logo and omits the project slug. A small logo floats in the top-left corner and links to the
33
+ app’s home page at `/`. Hover briefly over the menu button beside the logo or click it to open navigation.
34
+ With focus on the menu button, ArrowDown and ArrowUp open the popover and focus the first or last link.
35
+ Escape closes the popover.
36
+ Pages own their headings, layout, and spacing.
37
+ Render `PageHeader` from `@coreframe/dashboard/ui` as a compact single row. Use a small,
38
+ breadcrumb-like title beside the floating logo and group page-level controls at the far right.
39
+ Put subtitles and filters below the header.
40
+
41
+ ```tsx
42
+ <Page>
43
+ <PageHeader className="jobs-header">
44
+ <h1 style={{ fontSize: "0.875rem" }}>Jobs</h1>
45
+ <RefreshButton />
46
+ </PageHeader>
47
+ <JobsContent />
48
+ </Page>
49
+ ```
50
+
51
+ Pass `className` or `style` to customize the header container. The inner row reserves space for
52
+ the floating logo using the shell’s CSS variables and can wrap when space is limited.
53
+ Standalone pages get zero automatic logo clearance.
36
54
  Icon names are resolved during composition. The browser receives only the selected SVGs and their
37
55
  dimensions, rather than the full Tabler catalog.
38
56
 
57
+ To add Settings, create `dashboard/pages/settings/route.tsx` and an adjacent `page.yaml` with
58
+ `icon: settings`. Coreframe pins the link below the scrollable page list, including when Settings
59
+ is the only page. The app owns the route and its content at `/__dashboard/settings`.
60
+
39
61
  Set `layout: standalone` to omit the floating logo. A standalone page may place `DashboardMenu`
40
62
  from `@coreframe/dashboard/web` in its own header or layout; it receives the current application and
41
63
  page list automatically:
@@ -69,8 +91,9 @@ React Router route graph and navigation manifest.
69
91
 
70
92
  The generated dashboard does not need route adapters, a document root, a query-client module, or an
71
93
  entry file. Keep those defaults in the package unless the dashboard build contract itself must
72
- change. The dashboard is intentionally configured with `ssr: false` and does not prerender pages or
73
- ship an app-owned server entry.
94
+ change. The dashboard is configured with `ssr: false` and does not ship an app-owned server entry.
95
+ Framework Mode still uses Vite's server environment in development and renders the root document
96
+ at build time to generate the SPA's HTML.
74
97
 
75
98
  Projects can opt into app-owned customization without copying the default scaffold:
76
99
 
@@ -80,6 +103,140 @@ Projects can opt into app-owned customization without copying the default scaffo
80
103
  loads after the generated Panda stylesheet for additional project CSS; and
81
104
  - `vite.config.ts` and `react-router.config.ts` remain small tool-level adapters for build changes.
82
105
 
106
+ ## Settings
107
+
108
+ Define settings in a module shared by the Settings route and any pages that use them.
109
+
110
+ ```ts
111
+ import { defineSettings } from "@coreframe/dashboard/settings"
112
+ import { z } from "zod"
113
+
114
+ export const settings = defineSettings({
115
+ dashboard: {
116
+ compactTables: {
117
+ schema: z.boolean(),
118
+ defaultValue: false,
119
+ },
120
+ },
121
+ publishing: {
122
+ requireApproval: {
123
+ schema: z.boolean(),
124
+ defaultValue: true,
125
+ storage: "server",
126
+ },
127
+ },
128
+ })
129
+ ```
130
+
131
+ Use `useSetting(settings.dashboard.compactTables)` from `@coreframe/dashboard/web` to read the
132
+ value and call `save(value)` for a single change. A setting has no loaded value while its first read
133
+ is pending. The hook exposes the loaded revision along with read and save errors.
134
+
135
+ For a form, use `useSettingsBatch()`. Stage each edited value with
136
+ `batch.stage(setting, value, { expectedRevision })`, passing the revision captured when the user
137
+ started editing. If omitted, staging uses the revision from the shared query cache and retains it
138
+ on subsequent edits. Call `await batch.save()` to commit. The batch keeps its staged values when
139
+ saving fails. Use `batch.clear()` to discard them. All settings in a batch must use the same
140
+ storage backend.
141
+
142
+ Browser settings are stored in `localStorage` on the dashboard's origin. Keep them to non-sensitive
143
+ preferences that only need to follow the current browser. Setting keys follow the namespace path,
144
+ such as `dashboard.compactTables`. Supply a stable `key` to keep existing persisted values when
145
+ renaming a property.
146
+
147
+ For server settings, wrap the routes or their shared content with
148
+ `<SettingsProvider sync={settingsSync}>` from `@coreframe/dashboard/web`. Use the same stable
149
+ adapter instance across pages. The adapter implements `SettingsSync` from
150
+ `@coreframe/dashboard/settings` and calls the app's authenticated API:
151
+
152
+ - `read(keys)` returns persisted values with opaque revisions. Omit unset keys to use defaults.
153
+ - `save(changes)` sends the whole batch. The server authorizes and validates every change, compares
154
+ each expected revision, and commits all changes in one transaction. A null revision means the key
155
+ was unset. After a conflict, have the adapter throw `SettingsConflictError` with the conflicting keys.
156
+
157
+ If the app switches between accounts or tenants without a page reload, scope the adapter instance
158
+ to the active identity and remount any open forms so stale drafts cannot carry over.
159
+
160
+ ## Client routing in development
161
+
162
+ Projects can opt into a browser Data Router during development. This requires the client-compatible
163
+ page contract below; the setting does not automatically migrate Framework route modules.
164
+
165
+ Set `dashboard.devRouter` in `coreframe.config.ts`:
166
+
167
+ ```ts
168
+ export default defineConfig({
169
+ dashboard: { devRouter: "client" },
170
+ })
171
+ ```
172
+
173
+ The generated `dashboard/vite.config.ts` selects `coreframeDashboardClientPlugin` from
174
+ `@coreframe/vite/dashboard-client` when Coreframe starts client development. Existing projects
175
+ must adopt this Vite adapter as well as the setting. The relevant adapter shape is:
176
+
177
+ ```ts
178
+ const clientRouter =
179
+ env.command === "serve" && process.env.COREFRAME_DASHBOARD_DEV_ROUTER === "client"
180
+
181
+ const routerPlugins = clientRouter
182
+ ? [coreframeDashboardClientPlugin({ projectRoot })]
183
+ : [coreframeDashboardAppPlugin({ projectRoot }), reactRouter()]
184
+ ```
185
+
186
+ Spread `routerPlugins` into the existing plugins array, preserving Panda and other project
187
+ transforms. Import both dashboard adapters and `reactRouter` in this config.
188
+
189
+ Run the ordinary `pnpm dev` or `pnpm exec coreframe dashboard dev --port 5174` command. Coreframe
190
+ starts plain Vite for the dashboard UI, generates its browser route list from the same pages and
191
+ plugins as Framework Mode, and runs Framework type generation initially and after changes under
192
+ `dashboard/pages/` or to `dashboard/dashboard.config.ts`. Generation failures stop dashboard
193
+ development with an error. Changes to configuration dependencies outside these paths may require
194
+ restarting development. The setting defaults to `"framework"`.
195
+
196
+ `coreframe typegen` and `coreframe dashboard build` continue to use Framework Mode. Keep
197
+ `react-router.config.ts`, including `ssr: false`. Production builds still evaluate modules in a
198
+ server environment and render the root document at build time, so successful client development
199
+ does not establish production build compatibility. Run the dashboard build before deploying.
200
+
201
+ Client-compatible dashboard pages:
202
+
203
+ - Export a default React component. Use router hooks such as `useLoaderData`, `useActionData`,
204
+ `useParams`, `useMatches`, and `useRouteError`; client routing does not supply Framework
205
+ component or error-boundary props.
206
+ - Use `clientLoader` and `clientAction` for browser data work, calling the app API or dashboard
207
+ plugin APIs directly. These functions receive Data Router arguments; `serverLoader` and
208
+ `serverAction` are unavailable. Data Router revalidation defaults apply in this development mode.
209
+ - May export `ErrorBoundary`, `HydrateFallback`, `handle`, and `shouldRevalidate`.
210
+ - Must keep imports and page code browser-safe. Client development does not strip server exports
211
+ or server-only imports. Exports named `loader`, `action`, `headers`, `meta`, `links`, `middleware`,
212
+ and `clientMiddleware` produce an unsupported-feature error when the page loads.
213
+ - Must avoid Framework-only components and link features such as `Meta`, `Links`, `Scripts`,
214
+ `prefetch`, and `discover`. Use React document metadata elements where needed.
215
+
216
+ For example, a page can use client loading and hooks in both router modes:
217
+
218
+ ```tsx
219
+ import { useLoaderData, type LoaderFunctionArgs } from "react-router"
220
+
221
+ export async function clientLoader({ request }: LoaderFunctionArgs) {
222
+ const response = await fetch("/api/operator-summary", { signal: request.signal })
223
+ if (!response.ok) throw response
224
+ return response.json() as Promise<{ total: number }>
225
+ }
226
+
227
+ export default function Overview() {
228
+ const data = useLoaderData<typeof clientLoader>()
229
+ return <h1>{data.total} items</h1>
230
+ }
231
+ ```
232
+
233
+ Remove any `document` override in `dashboard/dashboard.config.ts` before selecting client routing;
234
+ custom Framework documents are rejected at startup. Move required content and wrappers into page
235
+ components. Coreframe supplies the browser entry, query provider, navigation, default page title,
236
+ favicon, styles, Sculpted runtime, and managed development overlay. The local dashboard API still
237
+ loads Node implementations through Vite's server environment. Its existing app-session admin
238
+ checks and same-origin request rules apply to both router modes.
239
+
83
240
  ## Style overrides
84
241
 
85
242
  The dashboard app's Panda build generates all dashboard styles, including the document reset,
@@ -116,8 +273,8 @@ globalCss: {
116
273
  },
117
274
  ```
118
275
 
119
- The logo button exposes `aria-expanded`; navigation links expose `aria-current="page"` for the
120
- current page. The reusable UI uses Panda recipe classes
276
+ The `.coreframe-dashboard__menu-toggle` button exposes its state through `aria-expanded`.
277
+ The current navigation link exposes `aria-current="page"`. The reusable UI uses Panda recipe classes
121
278
  such as `.dashboard-button` and `.dashboard-section__root`.
122
279
 
123
280
  Sculpted source editing applies to supported project-owned static Panda `css({ ... })` sources;
@@ -0,0 +1,7 @@
1
+ import { NonIndexRouteObject } from "react-router";
2
+
3
+ //#region src/app/client-route.d.ts
4
+ /** Adapts the supported browser-only subset of Framework route modules. */
5
+ declare function adaptClientRoute(module: Record<string, unknown>, file: string): Pick<NonIndexRouteObject, "Component" | "loader" | "action" | "ErrorBoundary" | "HydrateFallback" | "handle" | "shouldRevalidate">;
6
+ //#endregion
7
+ export { adaptClientRoute };
@@ -0,0 +1 @@
1
+ function e(e,t){for(let n of[`loader`,`action`,`headers`,`meta`,`links`,`middleware`,`clientMiddleware`])if(n in e)throw Error(`Dashboard client routing does not support the ${n} export in ${t}. Use clientLoader/clientAction, router hooks, and browser-safe page code, or select framework routing.`);return{Component:e.default,loader:e.clientLoader,action:e.clientAction,ErrorBoundary:e.ErrorBoundary,HydrateFallback:e.HydrateFallback,handle:e.handle,shouldRevalidate:e.shouldRevalidate}}export{e as adaptClientRoute};
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ import{DashboardEmptyState as e}from"../web-shell/shell.js";import"./empty.js";import t from"./index-route.js";import n from"./not-found.js";import{DashboardProviders as r}from"./providers.js";import i,{ErrorBoundary as a}from"./shell.js";import{Outlet as o,ScrollRestoration as s,createBrowserRouter as c,useLocation as l}from"react-router";import{StrictMode as u}from"react";import{Fragment as d,jsx as f,jsxs as p}from"react/jsx-runtime";import{createRoot as m}from"react-dom/client";import{RouterProvider as h}from"react-router/dom";import{routes as g}from"virtual:coreframe-internal/dashboard/client-routes";import{dashboardApplication as _,dashboardManifest as v}from"virtual:coreframe-internal/dashboard/manifest";import"virtual:coreframe-internal/dashboard/styles";function y(){let{pathname:e}=l();return p(d,{children:[f(`title`,{children:`${v.find(t=>t.path===e.split(`/`).filter(Boolean)[0])?.title||`Dashboard`} | ${_.name}`}),f(`link`,{rel:`icon`,href:_.favicon}),f(o,{}),f(s,{})]})}const b=c([{id:`root`,Component:y,HydrateFallback:()=>f(`p`,{role:`status`,children:`Loading dashboard…`}),children:[{id:`dashboard-shell`,Component:i,ErrorBoundary:a,children:[{index:!0,Component:v.length?t:e},...g,{path:`*`,Component:n}]}]}],{basename:`/__dashboard/`});m(document.getElementById(`root`)).render(f(u,{children:f(r,{children:f(h,{router:b})})}));export{};
@@ -1 +1 @@
1
- import{Link as e}from"react-router";import{jsx as t,jsxs as n}from"react/jsx-runtime";function r(){return n(`section`,{className:`coreframe-dashboard__state`,"aria-labelledby":`dashboard-not-found-title`,children:[t(`p`,{className:`coreframe-dashboard__eyebrow`,children:`Coreframe Dashboard`}),t(`h1`,{id:`dashboard-not-found-title`,children:`Page not found`}),t(`p`,{children:`The requested dashboard page does not exist.`}),t(e,{className:`coreframe-dashboard__button`,to:`/`,prefetch:`intent`,viewTransition:!0,children:`Go to dashboard`})]})}export{r as default};
1
+ import{Link as e}from"react-router";import{jsx as t,jsxs as n}from"react/jsx-runtime";function r(){return n(`section`,{className:`coreframe-dashboard__state`,"aria-labelledby":`dashboard-not-found-title`,children:[t(`p`,{className:`coreframe-dashboard__eyebrow`,children:`Coreframe Dashboard`}),t(`h1`,{id:`dashboard-not-found-title`,children:`Page not found`}),t(`p`,{children:`The requested dashboard page does not exist.`}),t(e,{className:`coreframe-dashboard__button`,to:`/`,viewTransition:!0,children:`Go to dashboard`})]})}export{r as default};
@@ -0,0 +1 @@
1
+ import{DashboardSculptedRuntime as e}from"./sculpted-runtime.js";import{Suspense as t,lazy as n}from"react";import{jsx as r,jsxs as i}from"react/jsx-runtime";import{QueryClient as a,QueryClientProvider as o}from"@tanstack/react-query";const s=new a({defaultOptions:{queries:{retry:1,staleTime:3e4}}}),c=import.meta.env.VITE_COREFRAME_MANAGED_DEV_OVERLAY_DEBUG===`1`,l=import.meta.env.DEV&&(import.meta.env.COREFRAME_MANAGED_DEV||c),u=import.meta.env.DEV?n(()=>import(`virtual:coreframe-internal/dashboard/managed-dev-overlay`).then(({ManagedDevOverlay:e})=>({default:e}))):null;function d({children:n}){return i(o,{client:s,children:[n,import.meta.env.DEV?r(e,{}):null,u&&l?r(t,{fallback:null,children:r(u,{debug:c})}):null]})}export{d as DashboardProviders};
@@ -1 +1 @@
1
- import{DashboardSculptedRuntime as e}from"./sculpted-runtime.js";import{Links as t,Meta as n,Outlet as r,Scripts as i,ScrollRestoration as a}from"react-router";import{Suspense as o,lazy as s}from"react";import{jsx as c,jsxs as l}from"react/jsx-runtime";import{dashboardApplication as u,dashboardManifest as d}from"virtual:coreframe-internal/dashboard/manifest";import{QueryClient as f,QueryClientProvider as p}from"@tanstack/react-query";import*as m from"virtual:coreframe-internal/dashboard/document";import"virtual:coreframe-internal/dashboard/styles";const h=new f({defaultOptions:{queries:{retry:1,staleTime:3e4}}}),g=import.meta.env.VITE_COREFRAME_MANAGED_DEV_OVERLAY_DEBUG===`1`,_=import.meta.env.DEV&&(import.meta.env.COREFRAME_MANAGED_DEV||g),v=import.meta.env.DEV?s(()=>import(`virtual:coreframe-internal/dashboard/managed-dev-overlay`).then(({ManagedDevOverlay:e})=>({default:e}))):null;function y({children:r}){let s=m.Layout,u=l(p,{client:h,children:[r,import.meta.env.DEV?c(e,{}):null,v&&_?c(o,{fallback:null,children:c(v,{debug:g})}):null]});return s?c(s,{children:u}):l(`html`,{lang:`en`,children:[l(`head`,{children:[c(`meta`,{charSet:`UTF-8`}),c(`meta`,{name:`viewport`,content:`width=device-width, initial-scale=1`}),c(n,{}),c(t,{})]}),l(`body`,{children:[u,c(a,{}),c(i,{})]})]})}const b=({location:e})=>{let t=e.pathname.split(`/`).filter(Boolean)[0];return[{title:`${d.find(e=>e.path===t)?.title||`Dashboard`} | ${u.name}`}]},x=m.links??(()=>[{rel:`icon`,href:u.favicon}]),S=m.meta??b;function C(){let e=m.default;return c(e||r,{})}export{y as Layout,C as default,x as links,S as meta};
1
+ import{DashboardProviders as e}from"./providers.js";import{Links as t,Meta as n,Outlet as r,Scripts as i,ScrollRestoration as a}from"react-router";import{jsx as o,jsxs as s}from"react/jsx-runtime";import{dashboardApplication as c,dashboardManifest as l}from"virtual:coreframe-internal/dashboard/manifest";import"virtual:coreframe-internal/dashboard/styles";import*as u from"virtual:coreframe-internal/dashboard/document";function d({children:r}){let c=u.Layout,l=o(e,{children:r});return c?o(c,{children:l}):s(`html`,{lang:`en`,children:[s(`head`,{children:[o(`meta`,{charSet:`UTF-8`}),o(`meta`,{name:`viewport`,content:`width=device-width, initial-scale=1`}),o(n,{}),o(t,{})]}),s(`body`,{children:[l,o(a,{}),o(i,{})]})]})}const f=({location:e})=>{let t=e.pathname.split(`/`).filter(Boolean)[0];return[{title:`${l.find(e=>e.path===t)?.title||`Dashboard`} | ${c.name}`}]},p=u.links??(()=>[{rel:`icon`,href:c.favicon}]),m=u.meta??f;function h(){let e=u.default;return o(e||r,{})}export{d as Layout,h as default,p as links,m as meta};
@@ -0,0 +1,60 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/settings/index.d.ts
4
+ /** Values that can round-trip through JSON storage and a server API. */
5
+ type SettingValue = null | boolean | number | string | SettingValue[] | {
6
+ [key: string]: SettingValue;
7
+ };
8
+ type SettingStorage = "local" | "server";
9
+ interface SettingDefinition<Value extends SettingValue = SettingValue> {
10
+ schema: z.ZodType<Value>;
11
+ defaultValue: Value;
12
+ storage?: SettingStorage;
13
+ key?: string;
14
+ }
15
+ interface SettingsTree {
16
+ [name: string]: SettingDefinition | SettingsTree;
17
+ }
18
+ /** A typed setting reference returned by defineSettings. */
19
+ interface Setting<Value extends SettingValue = SettingValue> {
20
+ readonly key: string;
21
+ readonly schema: z.ZodType<Value>;
22
+ readonly defaultValue: Value;
23
+ readonly storage: SettingStorage;
24
+ }
25
+ type SettingReferences<Tree> = { readonly [Key in keyof Tree]: Tree[Key] extends SettingDefinition<infer Value> ? Setting<Value> : SettingReferences<Tree[Key]> };
26
+ type CheckedDefaults<Tree> = { [Key in keyof Tree]: Tree[Key] extends {
27
+ schema: z.ZodType<infer Value>;
28
+ } ? {
29
+ defaultValue: NoInfer<Value>;
30
+ } : CheckedDefaults<Tree[Key]> };
31
+ /**
32
+ * Declares namespaced settings. By default a setting is stored in the browser under its dotted
33
+ * path. Set key to preserve a persisted identity independently of the TypeScript property path.
34
+ * Schemas validate JSON values and must accept their own parsed output.
35
+ */
36
+ declare function defineSettings<const Tree extends SettingsTree>(tree: Tree & CheckedDefaults<Tree>): SettingReferences<Tree>;
37
+ /** A persisted value. A read omits keys that have never been set. */
38
+ interface SettingSnapshot {
39
+ key: string;
40
+ value: SettingValue;
41
+ revision: string;
42
+ }
43
+ /** One change and the revision the editor read. Null means the key was absent. */
44
+ interface SettingChange {
45
+ key: string;
46
+ value: SettingValue;
47
+ expectedRevision: string | null;
48
+ }
49
+ /** App-owned adapter. The server must authorize, validate, and commit each batch atomically. */
50
+ interface SettingsSync {
51
+ read(keys: readonly string[]): Promise<readonly SettingSnapshot[]>;
52
+ save(changes: readonly SettingChange[]): Promise<void>;
53
+ }
54
+ /** Throw from the sync adapter when an expected revision no longer matches. */
55
+ declare class SettingsConflictError extends Error {
56
+ readonly keys: readonly string[];
57
+ constructor(keys: readonly string[]);
58
+ }
59
+ //#endregion
60
+ export { Setting, SettingChange, SettingSnapshot, SettingStorage, SettingValue, SettingsConflictError, SettingsSync, defineSettings };
@@ -0,0 +1 @@
1
+ function e(e){let t=new Set;function n(e,r){return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,i])=>{if(!e||e.includes(`.`))throw Error(`Invalid setting path segment: "${e}".`);let a=[...r,e];if(typeof i.schema?.parse!=`function`)return[e,n(i,a)];let{schema:o,defaultValue:s,storage:c=`local`,key:l=a.join(`.`)}=i;if(!l||t.has(l))throw Error(`Empty or duplicate setting key: "${l}".`);return t.add(l),[e,Object.freeze({key:l,schema:o,defaultValue:o.parse(s),storage:c})]})))}return n(e,[])}var t=class extends Error{keys;constructor(e){super(`Settings changed since they were loaded: ${e.join(`, `)}.`),this.keys=e,this.name=`SettingsConflictError`}};export{t as SettingsConflictError,e as defineSettings};
@@ -0,0 +1 @@
1
+ import{SettingsConflictError as e}from"./index.js";import{z as t}from"zod";const n=`coreframe.dashboard.settings.v1`,r=t.array(t.object({key:t.string(),value:t.json(),revision:t.string()}));function i(){let e=globalThis.localStorage.getItem(n),t=e===null?[]:r.parse(JSON.parse(e));return new Map(t.map(e=>[e.key,e]))}const a={async read(e){let t=i();return e.flatMap(e=>{let n=t.get(e);return n?[n]:[]})},async save(t){function r(){let r=i(),a=t.filter(e=>(r.get(e.key)?.revision??null)!==e.expectedRevision);if(a.length>0)throw new e(a.map(({key:e})=>e));for(let{key:e,value:n}of t){let t=Array.from(globalThis.crypto.getRandomValues(new Uint32Array(4))).join(`-`);r.set(e,{key:e,value:n,revision:t})}globalThis.localStorage.setItem(n,JSON.stringify([...r.values()]))}globalThis.navigator.locks?await globalThis.navigator.locks.request(n,r):r()}};export{a as localSettings};
@@ -0,0 +1,37 @@
1
+ import { Setting, SettingValue, SettingsSync } from "./index.js";
2
+ import { ReactNode } from "react";
3
+
4
+ //#region src/settings/react.d.ts
5
+ /** Supplies the app's server settings adapter. Keep the adapter instance stable. */
6
+ declare function SettingsProvider({
7
+ sync,
8
+ children
9
+ }: {
10
+ sync: SettingsSync;
11
+ children: ReactNode;
12
+ }): import("react").JSX.Element;
13
+ interface SaveOptions {
14
+ /** Override the current revision with the one captured when editing began. */
15
+ expectedRevision?: string | null;
16
+ }
17
+ /** Reads a setting and saves individual changes using the last loaded revision by default. */
18
+ declare function useSetting<Value extends SettingValue>(setting: Setting<Value>): {
19
+ value: Value | undefined;
20
+ revision: string | null | undefined;
21
+ isLoading: boolean;
22
+ error: Error | null;
23
+ save: (value: NoInfer<Value>, options?: SaveOptions) => Promise<void>;
24
+ isSaving: boolean;
25
+ saveError: Error | null;
26
+ };
27
+ /** Stages settings for one storage backend and commits them as a batch. Failed saves keep the draft. */
28
+ declare function useSettingsBatch(): {
29
+ stage: <Value extends SettingValue>(setting: Setting<Value>, value: NoInfer<Value>, options?: SaveOptions) => void;
30
+ clear: () => void;
31
+ save: () => Promise<void>;
32
+ size: number;
33
+ isSaving: boolean;
34
+ error: Error | null;
35
+ };
36
+ //#endregion
37
+ export { SettingsProvider, useSetting, useSettingsBatch };
@@ -0,0 +1 @@
1
+ import{localSettings as e}from"./local.js";import{createContext as t,useContext as n,useRef as r,useState as i}from"react";import{jsx as a}from"react/jsx-runtime";import{useMutation as o,useQuery as s,useQueryClient as c}from"@tanstack/react-query";const l=t(void 0),u=new WeakMap;let d=0;function f({sync:e,children:t}){return a(l.Provider,{value:e,children:t})}function p(t,n){if(t===`local`)return e;if(!n)throw Error(`Server settings require a SettingsProvider with a sync adapter.`);return n}function m(e,t,n){let r;return e===`server`&&t&&(r=u.get(t),r===void 0&&(r=++d,u.set(t,r))),[`coreframe.dashboard.settings`,e,r??null,n]}async function h(e,t){let[n]=await e.read([t.key]);if(n&&(n.key!==t.key||typeof n.revision!=`string`))throw Error(`The settings adapter returned an invalid snapshot for "${t.key}".`);return n?{value:t.schema.parse(n.value),revision:n.revision}:{value:t.defaultValue,revision:null}}function g(){let e=c();return o({retry:!1,networkMode:`always`,mutationFn:async t=>{let[n]=t,{storage:r}=n.setting,{sync:i}=n;if(t.some(e=>e.setting.storage!==r||e.sync!==i))throw Error(`All settings in a batch must use the same storage backend.`);let a=p(r,i),o=t.map(({setting:e,value:t,expectedRevision:n})=>({key:e.key,value:e.schema.parse(t),expectedRevision:n})),s=o.map(({key:e})=>({queryKey:m(r,i,e),exact:!0}));try{await a.save(o)}finally{await Promise.all(s.map(t=>e.cancelQueries(t))),await Promise.all(s.map(t=>e.invalidateQueries(t)))}}})}function _(e){let t=n(l),r=s({queryKey:m(e.storage,t,e.key),queryFn:()=>h(p(e.storage,t),e),enabled:globalThis.document!==void 0,retry:!1,networkMode:`always`,staleTime:0}),i=g();async function a(n,a){let o=a?.expectedRevision===void 0?r.data?.revision:a.expectedRevision;if(o===void 0)throw r.error??Error(`Load setting "${e.key}" before saving it.`);await i.mutateAsync([{setting:e,value:n,expectedRevision:o,sync:e.storage===`server`?t:void 0}])}return{value:r.data?.value,revision:r.data?.revision,isLoading:r.isPending,error:r.error,save:a,isSaving:i.isPending,saveError:i.error}}function v(){let e=n(l),t=c(),a=g(),o=r(new Map),s=r(!1),[u,d]=i(0);function f(){if(s.current)throw Error(`The settings batch is already saving.`)}function p(n,r,i){f();let a=m(n.storage,e,n.key),s=JSON.stringify(a),c=o.current.get(s),l=i?.expectedRevision===void 0?c?c.expectedRevision:t.getQueryData(a)?.revision:i.expectedRevision;if(l===void 0)throw Error(`Load setting "${n.key}" before staging it.`);o.current.set(s,{setting:n,value:r,expectedRevision:l,sync:n.storage===`server`?e:void 0}),d(o.current.size)}function h(){f(),o.current.clear(),d(0),a.reset()}async function _(){f();let[t,...n]=o.current.values();if(!t)return;let r=[t,...n];if(r.some(t=>t.setting.storage===`server`&&t.sync!==e))throw Error(`The settings sync adapter changed. Clear the batch and reload the settings.`);s.current=!0;try{await a.mutateAsync(r),o.current.clear(),d(0)}finally{s.current=!1}}return{stage:p,clear:h,save:_,size:u,isSaving:a.isPending,error:a.error}}export{f as SettingsProvider,_ as useSetting,v as useSettingsBatch};
@@ -7,6 +7,11 @@ declare function Page({
7
7
  className,
8
8
  ...props
9
9
  }: PageProps): import("react").JSX.Element;
10
+ /** Page-level header with clearance for the shell's floating logo. Render at the top of a page. */
11
+ declare function PageHeader({
12
+ children,
13
+ ...props
14
+ }: HTMLAttributes<HTMLElement>): import("react").JSX.Element;
10
15
  interface SectionProps extends Omit<HTMLAttributes<HTMLElement>, "title"> {
11
16
  title?: ReactNode;
12
17
  description?: ReactNode;
@@ -154,4 +159,4 @@ declare function ConfirmDialog({
154
159
  ...props
155
160
  }: ConfirmDialogProps): import("react").JSX.Element | null;
156
161
  //#endregion
157
- export { Button, ButtonProps, ButtonSize, ButtonTone, ButtonVariant, ConfirmDialog, ConfirmDialogProps, EmptyState, ErrorState, Field, FieldProps, Page, PageProps, Section, SectionProps, StateProps, Status, StatusProps, StatusTone, Tabs, TabsListProps, TabsPanelProps, TabsProps, TabsTriggerProps };
162
+ export { Button, ButtonProps, ButtonSize, ButtonTone, ButtonVariant, ConfirmDialog, ConfirmDialogProps, EmptyState, ErrorState, Field, FieldProps, Page, PageHeader, PageProps, Section, SectionProps, StateProps, Status, StatusProps, StatusTone, Tabs, TabsListProps, TabsPanelProps, TabsProps, TabsTriggerProps };
@@ -1 +1 @@
1
- import{cx as e}from"../styled-system/css/cx.js";import{styles as t}from"./styles.js";import{cloneElement as n,createContext as r,forwardRef as i,useCallback as a,useContext as o,useEffect as s,useId as c,useMemo as l,useRef as u}from"react";import{jsx as d,jsxs as f}from"react/jsx-runtime";function p({className:n,...r}){return d(`div`,{...r,className:e(t.page(),n),"data-dashboard-page":`true`})}function m({actions:n,children:r,className:i,description:a,headingId:o,title:s,...l}){let u=c(),p=t.section(),m=s!=null||a!=null||n!=null,h=o??`dashboard-section-${k(u)}`;return f(`section`,{...l,className:e(p.root,i),"aria-labelledby":s==null?l[`aria-labelledby`]:h,children:[m?f(`header`,{className:p.header,children:[f(`div`,{children:[s==null?null:d(`h2`,{className:p.heading,id:h,children:s}),a==null?null:d(`p`,{className:p.description,children:a})]}),n==null?null:d(`div`,{className:p.actions,children:n})]}):null,d(`div`,{className:p.content,children:r})]})}const h=r(null);function g({children:n,className:r,id:i,onValueChange:o,orientation:s=`horizontal`,value:f,...p}){let m=c(),g=k(i??`dashboard-tabs-${m}`),_=u(new Map),v=a(e=>{e!==f&&o(e)},[o,f]),y=a((e,t)=>{t?_.current.set(e,t):_.current.delete(e)},[]),b=l(()=>({baseId:g,orientation:s,registerTrigger:y,select:v,triggerRefs:_,value:f}),[g,s,y,v,f]),x=t.tabs();return d(h.Provider,{value:b,children:d(`div`,{...p,className:e(x.root,r),"data-dashboard-tabs":`true`,"data-orientation":s,id:i??g,children:n})})}function _({className:n,...r}){let i=O(),a=t.tabs();return d(`div`,{...r,className:e(a.list,n),role:`tablist`,"aria-orientation":i.orientation})}function v({children:n,className:r,disabled:i=!1,onClick:a,onKeyDown:o,value:c,...l}){let f=O(),p=u(null),m=t.tabs(),h=`${f.baseId}-tab-${k(c)}`,g=`${f.baseId}-panel-${k(c)}`,_=f.value===c;s(()=>(f.registerTrigger(h,p.current),()=>f.registerTrigger(h,null)),[f,h]);function v(e){let t=e.key,n=f.orientation===`horizontal`,r=n&&t===`ArrowRight`||!n&&t===`ArrowDown`?1:n&&t===`ArrowLeft`||!n&&t===`ArrowUp`?-1:0,i=Array.from(f.triggerRefs.current.values()).filter(e=>!e.disabled);if(t!==`Home`&&t!==`End`&&r===0||i.length===0)return;let a=i.indexOf(e.currentTarget),o=i[t===`Home`?0:t===`End`?i.length-1:(a+r+i.length)%i.length];if(!o)return;e.preventDefault(),o.focus();let s=o.dataset.dashboardTabValue;s&&f.select(s)}return d(`button`,{...l,ref:p,className:e(m.trigger,r),type:`button`,role:`tab`,id:h,"aria-controls":g,"aria-selected":_,"data-dashboard-tab-value":c,disabled:i,tabIndex:_?0:-1,onClick:e=>{a?.(e),!e.defaultPrevented&&!i&&f.select(c)},onKeyDown:e=>{o?.(e),e.defaultPrevented||v(e)},children:n})}function y({children:n,className:r,forceMount:i=!1,value:a,...o}){let s=O(),c=t.tabs(),l=`${s.baseId}-panel-${k(a)}`,u=`${s.baseId}-tab-${k(a)}`,f=s.value===a;return!f&&!i?null:d(`div`,{...o,className:e(c.panel,r),id:l,role:`tabpanel`,"aria-labelledby":u,hidden:!f,tabIndex:0,children:n})}const b=Object.assign(g,{List:_,Panel:y,Trigger:v});function x({className:n,role:r=`status`,tone:i=`neutral`,...a}){return d(`span`,{...a,className:e(t.status({tone:i}),n),role:r})}const S=i(function({busy:n=!1,busyLabel:r=`Loading`,children:i,className:a,disabled:o=!1,href:s,size:c=`md`,tone:l=`accent`,variant:u=`solid`,...f},p){let m=f[`aria-label`],h=e(t.button({size:c,tone:l,variant:u}),a);if(s!==void 0){let{onClick:e,...t}=f;return d(`a`,{...t,ref:p,href:s,className:h,"aria-label":n?r:m,"aria-busy":n||void 0,"aria-disabled":o||n||void 0,tabIndex:o||n?-1:t.tabIndex,onClick:t=>{if(o||n){t.preventDefault();return}e?.(t)},children:i})}let{onClick:g,type:_=`button`,...v}=f;return d(`button`,{...v,ref:p,className:h,type:_,disabled:o||n,"aria-label":n?r:m,"aria-busy":n||void 0,onClick:e=>g?.(e),children:i})});function C({children:r,className:i,description:a,error:o,id:s,label:l,required:u=!1,...p}){let m=c(),h=t.field(),g=r.props,_=s??g.id??`dashboard-field-${k(m)}`,v=a==null?void 0:`${_}-description`,y=o==null?void 0:`${_}-error`,b=o!=null&&o!==!1,x=[g[`aria-describedby`],v,y].filter(Boolean).join(` `),S=n(r,{id:_,required:u||g.required,"aria-describedby":x||void 0,"aria-invalid":b||g[`aria-invalid`]||void 0,"aria-required":u||g[`aria-required`]||void 0});return f(`div`,{...p,className:e(h.root,i),"data-invalid":b?`true`:void 0,children:[f(`label`,{className:h.label,htmlFor:_,children:[l,u?d(`span`,{"aria-hidden":`true`,children:` *`}):null]}),S,a==null?null:d(`p`,{className:h.description,id:v,children:a}),b?d(`p`,{className:h.error,id:y,role:`alert`,children:o}):null]})}function w({action:n,children:r,className:i,message:a,title:o,variant:s,...l}){let u=c(),p=(s===`empty`?t.emptyState:t.errorState)(),m=`dashboard-${s}-${k(u)}`;return f(`section`,{...l,className:e(p.root,i),"aria-labelledby":l[`aria-labelledby`]??m,role:s===`error`?`alert`:void 0,children:[d(`h2`,{className:p.title,id:m,children:o}),a==null?null:d(`p`,{className:p.message,children:a}),r,n==null?null:d(`div`,{className:p.action,children:n})]})}function T(e){return d(w,{...e,variant:`empty`})}function E(e){return d(w,{...e,variant:`error`})}function D({busy:n=!1,cancelLabel:r=`Cancel`,children:i,className:a,confirmLabel:o=`Confirm`,confirmTone:l=`danger`,description:p,onConfirm:m,onMouseDown:h,onOpenChange:g,open:_,title:v,...y}){let b=c(),x=t.confirmDialog(),C=u(null),w=u(null),T=u(null),E=u(null),D=`dashboard-confirm-title-${k(b)}`,O=p==null?void 0:`dashboard-confirm-description-${k(b)}`;return s(()=>{if(!_){E.current?.focus(),E.current=null;return}E.current||=document.activeElement instanceof HTMLElement?document.activeElement:null,n?C.current?.focus():w.current?.focus()},[n,_]),s(()=>{if(!_)return;function e(e){if(e.key===`Escape`){if(n)return;e.preventDefault(),g(!1);return}if(e.key!==`Tab`)return;let t=C.current?Array.from(C.current.querySelectorAll(`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`)):[];if(t.length===0)return;let r=t[0],i=t[t.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),i?.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r?.focus())}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[n,g,_]),_?d(`div`,{...y,className:e(x.backdrop,a),"data-dashboard-confirm-dialog":`true`,onMouseDown:e=>{h?.(e),!e.defaultPrevented&&e.target===e.currentTarget&&!n&&g(!1)},children:f(`div`,{ref:C,className:x.content,role:`dialog`,"aria-modal":`true`,"aria-busy":n||void 0,"aria-labelledby":D,"aria-describedby":O,tabIndex:-1,children:[d(`h2`,{className:x.title,id:D,children:v}),p==null?null:d(`p`,{className:x.description,id:O,children:p}),i,f(`div`,{className:x.actions,children:[d(S,{ref:w,className:x.cancel,variant:`outline`,disabled:n,onClick:()=>g(!1),children:r}),d(S,{ref:T,className:x.confirm,busy:n,tone:l,onClick:()=>void m(),children:o})]})]})}):null}function O(){let e=o(h);if(!e)throw Error(`Dashboard Tabs compound components must be used inside <Tabs>`);return e}function k(e){return e.replace(/[^a-zA-Z0-9_-]/gu,`-`)}export{S as Button,D as ConfirmDialog,T as EmptyState,E as ErrorState,C as Field,p as Page,m as Section,x as Status,b as Tabs};
1
+ import{cx as e}from"../styled-system/css/cx.js";import{styles as t}from"./styles.js";import{cloneElement as n,createContext as r,forwardRef as i,useCallback as a,useContext as o,useEffect as s,useId as c,useMemo as l,useRef as u}from"react";import{jsx as d,jsxs as f}from"react/jsx-runtime";function p({className:n,...r}){return d(`div`,{...r,className:e(t.page(),n),"data-dashboard-page":`true`})}function m({children:e,...t}){return d(`header`,{...t,children:d(`div`,{className:`coreframe-dashboard__page-header-content`,children:e})})}function h({actions:n,children:r,className:i,description:a,headingId:o,title:s,...l}){let u=c(),p=t.section(),m=s!=null||a!=null||n!=null,h=o??`dashboard-section-${A(u)}`;return f(`section`,{...l,className:e(p.root,i),"aria-labelledby":s==null?l[`aria-labelledby`]:h,children:[m?f(`header`,{className:p.header,children:[f(`div`,{children:[s==null?null:d(`h2`,{className:p.heading,id:h,children:s}),a==null?null:d(`p`,{className:p.description,children:a})]}),n==null?null:d(`div`,{className:p.actions,children:n})]}):null,d(`div`,{className:p.content,children:r})]})}const g=r(null);function _({children:n,className:r,id:i,onValueChange:o,orientation:s=`horizontal`,value:f,...p}){let m=c(),h=A(i??`dashboard-tabs-${m}`),_=u(new Map),v=a(e=>{e!==f&&o(e)},[o,f]),y=a((e,t)=>{t?_.current.set(e,t):_.current.delete(e)},[]),b=l(()=>({baseId:h,orientation:s,registerTrigger:y,select:v,triggerRefs:_,value:f}),[h,s,y,v,f]),x=t.tabs();return d(g.Provider,{value:b,children:d(`div`,{...p,className:e(x.root,r),"data-dashboard-tabs":`true`,"data-orientation":s,id:i??h,children:n})})}function v({className:n,...r}){let i=k(),a=t.tabs();return d(`div`,{...r,className:e(a.list,n),role:`tablist`,"aria-orientation":i.orientation})}function y({children:n,className:r,disabled:i=!1,onClick:a,onKeyDown:o,value:c,...l}){let f=k(),p=u(null),m=t.tabs(),h=`${f.baseId}-tab-${A(c)}`,g=`${f.baseId}-panel-${A(c)}`,_=f.value===c;s(()=>(f.registerTrigger(h,p.current),()=>f.registerTrigger(h,null)),[f,h]);function v(e){let t=e.key,n=f.orientation===`horizontal`,r=n&&t===`ArrowRight`||!n&&t===`ArrowDown`?1:n&&t===`ArrowLeft`||!n&&t===`ArrowUp`?-1:0,i=Array.from(f.triggerRefs.current.values()).filter(e=>!e.disabled);if(t!==`Home`&&t!==`End`&&r===0||i.length===0)return;let a=i.indexOf(e.currentTarget),o=i[t===`Home`?0:t===`End`?i.length-1:(a+r+i.length)%i.length];if(!o)return;e.preventDefault(),o.focus();let s=o.dataset.dashboardTabValue;s&&f.select(s)}return d(`button`,{...l,ref:p,className:e(m.trigger,r),type:`button`,role:`tab`,id:h,"aria-controls":g,"aria-selected":_,"data-dashboard-tab-value":c,disabled:i,tabIndex:_?0:-1,onClick:e=>{a?.(e),!e.defaultPrevented&&!i&&f.select(c)},onKeyDown:e=>{o?.(e),e.defaultPrevented||v(e)},children:n})}function b({children:n,className:r,forceMount:i=!1,value:a,...o}){let s=k(),c=t.tabs(),l=`${s.baseId}-panel-${A(a)}`,u=`${s.baseId}-tab-${A(a)}`,f=s.value===a;return!f&&!i?null:d(`div`,{...o,className:e(c.panel,r),id:l,role:`tabpanel`,"aria-labelledby":u,hidden:!f,tabIndex:0,children:n})}const x=Object.assign(_,{List:v,Panel:b,Trigger:y});function S({className:n,role:r=`status`,tone:i=`neutral`,...a}){return d(`span`,{...a,className:e(t.status({tone:i}),n),role:r})}const C=i(function({busy:n=!1,busyLabel:r=`Loading`,children:i,className:a,disabled:o=!1,href:s,size:c=`md`,tone:l=`accent`,variant:u=`solid`,...f},p){let m=f[`aria-label`],h=e(t.button({size:c,tone:l,variant:u}),a);if(s!==void 0){let{onClick:e,...t}=f;return d(`a`,{...t,ref:p,href:s,className:h,"aria-label":n?r:m,"aria-busy":n||void 0,"aria-disabled":o||n||void 0,tabIndex:o||n?-1:t.tabIndex,onClick:t=>{if(o||n){t.preventDefault();return}e?.(t)},children:i})}let{onClick:g,type:_=`button`,...v}=f;return d(`button`,{...v,ref:p,className:h,type:_,disabled:o||n,"aria-label":n?r:m,"aria-busy":n||void 0,onClick:e=>g?.(e),children:i})});function w({children:r,className:i,description:a,error:o,id:s,label:l,required:u=!1,...p}){let m=c(),h=t.field(),g=r.props,_=s??g.id??`dashboard-field-${A(m)}`,v=a==null?void 0:`${_}-description`,y=o==null?void 0:`${_}-error`,b=o!=null&&o!==!1,x=[g[`aria-describedby`],v,y].filter(Boolean).join(` `),S=n(r,{className:typeof r.type==`string`?e(h.control,g.className):g.className,id:_,required:u||g.required,"aria-describedby":x||void 0,"aria-invalid":b||g[`aria-invalid`]||void 0,"aria-required":u||g[`aria-required`]||void 0});return f(`div`,{...p,className:e(h.root,i),"data-invalid":b?`true`:void 0,children:[f(`label`,{className:h.label,htmlFor:_,children:[l,u?d(`span`,{"aria-hidden":`true`,children:` *`}):null]}),r.type===`select`?f(`span`,{className:`coreframe-dashboard__select`,children:[S,d(`svg`,{"aria-hidden":`true`,width:`16`,height:`16`,viewBox:`0 0 24 24`,children:d(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`m6 9l6 6l6-6`})})]}):S,a==null?null:d(`p`,{className:h.description,id:v,children:a}),b?d(`p`,{className:h.error,id:y,role:`alert`,children:o}):null]})}function T({action:n,children:r,className:i,message:a,title:o,variant:s,...l}){let u=c(),p=(s===`empty`?t.emptyState:t.errorState)(),m=`dashboard-${s}-${A(u)}`;return f(`section`,{...l,className:e(p.root,i),"aria-labelledby":l[`aria-labelledby`]??m,role:s===`error`?`alert`:void 0,children:[d(`h2`,{className:p.title,id:m,children:o}),a==null?null:d(`p`,{className:p.message,children:a}),r,n==null?null:d(`div`,{className:p.action,children:n})]})}function E(e){return d(T,{...e,variant:`empty`})}function D(e){return d(T,{...e,variant:`error`})}function O({busy:n=!1,cancelLabel:r=`Cancel`,children:i,className:a,confirmLabel:o=`Confirm`,confirmTone:l=`danger`,description:p,onConfirm:m,onMouseDown:h,onOpenChange:g,open:_,title:v,...y}){let b=c(),x=t.confirmDialog(),S=u(null),w=u(null),T=u(null),E=u(null),D=`dashboard-confirm-title-${A(b)}`,O=p==null?void 0:`dashboard-confirm-description-${A(b)}`;return s(()=>{if(!_){E.current?.focus(),E.current=null;return}E.current||=document.activeElement instanceof HTMLElement?document.activeElement:null,n?S.current?.focus():w.current?.focus()},[n,_]),s(()=>{if(!_)return;function e(e){if(e.key===`Escape`){if(n)return;e.preventDefault(),g(!1);return}if(e.key!==`Tab`)return;let t=S.current?Array.from(S.current.querySelectorAll(`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`)):[];if(t.length===0)return;let r=t[0],i=t[t.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),i?.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r?.focus())}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[n,g,_]),_?d(`div`,{...y,className:e(x.backdrop,a),"data-dashboard-confirm-dialog":`true`,onMouseDown:e=>{h?.(e),!e.defaultPrevented&&e.target===e.currentTarget&&!n&&g(!1)},children:f(`div`,{ref:S,className:x.content,role:`dialog`,"aria-modal":`true`,"aria-busy":n||void 0,"aria-labelledby":D,"aria-describedby":O,tabIndex:-1,children:[d(`h2`,{className:x.title,id:D,children:v}),p==null?null:d(`p`,{className:x.description,id:O,children:p}),i,f(`div`,{className:x.actions,children:[d(C,{ref:w,className:x.cancel,variant:`outline`,disabled:n,onClick:()=>g(!1),children:r}),d(C,{ref:T,className:x.confirm,busy:n,tone:l,onClick:()=>void m(),children:o})]})]})}):null}function k(){let e=o(g);if(!e)throw Error(`Dashboard Tabs compound components must be used inside <Tabs>`);return e}function A(e){return e.replace(/[^a-zA-Z0-9_-]/gu,`-`)}export{C as Button,O as ConfirmDialog,E as EmptyState,D as ErrorState,w as Field,p as Page,m as PageHeader,h as Section,S as Status,x as Tabs};
@@ -1,3 +1,4 @@
1
1
  import { DashboardMenu, DashboardMenuProps } from "./menu.js";
2
2
  import { DashboardEmptyState, DashboardErrorBoundary, DashboardIndexRedirect, DashboardShell, DashboardShellProps } from "./shell.js";
3
- export { DashboardEmptyState, DashboardErrorBoundary, DashboardIndexRedirect, DashboardMenu, type DashboardMenuProps, DashboardShell, type DashboardShellProps };
3
+ import { SettingsProvider, useSetting, useSettingsBatch } from "../settings/react.js";
4
+ export { DashboardEmptyState, DashboardErrorBoundary, DashboardIndexRedirect, DashboardMenu, type DashboardMenuProps, DashboardShell, type DashboardShellProps, SettingsProvider, useSetting, useSettingsBatch };
@@ -1 +1 @@
1
- import{DashboardMenu as e}from"./menu.js";import{DashboardEmptyState as t,DashboardErrorBoundary as n,DashboardIndexRedirect as r,DashboardShell as i}from"./shell.js";export{t as DashboardEmptyState,n as DashboardErrorBoundary,r as DashboardIndexRedirect,e as DashboardMenu,i as DashboardShell};
1
+ import{DashboardMenu as e}from"./menu.js";import{DashboardEmptyState as t,DashboardErrorBoundary as n,DashboardIndexRedirect as r,DashboardShell as i}from"./shell.js";import{SettingsProvider as a,useSetting as o,useSettingsBatch as s}from"../settings/react.js";export{t as DashboardEmptyState,n as DashboardErrorBoundary,r as DashboardIndexRedirect,e as DashboardMenu,i as DashboardShell,a as SettingsProvider,o as useSetting,s as useSettingsBatch};
@@ -11,9 +11,9 @@ interface DashboardNavigation {
11
11
  interface DashboardMenuProps {
12
12
  className?: string;
13
13
  }
14
- /** Logo and navigation popover. Place inside a dashboard page to own its position. */
14
+ /** App home link and dashboard navigation button. */
15
15
  declare function DashboardMenu({
16
16
  className
17
- }: DashboardMenuProps): import("react").JSX.Element | null;
17
+ }: DashboardMenuProps): import("react").JSX.Element;
18
18
  //#endregion
19
19
  export { DashboardMenu, DashboardMenuProps, DashboardNavigation };
@@ -1 +1 @@
1
- import{NavLink as e,useLocation as t}from"react-router";import{createContext as n,useContext as r,useEffect as i,useId as a,useRef as o,useState as s}from"react";import{jsx as c,jsxs as l}from"react/jsx-runtime";const u=n(void 0);function d({className:e}){let n=r(u),i=t();if(!n)throw Error(`DashboardMenu must be rendered inside a dashboard page.`);return n.pages.length<=1?null:c(f,{navigation:n,className:e},i.key)}function f({navigation:t,className:n}){let r=a(),u=o(null),d=o(null),f=o(null),p=o(void 0),[m,h]=s(!1);i(()=>{if(!m)return;if(p.current){let e=f.current?.querySelectorAll(`a`);(p.current===`first`?e?.[0]:e?.[e.length-1])?.focus(),p.current=void 0}function e(e){e.target instanceof Node&&!u.current?.contains(e.target)&&h(!1)}function t(e){e.key===`Escape`&&(h(!1),u.current?.contains(document.activeElement)&&d.current?.focus())}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[m]);let{application:g,pages:_}=t;return l(`div`,{ref:u,className:[`coreframe-dashboard__menu`,n].filter(Boolean).join(` `),onPointerEnter:e=>{e.pointerType!==`touch`&&h(!0)},onPointerLeave:()=>{u.current?.contains(document.activeElement)||h(!1)},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||h(!1)},children:[c(`button`,{ref:d,type:`button`,className:`coreframe-dashboard__logo`,"aria-label":`Dashboard navigation`,"aria-controls":r,"aria-expanded":m,onClick:()=>h(e=>!e),onKeyDown:e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;e.preventDefault();let t=e.key===`ArrowDown`?`first`:`last`;if(m){let e=f.current?.querySelectorAll(`a`);(t===`first`?e?.[0]:e?.[e.length-1])?.focus()}else p.current=t,h(!0)},children:g?c(`img`,{src:g.favicon,alt:``,className:`coreframe-dashboard__mark`}):c(`span`,{"aria-hidden":`true`,children:`C`})}),m?c(`div`,{className:`coreframe-dashboard__popover`,children:c(`nav`,{ref:f,id:r,className:`coreframe-dashboard__navigation`,"aria-label":`Dashboard`,children:c(`ul`,{className:`coreframe-dashboard__navigation-list`,children:_.map(t=>{let n=t.iconData;return c(`li`,{children:l(e,{className:`coreframe-dashboard__navigation-link`,to:`/${t.path}`,onClick:()=>{h(!1),d.current?.focus()},children:[c(`svg`,{"aria-hidden":`true`,className:`coreframe-dashboard__navigation-icon`,width:`20`,height:`20`,viewBox:`0 0 ${n.width} ${n.height}`,fill:`currentColor`,dangerouslySetInnerHTML:{__html:n.body}}),c(`span`,{className:`coreframe-dashboard__navigation-text`,children:t.title})]})},t.id)})})})}):null]})}export{d as DashboardMenu,u as DashboardNavigationContext};
1
+ import{NavLink as e,useLocation as t}from"react-router";import{createContext as n,useContext as r,useEffect as i,useId as a,useRef as o,useState as s}from"react";import{jsx as c,jsxs as l}from"react/jsx-runtime";const u=n(void 0);function d({className:e}){let n=r(u),i=t();if(!n)throw Error(`DashboardMenu must be rendered inside a dashboard page.`);return c(f,{navigation:n,className:e},i.key)}function f({navigation:t,className:n}){let r=a(),u=o(null),d=o(null),f=o(void 0),p=o(null),m=o(void 0),[h,g]=s(!1);i(()=>()=>clearTimeout(f.current),[]),i(()=>{if(!h)return;if(m.current){let e=p.current?.querySelectorAll(`a`);(m.current===`first`?e?.[0]:e?.[e.length-1])?.focus(),m.current=void 0}function e(e){e.target instanceof Node&&!u.current?.contains(e.target)&&g(!1)}function t(e){e.key===`Escape`&&(g(!1),u.current?.contains(document.activeElement)&&d.current?.focus())}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[h]);let{application:_,pages:v}=t,y=v.find(e=>e.source===`app`&&e.path===`settings`),b=v.filter(e=>e!==y),x=v.length>0,S=_?`${_.name} home`:`App home`,C=_?c(`img`,{src:_.favicon,alt:``,className:`coreframe-dashboard__mark`}):c(`span`,{"aria-hidden":`true`,children:`C`});function w(t){let n=t.iconData;return l(e,{className:`coreframe-dashboard__navigation-link`,to:`/${t.path}`,onClick:()=>{g(!1),d.current?.focus()},children:[c(`svg`,{"aria-hidden":`true`,className:`coreframe-dashboard__navigation-icon`,width:`20`,height:`20`,viewBox:`0 0 ${n.width} ${n.height}`,fill:`currentColor`,dangerouslySetInnerHTML:{__html:n.body}}),c(`span`,{className:`coreframe-dashboard__navigation-text`,children:t.title})]})}return l(`div`,{ref:u,className:[`coreframe-dashboard__menu`,n].filter(Boolean).join(` `),onPointerLeave:()=>{u.current?.contains(document.activeElement)||g(!1)},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||g(!1)},children:[c(`a`,{href:`/`,className:`coreframe-dashboard__logo`,"aria-label":S,children:C}),x&&c(`button`,{ref:d,type:`button`,className:`coreframe-dashboard__menu-toggle`,"aria-label":`Dashboard menu`,"aria-controls":h?r:void 0,"aria-expanded":h,onPointerEnter:e=>{e.pointerType!==`touch`&&!h&&(f.current=setTimeout(()=>g(!0),150))},onPointerLeave:()=>clearTimeout(f.current),onClick:()=>{clearTimeout(f.current),g(e=>!e)},onKeyDown:e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;e.preventDefault(),clearTimeout(f.current);let t=e.key===`ArrowDown`?`first`:`last`;if(h){let e=p.current?.querySelectorAll(`a`);(t===`first`?e?.[0]:e?.[e.length-1])?.focus()}else m.current=t,g(!0)},children:c(`svg`,{"aria-hidden":`true`,width:`16`,height:`16`,viewBox:`0 0 24 24`,children:c(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`2`,d:`M4 6h16M4 12h16M4 18h16`})})}),h?c(`div`,{className:`coreframe-dashboard__popover`,children:l(`nav`,{ref:p,id:r,className:`coreframe-dashboard__navigation`,"aria-label":`Dashboard`,children:[b.length>0?c(`ul`,{className:`coreframe-dashboard__navigation-list`,children:b.map(e=>c(`li`,{children:w(e)},e.id))}):null,y?c(`div`,{className:`coreframe-dashboard__navigation-settings`,children:w(y)}):null]})}):null]})}export{d as DashboardMenu,u as DashboardNavigationContext};
@@ -1,6 +1,6 @@
1
1
  import{DashboardMenu as e,DashboardNavigationContext as t}from"./menu.js";import{Link as n,Navigate as r,Outlet as i,isRouteErrorResponse as a,useLocation as o,useRouteError as s}from"react-router";import{jsx as c,jsxs as l}from"react/jsx-runtime";function u({pages:n,application:r}){let a=o().pathname.split(`/`).filter(Boolean)[0],s=n.find(e=>e.path===a)??(a?void 0:n[0]);return l(t,{value:{pages:n,application:r},children:[s?.layout===`standalone`?null:c(e,{className:`coreframe-dashboard__floating-navigation`}),c(i,{})]})}function d({pages:e}){let t=e[0];return t&&e.some(e=>e.source===`app`)?c(r,{replace:!0,to:`/${t.path}`}):c(f,{pages:e})}function f({pages:e=[]}){return l(`main`,{className:`coreframe-dashboard__introduction`,children:[c(`p`,{className:`coreframe-dashboard__eyebrow`,children:`Coreframe Dashboard`}),c(`h1`,{children:`Your dashboard starts here`}),c(`p`,{children:`A space for your app’s internal tools. Build ordinary React Router pages with your own content, layout, and API access.`}),e.length>0?l(`section`,{children:[c(`h2`,{children:`Installed tools`}),c(`ul`,{children:e.map(e=>c(`li`,{children:c(n,{to:`/${e.path}`,children:e.title})},e.id))})]}):null,l(`section`,{children:[c(`h2`,{children:`Add your first page`}),l(`p`,{children:[`Create `,c(`code`,{children:`dashboard/pages/overview/route.tsx`}),`:`]}),c(`pre`,{children:c(`code`,{children:`export default function Overview() {
2
2
  return <main><h1>Overview</h1></main>
3
3
  }`})}),l(`p`,{children:[`Add an adjacent `,c(`code`,{children:`page.yaml`}),` with a`,` `,c(`a`,{href:`https://icones.js.org/collection/tabler`,children:`Tabler icon`}),` and optional title:`]}),c(`pre`,{children:c(`code`,{children:`icon: home
4
- title: Overview`})}),l(`p`,{children:[`The page becomes available at `,c(`code`,{children:`/__dashboard/overview`}),`. This introduction disappears once an app-owned page exists.`]})]}),l(`section`,{children:[c(`h2`,{children:`Make it yours`}),l(`p`,{children:[`Pages own their headings and spacing. Customize default styles in`,` `,c(`code`,{children:`dashboard/panda.config.ts`}),`. A logo menu appears when there is more than one page.`]}),l(`p`,{children:[`Register optional reusable plugins in `,c(`code`,{children:`dashboard/dashboard.config.ts`}),`. App-owned pages are discovered automatically and do not need registration.`]})]}),l(`section`,{children:[c(`h2`,{children:`Disable the dashboard build`}),l(`p`,{children:[`If you do not need the dashboard, add this setting to the existing`,` `,c(`code`,{children:`defineConfig`}),` call in your project’s `,c(`code`,{children:`coreframe.config.ts`}),`:`]}),c(`pre`,{children:c(`code`,{children:`dashboard: {
4
+ title: Overview`})}),l(`p`,{children:[`The page becomes available at `,c(`code`,{children:`/__dashboard/overview`}),`. This introduction disappears once an app-owned page exists.`]})]}),l(`section`,{children:[c(`h2`,{children:`Make it yours`}),l(`p`,{children:[`Pages own their headings and spacing. Customize default styles in`,` `,c(`code`,{children:`dashboard/panda.config.ts`}),`. The logo links to your app’s home page. Hover over the button beside it or click it to open the menu.`]}),l(`p`,{children:[`Register optional reusable plugins in `,c(`code`,{children:`dashboard/dashboard.config.ts`}),`. App-owned pages are discovered automatically and do not need registration.`]})]}),l(`section`,{children:[c(`h2`,{children:`Disable the dashboard build`}),l(`p`,{children:[`If you do not need the dashboard, add this setting to the existing`,` `,c(`code`,{children:`defineConfig`}),` call in your project’s `,c(`code`,{children:`coreframe.config.ts`}),`:`]}),c(`pre`,{children:c(`code`,{children:`dashboard: {
5
5
  enabled: false,
6
6
  },`})}),c(`p`,{children:`This skips the dashboard bundle and its local development server. Remove the setting to enable the dashboard again.`})]})]})}function p(){let e=s(),t=a(e)&&e.status===404,r=import.meta.env.DEV&&e instanceof Error?e.message:t?`The requested dashboard page does not exist.`:`The dashboard hit an unexpected error.`;return l(`main`,{className:`coreframe-dashboard__state`,children:[c(`p`,{className:`coreframe-dashboard__eyebrow`,children:`Coreframe Dashboard`}),c(`h1`,{children:t?`Page not found`:`Dashboard unavailable`}),c(`p`,{children:r}),c(n,{className:`coreframe-dashboard__button`,to:`/`,children:`Go to dashboard`})]})}export{f as DashboardEmptyState,p as DashboardErrorBoundary,d as DashboardIndexRedirect,u as DashboardShell};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreframe/dashboard",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Reusable dashboard composition, shell, plugin, and authenticated runtime for Coreframe apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,6 +48,10 @@
48
48
  "types": "./dist/package/web-shell/index.d.ts",
49
49
  "default": "./dist/package/web-shell/index.js"
50
50
  },
51
+ "./settings": {
52
+ "types": "./dist/package/settings/index.d.ts",
53
+ "default": "./dist/package/settings/index.js"
54
+ },
51
55
  "./ui": {
52
56
  "types": "./dist/package/web/ui/index.d.ts",
53
57
  "default": "./dist/package/web/ui/index.js"
@@ -86,7 +90,7 @@
86
90
  "typescript": "6.0.3",
87
91
  "vite": "^8.3.5",
88
92
  "vitest": "^4.1.10",
89
- "@coreframe/panda": "0.1.15"
93
+ "@coreframe/panda": "0.1.17"
90
94
  },
91
95
  "scripts": {
92
96
  "build": "pnpm build:server",