@perses-dev/plugin-system 0.2.1 → 0.3.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/components/PluginLoadingBoundary/PluginLoader.d.ts.map +1 -1
- package/dist/components/PluginLoadingBoundary/PluginLoader.js +1 -1
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.js +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts +10 -4
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +1 -1
- package/dist/components/PluginRegistry/registry-state.d.ts +2 -2
- package/dist/components/PluginRegistry/registry-state.d.ts.map +1 -1
- package/dist/components/PluginRegistry/registry-state.js +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginLoader.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/PluginLoader.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"PluginLoader.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/PluginLoader.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,QAsBpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useQuery}from"react-query";import{usePluginRegistry}from"../PluginRegistry";export function PluginLoader(r){const{pluginType:
|
|
1
|
+
import{useQuery}from"react-query";import{usePluginRegistry}from"../PluginRegistry";export function PluginLoader(r){const{pluginType:e,kind:i}=r,{loadPlugin:u}=usePluginRegistry(),{error:n}=useQuery(`PluginLoader:${e}_${i}`,(()=>{if(void 0===u)throw new Error("PluginRegistry loadPlugin not available");return u(e,i)}),{enabled:void 0!==u});if(null!=n)throw n;return null}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Fragment,createContext,useContext,useMemo,useCallback,useEffect}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../model";import{usePluginRegistry}from"../PluginRegistry";import{PluginLoader}from"./PluginLoader";export function PluginLoadingBoundary(e){const{fallback:n,children:o}=e,{plugins:r}=usePluginRegistry(),[t,
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Fragment,createContext,useContext,useMemo,useCallback,useEffect}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../model";import{usePluginRegistry}from"../PluginRegistry";import{PluginLoader}from"./PluginLoader";export function PluginLoadingBoundary(e){const{fallback:n,children:o}=e,{plugins:r}=usePluginRegistry(),[t,i]=useImmer((()=>{const e={};for(const n of ALL_PLUGIN_TYPES)e[n]={};return e})),u=useCallback(((e,n)=>{i((o=>{o[e][n]=!0}))}),[i]),s=useMemo((()=>({registerPluginDependency:u})),[u]),{loaders:g,fragmentKey:a}=useMemo((()=>{let e="";const n=[];for(const o of ALL_PLUGIN_TYPES){e+=`_${o}:`;const i=t[o];for(const t in i)e+=t,void 0===r[o][t]&&n.push(_jsx(PluginLoader,{pluginType:o,kind:t},`${o}:${t}`))}return{loaders:n,fragmentKey:e}}),[r,t]),d=0===g.length;return _jsxs(PluginLoadingBoundaryContext.Provider,{value:s,children:[g,d&&_jsx(Fragment,{children:o},a),!1===d&&n]})}const PluginLoadingBoundaryContext=createContext(void 0);export function usePluginLoadingBoundary(){const e=useContext(PluginLoadingBoundaryContext);if(void 0===e)throw new Error("PluginLoadingBoundary context not found. Did you forget a Provider?");return e}export function usePlugin(e,n){const{registerPluginDependency:o}=usePluginLoadingBoundary();useEffect((()=>{o(e,n.kind)}),[e,n.kind,o]);const{plugins:r}=usePluginRegistry();return r[e][n.kind]}
|
|
@@ -10,14 +10,20 @@ export interface PluginRegistryProps {
|
|
|
10
10
|
* PluginRegistryContext provider that keeps track of all available plugins and
|
|
11
11
|
* their implementations once they've been loaded.
|
|
12
12
|
*/
|
|
13
|
-
export declare function PluginRegistry(props: PluginRegistryProps): JSX.Element
|
|
14
|
-
interface PluginRegistryContextType {
|
|
13
|
+
export declare function PluginRegistry(props: PluginRegistryProps): JSX.Element;
|
|
14
|
+
export interface PluginRegistryContextType {
|
|
15
|
+
/**
|
|
16
|
+
* Plugins that have already been loaded and are available for use.
|
|
17
|
+
*/
|
|
15
18
|
plugins: LoadedPluginsByTypeAndKind;
|
|
16
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Asks the plugin registry to load the specified plugin. This will be undefined until the list of available plugins
|
|
21
|
+
* has finished loading.
|
|
22
|
+
*/
|
|
23
|
+
loadPlugin?: (pluginType: PluginType, kind: string) => Promise<void>;
|
|
17
24
|
}
|
|
18
25
|
/**
|
|
19
26
|
* Gets the PluginRegistryContext, throwing if the provider is missing.
|
|
20
27
|
*/
|
|
21
28
|
export declare function usePluginRegistry(): PluginRegistryContextType;
|
|
22
|
-
export {};
|
|
23
29
|
//# sourceMappingURL=PluginRegistry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAoB,MAAM,kBAAkB,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,mBAAmB,EAAE,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACrD,kBAAkB,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;CACzE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAoB,MAAM,kBAAkB,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,mBAAmB,EAAE,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACrD,kBAAkB,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;CACzE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eA+BxD;AAID,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,0BAA0B,CAAC;IAEpC;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,yBAAyB,CAM7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useContext,useMemo,useCallback}from"react";import{useQuery}from"react-query";import{useRegistryState}from"./registry-state";export function PluginRegistry(e){const{children:t,getInstalledPlugins:
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useContext,useMemo,useCallback}from"react";import{useQuery}from"react-query";import{useRegistryState}from"./registry-state";export function PluginRegistry(e){const{children:t,getInstalledPlugins:i,importPluginModule:r}=e,o=useQuery("installed-plugins",i),{loadablePlugins:n,plugins:s,register:u}=useRegistryState(o.data),l=useCallback((async(e,t)=>{if(void 0!==s[e][t])return;const i=n[e][t];if(void 0===i)throw new Error(`No ${e} plugin is available for kind ${t}`);const o=await r(i);u(o)}),[s,n,r,u]),a=useMemo((()=>({plugins:s,loadPlugin:o.isLoading?void 0:l})),[o.isLoading,s,l]);return _jsx(PluginRegistryContext.Provider,{value:a,children:t})}const PluginRegistryContext=createContext(void 0);export function usePluginRegistry(){const e=useContext(PluginRegistryContext);if(void 0===e)throw new Error("No PluginRegistry context found. Did you forget a Provider?");return e}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { JsonObject } from '@perses-dev/core';
|
|
2
2
|
import { PluginModule, PluginResource, PluginType, PluginImplementation } from '../../model';
|
|
3
3
|
export declare type PluginResourcesByTypeAndKind = {
|
|
4
|
-
[K in PluginType]:
|
|
4
|
+
[K in PluginType]: Record<string, PluginResource>;
|
|
5
5
|
};
|
|
6
6
|
export declare type LoadedPluginsByTypeAndKind = {
|
|
7
|
-
[Type in PluginType]:
|
|
7
|
+
[Type in PluginType]: Record<string, PluginImplementation<Type, JsonObject>>;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Hook for setting up plugin registry state. Returns the state, plus a function
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-state.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/registry-state.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAEL,YAAY,EACZ,cAAc,EAEd,UAAU,EAEV,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAIrB,oBAAY,4BAA4B,GAAG;KACxC,CAAC,IAAI,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"registry-state.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/registry-state.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAEL,YAAY,EACZ,cAAc,EAEd,UAAU,EAEV,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAIrB,oBAAY,4BAA4B,GAAG;KACxC,CAAC,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC;CAClD,CAAC;AAGF,oBAAY,0BAA0B,GAAG;KACtC,IAAI,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;CAC7E,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,cAAc,EAAE;;;6BAuEjD,YAAY,KAAG,IAAI;EAerC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback,useMemo,useRef}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../model";import{createGraphQueryPlugin,createPanelPlugin,createVariablePlugin}from"./create-plugin";export function useRegistryState(e){const r=useMemo((()=>{const r={};for(const e of ALL_PLUGIN_TYPES)r[e]=
|
|
1
|
+
import{useCallback,useMemo,useRef}from"react";import{useImmer}from"use-immer";import{ALL_PLUGIN_TYPES}from"../../model";import{createGraphQueryPlugin,createPanelPlugin,createVariablePlugin}from"./create-plugin";export function useRegistryState(e){const r=useMemo((()=>{const r={};for(const e of ALL_PLUGIN_TYPES)r[e]={};if(void 0===e)return r;const n=e=>{const n=e.spec.supported_kinds;for(const o in n){const t=n[o];if(void 0===t)continue;const i=r[t];void 0===i[o]?i[o]=e:console.warn(`Got multiple ${t} plugin definitions for kind ${o}`)}};for(const r of e)n(r);return r}),[e]),[n,o]=useImmer((()=>{const e={};for(const r of ALL_PLUGIN_TYPES)e[r]={};return e})),t=useCallback((e=>{switch(e.pluginType){case"Variable":return void o((r=>{r.Variable[e.kind]=createVariablePlugin(e)}));case"Panel":return void o((r=>{r.Panel[e.kind]=createPanelPlugin(e)}));case"GraphQuery":return void o((r=>{r.GraphQuery[e.kind]=createGraphQueryPlugin(e)}));default:throw new Error(`Unhandled plugin config: ${e}`)}}),[o]),i=useRef(new Set);return{loadablePlugins:r,plugins:n,register:useCallback((e=>{i.current.has(e)||(e.setup(t),i.current.add(e))}),[t])}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/plugin-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The plugin feature in Pereses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@perses-dev/components": "^0.
|
|
25
|
-
"@perses-dev/core": "^0.
|
|
24
|
+
"@perses-dev/components": "^0.3.0",
|
|
25
|
+
"@perses-dev/core": "^0.3.0",
|
|
26
26
|
"immer": "^9.0.12",
|
|
27
|
-
"react-query": "^3.34.16",
|
|
28
27
|
"use-immer": "^0.6.0"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"react": "^17.0.2"
|
|
30
|
+
"react": "^17.0.2",
|
|
31
|
+
"react-query": "^3.34.16"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
34
|
"dist"
|