move arround classes to removed deps on settings

This commit is contained in:
MathMan05 2024-08-22 13:14:19 -05:00
parent 274c165357
commit 39f7a3701a
11 changed files with 320 additions and 288 deletions

View file

@ -4,8 +4,8 @@ import { Voice } from "./audio.js";
import { Contextmenu } from "./contextmenu.js";
import { Dialog } from "./dialog.js";
import { Permissions } from "./permissions.js";
import { Settings, RoleList } from "./settings.js";
import { Role } from "./role.js";
import { Settings } from "./settings.js";
import { Role, RoleList } from "./role.js";
import { InfiniteScroller } from "./infiniteScroller.js";
import { SnowFlake } from "./snowflake.js";
import { MarkDown } from "./markdown.js";

View file

@ -39,10 +39,7 @@ class Contextmenu {
intext.classList.add("contextbutton");
intext.textContent = thing[0];
console.log(thing);
if (thing[5] === "button") {
intext.onclick = thing[1].bind(addinfo, other);
}
else if (thing[5] === "submenu") {
if (thing[5] === "button" || thing[5] === "submenu") {
intext.onclick = thing[1].bind(addinfo, other);
}
div.appendChild(intext);

View file

@ -1,9 +1,9 @@
import { Channel } from "./channel.js";
import { Contextmenu } from "./contextmenu.js";
import { Role } from "./role.js";
import { Role, RoleList } from "./role.js";
import { Dialog } from "./dialog.js";
import { Member } from "./member.js";
import { Settings, RoleList } from "./settings.js";
import { Settings } from "./settings.js";
import { SnowFlake } from "./snowflake.js";
import { User } from "./user.js";
class Guild {

View file

@ -43,3 +43,121 @@ class Role {
}
}
export { Role };
import { Options } from "./settings.js";
class PermissionToggle {
rolejson;
permissions;
owner;
constructor(roleJSON, permissions, owner) {
this.rolejson = roleJSON;
this.permissions = permissions;
this.owner = owner;
}
generateHTML() {
const div = document.createElement("div");
div.classList.add("setting");
const name = document.createElement("span");
name.textContent = this.rolejson.readableName;
name.classList.add("settingsname");
div.append(name);
div.append(this.generateCheckbox());
const p = document.createElement("p");
p.textContent = this.rolejson.description;
div.appendChild(p);
return div;
}
generateCheckbox() {
const div = document.createElement("div");
div.classList.add("tritoggle");
const state = this.permissions.getPermission(this.rolejson.name);
const on = document.createElement("input");
on.type = "radio";
on.name = this.rolejson.name;
div.append(on);
if (state === 1) {
on.checked = true;
}
;
on.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, 1);
this.owner.changed();
};
const no = document.createElement("input");
no.type = "radio";
no.name = this.rolejson.name;
div.append(no);
if (state === 0) {
no.checked = true;
}
;
no.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, 0);
this.owner.changed();
};
if (this.permissions.hasDeny) {
const off = document.createElement("input");
off.type = "radio";
off.name = this.rolejson.name;
div.append(off);
if (state === -1) {
off.checked = true;
}
;
off.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, -1);
this.owner.changed();
};
}
return div;
}
submit() {
}
}
import { Buttons } from "./settings.js";
class RoleList extends Buttons {
permissions;
permission;
guild;
channel;
options;
onchange;
curid;
constructor(permissions, guild, onchange, channel = false) {
super("Roles");
this.guild = guild;
this.permissions = permissions;
this.channel = channel;
this.onchange = onchange;
const options = new Options("", this);
if (channel) {
this.permission = new Permissions("0", "0");
}
else {
this.permission = new Permissions("0");
}
for (const thing of Permissions.info) {
options.options.push(new PermissionToggle(thing, this.permission, options));
}
for (const i of permissions) {
console.log(i);
this.buttons.push([i[0].getObject().name, i[0].id]); //
}
this.options = options;
}
handleString(str) {
this.curid = str;
const arr = this.permissions.find(_ => _[0].id === str);
if (arr) {
const perm = arr[1];
this.permission.deny = perm.deny;
this.permission.allow = perm.allow;
this.options.name = SnowFlake.getSnowFlakeFromID(str, Role).getObject().name;
this.options.haschanged = false;
}
return this.options.generateHTML();
}
save() {
this.onchange(this.curid, this.permission);
}
}
export { RoleList };

View file

@ -1,6 +1,3 @@
import { Permissions } from "./permissions.js";
import { SnowFlake } from "./snowflake.js";
import { Role } from "./role.js";
//future me stuff
class Buttons {
name;
@ -68,75 +65,6 @@ class Buttons {
submit() {
}
}
class PermissionToggle {
rolejson;
permissions;
owner;
constructor(roleJSON, permissions, owner) {
this.rolejson = roleJSON;
this.permissions = permissions;
this.owner = owner;
}
generateHTML() {
const div = document.createElement("div");
div.classList.add("setting");
const name = document.createElement("span");
name.textContent = this.rolejson.readableName;
name.classList.add("settingsname");
div.append(name);
div.append(this.generateCheckbox());
const p = document.createElement("p");
p.textContent = this.rolejson.description;
div.appendChild(p);
return div;
}
generateCheckbox() {
const div = document.createElement("div");
div.classList.add("tritoggle");
const state = this.permissions.getPermission(this.rolejson.name);
const on = document.createElement("input");
on.type = "radio";
on.name = this.rolejson.name;
div.append(on);
if (state === 1) {
on.checked = true;
}
;
on.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, 1);
this.owner.changed();
};
const no = document.createElement("input");
no.type = "radio";
no.name = this.rolejson.name;
div.append(no);
if (state === 0) {
no.checked = true;
}
;
no.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, 0);
this.owner.changed();
};
if (this.permissions.hasDeny) {
const off = document.createElement("input");
off.type = "radio";
off.name = this.rolejson.name;
div.append(off);
if (state === -1) {
off.checked = true;
}
;
off.onclick = _ => {
this.permissions.setPermission(this.rolejson.name, -1);
this.owner.changed();
};
}
return div;
}
submit() {
}
}
class TextInput {
label;
owner;
@ -164,10 +92,13 @@ class TextInput {
}
onChange(ev) {
this.owner.changed();
const value = this.input.deref().value;
const input = this.input.deref();
if (input) {
const value = input.value;
this.onchange(value);
this.textContent = value;
}
}
onchange = _ => { };
watchForChange(func) {
this.onchange = func;
@ -231,10 +162,13 @@ class ColorInput {
}
onChange(ev) {
this.owner.changed();
const value = this.input.deref().value;
const input = this.input.deref();
if (input) {
const value = input.value;
this.onchange(value);
this.colorContent = value;
}
}
onchange = _ => { };
watchForChange(func) {
this.onchange = func;
@ -276,10 +210,13 @@ class SelectInput {
}
onChange(ev) {
this.owner.changed();
const value = this.select.deref().selectedIndex;
const select = this.select.deref();
if (select) {
const value = select.selectedIndex;
this.onchange(value);
this.index = value;
}
}
onchange = _ => { };
watchForChange(func) {
this.onchange = func;
@ -315,10 +252,13 @@ class MDInput {
}
onChange(ev) {
this.owner.changed();
const value = this.input.deref().value;
const input = this.input.deref();
if (input) {
const value = input.value;
this.onchange(value);
this.textContent = value;
}
}
onchange = _ => { };
watchForChange(func) {
this.onchange = func;
@ -351,8 +291,9 @@ class FileInput {
}
onChange(ev) {
this.owner.changed();
if (this.onchange) {
this.onchange(this.input.deref().files);
const input = this.input.deref();
if (this.onchange && input) {
this.onchange(input.files);
}
}
onchange = null;
@ -360,51 +301,11 @@ class FileInput {
this.onchange = func;
}
submit() {
this.onSubmit(this.input.deref().files);
const input = this.input.deref();
if (input) {
this.onSubmit(input.files);
}
}
class RoleList extends Buttons {
permissions;
permission;
guild;
channel;
options;
onchange;
curid;
constructor(permissions, guild, onchange, channel = false) {
super("Roles");
this.guild = guild;
this.permissions = permissions;
this.channel = channel;
this.onchange = onchange;
const options = new Options("", this);
if (channel) {
this.permission = new Permissions("0", "0");
}
else {
this.permission = new Permissions("0");
}
for (const thing of Permissions.info) {
options.addPermissionToggle(thing, this.permission); //
}
for (const i of permissions) {
console.log(i);
this.buttons.push([i[0].getObject().name, i[0].id]); //
}
this.options = options;
}
handleString(str) {
this.curid = str;
const perm = this.permissions.find(_ => _[0].id === str)[1];
this.permission.deny = perm.deny;
this.permission.allow = perm.allow;
this.options.name = SnowFlake.getSnowFlakeFromID(str, Role).getObject().name;
this.options.haschanged = false;
return this.options.generateHTML();
}
save() {
this.onchange(this.curid, this.permission);
}
}
class HtmlArea {
submit;
@ -434,9 +335,6 @@ class Options {
this.owner = owner;
this.ltr = ltr;
}
addPermissionToggle(roleJSON, permissions) {
this.options.push(new PermissionToggle(roleJSON, permissions, this));
}
addOptions(name, { ltr = false } = {}) {
const options = new Options(name, this, { ltr });
this.options.push(options);
@ -555,8 +453,10 @@ class Settings extends Buttons {
this.html = background;
}
hide() {
if (this.html) {
this.html.remove();
this.html = null;
}
}
export { Settings, RoleList };
}
export { Settings, Buttons, Options };

View file

@ -6,8 +6,8 @@ import {Dialog} from "./dialog.js";
import {Guild} from "./guild.js";
import { Localuser } from "./localuser.js";
import { Permissions } from "./permissions.js";
import { Settings, RoleList } from "./settings.js";
import { Role } from "./role.js";
import { Settings } from "./settings.js";
import { Role,RoleList } from "./role.js";
import {InfiniteScroller} from "./infiniteScroller.js";
import { SnowFlake } from "./snowflake.js";
import { channeljson, messagejson, readyjson } from "./jsontypes.js";

View file

@ -37,9 +37,7 @@ class Contextmenu<x,y>{
intext.classList.add("contextbutton")
intext.textContent=thing[0]
console.log(thing)
if(thing[5]==="button"){
intext.onclick=thing[1].bind(addinfo,other);
}else if(thing[5]==="submenu"){
if(thing[5]==="button"||thing[5]==="submenu"){
intext.onclick=thing[1].bind(addinfo,other);
}

View file

@ -1,10 +1,10 @@
import { Channel } from "./channel.js";
import { Localuser } from "./localuser.js";
import {Contextmenu} from "./contextmenu.js";
import {Role} from "./role.js";
import {Role,RoleList} from "./role.js";
import {Dialog} from "./dialog.js";
import {Member} from "./member.js";
import {Settings,RoleList} from "./settings.js";
import {Settings} from "./settings.js";
import {Permissions} from "./permissions.js";
import { SnowFlake } from "./snowflake.js";
import { channeljson, guildjson, emojijson, memberjson } from "./jsontypes.js";

View file

@ -7,7 +7,7 @@ import {Dialog} from "./dialog.js";
import {getapiurls, getBulkInfo, setTheme, Specialuser} from "./login.js";
import { SnowFlake } from "./snowflake.js";
import { Message } from "./message.js";
import { channeljson, guildjson, memberjson, presencejson, readyjson } from "./jsontypes.js";
import { channeljson, memberjson, presencejson, readyjson } from "./jsontypes.js";
import { Member } from "./member.js";
import { Settings } from "./settings.js";
import { MarkDown } from "./markdown.js";

View file

@ -44,3 +44,117 @@ class Role{
}
}
export {Role};
import {Options} from "./settings.js";
class PermissionToggle implements OptionsElement{
readonly rolejson:{name:string,readableName:string,description:string};
permissions:Permissions;
owner:Options;
constructor(roleJSON:PermissionToggle["rolejson"],permissions:Permissions,owner:Options){
this.rolejson=roleJSON;
this.permissions=permissions;
this.owner=owner;
}
generateHTML():HTMLElement{
const div=document.createElement("div");
div.classList.add("setting");
const name=document.createElement("span");
name.textContent=this.rolejson.readableName;
name.classList.add("settingsname");
div.append(name);
div.append(this.generateCheckbox());
const p=document.createElement("p");
p.textContent=this.rolejson.description;
div.appendChild(p);
return div;
}
generateCheckbox():HTMLElement{
const div=document.createElement("div");
div.classList.add("tritoggle");
const state=this.permissions.getPermission(this.rolejson.name);
const on=document.createElement("input");
on.type="radio";
on.name=this.rolejson.name;
div.append(on);
if(state===1){on.checked=true;};
on.onclick=_=>{
this.permissions.setPermission(this.rolejson.name,1);
this.owner.changed();
}
const no=document.createElement("input");
no.type="radio";
no.name=this.rolejson.name;
div.append(no);
if(state===0){no.checked=true;};
no.onclick=_=>{
this.permissions.setPermission(this.rolejson.name,0);
this.owner.changed();
}
if(this.permissions.hasDeny){
const off=document.createElement("input");
off.type="radio";
off.name=this.rolejson.name;
div.append(off);
if(state===-1){off.checked=true;};
off.onclick=_=>{
this.permissions.setPermission(this.rolejson.name,-1);
this.owner.changed();
}
}
return div;
}
submit(){
}
}
import { OptionsElement,Buttons } from "./settings.js";
class RoleList extends Buttons{
readonly permissions:[SnowFlake<Role>,Permissions][];
permission:Permissions;
readonly guild:Guild;
readonly channel:boolean;
readonly declare buttons:[string,string][];
readonly options:Options;
onchange:Function;
curid:string;
constructor(permissions:[SnowFlake<Role>,Permissions][],guild:Guild,onchange:Function,channel=false){
super("Roles");
this.guild=guild;
this.permissions=permissions;
this.channel=channel;
this.onchange=onchange;
const options=new Options("",this);
if(channel){
this.permission=new Permissions("0","0");
}else{
this.permission=new Permissions("0");
}
for(const thing of Permissions.info){
options.options.push(new PermissionToggle(thing,this.permission,options));
}
for(const i of permissions){
console.log(i);
this.buttons.push([i[0].getObject().name,i[0].id])//
}
this.options=options;
}
handleString(str:string):HTMLElement{
this.curid=str;
const arr=this.permissions.find(_=>_[0].id===str);
if(arr){
const perm=arr[1];
this.permission.deny=perm.deny;
this.permission.allow=perm.allow;
this.options.name=SnowFlake.getSnowFlakeFromID(str,Role).getObject().name;
this.options.haschanged=false;
}
return this.options.generateHTML();
}
save(){
this.onchange(this.curid,this.permission);
}
}
export {RoleList}

View file

@ -1,14 +1,10 @@
import { Permissions } from "./permissions.js";
import { Guild } from "./guild.js";
import { SnowFlake } from "./snowflake.js";
import { Role } from "./role.js";
interface OptionsElement {//OptionsElement<x>
generateHTML():HTMLElement;
submit:()=>void;
//watchForChange:(func:(arg1:x)=>void)=>void
}
//future me stuff
class Buttons implements OptionsElement{
readonly name:string;
readonly buttons:[string,Options|string][];
@ -18,7 +14,7 @@ class Buttons implements OptionsElement{
this.buttons=[];
this.name=name;
}
add(name:string,thing:Options=undefined){
add(name:string,thing:Options|undefined=undefined){
if(!thing){thing=new Options(name,this)}
this.buttons.push([name,thing]);
return thing;
@ -74,71 +70,7 @@ class Buttons implements OptionsElement{
}
}
class PermissionToggle implements OptionsElement{
readonly rolejson:{name:string,readableName:string,description:string};
permissions:Permissions;
owner:Options;
constructor(roleJSON:PermissionToggle["rolejson"],permissions:Permissions,owner:Options){
this.rolejson=roleJSON;
this.permissions=permissions;
this.owner=owner;
}
generateHTML():HTMLElement{
const div=document.createElement("div");
div.classList.add("setting");
const name=document.createElement("span");
name.textContent=this.rolejson.readableName;
name.classList.add("settingsname");
div.append(name);
div.append(this.generateCheckbox());
const p=document.createElement("p");
p.textContent=this.rolejson.description;
div.appendChild(p);
return div;
}
generateCheckbox():HTMLElement{
const div=document.createElement("div");
div.classList.add("tritoggle");
const state=this.permissions.getPermission(this.rolejson.name);
const on=document.createElement("input");
on.type="radio";
on.name=this.rolejson.name;
div.append(on);
if(state===1){on.checked=true;};
on.onclick=_=>{
this.permissions.setPermission(this.rolejson.name,1);
this.owner.changed();
}
const no=document.createElement("input");
no.type="radio";
no.name=this.rolejson.name;
div.append(no);
if(state===0){no.checked=true;};
no.onclick=_=>{
this.permissions.setPermission(this.rolejson.name,0);
this.owner.changed();
}
if(this.permissions.hasDeny){
const off=document.createElement("input");
off.type="radio";
off.name=this.rolejson.name;
div.append(off);
if(state===-1){off.checked=true;};
off.onclick=_=>{
this.permissions.setPermission(this.rolejson.name,-1);
this.owner.changed();
}
}
return div;
}
submit(){
}
}
class TextInput implements OptionsElement{
readonly label:string;
readonly owner:Options;
@ -166,10 +98,13 @@ class TextInput implements OptionsElement{
}
private onChange(ev:Event){
this.owner.changed();
const value=this.input.deref().value as string;
const input=this.input.deref();
if(input){
const value=input.value as string;
this.onchange(value);
this.textContent=value;
}
}
onchange:(str:string)=>void=_=>{};
watchForChange(func:(str:string)=>void){
this.onchange=func;
@ -235,10 +170,13 @@ class ColorInput implements OptionsElement{
}
private onChange(ev:Event){
this.owner.changed();
const value=this.input.deref().value as string;
const input=this.input.deref();
if(input){
const value=input.value as string;
this.onchange(value);
this.colorContent=value;
}
}
onchange:(str:string)=>void=_=>{};
watchForChange(func:(str:string)=>void){
this.onchange=func;
@ -282,10 +220,13 @@ class SelectInput implements OptionsElement{
}
private onChange(ev:Event){
this.owner.changed();
const value=this.select.deref().selectedIndex;
const select=this.select.deref();
if(select){
const value=select.selectedIndex;
this.onchange(value);
this.index=value;
}
}
onchange:(str:number)=>void=_=>{};
watchForChange(func:(str:number)=>void){
this.onchange=func;
@ -321,10 +262,13 @@ class MDInput implements OptionsElement{
}
onChange(ev:Event){
this.owner.changed();
const value=this.input.deref().value as string;
const input=this.input.deref();
if(input){
const value=input.value as string;
this.onchange(value);
this.textContent=value;
}
}
onchange:(str:string)=>void=_=>{};
watchForChange(func:(str:string)=>void){
this.onchange=func;
@ -336,7 +280,7 @@ class MDInput implements OptionsElement{
class FileInput implements OptionsElement{
readonly label:string;
readonly owner:Options;
readonly onSubmit:(str:FileList)=>void;
readonly onSubmit:(str:FileList|null)=>void;
input:WeakRef<HTMLInputElement>
constructor(label:string,onSubmit:(str:FileList)=>void,owner:Options,{}={}){
this.label=label;
@ -357,61 +301,23 @@ class FileInput implements OptionsElement{
}
onChange(ev:Event){
this.owner.changed();
if(this.onchange){
this.onchange(this.input.deref().files);
const input=this.input.deref();
if(this.onchange&&input){
this.onchange(input.files);
}
}
onchange:(str:FileList)=>void=null;
onchange:((str:FileList|null)=>void)|null=null;
watchForChange(func:(str:FileList)=>void){
this.onchange=func;
}
submit(){
this.onSubmit(this.input.deref().files);
const input=this.input.deref();
if(input){
this.onSubmit(input.files);
}
}
class RoleList extends Buttons{
readonly permissions:[SnowFlake<Role>,Permissions][];
permission:Permissions;
readonly guild:Guild;
readonly channel:boolean;
readonly declare buttons:[string,string][];
readonly options:Options;
onchange:Function;
curid:string;
constructor(permissions:[SnowFlake<Role>,Permissions][],guild:Guild,onchange:Function,channel=false){
super("Roles");
this.guild=guild;
this.permissions=permissions;
this.channel=channel;
this.onchange=onchange;
const options=new Options("",this);
if(channel){
this.permission=new Permissions("0","0");
}else{
this.permission=new Permissions("0");
}
for(const thing of Permissions.info){
options.addPermissionToggle(thing,this.permission);//
}
for(const i of permissions){
console.log(i);
this.buttons.push([i[0].getObject().name,i[0].id])//
}
this.options=options;
}
handleString(str:string):HTMLElement{
this.curid=str;
const perm=this.permissions.find(_=>_[0].id===str)[1];
this.permission.deny=perm.deny;
this.permission.allow=perm.allow;
this.options.name=SnowFlake.getSnowFlakeFromID(str,Role).getObject().name;
this.options.haschanged=false;
return this.options.generateHTML();
}
save(){
this.onchange(this.curid,this.permission);
}
}
class HtmlArea implements OptionsElement{
submit: () => void;
html:(()=>HTMLElement)|HTMLElement;
@ -440,9 +346,6 @@ class Options implements OptionsElement{
this.ltr=ltr;
}
addPermissionToggle(roleJSON:PermissionToggle["rolejson"],permissions:Permissions){
this.options.push(new PermissionToggle(roleJSON,permissions,this));
}
addOptions(name:string,{ltr=false}={}){
const options=new Options(name,this,{ltr});
this.options.push(options);
@ -537,7 +440,7 @@ class Options implements OptionsElement{
class Settings extends Buttons{
static readonly Buttons=Buttons;
static readonly Options=Options;
html:HTMLElement;
html:HTMLElement|null;
constructor(name:string){
super(name);
}
@ -568,10 +471,12 @@ class Settings extends Buttons{
this.html=background;
}
hide(){
if(this.html){
this.html.remove();
this.html=null;
}
}
}
export {Settings,RoleList}
export {Settings,OptionsElement,Buttons,Options}