@rainbow-robotics/plugin-ui 0.1.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 +85 -0
- package/build-browser.mjs +84 -0
- package/build-dist.mjs +42 -0
- package/dist/connect.d.ts +12 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +29 -0
- package/dist/connect.js.map +7 -0
- package/dist/elements.d.ts +195 -0
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.js +115 -0
- package/dist/elements.js.map +7 -0
- package/dist/manifest.d.ts +65 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +29 -0
- package/dist/manifest.js.map +7 -0
- package/dist/react.d.ts +47 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +57 -0
- package/dist/react.js.map +7 -0
- package/dist/sdk.d.ts +14 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +23 -0
- package/dist/sdk.js.map +7 -0
- package/dist-browser/@rainbow-robotics/plugin-ui/chunks/chunk-AMCIKVG7.js +1 -0
- package/dist-browser/@rainbow-robotics/plugin-ui/chunks/chunk-GJWPOWHG.js +1 -0
- package/dist-browser/@rainbow-robotics/plugin-ui/chunks/chunk-JRCDA3EG.js +1 -0
- package/dist-browser/@rainbow-robotics/plugin-ui/connect.js +1 -0
- package/dist-browser/@rainbow-robotics/plugin-ui/elements.js +1 -0
- package/dist-browser/@rainbow-robotics/plugin-ui/react.js +1 -0
- package/dist-browser/@rainbow-robotics/plugin-ui/sdk.js +1 -0
- package/dist-browser/vendor/react-dom-client.js +1 -0
- package/dist-browser/vendor/react-jsx-dev-runtime.js +1 -0
- package/dist-browser/vendor/react-jsx-runtime.js +1 -0
- package/dist-browser/vendor/react-runtime.js +65 -0
- package/dist-browser/vendor/react.js +1 -0
- package/package.json +73 -0
- package/src/connect.ts +68 -0
- package/src/elements.ts +257 -0
- package/src/host.tsx +343 -0
- package/src/manifest.ts +92 -0
- package/src/react.tsx +131 -0
- package/src/sdk.ts +41 -0
package/src/react.tsx
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Author bindings — the React components a plugin author imports from
|
|
3
|
+
* `@rainbow-robotics/plugin-ui/react`.
|
|
4
|
+
*
|
|
5
|
+
* These are *name tags*: they render rb-* custom elements into the sandbox's
|
|
6
|
+
* remote DOM. The real rb-components are rendered by the host (see ./host).
|
|
7
|
+
* Event names from each element's `remoteEvents` surface as `onX` props
|
|
8
|
+
* (e.g. `change` → `onChange`) carrying a `RemoteEvent` whose `detail` holds
|
|
9
|
+
* the payload.
|
|
10
|
+
*/
|
|
11
|
+
import { createRemoteComponent } from "@remote-dom/react";
|
|
12
|
+
import type { ComponentType, ReactNode, Ref } from "react";
|
|
13
|
+
import {
|
|
14
|
+
RbSliderElement,
|
|
15
|
+
RbButtonElement,
|
|
16
|
+
RbIconButtonElement,
|
|
17
|
+
RbTextElement,
|
|
18
|
+
RbTextInputElement,
|
|
19
|
+
RbSwitchElement,
|
|
20
|
+
RbSelectElement,
|
|
21
|
+
type RbButtonProps,
|
|
22
|
+
type RbIconButtonProps,
|
|
23
|
+
type RbSelectProps,
|
|
24
|
+
type RbSliderProps,
|
|
25
|
+
type RbSwitchProps,
|
|
26
|
+
type RbTextInputProps,
|
|
27
|
+
type RbTextProps,
|
|
28
|
+
} from "./elements";
|
|
29
|
+
|
|
30
|
+
// NOTE: createRemoteComponent only treats a prop as an event listener when it is
|
|
31
|
+
// declared in `eventProps`; it does NOT auto-derive from the element's
|
|
32
|
+
// `remoteEvents`. These maps MUST mirror the host's eventProps (see ./host).
|
|
33
|
+
//
|
|
34
|
+
// `eventProps` is typed against the element's *typed* EventListeners generic.
|
|
35
|
+
// Fully typing those generics would also force typing every `remoteProperties`
|
|
36
|
+
// shape on the classes (remote-dom itself uses @ts-expect-error around this), so
|
|
37
|
+
// we cast the event maps here. The values are verified by the demo e2e, and the
|
|
38
|
+
// returned components keep their element-derived prop types for plugin authors.
|
|
39
|
+
type EventMap = Record<string, { event: string }>;
|
|
40
|
+
const events = (map: EventMap) => ({ eventProps: map }) as never;
|
|
41
|
+
|
|
42
|
+
type NoEventProps = Record<never, never>;
|
|
43
|
+
|
|
44
|
+
type RemoteElementComponentProps<
|
|
45
|
+
Element,
|
|
46
|
+
Props,
|
|
47
|
+
EventProps = NoEventProps,
|
|
48
|
+
> = Props &
|
|
49
|
+
EventProps & {
|
|
50
|
+
children?: ReactNode;
|
|
51
|
+
ref?: Ref<Element>;
|
|
52
|
+
slot?: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type RemoteElementComponent<
|
|
56
|
+
Element,
|
|
57
|
+
Props,
|
|
58
|
+
EventProps = NoEventProps,
|
|
59
|
+
> = ComponentType<RemoteElementComponentProps<Element, Props, EventProps>>;
|
|
60
|
+
|
|
61
|
+
export type RbSliderChangeEvent = { detail: number };
|
|
62
|
+
export type RbTextInputEvent = { detail: string };
|
|
63
|
+
export type RbSwitchChangeEvent = { detail: boolean };
|
|
64
|
+
export type RbSelectChangeEvent = { detail: string };
|
|
65
|
+
|
|
66
|
+
export interface RbSliderEventProps {
|
|
67
|
+
onChange?: (event: RbSliderChangeEvent) => void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface RbPressEventProps {
|
|
71
|
+
onPress?: () => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface RbTextInputEventProps {
|
|
75
|
+
onInput?: (event: RbTextInputEvent) => void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface RbSwitchEventProps {
|
|
79
|
+
onChange?: (event: RbSwitchChangeEvent) => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface RbSelectEventProps {
|
|
83
|
+
onChange?: (event: RbSelectChangeEvent) => void;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const Slider = createRemoteComponent(
|
|
87
|
+
"rb-slider",
|
|
88
|
+
RbSliderElement,
|
|
89
|
+
events({ onChange: { event: "change" } }),
|
|
90
|
+
) as RemoteElementComponent<RbSliderElement, RbSliderProps, RbSliderEventProps>;
|
|
91
|
+
export const Button = createRemoteComponent(
|
|
92
|
+
"rb-button",
|
|
93
|
+
RbButtonElement,
|
|
94
|
+
events({ onPress: { event: "press" } }),
|
|
95
|
+
) as RemoteElementComponent<RbButtonElement, RbButtonProps, RbPressEventProps>;
|
|
96
|
+
export const IconButton = createRemoteComponent(
|
|
97
|
+
"rb-icon-button",
|
|
98
|
+
RbIconButtonElement,
|
|
99
|
+
events({ onPress: { event: "press" } }),
|
|
100
|
+
) as RemoteElementComponent<
|
|
101
|
+
RbIconButtonElement,
|
|
102
|
+
RbIconButtonProps,
|
|
103
|
+
RbPressEventProps
|
|
104
|
+
>;
|
|
105
|
+
export const Text = createRemoteComponent(
|
|
106
|
+
"rb-text",
|
|
107
|
+
RbTextElement,
|
|
108
|
+
) as RemoteElementComponent<RbTextElement, RbTextProps>;
|
|
109
|
+
export const TextInput = createRemoteComponent(
|
|
110
|
+
"rb-text-input",
|
|
111
|
+
RbTextInputElement,
|
|
112
|
+
events({ onInput: { event: "input" } }),
|
|
113
|
+
) as RemoteElementComponent<
|
|
114
|
+
RbTextInputElement,
|
|
115
|
+
RbTextInputProps,
|
|
116
|
+
RbTextInputEventProps
|
|
117
|
+
>;
|
|
118
|
+
export const Switch = createRemoteComponent(
|
|
119
|
+
"rb-switch",
|
|
120
|
+
RbSwitchElement,
|
|
121
|
+
events({ onChange: { event: "change" } }),
|
|
122
|
+
) as RemoteElementComponent<RbSwitchElement, RbSwitchProps, RbSwitchEventProps>;
|
|
123
|
+
export const Select = createRemoteComponent(
|
|
124
|
+
"rb-select",
|
|
125
|
+
RbSelectElement,
|
|
126
|
+
events({ onChange: { event: "change" } }),
|
|
127
|
+
) as RemoteElementComponent<RbSelectElement, RbSelectProps, RbSelectEventProps>;
|
|
128
|
+
|
|
129
|
+
export { useRb } from "./sdk";
|
|
130
|
+
export type { RbSdk, RbNotifyType } from "./sdk";
|
|
131
|
+
export type { RbSelectOption } from "./elements";
|
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin runtime SDK — the small, stable surface a plugin author calls from
|
|
3
|
+
* inside the sandbox to talk to the host (Muscat / nexus).
|
|
4
|
+
*
|
|
5
|
+
* The concrete implementation is injected by the host across the iframe thread
|
|
6
|
+
* (see ./connect for the sandbox side, ./host for the host side).
|
|
7
|
+
*/
|
|
8
|
+
import { createContext, useContext } from "react";
|
|
9
|
+
|
|
10
|
+
export type RbNotifyType = "info" | "success" | "warning" | "error";
|
|
11
|
+
|
|
12
|
+
export interface RbSdk {
|
|
13
|
+
/**
|
|
14
|
+
* Invoke a host-side action (declared in manifest.actions). Resolves with
|
|
15
|
+
* whatever the host/back end returns.
|
|
16
|
+
*/
|
|
17
|
+
action: (id: string, payload?: unknown) => Promise<unknown>;
|
|
18
|
+
/** Show a transient notification through the host's toast system. */
|
|
19
|
+
notify: (message: string, type?: RbNotifyType) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const noopSdk: RbSdk = {
|
|
23
|
+
action: async () => {
|
|
24
|
+
if (typeof console !== "undefined") {
|
|
25
|
+
console.warn("[plugin-ui] rb.action called outside of a host context");
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
},
|
|
29
|
+
notify: (message) => {
|
|
30
|
+
if (typeof console !== "undefined") {
|
|
31
|
+
console.warn("[plugin-ui] rb.notify (no host):", message);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const RbContext = createContext<RbSdk>(noopSdk);
|
|
37
|
+
|
|
38
|
+
/** Access the host SDK from within a plugin component. */
|
|
39
|
+
export function useRb(): RbSdk {
|
|
40
|
+
return useContext(RbContext);
|
|
41
|
+
}
|