Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into chore/story-block-system
Browse files Browse the repository at this point in the history
  • Loading branch information
KaWaite committed Aug 8, 2023
2 parents 24b52a2 + 17b2566 commit 2318a43
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function processUnsafeBuiltinBlocks(plugin?: UnsafeBuiltinPlugin[]) {

const unsafeBlocks: UnsafeBuiltinBlocks<Component> | undefined = plugin
.map(p =>
p.widgets.map(w => {
p.blocks?.map(w => {
return {
widgetId: `${p.id}/${w.extensionId}`,
...w,
Expand All @@ -23,11 +23,11 @@ function processUnsafeBuiltinBlocks(plugin?: UnsafeBuiltinPlugin[]) {
)
.reduce((a, b) => {
const newObject: { [key: string]: Component } = {};
b.forEach(w => {
b?.forEach(w => {
newObject[w.widgetId] = w.component;
});
return merge(a, newObject);
}, {});

return unsafeBlocks;
return unsafeBlocks || [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function processUnsafeBuiltinWidgets(plugin?: UnsafeBuiltinPlugin[]) {

const unsafeWidgets: UnsafeBuiltinWidgets<Component> | undefined = plugin
.map(p =>
p.widgets.map(w => {
p.widgets?.map(w => {
return {
widgetId: `${p.id}/${w.extensionId}`,
...w,
Expand All @@ -25,11 +25,11 @@ function processUnsafeBuiltinWidgets(plugin?: UnsafeBuiltinPlugin[]) {
)
.reduce((a, b) => {
const newObject: { [key: string]: Component } = {};
b.forEach(w => {
b?.forEach(w => {
newObject[w.widgetId] = w.component;
});
return merge(a, newObject);
}, {});

return unsafeWidgets;
return unsafeWidgets || [];
}
4 changes: 0 additions & 4 deletions web/src/beta/lib/unsafeBuiltinPlugins/.gitignore

This file was deleted.

34 changes: 0 additions & 34 deletions web/src/beta/lib/unsafeBuiltinPlugins/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions web/src/beta/lib/unsafeBuiltinPlugins/index.ts

This file was deleted.

7 changes: 5 additions & 2 deletions web/src/services/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type Config = {
documentationUrl?: string;
marketplaceUrl?: string;
extensionUrls?: string[];
unsafePluginUrls?: string[];
extensions?: Extensions;
unsafeBuiltinPlugins?: UnsafeBuiltinPlugin[];
};
Expand All @@ -60,7 +61,7 @@ declare global {
export default async function loadConfig() {
if (window.REEARTH_CONFIG) return;
window.REEARTH_CONFIG = defaultConfig;
const config = {
const config: Config = {
...defaultConfig,
...(await (await fetch("/reearth_config.json")).json()),
};
Expand All @@ -80,7 +81,9 @@ export default async function loadConfig() {
config.extensions = extensions;
}

config.unsafeBuiltinPlugins = await loadUnsafeBuiltinPlugins();
if (config.unsafePluginUrls) {
config.unsafeBuiltinPlugins = await loadUnsafeBuiltinPlugins(config.unsafePluginUrls);
}

window.REEARTH_CONFIG = config;
}
Expand Down
33 changes: 19 additions & 14 deletions web/src/services/config/unsafeBuiltinPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { FC } from "react";

export type UnsafeBuiltinPlugin = {
id: string;
name: string;
widgets: UnsafeBuiltinWidget[];
blocks: UnsafeBuiltinBlock[];
widgets?: UnsafeBuiltinWidget[];
blocks?: UnsafeBuiltinBlock[];
};

type UnsafeBuiltinWidget = UnsafeBuiltinPluginExtension<"widget">;
Expand All @@ -13,19 +15,22 @@ type UnsafeBuiltinPluginExtension<T extends "widget" | "block"> = {
type: T;
extensionId: string;
name: string;
component: React.FC;
component: FC;
};

export type UnsafeBuiltinWidgets<T = unknown> = Record<string, T>;

export async function loadUnsafeBuiltinPlugins() {
try {
const unsafeBuiltinPlugins = (
await import(/* @vite-ignore */ "src/beta/lib/unsafeBuiltinPlugins")
).default as UnsafeBuiltinPlugin[];
return unsafeBuiltinPlugins;
} catch (e) {
console.error("unsafe builtin plugin load failed", e);
}
return undefined;
}
export const loadUnsafeBuiltinPlugins = async (urls: string[]) => {
return (
await Promise.all(
urls.map(async url => {
try {
const plugin: UnsafeBuiltinPlugin = (await import(/* @vite-ignore */ url)).default;
return plugin;
} catch (e) {
throw new Error(`Specified unsafe built-in module could not find: ${url} ${e}`);
}
}),
)
).filter(Boolean);
};

0 comments on commit 2318a43

Please sign in to comment.