@vertesia/ui 0.54.0 → 0.55.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.
@@ -0,0 +1,67 @@
1
+ import type { VertesiaClient, ZenoClient } from "@vertesia/client";
2
+ import type { AccountRef, AuthTokenPayload, ProjectRef } from "@vertesia/common";
3
+ export declare const HOST_CONTEXT_VAR = "__vetesia_host_context__";
4
+ export interface UserSession {
5
+ isLoading: boolean;
6
+ client: VertesiaClient;
7
+ authError?: Error;
8
+ authToken?: AuthTokenPayload;
9
+ lastSelectedAccount?: string | null;
10
+ lastSelectedProject?: string | null;
11
+ onboardingComplete?: boolean;
12
+ store: ZenoClient;
13
+ user?: AuthTokenPayload;
14
+ account?: AccountRef;
15
+ accounts?: AccountRef[];
16
+ project?: ProjectRef;
17
+ rawAuthToken: Promise<string>;
18
+ }
19
+ export interface NavigateOptions {
20
+ replace?: boolean;
21
+ state?: any;
22
+ /**
23
+ * if defined prepend the basePath to the `to` argument
24
+ */
25
+ basePath?: string;
26
+ }
27
+ export interface RouterContext {
28
+ location: Location;
29
+ params: Record<string, string>;
30
+ state: any;
31
+ /**
32
+ * The path that matched the route. For widlcard `/*` paths this doens;t include the wildcard part.
33
+ * You can get the wildcard path from `remainingPath`.
34
+ */
35
+ matchedRoutePath: string;
36
+ remainingPath?: string;
37
+ navigate: (path: string, options?: NavigateOptions) => void;
38
+ }
39
+ type LazyImportFn = () => Promise<any>;
40
+ interface ComponentRoute {
41
+ path: string;
42
+ Component: React.ComponentType<any>;
43
+ }
44
+ interface LazyComponentRoute {
45
+ path: string;
46
+ LazyComponent: LazyImportFn;
47
+ }
48
+ type Route = ComponentRoute | LazyComponentRoute;
49
+ export interface MultiPagePluginProps {
50
+ title: string;
51
+ routes: Route[];
52
+ /**
53
+ * The path to use for the root resource. Defaults to '/'. Cannot contains path vairables or wildcards
54
+ */
55
+ index?: string;
56
+ children?: React.ReactNode;
57
+ fixLinks?: boolean;
58
+ }
59
+ export interface HostContext {
60
+ useUserSession: () => UserSession;
61
+ useRouterContext: () => RouterContext;
62
+ useNavigate: () => (path: string, options?: NavigateOptions) => void;
63
+ useLocation: () => Location;
64
+ MultiPagePlugin: React.ComponentType<MultiPagePluginProps>;
65
+ }
66
+ export {};
67
+ //# sourceMappingURL=HostContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostContext.d.ts","sourceRoot":"","sources":["../../src/context/HostContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjF,eAAO,MAAM,gBAAgB,6BAA6B,CAAC;AAK3D,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;CAChC;AACD,MAAM,WAAW,eAAe;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC1B,QAAQ,EAAE,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@
1
+ {"version":3,"file":"HostContext.js","sourceRoot":"","sources":["../../src/context/HostContext.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file contains the host context which is a set of live components and hooks shared
3
+ * with the plugins.
4
+ * The plugin must import a component or hook from the host context by using:
5
+ * import {SomeComponnet, useSomeHook } from '@vetesia/ui-extension-sdk/context';
6
+ */
7
+ export declare const useUserSession: () => import("./HostContext.js").UserSession, useRouterContext: () => import("./HostContext.js").RouterContext, useNavigate: () => (path: string, options?: import("./HostContext.js").NavigateOptions) => void, useLocation: () => Location, MultiPagePlugin: import("react").ComponentType<import("./HostContext.js").MultiPagePluginProps>;
8
+ export * from "./HostContext.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,eAAO,MACH,cAAc,gDACd,gBAAgB,kDAChB,WAAW,8BAMy/C,CAAC,uDALrgD,WAAW,kBACX,eAAe,gFACR,CAAC;AAEZ,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This file contains the host context which is a set of live components and hooks shared
3
+ * with the plugins.
4
+ * The plugin must import a component or hook from the host context by using:
5
+ * import {SomeComponnet, useSomeHook } from '@vetesia/ui-extension-sdk/context';
6
+ */
7
+ import { HOST_CONTEXT_VAR } from "./HostContext.js";
8
+ const context = globalThis[HOST_CONTEXT_VAR];
9
+ export const { useUserSession, useRouterContext, useNavigate, useLocation, MultiPagePlugin, } = context;
10
+ export * from "./HostContext.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAe,MAAM,kBAAkB,CAAC;AAEjE,MAAM,OAAO,GAAI,UAAkB,CAAC,gBAAgB,CAAgB,CAAC;AAErE,MAAM,CAAC,MAAM,EACT,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,eAAe,GAClB,GAAG,OAAO,CAAC;AAEZ,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { HostContext } from "../context/HostContext.js";
2
+ export declare function PluginHost({ pluginId, slot, context }: {
3
+ pluginId: string;
4
+ slot: string;
5
+ context: HostContext;
6
+ }): false | import("react/jsx-runtime").JSX.Element;
7
+ //# sourceMappingURL=PluginHost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginHost.d.ts","sourceRoot":"","sources":["../../src/host/PluginHost.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAoB,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAO1E,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,mDAO/G"}
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useInsertionEffect, useState } from "react";
3
+ import { usePluginModule } from "./PluginManager.js";
4
+ import { HOST_CONTEXT_VAR } from "../context/HostContext.js";
5
+ function createSharedContext(context) {
6
+ globalThis[HOST_CONTEXT_VAR] = context;
7
+ return context;
8
+ }
9
+ export function PluginHost({ pluginId, slot, context }) {
10
+ const [contextCreated, setContextCreated] = useState(false);
11
+ useEffect(() => {
12
+ createSharedContext(context);
13
+ setContextCreated(true);
14
+ }, []);
15
+ return contextCreated && _jsx(_PluginHost, { pluginId: pluginId, slot: slot });
16
+ }
17
+ function _PluginHost({ pluginId, slot }) {
18
+ const { plugin, module, error } = usePluginModule(pluginId);
19
+ useInsertionEffect(() => {
20
+ if (module) {
21
+ plugin.install();
22
+ }
23
+ }, [module]);
24
+ if (!plugin) {
25
+ return _jsxs("div", { children: ["Plugin ", pluginId, " not found"] });
26
+ }
27
+ else if (error) {
28
+ return _jsxs("div", { children: ["Failed to load plugin ", plugin.manifest.name, " from ", plugin.manifest.src, ": ", error.message] });
29
+ }
30
+ else if (module) {
31
+ return module.mount(slot);
32
+ }
33
+ else {
34
+ return _jsx("div", { children: "Loading ..." });
35
+ }
36
+ }
37
+ //# sourceMappingURL=PluginHost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginHost.js","sourceRoot":"","sources":["../../src/host/PluginHost.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAe,MAAM,2BAA2B,CAAC;AAE1E,SAAS,mBAAmB,CAAC,OAAoB;IAC5C,UAAkB,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC;IAChD,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAA4D;IAC5G,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5D,SAAS,CAAC,GAAG,EAAE;QACX,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC7B,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,cAAc,IAAI,KAAC,WAAW,IAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAI,CAAA;AAC5E,CAAC;AAED,SAAS,WAAW,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAsC;IACvE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5D,kBAAkB,CAAC,GAAG,EAAE;QACpB,IAAI,MAAM,EAAE,CAAC;YACT,MAAO,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;IACL,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,qCAAa,QAAQ,kBAAiB,CAAA;IACjD,CAAC;SAAM,IAAI,KAAK,EAAE,CAAC;QACf,OAAO,oDAA4B,MAAM,CAAC,QAAQ,CAAC,IAAI,YAAQ,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAI,KAAK,CAAC,OAAO,IAAO,CAAA;IAC9G,CAAC;SAAM,IAAI,MAAM,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;SAAM,CAAC;QACJ,OAAO,wCAAsB,CAAA;IACjC,CAAC;AAEL,CAAC"}
@@ -0,0 +1,59 @@
1
+ import React from "react";
2
+ import { PluginManifest } from "@vertesia/common";
3
+ export declare enum PluginInstanceStatus {
4
+ registered = 0,
5
+ loading = 1,
6
+ loaded = 2,
7
+ error = 3,//loading error
8
+ installed = 4
9
+ }
10
+ export interface PluginModule {
11
+ mount(slot: string): React.ReactNode;
12
+ css?: string;
13
+ }
14
+ export declare class PluginInstance {
15
+ manifest: PluginManifest;
16
+ status: PluginInstanceStatus;
17
+ _module?: PluginModule;
18
+ error?: Error;
19
+ constructor(manifest: PluginManifest);
20
+ get isInstalled(): boolean;
21
+ get isLoading(): boolean;
22
+ get styleId(): string;
23
+ _load(): Promise<void>;
24
+ getModule(): Promise<PluginModule>;
25
+ install(): void;
26
+ uninstall(): Promise<void>;
27
+ }
28
+ export declare class PluginManager {
29
+ plugins: Record<string, PluginInstance>;
30
+ constructor(manifests?: PluginManifest[]);
31
+ addAll(manifests: PluginManifest[]): PluginInstance[];
32
+ add(manifest: PluginManifest): PluginInstance;
33
+ remove(id: string): void;
34
+ get(id: string): PluginInstance;
35
+ }
36
+ export interface PluginManagerState {
37
+ manager: PluginManager;
38
+ refresh(): void;
39
+ }
40
+ interface PluginsProviderProps {
41
+ plugins: PluginManifest[];
42
+ children?: React.ReactNode | React.ReactNode[];
43
+ }
44
+ export declare function PluginsProvider({ plugins, children }: PluginsProviderProps): import("react/jsx-runtime").JSX.Element;
45
+ export declare function usePluginManager(): PluginManagerState;
46
+ export declare function usePluginInstance(id: string): PluginInstance;
47
+ /**
48
+ * Get the plugin instance and load the module. Returns null if the plugin is not yet loaded.
49
+ * When the plugin loads then returns the plugin instance
50
+ * @param id
51
+ * @returns
52
+ */
53
+ export declare function usePluginModule(id: string): {
54
+ plugin: PluginInstance | null;
55
+ module: PluginModule | null;
56
+ error: Error | null;
57
+ };
58
+ export {};
59
+ //# sourceMappingURL=PluginManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/host/PluginManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkE,MAAM,OAAO,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,oBAAY,oBAAoB;IAC5B,UAAU,IAAA;IACV,OAAO,IAAA;IACP,MAAM,IAAA;IACN,KAAK,IAAA,CAAE,eAAe;IACtB,SAAS,IAAA;CACZ;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,cAAc;IAKJ,QAAQ,EAAE,cAAc;IAJ3C,MAAM,EAAE,oBAAoB,CAAmC;IAC/D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;gBAEK,QAAQ,EAAE,cAAc;IAG3C,IAAI,WAAW,YAEd;IAED,IAAI,SAAS,YAEZ;IAED,IAAI,OAAO,WAEV;IAEK,KAAK;IAmBL,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAOxC,OAAO;IAmBD,SAAS;CASlB;AAED,qBAAa,aAAa;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAM;gBACjC,SAAS,GAAE,cAAc,EAAO;IAG5C,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE;IAGlC,GAAG,CAAC,QAAQ,EAAE,cAAc;IAK5B,MAAM,CAAC,EAAE,EAAE,MAAM;IAOjB,GAAG,CAAC,EAAE,EAAE,MAAM;CAGjB;AAED,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,IAAI,IAAI,CAAC;CACnB;AAID,UAAU,oBAAoB;IAC1B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;CAClD;AACD,wBAAgB,eAAe,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,oBAAoB,2CAU1E;AAED,wBAAgB,gBAAgB,uBAM/B;AAED,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,kBAE3C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG;IACzC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACvB,CAkCA"}
@@ -0,0 +1,195 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
3
+ export var PluginInstanceStatus;
4
+ (function (PluginInstanceStatus) {
5
+ PluginInstanceStatus[PluginInstanceStatus["registered"] = 0] = "registered";
6
+ PluginInstanceStatus[PluginInstanceStatus["loading"] = 1] = "loading";
7
+ PluginInstanceStatus[PluginInstanceStatus["loaded"] = 2] = "loaded";
8
+ PluginInstanceStatus[PluginInstanceStatus["error"] = 3] = "error";
9
+ PluginInstanceStatus[PluginInstanceStatus["installed"] = 4] = "installed";
10
+ })(PluginInstanceStatus || (PluginInstanceStatus = {}));
11
+ export class PluginInstance {
12
+ constructor(manifest) {
13
+ Object.defineProperty(this, "manifest", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: manifest
18
+ });
19
+ Object.defineProperty(this, "status", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: PluginInstanceStatus.registered
24
+ });
25
+ Object.defineProperty(this, "_module", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, "error", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ }
38
+ get isInstalled() {
39
+ return this.status === PluginInstanceStatus.installed;
40
+ }
41
+ get isLoading() {
42
+ return this.status === PluginInstanceStatus.loading;
43
+ }
44
+ get styleId() {
45
+ return `plugin-style-${this.manifest.id}`;
46
+ }
47
+ async _load() {
48
+ if (this.status === PluginInstanceStatus.registered) {
49
+ try {
50
+ const module = await import(/* @vite-ignore */ this.manifest.src);
51
+ this.status = PluginInstanceStatus.loading;
52
+ if (typeof module.mount !== "function") {
53
+ throw new Error(`Plugin ${this.manifest.id} does not provide a mount function`);
54
+ }
55
+ this._module = module;
56
+ this.status = PluginInstanceStatus.loaded;
57
+ }
58
+ catch (err) {
59
+ this.status = PluginInstanceStatus.error;
60
+ throw err;
61
+ }
62
+ }
63
+ else {
64
+ throw new Error(`Plugin ${this.manifest.id} was already loaded`);
65
+ }
66
+ }
67
+ async getModule() {
68
+ if (!this._module) {
69
+ await this._load();
70
+ }
71
+ return this._module;
72
+ }
73
+ install() {
74
+ if (this.status === PluginInstanceStatus.loaded && this._module) {
75
+ const module = this._module;
76
+ if (module.css) {
77
+ // inject css
78
+ let style = document.getElementById(this.styleId);
79
+ if (!style) {
80
+ style = document.createElement('style');
81
+ style.id = this.styleId;
82
+ style.appendChild(document.createTextNode(module.css));
83
+ document.head.appendChild(style);
84
+ this.status = PluginInstanceStatus.installed;
85
+ }
86
+ }
87
+ }
88
+ else if (this.status !== PluginInstanceStatus.installed) {
89
+ throw new Error(`Plugin ${this.manifest.id} is not loaded: ` + this.status);
90
+ }
91
+ }
92
+ async uninstall() {
93
+ if (this.status === PluginInstanceStatus.installed) {
94
+ const style = document.getElementById(this.styleId);
95
+ if (style) {
96
+ style.remove();
97
+ this.status = PluginInstanceStatus.loaded;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ export class PluginManager {
103
+ constructor(manifests = []) {
104
+ Object.defineProperty(this, "plugins", {
105
+ enumerable: true,
106
+ configurable: true,
107
+ writable: true,
108
+ value: {}
109
+ });
110
+ this.addAll(manifests);
111
+ }
112
+ addAll(manifests) {
113
+ return manifests.map(manifest => this.add(manifest));
114
+ }
115
+ add(manifest) {
116
+ const instance = new PluginInstance(manifest);
117
+ this.plugins[manifest.id] = instance;
118
+ return instance;
119
+ }
120
+ remove(id) {
121
+ const instance = this.plugins[id];
122
+ if (instance) {
123
+ instance.uninstall();
124
+ delete this.plugins[id];
125
+ }
126
+ }
127
+ get(id) {
128
+ return this.plugins[id];
129
+ }
130
+ }
131
+ const PluginManagerContext = createContext(null);
132
+ export function PluginsProvider({ plugins, children }) {
133
+ const [key, setKey] = useState(0);
134
+ const manager = useMemo(() => new PluginManager(plugins), [plugins]);
135
+ const ctx = {
136
+ manager,
137
+ refresh: () => setKey(key + 1),
138
+ };
139
+ return _jsx(PluginManagerContext.Provider, { value: ctx, children: children }, key);
140
+ }
141
+ export function usePluginManager() {
142
+ const ctx = useContext(PluginManagerContext);
143
+ if (!ctx) {
144
+ throw new Error('No PluginManagerContext found');
145
+ }
146
+ return ctx;
147
+ }
148
+ export function usePluginInstance(id) {
149
+ return usePluginManager().manager.get(id);
150
+ }
151
+ /**
152
+ * Get the plugin instance and load the module. Returns null if the plugin is not yet loaded.
153
+ * When the plugin loads then returns the plugin instance
154
+ * @param id
155
+ * @returns
156
+ */
157
+ export function usePluginModule(id) {
158
+ const [module, setModule] = useState(null);
159
+ const { manager } = usePluginManager();
160
+ const plugin = manager.get(id);
161
+ useEffect(() => {
162
+ if (plugin) {
163
+ plugin.getModule().then(setModule);
164
+ }
165
+ }, [plugin]);
166
+ if (!plugin) {
167
+ return {
168
+ plugin: null,
169
+ module: null,
170
+ error: new Error(`Plugin ${id} not found`),
171
+ };
172
+ }
173
+ else if (plugin.error) {
174
+ return {
175
+ plugin: plugin,
176
+ module: plugin._module || null,
177
+ error: plugin.error,
178
+ };
179
+ }
180
+ else if (module) {
181
+ return {
182
+ plugin: plugin,
183
+ module: module,
184
+ error: null,
185
+ };
186
+ }
187
+ else {
188
+ return {
189
+ plugin: plugin,
190
+ module: module,
191
+ error: plugin.error || null,
192
+ };
193
+ }
194
+ }
195
+ //# sourceMappingURL=PluginManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/host/PluginManager.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGvF,MAAM,CAAN,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC5B,2EAAU,CAAA;IACV,qEAAO,CAAA;IACP,mEAAM,CAAA;IACN,iEAAK,CAAA;IACL,yEAAS,CAAA;AACb,CAAC,EANW,oBAAoB,KAApB,oBAAoB,QAM/B;AAOD,MAAM,OAAO,cAAc;IAKvB,YAAmB,QAAwB;QAA/B;;;;mBAAO,QAAQ;WAAgB;QAJ3C;;;;mBAA+B,oBAAoB,CAAC,UAAU;WAAC;QAC/D;;;;;WAAuB;QACvB;;;;;WAAc;IAGd,CAAC;IAED,IAAI,WAAW;QACX,OAAO,IAAI,CAAC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B,CAAC;IACN,CAAC;SAAM,IAAI,MAAM,EAAE,CAAC;QAChB,OAAO;YACH,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,IAAI;SACd,CAAC;IACN,CAAC;SAAM,CAAC;QACJ,OAAO;YACH,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI;SAC9B,CAAC;IACN,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./PluginHost.js";
2
+ export * from "./PluginManager.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./PluginHost.js";
2
+ export * from "./PluginManager.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export {};
2
+ // TODO export here common components, hooks and utility functions
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,kEAAkE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertesia/ui",
3
- "version": "0.54.0",
3
+ "version": "0.55.0",
4
4
  "description": "Vertesia UI components and and hooks",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "types": "./lib/index.d.ts",
34
34
  "dependencies": {
35
- "@vertesia/client": "0.54.0",
36
- "@vertesia/common": "0.54.0"
35
+ "@vertesia/client": "0.55.0",
36
+ "@vertesia/common": "0.55.0"
37
37
  },
38
38
  "exports": {
39
39
  ".": {