najm-kit 2.8.2 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -27
- package/README.md +477 -237
- package/dist/{NajmUIProvider-BSbXaqak.d.ts → NajmUIProvider-BnReyojl.d.ts} +99 -163
- package/dist/adapters/app.d.ts +5 -1
- package/dist/adapters/app.mjs +3 -3
- package/dist/adapters/next.d.ts +28 -2
- package/dist/adapters/next.mjs +2 -2
- package/dist/chunk-7H6NFBQT.mjs +75 -0
- package/dist/{chunk-IRFFSAO2.mjs → chunk-EUQOTPLV.mjs} +26 -2
- package/dist/{chunk-USZUOJMK.mjs → chunk-FDONJASN.mjs} +163 -3
- package/dist/{chunk-GHMR45H3.mjs → chunk-HML2JZXT.mjs} +1 -1
- package/dist/chunk-JUYT2ISO.mjs +404 -0
- package/dist/{chunk-6OOBAEH2.mjs → chunk-TFHWLE7N.mjs} +1 -403
- package/dist/design-config-D_x1GCu3.d.ts +17 -0
- package/dist/design-types-Rkpt8Pg1.d.ts +159 -0
- package/dist/index.d.ts +60 -77
- package/dist/index.mjs +202 -220
- package/dist/json.mjs +3 -2
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.mjs +2 -0
- package/dist/server/react.d.ts +16 -0
- package/dist/server/react.mjs +23 -0
- package/dist/server/reactClientGuard.d.ts +2 -0
- package/dist/server/reactClientGuard.mjs +4 -0
- package/dist/uiBootstrap-Ci6K5j5t.d.ts +93 -0
- package/package.json +16 -2
package/dist/json.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Button } from './chunk-
|
|
2
|
-
export { NTableJson } from './chunk-
|
|
1
|
+
import { Button } from './chunk-JUYT2ISO.mjs';
|
|
2
|
+
export { NTableJson } from './chunk-JUYT2ISO.mjs';
|
|
3
3
|
import { cn } from './chunk-KVZACF4G.mjs';
|
|
4
|
+
import './chunk-TFHWLE7N.mjs';
|
|
4
5
|
import { useMemo, useRef, useCallback } from 'react';
|
|
5
6
|
import CodeMirror from '@uiw/react-codemirror';
|
|
6
7
|
import { json } from '@codemirror/lang-json';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { U as UiBootstrapConfig, a as UiBootstrapDiagnostic, b as UiBootstrapFailureReason, c as UiBootstrapFetcher, d as UiBootstrapLoader, e as UiBootstrapResource, f as UiBootstrapResources, g as UiBootstrapSnapshot, h as UiBootstrapValue, i as createUiBootstrapLoader } from '../uiBootstrap-Ci6K5j5t.js';
|
|
2
|
+
export { d as defineNajmDesignConfig, p as parseNajmDesignConfig, s as stringifyNajmDesignConfig } from '../design-config-D_x1GCu3.js';
|
|
3
|
+
export { N as NajmComponentThemeConfig, a as NajmDesignConfig, b as NajmLayoutConfig, c as NajmTypographyConfig } from '../design-types-Rkpt8Pg1.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { f as UiBootstrapResources, g as UiBootstrapSnapshot, U as UiBootstrapConfig } from '../uiBootstrap-Ci6K5j5t.js';
|
|
2
|
+
export { a as UiBootstrapDiagnostic, b as UiBootstrapFailureReason, c as UiBootstrapFetcher, e as UiBootstrapResource, h as UiBootstrapValue } from '../uiBootstrap-Ci6K5j5t.js';
|
|
3
|
+
|
|
4
|
+
interface ReactServerUiBootstrap<R extends UiBootstrapResources> {
|
|
5
|
+
/** Every resource for this request, resolved once and shared. */
|
|
6
|
+
load(): Promise<UiBootstrapSnapshot<R>>;
|
|
7
|
+
/** One resource, read off the same shared resolution. */
|
|
8
|
+
loadResource<K extends keyof R>(name: K): Promise<UiBootstrapSnapshot<R>[K]>;
|
|
9
|
+
/** `loadResource` pre-bound per name, for destructuring into a facade. */
|
|
10
|
+
loaders: {
|
|
11
|
+
[K in keyof R]: () => Promise<UiBootstrapSnapshot<R>[K]>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
declare function createReactServerUiBootstrap<R extends UiBootstrapResources>(config: UiBootstrapConfig<R>): ReactServerUiBootstrap<R>;
|
|
15
|
+
|
|
16
|
+
export { type ReactServerUiBootstrap, UiBootstrapConfig, UiBootstrapResources, UiBootstrapSnapshot, createReactServerUiBootstrap };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createUiBootstrapLoader } from '../chunk-7H6NFBQT.mjs';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
function createReactServerUiBootstrap(config) {
|
|
5
|
+
const cache2 = React.cache;
|
|
6
|
+
if (typeof cache2 !== "function") {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"najm-kit/server/react requires a React version that exports cache() (React 18.3 or newer). Upgrade react, or use createUiBootstrapLoader() from najm-kit/server directly."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const loader = createUiBootstrapLoader(config);
|
|
12
|
+
const load = cache2(loader.load);
|
|
13
|
+
const loadResource = async (name) => (await load())[name];
|
|
14
|
+
const loaders = Object.fromEntries(
|
|
15
|
+
Object.keys(config.resources).map((name) => [
|
|
16
|
+
name,
|
|
17
|
+
() => loadResource(name)
|
|
18
|
+
])
|
|
19
|
+
);
|
|
20
|
+
return { load, loadResource, loaders };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { createReactServerUiBootstrap };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// src/server/reactClientGuard.ts
|
|
2
|
+
throw new Error(
|
|
3
|
+
"najm-kit/server/react is a React Server Component module. It cannot be imported from a Client Component or any browser bundle. Seed the client from the server snapshot through NajmAppProvider instead, and use najm-kit/server for non-render server code."
|
|
4
|
+
);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** Reaches the application's own backend. The path is resource-relative. */
|
|
2
|
+
type UiBootstrapFetcher = (path: string) => Promise<Response>;
|
|
3
|
+
/** Why a resource fell back. Kept coarse enough to be worth alerting on. */
|
|
4
|
+
type UiBootstrapFailureReason = "fetch-failed" | "response-not-ok" | "invalid-json" | "invalid-envelope" | "invalid-payload";
|
|
5
|
+
/**
|
|
6
|
+
* What the application learns about a fallback.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately narrow. Response bodies, headers, cookies, and raw thrown
|
|
9
|
+
* values never appear here — a branding endpoint answering with a stack trace
|
|
10
|
+
* or a `Set-Cookie` must not become a log line. `error` is a normalized
|
|
11
|
+
* summary, never the thrown value itself.
|
|
12
|
+
*/
|
|
13
|
+
interface UiBootstrapDiagnostic {
|
|
14
|
+
resource: string;
|
|
15
|
+
reason: UiBootstrapFailureReason;
|
|
16
|
+
path: string;
|
|
17
|
+
/** Present for `response-not-ok`. */
|
|
18
|
+
status?: number;
|
|
19
|
+
/** Present when something was thrown; `"<name>: <message>"` for an `Error`. */
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
interface UiBootstrapResource<T> {
|
|
23
|
+
/** Passed to the fetcher unchanged. */
|
|
24
|
+
path: string;
|
|
25
|
+
/**
|
|
26
|
+
* Narrows the endpoint payload to the application's own type.
|
|
27
|
+
*
|
|
28
|
+
* Return `undefined` or throw to reject it — both are the same answer, so a
|
|
29
|
+
* parser built from `undefined` guards and one built from a schema that
|
|
30
|
+
* throws are equally usable without a wrapper.
|
|
31
|
+
*/
|
|
32
|
+
parse: (input: unknown) => T | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The built-in value, used whenever the endpoint cannot produce a valid one.
|
|
35
|
+
*
|
|
36
|
+
* A function, not a value: it is called per load, so an application that
|
|
37
|
+
* returns a fresh object keeps loads independent. Its failure is *not*
|
|
38
|
+
* caught — a missing factory theme is a broken build, and a second fallback
|
|
39
|
+
* would only hide it.
|
|
40
|
+
*/
|
|
41
|
+
fallback: () => T;
|
|
42
|
+
/** Per-resource envelope override. Defaults to the loader-level `select`. */
|
|
43
|
+
select?: (payload: unknown) => unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resources keyed by name.
|
|
47
|
+
*
|
|
48
|
+
* `any` rather than `unknown` in the value position: the payload types are
|
|
49
|
+
* unrelated to each other, and `UiBootstrapResource<unknown>` is not a
|
|
50
|
+
* supertype of `UiBootstrapResource<PublicBranding>` — `parse` and `fallback`
|
|
51
|
+
* make `T` invariant, so every concrete configuration would fail the
|
|
52
|
+
* constraint. Inference recovers the real type through `UiBootstrapValue`.
|
|
53
|
+
*/
|
|
54
|
+
type UiBootstrapResources = Record<string, UiBootstrapResource<any>>;
|
|
55
|
+
type UiBootstrapValue<R> = R extends UiBootstrapResource<infer T> ? T : never;
|
|
56
|
+
/** The resolved value of every configured resource, keyed by resource name. */
|
|
57
|
+
type UiBootstrapSnapshot<R extends UiBootstrapResources> = {
|
|
58
|
+
[K in keyof R]: UiBootstrapValue<R[K]>;
|
|
59
|
+
};
|
|
60
|
+
interface UiBootstrapConfig<R extends UiBootstrapResources> {
|
|
61
|
+
fetcher: UiBootstrapFetcher;
|
|
62
|
+
resources: R;
|
|
63
|
+
/**
|
|
64
|
+
* Unwraps the endpoint response.
|
|
65
|
+
*
|
|
66
|
+
* Defaults to Najm's `{ data }` envelope. Applications behind a different
|
|
67
|
+
* envelope — or none — pass their own; returning the payload unchanged is a
|
|
68
|
+
* valid selector, and throwing rejects the response as `invalid-envelope`.
|
|
69
|
+
*/
|
|
70
|
+
select?: (payload: unknown) => unknown;
|
|
71
|
+
/**
|
|
72
|
+
* Called once per fallback, never for a successful load.
|
|
73
|
+
*
|
|
74
|
+
* Optional because there is no sensible default: a package cannot know
|
|
75
|
+
* whether this application wants `console.warn`, a counter, or a pager. Its
|
|
76
|
+
* own failure is contained — an observability fault must not take the render
|
|
77
|
+
* with it.
|
|
78
|
+
*/
|
|
79
|
+
onDiagnostic?: (diagnostic: UiBootstrapDiagnostic) => void;
|
|
80
|
+
}
|
|
81
|
+
interface UiBootstrapLoader<R extends UiBootstrapResources> {
|
|
82
|
+
/** Every resource, loaded concurrently. */
|
|
83
|
+
load(): Promise<UiBootstrapSnapshot<R>>;
|
|
84
|
+
/** One resource on its own. */
|
|
85
|
+
loadResource<K extends keyof R>(name: K): Promise<UiBootstrapSnapshot<R>[K]>;
|
|
86
|
+
/** `loadResource` pre-bound per name, for destructuring into a facade. */
|
|
87
|
+
loaders: {
|
|
88
|
+
[K in keyof R]: () => Promise<UiBootstrapSnapshot<R>[K]>;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
declare function createUiBootstrapLoader<R extends UiBootstrapResources>(config: UiBootstrapConfig<R>): UiBootstrapLoader<R>;
|
|
92
|
+
|
|
93
|
+
export { type UiBootstrapConfig as U, type UiBootstrapDiagnostic as a, type UiBootstrapFailureReason as b, type UiBootstrapFetcher as c, type UiBootstrapLoader as d, type UiBootstrapResource as e, type UiBootstrapResources as f, type UiBootstrapSnapshot as g, type UiBootstrapValue as h, createUiBootstrapLoader as i };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "najm-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Reusable React UI component package for Najm framework",
|
|
@@ -32,6 +32,18 @@
|
|
|
32
32
|
"import": "./dist/adapters/app.mjs",
|
|
33
33
|
"default": "./dist/adapters/app.mjs"
|
|
34
34
|
},
|
|
35
|
+
"./server": {
|
|
36
|
+
"types": "./dist/server/index.d.ts",
|
|
37
|
+
"import": "./dist/server/index.mjs",
|
|
38
|
+
"default": "./dist/server/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./server/react": {
|
|
41
|
+
"types": "./dist/server/react.d.ts",
|
|
42
|
+
"react-server": "./dist/server/react.mjs",
|
|
43
|
+
"browser": "./dist/server/reactClientGuard.mjs",
|
|
44
|
+
"import": "./dist/server/react.mjs",
|
|
45
|
+
"default": "./dist/server/react.mjs"
|
|
46
|
+
},
|
|
35
47
|
"./package.json": "./package.json",
|
|
36
48
|
"./query": {
|
|
37
49
|
"types": "./dist/query.d.ts",
|
|
@@ -69,7 +81,9 @@
|
|
|
69
81
|
"dev:preview": "vite",
|
|
70
82
|
"preview": "vite preview",
|
|
71
83
|
"build:preview": "vite build",
|
|
72
|
-
"test": "bun test",
|
|
84
|
+
"test": "bun test && bun run test:rsc",
|
|
85
|
+
"test:rsc": "cd test/rsc && bun test --conditions react-server",
|
|
86
|
+
"test:next16": "bun run build && bun integration/next16-ui-bootstrap/run.ts",
|
|
73
87
|
"clean": "rimraf dist tsconfig.tsbuildinfo"
|
|
74
88
|
},
|
|
75
89
|
"peerDependencies": {
|