@nullplatform/ui-plugin-sdk 0.4.0 → 0.6.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/dist/catalog.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  * This file is pure data so it can be imported by the host without pulling
9
9
  * the DOM polyfill.
10
10
  */
11
+ export type { ContractProps, UiComponentsProps, UiComponentsTag } from "./contractProps.js";
11
12
  export type PropertyType = "string" | "number" | "boolean" | "object" | "array";
12
13
  export interface CatalogElementSpec {
13
14
  /** Custom element tag name. */
@@ -18,9 +19,65 @@ export interface CatalogElementSpec {
18
19
  /** Event name → React prop name. */
19
20
  events: Record<string, string>;
20
21
  /** Named slots (rendered as React element props). */
21
- slots?: string[];
22
+ slots?: readonly string[];
23
+ /** Closed lists for string props. The host drops any other value, so the element draws its default. */
24
+ values?: Readonly<Record<string, readonly string[]>>;
25
+ /**
26
+ * Props that end up in CSS, which the host only passes as plain values. `prop[].key` names a key of each item
27
+ * in an array prop.
28
+ */
29
+ cssValues?: readonly string[];
30
+ /** Whether the element draws nested elements. The host drops children otherwise. */
31
+ children?: boolean;
32
+ /** What the element draws for a prop the plugin leaves out or the host drops, whichever implementation draws it. */
33
+ defaults?: Readonly<Record<string, string | number | boolean>>;
22
34
  }
35
+ /**
36
+ * The values a plugin may pass to these props. The SDK's components are typed from these lists, and
37
+ * the host checks each value against them again at runtime, falling back to the element's default:
38
+ * a published bundle has already left TypeScript behind.
39
+ */
40
+ export declare const CATALOG_PROP_VALUES: {
41
+ readonly Text: {
42
+ readonly variant: readonly ["h1", "h2", "h3", "h4", "h5", "h6", "subtitle1", "subtitle2", "body1", "body2", "caption", "overline", "button"];
43
+ readonly align: readonly ["inherit", "left", "center", "right", "justify"];
44
+ };
45
+ readonly Button: {
46
+ readonly variant: readonly ["contained", "outlined", "text", "soft"];
47
+ readonly color: readonly ["inherit", "primary", "secondary", "success", "error", "info", "warning"];
48
+ readonly size: readonly ["small", "medium", "large"];
49
+ };
50
+ readonly Chip: {
51
+ readonly color: readonly ["default", "primary", "secondary", "success", "error", "info", "warning"];
52
+ readonly variant: readonly ["filled", "outlined", "soft"];
53
+ readonly size: readonly ["small", "medium"];
54
+ };
55
+ readonly Skeleton: {
56
+ readonly variant: readonly ["text", "rectangular", "rounded", "circular"];
57
+ };
58
+ readonly Stack: {
59
+ readonly direction: readonly ["row", "column"];
60
+ };
61
+ readonly Alert: {
62
+ readonly severity: readonly ["success", "info", "warning", "error"];
63
+ };
64
+ };
65
+ /**
66
+ * Every element a plugin can render: the SDK's own, then the design-system components whose contracts
67
+ * @nullplatform/react-ui-components publishes, copied into `contracts.generated.ts` by `pnpm sync:contracts`.
68
+ */
23
69
  export declare const CATALOG: readonly CatalogElementSpec[];
24
70
  export declare const CATALOG_BY_TAG: ReadonlyMap<string, CatalogElementSpec>;
71
+ export type TextVariant = (typeof CATALOG_PROP_VALUES.Text.variant)[number];
72
+ export type TextAlign = (typeof CATALOG_PROP_VALUES.Text.align)[number];
73
+ export type ButtonVariant = (typeof CATALOG_PROP_VALUES.Button.variant)[number];
74
+ export type ButtonColor = (typeof CATALOG_PROP_VALUES.Button.color)[number];
75
+ export type ChipColor = (typeof CATALOG_PROP_VALUES.Chip.color)[number];
76
+ export type ChipVariant = (typeof CATALOG_PROP_VALUES.Chip.variant)[number];
77
+ export type ChipSize = (typeof CATALOG_PROP_VALUES.Chip.size)[number];
78
+ export type SkeletonVariant = (typeof CATALOG_PROP_VALUES.Skeleton.variant)[number];
79
+ export type ButtonSize = (typeof CATALOG_PROP_VALUES.Button.size)[number];
80
+ export type StackDirection = (typeof CATALOG_PROP_VALUES.Stack.direction)[number];
81
+ export type AlertSeverity = (typeof CATALOG_PROP_VALUES.Alert.severity)[number];
25
82
  /** Name of the wrapper element remote-dom uses for React elements passed as props. */
26
83
  export declare const FRAGMENT_TAG = "remote-fragment";
package/dist/catalog.js CHANGED
@@ -8,7 +8,42 @@
8
8
  * This file is pure data so it can be imported by the host without pulling
9
9
  * the DOM polyfill.
10
10
  */
11
- export const CATALOG = [
11
+ import { UI_COMPONENTS_CONTRACTS } from "./contracts.generated";
12
+ /**
13
+ * The values a plugin may pass to these props. The SDK's components are typed from these lists, and
14
+ * the host checks each value against them again at runtime, falling back to the element's default:
15
+ * a published bundle has already left TypeScript behind.
16
+ */
17
+ export const CATALOG_PROP_VALUES = {
18
+ Text: {
19
+ variant: [
20
+ "h1", "h2", "h3", "h4", "h5", "h6",
21
+ "subtitle1", "subtitle2", "body1", "body2", "caption", "overline", "button",
22
+ ],
23
+ align: ["inherit", "left", "center", "right", "justify"],
24
+ },
25
+ Button: {
26
+ variant: ["contained", "outlined", "text", "soft"],
27
+ color: ["inherit", "primary", "secondary", "success", "error", "info", "warning"],
28
+ size: ["small", "medium", "large"],
29
+ },
30
+ Chip: {
31
+ color: ["default", "primary", "secondary", "success", "error", "info", "warning"],
32
+ variant: ["filled", "outlined", "soft"],
33
+ size: ["small", "medium"],
34
+ },
35
+ Skeleton: {
36
+ variant: ["text", "rectangular", "rounded", "circular"],
37
+ },
38
+ Stack: {
39
+ direction: ["row", "column"],
40
+ },
41
+ Alert: {
42
+ severity: ["success", "info", "warning", "error"],
43
+ },
44
+ };
45
+ /** The elements the SDK defines itself. */
46
+ const OWN_CATALOG = [
12
47
  {
13
48
  tag: "np-network-graph",
14
49
  component: "NetworkGraph",
@@ -64,6 +99,7 @@ export const CATALOG = [
64
99
  properties: { title: "string", subtitle: "string", padding: "string" },
65
100
  events: {},
66
101
  slots: ["action"],
102
+ children: true,
67
103
  },
68
104
  {
69
105
  tag: "np-stack",
@@ -76,6 +112,10 @@ export const CATALOG = [
76
112
  wrap: "boolean",
77
113
  },
78
114
  events: {},
115
+ values: CATALOG_PROP_VALUES.Stack,
116
+ cssValues: ["align", "justify"],
117
+ children: true,
118
+ defaults: { direction: "column", spacing: 1 },
79
119
  },
80
120
  {
81
121
  tag: "np-text",
@@ -87,6 +127,10 @@ export const CATALOG = [
87
127
  noWrap: "boolean",
88
128
  },
89
129
  events: {},
130
+ values: CATALOG_PROP_VALUES.Text,
131
+ cssValues: ["color"],
132
+ children: true,
133
+ defaults: { variant: "body2" },
90
134
  },
91
135
  {
92
136
  tag: "np-button",
@@ -100,6 +144,9 @@ export const CATALOG = [
100
144
  icon: "string",
101
145
  },
102
146
  events: { press: "onPress" },
147
+ values: CATALOG_PROP_VALUES.Button,
148
+ children: true,
149
+ defaults: { variant: "contained", color: "primary", size: "small" },
103
150
  },
104
151
  {
105
152
  tag: "np-chip",
@@ -111,12 +158,15 @@ export const CATALOG = [
111
158
  size: "string",
112
159
  },
113
160
  events: {},
161
+ values: CATALOG_PROP_VALUES.Chip,
162
+ defaults: { color: "default", variant: "filled", size: "small" },
114
163
  },
115
164
  {
116
165
  tag: "np-link",
117
166
  component: "Link",
118
167
  properties: { to: "string", params: "object", href: "string" },
119
168
  events: { press: "onPress" },
169
+ children: true,
120
170
  },
121
171
  {
122
172
  tag: "np-table",
@@ -128,30 +178,39 @@ export const CATALOG = [
128
178
  emptyMessage: "string",
129
179
  },
130
180
  events: { rowPress: "onRowPress" },
181
+ cssValues: ["columns[].width"],
131
182
  },
132
183
  {
133
184
  tag: "np-skeleton",
134
185
  component: "Skeleton",
135
186
  properties: { height: "number", width: "string", variant: "string" },
136
187
  events: {},
188
+ values: CATALOG_PROP_VALUES.Skeleton,
189
+ defaults: { height: 20, width: "100%", variant: "rounded" },
137
190
  },
138
191
  {
139
192
  tag: "np-empty",
140
193
  component: "Empty",
141
194
  properties: { title: "string", description: "string" },
142
195
  events: {},
196
+ children: true,
143
197
  },
144
198
  {
145
199
  tag: "np-alert",
146
200
  component: "Alert",
147
201
  properties: { severity: "string", title: "string" },
148
202
  events: {},
203
+ values: CATALOG_PROP_VALUES.Alert,
204
+ children: true,
205
+ defaults: { severity: "info" },
149
206
  },
150
207
  {
151
208
  tag: "np-icon",
152
209
  component: "Icon",
153
210
  properties: { icon: "string", size: "number", color: "string" },
154
211
  events: {},
212
+ // The host hands it to the app's `renderIcon`, and admin-dashboard's styles the icon with it.
213
+ cssValues: ["color"],
155
214
  },
156
215
  {
157
216
  tag: "np-divider",
@@ -192,6 +251,8 @@ export const CATALOG = [
192
251
  grow: "boolean",
193
252
  },
194
253
  events: {},
254
+ cssValues: ["height", "width"],
255
+ children: true,
195
256
  },
196
257
  {
197
258
  // Responsive grid: as many columns as fit `min` px wide, up to `columns`.
@@ -199,6 +260,7 @@ export const CATALOG = [
199
260
  component: "Grid",
200
261
  properties: { columns: "number", min: "number", gap: "number" },
201
262
  events: {},
263
+ children: true,
202
264
  },
203
265
  {
204
266
  // Big number tile: label, formatted value, optional delta with a trend arrow and tone.
@@ -215,6 +277,7 @@ export const CATALOG = [
215
277
  color: "string",
216
278
  },
217
279
  events: {},
280
+ cssValues: ["color"],
218
281
  },
219
282
  {
220
283
  tag: "np-sparkline",
@@ -226,6 +289,7 @@ export const CATALOG = [
226
289
  area: "boolean",
227
290
  },
228
291
  events: {},
292
+ cssValues: ["color"],
229
293
  },
230
294
  {
231
295
  // Time series. `series: [{ name, values, color? }]`, `categories` are the x labels (same length as values).
@@ -242,6 +306,7 @@ export const CATALOG = [
242
306
  hideLegend: "boolean",
243
307
  },
244
308
  events: { pointPress: "onPointPress" },
309
+ cssValues: ["series[].color"],
245
310
  },
246
311
  {
247
312
  tag: "np-bar-chart",
@@ -257,6 +322,7 @@ export const CATALOG = [
257
322
  hideLegend: "boolean",
258
323
  },
259
324
  events: { barPress: "onBarPress" },
325
+ cssValues: ["series[].color"],
260
326
  },
261
327
  {
262
328
  // Part-to-whole. `items: [{ name, value, color? }]`; the center shows `total` or the sum.
@@ -271,6 +337,7 @@ export const CATALOG = [
271
337
  hideLegend: "boolean",
272
338
  },
273
339
  events: { slicePress: "onSlicePress" },
340
+ cssValues: ["items[].color"],
274
341
  },
275
342
  {
276
343
  // Horizontal share bar, 0..1.
@@ -283,8 +350,14 @@ export const CATALOG = [
283
350
  height: "number",
284
351
  },
285
352
  events: {},
353
+ cssValues: ["color"],
286
354
  },
287
355
  ];
356
+ /**
357
+ * Every element a plugin can render: the SDK's own, then the design-system components whose contracts
358
+ * @nullplatform/react-ui-components publishes, copied into `contracts.generated.ts` by `pnpm sync:contracts`.
359
+ */
360
+ export const CATALOG = [...OWN_CATALOG, ...UI_COMPONENTS_CONTRACTS];
288
361
  export const CATALOG_BY_TAG = new Map(CATALOG.map((spec) => [spec.tag, spec]));
289
362
  /** Name of the wrapper element remote-dom uses for React elements passed as props. */
290
363
  export const FRAGMENT_TAG = "remote-fragment";
@@ -0,0 +1,7 @@
1
+ import "./polyfill.js";
2
+ import "@remote-dom/react/polyfill";
3
+ import { type ComponentType, type ReactNode } from "react";
4
+ /** The React component a plugin renders a catalog element with. */
5
+ export declare function component<Props extends Record<string, unknown>>(tag: string): ComponentType<Props & {
6
+ children?: ReactNode;
7
+ }>;
@@ -0,0 +1,40 @@
1
+ import "./polyfill.js";
2
+ import "@remote-dom/react/polyfill";
3
+ import { createRemoteComponent } from "@remote-dom/react";
4
+ import { createElement } from "react";
5
+ import { CATALOG_BY_TAG } from "./catalog.js";
6
+ import { defineCatalogElements } from "./elements.js";
7
+ const elements = defineCatalogElements();
8
+ /** The React component a plugin renders a catalog element with. */
9
+ export function component(tag) {
10
+ const spec = CATALOG_BY_TAG.get(tag);
11
+ if (!spec)
12
+ throw new Error(`Unknown catalog element ${tag}`);
13
+ const eventProps = {};
14
+ for (const [event, prop] of Object.entries(spec.events))
15
+ eventProps[prop] = { event };
16
+ const Remote = createRemoteComponent(tag, elements.get(tag), {
17
+ eventProps: eventProps,
18
+ });
19
+ const handlerProps = Object.values(spec.events);
20
+ if (handlerProps.length === 0)
21
+ return Remote;
22
+ // remote-dom delivers a RemoteEvent to listeners; plugin authors want the payload the host sent.
23
+ const Wrapped = (props) => {
24
+ const mapped = { ...props };
25
+ for (const prop of handlerProps) {
26
+ const handler = props[prop];
27
+ if (typeof handler === "function") {
28
+ mapped[prop] = (event) => {
29
+ const detail = event && typeof event === "object" && "detail" in event
30
+ ? event.detail
31
+ : event;
32
+ return handler(detail);
33
+ };
34
+ }
35
+ }
36
+ return createElement(Remote, mapped);
37
+ };
38
+ Wrapped.displayName = spec.component;
39
+ return Wrapped;
40
+ }
@@ -3,9 +3,12 @@ import "./polyfill.js";
3
3
  * React components a plugin renders with. Each one maps to a catalog element;
4
4
  * the host decides how it looks.
5
5
  */
6
- import "@remote-dom/react/polyfill";
7
- import { type ComponentType, type ReactNode } from "react";
8
- export declare const TextField: ComponentType<{
6
+ import type { ReactNode } from "react";
7
+ import { type AlertSeverity, type ButtonColor, type ButtonSize, type ButtonVariant, type ChipColor, type ChipSize, type ChipVariant, type SkeletonVariant, type StackDirection, type TextAlign, type TextVariant } from "./catalog.js";
8
+ export type { AlertSeverity, ButtonColor, ButtonSize, ButtonVariant, ChipColor, ChipSize, ChipVariant, SkeletonVariant, StackDirection, TextAlign, TextVariant, } from "./catalog.js";
9
+ export * from "./components.generated";
10
+ export type { ContractProps, UiComponentsTag } from "./contractProps.js";
11
+ export declare const TextField: import("react").ComponentType<{
9
12
  label: string;
10
13
  value: string;
11
14
  multiline?: boolean;
@@ -16,7 +19,7 @@ export declare const TextField: ComponentType<{
16
19
  } & {
17
20
  children?: ReactNode;
18
21
  }>;
19
- export declare const Select: ComponentType<{
22
+ export declare const Select: import("react").ComponentType<{
20
23
  label: string;
21
24
  value?: string;
22
25
  values?: string[];
@@ -30,7 +33,7 @@ export declare const Select: ComponentType<{
30
33
  } & {
31
34
  children?: ReactNode;
32
35
  }>;
33
- export declare const Switch: ComponentType<{
36
+ export declare const Switch: import("react").ComponentType<{
34
37
  label: string;
35
38
  checked: boolean;
36
39
  disabled?: boolean;
@@ -38,7 +41,7 @@ export declare const Switch: ComponentType<{
38
41
  } & {
39
42
  children?: ReactNode;
40
43
  }>;
41
- export declare const NetworkGraph: ComponentType<{
44
+ export declare const NetworkGraph: import("react").ComponentType<{
42
45
  nodes: Array<Record<string, unknown>>;
43
46
  edges: Array<{
44
47
  from: string;
@@ -59,7 +62,7 @@ export interface TableColumn {
59
62
  export type TableRow = Record<string, string | number | boolean | null | undefined> & {
60
63
  id?: string | number;
61
64
  };
62
- export declare const Image: ComponentType<{
65
+ export declare const Image: import("react").ComponentType<{
63
66
  src: string;
64
67
  alt: string;
65
68
  width?: number;
@@ -67,7 +70,7 @@ export declare const Image: ComponentType<{
67
70
  } & {
68
71
  children?: ReactNode;
69
72
  }>;
70
- export declare const Card: ComponentType<{
73
+ export declare const Card: import("react").ComponentType<{
71
74
  title?: string;
72
75
  subtitle?: string;
73
76
  padding?: string;
@@ -75,8 +78,8 @@ export declare const Card: ComponentType<{
75
78
  } & {
76
79
  children?: ReactNode;
77
80
  }>;
78
- export declare const Stack: ComponentType<{
79
- direction?: "row" | "column";
81
+ export declare const Stack: import("react").ComponentType<{
82
+ direction?: StackDirection;
80
83
  spacing?: number;
81
84
  align?: string;
82
85
  justify?: string;
@@ -84,18 +87,19 @@ export declare const Stack: ComponentType<{
84
87
  } & {
85
88
  children?: ReactNode;
86
89
  }>;
87
- export declare const Text: ComponentType<{
88
- variant?: string;
90
+ export declare const Text: import("react").ComponentType<{
91
+ variant?: TextVariant;
92
+ /** A theme color path (`text.secondary`, `error.main`) or any CSS color. */
89
93
  color?: string;
90
- align?: string;
94
+ align?: TextAlign;
91
95
  noWrap?: boolean;
92
96
  } & {
93
97
  children?: ReactNode;
94
98
  }>;
95
- export declare const Button: ComponentType<{
96
- variant?: "contained" | "outlined" | "text" | "soft";
97
- color?: string;
98
- size?: "small" | "medium" | "large";
99
+ export declare const Button: import("react").ComponentType<{
100
+ variant?: ButtonVariant;
101
+ color?: ButtonColor;
102
+ size?: ButtonSize;
99
103
  disabled?: boolean;
100
104
  loading?: boolean;
101
105
  icon?: string;
@@ -103,15 +107,15 @@ export declare const Button: ComponentType<{
103
107
  } & {
104
108
  children?: ReactNode;
105
109
  }>;
106
- export declare const Chip: ComponentType<{
110
+ export declare const Chip: import("react").ComponentType<{
107
111
  label: string;
108
- color?: string;
109
- variant?: string;
110
- size?: string;
112
+ color?: ChipColor;
113
+ variant?: ChipVariant;
114
+ size?: ChipSize;
111
115
  } & {
112
116
  children?: ReactNode;
113
117
  }>;
114
- export declare const Link: ComponentType<{
118
+ export declare const Link: import("react").ComponentType<{
115
119
  to?: string;
116
120
  params?: Record<string, string | number>;
117
121
  href?: string;
@@ -119,7 +123,7 @@ export declare const Link: ComponentType<{
119
123
  } & {
120
124
  children?: ReactNode;
121
125
  }>;
122
- export declare const Table: ComponentType<{
126
+ export declare const Table: import("react").ComponentType<{
123
127
  columns: TableColumn[];
124
128
  rows: TableRow[];
125
129
  dense?: boolean;
@@ -128,41 +132,41 @@ export declare const Table: ComponentType<{
128
132
  } & {
129
133
  children?: ReactNode;
130
134
  }>;
131
- export declare const Skeleton: ComponentType<{
135
+ export declare const Skeleton: import("react").ComponentType<{
132
136
  height?: number;
133
137
  width?: string;
134
- variant?: string;
138
+ variant?: SkeletonVariant;
135
139
  } & {
136
140
  children?: ReactNode;
137
141
  }>;
138
- export declare const Empty: ComponentType<{
142
+ export declare const Empty: import("react").ComponentType<{
139
143
  title?: string;
140
144
  description?: string;
141
145
  } & {
142
146
  children?: ReactNode;
143
147
  }>;
144
- export declare const Alert: ComponentType<{
145
- severity?: "success" | "info" | "warning" | "error";
148
+ export declare const Alert: import("react").ComponentType<{
149
+ severity?: AlertSeverity;
146
150
  title?: string;
147
151
  } & {
148
152
  children?: ReactNode;
149
153
  }>;
150
- export declare const Icon: ComponentType<{
154
+ export declare const Icon: import("react").ComponentType<{
151
155
  icon: string;
152
156
  size?: number;
153
157
  color?: string;
154
158
  } & {
155
159
  children?: ReactNode;
156
160
  }>;
157
- export declare const Divider: ComponentType<{
161
+ export declare const Divider: import("react").ComponentType<{
158
162
  children?: ReactNode;
159
163
  }>;
160
- export declare const Markdown: ComponentType<{
164
+ export declare const Markdown: import("react").ComponentType<{
161
165
  content: string;
162
166
  } & {
163
167
  children?: ReactNode;
164
168
  }>;
165
- export declare const Code: ComponentType<{
169
+ export declare const Code: import("react").ComponentType<{
166
170
  content: string;
167
171
  language?: string;
168
172
  maxHeight?: number;
@@ -175,7 +179,7 @@ export interface EgoEdge {
175
179
  kind?: string;
176
180
  }
177
181
  /** Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right. */
178
- export declare const EgoGraph: ComponentType<{
182
+ export declare const EgoGraph: import("react").ComponentType<{
179
183
  focus: string;
180
184
  inbound: EgoEdge[];
181
185
  outbound: EgoEdge[];
@@ -184,7 +188,7 @@ export declare const EgoGraph: ComponentType<{
184
188
  } & {
185
189
  children?: ReactNode;
186
190
  }>;
187
- export declare const Box: ComponentType<{
191
+ export declare const Box: import("react").ComponentType<{
188
192
  padding?: string;
189
193
  height?: string;
190
194
  width?: string;
@@ -193,7 +197,7 @@ export declare const Box: ComponentType<{
193
197
  children?: ReactNode;
194
198
  }>;
195
199
  /** Responsive grid: as many columns as fit `min` px, up to `columns`. */
196
- export declare const Grid: ComponentType<{
200
+ export declare const Grid: import("react").ComponentType<{
197
201
  columns?: number;
198
202
  min?: number;
199
203
  gap?: number;
@@ -202,7 +206,7 @@ export declare const Grid: ComponentType<{
202
206
  }>;
203
207
  export type ValueFormat = "number" | "currency" | "percent" | "compact";
204
208
  /** Big number tile. `trend` draws the arrow; `tone` colors the delta (`positive` = good, whatever the direction). */
205
- export declare const Metric: ComponentType<{
209
+ export declare const Metric: import("react").ComponentType<{
206
210
  label: string;
207
211
  value: string;
208
212
  delta?: string;
@@ -222,7 +226,7 @@ export declare const Metric: ComponentType<{
222
226
  */
223
227
  export type ThemeColor = "primary" | "info" | "success" | "warning" | "error" | "secondary" | "grey" | "muted" | `palette:${number}`;
224
228
  /** `area` fills under the line; off by default. */
225
- export declare const Sparkline: ComponentType<{
229
+ export declare const Sparkline: import("react").ComponentType<{
226
230
  values: number[];
227
231
  height?: number;
228
232
  color?: string;
@@ -242,7 +246,7 @@ export interface ChartPoint {
242
246
  index: number;
243
247
  }
244
248
  /** Time series; `categories` are the x labels, one per value. */
245
- export declare const LineChart: ComponentType<{
249
+ export declare const LineChart: import("react").ComponentType<{
246
250
  series: ChartSeries[];
247
251
  categories: string[];
248
252
  stacked?: boolean;
@@ -256,7 +260,7 @@ export declare const LineChart: ComponentType<{
256
260
  } & {
257
261
  children?: ReactNode;
258
262
  }>;
259
- export declare const BarChart: ComponentType<{
263
+ export declare const BarChart: import("react").ComponentType<{
260
264
  series: ChartSeries[];
261
265
  categories: string[];
262
266
  stacked?: boolean;
@@ -275,7 +279,7 @@ export interface DonutItem {
275
279
  color?: ThemeColor | string;
276
280
  }
277
281
  /** Part-to-whole ring; the center shows `total` or the formatted sum. */
278
- export declare const Donut: ComponentType<{
282
+ export declare const Donut: import("react").ComponentType<{
279
283
  items: DonutItem[];
280
284
  total?: string;
281
285
  height?: number;
@@ -287,7 +291,7 @@ export declare const Donut: ComponentType<{
287
291
  children?: ReactNode;
288
292
  }>;
289
293
  /** Horizontal share bar, `value` in 0..1. */
290
- export declare const ProgressBar: ComponentType<{
294
+ export declare const ProgressBar: import("react").ComponentType<{
291
295
  value: number;
292
296
  label?: string;
293
297
  color?: string;
@@ -0,0 +1,61 @@
1
+ export declare const Badge: import("react").ComponentType<{
2
+ badgeContent?: string | undefined;
3
+ color?: "default" | "success" | "error" | "warning" | "info" | "primary" | "secondary" | undefined;
4
+ variant?: "standard" | "dot" | undefined;
5
+ max?: number | undefined;
6
+ invisible?: boolean | undefined;
7
+ showZero?: boolean | undefined;
8
+ overlap?: "rectangular" | "circular" | undefined;
9
+ } & {} & {} & {
10
+ children?: import("react").ReactNode;
11
+ }>;
12
+ export declare const Paper: import("react").ComponentType<{
13
+ elevation?: number | undefined;
14
+ variant?: "elevation" | "outlined" | undefined;
15
+ square?: boolean | undefined;
16
+ } & {} & {} & {
17
+ children?: import("react").ReactNode;
18
+ }>;
19
+ export declare const List: import("react").ComponentType<{
20
+ dense?: boolean | undefined;
21
+ disablePadding?: boolean | undefined;
22
+ } & {} & {} & {
23
+ children?: import("react").ReactNode;
24
+ }>;
25
+ export declare const ListItem: import("react").ComponentType<{
26
+ dense?: boolean | undefined;
27
+ divider?: boolean | undefined;
28
+ disableGutters?: boolean | undefined;
29
+ disablePadding?: boolean | undefined;
30
+ alignItems?: "center" | "flex-start" | undefined;
31
+ } & {} & {
32
+ secondaryAction?: import("react").ReactNode;
33
+ } & {
34
+ children?: import("react").ReactNode;
35
+ }>;
36
+ export declare const ListItemText: import("react").ComponentType<{
37
+ primary?: string | undefined;
38
+ secondary?: string | undefined;
39
+ inset?: boolean | undefined;
40
+ } & {} & {} & {
41
+ children?: import("react").ReactNode;
42
+ }>;
43
+ export declare const LinearProgress: import("react").ComponentType<{
44
+ value?: number | undefined;
45
+ valueBuffer?: number | undefined;
46
+ variant?: "query" | "determinate" | "indeterminate" | "buffer" | undefined;
47
+ color?: "success" | "error" | "warning" | "info" | "primary" | "secondary" | "inherit" | undefined;
48
+ label?: Readonly<Record<string, unknown>> | undefined;
49
+ } & {} & {} & {
50
+ children?: import("react").ReactNode;
51
+ }>;
52
+ export declare const CircularProgress: import("react").ComponentType<{
53
+ value?: number | undefined;
54
+ variant?: "determinate" | "indeterminate" | undefined;
55
+ color?: "success" | "error" | "warning" | "info" | "primary" | "secondary" | "inherit" | undefined;
56
+ size?: number | undefined;
57
+ thickness?: number | undefined;
58
+ label?: Readonly<Record<string, unknown>> | undefined;
59
+ } & {} & {} & {
60
+ children?: import("react").ReactNode;
61
+ }>;
@@ -0,0 +1,10 @@
1
+ // Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.4. Don't edit: change the contract in
2
+ // react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
3
+ import { component } from "./component.js";
4
+ export const Badge = component("np-badge");
5
+ export const Paper = component("np-paper");
6
+ export const List = component("np-list");
7
+ export const ListItem = component("np-list-item");
8
+ export const ListItemText = component("np-list-item-text");
9
+ export const LinearProgress = component("np-linear-progress");
10
+ export const CircularProgress = component("np-circular-progress");
@@ -1,46 +1,7 @@
1
1
  import "./polyfill.js";
2
- /**
3
- * React components a plugin renders with. Each one maps to a catalog element;
4
- * the host decides how it looks.
5
- */
6
- import "@remote-dom/react/polyfill";
7
- import { createRemoteComponent } from "@remote-dom/react";
8
- import { createElement } from "react";
9
- import { CATALOG_BY_TAG } from "./catalog.js";
10
- import { defineCatalogElements } from "./elements.js";
11
- const elements = defineCatalogElements();
12
- function component(tag) {
13
- const spec = CATALOG_BY_TAG.get(tag);
14
- if (!spec)
15
- throw new Error(`Unknown catalog element ${tag}`);
16
- const eventProps = {};
17
- for (const [event, prop] of Object.entries(spec.events))
18
- eventProps[prop] = { event };
19
- const Remote = createRemoteComponent(tag, elements.get(tag), {
20
- eventProps: eventProps,
21
- });
22
- const handlerProps = Object.values(spec.events);
23
- if (handlerProps.length === 0)
24
- return Remote;
25
- // remote-dom delivers a RemoteEvent to listeners; plugin authors want the payload the host sent.
26
- const Wrapped = (props) => {
27
- const mapped = { ...props };
28
- for (const prop of handlerProps) {
29
- const handler = props[prop];
30
- if (typeof handler === "function") {
31
- mapped[prop] = (event) => {
32
- const detail = event && typeof event === "object" && "detail" in event
33
- ? event.detail
34
- : event;
35
- return handler(detail);
36
- };
37
- }
38
- }
39
- return createElement(Remote, mapped);
40
- };
41
- Wrapped.displayName = spec.component;
42
- return Wrapped;
43
- }
2
+ import { component } from "./component.js";
3
+ // The design-system components plugins render, one per contract react-ui-components publishes.
4
+ export * from "./components.generated";
44
5
  export const TextField = component("np-text-field");
45
6
  export const Select = component("np-select");
46
7
  export const Switch = component("np-switch");
@@ -1,6 +1,10 @@
1
1
  export type WhenQuery = Record<string, unknown>;
2
- /** Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time. */
3
- export declare const CONTEXT_ROOTS: readonly ["nrn", "organization", "account", "namespace", "application", "scope", "deployment", "user"];
2
+ /**
3
+ * Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time.
4
+ * `locale` and `route` are in the plugin context but are not roots: the platform resolves installations without
5
+ * knowing either, so a condition on them could only ever hold in developer mode.
6
+ */
7
+ export declare const CONTEXT_ROOTS: readonly ["nrn", "organization", "account", "namespace", "application", "user"];
4
8
  export type ContextRoot = (typeof CONTEXT_ROOTS)[number];
5
9
  export declare const WHEN_LIMITS: {
6
10
  readonly depth: 16;
@@ -4,8 +4,17 @@
4
4
  * the API (installations and manifests) and in the host (developer mode).
5
5
  */
6
6
  import sift from 'sift';
7
- /** Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time. */
8
- export const CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'deployment', 'user'];
7
+ /**
8
+ * Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time.
9
+ * `locale` and `route` are in the plugin context but are not roots: the platform resolves installations without
10
+ * knowing either, so a condition on them could only ever hold in developer mode.
11
+ */
12
+ export const CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'user'];
13
+ /**
14
+ * In the plugin context, but not usable in a condition yet. Installations resolve for the application's NRN, so the
15
+ * platform never loads a scope or a deployment and a condition on either would silently never match.
16
+ */
17
+ const UNSUPPORTED_ROOTS = new Set(['scope', 'deployment']);
9
18
  /** Operators that would execute code or are meaningless outside MongoDB. */
10
19
  const ALLOWED_OPERATORS = new Set(['$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin', '$exists', '$size', '$all', '$elemMatch', '$not', '$and', '$or', '$nor', '$mod']);
11
20
  export const WHEN_LIMITS = { depth: 16, nodes: 512, array: 100, string: 1024 };
@@ -84,6 +93,9 @@ export function validateWhen(input) {
84
93
  throw new WhenError('when must be an object');
85
94
  assertSafe(input);
86
95
  for (const root of extractRoots(input)) {
96
+ if (UNSUPPORTED_ROOTS.has(root)) {
97
+ throw new WhenError(`Context root "${root}" is not supported yet: plugins resolve for the application, so it would never match`);
98
+ }
87
99
  if (!CONTEXT_ROOTS.includes(root)) {
88
100
  throw new WhenError(`Unknown context root "${root}" (allowed: ${CONTEXT_ROOTS.join(', ')})`);
89
101
  }
@@ -14,8 +14,17 @@ exports.rolloutIncludes = rolloutIncludes;
14
14
  * the API (installations and manifests) and in the host (developer mode).
15
15
  */
16
16
  const sift_1 = __importDefault(require("sift"));
17
- /** Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time. */
18
- exports.CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'deployment', 'user'];
17
+ /**
18
+ * Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time.
19
+ * `locale` and `route` are in the plugin context but are not roots: the platform resolves installations without
20
+ * knowing either, so a condition on them could only ever hold in developer mode.
21
+ */
22
+ exports.CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'user'];
23
+ /**
24
+ * In the plugin context, but not usable in a condition yet. Installations resolve for the application's NRN, so the
25
+ * platform never loads a scope or a deployment and a condition on either would silently never match.
26
+ */
27
+ const UNSUPPORTED_ROOTS = new Set(['scope', 'deployment']);
19
28
  /** Operators that would execute code or are meaningless outside MongoDB. */
20
29
  const ALLOWED_OPERATORS = new Set(['$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin', '$exists', '$size', '$all', '$elemMatch', '$not', '$and', '$or', '$nor', '$mod']);
21
30
  exports.WHEN_LIMITS = { depth: 16, nodes: 512, array: 100, string: 1024 };
@@ -95,6 +104,9 @@ function validateWhen(input) {
95
104
  throw new WhenError('when must be an object');
96
105
  assertSafe(input);
97
106
  for (const root of extractRoots(input)) {
107
+ if (UNSUPPORTED_ROOTS.has(root)) {
108
+ throw new WhenError(`Context root "${root}" is not supported yet: plugins resolve for the application, so it would never match`);
109
+ }
98
110
  if (!exports.CONTEXT_ROOTS.includes(root)) {
99
111
  throw new WhenError(`Unknown context root "${root}" (allowed: ${exports.CONTEXT_ROOTS.join(', ')})`);
100
112
  }
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from "react";
2
+ import type { UI_COMPONENTS_CONTRACTS } from "./contracts.generated";
3
+ type Contract = (typeof UI_COMPONENTS_CONTRACTS)[number];
4
+ /** The elements the SDK takes from @nullplatform/react-ui-components' contracts. */
5
+ export type UiComponentsTag = Contract["tag"];
6
+ type TypeOf<Type> = Type extends "string" ? string : Type extends "number" ? number : Type extends "boolean" ? boolean : Type extends "array" ? readonly unknown[] : Readonly<Record<string, unknown>>;
7
+ type Values<C> = C extends {
8
+ values: infer V;
9
+ } ? V : {};
10
+ type Events<C> = C extends {
11
+ events: infer E;
12
+ } ? E : {};
13
+ type Slots<C> = C extends {
14
+ slots: readonly (infer S extends string)[];
15
+ } ? S : never;
16
+ /**
17
+ * The props a plugin renders an element with, read off its contract: each property with its type, a value list
18
+ * as the union of its values, each event as a callback and each slot as an element.
19
+ */
20
+ export type ContractProps<Tag extends UiComponentsTag, C = Extract<Contract, {
21
+ tag: Tag;
22
+ }>> = C extends {
23
+ properties: infer Properties;
24
+ } ? {
25
+ -readonly [Name in keyof Properties]?: Name extends keyof Values<C> ? Values<C>[Name] extends readonly (infer Value)[] ? Value : never : TypeOf<Properties[Name]>;
26
+ } & {
27
+ [Event in keyof Events<C> as Events<C>[Event] & string]?: (payload: unknown) => void;
28
+ } & {
29
+ [Slot in Slots<C>]?: ReactNode;
30
+ } : never;
31
+ /** Each design-system component a plugin renders, by the name react-ui-components exports it with, with its props. */
32
+ export type UiComponentsProps = {
33
+ [C in Contract as C["component"]]: ContractProps<C["tag"]> & {
34
+ children?: ReactNode;
35
+ };
36
+ };
37
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,102 @@
1
+ export declare const UI_COMPONENTS_CONTRACTS: readonly [{
2
+ readonly tag: "np-badge";
3
+ readonly component: "Badge";
4
+ readonly properties: {
5
+ readonly badgeContent: "string";
6
+ readonly color: "string";
7
+ readonly variant: "string";
8
+ readonly max: "number";
9
+ readonly invisible: "boolean";
10
+ readonly showZero: "boolean";
11
+ readonly overlap: "string";
12
+ };
13
+ readonly events: {};
14
+ readonly values: {
15
+ readonly color: readonly ["default", "primary", "secondary", "error", "info", "success", "warning"];
16
+ readonly variant: readonly ["standard", "dot"];
17
+ readonly overlap: readonly ["rectangular", "circular"];
18
+ };
19
+ readonly children: true;
20
+ }, {
21
+ readonly tag: "np-paper";
22
+ readonly component: "Paper";
23
+ readonly properties: {
24
+ readonly elevation: "number";
25
+ readonly variant: "string";
26
+ readonly square: "boolean";
27
+ };
28
+ readonly events: {};
29
+ readonly values: {
30
+ readonly variant: readonly ["elevation", "outlined"];
31
+ };
32
+ readonly children: true;
33
+ }, {
34
+ readonly tag: "np-list";
35
+ readonly component: "List";
36
+ readonly properties: {
37
+ readonly dense: "boolean";
38
+ readonly disablePadding: "boolean";
39
+ };
40
+ readonly events: {};
41
+ readonly children: true;
42
+ }, {
43
+ readonly tag: "np-list-item";
44
+ readonly component: "ListItem";
45
+ readonly properties: {
46
+ readonly dense: "boolean";
47
+ readonly divider: "boolean";
48
+ readonly disableGutters: "boolean";
49
+ readonly disablePadding: "boolean";
50
+ readonly alignItems: "string";
51
+ };
52
+ readonly events: {};
53
+ readonly slots: readonly ["secondaryAction"];
54
+ readonly values: {
55
+ readonly alignItems: readonly ["center", "flex-start"];
56
+ };
57
+ readonly children: true;
58
+ }, {
59
+ readonly tag: "np-list-item-text";
60
+ readonly component: "ListItemText";
61
+ readonly properties: {
62
+ readonly primary: "string";
63
+ readonly secondary: "string";
64
+ readonly inset: "boolean";
65
+ };
66
+ readonly events: {};
67
+ readonly children: true;
68
+ }, {
69
+ readonly tag: "np-linear-progress";
70
+ readonly component: "LinearProgress";
71
+ readonly properties: {
72
+ readonly value: "number";
73
+ readonly valueBuffer: "number";
74
+ readonly variant: "string";
75
+ readonly color: "string";
76
+ readonly label: "object";
77
+ };
78
+ readonly events: {};
79
+ readonly values: {
80
+ readonly variant: readonly ["determinate", "indeterminate", "buffer", "query"];
81
+ readonly color: readonly ["inherit", "primary", "secondary", "success", "error", "info", "warning"];
82
+ };
83
+ }, {
84
+ readonly tag: "np-circular-progress";
85
+ readonly component: "CircularProgress";
86
+ readonly properties: {
87
+ readonly value: "number";
88
+ readonly variant: "string";
89
+ readonly color: "string";
90
+ readonly size: "number";
91
+ readonly thickness: "number";
92
+ readonly label: "object";
93
+ };
94
+ readonly events: {};
95
+ readonly values: {
96
+ readonly variant: readonly ["determinate", "indeterminate"];
97
+ readonly color: readonly ["inherit", "primary", "secondary", "success", "error", "info", "warning"];
98
+ };
99
+ readonly defaults: {
100
+ readonly thickness: 3.6;
101
+ };
102
+ }];
@@ -0,0 +1,58 @@
1
+ // Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.4. Don't edit: change the contract in
2
+ // react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
3
+ export const UI_COMPONENTS_CONTRACTS = [
4
+ {
5
+ tag: "np-badge",
6
+ component: "Badge",
7
+ properties: { "badgeContent": "string", "color": "string", "variant": "string", "max": "number", "invisible": "boolean", "showZero": "boolean", "overlap": "string" },
8
+ events: {},
9
+ values: { "color": ["default", "primary", "secondary", "error", "info", "success", "warning"], "variant": ["standard", "dot"], "overlap": ["rectangular", "circular"] },
10
+ children: true,
11
+ },
12
+ {
13
+ tag: "np-paper",
14
+ component: "Paper",
15
+ properties: { "elevation": "number", "variant": "string", "square": "boolean" },
16
+ events: {},
17
+ values: { "variant": ["elevation", "outlined"] },
18
+ children: true,
19
+ },
20
+ {
21
+ tag: "np-list",
22
+ component: "List",
23
+ properties: { "dense": "boolean", "disablePadding": "boolean" },
24
+ events: {},
25
+ children: true,
26
+ },
27
+ {
28
+ tag: "np-list-item",
29
+ component: "ListItem",
30
+ properties: { "dense": "boolean", "divider": "boolean", "disableGutters": "boolean", "disablePadding": "boolean", "alignItems": "string" },
31
+ events: {},
32
+ slots: ["secondaryAction"],
33
+ values: { "alignItems": ["center", "flex-start"] },
34
+ children: true,
35
+ },
36
+ {
37
+ tag: "np-list-item-text",
38
+ component: "ListItemText",
39
+ properties: { "primary": "string", "secondary": "string", "inset": "boolean" },
40
+ events: {},
41
+ children: true,
42
+ },
43
+ {
44
+ tag: "np-linear-progress",
45
+ component: "LinearProgress",
46
+ properties: { "value": "number", "valueBuffer": "number", "variant": "string", "color": "string", "label": "object" },
47
+ events: {},
48
+ values: { "variant": ["determinate", "indeterminate", "buffer", "query"], "color": ["inherit", "primary", "secondary", "success", "error", "info", "warning"] },
49
+ },
50
+ {
51
+ tag: "np-circular-progress",
52
+ component: "CircularProgress",
53
+ properties: { "value": "number", "variant": "string", "color": "string", "size": "number", "thickness": "number", "label": "object" },
54
+ events: {},
55
+ values: { "variant": ["determinate", "indeterminate"], "color": ["inherit", "primary", "secondary", "success", "error", "info", "warning"] },
56
+ defaults: { "thickness": 3.6 },
57
+ },
58
+ ];
@@ -10,6 +10,10 @@ export declare const PROTOCOL_VERSION = 1;
10
10
  export type FunctionToken = {
11
11
  $fn: string;
12
12
  };
13
+ /**
14
+ * Where the plugin is rendering. Identity only (ids, slugs, names): every plugin receives it whatever its
15
+ * permissions, so anything else about an entity goes through `api` with a declared permission.
16
+ */
13
17
  export interface PluginContext {
14
18
  organization?: {
15
19
  id: number | string;
@@ -31,6 +35,16 @@ export interface PluginContext {
31
35
  slug?: string;
32
36
  name?: string;
33
37
  };
38
+ /** Set on scope pages. Not usable in `when` yet (see `CONTEXT_ROOTS`). */
39
+ scope?: {
40
+ id: number | string;
41
+ slug?: string;
42
+ name?: string;
43
+ };
44
+ /** Set on deployment pages. Not usable in `when` yet (see `CONTEXT_ROOTS`). */
45
+ deployment?: {
46
+ id: number | string;
47
+ };
34
48
  nrn?: string;
35
49
  user?: {
36
50
  id: number | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullplatform/ui-plugin-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "SDK for nullplatform UI plugins: catalog components, bridge client and defineUI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -32,9 +32,11 @@
32
32
  ],
33
33
  "scripts": {
34
34
  "build": "tsc -p tsconfig.json && tsc -p tsconfig.contract.cjs.json && node scripts/finish-build.mjs",
35
- "typecheck": "tsc -p tsconfig.json --noEmit",
36
- "test": "vitest run --passWithNoTests"
35
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test-types.json",
36
+ "test": "vitest run --passWithNoTests",
37
+ "sync:contracts": "node scripts/sync-contracts.mjs"
37
38
  },
39
+ "uiComponentsContracts": "0.15.4",
38
40
  "dependencies": {
39
41
  "@remote-dom/core": "^1.11.1",
40
42
  "@remote-dom/react": "^1.2.2",