-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): unsafe plugin support (#576)
Co-authored-by: YK <[email protected]>
- Loading branch information
1 parent
1410264
commit 1ebef7e
Showing
64 changed files
with
263 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
web/src/beta/lib/core/Crust/Infobox/Block/builtin/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { merge } from "lodash-es"; | ||
|
||
import type { Component } from ".."; | ||
|
||
import DataList from "./DataList"; | ||
import HTML from "./HTML"; | ||
import Image from "./Image"; | ||
import Location from "./Location"; | ||
import Text from "./Text"; | ||
import { unsafeBuiltinBlocks, type UnsafeBuiltinBlocks } from "./unsafeBlocks"; | ||
import Video from "./Video"; | ||
|
||
export const DATALIST_BUILTIN_BLOCK_ID = "reearth/dlblock"; | ||
export const IMAGE_BUILTIN_BLOCK_ID = "reearth/imageblock"; | ||
export const LOCATION_BUILTIN_BLOCK_ID = "reearth/locationblock"; | ||
export const TEXT_BUILTIN_BLOCK_ID = "reearth/textblock"; | ||
export const VIDEO_BUILTIN_BLOCK_ID = "reearth/videoblock"; | ||
export const HTML_BUILTIN_BLOCK_ID = "reearth/htmlblock"; | ||
|
||
export type ReEarthBuiltinBlocks<T = unknown> = Record< | ||
| typeof DATALIST_BUILTIN_BLOCK_ID | ||
| typeof IMAGE_BUILTIN_BLOCK_ID | ||
| typeof LOCATION_BUILTIN_BLOCK_ID | ||
| typeof TEXT_BUILTIN_BLOCK_ID | ||
| typeof VIDEO_BUILTIN_BLOCK_ID | ||
| typeof HTML_BUILTIN_BLOCK_ID, | ||
T | ||
>; | ||
|
||
export type BuiltinBlocks<T = unknown> = ReEarthBuiltinBlocks<T> & UnsafeBuiltinBlocks<T>; | ||
|
||
const reearthBuiltin: BuiltinBlocks<Component> = { | ||
[DATALIST_BUILTIN_BLOCK_ID]: DataList, | ||
[IMAGE_BUILTIN_BLOCK_ID]: Image, | ||
[LOCATION_BUILTIN_BLOCK_ID]: Location, | ||
[TEXT_BUILTIN_BLOCK_ID]: Text, | ||
[VIDEO_BUILTIN_BLOCK_ID]: Video, | ||
[HTML_BUILTIN_BLOCK_ID]: HTML, | ||
}; | ||
|
||
const builtin = merge({}, reearthBuiltin, unsafeBuiltinBlocks); | ||
|
||
export const isBuiltinBlock = (id: string): id is keyof BuiltinBlocks => { | ||
return !!builtin[id as keyof BuiltinBlocks]; | ||
}; | ||
|
||
export default builtin; |
35 changes: 35 additions & 0 deletions
35
web/src/beta/lib/core/Crust/Infobox/Block/builtin/unsafeBlocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { merge } from "lodash-es"; | ||
|
||
import { Component } from ".."; | ||
import { UnsafeBuiltinPlugin } from "../../../types"; | ||
|
||
export type UnsafeBuiltinBlocks<T = unknown> = Record<string, T>; | ||
|
||
const unsafeBuiltinPlugins = ( | ||
await import(/* @vite-ignore */ "@reearth/beta/lib/unsafeBuiltinPlugins") | ||
).default; | ||
|
||
export const unsafeBuiltinBlocks = processUnsafeBuiltinBlocks(unsafeBuiltinPlugins); | ||
|
||
function processUnsafeBuiltinBlocks(plugin?: UnsafeBuiltinPlugin[]) { | ||
if (!plugin) return; | ||
|
||
const unsafeBlocks: UnsafeBuiltinBlocks<Component> | undefined = plugin | ||
.map(p => | ||
p.widgets.map(w => { | ||
return { | ||
widgetId: `${p.id}/${w.extensionId}`, | ||
...w, | ||
}; | ||
}), | ||
) | ||
.reduce((a, b) => { | ||
const newObject: { [key: string]: Component } = {}; | ||
b.forEach(w => { | ||
newObject[w.widgetId] = w.component; | ||
}); | ||
return merge(a, newObject); | ||
}, {}); | ||
|
||
return unsafeBlocks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...t/Widgets/Widget/Button/index.stories.tsx → ...s/Widget/builtin/Button/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dgets/Widget/LegacyMenu/index.stories.tsx → ...dget/builtin/LegacyMenu/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...e/Crust/Widgets/Widget/Navigator/hooks.ts → ...Widgets/Widget/builtin/Navigator/hooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...idgets/Widget/Navigator/index.stories.tsx → ...idget/builtin/Navigator/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../Crust/Widgets/Widget/Navigator/index.tsx → ...idgets/Widget/builtin/Navigator/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ets/Widget/SplashScreen/index.stories.tsx → ...et/builtin/SplashScreen/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.