@nullplatform/ui-plugin-sdk 0.2.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/README.md +38 -0
- package/dist/bridge.d.ts +40 -0
- package/dist/bridge.js +84 -0
- package/dist/catalog.d.ts +26 -0
- package/dist/catalog.js +113 -0
- package/dist/components.d.ts +149 -0
- package/dist/components.js +57 -0
- package/dist/context.d.ts +47 -0
- package/dist/context.js +47 -0
- package/dist/contract/allowlist.d.ts +16 -0
- package/dist/contract/allowlist.js +70 -0
- package/dist/contract/index.d.ts +4 -0
- package/dist/contract/index.js +4 -0
- package/dist/contract/manifest.d.ts +46 -0
- package/dist/contract/manifest.js +108 -0
- package/dist/contract/storage.d.ts +4 -0
- package/dist/contract/storage.js +19 -0
- package/dist/contract/when.d.ts +19 -0
- package/dist/contract/when.js +104 -0
- package/dist/contract-cjs/allowlist.js +76 -0
- package/dist/contract-cjs/index.js +24 -0
- package/dist/contract-cjs/manifest.js +114 -0
- package/dist/contract-cjs/package.json +1 -0
- package/dist/contract-cjs/storage.js +24 -0
- package/dist/contract-cjs/when.js +115 -0
- package/dist/defineUI.d.ts +15 -0
- package/dist/defineUI.js +18 -0
- package/dist/elements.d.ts +10 -0
- package/dist/elements.js +39 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/polyfill.d.ts +6 -0
- package/dist/polyfill.js +6 -0
- package/dist/protocol.d.ts +170 -0
- package/dist/protocol.js +112 -0
- package/dist/worker.d.ts +17 -0
- package/dist/worker.js +135 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# nullplatform UI plugin SDK
|
|
2
|
+
|
|
3
|
+
Build widgets and pages for nullplatform's UI plugin host.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @nullplatform/ui-plugin-sdk react react-dom
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { defineUI, Card, Text } from '@nullplatform/ui-plugin-sdk';
|
|
11
|
+
|
|
12
|
+
function Summary() {
|
|
13
|
+
return <Card title="My plugin"><Text>Hello</Text></Card>;
|
|
14
|
+
}
|
|
15
|
+
defineUI({ widgets: { summary: Summary } });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Build one self-contained classic IIFE (including React and the SDK). The host
|
|
19
|
+
runs it in an isolated worker and renders its remote components using the host's
|
|
20
|
+
design system. Declare registered mountpoints, widgets and bridge permissions in
|
|
21
|
+
your plugin manifest.
|
|
22
|
+
|
|
23
|
+
The same package provides DOM-free validation for Node tooling and APIs:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { validateManifest } from '@nullplatform/ui-plugin-sdk/contract';
|
|
27
|
+
// CommonJS: require('@nullplatform/ui-plugin-sdk/contract')
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`nullplatform.api` accesses allowed nullplatform API paths through the host.
|
|
31
|
+
`nullplatform.http` accesses explicitly declared external hosts using short-lived
|
|
32
|
+
plugin tokens. `nullplatform.assets.url(path)` resolves a file from the installed
|
|
33
|
+
bundle; `Image` displays images/SVG from platform storage.
|
|
34
|
+
|
|
35
|
+
The SDK carries no API keys. Publish your plugin bundle through the UI API, pin it
|
|
36
|
+
as a `ui_bundle` component of a central nullplatform Package, and install the exact
|
|
37
|
+
package revision on the desired NRN. Installing this npm SDK does not publish or
|
|
38
|
+
install a plugin in nullplatform.
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin-side client of the host bridge. The only way out of the sandbox.
|
|
3
|
+
*/
|
|
4
|
+
import { type ApiRequest, type BridgeMethodName, type BridgeMethods, type HostMessage, type HttpRequest, type HttpResponse, type NavigationTarget, type PluginContext, type SnackbarOptions, type WorkerMessage } from './protocol.js';
|
|
5
|
+
export declare class BridgeClient {
|
|
6
|
+
private port;
|
|
7
|
+
private pending;
|
|
8
|
+
private seq;
|
|
9
|
+
attach(port: MessagePort): void;
|
|
10
|
+
post(message: WorkerMessage, transfer?: Transferable[]): void;
|
|
11
|
+
call<M extends BridgeMethodName>(method: M, ...args: Parameters<BridgeMethods[M]>): ReturnType<BridgeMethods[M]>;
|
|
12
|
+
/** Feeds a `result` message from the host. Returns true when it was consumed. */
|
|
13
|
+
handleResult(message: HostMessage): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const bridge: BridgeClient;
|
|
16
|
+
/** Typed facade exposed to plugin code. */
|
|
17
|
+
export declare const nullplatform: {
|
|
18
|
+
assets: {
|
|
19
|
+
url(path: string): Promise<string>;
|
|
20
|
+
};
|
|
21
|
+
api: {
|
|
22
|
+
request<T = unknown>(request: ApiRequest): Promise<T>;
|
|
23
|
+
get<T = unknown>(path: string, query?: ApiRequest["query"]): Promise<T>;
|
|
24
|
+
};
|
|
25
|
+
/** External https hosts declared in `permissions.http`. Executed by the host with a plugin call token. */
|
|
26
|
+
http: {
|
|
27
|
+
request(request: HttpRequest): Promise<HttpResponse>;
|
|
28
|
+
get(url: string, query?: HttpRequest["query"]): Promise<HttpResponse>;
|
|
29
|
+
};
|
|
30
|
+
navigation: {
|
|
31
|
+
push(target: NavigationTarget): Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
ui: {
|
|
34
|
+
snackbar(options: SnackbarOptions): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
context: {
|
|
37
|
+
get(): Promise<PluginContext>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export type NullplatformBridge = typeof nullplatform;
|
package/dist/bridge.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin-side client of the host bridge. The only way out of the sandbox.
|
|
3
|
+
*/
|
|
4
|
+
import { BridgeError, deserializeError, } from './protocol.js';
|
|
5
|
+
export class BridgeClient {
|
|
6
|
+
port = null;
|
|
7
|
+
pending = new Map();
|
|
8
|
+
seq = 0;
|
|
9
|
+
attach(port) {
|
|
10
|
+
this.port = port;
|
|
11
|
+
}
|
|
12
|
+
post(message, transfer) {
|
|
13
|
+
if (!this.port)
|
|
14
|
+
throw new BridgeError('Bridge is not connected', 'NOT_CONNECTED');
|
|
15
|
+
this.port.postMessage(message, transfer ?? []);
|
|
16
|
+
}
|
|
17
|
+
call(method, ...args) {
|
|
18
|
+
const id = `c${++this.seq}`;
|
|
19
|
+
const promise = new Promise((resolve, reject) => {
|
|
20
|
+
this.pending.set(id, { resolve, reject });
|
|
21
|
+
try {
|
|
22
|
+
this.post({ type: 'call', id, method, args });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
this.pending.delete(id);
|
|
26
|
+
reject(error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return promise;
|
|
30
|
+
}
|
|
31
|
+
/** Feeds a `result` message from the host. Returns true when it was consumed. */
|
|
32
|
+
handleResult(message) {
|
|
33
|
+
if (message.type !== 'result')
|
|
34
|
+
return false;
|
|
35
|
+
const pending = this.pending.get(message.id);
|
|
36
|
+
if (!pending)
|
|
37
|
+
return true;
|
|
38
|
+
this.pending.delete(message.id);
|
|
39
|
+
if (message.ok)
|
|
40
|
+
pending.resolve(message.value);
|
|
41
|
+
else
|
|
42
|
+
pending.reject(deserializeError(message.error ?? { message: 'Unknown bridge error' }));
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const bridge = new BridgeClient();
|
|
47
|
+
/** Typed facade exposed to plugin code. */
|
|
48
|
+
export const nullplatform = {
|
|
49
|
+
assets: {
|
|
50
|
+
url(path) { return bridge.call('assets.url', path); },
|
|
51
|
+
},
|
|
52
|
+
api: {
|
|
53
|
+
request(request) {
|
|
54
|
+
return bridge.call('api.request', request);
|
|
55
|
+
},
|
|
56
|
+
get(path, query) {
|
|
57
|
+
return this.request({ method: 'GET', path, query });
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
/** External https hosts declared in `permissions.http`. Executed by the host with a plugin call token. */
|
|
61
|
+
http: {
|
|
62
|
+
request(request) {
|
|
63
|
+
return bridge.call('http.request', request);
|
|
64
|
+
},
|
|
65
|
+
get(url, query) {
|
|
66
|
+
return this.request({ method: 'GET', url, query });
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
navigation: {
|
|
70
|
+
push(target) {
|
|
71
|
+
return bridge.call('navigation.push', target);
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
ui: {
|
|
75
|
+
snackbar(options) {
|
|
76
|
+
return bridge.call('ui.snackbar', options);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
context: {
|
|
80
|
+
get() {
|
|
81
|
+
return bridge.call('context.get');
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component catalog shared by the SDK (plugin side) and the host.
|
|
3
|
+
*
|
|
4
|
+
* A plugin can only render these elements. The host maps each one to a
|
|
5
|
+
* component of the nullplatform design system, which is what makes plugins
|
|
6
|
+
* look native: theme, typography and spacing are never the plugin's concern.
|
|
7
|
+
*
|
|
8
|
+
* This file is pure data so it can be imported by the host without pulling
|
|
9
|
+
* the DOM polyfill.
|
|
10
|
+
*/
|
|
11
|
+
export type PropertyType = 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
12
|
+
export interface CatalogElementSpec {
|
|
13
|
+
/** Custom element tag name. */
|
|
14
|
+
tag: string;
|
|
15
|
+
/** React component name exported by the SDK. */
|
|
16
|
+
component: string;
|
|
17
|
+
properties: Record<string, PropertyType>;
|
|
18
|
+
/** Event name → React prop name. */
|
|
19
|
+
events: Record<string, string>;
|
|
20
|
+
/** Named slots (rendered as React element props). */
|
|
21
|
+
slots?: string[];
|
|
22
|
+
}
|
|
23
|
+
export declare const CATALOG: readonly CatalogElementSpec[];
|
|
24
|
+
export declare const CATALOG_BY_TAG: ReadonlyMap<string, CatalogElementSpec>;
|
|
25
|
+
/** Name of the wrapper element remote-dom uses for React elements passed as props. */
|
|
26
|
+
export declare const FRAGMENT_TAG = "remote-fragment";
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The component catalog shared by the SDK (plugin side) and the host.
|
|
3
|
+
*
|
|
4
|
+
* A plugin can only render these elements. The host maps each one to a
|
|
5
|
+
* component of the nullplatform design system, which is what makes plugins
|
|
6
|
+
* look native: theme, typography and spacing are never the plugin's concern.
|
|
7
|
+
*
|
|
8
|
+
* This file is pure data so it can be imported by the host without pulling
|
|
9
|
+
* the DOM polyfill.
|
|
10
|
+
*/
|
|
11
|
+
export const CATALOG = [
|
|
12
|
+
{ tag: 'np-image', component: 'Image', properties: { src: 'string', alt: 'string', width: 'number', height: 'number' }, events: {} },
|
|
13
|
+
{
|
|
14
|
+
tag: 'np-card',
|
|
15
|
+
component: 'Card',
|
|
16
|
+
properties: { title: 'string', subtitle: 'string', padding: 'string' },
|
|
17
|
+
events: {},
|
|
18
|
+
slots: ['action'],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
tag: 'np-stack',
|
|
22
|
+
component: 'Stack',
|
|
23
|
+
properties: { direction: 'string', spacing: 'number', align: 'string', justify: 'string', wrap: 'boolean' },
|
|
24
|
+
events: {},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
tag: 'np-text',
|
|
28
|
+
component: 'Text',
|
|
29
|
+
properties: { variant: 'string', color: 'string', align: 'string', noWrap: 'boolean' },
|
|
30
|
+
events: {},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
tag: 'np-button',
|
|
34
|
+
component: 'Button',
|
|
35
|
+
properties: { variant: 'string', color: 'string', size: 'string', disabled: 'boolean', loading: 'boolean', icon: 'string' },
|
|
36
|
+
events: { press: 'onPress' },
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
tag: 'np-chip',
|
|
40
|
+
component: 'Chip',
|
|
41
|
+
properties: { label: 'string', color: 'string', variant: 'string', size: 'string' },
|
|
42
|
+
events: {},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
tag: 'np-link',
|
|
46
|
+
component: 'Link',
|
|
47
|
+
properties: { to: 'string', params: 'object', href: 'string' },
|
|
48
|
+
events: { press: 'onPress' },
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
tag: 'np-table',
|
|
52
|
+
component: 'Table',
|
|
53
|
+
properties: { columns: 'array', rows: 'array', dense: 'boolean', emptyMessage: 'string' },
|
|
54
|
+
events: { rowPress: 'onRowPress' },
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
tag: 'np-skeleton',
|
|
58
|
+
component: 'Skeleton',
|
|
59
|
+
properties: { height: 'number', width: 'string', variant: 'string' },
|
|
60
|
+
events: {},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
tag: 'np-empty',
|
|
64
|
+
component: 'Empty',
|
|
65
|
+
properties: { title: 'string', description: 'string' },
|
|
66
|
+
events: {},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
tag: 'np-alert',
|
|
70
|
+
component: 'Alert',
|
|
71
|
+
properties: { severity: 'string', title: 'string' },
|
|
72
|
+
events: {},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
tag: 'np-icon',
|
|
76
|
+
component: 'Icon',
|
|
77
|
+
properties: { icon: 'string', size: 'number', color: 'string' },
|
|
78
|
+
events: {},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
tag: 'np-divider',
|
|
82
|
+
component: 'Divider',
|
|
83
|
+
properties: {},
|
|
84
|
+
events: {},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
tag: 'np-markdown',
|
|
88
|
+
component: 'Markdown',
|
|
89
|
+
properties: { content: 'string' },
|
|
90
|
+
events: {},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
tag: 'np-code',
|
|
94
|
+
component: 'Code',
|
|
95
|
+
properties: { content: 'string', language: 'string', maxHeight: 'number' },
|
|
96
|
+
events: {},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
tag: 'np-ego-graph',
|
|
100
|
+
component: 'EgoGraph',
|
|
101
|
+
properties: { focus: 'string', inbound: 'array', outbound: 'array', height: 'number' },
|
|
102
|
+
events: { nodePress: 'onNodePress' },
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
tag: 'np-box',
|
|
106
|
+
component: 'Box',
|
|
107
|
+
properties: { padding: 'string', height: 'string', width: 'string', grow: 'boolean' },
|
|
108
|
+
events: {},
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
export const CATALOG_BY_TAG = new Map(CATALOG.map((spec) => [spec.tag, spec]));
|
|
112
|
+
/** Name of the wrapper element remote-dom uses for React elements passed as props. */
|
|
113
|
+
export const FRAGMENT_TAG = 'remote-fragment';
|
|
@@ -0,0 +1,149 @@
|
|
|
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 { type ComponentType, type ReactNode } from 'react';
|
|
8
|
+
export interface TableColumn {
|
|
9
|
+
key: string;
|
|
10
|
+
header: string;
|
|
11
|
+
align?: 'left' | 'right' | 'center';
|
|
12
|
+
width?: number | string;
|
|
13
|
+
}
|
|
14
|
+
export type TableRow = Record<string, string | number | boolean | null | undefined> & {
|
|
15
|
+
id?: string | number;
|
|
16
|
+
};
|
|
17
|
+
export declare const Image: ComponentType<{
|
|
18
|
+
src: string;
|
|
19
|
+
alt: string;
|
|
20
|
+
width?: number;
|
|
21
|
+
height?: number;
|
|
22
|
+
} & {
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const Card: ComponentType<{
|
|
26
|
+
title?: string;
|
|
27
|
+
subtitle?: string;
|
|
28
|
+
padding?: string;
|
|
29
|
+
action?: ReactNode;
|
|
30
|
+
} & {
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const Stack: ComponentType<{
|
|
34
|
+
direction?: "row" | "column";
|
|
35
|
+
spacing?: number;
|
|
36
|
+
align?: string;
|
|
37
|
+
justify?: string;
|
|
38
|
+
wrap?: boolean;
|
|
39
|
+
} & {
|
|
40
|
+
children?: ReactNode;
|
|
41
|
+
}>;
|
|
42
|
+
export declare const Text: ComponentType<{
|
|
43
|
+
variant?: string;
|
|
44
|
+
color?: string;
|
|
45
|
+
align?: string;
|
|
46
|
+
noWrap?: boolean;
|
|
47
|
+
} & {
|
|
48
|
+
children?: ReactNode;
|
|
49
|
+
}>;
|
|
50
|
+
export declare const Button: ComponentType<{
|
|
51
|
+
variant?: "contained" | "outlined" | "text" | "soft";
|
|
52
|
+
color?: string;
|
|
53
|
+
size?: "small" | "medium" | "large";
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
loading?: boolean;
|
|
56
|
+
icon?: string;
|
|
57
|
+
onPress?: () => void;
|
|
58
|
+
} & {
|
|
59
|
+
children?: ReactNode;
|
|
60
|
+
}>;
|
|
61
|
+
export declare const Chip: ComponentType<{
|
|
62
|
+
label: string;
|
|
63
|
+
color?: string;
|
|
64
|
+
variant?: string;
|
|
65
|
+
size?: string;
|
|
66
|
+
} & {
|
|
67
|
+
children?: ReactNode;
|
|
68
|
+
}>;
|
|
69
|
+
export declare const Link: ComponentType<{
|
|
70
|
+
to?: string;
|
|
71
|
+
params?: Record<string, string | number>;
|
|
72
|
+
href?: string;
|
|
73
|
+
onPress?: () => void;
|
|
74
|
+
} & {
|
|
75
|
+
children?: ReactNode;
|
|
76
|
+
}>;
|
|
77
|
+
export declare const Table: ComponentType<{
|
|
78
|
+
columns: TableColumn[];
|
|
79
|
+
rows: TableRow[];
|
|
80
|
+
dense?: boolean;
|
|
81
|
+
emptyMessage?: string;
|
|
82
|
+
onRowPress?: (row: TableRow) => void;
|
|
83
|
+
} & {
|
|
84
|
+
children?: ReactNode;
|
|
85
|
+
}>;
|
|
86
|
+
export declare const Skeleton: ComponentType<{
|
|
87
|
+
height?: number;
|
|
88
|
+
width?: string;
|
|
89
|
+
variant?: string;
|
|
90
|
+
} & {
|
|
91
|
+
children?: ReactNode;
|
|
92
|
+
}>;
|
|
93
|
+
export declare const Empty: ComponentType<{
|
|
94
|
+
title?: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
} & {
|
|
97
|
+
children?: ReactNode;
|
|
98
|
+
}>;
|
|
99
|
+
export declare const Alert: ComponentType<{
|
|
100
|
+
severity?: "success" | "info" | "warning" | "error";
|
|
101
|
+
title?: string;
|
|
102
|
+
} & {
|
|
103
|
+
children?: ReactNode;
|
|
104
|
+
}>;
|
|
105
|
+
export declare const Icon: ComponentType<{
|
|
106
|
+
icon: string;
|
|
107
|
+
size?: number;
|
|
108
|
+
color?: string;
|
|
109
|
+
} & {
|
|
110
|
+
children?: ReactNode;
|
|
111
|
+
}>;
|
|
112
|
+
export declare const Divider: ComponentType<{
|
|
113
|
+
children?: ReactNode;
|
|
114
|
+
}>;
|
|
115
|
+
export declare const Markdown: ComponentType<{
|
|
116
|
+
content: string;
|
|
117
|
+
} & {
|
|
118
|
+
children?: ReactNode;
|
|
119
|
+
}>;
|
|
120
|
+
export declare const Code: ComponentType<{
|
|
121
|
+
content: string;
|
|
122
|
+
language?: string;
|
|
123
|
+
maxHeight?: number;
|
|
124
|
+
} & {
|
|
125
|
+
children?: ReactNode;
|
|
126
|
+
}>;
|
|
127
|
+
export interface EgoEdge {
|
|
128
|
+
node: string;
|
|
129
|
+
label?: string;
|
|
130
|
+
kind?: string;
|
|
131
|
+
}
|
|
132
|
+
/** Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right. */
|
|
133
|
+
export declare const EgoGraph: ComponentType<{
|
|
134
|
+
focus: string;
|
|
135
|
+
inbound: EgoEdge[];
|
|
136
|
+
outbound: EgoEdge[];
|
|
137
|
+
height?: number;
|
|
138
|
+
onNodePress?: (node: string) => void;
|
|
139
|
+
} & {
|
|
140
|
+
children?: ReactNode;
|
|
141
|
+
}>;
|
|
142
|
+
export declare const Box: ComponentType<{
|
|
143
|
+
padding?: string;
|
|
144
|
+
height?: string;
|
|
145
|
+
width?: string;
|
|
146
|
+
grow?: boolean;
|
|
147
|
+
} & {
|
|
148
|
+
children?: ReactNode;
|
|
149
|
+
}>;
|
|
@@ -0,0 +1,57 @@
|
|
|
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), { eventProps: eventProps });
|
|
20
|
+
const handlerProps = Object.values(spec.events);
|
|
21
|
+
if (handlerProps.length === 0)
|
|
22
|
+
return Remote;
|
|
23
|
+
// remote-dom delivers a RemoteEvent to listeners; plugin authors want the payload the host sent.
|
|
24
|
+
const Wrapped = (props) => {
|
|
25
|
+
const mapped = { ...props };
|
|
26
|
+
for (const prop of handlerProps) {
|
|
27
|
+
const handler = props[prop];
|
|
28
|
+
if (typeof handler === 'function') {
|
|
29
|
+
mapped[prop] = (event) => {
|
|
30
|
+
const detail = event && typeof event === 'object' && 'detail' in event ? event.detail : event;
|
|
31
|
+
return handler(detail);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return createElement(Remote, mapped);
|
|
36
|
+
};
|
|
37
|
+
Wrapped.displayName = spec.component;
|
|
38
|
+
return Wrapped;
|
|
39
|
+
}
|
|
40
|
+
export const Image = component('np-image');
|
|
41
|
+
export const Card = component('np-card');
|
|
42
|
+
export const Stack = component('np-stack');
|
|
43
|
+
export const Text = component('np-text');
|
|
44
|
+
export const Button = component('np-button');
|
|
45
|
+
export const Chip = component('np-chip');
|
|
46
|
+
export const Link = component('np-link');
|
|
47
|
+
export const Table = component('np-table');
|
|
48
|
+
export const Skeleton = component('np-skeleton');
|
|
49
|
+
export const Empty = component('np-empty');
|
|
50
|
+
export const Alert = component('np-alert');
|
|
51
|
+
export const Icon = component('np-icon');
|
|
52
|
+
export const Divider = component('np-divider');
|
|
53
|
+
export const Markdown = component('np-markdown');
|
|
54
|
+
export const Code = component('np-code');
|
|
55
|
+
/** Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right. */
|
|
56
|
+
export const EgoGraph = component('np-ego-graph');
|
|
57
|
+
export const Box = component('np-box');
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { PluginContext } from './protocol.js';
|
|
3
|
+
export interface WidgetProps {
|
|
4
|
+
/** Slot this widget instance is mounted in. */
|
|
5
|
+
slot: string;
|
|
6
|
+
/** Per-installation configuration, when the host provides one. */
|
|
7
|
+
config?: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Called by the worker runtime when the host pushes a new context. */
|
|
10
|
+
export declare function broadcastContext(context: PluginContext): void;
|
|
11
|
+
export declare function PluginContextProvider({ initial, children }: {
|
|
12
|
+
initial: PluginContext;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
/** Current organization / account / namespace / application the widget is shown for. */
|
|
16
|
+
export declare function usePluginContext(): PluginContext;
|
|
17
|
+
/** The bridge facade, for calling the nullplatform API, navigating, or showing snackbars. */
|
|
18
|
+
export declare function useNullplatform(): {
|
|
19
|
+
assets: {
|
|
20
|
+
url(path: string): Promise<string>;
|
|
21
|
+
};
|
|
22
|
+
api: {
|
|
23
|
+
request<T = unknown>(request: import("./protocol").ApiRequest): Promise<T>;
|
|
24
|
+
get<T = unknown>(path: string, query?: import("./protocol").ApiRequest["query"]): Promise<T>;
|
|
25
|
+
};
|
|
26
|
+
http: {
|
|
27
|
+
request(request: import("./protocol").HttpRequest): Promise<import("./protocol").HttpResponse>;
|
|
28
|
+
get(url: string, query?: import("./protocol").HttpRequest["query"]): Promise<import("./protocol").HttpResponse>;
|
|
29
|
+
};
|
|
30
|
+
navigation: {
|
|
31
|
+
push(target: import("./protocol").NavigationTarget): Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
ui: {
|
|
34
|
+
snackbar(options: import("./protocol").SnackbarOptions): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
context: {
|
|
37
|
+
get(): Promise<PluginContext>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export interface QueryState<T> {
|
|
41
|
+
data: T | undefined;
|
|
42
|
+
error: Error | undefined;
|
|
43
|
+
loading: boolean;
|
|
44
|
+
refetch: () => void;
|
|
45
|
+
}
|
|
46
|
+
/** Minimal data hook: runs `fetcher` when `deps` change. */
|
|
47
|
+
export declare function useQuery<T>(fetcher: () => Promise<T>, deps?: unknown[]): QueryState<T>;
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { nullplatform } from './bridge.js';
|
|
4
|
+
const PluginContextReact = createContext({});
|
|
5
|
+
const ContextUpdaters = new Set();
|
|
6
|
+
/** Called by the worker runtime when the host pushes a new context. */
|
|
7
|
+
export function broadcastContext(context) {
|
|
8
|
+
for (const update of ContextUpdaters)
|
|
9
|
+
update(context);
|
|
10
|
+
}
|
|
11
|
+
export function PluginContextProvider({ initial, children }) {
|
|
12
|
+
const [context, setContext] = useState(initial);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
ContextUpdaters.add(setContext);
|
|
15
|
+
return () => {
|
|
16
|
+
ContextUpdaters.delete(setContext);
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
return _jsx(PluginContextReact.Provider, { value: context, children: children });
|
|
20
|
+
}
|
|
21
|
+
/** Current organization / account / namespace / application the widget is shown for. */
|
|
22
|
+
export function usePluginContext() {
|
|
23
|
+
return useContext(PluginContextReact);
|
|
24
|
+
}
|
|
25
|
+
/** The bridge facade, for calling the nullplatform API, navigating, or showing snackbars. */
|
|
26
|
+
export function useNullplatform() {
|
|
27
|
+
return nullplatform;
|
|
28
|
+
}
|
|
29
|
+
/** Minimal data hook: runs `fetcher` when `deps` change. */
|
|
30
|
+
export function useQuery(fetcher, deps = []) {
|
|
31
|
+
const [state, setState] = useState({ loading: true, tick: 0 });
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
let cancelled = false;
|
|
34
|
+
setState((prev) => ({ ...prev, loading: true }));
|
|
35
|
+
fetcher().then((data) => !cancelled && setState((prev) => ({ ...prev, data, error: undefined, loading: false })), (error) => !cancelled && setState((prev) => ({ ...prev, error: error, loading: false })));
|
|
36
|
+
return () => {
|
|
37
|
+
cancelled = true;
|
|
38
|
+
};
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, [...deps, state.tick]);
|
|
41
|
+
return {
|
|
42
|
+
data: state.data,
|
|
43
|
+
error: state.error,
|
|
44
|
+
loading: state.loading,
|
|
45
|
+
refetch: () => setState((prev) => ({ ...prev, tick: prev.tick + 1 })),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ApiPermission, HttpPermission } from './manifest.js';
|
|
2
|
+
/** Splits a path into segments; rejects traversal, empty segments and query/hash fragments. */
|
|
3
|
+
export declare function normalizePath(path: string): string[] | null;
|
|
4
|
+
/**
|
|
5
|
+
* Decides whether a plugin API request (a nullplatform public API path) is covered
|
|
6
|
+
* by its declared `permissions.api`. Query strings are never part of the decision.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isApiRequestAllowed(permissions: ApiPermission[] | undefined, method: string, path: string): boolean;
|
|
9
|
+
/** @deprecated use `isApiRequestAllowed`. */
|
|
10
|
+
export declare const isRequestAllowed: typeof isApiRequestAllowed;
|
|
11
|
+
/**
|
|
12
|
+
* Decides whether an external HTTP request is covered by `permissions.http`:
|
|
13
|
+
* https only, no credentials in the URL, exact host (including port when declared),
|
|
14
|
+
* declared method and path pattern.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isHttpRequestAllowed(permissions: HttpPermission[] | undefined, method: string, url: string): boolean;
|