@devframes/json-render 0.8.2 → 0.9.0-beta.10
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/dist/hub.d.mts +19 -1
- package/dist/index.d.mts +86 -3
- package/dist/index.mjs +7 -4
- package/dist/node/index.d.mts +233 -8
- package/dist/node/index.mjs +2 -9
- package/dist/{view-index-BItK4ftT.mjs → view-index-CJ8aJJLZ.mjs} +45 -3
- package/package.json +7 -8
package/dist/hub.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { i as JsonRenderViewRef, n as JsonRenderView } from "./types-CC2-FD2H.mjs";
|
|
2
|
+
import { DockRenderer, DockRendererMountOptions } from "@devframes/hub/client";
|
|
2
3
|
import { DevframeDockEntryBase } from "@devframes/hub/types";
|
|
3
4
|
//#region src/hub.d.ts
|
|
4
5
|
/**
|
|
@@ -17,6 +18,23 @@ declare module '@devframes/hub/types' {
|
|
|
17
18
|
'json-render': DevframeJsonRenderDockEntry;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The mount options a hub viewer hands a json-render dock renderer — the
|
|
23
|
+
* hub's `DockRendererMountOptions` narrowed to the `'json-render'` entry.
|
|
24
|
+
* This protocol package owns the renderer contract so every frontend —
|
|
25
|
+
* `@devframes/json-render-ui`, a community renderer, a host page's own —
|
|
26
|
+
* implements one shared shape instead of re-declaring it.
|
|
27
|
+
*/
|
|
28
|
+
type JsonRenderDockMountOptions = DockRendererMountOptions<DevframeJsonRenderDockEntry>;
|
|
29
|
+
/**
|
|
30
|
+
* The renderer contract for `'json-render'` docks: a hub `DockRenderer`
|
|
31
|
+
* narrowed to {@link DevframeJsonRenderDockEntry}. Implement it to replace
|
|
32
|
+
* the reference frontend — register the implementation locally
|
|
33
|
+
* (`createDevframeClientHost({ renderers })`) or ship it as a prebuilt
|
|
34
|
+
* module registered through the hub's renderer manifest
|
|
35
|
+
* (`initHub({ renderers })`).
|
|
36
|
+
*/
|
|
37
|
+
type JsonRenderDockRenderer = DockRenderer<DevframeJsonRenderDockEntry>;
|
|
20
38
|
/**
|
|
21
39
|
* Build a `json-render` dock entry from a {@link JsonRenderView} and the dock
|
|
22
40
|
* metadata (id, title, icon, …). Projects the view down to its serializable
|
|
@@ -24,4 +42,4 @@ declare module '@devframes/hub/types' {
|
|
|
24
42
|
*/
|
|
25
43
|
declare function toJsonRenderDockEntry(view: JsonRenderView, meta: Omit<DevframeJsonRenderDockEntry, 'type' | 'view'>): DevframeJsonRenderDockEntry;
|
|
26
44
|
//#endregion
|
|
27
|
-
export { DevframeJsonRenderDockEntry, toJsonRenderDockEntry };
|
|
45
|
+
export { DevframeJsonRenderDockEntry, JsonRenderDockMountOptions, JsonRenderDockRenderer, toJsonRenderDockEntry };
|
package/dist/index.d.mts
CHANGED
|
@@ -133,9 +133,51 @@ declare const TreePropsSchema: z.ZodObject<{
|
|
|
133
133
|
data: z.ZodOptional<z.ZodUnknown>;
|
|
134
134
|
defaultExpanded: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
135
135
|
}, z.core.$strip>;
|
|
136
|
+
declare const TabsPropsSchema: z.ZodObject<{
|
|
137
|
+
tabs: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
|
|
138
|
+
value: z.ZodString;
|
|
139
|
+
label: z.ZodString;
|
|
140
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
141
|
+
badge: z.ZodOptional<z.ZodString>;
|
|
142
|
+
badgeVariant: z.ZodOptional<z.ZodEnum<{
|
|
143
|
+
success: "success";
|
|
144
|
+
default: "default";
|
|
145
|
+
warning: "warning";
|
|
146
|
+
danger: "danger";
|
|
147
|
+
info: "info";
|
|
148
|
+
}>>;
|
|
149
|
+
}, z.core.$loose>>, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
150
|
+
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
151
|
+
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
152
|
+
orientation: z.ZodOptional<z.ZodEnum<{
|
|
153
|
+
horizontal: "horizontal";
|
|
154
|
+
vertical: "vertical";
|
|
155
|
+
}>>;
|
|
156
|
+
}, z.core.$strip>;
|
|
157
|
+
declare const LinkPropsSchema: z.ZodObject<{
|
|
158
|
+
href: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
159
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
160
|
+
icon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
161
|
+
external: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
162
|
+
}, z.core.$strip>;
|
|
163
|
+
declare const SelectPropsSchema: z.ZodObject<{
|
|
164
|
+
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
165
|
+
options: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
166
|
+
value: z.ZodString;
|
|
167
|
+
label: z.ZodOptional<z.ZodString>;
|
|
168
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
169
|
+
description: z.ZodOptional<z.ZodString>;
|
|
170
|
+
}, z.core.$loose>]>>, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
171
|
+
placeholder: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
172
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
173
|
+
disabled: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
174
|
+
searchable: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
175
|
+
native: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
176
|
+
}, z.core.$strip>;
|
|
136
177
|
/**
|
|
137
178
|
* Map of base-catalog component name → Zod prop schema. The keys are the
|
|
138
|
-
* canonical component set (catalog v1
|
|
179
|
+
* canonical component set (catalog v1: the original fourteen plus the
|
|
180
|
+
* additive Tabs/Link/Select).
|
|
139
181
|
*/
|
|
140
182
|
declare const basePropSchemas: {
|
|
141
183
|
readonly Stack: z.ZodObject<{
|
|
@@ -269,6 +311,47 @@ declare const basePropSchemas: {
|
|
|
269
311
|
data: z.ZodOptional<z.ZodUnknown>;
|
|
270
312
|
defaultExpanded: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
271
313
|
}, z.core.$strip>;
|
|
314
|
+
readonly Tabs: z.ZodObject<{
|
|
315
|
+
tabs: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
|
|
316
|
+
value: z.ZodString;
|
|
317
|
+
label: z.ZodString;
|
|
318
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
319
|
+
badge: z.ZodOptional<z.ZodString>;
|
|
320
|
+
badgeVariant: z.ZodOptional<z.ZodEnum<{
|
|
321
|
+
success: "success";
|
|
322
|
+
default: "default";
|
|
323
|
+
warning: "warning";
|
|
324
|
+
danger: "danger";
|
|
325
|
+
info: "info";
|
|
326
|
+
}>>;
|
|
327
|
+
}, z.core.$loose>>, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
328
|
+
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
329
|
+
defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
330
|
+
orientation: z.ZodOptional<z.ZodEnum<{
|
|
331
|
+
horizontal: "horizontal";
|
|
332
|
+
vertical: "vertical";
|
|
333
|
+
}>>;
|
|
334
|
+
}, z.core.$strip>;
|
|
335
|
+
readonly Link: z.ZodObject<{
|
|
336
|
+
href: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
337
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
338
|
+
icon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
339
|
+
external: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
340
|
+
}, z.core.$strip>;
|
|
341
|
+
readonly Select: z.ZodObject<{
|
|
342
|
+
value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
343
|
+
options: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
344
|
+
value: z.ZodString;
|
|
345
|
+
label: z.ZodOptional<z.ZodString>;
|
|
346
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
347
|
+
description: z.ZodOptional<z.ZodString>;
|
|
348
|
+
}, z.core.$loose>]>>, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
349
|
+
placeholder: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
350
|
+
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
351
|
+
disabled: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
352
|
+
searchable: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
353
|
+
native: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodIntersection<z.ZodObject<{}, z.core.$loose>, z.ZodRecord<z.ZodString, z.ZodUnknown>>]>>;
|
|
354
|
+
}, z.core.$strip>;
|
|
272
355
|
};
|
|
273
356
|
/** Canonical base-catalog component name. */
|
|
274
357
|
type BaseComponentName = keyof typeof basePropSchemas;
|
|
@@ -303,7 +386,7 @@ declare const baseSchema: import("@json-render/core").Schema<{
|
|
|
303
386
|
}>;
|
|
304
387
|
}>;
|
|
305
388
|
/**
|
|
306
|
-
* The Devframes base catalog (catalog v1): the
|
|
389
|
+
* The Devframes base catalog (catalog v1): the seventeen canonical components
|
|
307
390
|
* with their Devframes-authored Zod prop schemas and descriptions, and an
|
|
308
391
|
* empty action set (actions are dispatched dynamically via the bridge, they
|
|
309
392
|
* are not declared here). Reference frontend libraries implement this set.
|
|
@@ -364,4 +447,4 @@ interface JsonRenderIndexEntry {
|
|
|
364
447
|
/** The shape of the view-index shared state: entries keyed by `stateKey`. */
|
|
365
448
|
type JsonRenderIndex = Record<string, JsonRenderIndexEntry>;
|
|
366
449
|
//#endregion
|
|
367
|
-
export { BadgePropsSchema, type BaseComponentName, ButtonPropsSchema, CardPropsSchema, type Catalog, CodeBlockPropsSchema, DataTablePropsSchema, type DevframeJsonRenderSpec, DividerPropsSchema, IconPropsSchema, type InferComponentProps, JSON_RENDER_INDEX_KEY, type JsonRenderIndex, type JsonRenderIndexEntry, type JsonRenderView, type JsonRenderViewInlineRef, type JsonRenderViewRef, type JsonRenderViewStateRef, KeyValueTablePropsSchema, ProgressPropsSchema, type Spec, StackPropsSchema, type StateModel, type StateStore, SwitchPropsSchema, TextInputPropsSchema, TextPropsSchema, TreePropsSchema, type UIElement, baseCatalog, baseComponentNames, basePropSchemas, baseSchema };
|
|
450
|
+
export { BadgePropsSchema, type BaseComponentName, ButtonPropsSchema, CardPropsSchema, type Catalog, CodeBlockPropsSchema, DataTablePropsSchema, type DevframeJsonRenderSpec, DividerPropsSchema, IconPropsSchema, type InferComponentProps, JSON_RENDER_INDEX_KEY, type JsonRenderIndex, type JsonRenderIndexEntry, type JsonRenderView, type JsonRenderViewInlineRef, type JsonRenderViewRef, type JsonRenderViewStateRef, KeyValueTablePropsSchema, LinkPropsSchema, ProgressPropsSchema, SelectPropsSchema, type Spec, StackPropsSchema, type StateModel, type StateStore, SwitchPropsSchema, TabsPropsSchema, TextInputPropsSchema, TextPropsSchema, TreePropsSchema, type UIElement, baseCatalog, baseComponentNames, basePropSchemas, baseSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as TextPropsSchema, a as CodeBlockPropsSchema, b as basePropSchemas, c as IconPropsSchema, d as ProgressPropsSchema, f as SelectPropsSchema, g as TextInputPropsSchema, h as TabsPropsSchema, i as CardPropsSchema, l as KeyValueTablePropsSchema, m as SwitchPropsSchema, n as BadgePropsSchema, o as DataTablePropsSchema, p as StackPropsSchema, r as ButtonPropsSchema, s as DividerPropsSchema, t as JSON_RENDER_INDEX_KEY, u as LinkPropsSchema, v as TreePropsSchema, y as baseComponentNames } from "./view-index-CJ8aJJLZ.mjs";
|
|
2
2
|
import { defineCatalog, defineSchema } from "@json-render/core";
|
|
3
3
|
//#region src/catalog.ts
|
|
4
4
|
/**
|
|
@@ -39,10 +39,13 @@ const componentDescriptions = {
|
|
|
39
39
|
DataTable: "Tabular data with columns, rows and optional scroll height.",
|
|
40
40
|
CodeBlock: "Preformatted code block with a filename and language label.",
|
|
41
41
|
Progress: "Determinate progress bar.",
|
|
42
|
-
Tree: "Recursive object/array viewer with expandable nodes."
|
|
42
|
+
Tree: "Recursive object/array viewer with expandable nodes.",
|
|
43
|
+
Tabs: "Tabbed container; each child renders under the positionally-matching tab.",
|
|
44
|
+
Link: "Hyperlink to a safe-scheme URL with an optional icon.",
|
|
45
|
+
Select: "Single-select dropdown bound to a state value, with optional search or a native `<select>` fallback."
|
|
43
46
|
};
|
|
44
47
|
/**
|
|
45
|
-
* The Devframes base catalog (catalog v1): the
|
|
48
|
+
* The Devframes base catalog (catalog v1): the seventeen canonical components
|
|
46
49
|
* with their Devframes-authored Zod prop schemas and descriptions, and an
|
|
47
50
|
* empty action set (actions are dispatched dynamically via the bridge, they
|
|
48
51
|
* are not declared here). Reference frontend libraries implement this set.
|
|
@@ -55,4 +58,4 @@ const baseCatalog = defineCatalog(baseSchema, {
|
|
|
55
58
|
actions: {}
|
|
56
59
|
});
|
|
57
60
|
//#endregion
|
|
58
|
-
export { BadgePropsSchema, ButtonPropsSchema, CardPropsSchema, CodeBlockPropsSchema, DataTablePropsSchema, DividerPropsSchema, IconPropsSchema, JSON_RENDER_INDEX_KEY, KeyValueTablePropsSchema, ProgressPropsSchema, StackPropsSchema, SwitchPropsSchema, TextInputPropsSchema, TextPropsSchema, TreePropsSchema, baseCatalog, baseComponentNames, basePropSchemas, baseSchema };
|
|
61
|
+
export { BadgePropsSchema, ButtonPropsSchema, CardPropsSchema, CodeBlockPropsSchema, DataTablePropsSchema, DividerPropsSchema, IconPropsSchema, JSON_RENDER_INDEX_KEY, KeyValueTablePropsSchema, LinkPropsSchema, ProgressPropsSchema, SelectPropsSchema, StackPropsSchema, SwitchPropsSchema, TabsPropsSchema, TextInputPropsSchema, TextPropsSchema, TreePropsSchema, baseCatalog, baseComponentNames, basePropSchemas, baseSchema };
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { n as JsonRenderView, t as DevframeJsonRenderSpec } from "../types-CC2-FD2H.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { DevframeNodeContext, DevframeScopedNodeContext } from "devframe/types";
|
|
2
|
+
import { DevframeNodeContext, DevframeScopedNodeContext } from "devframe";
|
|
4
3
|
//#region src/node/create-view.d.ts
|
|
5
4
|
/** Options for {@link createJsonRenderView}. */
|
|
6
5
|
interface CreateJsonRenderViewOptions {
|
|
@@ -43,12 +42,236 @@ type AnyContext = DevframeNodeContext | DevframeScopedNodeContext<string>;
|
|
|
43
42
|
*/
|
|
44
43
|
declare function createJsonRenderView(ctx: AnyContext, options: CreateJsonRenderViewOptions): JsonRenderView;
|
|
45
44
|
//#endregion
|
|
46
|
-
//#region
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
//#region ../../node_modules/.pnpm/nostics@1.2.0/node_modules/nostics/dist/diagnostic-wduO7saY.d.mts
|
|
46
|
+
//#region src/utils.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* A value of type T, or a function that resolves T from a single params object.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
type ValueOrFn<T, P = any> = T | ((params: P) => T);
|
|
53
|
+
/**
|
|
54
|
+
* Extracts the param type from a single-arg function, or `never` for
|
|
55
|
+
* non-function inputs. Pairs with {@link ValueOrFn}.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
type ExtractFnParam<T> = T extends ((params: infer P) => any) ? P : never;
|
|
60
|
+
/**
|
|
61
|
+
* Converts a union of types to their intersection.
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
66
|
+
/**
|
|
67
|
+
* `true` when `T` is the `any` type.
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
type IsAny<Type> = 0 extends 1 & Type ? true : false;
|
|
72
|
+
/**
|
|
73
|
+
* `true` when `T` is the `unknown` type (and not `any`).
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
type IsUnknown<Type> = IsAny<Type> extends true ? false : unknown extends Type ? true : false;
|
|
78
|
+
/**
|
|
79
|
+
* Expands a type to its property listing so editor hovers show the resolved
|
|
80
|
+
* shape instead of a chain of aliases / intersections.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
type Prettify<Type> = { [Key in keyof Type]: Type[Key]; };
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/diagnostic.d.ts
|
|
87
|
+
/**
|
|
88
|
+
* Define-time shape of a diagnostic. Each field can be a static value or a
|
|
89
|
+
* function that resolves it from a shared `params` object passed at call
|
|
90
|
+
* time. Runtime-only fields (`cause`, `sources`) from {@link DiagnosticInit}
|
|
91
|
+
* are intentionally omitted: they're only meaningful at the call site.
|
|
92
|
+
*/
|
|
93
|
+
interface DiagnosticDefinition<P = any> {
|
|
94
|
+
/**
|
|
95
|
+
* The error message: why this failed. String, or a function of `params`.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* why: (p: { name: string }) => `module "${p.name}" failed to load`
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
why: ValueOrFn<string, P>;
|
|
103
|
+
/**
|
|
104
|
+
* Actionable instructions on how to resolve the problem. String, or a
|
|
105
|
+
* function of `params`.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* fix: (p: { name: string }) => `run "npm install ${p.name}"`
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
fix?: ValueOrFn<string, P>;
|
|
113
|
+
/**
|
|
114
|
+
* Per-code docs URL. A string overrides
|
|
115
|
+
* {@link DefineDiagnosticsOptions.docsBase} for this code; `false` opts this
|
|
116
|
+
* code out entirely, even when `docsBase` is set. When omitted, the URL is
|
|
117
|
+
* derived from `docsBase`.
|
|
118
|
+
*/
|
|
119
|
+
docs?: string | false;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Runtime-only fields that can be passed alongside the interpolation params
|
|
123
|
+
* at call time. Merged into the same object so callers pass everything in
|
|
124
|
+
* one place.
|
|
125
|
+
*/
|
|
126
|
+
interface DiagnosticCallParams {
|
|
127
|
+
/**
|
|
128
|
+
* Original error or exception that triggered this diagnostic. Pass it
|
|
129
|
+
* through when re-throwing so the original stack trace is preserved.
|
|
130
|
+
*/
|
|
131
|
+
cause?: unknown;
|
|
132
|
+
/**
|
|
133
|
+
* Locations in user code that contributed to this diagnostic, in
|
|
134
|
+
* `file:line:column` format. Useful for compilers and other tools where the
|
|
135
|
+
* JS stack trace doesn't reflect the user's source.
|
|
136
|
+
*/
|
|
137
|
+
sources?: string[];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Structured initializer for a {@link Diagnostic}. `why` is the only required
|
|
141
|
+
* field: it becomes the {@link Diagnostic.message}. The remaining fields are
|
|
142
|
+
* optional metadata that reporters and consumers can render or forward.
|
|
143
|
+
*/
|
|
144
|
+
interface DiagnosticInit extends DiagnosticCallParams {
|
|
145
|
+
/**
|
|
146
|
+
* The diagnostic code, e.g. `MATH_E001`. Appear as {@link Diagnostic.name}.
|
|
147
|
+
*/
|
|
148
|
+
code: string;
|
|
149
|
+
/**
|
|
150
|
+
* The actual error message: why this failed.
|
|
151
|
+
* Mirrored to `Error.message`.
|
|
152
|
+
*/
|
|
153
|
+
why: string;
|
|
154
|
+
/**
|
|
155
|
+
* Optional actionable instructions on how to resolve the problem.
|
|
156
|
+
*/
|
|
157
|
+
fix?: string;
|
|
158
|
+
/**
|
|
159
|
+
* URL to extended documentation for this diagnostic.
|
|
160
|
+
*/
|
|
161
|
+
docs?: string;
|
|
49
162
|
}
|
|
50
|
-
|
|
51
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Permissive reporter constraint used internally so reporters with 1 arg,
|
|
165
|
+
* required options, or optional options all satisfy the array constraint.
|
|
166
|
+
*
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
169
|
+
type AnyDiagnosticReporter = (diagnostic: Diagnostic, options: any) => void;
|
|
170
|
+
/**
|
|
171
|
+
* Resolves the `params` type a code expects from the intersection of params
|
|
172
|
+
* across all function-typed fields, falling back to `{}` when every field is
|
|
173
|
+
* static. Merged with {@link DiagnosticCallParams} at the call site.
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
type InferCodeParams<Def> = [ExtractFnParam<Def[keyof Def]>] extends [never] ? {} : UnionToIntersection<ExtractFnParam<Def[keyof Def]>>;
|
|
178
|
+
/**
|
|
179
|
+
* The first positional argument of a {@link DiagnosticHandle} call:
|
|
180
|
+
* interpolation params merged with the runtime-only call-site fields
|
|
181
|
+
* (`cause`, `sources`).
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
type CallSiteParams<Params> = Params & DiagnosticCallParams;
|
|
186
|
+
/**
|
|
187
|
+
* Resolves the full argument tuple for a {@link DiagnosticHandle} call.
|
|
188
|
+
* Branches on whether params and reporter options each have required fields.
|
|
189
|
+
* Required positions become required tuple elements, all-optional ones
|
|
190
|
+
* become `?`, and when no reporter declares any options the parameter is
|
|
191
|
+
* omitted entirely.
|
|
192
|
+
*
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
195
|
+
type ActionArgs<Params, ReporterOpts> = keyof ReporterOpts extends never ? {} extends Params ? [params?: CallSiteParams<Params>] : [params: CallSiteParams<Params>] : {} extends ReporterOpts ? {} extends Params ? [params?: CallSiteParams<Params>, reporterOptions?: ReporterOpts] : [params: CallSiteParams<Params>, reporterOptions?: ReporterOpts] : {} extends Params ? [params: CallSiteParams<Params> | undefined, reporterOptions: ReporterOpts] : [params: CallSiteParams<Params>, reporterOptions: ReporterOpts];
|
|
196
|
+
/**
|
|
197
|
+
* Per-code handle exposed by {@link defineDiagnostics}. Each code is a
|
|
198
|
+
* callable: invoke it to build the diagnostic and run every reporter, or
|
|
199
|
+
* prefix the call with `throw` to raise it.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* diagnostics.MATH_E001({ name: 'x' }) // report
|
|
204
|
+
* throw diagnostics.MATH_E001({ name: 'x' }) // throw
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
interface DiagnosticHandle<Params, ReporterOpts> {
|
|
208
|
+
/**
|
|
209
|
+
* Builds the diagnostic, runs every reporter, and returns the diagnostic
|
|
210
|
+
* instance. The returned diagnostic can be inspected, attached as `cause`,
|
|
211
|
+
* or thrown with `throw`.
|
|
212
|
+
*/
|
|
213
|
+
(...args: ActionArgs<Params, ReporterOpts>): Diagnostic;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Return type of {@link defineDiagnostics}.
|
|
217
|
+
*/
|
|
218
|
+
type Diagnostics<Codes extends Record<string, DiagnosticDefinition>, Reporters extends readonly AnyDiagnosticReporter[]> = { [Code in keyof Codes]: DiagnosticHandle<InferCodeParams<Codes[Code]>, Prettify<ExtractReportersOptions<Reporters>>>; };
|
|
219
|
+
declare class Diagnostic extends Error {
|
|
220
|
+
name: string;
|
|
221
|
+
/**
|
|
222
|
+
* The diagnostic code, e.g. `MATH_E001`.
|
|
223
|
+
* Also appears as the `name` property.
|
|
224
|
+
*/
|
|
225
|
+
code: string;
|
|
226
|
+
/**
|
|
227
|
+
* URL to extended documentation for this diagnostic code.
|
|
228
|
+
* Auto-generated from {@link DefineDiagnosticsOptions.docsBase}.
|
|
229
|
+
*/
|
|
230
|
+
docs?: string;
|
|
231
|
+
/**
|
|
232
|
+
* Optional actionable instructions on how to resolve the problem.
|
|
233
|
+
*/
|
|
234
|
+
fix?: string;
|
|
235
|
+
/**
|
|
236
|
+
* Locations in user code that contributed to this diagnostic, in
|
|
237
|
+
* `file:line:column` format. Relevant when the stack trace doesn't reflect
|
|
238
|
+
* the user's source (e.g. compilers, bundlers), otherwise redundant with the
|
|
239
|
+
* stack and should be omitted.
|
|
240
|
+
*/
|
|
241
|
+
sources?: string[];
|
|
242
|
+
/**
|
|
243
|
+
* Alias for {@link Error.message}: the reason this diagnostic was raised.
|
|
244
|
+
*/
|
|
245
|
+
get why(): string;
|
|
246
|
+
/**
|
|
247
|
+
* @param init structured initializer; `why` is required
|
|
248
|
+
* @param captureFrom V8 stack-cutoff frame. Defaults to {@link Diagnostic}
|
|
249
|
+
* so the top of the trace is the `new Diagnostic(...)` call site.
|
|
250
|
+
* `defineDiagnostics` passes its action method to strip its own frames too.
|
|
251
|
+
* Ignored on engines without `Error.captureStackTrace`.
|
|
252
|
+
*/
|
|
253
|
+
constructor(init: DiagnosticInit, captureFrom?: Function);
|
|
254
|
+
/**
|
|
255
|
+
* Converts the diagnostic into a serializable structured object.
|
|
256
|
+
*/
|
|
257
|
+
toJSON(): object;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Extracts the options object a reporter accepts as its 2nd argument. Returns
|
|
261
|
+
* `{}` when the reporter has no 2nd arg (so it contributes nothing to the
|
|
262
|
+
* merged shape).
|
|
263
|
+
*/
|
|
264
|
+
type ExtractSingleReporterOptions<Reporter> = Reporter extends ((diagnostic: Diagnostic, options: infer ReporterOpts) => any) ? IsUnknown<ReporterOpts> extends true ? {} : Exclude<ReporterOpts, undefined> : {};
|
|
265
|
+
/**
|
|
266
|
+
* Intersects every reporter's options shape into a single object. If any
|
|
267
|
+
* reporter has a required field, the merged shape has a required field, and
|
|
268
|
+
* {@link ActionArgs} flips `reporterOptions` from optional to required via
|
|
269
|
+
* `{} extends Merged`.
|
|
270
|
+
*/
|
|
271
|
+
type ExtractReportersOptions<Reporters extends readonly any[]> = Reporters extends readonly [infer First, ...infer Rest] ? ExtractSingleReporterOptions<First> & ExtractReportersOptions<Rest> : {};
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/node/diagnostics.d.ts
|
|
274
|
+
declare const diagnostics: Diagnostics<{
|
|
52
275
|
readonly DF0038: {
|
|
53
276
|
readonly why: (p: {
|
|
54
277
|
id: string;
|
|
@@ -77,6 +300,8 @@ declare const diagnostics: import("nostics").Diagnostics<{
|
|
|
77
300
|
}) => string;
|
|
78
301
|
readonly fix: "Specs and state travel as strict JSON — remove functions, symbols, class instances, Map/Set, or circular references.";
|
|
79
302
|
};
|
|
80
|
-
}, readonly [
|
|
303
|
+
}, readonly [(d: Diagnostic, { method }?: {
|
|
304
|
+
method?: "log" | "warn" | "error";
|
|
305
|
+
}) => void]>;
|
|
81
306
|
//#endregion
|
|
82
307
|
export { type CreateJsonRenderViewOptions, createJsonRenderView, diagnostics as jsonRenderDiagnostics };
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as basePropSchemas, t as JSON_RENDER_INDEX_KEY } from "../view-index-CJ8aJJLZ.mjs";
|
|
2
2
|
import { createSharedState } from "devframe/utils/shared-state";
|
|
3
|
-
import {
|
|
4
|
-
import { defineDiagnostics } from "nostics";
|
|
5
|
-
import { ansiFormatter } from "nostics/formatters/ansi";
|
|
3
|
+
import { defineDiagnostics } from "devframe/utils/nostics";
|
|
6
4
|
//#region src/node/diagnostics.ts
|
|
7
|
-
const formatAnsi = ansiFormatter(colors);
|
|
8
|
-
function jsonRenderReporter(d, { method = "warn" } = {}) {
|
|
9
|
-
console[method](formatAnsi(d));
|
|
10
|
-
}
|
|
11
5
|
const diagnostics = defineDiagnostics({
|
|
12
6
|
docsBase: "https://devfra.me/errors",
|
|
13
|
-
reporters: [jsonRenderReporter],
|
|
14
7
|
codes: {
|
|
15
8
|
DF0038: {
|
|
16
9
|
why: (p) => `JSON-render view "${p.id}" received invalid props on element "${p.key}": ${p.issues}`,
|
|
@@ -147,9 +147,48 @@ const TreePropsSchema = z.object({
|
|
|
147
147
|
data: z.unknown().optional(),
|
|
148
148
|
defaultExpanded: bool.optional()
|
|
149
149
|
});
|
|
150
|
+
const TabsPropsSchema = z.object({
|
|
151
|
+
tabs: scalar(z.array(z.looseObject({
|
|
152
|
+
value: z.string(),
|
|
153
|
+
label: z.string(),
|
|
154
|
+
icon: z.string().optional(),
|
|
155
|
+
badge: z.string().optional(),
|
|
156
|
+
badgeVariant: z.enum([
|
|
157
|
+
"default",
|
|
158
|
+
"info",
|
|
159
|
+
"success",
|
|
160
|
+
"warning",
|
|
161
|
+
"danger"
|
|
162
|
+
]).optional()
|
|
163
|
+
}))).optional(),
|
|
164
|
+
value: str.optional(),
|
|
165
|
+
defaultValue: str.optional(),
|
|
166
|
+
orientation: z.enum(["horizontal", "vertical"]).optional()
|
|
167
|
+
});
|
|
168
|
+
const LinkPropsSchema = z.object({
|
|
169
|
+
href: str.optional(),
|
|
170
|
+
label: str.optional(),
|
|
171
|
+
icon: str.optional(),
|
|
172
|
+
external: bool.optional()
|
|
173
|
+
});
|
|
174
|
+
const SelectPropsSchema = z.object({
|
|
175
|
+
value: str.optional(),
|
|
176
|
+
options: scalar(z.array(z.union([z.string(), z.looseObject({
|
|
177
|
+
value: z.string(),
|
|
178
|
+
label: z.string().optional(),
|
|
179
|
+
icon: z.string().optional(),
|
|
180
|
+
description: z.string().optional()
|
|
181
|
+
})]))).optional(),
|
|
182
|
+
placeholder: str.optional(),
|
|
183
|
+
label: str.optional(),
|
|
184
|
+
disabled: bool.optional(),
|
|
185
|
+
searchable: bool.optional(),
|
|
186
|
+
native: bool.optional()
|
|
187
|
+
});
|
|
150
188
|
/**
|
|
151
189
|
* Map of base-catalog component name → Zod prop schema. The keys are the
|
|
152
|
-
* canonical component set (catalog v1
|
|
190
|
+
* canonical component set (catalog v1: the original fourteen plus the
|
|
191
|
+
* additive Tabs/Link/Select).
|
|
153
192
|
*/
|
|
154
193
|
const basePropSchemas = {
|
|
155
194
|
Stack: StackPropsSchema,
|
|
@@ -165,7 +204,10 @@ const basePropSchemas = {
|
|
|
165
204
|
DataTable: DataTablePropsSchema,
|
|
166
205
|
CodeBlock: CodeBlockPropsSchema,
|
|
167
206
|
Progress: ProgressPropsSchema,
|
|
168
|
-
Tree: TreePropsSchema
|
|
207
|
+
Tree: TreePropsSchema,
|
|
208
|
+
Tabs: TabsPropsSchema,
|
|
209
|
+
Link: LinkPropsSchema,
|
|
210
|
+
Select: SelectPropsSchema
|
|
169
211
|
};
|
|
170
212
|
/** The ordered list of base-catalog component names (catalog v1). */
|
|
171
213
|
const baseComponentNames = Object.keys(basePropSchemas);
|
|
@@ -183,4 +225,4 @@ const baseComponentNames = Object.keys(basePropSchemas);
|
|
|
183
225
|
*/
|
|
184
226
|
const JSON_RENDER_INDEX_KEY = "devframe:json-render:index";
|
|
185
227
|
//#endregion
|
|
186
|
-
export {
|
|
228
|
+
export { TextPropsSchema as _, CodeBlockPropsSchema as a, basePropSchemas as b, IconPropsSchema as c, ProgressPropsSchema as d, SelectPropsSchema as f, TextInputPropsSchema as g, TabsPropsSchema as h, CardPropsSchema as i, KeyValueTablePropsSchema as l, SwitchPropsSchema as m, BadgePropsSchema as n, DataTablePropsSchema as o, StackPropsSchema as p, ButtonPropsSchema as r, DividerPropsSchema as s, JSON_RENDER_INDEX_KEY as t, LinkPropsSchema as u, TreePropsSchema as v, baseComponentNames as y };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devframes/json-render",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.9.0-beta.10",
|
|
5
|
+
"description": "Protocol layer for describing devframe views as JSON that any renderer can display.",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/devframes/devframe#readme",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@devframes/hub": "0.
|
|
34
|
-
"devframe": "0.
|
|
33
|
+
"@devframes/hub": "0.9.0-beta.10",
|
|
34
|
+
"devframe": "0.9.0-beta.10"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@devframes/hub": {
|
|
@@ -40,14 +40,13 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@json-render/core": "^0.19.0",
|
|
43
|
-
"nostics": "^1.2.0",
|
|
44
43
|
"zod": "^4.4.3"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^26.
|
|
46
|
+
"@types/node": "^26.2.0",
|
|
48
47
|
"tsdown": "^0.22.14",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
48
|
+
"devframe": "0.9.0-beta.10",
|
|
49
|
+
"@devframes/hub": "0.9.0-beta.10"
|
|
51
50
|
},
|
|
52
51
|
"scripts": {
|
|
53
52
|
"build": "tsdown",
|