@nullplatform/ui-plugin-sdk 0.7.1 → 0.9.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
@@ -55,20 +55,33 @@ export declare const CATALOG_PROP_VALUES: {
55
55
  readonly color: readonly ["inherit", "primary", "secondary", "success", "error", "info", "warning"];
56
56
  readonly size: readonly ["small", "medium", "large"];
57
57
  };
58
+ readonly EgoGraph: {
59
+ readonly layout: readonly ["columns", "constellation"];
60
+ };
58
61
  readonly Chip: {
59
62
  readonly color: readonly ["default", "primary", "secondary", "success", "error", "info", "warning"];
60
63
  readonly variant: readonly ["filled", "outlined", "soft"];
61
64
  readonly size: readonly ["small", "medium"];
62
65
  };
66
+ readonly Link: {
67
+ readonly color: readonly ["primary", "secondary", "error", "inherit", "textPrimary", "textSecondary"];
68
+ readonly underline: readonly ["none", "hover", "always"];
69
+ };
63
70
  readonly Skeleton: {
64
71
  readonly variant: readonly ["text", "rectangular", "rounded", "circular"];
65
72
  };
73
+ readonly Card: {
74
+ readonly tone: readonly ["default", "accent"];
75
+ };
66
76
  readonly Stack: {
67
77
  readonly direction: readonly ["row", "column"];
68
78
  };
69
79
  readonly Alert: {
70
80
  readonly severity: readonly ["success", "info", "warning", "error"];
71
81
  };
82
+ readonly Scatter: {
83
+ readonly xScale: readonly ["linear", "log"];
84
+ };
72
85
  };
73
86
  /**
74
87
  * Every element a plugin can render: the SDK's own, then the design-system components whose contracts
@@ -84,8 +97,12 @@ export type ChipColor = (typeof CATALOG_PROP_VALUES.Chip.color)[number];
84
97
  export type ChipVariant = (typeof CATALOG_PROP_VALUES.Chip.variant)[number];
85
98
  export type ChipSize = (typeof CATALOG_PROP_VALUES.Chip.size)[number];
86
99
  export type SkeletonVariant = (typeof CATALOG_PROP_VALUES.Skeleton.variant)[number];
100
+ export type CardTone = (typeof CATALOG_PROP_VALUES.Card.tone)[number];
87
101
  export type ButtonSize = (typeof CATALOG_PROP_VALUES.Button.size)[number];
88
102
  export type StackDirection = (typeof CATALOG_PROP_VALUES.Stack.direction)[number];
89
103
  export type AlertSeverity = (typeof CATALOG_PROP_VALUES.Alert.severity)[number];
104
+ export type LinkColor = (typeof CATALOG_PROP_VALUES.Link.color)[number];
105
+ export type LinkUnderline = (typeof CATALOG_PROP_VALUES.Link.underline)[number];
106
+ export type ScatterScale = (typeof CATALOG_PROP_VALUES.Scatter.xScale)[number];
90
107
  /** Name of the wrapper element remote-dom uses for React elements passed as props. */
91
108
  export declare const FRAGMENT_TAG = "remote-fragment";
package/dist/catalog.js CHANGED
@@ -27,20 +27,35 @@ export const CATALOG_PROP_VALUES = {
27
27
  color: ["inherit", "primary", "secondary", "success", "error", "info", "warning"],
28
28
  size: ["small", "medium", "large"],
29
29
  },
30
+ EgoGraph: {
31
+ layout: ["columns", "constellation"],
32
+ },
30
33
  Chip: {
31
34
  color: ["default", "primary", "secondary", "success", "error", "info", "warning"],
32
35
  variant: ["filled", "outlined", "soft"],
33
36
  size: ["small", "medium"],
34
37
  },
38
+ // MUI's Link resolves only these colors; any other one breaks its underline.
39
+ Link: {
40
+ color: ["primary", "secondary", "error", "inherit", "textPrimary", "textSecondary"],
41
+ underline: ["none", "hover", "always"],
42
+ },
35
43
  Skeleton: {
36
44
  variant: ["text", "rectangular", "rounded", "circular"],
37
45
  },
46
+ // accent: a soft tint of the primary color, for content set apart from the page (an AI answer, a highlight)
47
+ Card: {
48
+ tone: ["default", "accent"],
49
+ },
38
50
  Stack: {
39
51
  direction: ["row", "column"],
40
52
  },
41
53
  Alert: {
42
54
  severity: ["success", "info", "warning", "error"],
43
55
  },
56
+ Scatter: {
57
+ xScale: ["linear", "log"],
58
+ },
44
59
  };
45
60
  /** The elements the SDK defines itself. */
46
61
  const OWN_CATALOG = [
@@ -96,9 +111,17 @@ const OWN_CATALOG = [
96
111
  {
97
112
  tag: "np-card",
98
113
  component: "Card",
99
- properties: { title: "string", subtitle: "string", padding: "string" },
100
- events: {},
101
- slots: ["action"],
114
+ properties: {
115
+ title: "string",
116
+ subtitle: "string",
117
+ padding: "string",
118
+ to: "string",
119
+ params: "object",
120
+ tone: "string",
121
+ },
122
+ events: { press: "onPress" },
123
+ values: CATALOG_PROP_VALUES.Card,
124
+ slots: ["action", "avatar", "header"],
102
125
  children: true,
103
126
  },
104
127
  {
@@ -144,6 +167,7 @@ const OWN_CATALOG = [
144
167
  icon: "string",
145
168
  },
146
169
  events: { press: "onPress" },
170
+ slots: ["endIcon"],
147
171
  values: CATALOG_PROP_VALUES.Button,
148
172
  children: true,
149
173
  defaults: { variant: "contained", color: "primary", size: "small" },
@@ -164,8 +188,15 @@ const OWN_CATALOG = [
164
188
  {
165
189
  tag: "np-link",
166
190
  component: "Link",
167
- properties: { to: "string", params: "object", href: "string" },
191
+ properties: {
192
+ to: "string",
193
+ params: "object",
194
+ href: "string",
195
+ color: "string",
196
+ underline: "string",
197
+ },
168
198
  events: { press: "onPress" },
199
+ values: CATALOG_PROP_VALUES.Link,
169
200
  children: true,
170
201
  },
171
202
  {
@@ -233,22 +264,35 @@ const OWN_CATALOG = [
233
264
  {
234
265
  tag: "np-ego-graph",
235
266
  component: "EgoGraph",
267
+ // `columns` lists each side as rows; `constellation` draws each side's `group`s as clusters around the focus.
236
268
  properties: {
237
269
  focus: "string",
238
270
  inbound: "array",
239
271
  outbound: "array",
240
272
  height: "number",
273
+ layout: "string",
274
+ selected: "object",
241
275
  },
242
- events: { nodePress: "onNodePress" },
276
+ values: CATALOG_PROP_VALUES.EgoGraph,
277
+ defaults: { layout: "columns" },
278
+ events: { nodePress: "onNodePress", neighborPress: "onNeighborPress", groupPress: "onGroupPress" },
243
279
  },
244
280
  {
245
281
  tag: "np-box",
246
282
  component: "Box",
247
283
  properties: {
248
284
  padding: "string",
285
+ paddingX: "number",
286
+ paddingY: "number",
287
+ paddingTop: "number",
288
+ paddingRight: "number",
289
+ paddingBottom: "number",
290
+ paddingLeft: "number",
249
291
  height: "string",
250
292
  width: "string",
251
293
  grow: "boolean",
294
+ // stays in view as the page scrolls (a side index, a table of contents); scrolls inside when taller than the screen
295
+ sticky: "boolean",
252
296
  },
253
297
  events: {},
254
298
  cssValues: ["height", "width"],
@@ -335,10 +379,47 @@ const OWN_CATALOG = [
335
379
  format: "string",
336
380
  currency: "string",
337
381
  hideLegend: "boolean",
382
+ hidePercent: "boolean",
338
383
  },
339
384
  events: { slicePress: "onSlicePress" },
340
385
  cssValues: ["items[].color"],
341
386
  },
387
+ {
388
+ // Two measures per item, size as a third. `points: [{ id?, label, x, y, size?, color?, hollow? }]`; `quadrants`
389
+ // splits the plane at `{ x, y }` and names and tints the four corners. Not every host draws it: see `hostRenders`.
390
+ tag: "np-scatter",
391
+ component: "Scatter",
392
+ properties: {
393
+ points: "array",
394
+ quadrants: "object",
395
+ xLabel: "string",
396
+ yLabel: "string",
397
+ sizeLabel: "string",
398
+ xScale: "string",
399
+ xFormat: "string",
400
+ yFormat: "string",
401
+ xMax: "number",
402
+ yMax: "number",
403
+ selected: "string",
404
+ height: "number",
405
+ },
406
+ events: { pointPress: "onPointPress" },
407
+ values: CATALOG_PROP_VALUES.Scatter,
408
+ cssValues: ["points[].color"],
409
+ },
410
+ {
411
+ // Groups as soft circles with their members inside as bubbles, sized by `size`. `groups: [{ id?, label, color?,
412
+ // nodes: [{ id, label, size? }] }]`; a node may sit in several groups. Not every host draws it: see `hostRenders`.
413
+ tag: "np-cluster-map",
414
+ component: "ClusterMap",
415
+ properties: {
416
+ groups: "array",
417
+ selected: "string",
418
+ sizeLabel: "string",
419
+ },
420
+ events: { nodePress: "onNodePress" },
421
+ cssValues: ["groups[].color"],
422
+ },
342
423
  {
343
424
  // Horizontal share bar, 0..1.
344
425
  tag: "np-progress-bar",
package/dist/component.js CHANGED
@@ -4,6 +4,7 @@ import { createRemoteComponent } from "@remote-dom/react";
4
4
  import { createElement, useLayoutEffect, useRef } from "react";
5
5
  import { CATALOG_BY_TAG } from "./catalog.js";
6
6
  import { defineCatalogElements } from "./elements.js";
7
+ import { registerTag } from "./host.js";
7
8
  const elements = defineCatalogElements();
8
9
  /** The React component a plugin renders a catalog element with. */
9
10
  export function component(tag) {
@@ -30,19 +31,27 @@ export function component(tag) {
30
31
  passed.current = Object.keys(props).filter((prop) => prop !== "children");
31
32
  });
32
33
  // remote-dom delivers a RemoteEvent to listeners; plugin authors want the payload the host sent.
34
+ // One wrapper per handler prop for the element's whole life, reading the latest handler from a ref:
35
+ // a new function every render would make the host release the one its rendered element still holds,
36
+ // and an event fired before the host re-renders (a fast keystroke) would call a released id.
37
+ const latest = useRef({});
38
+ const stable = useRef({});
39
+ latest.current = props;
33
40
  for (const prop of handlerProps) {
34
- const handler = props[prop];
35
- if (typeof handler === "function") {
36
- mapped[prop] = (event) => {
37
- const detail = event && typeof event === "object" && "detail" in event
38
- ? event.detail
39
- : event;
40
- return handler(detail);
41
- };
42
- }
41
+ if (typeof props[prop] !== "function")
42
+ continue;
43
+ stable.current[prop] ??= (event) => {
44
+ const detail = event && typeof event === "object" && "detail" in event
45
+ ? event.detail
46
+ : event;
47
+ const handler = latest.current[prop];
48
+ return typeof handler === "function" ? handler(detail) : undefined;
49
+ };
50
+ mapped[prop] = stable.current[prop];
43
51
  }
44
52
  return createElement(Remote, mapped);
45
53
  };
46
54
  Wrapped.displayName = spec.component;
55
+ registerTag(Wrapped, tag);
47
56
  return Wrapped;
48
57
  }
@@ -4,10 +4,11 @@ import "./polyfill.js";
4
4
  * the host decides how it looks.
5
5
  */
6
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";
7
+ import { type AlertSeverity, type ButtonColor, type ButtonSize, type ButtonVariant, type CardTone, type ChipColor, type ChipSize, type ChipVariant, type LinkColor, type LinkUnderline, type ScatterScale, type SkeletonVariant, type StackDirection, type TextAlign, type TextVariant } from "./catalog.js";
8
+ export type { AlertSeverity, ButtonColor, ButtonSize, ButtonVariant, CardTone, ChipColor, ChipSize, ChipVariant, LinkColor, LinkUnderline, ScatterScale, SkeletonVariant, StackDirection, TextAlign, TextVariant, } from "./catalog.js";
9
9
  export * from "./components.generated.js";
10
10
  export type { ContractProps, UiComponentsTag } from "./contractProps.js";
11
+ export type { DataTableAvatar, DataTableColor, DataTableColumn, DataTableFormatter, DataTableLabelVariant, DataTableLink, DataTablePagination, DataTableRow, DataTableRowAction, DataTableState, DataTableTypography, } from "./dataTable.js";
11
12
  export declare const TextField: import("react").ComponentType<{
12
13
  label: string;
13
14
  value: string;
@@ -75,6 +76,17 @@ export declare const Card: import("react").ComponentType<{
75
76
  subtitle?: string;
76
77
  padding?: string;
77
78
  action?: ReactNode;
79
+ /** Drawn before the title, such as `<Icon icon="lucide:shield-alert" />`. */
80
+ avatar?: ReactNode;
81
+ /** Drawn in place of `title` and `subtitle`, for a title that text alone can't say. */
82
+ header?: ReactNode;
83
+ /** A logical route of the host: the whole card links to it. */
84
+ to?: string;
85
+ params?: Record<string, string | number>;
86
+ /** `accent` tints the card softly with the primary color, to set its content apart (an AI answer, a highlight). */
87
+ tone?: CardTone;
88
+ /** Makes the whole card clickable. `action` stays outside the clickable area; keep other controls out of it. */
89
+ onPress?: () => void;
78
90
  } & {
79
91
  children?: ReactNode;
80
92
  }>;
@@ -103,6 +115,8 @@ export declare const Button: import("react").ComponentType<{
103
115
  disabled?: boolean;
104
116
  loading?: boolean;
105
117
  icon?: string;
118
+ /** Drawn after the label, such as `<Icon icon="lucide:chevron-right" />`. */
119
+ endIcon?: ReactNode;
106
120
  onPress?: () => void;
107
121
  } & {
108
122
  children?: ReactNode;
@@ -119,6 +133,10 @@ export declare const Link: import("react").ComponentType<{
119
133
  to?: string;
120
134
  params?: Record<string, string | number>;
121
135
  href?: string;
136
+ /** Unset, the theme's link color. `inherit` takes the surrounding text's. */
137
+ color?: LinkColor;
138
+ /** Unset, the theme's: underlined on hover. */
139
+ underline?: LinkUnderline;
122
140
  onPress?: () => void;
123
141
  } & {
124
142
  children?: ReactNode;
@@ -177,22 +195,56 @@ export interface EgoEdge {
177
195
  node: string;
178
196
  label?: string;
179
197
  kind?: string;
198
+ /** The cluster the node joins in the `constellation` layout (a namespace, a kind); its `kind` when absent. */
199
+ group?: string;
180
200
  }
181
- /** Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right. */
201
+ /** Which side of the ego graph: `in` uses the focus, the focus uses `out`. */
202
+ export type EgoDirection = "in" | "out";
203
+ /** What the ego graph highlights: one node, or one side's group. */
204
+ export interface EgoSelection {
205
+ node?: string;
206
+ direction?: EgoDirection;
207
+ group?: string;
208
+ }
209
+ /**
210
+ * Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right.
211
+ * `layout: "constellation"` draws each side's groups as clusters of dots around the focus, for large neighborhoods.
212
+ */
182
213
  export declare const EgoGraph: import("react").ComponentType<{
183
214
  focus: string;
184
215
  inbound: EgoEdge[];
185
216
  outbound: EgoEdge[];
186
217
  height?: number;
218
+ layout?: "columns" | "constellation";
219
+ selected?: EgoSelection;
187
220
  onNodePress?: (node: string) => void;
221
+ /** Constellation only: the pressed dot with its side and group (a node can sit on both sides). */
222
+ onNeighborPress?: (neighbor: {
223
+ node: string;
224
+ direction: EgoDirection;
225
+ group: string;
226
+ }) => void;
227
+ onGroupPress?: (group: {
228
+ direction: EgoDirection;
229
+ group: string;
230
+ }) => void;
188
231
  } & {
189
232
  children?: ReactNode;
190
233
  }>;
234
+ /** `sticky` keeps the box in view as the page scrolls; the host sets the offset, and a taller box scrolls inside. */
191
235
  export declare const Box: import("react").ComponentType<{
192
236
  padding?: string;
237
+ /** In the theme's spacing units (1 = 8px). Each one overrides `padding` on its sides. */
238
+ paddingX?: number;
239
+ paddingY?: number;
240
+ paddingTop?: number;
241
+ paddingRight?: number;
242
+ paddingBottom?: number;
243
+ paddingLeft?: number;
193
244
  height?: string;
194
245
  width?: string;
195
246
  grow?: boolean;
247
+ sticky?: boolean;
196
248
  } & {
197
249
  children?: ReactNode;
198
250
  }>;
@@ -286,10 +338,93 @@ export declare const Donut: import("react").ComponentType<{
286
338
  format?: ValueFormat;
287
339
  currency?: string;
288
340
  hideLegend?: boolean;
341
+ /** Leaves each slice's share out of the legend; the center still shows it for the slice under the cursor. */
342
+ hidePercent?: boolean;
289
343
  onSlicePress?: (item: DonutItem) => void;
290
344
  } & {
291
345
  children?: ReactNode;
292
346
  }>;
347
+ export interface ScatterPoint {
348
+ /** What `selected` and the press payload identify the point by; the label when left out. */
349
+ id?: string;
350
+ label: string;
351
+ x: number;
352
+ y: number;
353
+ /** Relative area: the largest point gets the largest dot. Every dot is the same size when left out. */
354
+ size?: number;
355
+ color?: ThemeColor | string;
356
+ /** Outline with a faint fill, for points that matter less. */
357
+ hollow?: boolean;
358
+ }
359
+ /**
360
+ * Splits the plane at `x` and `y`. `labels` names the corners and `colors` tints them, both in reading order
361
+ * (top left, top right, bottom left, bottom right); `null` leaves a corner untinted.
362
+ */
363
+ export interface ScatterQuadrants {
364
+ x: number;
365
+ y: number;
366
+ labels?: [string, string, string, string];
367
+ colors?: [ThemeColor | string | null, ThemeColor | string | null, ThemeColor | string | null, ThemeColor | string | null];
368
+ }
369
+ /**
370
+ * Items placed by two measures, with a third as dot size: where each sits says what to do with it.
371
+ * Labels show where they fit; the rest show on hover. With `sizeLabel` the chart keys the dot sizes below it.
372
+ * Not every host draws it: check `hostRenders(Scatter)`.
373
+ */
374
+ export declare const Scatter: import("react").ComponentType<{
375
+ points: ScatterPoint[];
376
+ quadrants?: ScatterQuadrants;
377
+ xLabel?: string;
378
+ yLabel?: string;
379
+ /** What `size` counts, for the tooltip; the tooltip leaves size out without it. */
380
+ sizeLabel?: string;
381
+ /** `log` spreads points that crowd the low end, such as counts from 2 to 50. */
382
+ xScale?: ScatterScale;
383
+ xFormat?: ValueFormat;
384
+ yFormat?: ValueFormat;
385
+ /** Axis ends; the data's maximum, rounded, when left out. Both axes start at the data's minimum on `log`, at 0 otherwise. */
386
+ xMax?: number;
387
+ yMax?: number;
388
+ /** The `id` of the point drawn as chosen. */
389
+ selected?: string;
390
+ height?: number;
391
+ onPointPress?: (point: ScatterPoint) => void;
392
+ } & {
393
+ children?: ReactNode;
394
+ }>;
395
+ export interface ClusterMapNode {
396
+ /** What `selected` and the press payload identify the node by; the same id in two groups is the same node. */
397
+ id: string;
398
+ label: string;
399
+ /** Relative area: the largest node gets the largest bubble. A middle-sized bubble when left out. */
400
+ size?: number;
401
+ }
402
+ export interface ClusterMapGroup {
403
+ /** What the press payload names the group by; the label when left out. */
404
+ id?: string;
405
+ label: string;
406
+ nodes: ClusterMapNode[];
407
+ color?: ThemeColor | string;
408
+ }
409
+ /**
410
+ * Who or what belongs where: each group a soft circle with its members inside as bubbles with their initials, sized
411
+ * by `size`. A node can sit in several groups; selecting it marks it in each and fades the groups without it.
412
+ * Not every host draws it: check `hostRenders(ClusterMap)`.
413
+ */
414
+ export declare const ClusterMap: import("react").ComponentType<{
415
+ groups: ClusterMapGroup[];
416
+ /** The `id` of the node drawn as chosen. */
417
+ selected?: string;
418
+ /** What `size` counts, for the hover; the hover shows only the name without it. */
419
+ sizeLabel?: string;
420
+ onNodePress?: (node: {
421
+ id: string;
422
+ label: string;
423
+ group: string;
424
+ }) => void;
425
+ } & {
426
+ children?: ReactNode;
427
+ }>;
293
428
  /** Horizontal share bar, `value` in 0..1. */
294
429
  export declare const ProgressBar: import("react").ComponentType<{
295
430
  value: number;
@@ -263,6 +263,7 @@ export declare const CountdownButton: import("react").ComponentType<{
263
263
  export declare const Label: import("react").ComponentType<{
264
264
  color?: "default" | "success" | "error" | "warning" | "info" | "primary" | "secondary" | undefined;
265
265
  variant?: "outlined" | "filled" | "ghost" | "soft" | undefined;
266
+ textTransform?: "capitalize" | "none" | undefined;
266
267
  } & {} & {
267
268
  startIcon?: import("react").ReactNode;
268
269
  endIcon?: import("react").ReactNode;
@@ -328,3 +329,36 @@ export declare const ActivityTimeline: import("react").ComponentType<{
328
329
  } & {} & {} & {
329
330
  children?: import("react").ReactNode;
330
331
  }>;
332
+ export declare const ListItemButton: import("react").ComponentType<{
333
+ selected?: boolean | undefined;
334
+ disabled?: boolean | undefined;
335
+ dense?: boolean | undefined;
336
+ divider?: boolean | undefined;
337
+ disableGutters?: boolean | undefined;
338
+ alignItems?: "center" | "flex-start" | undefined;
339
+ } & {
340
+ readonly onClick?: ((payload: unknown) => void) | undefined;
341
+ } & {} & {
342
+ children?: import("react").ReactNode;
343
+ }>;
344
+ export declare const DataTable: import("react").ComponentType<Omit<{
345
+ columns?: readonly unknown[] | undefined;
346
+ data?: readonly unknown[] | undefined;
347
+ serverSide?: boolean | undefined;
348
+ isLoading?: boolean | undefined;
349
+ initialState?: Readonly<Record<string, unknown>> | undefined;
350
+ paginationProps?: Readonly<Record<string, unknown>> | undefined;
351
+ variant?: "default" | "embedded" | undefined;
352
+ } & {
353
+ readonly onChangeTableState?: ((payload: unknown) => void) | undefined;
354
+ readonly onRowClick?: ((payload: unknown) => void) | undefined;
355
+ } & {}, "data" | "onChangeTableState" | "onRowClick" | "columns" | "initialState" | "paginationProps"> & Pick<{
356
+ columns?: readonly import("./dataTable").DataTableColumn[];
357
+ data?: readonly import("./dataTable").DataTableRow[];
358
+ initialState?: import("./dataTable").DataTableState;
359
+ paginationProps?: import("./dataTable").DataTablePagination;
360
+ onChangeTableState?: (state: import("./dataTable").DataTableState) => void;
361
+ onRowClick?: (row: import("./dataTable").DataTableRow) => void;
362
+ }, "data" | "onChangeTableState" | "onRowClick" | "columns" | "initialState" | "paginationProps"> & {
363
+ children?: import("react").ReactNode;
364
+ }>;
@@ -1,4 +1,4 @@
1
- // Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.9. Don't edit: change the contract in
1
+ // Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.12. Don't edit: change the contract in
2
2
  // react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
3
3
  import { component } from "./component.js";
4
4
  export const Badge = component("np-badge");
@@ -38,3 +38,5 @@ export const TabBar = component("np-tab-bar");
38
38
  export const BreadcrumbTrail = component("np-breadcrumb-trail");
39
39
  export const ChipList = component("np-chip-list");
40
40
  export const ActivityTimeline = component("np-activity-timeline");
41
+ export const ListItemButton = component("np-list-item-button");
42
+ export const DataTable = component("np-data-table");
@@ -21,8 +21,12 @@ export const Icon = component("np-icon");
21
21
  export const Divider = component("np-divider");
22
22
  export const Markdown = component("np-markdown");
23
23
  export const Code = component("np-code");
24
- /** Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right. */
24
+ /**
25
+ * Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right.
26
+ * `layout: "constellation"` draws each side's groups as clusters of dots around the focus, for large neighborhoods.
27
+ */
25
28
  export const EgoGraph = component("np-ego-graph");
29
+ /** `sticky` keeps the box in view as the page scrolls; the host sets the offset, and a taller box scrolls inside. */
26
30
  export const Box = component("np-box");
27
31
  /** Responsive grid: as many columns as fit `min` px, up to `columns`. */
28
32
  export const Grid = component("np-grid");
@@ -35,5 +39,17 @@ export const LineChart = component("np-line-chart");
35
39
  export const BarChart = component("np-bar-chart");
36
40
  /** Part-to-whole ring; the center shows `total` or the formatted sum. */
37
41
  export const Donut = component("np-donut");
42
+ /**
43
+ * Items placed by two measures, with a third as dot size: where each sits says what to do with it.
44
+ * Labels show where they fit; the rest show on hover. With `sizeLabel` the chart keys the dot sizes below it.
45
+ * Not every host draws it: check `hostRenders(Scatter)`.
46
+ */
47
+ export const Scatter = component("np-scatter");
48
+ /**
49
+ * Who or what belongs where: each group a soft circle with its members inside as bubbles with their initials, sized
50
+ * by `size`. A node can sit in several groups; selecting it marks it in each and fades the groups without it.
51
+ * Not every host draws it: check `hostRenders(ClusterMap)`.
52
+ */
53
+ export const ClusterMap = component("np-cluster-map");
38
54
  /** Horizontal share bar, `value` in 0..1. */
39
55
  export const ProgressBar = component("np-progress-bar");
@@ -1,5 +1,6 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { UI_COMPONENTS_CONTRACTS } from "./contracts.generated.js";
3
+ import type { DataTableColumn, DataTablePagination, DataTableRow, DataTableState } from "./dataTable.js";
3
4
  type Contract = (typeof UI_COMPONENTS_CONTRACTS)[number];
4
5
  /** The elements the SDK takes from @nullplatform/react-ui-components' contracts. */
5
6
  export type UiComponentsTag = Contract["tag"];
@@ -13,11 +14,27 @@ type Events<C> = C extends {
13
14
  type Slots<C> = C extends {
14
15
  slots: readonly (infer S extends string)[];
15
16
  } ? S : never;
17
+ /**
18
+ * What a contract can only type loosely, an array's items or an event's payload, typed by hand for the elements
19
+ * that need it. A key the contract doesn't declare is left out, so this can't add a prop the host would drop.
20
+ */
21
+ interface ContractPropTypes {
22
+ "np-data-table": {
23
+ columns?: readonly DataTableColumn[];
24
+ data?: readonly DataTableRow[];
25
+ initialState?: DataTableState;
26
+ paginationProps?: DataTablePagination;
27
+ onChangeTableState?: (state: DataTableState) => void;
28
+ onRowClick?: (row: DataTableRow) => void;
29
+ };
30
+ }
31
+ type Typed<Tag, Props> = Tag extends keyof ContractPropTypes ? Omit<Props, keyof ContractPropTypes[Tag]> & Pick<ContractPropTypes[Tag], Extract<keyof ContractPropTypes[Tag], keyof Props>> : Props;
16
32
  /**
17
33
  * The props a plugin renders an element with, read off its contract: each property with its type, a value list
18
34
  * as the union of its values, each event as a callback and each slot as an element.
19
35
  */
20
- export type ContractProps<Tag extends UiComponentsTag, C = Extract<Contract, {
36
+ export type ContractProps<Tag extends UiComponentsTag> = Typed<Tag, LooseContractProps<Tag>>;
37
+ type LooseContractProps<Tag extends UiComponentsTag, C = Extract<Contract, {
21
38
  tag: Tag;
22
39
  }>> = C extends {
23
40
  properties: infer Properties;
@@ -372,12 +372,14 @@ export declare const UI_COMPONENTS_CONTRACTS: readonly [{
372
372
  readonly properties: {
373
373
  readonly color: "string";
374
374
  readonly variant: "string";
375
+ readonly textTransform: "string";
375
376
  };
376
377
  readonly events: {};
377
378
  readonly slots: readonly ["startIcon", "endIcon"];
378
379
  readonly values: {
379
380
  readonly color: readonly ["default", "primary", "secondary", "info", "success", "warning", "error"];
380
381
  readonly variant: readonly ["filled", "outlined", "ghost", "soft"];
382
+ readonly textTransform: readonly ["capitalize", "none"];
381
383
  };
382
384
  readonly children: true;
383
385
  }, {
@@ -469,4 +471,41 @@ export declare const UI_COMPONENTS_CONTRACTS: readonly [{
469
471
  };
470
472
  readonly events: {};
471
473
  readonly imageValues: readonly ["items[].avatar"];
474
+ }, {
475
+ readonly tag: "np-list-item-button";
476
+ readonly component: "ListItemButton";
477
+ readonly properties: {
478
+ readonly selected: "boolean";
479
+ readonly disabled: "boolean";
480
+ readonly dense: "boolean";
481
+ readonly divider: "boolean";
482
+ readonly disableGutters: "boolean";
483
+ readonly alignItems: "string";
484
+ };
485
+ readonly events: {
486
+ readonly press: "onClick";
487
+ };
488
+ readonly values: {
489
+ readonly alignItems: readonly ["center", "flex-start"];
490
+ };
491
+ readonly children: true;
492
+ }, {
493
+ readonly tag: "np-data-table";
494
+ readonly component: "DataTable";
495
+ readonly properties: {
496
+ readonly columns: "array";
497
+ readonly data: "array";
498
+ readonly serverSide: "boolean";
499
+ readonly isLoading: "boolean";
500
+ readonly initialState: "object";
501
+ readonly paginationProps: "object";
502
+ readonly variant: "string";
503
+ };
504
+ readonly events: {
505
+ readonly stateChange: "onChangeTableState";
506
+ readonly rowClick: "onRowClick";
507
+ };
508
+ readonly values: {
509
+ readonly variant: readonly ["default", "embedded"];
510
+ };
472
511
  }];
@@ -1,4 +1,4 @@
1
- // Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.9. Don't edit: change the contract in
1
+ // Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.12. Don't edit: change the contract in
2
2
  // react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
3
3
  export const UI_COMPONENTS_CONTRACTS = [
4
4
  {
@@ -216,10 +216,10 @@ export const UI_COMPONENTS_CONTRACTS = [
216
216
  {
217
217
  tag: "np-label",
218
218
  component: "Label",
219
- properties: { "color": "string", "variant": "string" },
219
+ properties: { "color": "string", "variant": "string", "textTransform": "string" },
220
220
  events: {},
221
221
  slots: ["startIcon", "endIcon"],
222
- values: { "color": ["default", "primary", "secondary", "info", "success", "warning", "error"], "variant": ["filled", "outlined", "ghost", "soft"] },
222
+ values: { "color": ["default", "primary", "secondary", "info", "success", "warning", "error"], "variant": ["filled", "outlined", "ghost", "soft"], "textTransform": ["capitalize", "none"] },
223
223
  children: true,
224
224
  },
225
225
  {
@@ -265,4 +265,19 @@ export const UI_COMPONENTS_CONTRACTS = [
265
265
  events: {},
266
266
  imageValues: ["items[].avatar"],
267
267
  },
268
+ {
269
+ tag: "np-list-item-button",
270
+ component: "ListItemButton",
271
+ properties: { "selected": "boolean", "disabled": "boolean", "dense": "boolean", "divider": "boolean", "disableGutters": "boolean", "alignItems": "string" },
272
+ events: { "press": "onClick" },
273
+ values: { "alignItems": ["center", "flex-start"] },
274
+ children: true,
275
+ },
276
+ {
277
+ tag: "np-data-table",
278
+ component: "DataTable",
279
+ properties: { "columns": "array", "data": "array", "serverSide": "boolean", "isLoading": "boolean", "initialState": "object", "paginationProps": "object", "variant": "string" },
280
+ events: { "stateChange": "onChangeTableState", "rowClick": "onRowClick" },
281
+ values: { "variant": ["default", "embedded"] },
282
+ },
268
283
  ];
@@ -0,0 +1,138 @@
1
+ import type { TextVariant } from "./catalog.js";
2
+ /**
3
+ * The shapes the design system's `DataTable` takes from a plugin, which its contract can only type as arrays and
4
+ * objects. A subset of react-ui-components' own types: plain data only.
5
+ */
6
+ export type DataTableColor = "default" | "primary" | "secondary" | "error" | "info" | "success" | "warning";
7
+ export type DataTableLabelVariant = "filled" | "outlined" | "ghost" | "soft";
8
+ /** A row's menu entry. `icon` is an iconify name, such as `mdi:open-in-new`. */
9
+ export interface DataTableRowAction {
10
+ id: string;
11
+ label: string;
12
+ icon?: string;
13
+ }
14
+ export interface DataTableTypography {
15
+ variant?: TextVariant;
16
+ /** A theme colour path, such as `text.secondary`, or a plain colour. */
17
+ color?: string;
18
+ maxLength?: number;
19
+ transform?: "uppercase" | "lowercase" | "capitalize" | "titlecase" | "none";
20
+ maxLines?: number;
21
+ }
22
+ /** How a column draws its cells. Without one, a cell draws its value as text. */
23
+ export type DataTableFormatter = {
24
+ type: "text";
25
+ typography?: DataTableTypography;
26
+ } | {
27
+ type: "date";
28
+ format?: "relative" | "absolute";
29
+ config?: {
30
+ tooltip?: {
31
+ enabled: boolean;
32
+ placement?: "top" | "bottom" | "left" | "right";
33
+ };
34
+ };
35
+ typography?: DataTableTypography;
36
+ } | {
37
+ type: "chip";
38
+ format?: "default" | "outlined" | "filled";
39
+ config?: {
40
+ color?: DataTableColor;
41
+ size?: "small" | "medium";
42
+ /** The text and colour each value draws with, such as a status → its colour. */
43
+ mapping?: Record<string, {
44
+ label?: string;
45
+ color?: DataTableColor;
46
+ }>;
47
+ };
48
+ typography?: DataTableTypography;
49
+ } | {
50
+ type: "label";
51
+ config?: {
52
+ color?: DataTableColor;
53
+ variant?: DataTableLabelVariant;
54
+ /** `none` keeps names such as repositories and slugs as they are. */
55
+ textTransform?: "capitalize" | "none";
56
+ mapping?: Record<string, {
57
+ label?: string;
58
+ color?: DataTableColor;
59
+ variant?: DataTableLabelVariant;
60
+ }>;
61
+ };
62
+ } | {
63
+ type: "link";
64
+ config?: {
65
+ underline?: "none" | "hover" | "always";
66
+ /** The colours MUI's Link resolves. */
67
+ color?: "primary" | "secondary" | "error";
68
+ displayText?: string;
69
+ };
70
+ typography?: DataTableTypography;
71
+ } | {
72
+ type: "avatar";
73
+ config?: {
74
+ size?: "small" | "medium" | "large";
75
+ };
76
+ } | {
77
+ type: "icon";
78
+ config?: {
79
+ color?: string;
80
+ size?: number;
81
+ };
82
+ } | {
83
+ type: "actions";
84
+ config: {
85
+ actions: DataTableRowAction[];
86
+ onAction?: (actionId: string, row: DataTableRow) => void;
87
+ };
88
+ };
89
+ export interface DataTableColumn {
90
+ id: string;
91
+ header: string;
92
+ /** The row key the column reads, or a dotted path such as `owner.name`. */
93
+ accessor: string;
94
+ sortable?: boolean;
95
+ sizing?: {
96
+ size?: number;
97
+ minSize?: number;
98
+ maxSize?: number;
99
+ };
100
+ fixed?: {
101
+ position: "left" | "right";
102
+ priority?: number;
103
+ };
104
+ formatter?: DataTableFormatter;
105
+ }
106
+ /** A link cell: a route of the host, or an `href` outside it, which opens in a new tab. */
107
+ export type DataTableLink = {
108
+ text: string;
109
+ to: string;
110
+ params?: Record<string, string | number>;
111
+ } | {
112
+ text: string;
113
+ href: string;
114
+ };
115
+ /** An avatar cell: a name, or a name with its colour. */
116
+ export type DataTableAvatar = string | {
117
+ name: string;
118
+ color?: DataTableColor;
119
+ };
120
+ /** A row: primitives, `DataTableLink`s in link columns, `DataTableAvatar`s in avatar columns. */
121
+ export type DataTableRow = Record<string, unknown>;
122
+ export interface DataTableState {
123
+ sorting?: Array<{
124
+ id: string;
125
+ desc: boolean;
126
+ }>;
127
+ /** `pageIndex` from 0. */
128
+ pagination?: {
129
+ pageIndex: number;
130
+ pageSize: number;
131
+ };
132
+ }
133
+ export interface DataTablePagination {
134
+ /** With `serverSide`, the number of rows in all pages. */
135
+ totalCount?: number;
136
+ hasNextPage?: boolean;
137
+ pageSizeOptions?: number[];
138
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/host.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { ComponentType } from "react";
2
+ export declare function registerTag(component: object, tag: string): void;
3
+ /** Called by the worker runtime with the elements the host announced on `init`. */
4
+ export declare function setHostElements(elements: unknown): void;
5
+ /**
6
+ * Whether this host draws `component`. A host older than the element fails the whole widget when a plugin renders
7
+ * it, so render a newer element only when this is true. False on hosts that don't announce their elements, which
8
+ * predate every element that needs the check.
9
+ */
10
+ export declare function hostRenders(component: ComponentType<any>): boolean;
package/dist/host.js ADDED
@@ -0,0 +1,19 @@
1
+ // The tag each catalog component renders, filled in by `component()`.
2
+ const TAGS = new WeakMap();
3
+ let hostElements = new Set();
4
+ export function registerTag(component, tag) {
5
+ TAGS.set(component, tag);
6
+ }
7
+ /** Called by the worker runtime with the elements the host announced on `init`. */
8
+ export function setHostElements(elements) {
9
+ hostElements = new Set(Array.isArray(elements) ? elements.filter((tag) => typeof tag === "string") : []);
10
+ }
11
+ /**
12
+ * Whether this host draws `component`. A host older than the element fails the whole widget when a plugin renders
13
+ * it, so render a newer element only when this is true. False on hosts that don't announce their elements, which
14
+ * predate every element that needs the check.
15
+ */
16
+ export function hostRenders(component) {
17
+ const tag = TAGS.get(component);
18
+ return tag !== undefined && hostElements.has(tag);
19
+ }
package/dist/index.d.ts CHANGED
@@ -4,5 +4,6 @@ export { usePluginContext, useNullplatform, useQuery, type WidgetProps, type Que
4
4
  export { nullplatform, type NullplatformBridge } from './bridge.js';
5
5
  export { useTopic, useSetTopic, type UseTopicOptions, type UseTopicResult, type UseSetTopicOptions, type SetTopicState, type TopicMap, type ServiceDraftV1, } from './topics.js';
6
6
  export * from './components.js';
7
+ export { hostRenders } from './host.js';
7
8
  export type { PluginContext, ApiRequest, HttpRequest, HttpResponse, NavigationTarget, SnackbarOptions, TopicSnapshot, TopicStatus } from './protocol.js';
8
9
  export { BridgeError } from './protocol.js';
package/dist/index.js CHANGED
@@ -4,4 +4,5 @@ export { usePluginContext, useNullplatform, useQuery } from './context.js';
4
4
  export { nullplatform } from './bridge.js';
5
5
  export { useTopic, useSetTopic, } from './topics.js';
6
6
  export * from './components.js';
7
+ export { hostRenders } from './host.js';
7
8
  export { BridgeError } from './protocol.js';
@@ -146,10 +146,13 @@ export type WorkerMessage = {
146
146
  mountId?: string;
147
147
  error: SerializedError;
148
148
  };
149
- export type HostMessage = {
149
+ export type HostMessage =
150
+ /** `elements`: the catalog tags this host draws. Hosts before it fail a widget that renders a tag they lack. */
151
+ {
150
152
  type: 'init';
151
153
  pluginId: string;
152
154
  context: PluginContext;
155
+ elements?: string[];
153
156
  } | {
154
157
  type: 'mount';
155
158
  mountId: string;
@@ -204,8 +207,9 @@ export declare function serializeFunctions(value: unknown, nextId: () => string,
204
207
  /** Deeply replaces function tokens with functions produced by `resolve`. */
205
208
  export declare function deserializeFunctions(value: unknown, resolve: (id: string) => (...args: unknown[]) => unknown): unknown;
206
209
  /**
207
- * Makes a value safe to post: drops functions, DOM nodes, cycles and events,
208
- * keeping plain data. Used for event handler arguments flowing host → worker.
210
+ * Makes a value safe to post: keeps plain data (arrays and plain objects), flattens dates, and drops functions,
211
+ * DOM nodes, cycles and class instances, such as the window or a React fiber. An event keeps only its type and
212
+ * detail. Used for what flows host → worker: event handler arguments and bridge call results.
209
213
  */
210
214
  export declare function toCloneable(value: unknown, seen?: WeakSet<object>): unknown;
211
215
  export declare function createIdGenerator(prefix: string): () => string;
package/dist/protocol.js CHANGED
@@ -109,9 +109,20 @@ export function deserializeFunctions(value, resolve) {
109
109
  }
110
110
  return value;
111
111
  }
112
+ /** An object literal, `JSON.parse` output or `Object.create(null)`, from any realm: not a class instance. */
113
+ function isPlainObject(value) {
114
+ const proto = Object.getPrototypeOf(value);
115
+ return proto === null || Object.getPrototypeOf(proto) === null;
116
+ }
117
+ /** A React synthetic event: its target fiber and `view` (the window) reach the whole page. */
118
+ function isReactEvent(value) {
119
+ const event = value;
120
+ return typeof event.nativeEvent === 'object' && typeof event.isPropagationStopped === 'function';
121
+ }
112
122
  /**
113
- * Makes a value safe to post: drops functions, DOM nodes, cycles and events,
114
- * keeping plain data. Used for event handler arguments flowing host → worker.
123
+ * Makes a value safe to post: keeps plain data (arrays and plain objects), flattens dates, and drops functions,
124
+ * DOM nodes, cycles and class instances, such as the window or a React fiber. An event keeps only its type and
125
+ * detail. Used for what flows host → worker: event handler arguments and bridge call results.
115
126
  */
116
127
  export function toCloneable(value, seen = new WeakSet()) {
117
128
  if (value === null || value === undefined)
@@ -129,14 +140,14 @@ export function toCloneable(value, seen = new WeakSet()) {
129
140
  }
130
141
  if (typeof Node !== 'undefined' && value instanceof Node)
131
142
  return undefined;
132
- if (type === 'object') {
133
- if (seen.has(value))
134
- return undefined;
135
- seen.add(value);
136
- }
143
+ if (isReactEvent(value))
144
+ return { type: String(value.type) };
145
+ if (seen.has(value))
146
+ return undefined;
147
+ seen.add(value);
137
148
  if (Array.isArray(value))
138
149
  return value.map((item) => toCloneable(item, seen));
139
- if (type === 'object') {
150
+ if (isPlainObject(value)) {
140
151
  const out = {};
141
152
  for (const [key, item] of Object.entries(value)) {
142
153
  const cloned = toCloneable(item, seen);
package/dist/worker.js CHANGED
@@ -9,6 +9,7 @@ import { BatchingRemoteConnection } from '@remote-dom/core/elements';
9
9
  import { defineCatalogElements, ROOT_TAG } from './elements.js';
10
10
  import { bridge } from './bridge.js';
11
11
  import { PluginContextProvider, broadcastContext } from './context.js';
12
+ import { setHostElements } from './host.js';
12
13
  import { receiveTopic } from './topics.js';
13
14
  import { PROTOCOL_VERSION, createIdGenerator, serializeError, serializeFunctions, } from './protocol.js';
14
15
  const nextFunctionId = createIdGenerator('fn');
@@ -86,6 +87,7 @@ function handle(port, message) {
86
87
  switch (message.type) {
87
88
  case 'init':
88
89
  pluginId = message.pluginId;
90
+ setHostElements(message.elements);
89
91
  broadcastContext(message.context);
90
92
  break;
91
93
  case 'mount':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullplatform/ui-plugin-sdk",
3
- "version": "0.7.1",
3
+ "version": "0.9.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",
@@ -36,7 +36,7 @@
36
36
  "test": "vitest run --passWithNoTests",
37
37
  "sync:contracts": "node scripts/sync-contracts.mjs"
38
38
  },
39
- "uiComponentsContracts": "0.15.9",
39
+ "uiComponentsContracts": "0.15.12",
40
40
  "dependencies": {
41
41
  "@remote-dom/core": "^1.11.1",
42
42
  "@remote-dom/react": "^1.2.2",