@nullplatform/ui-plugin-sdk 0.5.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,10 +19,19 @@ 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
  }
23
- export declare const CATALOG: readonly CatalogElementSpec[];
24
- export declare const CATALOG_BY_TAG: ReadonlyMap<string, CatalogElementSpec>;
25
35
  /**
26
36
  * The values a plugin may pass to these props. The SDK's components are typed from these lists, and
27
37
  * the host checks each value against them again at runtime, falling back to the element's default:
@@ -35,6 +45,7 @@ export declare const CATALOG_PROP_VALUES: {
35
45
  readonly Button: {
36
46
  readonly variant: readonly ["contained", "outlined", "text", "soft"];
37
47
  readonly color: readonly ["inherit", "primary", "secondary", "success", "error", "info", "warning"];
48
+ readonly size: readonly ["small", "medium", "large"];
38
49
  };
39
50
  readonly Chip: {
40
51
  readonly color: readonly ["default", "primary", "secondary", "success", "error", "info", "warning"];
@@ -44,7 +55,19 @@ export declare const CATALOG_PROP_VALUES: {
44
55
  readonly Skeleton: {
45
56
  readonly variant: readonly ["text", "rectangular", "rounded", "circular"];
46
57
  };
58
+ readonly Stack: {
59
+ readonly direction: readonly ["row", "column"];
60
+ };
61
+ readonly Alert: {
62
+ readonly severity: readonly ["success", "info", "warning", "error"];
63
+ };
47
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
+ */
69
+ export declare const CATALOG: readonly CatalogElementSpec[];
70
+ export declare const CATALOG_BY_TAG: ReadonlyMap<string, CatalogElementSpec>;
48
71
  export type TextVariant = (typeof CATALOG_PROP_VALUES.Text.variant)[number];
49
72
  export type TextAlign = (typeof CATALOG_PROP_VALUES.Text.align)[number];
50
73
  export type ButtonVariant = (typeof CATALOG_PROP_VALUES.Button.variant)[number];
@@ -53,5 +76,8 @@ export type ChipColor = (typeof CATALOG_PROP_VALUES.Chip.color)[number];
53
76
  export type ChipVariant = (typeof CATALOG_PROP_VALUES.Chip.variant)[number];
54
77
  export type ChipSize = (typeof CATALOG_PROP_VALUES.Chip.size)[number];
55
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];
56
82
  /** Name of the wrapper element remote-dom uses for React elements passed as props. */
57
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,34 +350,14 @@ export const CATALOG = [
283
350
  height: "number",
284
351
  },
285
352
  events: {},
353
+ cssValues: ["color"],
286
354
  },
287
355
  ];
288
- export const CATALOG_BY_TAG = new Map(CATALOG.map((spec) => [spec.tag, spec]));
289
356
  /**
290
- * The values a plugin may pass to these props. The SDK's components are typed from these lists, and
291
- * the host checks each value against them again at runtime, falling back to the element's default:
292
- * a published bundle has already left TypeScript behind.
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`.
293
359
  */
294
- export const CATALOG_PROP_VALUES = {
295
- Text: {
296
- variant: [
297
- "h1", "h2", "h3", "h4", "h5", "h6",
298
- "subtitle1", "subtitle2", "body1", "body2", "caption", "overline", "button",
299
- ],
300
- align: ["inherit", "left", "center", "right", "justify"],
301
- },
302
- Button: {
303
- variant: ["contained", "outlined", "text", "soft"],
304
- color: ["inherit", "primary", "secondary", "success", "error", "info", "warning"],
305
- },
306
- Chip: {
307
- color: ["default", "primary", "secondary", "success", "error", "info", "warning"],
308
- variant: ["filled", "outlined", "soft"],
309
- size: ["small", "medium"],
310
- },
311
- Skeleton: {
312
- variant: ["text", "rectangular", "rounded", "circular"],
313
- },
314
- };
360
+ export const CATALOG = [...OWN_CATALOG, ...UI_COMPONENTS_CONTRACTS];
361
+ export const CATALOG_BY_TAG = new Map(CATALOG.map((spec) => [spec.tag, spec]));
315
362
  /** Name of the wrapper element remote-dom uses for React elements passed as props. */
316
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,11 +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
- import { type ButtonColor, type ButtonVariant, type ChipColor, type ChipSize, type ChipVariant, type SkeletonVariant, type TextAlign, type TextVariant } from "./catalog.js";
9
- export type { ButtonColor, ButtonVariant, ChipColor, ChipSize, ChipVariant, SkeletonVariant, TextAlign, TextVariant, } from "./catalog.js";
10
- 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<{
11
12
  label: string;
12
13
  value: string;
13
14
  multiline?: boolean;
@@ -18,7 +19,7 @@ export declare const TextField: ComponentType<{
18
19
  } & {
19
20
  children?: ReactNode;
20
21
  }>;
21
- export declare const Select: ComponentType<{
22
+ export declare const Select: import("react").ComponentType<{
22
23
  label: string;
23
24
  value?: string;
24
25
  values?: string[];
@@ -32,7 +33,7 @@ export declare const Select: ComponentType<{
32
33
  } & {
33
34
  children?: ReactNode;
34
35
  }>;
35
- export declare const Switch: ComponentType<{
36
+ export declare const Switch: import("react").ComponentType<{
36
37
  label: string;
37
38
  checked: boolean;
38
39
  disabled?: boolean;
@@ -40,7 +41,7 @@ export declare const Switch: ComponentType<{
40
41
  } & {
41
42
  children?: ReactNode;
42
43
  }>;
43
- export declare const NetworkGraph: ComponentType<{
44
+ export declare const NetworkGraph: import("react").ComponentType<{
44
45
  nodes: Array<Record<string, unknown>>;
45
46
  edges: Array<{
46
47
  from: string;
@@ -61,7 +62,7 @@ export interface TableColumn {
61
62
  export type TableRow = Record<string, string | number | boolean | null | undefined> & {
62
63
  id?: string | number;
63
64
  };
64
- export declare const Image: ComponentType<{
65
+ export declare const Image: import("react").ComponentType<{
65
66
  src: string;
66
67
  alt: string;
67
68
  width?: number;
@@ -69,7 +70,7 @@ export declare const Image: ComponentType<{
69
70
  } & {
70
71
  children?: ReactNode;
71
72
  }>;
72
- export declare const Card: ComponentType<{
73
+ export declare const Card: import("react").ComponentType<{
73
74
  title?: string;
74
75
  subtitle?: string;
75
76
  padding?: string;
@@ -77,8 +78,8 @@ export declare const Card: ComponentType<{
77
78
  } & {
78
79
  children?: ReactNode;
79
80
  }>;
80
- export declare const Stack: ComponentType<{
81
- direction?: "row" | "column";
81
+ export declare const Stack: import("react").ComponentType<{
82
+ direction?: StackDirection;
82
83
  spacing?: number;
83
84
  align?: string;
84
85
  justify?: string;
@@ -86,7 +87,7 @@ export declare const Stack: ComponentType<{
86
87
  } & {
87
88
  children?: ReactNode;
88
89
  }>;
89
- export declare const Text: ComponentType<{
90
+ export declare const Text: import("react").ComponentType<{
90
91
  variant?: TextVariant;
91
92
  /** A theme color path (`text.secondary`, `error.main`) or any CSS color. */
92
93
  color?: string;
@@ -95,10 +96,10 @@ export declare const Text: ComponentType<{
95
96
  } & {
96
97
  children?: ReactNode;
97
98
  }>;
98
- export declare const Button: ComponentType<{
99
+ export declare const Button: import("react").ComponentType<{
99
100
  variant?: ButtonVariant;
100
101
  color?: ButtonColor;
101
- size?: "small" | "medium" | "large";
102
+ size?: ButtonSize;
102
103
  disabled?: boolean;
103
104
  loading?: boolean;
104
105
  icon?: string;
@@ -106,7 +107,7 @@ export declare const Button: ComponentType<{
106
107
  } & {
107
108
  children?: ReactNode;
108
109
  }>;
109
- export declare const Chip: ComponentType<{
110
+ export declare const Chip: import("react").ComponentType<{
110
111
  label: string;
111
112
  color?: ChipColor;
112
113
  variant?: ChipVariant;
@@ -114,7 +115,7 @@ export declare const Chip: ComponentType<{
114
115
  } & {
115
116
  children?: ReactNode;
116
117
  }>;
117
- export declare const Link: ComponentType<{
118
+ export declare const Link: import("react").ComponentType<{
118
119
  to?: string;
119
120
  params?: Record<string, string | number>;
120
121
  href?: string;
@@ -122,7 +123,7 @@ export declare const Link: ComponentType<{
122
123
  } & {
123
124
  children?: ReactNode;
124
125
  }>;
125
- export declare const Table: ComponentType<{
126
+ export declare const Table: import("react").ComponentType<{
126
127
  columns: TableColumn[];
127
128
  rows: TableRow[];
128
129
  dense?: boolean;
@@ -131,41 +132,41 @@ export declare const Table: ComponentType<{
131
132
  } & {
132
133
  children?: ReactNode;
133
134
  }>;
134
- export declare const Skeleton: ComponentType<{
135
+ export declare const Skeleton: import("react").ComponentType<{
135
136
  height?: number;
136
137
  width?: string;
137
138
  variant?: SkeletonVariant;
138
139
  } & {
139
140
  children?: ReactNode;
140
141
  }>;
141
- export declare const Empty: ComponentType<{
142
+ export declare const Empty: import("react").ComponentType<{
142
143
  title?: string;
143
144
  description?: string;
144
145
  } & {
145
146
  children?: ReactNode;
146
147
  }>;
147
- export declare const Alert: ComponentType<{
148
- severity?: "success" | "info" | "warning" | "error";
148
+ export declare const Alert: import("react").ComponentType<{
149
+ severity?: AlertSeverity;
149
150
  title?: string;
150
151
  } & {
151
152
  children?: ReactNode;
152
153
  }>;
153
- export declare const Icon: ComponentType<{
154
+ export declare const Icon: import("react").ComponentType<{
154
155
  icon: string;
155
156
  size?: number;
156
157
  color?: string;
157
158
  } & {
158
159
  children?: ReactNode;
159
160
  }>;
160
- export declare const Divider: ComponentType<{
161
+ export declare const Divider: import("react").ComponentType<{
161
162
  children?: ReactNode;
162
163
  }>;
163
- export declare const Markdown: ComponentType<{
164
+ export declare const Markdown: import("react").ComponentType<{
164
165
  content: string;
165
166
  } & {
166
167
  children?: ReactNode;
167
168
  }>;
168
- export declare const Code: ComponentType<{
169
+ export declare const Code: import("react").ComponentType<{
169
170
  content: string;
170
171
  language?: string;
171
172
  maxHeight?: number;
@@ -178,7 +179,7 @@ export interface EgoEdge {
178
179
  kind?: string;
179
180
  }
180
181
  /** Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right. */
181
- export declare const EgoGraph: ComponentType<{
182
+ export declare const EgoGraph: import("react").ComponentType<{
182
183
  focus: string;
183
184
  inbound: EgoEdge[];
184
185
  outbound: EgoEdge[];
@@ -187,7 +188,7 @@ export declare const EgoGraph: ComponentType<{
187
188
  } & {
188
189
  children?: ReactNode;
189
190
  }>;
190
- export declare const Box: ComponentType<{
191
+ export declare const Box: import("react").ComponentType<{
191
192
  padding?: string;
192
193
  height?: string;
193
194
  width?: string;
@@ -196,7 +197,7 @@ export declare const Box: ComponentType<{
196
197
  children?: ReactNode;
197
198
  }>;
198
199
  /** Responsive grid: as many columns as fit `min` px, up to `columns`. */
199
- export declare const Grid: ComponentType<{
200
+ export declare const Grid: import("react").ComponentType<{
200
201
  columns?: number;
201
202
  min?: number;
202
203
  gap?: number;
@@ -205,7 +206,7 @@ export declare const Grid: ComponentType<{
205
206
  }>;
206
207
  export type ValueFormat = "number" | "currency" | "percent" | "compact";
207
208
  /** Big number tile. `trend` draws the arrow; `tone` colors the delta (`positive` = good, whatever the direction). */
208
- export declare const Metric: ComponentType<{
209
+ export declare const Metric: import("react").ComponentType<{
209
210
  label: string;
210
211
  value: string;
211
212
  delta?: string;
@@ -225,7 +226,7 @@ export declare const Metric: ComponentType<{
225
226
  */
226
227
  export type ThemeColor = "primary" | "info" | "success" | "warning" | "error" | "secondary" | "grey" | "muted" | `palette:${number}`;
227
228
  /** `area` fills under the line; off by default. */
228
- export declare const Sparkline: ComponentType<{
229
+ export declare const Sparkline: import("react").ComponentType<{
229
230
  values: number[];
230
231
  height?: number;
231
232
  color?: string;
@@ -245,7 +246,7 @@ export interface ChartPoint {
245
246
  index: number;
246
247
  }
247
248
  /** Time series; `categories` are the x labels, one per value. */
248
- export declare const LineChart: ComponentType<{
249
+ export declare const LineChart: import("react").ComponentType<{
249
250
  series: ChartSeries[];
250
251
  categories: string[];
251
252
  stacked?: boolean;
@@ -259,7 +260,7 @@ export declare const LineChart: ComponentType<{
259
260
  } & {
260
261
  children?: ReactNode;
261
262
  }>;
262
- export declare const BarChart: ComponentType<{
263
+ export declare const BarChart: import("react").ComponentType<{
263
264
  series: ChartSeries[];
264
265
  categories: string[];
265
266
  stacked?: boolean;
@@ -278,7 +279,7 @@ export interface DonutItem {
278
279
  color?: ThemeColor | string;
279
280
  }
280
281
  /** Part-to-whole ring; the center shows `total` or the formatted sum. */
281
- export declare const Donut: ComponentType<{
282
+ export declare const Donut: import("react").ComponentType<{
282
283
  items: DonutItem[];
283
284
  total?: string;
284
285
  height?: number;
@@ -290,7 +291,7 @@ export declare const Donut: ComponentType<{
290
291
  children?: ReactNode;
291
292
  }>;
292
293
  /** Horizontal share bar, `value` in 0..1. */
293
- export declare const ProgressBar: ComponentType<{
294
+ export declare const ProgressBar: import("react").ComponentType<{
294
295
  value: number;
295
296
  label?: string;
296
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");
@@ -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
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullplatform/ui-plugin-sdk",
3
- "version": "0.5.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",
@@ -33,8 +33,10 @@
33
33
  "scripts": {
34
34
  "build": "tsc -p tsconfig.json && tsc -p tsconfig.contract.cjs.json && node scripts/finish-build.mjs",
35
35
  "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test-types.json",
36
- "test": "vitest run --passWithNoTests"
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",