sltsv
This commit is contained in:
parent
3e6309ae7c
commit
b2f4622701
File diff suppressed because one or more lines are too long
|
@ -92,9 +92,10 @@ export const settings = {
|
|||
"Disable BetterDiscord": {id: "bd-disable", info: "Disable Betterdiscord (plugins, themes, etc).", implemented: false, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
"Blur Personnal Informations":{id: "lightcord-6", info: "Blur sensitive informations like email, payment infos and more.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
"Calling Ring Beat": {id: "lightcord-2", info: "Enable Discord's special calling beat.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
"Developer Options": {id: "lightcord-1", info: "Enable Discord's Internal Developer Options. This allow the \"Experiments\" tab and the \"Developer Options\" tab. (must close and reopen settings)", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
"Developer Options": {id: "lightcord-1", info: "Enable Discord's Internal Developer Options. This allow the \"Experiments\" tab and the \"Developer Options\" tab. (must reopen settings)", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
"Ad Block": {id: "lightcord-4", info: "Block any BOT that dm you with an invite link. Even in an embed.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
"Enable Lightcord Servers": {id: "lightcord-5", info: "Enable Lightcord's servers. Disabling this will disable custom badges.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
"Disable typing": {id: "lightcord-7", info: "Don't let other see you're typing.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
|
||||
|
||||
/** Lightcord Window */
|
||||
"Always-on-Top": {id: "lightcord-3", info: "Enable window's Always-on-Top mode, where Lightcord stays on top of other applications.", implemented: true, hidden: false, cat: "lightcord", category: "Window"},
|
||||
|
@ -143,7 +144,8 @@ export const defaultCookie = {
|
|||
"lightcord-3": false,
|
||||
"lightcord-4": false,
|
||||
"lightcord-5": true,
|
||||
"lightcord-6": true
|
||||
"lightcord-6": true,
|
||||
"lightcord-7": false,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import webpackModules from "./webpackModules"
|
||||
|
||||
export default new class DisableTyping {
|
||||
constructor(){
|
||||
window.Lightcord.Api.ensureExported(e => e.default && e.default.startTyping)
|
||||
.then(typingModule => {
|
||||
console.log(typingModule, new Error("gay"))
|
||||
let self = this
|
||||
const startTyping = typingModule.default.startTyping
|
||||
typingModule.default.startTyping = function(){
|
||||
if(self.disabled)return startTyping.call(this, ...arguments)
|
||||
}
|
||||
const stopTyping = typingModule.default.stopTyping
|
||||
typingModule.default.stopTyping = function(){
|
||||
if(self.disabled)return stopTyping.call(this, ...arguments)
|
||||
}
|
||||
this.disabled = true
|
||||
})
|
||||
}
|
||||
|
||||
disable(){
|
||||
this.disabled = true
|
||||
}
|
||||
|
||||
enable(){
|
||||
this.disabled = false
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ import V2C_AccountInfos from "../ui/AccountInfos";
|
|||
import { remote } from "electron";
|
||||
import AntiAdDM from "./AntiAdDM";
|
||||
import blurPrivate from "./blurPrivate";
|
||||
import disableTyping from "./disableTyping";
|
||||
|
||||
export default new class V2_SettingsPanel {
|
||||
|
||||
|
@ -244,6 +245,13 @@ export default new class V2_SettingsPanel {
|
|||
blurPrivate.disable()
|
||||
}
|
||||
}
|
||||
if (id === "lightcord-7") {
|
||||
if(enabled){
|
||||
disableTyping.enable()
|
||||
}else{
|
||||
disableTyping.disable()
|
||||
}
|
||||
}
|
||||
|
||||
this.saveSettings();
|
||||
}
|
||||
|
@ -264,6 +272,7 @@ export default new class V2_SettingsPanel {
|
|||
if (settingsCookie["lightcord-3"]) remote.getCurrentWindow().setAlwaysOnTop(true)
|
||||
if (settingsCookie["lightcord-4"]) AntiAdDM.enable()
|
||||
if (settingsCookie["lightcord-6"]) blurPrivate.enable()
|
||||
if (settingsCookie["lightcord-7"]) disableTyping.enable()
|
||||
|
||||
if (settingsCookie["fork-ps-5"]) {
|
||||
ContentManager.watchContent("plugin");
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
|
||||
module.exports = class LightcordApiExemple {
|
||||
getName() {return "Lightcord Api Exemple";} // Name of your plugin to show on the plugins page
|
||||
getName() {return "LightcordApiExemple";} // Name of your plugin to show on the plugins page
|
||||
getDescription() {return "Describe the basic functions. Maybe a support server link.";} // Description to show on the plugins page
|
||||
getVersion() {return "0.0.1";} // Current version. I recommend following semantic versioning <http://semver.org/> (e.g. 0.0.1)
|
||||
getAuthor() {return "Not Thomiz";} // Your name
|
||||
|
@ -21,4 +21,19 @@ module.exports = class LightcordApiExemple {
|
|||
stop() {} // Called when the plugin is deactivated
|
||||
|
||||
observer(changes) {} // Observer for the `document`. Better documentation than I can provide is found here: <https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver>
|
||||
|
||||
getSettingsPanel(){
|
||||
let settings = [
|
||||
{
|
||||
component: "inputs.Button",
|
||||
props: {
|
||||
children: [
|
||||
"sltsv"
|
||||
],
|
||||
color: "red"
|
||||
}
|
||||
}
|
||||
]
|
||||
return windows.Lightcord.Api.Utils.PluginUtils.renderSettings(settings)
|
||||
}
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
// bait typescript into thinking this is not reactDOM so no circular dependency.
|
||||
export = window["Reac"+"tDOM"] as typeof import("react-dom")
|
|
@ -1,9 +1,11 @@
|
|||
import DiscordButton from "./Discord/Button"
|
||||
import Switch from "./Discord/Switch"
|
||||
import RadioGroup from "./Discord/RadioGroup"
|
||||
import TextArea from "./Discord/TextArea"
|
||||
import TextInput from "./Discord/TextInput"
|
||||
import Dropdown from "./Discord/Dropdown"
|
||||
import DiscordButton from "./inputs/Button"
|
||||
import Switch from "./inputs/Switch"
|
||||
import RadioGroup from "./inputs/RadioGroup"
|
||||
import TextArea from "./inputs/TextArea"
|
||||
import TextInput from "./inputs/TextInput"
|
||||
import Dropdown from "./inputs/Dropdown"
|
||||
import Title from "./general/Title"
|
||||
import SettingsTitle from "./general/SettingsTitle"
|
||||
|
||||
export default {
|
||||
inputs: {
|
||||
|
@ -14,5 +16,9 @@ export default {
|
|||
TextArea: TextArea,
|
||||
TextInput: TextInput,
|
||||
Dropdown: Dropdown
|
||||
},
|
||||
general: {
|
||||
Title: Title,
|
||||
SettingsTitle: SettingsTitle
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
import WebpackLoader from "../../modules/WebpackLoader"
|
||||
import Title from "./Title"
|
||||
import { ReactNode } from "react"
|
||||
import Utils from "../../modules/Utils"
|
||||
|
||||
type SettingsTitleProps = {
|
||||
children: ReactNode
|
||||
className?: string
|
||||
}
|
||||
|
||||
let TitleModules
|
||||
export default class SettingsTitle extends React.Component<SettingsTitleProps, SettingsTitleProps> {
|
||||
constructor(props: SettingsTitleProps){
|
||||
super(props)
|
||||
props = SettingsTitle.normalizeProps(props)
|
||||
this.state = Object.create(props)
|
||||
}
|
||||
|
||||
static normalizeProps(props: SettingsTitleProps):SettingsTitleProps{
|
||||
props = Object.create(props)
|
||||
if(!props || typeof props !== "object")props = {children: []}
|
||||
if(typeof props.className !== "string")delete props.className
|
||||
|
||||
let levels = [props]
|
||||
while(Utils.getNestedProps(props, levels.map(e => "__proto__").join("."))){
|
||||
levels.push(Utils.getNestedProps(props, levels.map(e => "__proto__").join(".")))
|
||||
}
|
||||
let finals = Object.assign({}, ...levels)
|
||||
|
||||
return finals
|
||||
}
|
||||
|
||||
get modules(){
|
||||
return TitleModules || (TitleModules = [
|
||||
WebpackLoader.find(e => typeof e.marginTop60 === "string")
|
||||
])
|
||||
}
|
||||
|
||||
render(){
|
||||
let [
|
||||
marginModule
|
||||
] = this.modules
|
||||
|
||||
let props = SettingsTitle.normalizeProps(this.state || this.props)
|
||||
if(!this.state){
|
||||
this.state = Object.create(props)
|
||||
}
|
||||
|
||||
let className = `${marginModule.marginTop60} ${marginModule.marginBottom20}`
|
||||
if(props.className)className =+ " "+props.className
|
||||
|
||||
return React.createElement(Title, {className}, props.children)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
import WebpackLoader from "../../modules/WebpackLoader"
|
||||
import { ReactNode } from "react"
|
||||
import uuid from "../../modules/uuid"
|
||||
import Utils from "../../modules/Utils"
|
||||
|
||||
type TitleProps = {
|
||||
children?: ReactNode,
|
||||
className?: string
|
||||
}
|
||||
|
||||
let TitleModules
|
||||
export default class Title extends React.Component<TitleProps, TitleProps> {
|
||||
constructor(props: TitleProps){
|
||||
super(props)
|
||||
props = Title.normalizeProps(props)
|
||||
this.state = Object.create(props)
|
||||
}
|
||||
|
||||
_key: string
|
||||
|
||||
get key(){
|
||||
return this._key || uuid()
|
||||
}
|
||||
|
||||
static normalizeProps(props: TitleProps):TitleProps{
|
||||
props = Object.create(props)
|
||||
if(!props || typeof props !== "object")props = {children: []}
|
||||
if(!props.children)props.children = []
|
||||
if(typeof props.className !== "string")props.className = ""
|
||||
|
||||
let levels = [props]
|
||||
while(Utils.getNestedProps(props, levels.map(e => "__proto__").join("."))){
|
||||
levels.push(Utils.getNestedProps(props, levels.map(e => "__proto__").join(".")))
|
||||
}
|
||||
let finals = Object.assign({}, ...levels)
|
||||
|
||||
return finals
|
||||
}
|
||||
|
||||
get modules(){
|
||||
return TitleModules || (TitleModules = [
|
||||
WebpackLoader.find(e => typeof e.colorStandard === "string"),
|
||||
WebpackLoader.find(e => typeof e.size32 === "string"),
|
||||
WebpackLoader.find(e => typeof e.h2 === "string")
|
||||
])
|
||||
}
|
||||
|
||||
render(){
|
||||
let [
|
||||
colorModule,
|
||||
sizeModule,
|
||||
titleModule
|
||||
] = this.modules
|
||||
|
||||
let props = Title.normalizeProps(this.state || this.props)
|
||||
if(!this.state){
|
||||
this.state = props
|
||||
}
|
||||
|
||||
let className = `${colorModule.colorStandard} ${sizeModule.size14} ${titleModule.h2} ${titleModule.defaultColor} ${titleModule.defaultMarginh2}`
|
||||
if(props.className)className += " "+props.className
|
||||
|
||||
return React.createElement("h2", {className, key: this.key}, props.children)
|
||||
}
|
||||
}
|
|
@ -47,6 +47,14 @@ export default class Button extends React.Component<{
|
|||
</button>
|
||||
</div>)
|
||||
}
|
||||
|
||||
static get AllPreviews(){
|
||||
return AllPreviews || (AllPreviews = [
|
||||
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export type ButtonColor = "brand" | "grey" | "red" | "green" | "yellow" | "primary" | "link" | "white" | "black" | "transparent"
|
|
@ -1,6 +1,7 @@
|
|||
import NOOP from "../../modules/noop"
|
||||
import WebpackLoader from "../../modules/WebpackLoader"
|
||||
import { ReactNode, CSSProperties } from "react"
|
||||
import Utils from "../../modules/Utils"
|
||||
|
||||
type DropdownProps = {
|
||||
className?: string,
|
||||
|
@ -43,13 +44,14 @@ type themeOverride = {
|
|||
let DropdownModules
|
||||
export default class Dropdown extends React.Component<DropdownProps, DropdownProps> {
|
||||
constructor(props:DropdownProps){
|
||||
props = Dropdown.normalizeProps(props)
|
||||
super(props)
|
||||
props = Dropdown.normalizeProps(props)
|
||||
this.state = props
|
||||
this.onChange = this.onChange.bind(this)
|
||||
}
|
||||
|
||||
static normalizeProps(props:DropdownProps):DropdownProps{
|
||||
props = Object.create(props)
|
||||
if(!props || typeof props !== "object")props = {}
|
||||
if(typeof props.className !== "string")delete props.className
|
||||
if(typeof props.darkThemeColorOverrides !== "object" || !props.darkThemeColorOverrides)delete props.darkThemeColorOverrides
|
||||
|
@ -69,7 +71,13 @@ export default class Dropdown extends React.Component<DropdownProps, DropdownPro
|
|||
if(typeof props.styleOverrides !== "object")delete props.styleOverrides
|
||||
if(typeof props.value !== "string")props.value = null
|
||||
|
||||
return props
|
||||
let levels = [props]
|
||||
while(Utils.getNestedProps(props, levels.map(e => "__proto__").join("."))){
|
||||
levels.push(Utils.getNestedProps(props, levels.map(e => "__proto__").join(".")))
|
||||
}
|
||||
let finals = Object.assign({}, ...levels)
|
||||
|
||||
return finals
|
||||
}
|
||||
|
||||
onChange(value){
|
|
@ -1,5 +1,6 @@
|
|||
import NOOP from "../../modules/noop"
|
||||
import WebpackLoader from "../../modules/WebpackLoader"
|
||||
import Utils from "../../modules/Utils"
|
||||
|
||||
|
||||
type RadioGroupProps = {
|
||||
|
@ -20,13 +21,14 @@ type RadioGroupProps = {
|
|||
let RadioGroupModule
|
||||
export default class RadioGroup extends React.Component<RadioGroupProps, RadioGroupProps> {
|
||||
constructor(props:RadioGroupProps){
|
||||
props = RadioGroup.normalizeProps(props)
|
||||
super(props)
|
||||
props = RadioGroup.normalizeProps(props)
|
||||
this.state = props
|
||||
this.onChange = this.onChange.bind(this)
|
||||
}
|
||||
|
||||
static normalizeProps(props:RadioGroupProps):RadioGroupProps{
|
||||
props = Object.create(props)
|
||||
if(!props || typeof props !== "object")props = {}
|
||||
let defaultOptions = false
|
||||
if(!props.options || !Array.isArray(props.options)){
|
||||
|
@ -51,7 +53,13 @@ export default class RadioGroup extends React.Component<RadioGroupProps, RadioGr
|
|||
if(typeof props.infoClassName !== "string")props.infoClassName = ""
|
||||
if(!props.onChange || typeof props.onChange !== "function")props.onChange = NOOP
|
||||
|
||||
return props
|
||||
let levels = [props]
|
||||
while(Utils.getNestedProps(props, levels.map(e => "__proto__").join("."))){
|
||||
levels.push(Utils.getNestedProps(props, levels.map(e => "__proto__").join(".")))
|
||||
}
|
||||
let finals = Object.assign({}, ...levels)
|
||||
|
||||
return finals
|
||||
}
|
||||
|
||||
onChange(ev){
|
|
@ -1,6 +1,7 @@
|
|||
import WebpackLoader from "../../modules/WebpackLoader"
|
||||
import uuid from "../../modules/uuid"
|
||||
import NOOP from "../../modules/noop"
|
||||
import Utils from "../../modules/Utils"
|
||||
|
||||
type SwitchProps = {
|
||||
id?: string,
|
||||
|
@ -17,14 +18,15 @@ type SwitchProps = {
|
|||
let SwitchModules
|
||||
export default class Switch extends React.Component<SwitchProps, {value: boolean}> {
|
||||
constructor(props:SwitchProps){
|
||||
props = Switch.normalizeProps(props)
|
||||
super(props)
|
||||
props = Switch.normalizeProps(props)
|
||||
|
||||
this.state = Object.create(props)
|
||||
this.onChange = this.onChange.bind(this)
|
||||
}
|
||||
|
||||
static normalizeProps(props:SwitchProps){
|
||||
props = Object.create(props)
|
||||
if(!props)props = {}
|
||||
if(!props.id || typeof props.id !== "string")props.id = null
|
||||
if(!props.onChange || typeof props.onChange !== "function")props.onChange = NOOP
|
||||
|
@ -36,7 +38,13 @@ export default class Switch extends React.Component<SwitchProps, {value: boolean
|
|||
if(!props.size || !["default", "mini"].includes(props.size.toLowerCase()))props.size = "default"
|
||||
if(!props.style || typeof props.style !== "object")props.style = {}
|
||||
|
||||
return props
|
||||
let levels = [props]
|
||||
while(Utils.getNestedProps(props, levels.map(e => "__proto__").join("."))){
|
||||
levels.push(Utils.getNestedProps(props, levels.map(e => "__proto__").join(".")))
|
||||
}
|
||||
let finals = Object.assign({}, ...levels)
|
||||
|
||||
return finals
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import WebpackLoader from "../../modules/WebpackLoader"
|
||||
import NOOP from "../../modules/noop"
|
||||
import Utils from "../../modules/Utils"
|
||||
|
||||
type TextAreaProps = {
|
||||
name?: string,
|
||||
|
@ -24,8 +25,8 @@ type TextAreaProps = {
|
|||
let TextAreaModules
|
||||
export default class TextArea extends React.Component<TextAreaProps, TextAreaProps> {
|
||||
constructor(props){
|
||||
props = TextArea.normalizeProps(props)
|
||||
super(props)
|
||||
props = TextArea.normalizeProps(props)
|
||||
this.state = Object.create(props)
|
||||
|
||||
this.onChange = this.onChange.bind(this)
|
||||
|
@ -35,6 +36,7 @@ export default class TextArea extends React.Component<TextAreaProps, TextAreaPro
|
|||
}
|
||||
|
||||
static normalizeProps(props:TextAreaProps):TextAreaProps {
|
||||
props = Object.create(props)
|
||||
if(!props)props = {}
|
||||
if(!props.name || typeof props.name !== "string")props.name = ""
|
||||
if(!props.disabled || typeof props.disabled !== "boolean")props.disabled = false
|
||||
|
@ -54,7 +56,13 @@ export default class TextArea extends React.Component<TextAreaProps, TextAreaPro
|
|||
if(typeof props.onBlur !== "function")props.onBlur = NOOP
|
||||
if(typeof props.onKeyDown !== "function")props.onKeyDown = NOOP
|
||||
|
||||
return props
|
||||
let levels = [props]
|
||||
while(Utils.getNestedProps(props, levels.map(e => "__proto__").join("."))){
|
||||
levels.push(Utils.getNestedProps(props, levels.map(e => "__proto__").join(".")))
|
||||
}
|
||||
let finals = Object.assign({}, ...levels)
|
||||
|
||||
return finals
|
||||
}
|
||||
|
||||
get modules(){
|
||||
|
@ -91,6 +99,7 @@ export default class TextArea extends React.Component<TextAreaProps, TextAreaPro
|
|||
if(!this.state){
|
||||
this.state = Object.create(props)
|
||||
}
|
||||
|
||||
return <TextAreaComponent {...props} onChange={this.onChange} onFocus={this.onFocus} onBlur={this.onBlur} onKeyDown={this.onKeyDown}/>
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import WebpackLoader from "../../modules/WebpackLoader"
|
||||
import NOOP from "../../modules/noop"
|
||||
import Utils from "../../modules/Utils"
|
||||
|
||||
type TextInputProps = {
|
||||
name?: string,
|
||||
|
@ -20,17 +21,20 @@ type TextInputProps = {
|
|||
let TextInputModules
|
||||
export default class TextInput extends React.PureComponent<TextInputProps, TextInputProps> {
|
||||
hasSet: boolean
|
||||
constructor(props){
|
||||
props = TextInput.normalizeProps(props)
|
||||
constructor(props: TextInputProps){
|
||||
super(props)
|
||||
props = TextInput.normalizeProps(props)
|
||||
this.state = props
|
||||
|
||||
console.log(this.state)
|
||||
|
||||
this.onChange = this.onChange.bind(this)
|
||||
this.onFocus = this.onFocus.bind(this)
|
||||
this.onBlur = this.onBlur.bind(this)
|
||||
}
|
||||
|
||||
static normalizeProps(props:TextInputProps):TextInputProps {
|
||||
props = Object.create(props)
|
||||
if(!props)props = {}
|
||||
if(!props.name || typeof props.name !== "string")props.name = ""
|
||||
if(!props.size || !["default", "mini"].includes(props.size))props.size = "default"
|
||||
|
@ -46,7 +50,13 @@ export default class TextInput extends React.PureComponent<TextInputProps, TextI
|
|||
if(typeof props.onFocus !== "function")props.onFocus = NOOP
|
||||
if(typeof props.onBlur !== "function")props.onBlur = NOOP
|
||||
|
||||
return props
|
||||
let levels = [props]
|
||||
while(Utils.getNestedProps(props, levels.map(e => "__proto__").join("."))){
|
||||
levels.push(Utils.getNestedProps(props, levels.map(e => "__proto__").join(".")))
|
||||
}
|
||||
let finals = Object.assign({}, ...levels)
|
||||
|
||||
return finals
|
||||
}
|
||||
|
||||
get modules(){
|
||||
|
@ -80,8 +90,9 @@ export default class TextInput extends React.PureComponent<TextInputProps, TextI
|
|||
|
||||
let props = TextInput.normalizeProps(this.state || this.props)
|
||||
if(!this.state){
|
||||
this.state = Object.create(props)
|
||||
this.state = props
|
||||
}
|
||||
console.log(props)
|
||||
return <TextAreaComponent {...props} onChange={this.onChange} onFocus={this.onFocus} onBlur={this.onBlur}/>
|
||||
}
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
import WebpackLoader from "./modules/WebpackLoader"
|
||||
import Components from "./components/components"
|
||||
import uuid from "./modules/uuid"
|
||||
import PluginUtilities from "./modules/PluginUtilities"
|
||||
import Utils from "./modules/Utils"
|
||||
|
||||
const LightcordApi = {
|
||||
WebpackLoader: WebpackLoader,
|
||||
Components: Components,
|
||||
uuid: uuid
|
||||
uuid: uuid,
|
||||
Utils: Utils
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
import components from "../components/components"
|
||||
import Utils from "./Utils"
|
||||
import { ComponentProps } from "react"
|
||||
import uuid from "./uuid"
|
||||
import TextInput from "../components/inputs/TextInput"
|
||||
|
||||
export default new class PluginUtilities {
|
||||
constructor(){}
|
||||
|
||||
renderSettings(settings:SettingItem[]){
|
||||
let items = this.renderSettingsToReact(settings)
|
||||
let elem = React.createElement("div", {key: uuid()}, items)
|
||||
return Utils.ReactToHTMLElement(elem)
|
||||
}
|
||||
|
||||
renderSettingsToReact(settings:SettingItem[]){
|
||||
let items = []
|
||||
settings.forEach(item => {
|
||||
console.log(item)
|
||||
if(typeof item !== "object")return items.push(item)
|
||||
if(item.props && "children" in item.props){
|
||||
if(!Array.isArray(item.props.children))item.props.children = [item.props.children]
|
||||
item.props.children = this.renderSettingsToReact(item.props.children)
|
||||
}
|
||||
if(!item.props)item.props = {}
|
||||
item.props.key = uuid()
|
||||
let component = Utils.getNestedProps(components, item.component)
|
||||
if(!component){
|
||||
let warning = new TextInput({
|
||||
value: `Warning: No component was found for: "${item.component}". Please correct your code.`,
|
||||
disabled: true,
|
||||
error: `Warning: No component was found for: "${item.component}". Please correct your code.`
|
||||
}).render()
|
||||
items.push(warning)
|
||||
return
|
||||
}
|
||||
items.push(React.createElement(component, Object.create(item.props)))
|
||||
})
|
||||
return items
|
||||
}
|
||||
}
|
||||
|
||||
type SettingItem = {
|
||||
component: string,
|
||||
props: ComponentProps<any>
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { ReactElement } from "react";
|
||||
import ReactDOM = require("react-dom")
|
||||
import PluginUtilities from "./PluginUtilities";
|
||||
|
||||
export default new class Utils {
|
||||
constructor(){}
|
||||
|
||||
ReactToHTMLElement(ReactElement: ReactElement){
|
||||
const element = document.createElement("div")
|
||||
ReactDOM.render(ReactElement, element)
|
||||
return element
|
||||
}
|
||||
|
||||
get PluginUtils(){return PluginUtilities}
|
||||
|
||||
getNestedProps(obj:any, path: string){
|
||||
let segments = path.split(".")
|
||||
for(let seg of segments){
|
||||
obj = obj && (seg in obj) ? obj[seg] : undefined
|
||||
}
|
||||
return obj
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue