17 lines
36 KiB
JavaScript
17 lines
36 KiB
JavaScript
"use strict";exports.id=9901,exports.ids=[9901],exports.modules={46083:(e,a,t)=>{t.d(a,{A:()=>c});var l=t(8732),s=t(82015),i=t.n(s),n=t(32251),r=t(36138),d=t(27825),o=t.n(d);function c({targetField:e,fieldIndex:a,tableFields:s,setTableFields:d,refreshFieldsListRef:c,setActiveEdit:u,database:m,currentTable:x,user:p}){let h=e?.dataType?e.dataType.replace(/\d|\(|\)/g,""):null,f=e?.dataType?e.dataType.replace(/[^\d]/g,""):"200",g=t(94327),y=i().useRef(o().cloneDeep(e)),v=i().useRef(),[j,N]=i().useState(e),[w,b]=i().useState(e?.fieldName),[T,_]=i().useState(h),[F,S]=i().useState(f),[C,A]=i().useState("Varchar is simply letters and numbers within the range 0 - 255"),[k,D]=i().useState(e?.richText&&!e?.encrypted?"Yes":"No"),V=!!T?.match(/uuid/i);return(0,l.jsx)("div",{className:"w-full -mt-3 bg-white dark:bg-slate-800 flex-wrap",ref:v,children:(0,l.jsxs)("form",{className:"flex flex-col xl:flex-row items-start gap-4 w-full justify-between border border-solid p-4 border-slate-200 dark:border-slate-600 rounded rounded-t-none focus:shadow-lg shadow-slate-700 dark:shadow-black relative flex-wrap",onSubmit:e=>{e.preventDefault(),d(e=>(e[a]=j,e)),c.current(e=>e+1);let t=e.target;t.closest(".table-field-wrapper")?.querySelector(".edit-table-field-section")?.classList.toggle("hidden")},children:[(0,l.jsxs)("div",{className:"gap-4 flex-wrap w-full md:w-auto flex-col xl:flex-row items-stretch",children:[(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,l.jsx)("label",{htmlFor:"new_field_name",children:"Field Name"}),(0,l.jsx)("input",{type:"text",name:"new_field_name",id:"new_field_name",placeholder:"Eg. post_title",onInput:async e=>{let a=e.target;a.value=a.value.toLowerCase().replace(/ /g,"_"),N(e=>(e.fieldName=a.value,e.updatedField=!0,e.originName||(e.originName=w),e))},required:!0,defaultValue:w})]}),(0,l.jsxs)("div",{className:"flex flex-col items-start gap-4 xl:gap-0.5",children:[(0,l.jsxs)("div",{className:"flex-wrap xl:flex-nowrap w-full md:w-auto",children:[(0,l.jsx)("label",{htmlFor:"new_field_data_type",children:"Data Type"}),(0,l.jsxs)("div",{className:"dropdown-wrapper reversed text-sm items-start",children:[(0,l.jsx)("span",{className:"px-2 bg-slate-200 dark:bg-slate-700 rounded-full hover:bg-slate-100 dark:hover:bg-slate-600 hidden xl:flex",children:"Info"}),(0,l.jsx)("div",{className:"dropdown mt-0 xl:-mt-2",children:(0,l.jsx)("span",{children:C})})]})]}),(0,l.jsxs)("div",{className:"w-auto",children:[(0,l.jsx)("select",{name:"new_field_data_type",id:"new_field_data_type",className:"w-full xl-w-auto",onChange:a=>{let t=a.target;_(t.value),t.childNodes.forEach(e=>{e.value===t.value&&e.dataset.desc&&A(e.dataset.desc),e.value===t.value&&e.dataset.literal?(j.defaultValueLiteral=e.dataset.literal,j.nullValue=!1):delete j.defaultValueLiteral}),e.dataType=t.value+(t.value.match(/VARCHAR/)?`(${F||200})`:"")},defaultValue:T||void 0,children:g.map((e,a)=>e.name.match(/VARCHAR/)?(0,l.jsx)("option",{value:e.name,"data-desc":e.description,children:e.title+"("+(F||200)+")"},a+1):(0,l.jsx)("option",{value:e.name,"data-desc":e.description,"data-literal":e.valueLiteral||void 0,children:e.title},a+1))}),T?.match(/VARCHAR/)&&(0,l.jsx)("input",{type:"number",defaultValue:F||200,className:"px-2",style:{maxWidth:"60px"},max:255,min:5,onChange:a=>{S(a.target.value),e.dataType=T+`(${a.target.value})`}})]})]}),T?.match(/text/i)&&(0,l.jsx)(i().Fragment,{children:(0,l.jsx)(r.A,{targetField:e})}),!e.dataType?.match(/text/i)&&!V&&(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",style:{minWidth:"70px"},children:[(0,l.jsx)("label",{htmlFor:"new_field_required",children:"Required?"}),(0,l.jsxs)("select",{name:"new_field_required",id:"new_field_required",className:"px-2",defaultValue:e?.notNullValue?"Yes":"No",onChange:a=>{console.log(e),"Yes"===a.target.value?e.notNullValue=!0:(e.notNullValue=!1,delete e.notNullValue)},children:[(0,l.jsx)("option",{value:"No",children:"No"}),(0,l.jsx)("option",{value:"Yes",children:"Yes"})]})]}),!V&&(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,l.jsx)("label",{htmlFor:"new_field_default_value",children:j?.dataType?.match(/text$/i)?"Can't Set Default for text values":"Default Value (optional)"}),(0,l.jsx)("input",{type:"text",name:"new_field_default_value",id:"new_field_default_value",className:j?.dataType?.match(/text$/i)?"pointer-events-none opacity-50":"",placeholder:"Default Value",defaultValue:j?.defaultValue?j.defaultValue:j?.nullValue?"NULL":"",onInput:e=>{let a=e.target;j.dataType?.match(/text$/i)||N(e=>(a.value.match(/./)?delete e.notNullValue:(delete e.defaultValue,delete e.nullValue),a.value.match(/^null$/i)?(delete e.defaultValue,e.nullValue=!0):a.value.match(/./)&&(delete e.nullValue,e.defaultValue=a.value),e))}})]}),!V&&(0,l.jsx)(n.A,{database:m,setFieldData:N,setTableFields:d,tableFields:s,targetField:e,user:p,currentTable:x,fieldIndex:a})]}),(0,l.jsxs)("div",{className:"secondary mt-auto flex-wrap w-full xl:w-auto",children:[(0,l.jsx)("button",{type:"submit",className:"secondary mt-auto py-3 w-full md:w-auto grow",children:"Save Updates"}),(0,l.jsx)("div",{className:"button outlined gray mt-auto py-2.5 w-full md:w-auto justify-center grow",onClick:t=>{y.current&&(e=o().cloneDeep(y.current)),d(e=>{let t=o().cloneDeep(e);return a&&y.current&&(t[a]=o().cloneDeep(y.current)),t}),u&&u(!1)},children:"Cancel"})]})]})})}},32251:(e,a,t)=>{t.d(a,{A:()=>g});var l=t(8732),s=t(82015),i=t.n(s),n=t(83155),r=t(58150);function d({targetField:e}){if(!e?.richText)return null;let[a,t]=i().useState(e.cssFiles||[]),s=i().useRef(null);return(0,l.jsxs)("div",{className:"flex flex-col items-start gap-2 w-full my-4",style:{minWidth:"70px"},children:[(0,l.jsx)("span",{className:"label text-xs text-slate-500",children:"Add CSS"}),a.map((e,a)=>(0,l.jsxs)("div",{className:"relative border border-solid border-slate-300 text-xs px-2 py-1 rounded-full",children:[(0,l.jsx)("span",{children:e}),(0,l.jsx)(r.A,{size:20,onClick:()=>{t(a=>a.filter(a=>a!==e))},className:"cursor-pointer hover:opacity-60 "})]},a+1)),(0,l.jsxs)("div",{className:"row w-full",children:[(0,l.jsx)(n.A,{name:"css-file",placeholder:"CSS file URL",elementRef:s}),(0,l.jsx)("button",{className:"secondary outlined",onClick:()=>{let e=s.current?.value;e?.match(/./)&&t(a=>[...new Set([...a,e])])},children:"Add"})]}),(0,l.jsx)("span",{className:"text-sm text-slate-600",children:"Add CSS files to your Rich Text field"})]})}function o({targetField:e,setFieldData:a}){return(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",style:{minWidth:"70px"},children:[(0,l.jsx)("label",{htmlFor:"encryption_field",children:"Encrypt?"}),(0,l.jsxs)("select",{name:"encryption_field",id:"encryption_field",className:"px-2",defaultValue:e?.encrypted?"Yes":"No",onChange:e=>{a&&a(a=>(e.target.value.match(/yes/i)?a.encrypted=!0:(a.encrypted=!1,delete a.encrypted),a))},children:[(0,l.jsx)("option",{value:"No",children:"No"}),(0,l.jsx)("option",{value:"Yes",children:"Yes"})]})]})}var c=t(93763);function u({targetField:e,setFieldData:a}){return null}function m({targetField:e}){return(0,l.jsxs)("div",{className:"flex flex-col items-start gap-2 w-full",style:{minWidth:"70px"},children:[(0,l.jsx)("label",{htmlFor:"encryption_field",children:"Pattern"}),(0,l.jsx)("span",{className:"text-sm text-slate-500",children:'This describes a pattern that must be matched for this field to be valid. If you add a pattern and make a db entry that doesn\'t match, the entry will be "NULL" or an empty string or the default value.'}),(0,l.jsx)("input",{type:"text",placeholder:"Regex Pattern. Eg: '\\\\.[a-z]+'",onInput:a=>{let t=a.target;t?.value?.length>0?e.pattern=t.value:delete e.pattern},defaultValue:e?.pattern}),(0,l.jsx)("input",{type:"text",placeholder:"Regex Pattern Flags. Eg: igm",onInput:a=>{let t=a.target;t?.value?.length>0?e.patternFlags=t.value:delete e.patternFlags},defaultValue:e?.patternFlags})]})}var x=t(27825),p=t.n(x),h=t(84483);function f({targetField:e,setFieldData:a}){return(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",style:{minWidth:"70px"},children:[(0,l.jsx)("label",{htmlFor:"unique_field",children:"Unique Field?"}),(0,l.jsxs)("select",{name:"unique_field",id:"unique_field",className:"px-2",defaultValue:e?.unique?"Yes":"No",onChange:e=>{a&&a(a=>(e.target.value.match(/yes/i)?a.unique=!0:(a.unique=!1,delete a.unique),a))},children:[(0,l.jsx)("option",{value:"No",children:"No"}),(0,l.jsx)("option",{value:"Yes",children:"Yes"})]})]})}function g({targetField:e,currentTable:a,database:t,tableFields:s,setTableFields:n,setFieldData:r,user:x,fieldIndex:g}){let[y,v]=i().useState(!1),j=i().useRef(p().cloneDeep(e));return(0,l.jsxs)(i().Fragment,{children:[(0,l.jsx)("span",{className:"button outlined gray mt-5 w-full xl:w-auto",onClick:()=>{v(!0)},children:"More"}),(0,l.jsx)(h.A,{open:y,onClose:()=>{j.current&&(e=p().cloneDeep(j.current)),v(!1)},maxWidth:"600px",children:(0,l.jsxs)("div",{className:"m-auto flex flex-col max-w-xl w-full max-h-[90vh] overflow-y-auto",children:[(0,l.jsx)("div",{className:"w-full justify-between",children:(0,l.jsx)("span",{className:"text-xl",children:"More Options"})}),(0,l.jsx)(d,{targetField:e}),(0,l.jsx)(f,{targetField:e,setFieldData:r}),(0,l.jsx)(o,{targetField:e,setFieldData:r}),a&&(0,l.jsx)(c.A,{targetField:e,setFieldData:r,database:t,tableFields:s,setTableFields:n,currentTable:a,user:x}),(0,l.jsx)(u,{targetField:e,setFieldData:r}),(0,l.jsx)(m,{targetField:e}),(0,l.jsx)("button",{className:"w-full outlined more-padding",onClick:()=>{v(!1)},children:"Done"})]})})]})}},471:(e,a,t)=>{t.d(a,{A:()=>F});var l=t(8732),s=t(82015),i=t.n(s);function n({tableFields:e,setTableFields:a,setRefresh:t,setPageRefresh:l,refreshFieldsListRef:s}){let i=e.findIndex(e=>"date_created"===e.fieldName);e.splice(i,0,{newTempField:!0}),a(e),s?.current&&s.current(e=>e+1)}t(80255);var r=t(51339),d=t(16757),o=t(42960),c=t(93763),u=t(46169);function m({field:e,setTargetField:a,fieldIndex:t,tableFields:s,setTableFields:n,refreshFieldsListRef:r,database:d,currentTable:m,user:x,isDelegated:p,setLoading:h}){let[f,g]=i().useState(e),[y,v]=i().useState(!1);return(0,l.jsxs)("div",{className:"flex-col w-full table-field-wrapper"+(y?" shadow-2xl shadow-slate-700/40 relative z-50":""),children:[(0,l.jsxs)("div",{className:"card no-hover items-center w-full py-4"+(y?" rounded-t":" rounded")+(f.fieldName?.match(o.A)?" text-slate-400 pointer-events-none border-slate-200 border":" light-gray"),children:[(0,l.jsx)("span",{className:"font-bold"+(f.fieldName?.match(o.A)?" dark:text-slate-500":" dark:text-white"),children:f.fieldName}),(0,l.jsx)("span",{className:"text-xs py-1 px-2 bg-slate-100 dark:bg-slate-700 dark:text-slate-200 rounded ",children:f.dataType}),f?.foreignKey&&(0,l.jsxs)("div",{className:"text-xs bg-primary text-white px-2 py-0.5 rounded-full",children:[(0,l.jsx)("span",{children:"Foreign Key: "}),(0,l.jsxs)("span",{children:[f.foreignKey.destinationTableName," ("," ",(0,l.jsx)("b",{children:f.foreignKey.destinationTableColumnName})," ",")"]})]}),f.fieldName?.match(o.A)&&(0,l.jsx)("span",{className:"text-slate-300 text-sm font-semibold ml-0 md:ml-auto",children:"Default Field"}),!(!p&&!f.fieldName?.match(o.A)&&f.dataType?.match(/INT/))||f.foreignKey||d?.active_clone?.toString()?.match(/1/)?!p&&!f.fieldName?.match(o.A)&&f.dataType?.match(/INT/)&&!d?.active_clone?.toString()?.match(/1/)?(0,l.jsx)("div",{className:"ml-0 md:ml-auto flex-wrap",children:(0,l.jsx)("div",{className:"button py-1 text-xs light-gray",onClick:a=>{window.confirm("Delete this foreign Key?")&&(delete e.foreignKey,h(!0),(0,u.A)("/api/updateClonedTableForeignKeys",{method:"post",body:{tableData:m,database:d.db_full_name,dbSlug:d.db_slug,delegated:!!window.location?.search?.match(/delegated=true/i)}},!0).then(e=>{e.success?window.location.reload():window.alert("Update Failed, Please Try again.")}))},style:{color:"var(--slate-500)"},children:"Delete Foreign Key"})}):(0,l.jsx)(i().Fragment,{}):(0,l.jsx)("div",{className:"ml-0 md:ml-auto flex-wrap",children:(0,l.jsx)("div",{className:"button outlined py-1 text-xs gray",onClick:e=>{y?v(!1):v(!0)},style:{color:"var(--slate-500)"},children:"Add Foreign Key"})})]}),y&&!p&&(0,l.jsx)("div",{className:"card col w-full -mt-5 pt-0 no-hover",children:(0,l.jsx)(c.A,{targetField:e,setFieldData:g,tableFields:s,setTableFields:n,database:d,currentTable:m,user:x,setActiveEdit:v,activeClonedTable:!0})})]})}var x=t(32251),p=t(36138);function h({fieldIndex:e,setTableFields:a,database:s,user:n,isNewField:r,setLiteralValue:d,tempFieldData:o,setTempFieldData:c,dataTypeValue:u,setDataTypeValue:m,dataType:h,setDataType:f,dataTypeDesc:g,setDataTypeDesc:y}){let v=t(94327);i().useRef();let j=!!h.match(/uuid/i);return(0,l.jsxs)(i().Fragment,{children:[r&&(0,l.jsx)("span",{className:"absolute -top-4 text-sm bg-fuchsia-600 dark:bg-white text-white dark:text-fuchsia-800 px-3 py-1 rounded-full",children:"New Field"}),(0,l.jsxs)("div",{className:"gap-4 flex-wrap xl:flex-nowrap flex-col xl:flex-row items-stretch w-full xl:w-auto",children:[(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,l.jsx)("label",{htmlFor:"new_field_name",children:"Field Name"}),(0,l.jsx)("input",{type:"text",name:"new_field_name",id:"new_field_name",placeholder:"Eg. post_title",onInput:async e=>{let a=e.target,t=a.value.toLowerCase().replace(/ /g,"_");a.value=t},required:!0})]}),(0,l.jsxs)("div",{className:"flex flex-col items-start gap-4 xl:gap-0.5",children:[(0,l.jsxs)("div",{className:"items-start flex-wrap xl:flex-nowrap",children:[(0,l.jsx)("label",{htmlFor:"new_field_data_type",children:"Data Type"}),(0,l.jsxs)("div",{className:"dropdown-wrapper reversed text-sm w-full items-start gap-2",children:[(0,l.jsx)("span",{className:"px-2 bg-slate-200 dark:bg-slate-700 rounded-full hover:bg-slate-100 dark:hover:bg-slate-600 hidden xl:flex",children:"Info"}),(0,l.jsx)("div",{className:"dropdown mt-0 xl:-mt-2",children:(0,l.jsx)("span",{children:g})})]})]}),(0,l.jsxs)("div",{className:"w-full xl:w-auto",children:[(0,l.jsx)("select",{name:"new_field_data_type",id:"new_field_data_type",className:"w-full xl:w-auto",onChange:e=>{let a=e.target;f(a.value),a.childNodes.forEach(e=>{e.value===a.value&&y(e.dataset.desc),e.value===a.value&&e.dataset.literal&&d(e.dataset.literal)})},children:v.map((e,a)=>e.name.match(/VARCHAR/)?(0,l.jsx)("option",{value:e.name,"data-desc":e.description,children:e.title+"("+(u||200)+")"},a+1):(0,l.jsx)("option",{value:e.name,"data-desc":e.description,"data-literal":e.valueLiteral||void 0,children:e.title},a+1))}),h.match(/VARCHAR/)&&(0,l.jsx)("input",{type:"number",defaultValue:u,className:"px-2",style:{maxWidth:"60px"},max:255,min:5,onChange:e=>{m(e.target.value)}})]})]}),h?.match(/text/i)&&(0,l.jsx)(i().Fragment,{children:(0,l.jsx)(p.A,{targetField:o})}),!j&&(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",style:{minWidth:"70px"},children:[(0,l.jsx)("label",{htmlFor:"new_field_required",children:"Required?"}),(0,l.jsxs)("select",{name:"new_field_required",id:"new_field_required",className:"px-2",children:[(0,l.jsx)("option",{value:"No",children:"No"}),(0,l.jsx)("option",{value:"Yes",children:"Yes"})]})]}),!j&&(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,l.jsx)("label",{htmlFor:"new_field_default_value",children:"Default Value (optional)"}),(0,l.jsx)("input",{type:"text",name:"new_field_default_value",id:"new_field_default_value",placeholder:"Default Value"})]}),!j&&(0,l.jsx)(x.A,{database:s,setFieldData:c,targetField:o,user:n,fieldIndex:e})]}),(0,l.jsxs)("div",{className:"secondary mt-auto flex-wrap xl:flex-nowrap w-full xl:w-auto",children:[(0,l.jsx)("button",{type:"submit",className:"secondary mt-auto py-3 w-full sm:w-auto justify-center grow",children:"Add Field"}),(0,l.jsx)("div",{className:"button outlined-gray mt-auto py-2.5 w-full sm:w-auto justify-center grow",onClick:t=>{a(a=>a.filter((a,t)=>t!=e))},children:"Cancel"})]})]})}function f({fieldIndex:e,tableFields:a,setTableFields:s,refreshFieldsListRef:n,database:r,currentTable:d,user:o}){t(94327);let[c,u]=i().useState("VARCHAR"),[m,x]=i().useState("200"),[p,f]=i().useState("Varchar is simply letters and numbers within the range 0 - 255"),[g,y]=i().useState({}),v=i().useRef(),[j,N]=i().useState(""),w=!!c.match(/uuid/i);return(0,l.jsx)("div",{className:"w-full mt-1 flex-wrap relative z-0 hover:z-20",ref:v,children:(0,l.jsx)("form",{className:"flex flex-row items-start gap-4 w-full justify-between border border-solid p-4 pt-6 border-slate-400 rounded focus:shadow-lg shadow-slate-400/40 dark:shadow-black/30 relative flex-wrap xl:flex-nowrap shadow-xl",onSubmit:a=>{a.preventDefault();let t=g.foreignKey;t&&!t.destinationTableName&&delete g.foreignKey;let l=a.target,i=l.new_field_name.value,r=l.new_field_data_type.value,d=l.new_field_required?.value,o=l.new_field_default_value?.value,c=l.encryption_field?.value,u=l.rich_text_option?.value,x=l.foreign_key_field,p=l.foreign_key_destination_table_name,h=l.foreign_key_destination_table_column_name;x?.value;let f={...g,fieldName:i,dataType:g?.dataType&&g?.foreignKey?g.dataType:r?.match(/VARCHAR/)?`${r}(${m})`:r};d?.match(/yes/i)?f.notNullValue=!0:o?.match(/./)||(f.nullValue=!0),o?.match(/./)&&(f.defaultValue=o),c?.match(/yes/i)&&(f.encrypted=!0),h?.value?.match(/./i)&&!h?.value?.match(/^--$/i)&&(f.dataType=h.dataset.dataType,f.foreignKey={foreignKeyName:h.dataset.foreignKeyName,destinationTableName:p.dataset.destinationTableName,destinationTableColumnName:h.dataset.destinationTableColumnName,cascadeDelete:!0}),u?.match(/yes/i)&&(f.richText=!0),w?(f.defaultValueLiteral=j,f.nullValue=!1):delete f.defaultValueLiteral,console.log("newFieldObject",f),function({fieldIndex:e,setTableFields:a,refreshFieldsListRef:t,payload:l}){a(a=>(a.splice(e,1,l),a)),t?.current&&t.current(e=>e+1)}({fieldIndex:e,setTableFields:s,refreshFieldsListRef:n,payload:f})},children:(0,l.jsx)(h,{database:r,fieldIndex:e,isNewField:!0,literalValue:j,refreshFieldsListRef:n,setLiteralValue:N,setTableFields:s,user:o,currentTable:d,tableFields:a,tempFieldData:g,setTempFieldData:y,dataTypeValue:m,setDataTypeValue:x,dataType:c,setDataType:u,dataTypeDesc:p,setDataTypeDesc:f})})})}var g=t(27825),y=t.n(g);function v({tableFields:e,setTableFields:a,refreshFieldsListRef:t,order:l,field:s,e:i}){let n=y().cloneDeep(e),r=n.findIndex(e=>e.fieldName===s.fieldName);if(r<0)return;let d=n[r];if("up"===l&&r&&r<=1){console.log("Min Reached =>",r);return}if("down"===l&&r&&r>=n.length-7){console.log("Max Reached =>",r);return}try{let e;let a=i.target.closest(".table-field-wrapper"),t=a.previousElementSibling,s=a.nextElementSibling,n=window.DSQL.Flip,r=n.getState(a);"up"===l?(e=n.getState(t),a.parentNode?.insertBefore(a,t)):s?.nextElementSibling&&(e=n.getState(s),a.parentNode?.insertBefore(a,s.nextElementSibling)),n.from(r,{duration:.3,ease:"power1.inOut"}),n.from(e,{duration:.3,ease:"power1.inOut"})}catch(e){console.log("Error =>",e.message)}if(!r){console.log("No target Field Index =>",r);return}n.splice(r,1),"up"===l?n.splice(r-1,0,d):n.splice(r+1,0,d),setTimeout(()=>{a([...n]),t.current&&t.current(e=>e+1)},500)}var j=t(46083),N=t(55904),w=t(58526);function b({field:e,setTargetField:a,fieldIndex:t,tableFields:s,setTableFields:n,refreshFieldsListRef:r,database:d,currentTable:c,confirmedDelegetedUser:u,user:m}){let x=u?.delegated,p=u?.priviledges?.match(/Edit Tables/i);u?.priviledges?.match(/Delete Tables/i),u?.priviledges?.match(/Create Tables/i);let{active_clone:h,active_clone_parent_db:f,remote_connected:g}=d,[y,b]=i().useState(e),[T,_]=i().useState(!1);return(0,l.jsxs)("div",{className:"flex-col w-full table-field-wrapper"+(T?" shadow-2xl shadow-slate-300/40 dark:shadow-black/30 relative z-50":""),children:[(0,l.jsxs)("div",{className:"card no-hover items-center w-full py-4"+(T?" rounded-t":" rounded")+(y.fieldName?.match(o.A)?" text-slate-400 pointer-events-none border-slate-200 border":" light-gray"),children:[(0,l.jsx)("span",{className:"font-bold"+(y.fieldName?.match(o.A)?" dark:text-slate-500":" dark:text-white"),children:y.fieldName}),(0,l.jsx)("span",{className:"text-xs py-1 px-2 bg-slate-100 dark:bg-slate-700 dark:text-slate-200 rounded ",children:y.dataType}),y?.foreignKey&&(0,l.jsxs)("div",{className:"text-xs bg-primary text-white px-2 py-0.5 rounded-full",children:[(0,l.jsx)("span",{children:"Foreign Key: "}),(0,l.jsxs)("span",{children:[y.foreignKey.destinationTableName," ("," ",(0,l.jsx)("b",{children:y.foreignKey.destinationTableColumnName})," ",")"]})]}),y.fieldName?.match(o.A)&&(0,l.jsx)("span",{className:"text-slate-300 text-sm font-semibold ml-0 md:ml-auto",children:"Default Field"}),!y.fieldName?.match(o.A)&&!f&&!g&&(0,l.jsx)("div",{className:"ml-0 md:ml-auto flex-wrap",children:(!x||x&&p)&&(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)(N.A,{children:[(0,l.jsx)("div",{className:"button outlined py-1 text-xs gray",onClick:e=>{T?_(!1):_(!0)},style:{color:"var(--slate-500)"},children:"Edit"}),!f&&!g&&(0,l.jsx)("div",{className:"button outlined py-1 text-xs gray",onClick:a=>{window.confirm(`Delete "${e.fieldName}"?`)&&n(e=>e.filter((e,a)=>a!=t))},style:{color:"var(--slate-500)"},children:"Delete"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"button outlined gray p-2 w-8 h-8 rounded-full rotate-180",onClick:a=>{v({tableFields:s,setTableFields:n,refreshFieldsListRef:r,order:"up",field:e,e:a})},children:(0,l.jsx)(w.A,{size:20})}),(0,l.jsx)("div",{className:"button outlined gray p-2 w-8 h-8 rounded-full",onClick:a=>{v({tableFields:s,setTableFields:n,refreshFieldsListRef:r,order:"down",field:e,e:a})},children:(0,l.jsx)(w.A,{size:20})})]})]})})]}),T&&(0,l.jsx)("div",{className:"w-full",children:(0,l.jsx)(j.A,{fieldIndex:t,tableFields:s,setTableFields:n,refreshFieldsListRef:r,targetField:e,setActiveEdit:_,database:d,currentTable:c,user:m})})]})}var T=t(60424);let _=1;function F({user:e,tableFields:a,setTableFields:t,setTargetField:s,refreshFieldsListRef:o,updateTable:c,updateTableAfterFieldsUpdateFunction:u,collapsed:x,database:p,table:h,confirmedDelegetedUser:g,query:y}){h?.childTable&&h.childTableDbFullName?.replace(new RegExp(/datasquirel_user_\d+_/),"");let v=g?.delegated,j=g?.priviledges?.match(/Edit Tables/i);g?.priviledges?.match(/Delete Tables/i),g?.priviledges?.match(/Create Tables/i);let{active_clone:N,active_clone_parent_db:w,remote_connected:F}=p,[S,C]=i().useState(0);o.current=C;let[A,k]=i().useState(!1),[D,V]=i().useState(x||!1);return v&&!j?(0,l.jsx)(l.Fragment,{}):(0,l.jsxs)("section",{className:"paper green",children:[A&&(0,l.jsx)(d.A,{}),h?.childTable?(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,l.jsx)("h2",{className:"text-xl m-0 text-left title",children:"Fields"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{let t=(0,T.A)({paradigm:"JavaScript",table:h,query:y,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("JavaScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (JS)"})}),(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{let t=(0,T.A)({paradigm:"TypeScript",table:h,query:y,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("TypeScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (TS)"})})]})]}),(0,l.jsx)("div",{className:"flex-col w-full",style:D?{maxHeight:"200px"}:{},children:a&&a[0]&&a.map((i,n)=>(_++,(0,l.jsx)(m,{field:i,fieldIndex:n,setTargetField:s,setTableFields:t,refreshFieldsListRef:o,tableFields:a,database:p,setLoading:k,currentTable:h,user:e,isDelegated:v},_)))}),x&&(0,l.jsx)(r.A,{collapse:D||!1,setCollapse:V})]}):(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)("div",{className:"w-full justify-between flex-wrap",children:[(0,l.jsx)("h2",{className:"text-xl m-0 text-left title",children:"Fields"}),(0,l.jsxs)("div",{children:[(!v||v&&j)&&!w&&!F&&(0,l.jsxs)("div",{className:"button secondary outlined",onClick:e=>{D&&V(!1),n({setTableFields:t,tableFields:a,setRefresh:C,refreshFieldsListRef:o})},children:[(0,l.jsx)("span",{className:"symbol",children:"+"}),(0,l.jsx)("span",{children:"Add New Field"})]}),(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{if(!h)return;let t=(0,T.A)({paradigm:"JavaScript",table:h,query:y,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("JavaScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (JS)"})}),(0,l.jsx)("div",{className:"button outlined light-gray",onClick:a=>{if(!h)return;let t=(0,T.A)({paradigm:"TypeScript",table:h,query:y,user:e});t&&navigator.clipboard.writeText(t).then(()=>{window.alert("TypeScript Type Definition Copied")})},children:(0,l.jsx)("span",{children:"Copy TypeDef (TS)"})})]})]}),(0,l.jsxs)("div",{className:"flex-col w-full",style:D?{maxHeight:"200px"}:{},children:[a&&a[0]&&a.map((i,n)=>(_++,i.newTempField)?(0,l.jsx)(f,{fieldIndex:n,tableFields:a,setTableFields:t,refreshFieldsListRef:o,database:p,currentTable:h,user:e},_):(0,l.jsx)(b,{field:i,fieldIndex:n,setTargetField:s,setTableFields:t,refreshFieldsListRef:o,tableFields:a,database:p,currentTable:h,confirmedDelegetedUser:g,user:e},_)),(!v||v&&j)&&!w&&!F&&(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)("div",{className:"button outlined gray w-full more-padding",style:{borderStyle:"dashed"},onClick:e=>{D&&V(!1),n({setTableFields:t,tableFields:a,setRefresh:C,refreshFieldsListRef:o})},children:[(0,l.jsx)("span",{className:"symbol",children:"+"}),(0,l.jsx)("span",{children:"Add New Field"})]}),c&&(0,l.jsx)("button",{className:"secondary w-full py-3",onClick:e=>{window.confirm("Update Table Fields?")&&(k(!0),u&&u(k))},children:"Update Table Fields"})]})]}),x&&(0,l.jsx)(r.A,{collapse:D,setCollapse:V})]})]})}},93763:(e,a,t)=>{t.d(a,{A:()=>o});var l=t(8732),s=t(82015),i=t.n(s),n=t(46169),r=t(16757),d=t(2913);function o({targetField:e,setFieldData:a,tableFields:t,setTableFields:s,database:o,currentTable:c,user:u,setActiveEdit:m,activeClonedTable:x}){let[p,h]=i().useState(!!e?.foreignKey),[f,g]=i().useState(null),[y,v]=i().useState(null),[j,N]=i().useState(null),[w,b]=i().useState(null),[T,_]=i().useState(!1),[F,S]=i().useState("boolean"!=typeof e.foreignKey?.cascadeDelete||e.foreignKey.cascadeDelete),[C,A]=i().useState("boolean"==typeof e.foreignKey?.cascadeUpdate&&e.foreignKey.cascadeUpdate);return(0,l.jsxs)("div",{className:"flex flex-col items-start gap-2 w-full mt-2 relative",style:{minWidth:"70px"},children:[T&&(0,l.jsx)(r.A,{}),(0,l.jsxs)("label",{htmlFor:"foreign_key_field",className:"flex flex-wrap items-center gap-2 mt-2",children:[(0,l.jsx)("span",{children:"Foreign Key?"}),(0,l.jsxs)("div",{className:"dropdown-wrapper reversed text-sm items-start",children:[(0,l.jsx)("span",{className:"px-2 bg-slate-200 rounded-full hover:bg-slate-100 hidden xl:flex text-slate-600",children:"Info"}),(0,l.jsx)("div",{className:"dropdown mt-0 xl:-mt-2",children:(0,l.jsx)("span",{children:"Foriegn key links the current table to another table"})})]})]}),(0,l.jsxs)("select",{name:"foreign_key_field",id:"foreign_key_field",className:"px-2",defaultValue:e?.foreignKey?"Yes":"No",onChange:e=>{e.target.value.match(/yes/i)?(h(!0),a&&a(e=>(e.foreignKey={foreignKeyName:void 0,destinationTableName:void 0,destinationTableColumnName:void 0,cascadeDelete:!0},e))):(h(!1),a&&a(e=>(delete e.foreignKey,e)))},children:[(0,l.jsx)("option",{value:"No",children:"No"}),(0,l.jsx)("option",{value:"Yes",children:"Yes"})]}),p&&f&&(0,l.jsx)(i().Fragment,{children:(0,l.jsxs)("select",{name:"foreign_key_destination_table_name",id:"foreign_key_destination_table_name",className:"px-2",defaultValue:e?.foreignKey?.destinationTableName?e.foreignKey.destinationTableName:void 0,onChange:e=>{let t=e.target;if(e.target.value?.match(/--/)){a?a(e=>{let a=e.foreignKey;return a&&(a.destinationTableName=void 0),e}):t.dataset.destinationTableName=void 0;return}let l=f.filter(a=>a.tableName===e.target.value)[0];v(l),l?.fields&&N(l.fields),a?a(a=>{let t=a.foreignKey;return t&&(t.destinationTableName=e.target.value),a}):e.target.dataset.destinationTableName=e.target.value},children:[(0,l.jsx)("option",{value:"--",children:"--Select Table--"}),f.map((e,a)=>(0,l.jsx)("option",{value:e.tableName,children:e.tableFullName},a+1))]})}),y&&j&&(0,l.jsxs)(i().Fragment,{children:[(0,l.jsxs)("select",{name:"foreign_key_destination_table_column_name",id:"foreign_key_destination_table_column_name",className:"px-2",defaultValue:e?.foreignKey?.destinationTableColumnName?e.foreignKey.destinationTableColumnName:void 0,onChange:e=>{try{let t=j.filter(a=>a.fieldName===e.target.value)[0];if(b(t),e.target.value?.match(/--/)){a&&a(e=>{let a=e.foreignKey;return a&&(a.destinationTableColumnName=void 0),e});return}let l=`dsql_${o.user_id}_${o.db_slug}_${Date.now()}`;a?a(e=>{e.dataType=t.dataType;let a=e.foreignKey;return a&&(a.destinationTableColumnName=t.fieldName,a.destinationTableColumnType=t.dataType,a.foreignKeyName=l),e}):(e.target.dataset.dataType=t.dataType,e.target.dataset.destinationTableColumnName=t.fieldName,e.target.dataset.foreignKeyName=l)}catch(e){(0,n.A)("/api/admin/clientError",{method:"post",body:{component:"ForeignKey/lines-232-264",message:e.message,user:u}})}},children:[(0,l.jsx)("option",{value:"--",children:"--Select Column--"}),j.map((e,a)=>(0,l.jsx)("option",{value:e.fieldName,children:e.fieldName},a+1))]}),x&&w&&(0,l.jsx)("button",{className:"secondary w-full",onClick:e=>{_(!0),(0,n.A)("/api/updateClonedTableForeignKeys",{method:"post",body:{tableData:c,database:o.db_full_name,dbSlug:o.db_slug,delegated:!!window.location?.search?.match(/delegated=true/i)}},!0).then(e=>{e.success?window.alert("Foreign Key Added Successfully!"):window.alert("Update Failed, Please Try again."),setTimeout(()=>{m&&m(!1)},1e3)})},children:"Add Foreign Key"}),(0,l.jsx)(d.A,{checkBoxValues:[{title:"Cascade Delete",default:F,name:"cascade-delete",onChangeHandler:e=>{S(e.target.checked)}},{title:"Cascade Update",name:"cascade-update",default:C,onChangeHandler:e=>{A(e.target.checked)}}],smallText:!0})]}),x&&(0,l.jsx)("button",{className:"light-gray w-full",onClick:a=>{delete e.foreignKey,m&&m(!1)},children:"Cancel"})]})}},36138:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(8732);function s({targetField:e}){return(0,l.jsxs)("div",{className:"flex flex-col items-start gap-0.5",style:{minWidth:"70px"},children:[(0,l.jsx)("label",{htmlFor:"rich_text_option",children:"Text Type"}),(0,l.jsxs)("select",{name:"rich_text_option",id:"rich_text_option",className:"px-2",onChange:a=>{switch(delete e.json,delete e.richText,delete e.yaml,delete e.html,delete e.javascript,delete e.shell,a.target.value){case"plain":break;case"rte":e.richText=!0;break;case"json":e.json=!0;break;case"yaml":e.yaml=!0;break;case"html":e.html=!0;break;case"css":e.css=!0;break;case"javascript":e.javascript=!0;break;case"shell":e.shell=!0}},defaultValue:e.richText?"rte":e.json?"json":e.yaml?"yaml":e.html?"html":e.javascript?"javascript":e.shell?"shell":e.css?"css":"plain",children:[(0,l.jsx)("option",{value:"plain",children:"Plain Text"}),(0,l.jsx)("option",{value:"rte",children:"Rich Text"}),(0,l.jsx)("option",{value:"json",children:"JSON"}),(0,l.jsx)("option",{value:"yaml",children:"YAML"}),(0,l.jsx)("option",{value:"html",children:"HTML"}),(0,l.jsx)("option",{value:"css",children:"CSS"}),(0,l.jsx)("option",{value:"javascript",children:"Javascript"}),(0,l.jsx)("option",{value:"shell",children:"Shell"})]})]})}t(82015)},60424:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(42960);function s({paradigm:e,table:a,query:t,user:s}){let i="";try{let s=`DSQL_${t.single}_${t.single_table}`.toUpperCase(),r=a.fields;function n(e){return e?.match(/int/i)?"number":(e?.match(/text|varchar|timestamp/i),"string")}let d=[],o=[];d.push(`type ${s} = {`),o.push(`/**
|
|
* @typedef {object} ${s}`),r.forEach(e=>{let a=e.nullValue?"?":e.fieldName?.match(l.A)?"?":"";d.push(` ${e.fieldName}${a}: ${n(e.dataType||"")};`),o.push(` * @property {${n(e.dataType||"")}${a}} ${e.fieldName}`)}),d.push("}"),o.push(" */"),e?.match(/javascript/i)&&(i=o.join("\n")),e?.match(/typescript/i)&&(i=d.join("\n"))}catch(e){console.log(e.message),i=null}return i}},2913:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(8732);function s({name:e,checkBoxValues:a,setAlert:t,labelColor:s,flexRow:i,baseText:n,smallText:r,className:d}){return(0,l.jsx)("div",{className:"flex items-start gap-x-4"+(i?" flex-row flex-wrap gap-y-2 ":" flex-col gap-y-4 ")+(d||""),children:a.map((a,i)=>{let{payload:d,title:o,onChangeHandler:c,fixed:u,jsx:m}=a,x=a.name?`${e}-${a.name}`:d?e+"-"+d:e;return(0,l.jsxs)("div",{className:"flex items-center"+(a.default&&u?" pointer-events-none":"")+(r?" gap-1 ":" gap-2 ")+(a?.className?a.className:""),children:[(0,l.jsx)("input",{className:"m-0"+(r?" w-4 h-4":" w-5 h-5"),type:"checkbox",defaultChecked:!!a.default,name:x,id:x,onChange:e=>{t&&t(null),c&&c(e,a)},value:d,style:{minWidth:"20px"},...a.props}),m||(0,l.jsx)("label",{htmlFor:x,className:"m-0 "+(s||"text-slate-800 dark:text-white/80")+(n||r?" text-base":" text-lg"),children:o})]},i+1)})})}t(82015)},51339:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(8732);function s({collapse:e,setCollapse:a}){return(0,l.jsxs)("div",{className:"collapse-block"+(e?" -mt-16 -mb-6 pt-10":" mt-0 mb-0 p-0"),onClick:t=>{e?a(!1):a(!0)},children:[(0,l.jsx)("span",{children:e?"Expand":"Collapse"}),(0,l.jsx)("img",{src:"/images/down-arrow-dark.svg",alt:"Down Arrow",width:16,className:"dark:hidden opacity-30 "+(e?"":"rotate-180")}),(0,l.jsx)("img",{src:"/images/down-arrow-white.svg",alt:"Down Arrow",width:16,className:"opacity-30 hidden dark:flex "+(e?"":"rotate-180")})]})}t(82015)},84483:(e,a,t)=>{t.d(a,{A:()=>s});var l=t(8732);function s({children:e,open:a,setOpen:t,onClose:s,maxWidth:i}){return(0,l.jsx)(l.Fragment,{})}t(82015),t(1976),t(58150)},42960:(e,a,t)=>{t.d(a,{A:()=>l});let l=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},72272:(e,a,t)=>{t.d(a,{A:()=>d});var l=t(77047),s=t(29021),i=t.n(s),n=t(33873),r=t.n(n);function d({userId:e}){try{let a=r().resolve(process.cwd(),`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${e}/main.json`);return JSON.parse(i().readFileSync(a,"utf-8"))}catch(e){return(0,l.A)({component:"grabUserSchemaData",message:e.message}),null}}},77047:(e,a,t)=>{t.d(a,{A:()=>i});var l=t(29021),s=t.n(l);async function i({user:e,message:a,component:t,noMail:l,req:i}){let n=new Date,r=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],a=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],l=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||l||a||i.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let l=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${a}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(l+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),i?.url&&(l+=`
|
|
URL: ${i.url}`),i?.body&&(l+=`
|
|
Request Body: ${JSON.stringify(i.body,null,4)}`),r&&(l+=`
|
|
IP: ${r}`),l+=`
|
|
Date: ${n.toDateString()}
|
|
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let d=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",l),s().appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${d}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},94327:e=>{e.exports=JSON.parse('[{"title":"VARCHAR","name":"VARCHAR","value":"0-255","argument":true,"description":"Varchar is simply letters and numbers within the range 0 - 255","maxValue":255},{"title":"TINYINT","name":"TINYINT","value":"0-100","description":"TINYINT means Integers: 0 to 100","maxValue":127},{"title":"SMALLINT","name":"SMALLINT","value":"0-255","description":"SMALLINT means Integers: 0 to 240933","maxValue":32767},{"title":"MEDIUMINT","name":"MEDIUMINT","value":"0-255","description":"MEDIUMINT means Integers: 0 to 1245568545560","maxValue":8388607},{"title":"INT","name":"INT","value":"0-255","description":"INT means Integers: 0 to 12560","maxValue":2147483647},{"title":"BIGINT","name":"BIGINT","value":"0-255","description":"BIGINT means Integers: 0 to 1245569056767568545560","maxValue":2e+63},{"title":"TINYTEXT","name":"TINYTEXT","value":"0-255","description":"Text with 255 max characters","maxValue":127},{"title":"TEXT","name":"TEXT","value":"0-100","description":"MEDIUMTEXT is just text with max length 16,777,215","maxValue":127},{"title":"MEDIUMTEXT","name":"MEDIUMTEXT","value":"0-255","description":"MEDIUMTEXT is just text with max length 16,777,215","maxValue":127},{"title":"LONGTEXT","name":"LONGTEXT","value":"0-255","description":"LONGTEXT is just text with max length 4,294,967,295","maxValue":127},{"title":"UUID","name":"UUID","valueLiteral":"UUID()","description":"A Unique ID"}]')}}; |