this repo has no description

Merge pull request #103 from moonlight-mod/notnite/moonbase-custom

moonbase: Make custom settings real

authored by Cynthia Foxwell and committed by GitHub 421ef5b6 13c46c9e

Changed files
+88 -2
packages
core-extensions
src
moonbase
types
+5 -1
packages/core-extensions/src/moonbase/index.tsx
··· 21 21 ] 22 22 }, 23 23 24 - moonbase: { 24 + settings: { 25 25 dependencies: [ 26 26 { ext: "spacepack", id: "spacepack" }, 27 27 { ext: "settings", id: "settings" }, ··· 42 42 } 43 43 ], 44 44 entrypoint: true 45 + }, 46 + 47 + moonbase: { 48 + dependencies: [{ ext: "moonbase", id: "stores" }] 45 49 } 46 50 }; 47 51
+10
packages/core-extensions/src/moonbase/webpackModules/moonbase.ts
··· 1 + import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores"; 2 + import type { Moonbase } from "@moonlight-mod/types/coreExtensions/moonbase"; 3 + 4 + export const moonbase: Moonbase = { 5 + registerConfigComponent(ext, option, component) { 6 + MoonbaseSettingsStore.registerConfigComponent(ext, option, component); 7 + } 8 + }; 9 + 10 + export default moonbase;
packages/core-extensions/src/moonbase/webpackModules/moonbase.tsx packages/core-extensions/src/moonbase/webpackModules/settings.tsx
+16
packages/core-extensions/src/moonbase/webpackModules/stores.ts
··· 13 13 checkExtensionCompat, 14 14 ExtensionCompat 15 15 } from "@moonlight-mod/core/extension/loader"; 16 + import { CustomComponent } from "@moonlight-mod/types/coreExtensions/moonbase"; 16 17 17 18 const logger = moonlight.getLogger("moonbase"); 18 19 ··· 23 24 private origConfig: Config; 24 25 private config: Config; 25 26 private extensionIndex: number; 27 + private configComponents: Record<string, Record<string, CustomComponent>> = 28 + {}; 26 29 27 30 modified: boolean; 28 31 submitting: boolean; ··· 387 390 tryGetExtensionName(id: string) { 388 391 const uniqueId = this.getExtensionUniqueId(id); 389 392 return (uniqueId != null ? this.getExtensionName(uniqueId) : null) ?? id; 393 + } 394 + 395 + registerConfigComponent( 396 + ext: string, 397 + name: string, 398 + component: CustomComponent 399 + ) { 400 + if (!(ext in this.configComponents)) this.configComponents[ext] = {}; 401 + this.configComponents[ext][name] = component; 402 + } 403 + 404 + getExtensionConfigComponent(ext: string, name: string) { 405 + return this.configComponents[ext]?.[name]; 390 406 } 391 407 392 408 writeConfig() {
+35 -1
packages/core-extensions/src/moonbase/webpackModules/ui/extensions/settings.tsx
··· 392 392 ); 393 393 } 394 394 395 + function Custom({ ext, name, setting, disabled }: SettingsProps) { 396 + const { value, displayName } = useConfigEntry<any>(ext.uniqueId, name); 397 + 398 + const { component: Component } = useStateFromStores( 399 + [MoonbaseSettingsStore], 400 + () => { 401 + return { 402 + component: MoonbaseSettingsStore.getExtensionConfigComponent( 403 + ext.id, 404 + name 405 + ) 406 + }; 407 + }, 408 + [ext.uniqueId, name] 409 + ); 410 + 411 + if (Component == null) { 412 + const { Text } = Components; 413 + return ( 414 + <Text variant="text/md/normal">{`Custom setting "${displayName}" is missing a component. Perhaps the extension is not installed?`}</Text> 415 + ); 416 + } 417 + 418 + return ( 419 + <Component 420 + value={value} 421 + setValue={(value) => 422 + MoonbaseSettingsStore.setExtensionConfig(ext.id, name, value) 423 + } 424 + /> 425 + ); 426 + } 427 + 395 428 function Setting({ ext, name, setting, disabled }: SettingsProps) { 396 429 const elements: Partial<Record<ExtensionSettingType, SettingsComponent>> = { 397 430 [ExtensionSettingType.Boolean]: Boolean, ··· 401 434 [ExtensionSettingType.Select]: Select, 402 435 [ExtensionSettingType.MultiSelect]: MultiSelect, 403 436 [ExtensionSettingType.List]: List, 404 - [ExtensionSettingType.Dictionary]: Dictionary 437 + [ExtensionSettingType.Dictionary]: Dictionary, 438 + [ExtensionSettingType.Custom]: Custom 405 439 }; 406 440 const element = elements[setting.type]; 407 441 if (element == null) return <></>;
+1
packages/types/src/coreExtensions.ts
··· 3 3 export * as Markdown from "./coreExtensions/markdown"; 4 4 export * as ContextMenu from "./coreExtensions/contextMenu"; 5 5 export * as Notices from "./coreExtensions/notices"; 6 + export * as Moonbase from "./coreExtensions/moonbase";
+12
packages/types/src/coreExtensions/moonbase.ts
··· 1 + export type CustomComponent = React.FC<{ 2 + value: any; 3 + setValue: (value: any) => void; 4 + }>; 5 + 6 + export type Moonbase = { 7 + registerConfigComponent: ( 8 + ext: string, 9 + option: string, 10 + component: CustomComponent 11 + ) => void; 12 + };
+3
packages/types/src/discord/require.ts
··· 3 3 import { Settings } from "../coreExtensions/settings"; 4 4 import { Spacepack } from "../coreExtensions/spacepack"; 5 5 import { Notices } from "../coreExtensions/notices"; 6 + import { Moonbase } from "../coreExtensions/moonbase"; 6 7 7 8 declare function WebpackRequire(id: string): any; 8 9 ··· 10 11 declare function WebpackRequire(id: "contextMenu_contextMenu"): ContextMenu; 11 12 12 13 declare function WebpackRequire(id: "markdown_markdown"): Markdown; 14 + 15 + declare function WebpackRequire(id: "moonbase_moonbase"): Moonbase; 13 16 14 17 declare function WebpackRequire(id: "notices_notices"): Notices; 15 18
+6
packages/types/src/import.d.ts
··· 17 17 export = Markdown; 18 18 } 19 19 20 + declare module "@moonlight-mod/wp/moonbase_moonbase" { 21 + import { CoreExtensions } from "@moonlight-mod/types"; 22 + const Moonbase: CoreExtensions.Moonbase.Moonbase; 23 + export = Moonbase; 24 + } 25 + 20 26 declare module "@moonlight-mod/wp/notices_notices" { 21 27 import { CoreExtensions } from "@moonlight-mod/types"; 22 28 const Notices: CoreExtensions.Notices.Notices;