@perses-dev/plugin-system 0.8.0 → 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/cjs/components/PluginRegistry/PluginRegistry.js +43 -29
- package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +114 -38
- package/dist/cjs/components/PluginRegistry/index.js +17 -18
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +23 -20
- package/dist/cjs/components/PluginRegistry/plugin-registry-model.js +17 -7
- package/dist/cjs/components/PluginRegistry/test-plugins/bert/index.js +22 -12
- package/dist/cjs/components/PluginRegistry/test-plugins/ernie/index.js +20 -8
- package/dist/cjs/components/PluginRegistry/test-plugins/index.js +59 -39
- package/dist/cjs/components/index.js +17 -20
- package/dist/cjs/index.js +19 -20
- package/dist/cjs/model/datasource.js +16 -0
- package/dist/cjs/model/index.js +21 -21
- package/dist/cjs/model/panels.js +4 -21
- package/dist/cjs/model/plugins.js +4 -7
- package/dist/cjs/model/time-series-queries.js +16 -0
- package/dist/cjs/model/variables.js +5 -17
- package/dist/cjs/model/visual-editing.js +10 -2
- package/dist/cjs/runtime/datasources.js +20 -13
- package/dist/cjs/runtime/index.js +22 -21
- package/dist/cjs/runtime/plugins.js +25 -22
- package/dist/cjs/runtime/query-string.js +17 -10
- package/dist/cjs/runtime/template-variables.js +34 -16
- package/dist/cjs/runtime/time-range.js +17 -10
- package/dist/cjs/runtime/time-series-queries.js +58 -0
- package/dist/cjs/test/render.js +32 -13
- package/dist/cjs/test/setup-tests.js +4 -10
- package/dist/cjs/utils/cache-keys.js +8 -7
- package/dist/components/PluginRegistry/PluginRegistry.js +81 -1
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -0
- package/dist/components/PluginRegistry/PluginRegistry.test.js +142 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.js.map +1 -0
- package/dist/components/PluginRegistry/index.js +16 -1
- package/dist/components/PluginRegistry/index.js.map +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.js +66 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -0
- package/dist/components/PluginRegistry/plugin-registry-model.d.ts +1 -2
- package/dist/components/PluginRegistry/plugin-registry-model.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-registry-model.js +23 -1
- package/dist/components/PluginRegistry/plugin-registry-model.js.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/bert/index.js +25 -1
- package/dist/components/PluginRegistry/test-plugins/bert/index.js.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/ernie/index.d.ts.map +1 -1
- package/dist/components/PluginRegistry/test-plugins/ernie/index.js +30 -1
- package/dist/components/PluginRegistry/test-plugins/ernie/index.js.map +1 -0
- package/dist/components/PluginRegistry/test-plugins/index.js +35 -1
- package/dist/components/PluginRegistry/test-plugins/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -3
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +15 -1
- package/dist/components/index.js.map +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -0
- package/dist/model/datasource.d.ts +9 -0
- package/dist/model/datasource.d.ts.map +1 -0
- package/dist/model/datasource.js +15 -0
- package/dist/model/datasource.js.map +1 -0
- package/dist/model/index.d.ts +2 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +20 -1
- package/dist/model/index.js.map +1 -0
- package/dist/model/panels.d.ts +7 -11
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js +15 -1
- package/dist/model/panels.js.map +1 -0
- package/dist/model/plugins.d.ts +16 -25
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js +15 -1
- package/dist/model/plugins.js.map +1 -0
- package/dist/model/time-series-queries.d.ts +28 -0
- package/dist/model/time-series-queries.d.ts.map +1 -0
- package/dist/model/time-series-queries.js +15 -0
- package/dist/model/time-series-queries.js.map +1 -0
- package/dist/model/variables.d.ts +16 -11
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +15 -1
- package/dist/model/variables.js.map +1 -0
- package/dist/model/visual-editing.d.ts +5 -6
- package/dist/model/visual-editing.d.ts.map +1 -1
- package/dist/model/visual-editing.js +15 -1
- package/dist/model/visual-editing.js.map +1 -0
- package/dist/runtime/datasources.d.ts +5 -9
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js +23 -1
- package/dist/runtime/datasources.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +20 -1
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/plugins.d.ts +5 -14
- package/dist/runtime/plugins.d.ts.map +1 -1
- package/dist/runtime/plugins.js +33 -1
- package/dist/runtime/plugins.js.map +1 -0
- package/dist/runtime/query-string.js +25 -1
- package/dist/runtime/query-string.js.map +1 -0
- package/dist/runtime/template-variables.d.ts +10 -1
- package/dist/runtime/template-variables.d.ts.map +1 -1
- package/dist/runtime/template-variables.js +44 -1
- package/dist/runtime/template-variables.js.map +1 -0
- package/dist/runtime/time-range.js +25 -1
- package/dist/runtime/time-range.js.map +1 -0
- package/dist/runtime/time-series-queries.d.ts +14 -0
- package/dist/runtime/time-series-queries.d.ts.map +1 -0
- package/dist/runtime/time-series-queries.js +54 -0
- package/dist/runtime/time-series-queries.js.map +1 -0
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +42 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.d.ts.map +1 -1
- package/dist/test/setup-tests.js +16 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/utils/cache-keys.js +19 -1
- package/dist/utils/cache-keys.js.map +1 -0
- package/package.json +11 -8
- package/dist/cjs/components/PluginBoundary.js +0 -14
- package/dist/cjs/components/PluginLoadingBoundary/PluginLoader.js +0 -39
- package/dist/cjs/components/PluginLoadingBoundary/PluginLoadingBoundary.js +0 -85
- package/dist/cjs/components/PluginLoadingBoundary/index.js +0 -29
- package/dist/cjs/components/PluginRegistry/legacy/PluginRegistry.js +0 -57
- package/dist/cjs/components/PluginRegistry/legacy/index.js +0 -29
- package/dist/cjs/components/PluginRegistry/legacy/registry-state.js +0 -97
- package/dist/cjs/components/PluginRegistry/test-plugins/bert/plugin.json +0 -32
- package/dist/cjs/components/PluginRegistry/test-plugins/ernie/plugin.json +0 -24
- package/dist/cjs/model/graph-queries.js +0 -28
- package/dist/components/PluginBoundary.d.ts +0 -13
- package/dist/components/PluginBoundary.d.ts.map +0 -1
- package/dist/components/PluginBoundary.js +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoader.d.ts +0 -11
- package/dist/components/PluginLoadingBoundary/PluginLoader.d.ts.map +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoader.js +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts +0 -27
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.d.ts.map +0 -1
- package/dist/components/PluginLoadingBoundary/PluginLoadingBoundary.js +0 -1
- package/dist/components/PluginLoadingBoundary/index.d.ts +0 -2
- package/dist/components/PluginLoadingBoundary/index.d.ts.map +0 -1
- package/dist/components/PluginLoadingBoundary/index.js +0 -1
- package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts +0 -29
- package/dist/components/PluginRegistry/legacy/PluginRegistry.d.ts.map +0 -1
- package/dist/components/PluginRegistry/legacy/PluginRegistry.js +0 -1
- package/dist/components/PluginRegistry/legacy/index.d.ts +0 -2
- package/dist/components/PluginRegistry/legacy/index.d.ts.map +0 -1
- package/dist/components/PluginRegistry/legacy/index.js +0 -1
- package/dist/components/PluginRegistry/legacy/registry-state.d.ts +0 -18
- package/dist/components/PluginRegistry/legacy/registry-state.d.ts.map +0 -1
- package/dist/components/PluginRegistry/legacy/registry-state.js +0 -1
- package/dist/components/PluginRegistry/test-plugins/bert/plugin.json +0 -32
- package/dist/components/PluginRegistry/test-plugins/ernie/plugin.json +0 -24
- package/dist/model/graph-queries.d.ts +0 -36
- package/dist/model/graph-queries.d.ts.map +0 -1
- package/dist/model/graph-queries.js +0 -1
package/dist/utils/cache-keys.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/**
|
|
14
|
+
* Gets a unique key for a plugin type/kind that can be used as a cache key.
|
|
15
|
+
*/ export function getTypeAndKindKey(pluginType, kind) {
|
|
16
|
+
return `${pluginType}:${kind}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=cache-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/cache-keys.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PluginType } from '../model';\n\n/**\n * Gets a unique key for a plugin type/kind that can be used as a cache key.\n */\nexport function getTypeAndKindKey(pluginType: PluginType, kind: string) {\n return `${pluginType}:${kind}`;\n}\n"],"names":["getTypeAndKindKey","pluginType","kind"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC;;CAEC,GACD,OAAO,SAASA,iBAAiB,CAACC,UAAsB,EAAEC,IAAY,EAAE;IACtE,OAAO,CAAC,EAAED,UAAU,CAAC,CAAC,EAAEC,IAAI,CAAC,CAAC,CAAC;AACjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/plugin-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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",
|
|
@@ -12,26 +12,29 @@
|
|
|
12
12
|
"url": "https://github.com/perses/perses/issues"
|
|
13
13
|
},
|
|
14
14
|
"module": "dist/index.js",
|
|
15
|
-
"main": "dist
|
|
15
|
+
"main": "dist//cjs/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "rimraf dist/",
|
|
19
|
-
"build": "
|
|
20
|
-
"build:cjs": "
|
|
19
|
+
"build": "concurrently \"npm:build:*\"",
|
|
20
|
+
"build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
|
|
21
|
+
"build:esm": "swc ./src -d dist --config-file ../.swcrc",
|
|
22
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --preserveWatchOutput",
|
|
23
|
+
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
21
24
|
"test": "TZ=UTC jest",
|
|
22
25
|
"lint": "eslint src --ext .ts,.tsx",
|
|
23
26
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@perses-dev/components": "^0.
|
|
27
|
-
"@perses-dev/core": "^0.
|
|
29
|
+
"@perses-dev/components": "^0.9.0",
|
|
30
|
+
"@perses-dev/core": "^0.9.0",
|
|
28
31
|
"immer": "^9.0.15",
|
|
29
32
|
"use-immer": "^0.7.0"
|
|
30
33
|
},
|
|
31
34
|
"peerDependencies": {
|
|
35
|
+
"@tanstack/react-query": "^4.7.1",
|
|
32
36
|
"react": "^17.0.2 || ^18.0.0",
|
|
33
|
-
"react-dom": "^17.0.2 || ^18.0.0"
|
|
34
|
-
"react-query": "^3.34.16"
|
|
37
|
+
"react-dom": "^17.0.2 || ^18.0.0"
|
|
35
38
|
},
|
|
36
39
|
"files": [
|
|
37
40
|
"dist"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PluginBoundary = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const components_1 = require("@perses-dev/components");
|
|
6
|
-
const PluginLoadingBoundary_1 = require("./PluginLoadingBoundary");
|
|
7
|
-
/**
|
|
8
|
-
* Combination ErrorBoundary and PluginLoadingBoundary.
|
|
9
|
-
*/
|
|
10
|
-
function PluginBoundary(props) {
|
|
11
|
-
const { ErrorFallbackComponent, loadingFallback, children } = props;
|
|
12
|
-
return ((0, jsx_runtime_1.jsx)(components_1.ErrorBoundary, { FallbackComponent: ErrorFallbackComponent, children: (0, jsx_runtime_1.jsx)(PluginLoadingBoundary_1.PluginLoadingBoundary, { fallback: loadingFallback, children: children }) }));
|
|
13
|
-
}
|
|
14
|
-
exports.PluginBoundary = PluginBoundary;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2021 The Perses Authors
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.PluginLoader = void 0;
|
|
16
|
-
const react_query_1 = require("react-query");
|
|
17
|
-
const legacy_1 = require("../PluginRegistry/legacy");
|
|
18
|
-
/**
|
|
19
|
-
* Uses the PluginRegistry to load the specified plugin and throws any errors
|
|
20
|
-
* encountered while loading.
|
|
21
|
-
*/
|
|
22
|
-
function PluginLoader(props) {
|
|
23
|
-
const { pluginType, kind } = props;
|
|
24
|
-
// Load the plugin and throw any loading/not found errors
|
|
25
|
-
const { loadPlugin } = (0, legacy_1.usePluginRegistry)();
|
|
26
|
-
const { error } = (0, react_query_1.useQuery)(`PluginLoader:${pluginType}_${kind}`, () => {
|
|
27
|
-
// The enabled option below should prevent this from being run until loadPlugin is available, but check here to
|
|
28
|
-
// make Typescript happy
|
|
29
|
-
if (loadPlugin === undefined) {
|
|
30
|
-
throw new Error('PluginRegistry loadPlugin not available');
|
|
31
|
-
}
|
|
32
|
-
return loadPlugin(pluginType, kind);
|
|
33
|
-
}, { enabled: loadPlugin !== undefined });
|
|
34
|
-
if (error !== undefined && error !== null) {
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
exports.PluginLoader = PluginLoader;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePlugin = exports.usePluginLoadingBoundary = exports.PluginLoadingBoundary = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const use_immer_1 = require("use-immer");
|
|
7
|
-
const model_1 = require("../../model");
|
|
8
|
-
const legacy_1 = require("../PluginRegistry/legacy");
|
|
9
|
-
const PluginLoader_1 = require("./PluginLoader");
|
|
10
|
-
/**
|
|
11
|
-
* Plugin dependencies are registered here by children. This takes care of loading
|
|
12
|
-
* those dependencies on demand and acts similar to React's Suspense in that it
|
|
13
|
-
* will show a loading fallback while those plugins are being loaded.
|
|
14
|
-
*/
|
|
15
|
-
function PluginLoadingBoundary(props) {
|
|
16
|
-
const { fallback, children } = props;
|
|
17
|
-
const { plugins } = (0, legacy_1.usePluginRegistry)();
|
|
18
|
-
// Keep track of all plugin dependencies registered by child components
|
|
19
|
-
const [dependencies, setDependencies] = (0, use_immer_1.useImmer)(() => {
|
|
20
|
-
const deps = {};
|
|
21
|
-
for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
|
|
22
|
-
deps[pluginType] = {};
|
|
23
|
-
}
|
|
24
|
-
return deps;
|
|
25
|
-
});
|
|
26
|
-
// When children are rendered, they can register a dependency here to tell us
|
|
27
|
-
// what plugins they need so we can load them if necessary
|
|
28
|
-
const registerPluginDependency = (0, react_1.useCallback)((pluginType, kind) => {
|
|
29
|
-
setDependencies((draft) => {
|
|
30
|
-
draft[pluginType][kind] = true;
|
|
31
|
-
});
|
|
32
|
-
}, [setDependencies]);
|
|
33
|
-
const context = (0, react_1.useMemo)(() => ({ registerPluginDependency }), [registerPluginDependency]);
|
|
34
|
-
const { loaders, fragmentKey } = (0, react_1.useMemo)(() => {
|
|
35
|
-
let fragmentKey = '';
|
|
36
|
-
const loaders = [];
|
|
37
|
-
for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
|
|
38
|
-
// Build an overall key for the dependencies by combining pluginType and
|
|
39
|
-
// kind of all dependencies
|
|
40
|
-
fragmentKey += `_${pluginType}:`;
|
|
41
|
-
const kinds = dependencies[pluginType];
|
|
42
|
-
for (const kind in kinds) {
|
|
43
|
-
fragmentKey += kind;
|
|
44
|
-
// Is this plugin already loaded?
|
|
45
|
-
const plugin = plugins[pluginType][kind];
|
|
46
|
-
if (plugin !== undefined)
|
|
47
|
-
continue;
|
|
48
|
-
// Nope, add it to the loaders list
|
|
49
|
-
loaders.push((0, jsx_runtime_1.jsx)(PluginLoader_1.PluginLoader, { pluginType: pluginType, kind: kind }, `${pluginType}:${kind}`));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return { loaders, fragmentKey };
|
|
53
|
-
}, [plugins, dependencies]);
|
|
54
|
-
// All dependencies are loaded once we don't have any loaders to render
|
|
55
|
-
const isLoaded = loaders.length === 0;
|
|
56
|
-
return ((0, jsx_runtime_1.jsxs)(PluginLoadingBoundaryContext.Provider, { value: context, children: [loaders, isLoaded && (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: children }, fragmentKey), isLoaded === false && fallback] }));
|
|
57
|
-
}
|
|
58
|
-
exports.PluginLoadingBoundary = PluginLoadingBoundary;
|
|
59
|
-
const PluginLoadingBoundaryContext = (0, react_1.createContext)(undefined);
|
|
60
|
-
/**
|
|
61
|
-
* Gets the PluginLoadingBoundary context and throws if the Provider is missing.
|
|
62
|
-
*/
|
|
63
|
-
function usePluginLoadingBoundary() {
|
|
64
|
-
const ctx = (0, react_1.useContext)(PluginLoadingBoundaryContext);
|
|
65
|
-
if (ctx === undefined) {
|
|
66
|
-
throw new Error(`PluginLoadingBoundary context not found. Did you forget a Provider?`);
|
|
67
|
-
}
|
|
68
|
-
return ctx;
|
|
69
|
-
}
|
|
70
|
-
exports.usePluginLoadingBoundary = usePluginLoadingBoundary;
|
|
71
|
-
/**
|
|
72
|
-
* Generic usePlugin that will register the dependency with the nearest LoadingBoundary and get the plugin if it's
|
|
73
|
-
* already loaded
|
|
74
|
-
*/
|
|
75
|
-
function usePlugin(pluginType, kind) {
|
|
76
|
-
// Tell the loading boundary about the dependency
|
|
77
|
-
const { registerPluginDependency } = usePluginLoadingBoundary();
|
|
78
|
-
(0, react_1.useEffect)(() => {
|
|
79
|
-
registerPluginDependency(pluginType, kind);
|
|
80
|
-
}, [pluginType, kind, registerPluginDependency]);
|
|
81
|
-
// Get the plugin, which could be undefined if it hasn't loaded yet
|
|
82
|
-
const { plugins } = (0, legacy_1.usePluginRegistry)();
|
|
83
|
-
return plugins[pluginType][kind];
|
|
84
|
-
}
|
|
85
|
-
exports.usePlugin = usePlugin;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2021 The Perses Authors
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
-
}
|
|
20
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
-
}) : (function(o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
}));
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
__exportStar(require("./PluginLoadingBoundary"), exports);
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePluginRegistry = exports.PluginRegistry = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
// Copyright 2021 The Perses Authors
|
|
6
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
// you may not use this file except in compliance with the License.
|
|
8
|
-
// You may obtain a copy of the License at
|
|
9
|
-
//
|
|
10
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
//
|
|
12
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
// See the License for the specific language governing permissions and
|
|
16
|
-
// limitations under the License.
|
|
17
|
-
const react_1 = require("react");
|
|
18
|
-
const react_query_1 = require("react-query");
|
|
19
|
-
const registry_state_1 = require("./registry-state");
|
|
20
|
-
/**
|
|
21
|
-
* PluginRegistryContext provider that keeps track of all available plugins and
|
|
22
|
-
* their implementations once they've been loaded.
|
|
23
|
-
*/
|
|
24
|
-
function PluginRegistry(props) {
|
|
25
|
-
const { children, getInstalledPlugins, importPluginModule } = props;
|
|
26
|
-
const installedPlugins = (0, react_query_1.useQuery)('installed-plugins', getInstalledPlugins);
|
|
27
|
-
const { loadablePlugins, plugins, register } = (0, registry_state_1.useRegistryState)(installedPlugins.data);
|
|
28
|
-
const loadPlugin = (0, react_1.useCallback)(async (pluginType, kind) => {
|
|
29
|
-
// Is it already loaded?
|
|
30
|
-
const plugin = plugins[pluginType][kind];
|
|
31
|
-
if (plugin !== undefined)
|
|
32
|
-
return;
|
|
33
|
-
// Is it a valid plugin we know about?
|
|
34
|
-
const resource = loadablePlugins[pluginType][kind];
|
|
35
|
-
if (resource === undefined) {
|
|
36
|
-
throw new Error(`No ${pluginType} plugin is available for kind ${kind}`);
|
|
37
|
-
}
|
|
38
|
-
// Load and register the resource
|
|
39
|
-
const pluginModule = await importPluginModule(resource);
|
|
40
|
-
register(resource, pluginModule);
|
|
41
|
-
}, [plugins, loadablePlugins, importPluginModule, register]);
|
|
42
|
-
const registry = (0, react_1.useMemo)(() => ({ plugins, loadPlugin: installedPlugins.isLoading ? undefined : loadPlugin }), [installedPlugins.isLoading, plugins, loadPlugin]);
|
|
43
|
-
return (0, jsx_runtime_1.jsx)(PluginRegistryContext.Provider, { value: registry, children: children });
|
|
44
|
-
}
|
|
45
|
-
exports.PluginRegistry = PluginRegistry;
|
|
46
|
-
const PluginRegistryContext = (0, react_1.createContext)(undefined);
|
|
47
|
-
/**
|
|
48
|
-
* Gets the PluginRegistryContext, throwing if the provider is missing.
|
|
49
|
-
*/
|
|
50
|
-
function usePluginRegistry() {
|
|
51
|
-
const ctx = (0, react_1.useContext)(PluginRegistryContext);
|
|
52
|
-
if (ctx === undefined) {
|
|
53
|
-
throw new Error('No PluginRegistry context found. Did you forget a Provider?');
|
|
54
|
-
}
|
|
55
|
-
return ctx;
|
|
56
|
-
}
|
|
57
|
-
exports.usePluginRegistry = usePluginRegistry;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2021 The Perses Authors
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
-
}
|
|
20
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
-
}) : (function(o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
}));
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
__exportStar(require("./PluginRegistry"), exports);
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2022 The Perses Authors
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.useRegistryState = void 0;
|
|
16
|
-
const react_1 = require("react");
|
|
17
|
-
const use_immer_1 = require("use-immer");
|
|
18
|
-
const model_1 = require("../../../model");
|
|
19
|
-
/**
|
|
20
|
-
* Hook for setting up plugin registry state. Returns the state, plus a function
|
|
21
|
-
* for registering plugins with that state.
|
|
22
|
-
*/
|
|
23
|
-
function useRegistryState(installedPlugins) {
|
|
24
|
-
// Go through all installed plugins and bundled plugins and build an index of
|
|
25
|
-
// those resources by type and kind
|
|
26
|
-
const loadablePlugins = (0, react_1.useMemo)(() => {
|
|
27
|
-
const loadableProps = {};
|
|
28
|
-
for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
|
|
29
|
-
loadableProps[pluginType] = {};
|
|
30
|
-
}
|
|
31
|
-
// If no plugins installed or waiting on that data, nothing else to do
|
|
32
|
-
if (installedPlugins === undefined)
|
|
33
|
-
return loadableProps;
|
|
34
|
-
for (const resource of installedPlugins) {
|
|
35
|
-
for (const plugin of resource.spec.plugins) {
|
|
36
|
-
const { pluginType, kind } = plugin;
|
|
37
|
-
const map = loadableProps[pluginType];
|
|
38
|
-
if (map[kind] !== undefined) {
|
|
39
|
-
console.warn(`Got multiple ${pluginType} plugin definitions for kind ${kind}`);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
map[kind] = resource;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return loadableProps;
|
|
46
|
-
}, [installedPlugins]);
|
|
47
|
-
const [plugins, setPlugins] = (0, use_immer_1.useImmer)(() => {
|
|
48
|
-
const loadedPlugins = {};
|
|
49
|
-
for (const pluginType of model_1.ALL_PLUGIN_TYPES) {
|
|
50
|
-
loadedPlugins[pluginType] = {};
|
|
51
|
-
}
|
|
52
|
-
return loadedPlugins;
|
|
53
|
-
});
|
|
54
|
-
const registeredModules = (0, react_1.useRef)(new Set());
|
|
55
|
-
const register = (0, react_1.useCallback)((resource, pluginModule) => {
|
|
56
|
-
// De-dupe register calls in case multiple plugin loading boundaries
|
|
57
|
-
// are waiting for the same module in parallel
|
|
58
|
-
if (registeredModules.current.has(pluginModule)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
// Treat plugin module as JS module with named exports that are each a Plugin
|
|
62
|
-
const plugins = pluginModule;
|
|
63
|
-
setPlugins((draft) => {
|
|
64
|
-
// Look for all the plugins specified in the metadata
|
|
65
|
-
for (const pluginMetadata of resource.spec.plugins) {
|
|
66
|
-
// Assume that plugins will be exported under the same named export as the kind they handle
|
|
67
|
-
// TODO: Do we need to allow for different named exports and an option in the metadata to tell us the name?
|
|
68
|
-
const { pluginType, kind } = pluginMetadata;
|
|
69
|
-
const plugin = plugins[kind];
|
|
70
|
-
if (plugin === undefined) {
|
|
71
|
-
// TODO: How to handle missing plugins?
|
|
72
|
-
console.warn(`Could not find ${pluginType} plugin for kind '${kind}' in ${resource.metadata.name}`);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
// Add to registry state
|
|
76
|
-
switch (pluginType) {
|
|
77
|
-
case 'Variable':
|
|
78
|
-
draft.Variable[kind] = plugin;
|
|
79
|
-
break;
|
|
80
|
-
case 'Panel':
|
|
81
|
-
draft.Panel[kind] = plugin;
|
|
82
|
-
break;
|
|
83
|
-
case 'GraphQuery':
|
|
84
|
-
draft.GraphQuery[kind] = plugin;
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
const exhaustive = pluginType;
|
|
88
|
-
throw new Error(`Unhandled plugin config: ${exhaustive}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
// Remember this module has been registered
|
|
93
|
-
registeredModules.current.add(pluginModule);
|
|
94
|
-
}, [setPlugins]);
|
|
95
|
-
return { loadablePlugins, plugins, register };
|
|
96
|
-
}
|
|
97
|
-
exports.useRegistryState = useRegistryState;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"kind": "PluginModule",
|
|
3
|
-
"metadata": { "name": "Bert" },
|
|
4
|
-
"spec": {
|
|
5
|
-
"plugins": [
|
|
6
|
-
{
|
|
7
|
-
"pluginType": "Panel",
|
|
8
|
-
"kind": "BertPanel1",
|
|
9
|
-
"display": {
|
|
10
|
-
"name": "Bert Panel 1",
|
|
11
|
-
"description": ""
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"pluginType": "Panel",
|
|
16
|
-
"kind": "BertPanel2",
|
|
17
|
-
"display": {
|
|
18
|
-
"name": "Bert Panel 2",
|
|
19
|
-
"description": ""
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"pluginType": "Variable",
|
|
24
|
-
"kind": "BertVariable",
|
|
25
|
-
"display": {
|
|
26
|
-
"name": "Bert Variable",
|
|
27
|
-
"description": ""
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"kind": "PluginModule",
|
|
3
|
-
"metadata": { "name": "Ernie" },
|
|
4
|
-
"spec": {
|
|
5
|
-
"plugins": [
|
|
6
|
-
{
|
|
7
|
-
"pluginType": "Variable",
|
|
8
|
-
"kind": "ErnieVariable",
|
|
9
|
-
"display": {
|
|
10
|
-
"name": "Ernie Variable",
|
|
11
|
-
"description": "A variable plugin that exists in the plugin module"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"pluginType": "Variable",
|
|
16
|
-
"kind": "MissingErnieVariable",
|
|
17
|
-
"display": {
|
|
18
|
-
"name": "Ernie Variable",
|
|
19
|
-
"description": "A variable plugin that exists here in the metadata, but is not in the plugin module"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2021 The Perses Authors
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.useGraphQuery = void 0;
|
|
16
|
-
const PluginLoadingBoundary_1 = require("../components/PluginLoadingBoundary");
|
|
17
|
-
/**
|
|
18
|
-
* Use a Graph Query's results from a graph query plugin at runtime.
|
|
19
|
-
*/
|
|
20
|
-
const useGraphQuery = (definition) => {
|
|
21
|
-
const plugin = (0, PluginLoadingBoundary_1.usePlugin)('GraphQuery', definition.kind);
|
|
22
|
-
if (plugin === undefined) {
|
|
23
|
-
// Provide default values while the plugin is being loaded
|
|
24
|
-
return { loading: true };
|
|
25
|
-
}
|
|
26
|
-
return plugin.useGraphQuery(definition);
|
|
27
|
-
};
|
|
28
|
-
exports.useGraphQuery = useGraphQuery;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { ErrorBoundaryProps } from '@perses-dev/components';
|
|
3
|
-
import { PluginLoadingBoundaryProps } from './PluginLoadingBoundary';
|
|
4
|
-
export interface PluginBoundaryProps {
|
|
5
|
-
loadingFallback: PluginLoadingBoundaryProps['fallback'];
|
|
6
|
-
ErrorFallbackComponent: Required<ErrorBoundaryProps>['FallbackComponent'];
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Combination ErrorBoundary and PluginLoadingBoundary.
|
|
11
|
-
*/
|
|
12
|
-
export declare function PluginBoundary(props: PluginBoundaryProps): JSX.Element;
|
|
13
|
-
//# sourceMappingURL=PluginBoundary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginBoundary.d.ts","sourceRoot":"","sources":["../../src/components/PluginBoundary.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAiB,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAyB,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE5F,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,0BAA0B,CAAC,UAAU,CAAC,CAAC;IACxD,sBAAsB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,mBAAmB,CAAC,CAAC;IAC1E,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eAQxD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{ErrorBoundary}from"@perses-dev/components";import{PluginLoadingBoundary}from"./PluginLoadingBoundary";export function PluginBoundary(r){const{ErrorFallbackComponent:n,loadingFallback:o,children:a}=r;return _jsx(ErrorBoundary,{FallbackComponent:n,children:_jsx(PluginLoadingBoundary,{fallback:o,children:a})})}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PluginType } from '../../model';
|
|
2
|
-
export interface PluginLoaderProps {
|
|
3
|
-
pluginType: PluginType;
|
|
4
|
-
kind: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Uses the PluginRegistry to load the specified plugin and throws any errors
|
|
8
|
-
* encountered while loading.
|
|
9
|
-
*/
|
|
10
|
-
export declare function PluginLoader(props: PluginLoaderProps): null;
|
|
11
|
-
//# sourceMappingURL=PluginLoader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import{useQuery}from"react-query";import{usePluginRegistry}from"../PluginRegistry/legacy";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,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { JsonObject } from '@perses-dev/core';
|
|
3
|
-
import { PluginType, PluginImplementation } from '../../model';
|
|
4
|
-
export interface PluginLoadingBoundaryProps {
|
|
5
|
-
fallback: React.ReactNode;
|
|
6
|
-
children?: React.ReactNode;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Plugin dependencies are registered here by children. This takes care of loading
|
|
10
|
-
* those dependencies on demand and acts similar to React's Suspense in that it
|
|
11
|
-
* will show a loading fallback while those plugins are being loaded.
|
|
12
|
-
*/
|
|
13
|
-
export declare function PluginLoadingBoundary(props: PluginLoadingBoundaryProps): JSX.Element;
|
|
14
|
-
interface PluginLoadingBoundaryContextType {
|
|
15
|
-
registerPluginDependency: (pluginType: PluginType, kind: string) => void;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Gets the PluginLoadingBoundary context and throws if the Provider is missing.
|
|
19
|
-
*/
|
|
20
|
-
export declare function usePluginLoadingBoundary(): PluginLoadingBoundaryContextType;
|
|
21
|
-
/**
|
|
22
|
-
* Generic usePlugin that will register the dependency with the nearest LoadingBoundary and get the plugin if it's
|
|
23
|
-
* already loaded
|
|
24
|
-
*/
|
|
25
|
-
export declare function usePlugin<Type extends PluginType>(pluginType: Type, kind: string): PluginImplementation<Type, JsonObject> | undefined;
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=PluginLoadingBoundary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginLoadingBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/PluginLoadingBoundary.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAoB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AASjF,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,eAgEtE;AAED,UAAU,gCAAgC;IACxC,wBAAwB,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1E;AAID;;GAEG;AACH,wBAAgB,wBAAwB,qCAMvC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,UAAU,EAC/C,UAAU,EAAE,IAAI,EAChB,IAAI,EAAE,MAAM,GACX,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,SAAS,CAUpD"}
|
|
@@ -1 +0,0 @@
|
|
|
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/legacy";import{PluginLoader}from"./PluginLoader";export function PluginLoadingBoundary(e){const{fallback:n,children:o}=e,{plugins:r}=usePluginRegistry(),[t,u]=useImmer((()=>{const e={};for(const n of ALL_PLUGIN_TYPES)e[n]={};return e})),i=useCallback(((e,n)=>{u((o=>{o[e][n]=!0}))}),[u]),s=useMemo((()=>({registerPluginDependency:i})),[i]),{loaders:g,fragmentKey:a}=useMemo((()=>{let e="";const n=[];for(const o of ALL_PLUGIN_TYPES){e+=`_${o}:`;const u=t[o];for(const t in u)e+=t,void 0===r[o][t]&&n.push(_jsx(PluginLoader,{pluginType:o,kind:t},`${o}:${t}`))}return{loaders:n,fragmentKey:e}}),[r,t]),l=0===g.length;return _jsxs(PluginLoadingBoundaryContext.Provider,{value:s,children:[g,l&&_jsx(Fragment,{children:o},a),!1===l&&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)}),[e,n,o]);const{plugins:r}=usePluginRegistry();return r[e][n]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PluginLoadingBoundary/index.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export*from"./PluginLoadingBoundary";
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { PluginModuleResource, PluginType } from '../../../model';
|
|
3
|
-
import { LoadedPluginsByTypeAndKind } from './registry-state';
|
|
4
|
-
export interface PluginRegistryProps {
|
|
5
|
-
children?: React.ReactNode;
|
|
6
|
-
getInstalledPlugins: () => Promise<PluginModuleResource[]>;
|
|
7
|
-
importPluginModule: (resource: PluginModuleResource) => Promise<unknown>;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* PluginRegistryContext provider that keeps track of all available plugins and
|
|
11
|
-
* their implementations once they've been loaded.
|
|
12
|
-
*/
|
|
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
|
-
*/
|
|
18
|
-
plugins: LoadedPluginsByTypeAndKind;
|
|
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>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Gets the PluginRegistryContext, throwing if the provider is missing.
|
|
27
|
-
*/
|
|
28
|
-
export declare function usePluginRegistry(): PluginRegistryContextType;
|
|
29
|
-
//# sourceMappingURL=PluginRegistry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../../src/components/PluginRegistry/legacy/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClE,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,oBAAoB,EAAE,CAAC,CAAC;IAC3D,kBAAkB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1E;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"}
|