diff --git a/smart-setting-components/ejs.min.cjs b/smart-setting-components/ejs.min.cjs deleted file mode 100644 index 5d3c90d8..00000000 --- a/smart-setting-components/ejs.min.cjs +++ /dev/null @@ -1 +0,0 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ejs=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i1;if(options.cache){if(!filename){throw new Error("cache option requires a filename")}func=exports.cache.get(filename);if(func){return func}if(!hasTemplate){template=fileLoader(filename).toString().replace(_BOM,"")}}else if(!hasTemplate){if(!filename){throw new Error("Internal EJS error: no file name or template "+"provided")}template=fileLoader(filename).toString().replace(_BOM,"")}func=exports.compile(template,options);if(options.cache){exports.cache.set(filename,func)}return func}function tryHandleCache(options,data,cb){var result;if(!cb){if(typeof exports.promiseImpl=="function"){return new exports.promiseImpl(function(resolve,reject){try{result=handleCache(options)(data);resolve(result)}catch(err){reject(err)}})}else{throw new Error("Please provide a callback function")}}else{try{result=handleCache(options)(data)}catch(err){return cb(err)}cb(null,result)}}function fileLoader(filePath){return exports.fileLoader(filePath)}function includeFile(path,options){var opts=utils.shallowCopy(utils.createNullProtoObjWherePossible(),options);opts.filename=getIncludePath(path,opts);if(typeof options.includer==="function"){var includerResult=options.includer(path,opts.filename);if(includerResult){if(includerResult.filename){opts.filename=includerResult.filename}if(includerResult.template){return handleCache(opts,includerResult.template)}}}return handleCache(opts)}function rethrow(err,str,flnm,lineno,esc){var lines=str.split("\n");var start=Math.max(lineno-3,0);var end=Math.min(lines.length,lineno+3);var filename=esc(flnm);var context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" >> ":" ")+curr+"| "+line}).join("\n");err.path=filename;err.message=(filename||"ejs")+":"+lineno+"\n"+context+"\n\n"+err.message;throw err}function stripSemi(str){return str.replace(/;(\s*$)/,"$1")}exports.compile=function compile(template,opts){var templ;if(opts&&opts.scope){if(!scopeOptionWarned){console.warn("`scope` option is deprecated and will be removed in EJS 3");scopeOptionWarned=true}if(!opts.context){opts.context=opts.scope}delete opts.scope}templ=new Template(template,opts);return templ.compile()};exports.render=function(template,d,o){var data=d||utils.createNullProtoObjWherePossible();var opts=o||utils.createNullProtoObjWherePossible();if(arguments.length==2){utils.shallowCopyFromList(opts,data,_OPTS_PASSABLE_WITH_DATA)}return handleCache(opts,template)(data)};exports.renderFile=function(){var args=Array.prototype.slice.call(arguments);var filename=args.shift();var cb;var opts={filename:filename};var data;var viewOpts;if(typeof arguments[arguments.length-1]=="function"){cb=args.pop()}if(args.length){data=args.shift();if(args.length){utils.shallowCopy(opts,args.pop())}else{if(data.settings){if(data.settings.views){opts.views=data.settings.views}if(data.settings["view cache"]){opts.cache=true}viewOpts=data.settings["view options"];if(viewOpts){utils.shallowCopy(opts,viewOpts)}}utils.shallowCopyFromList(opts,data,_OPTS_PASSABLE_WITH_DATA_EXPRESS)}opts.filename=filename}else{data=utils.createNullProtoObjWherePossible()}return tryHandleCache(opts,data,cb)};exports.Template=Template;exports.clearCache=function(){exports.cache.reset()};function Template(text,opts){opts=opts||utils.createNullProtoObjWherePossible();var options=utils.createNullProtoObjWherePossible();this.templateText=text;this.mode=null;this.truncate=false;this.currentLine=1;this.source="";options.client=opts.client||false;options.escapeFunction=opts.escape||opts.escapeFunction||utils.escapeXML;options.compileDebug=opts.compileDebug!==false;options.debug=!!opts.debug;options.filename=opts.filename;options.openDelimiter=opts.openDelimiter||exports.openDelimiter||_DEFAULT_OPEN_DELIMITER;options.closeDelimiter=opts.closeDelimiter||exports.closeDelimiter||_DEFAULT_CLOSE_DELIMITER;options.delimiter=opts.delimiter||exports.delimiter||_DEFAULT_DELIMITER;options.strict=opts.strict||false;options.context=opts.context;options.cache=opts.cache||false;options.rmWhitespace=opts.rmWhitespace;options.root=opts.root;options.includer=opts.includer;options.outputFunctionName=opts.outputFunctionName;options.localsName=opts.localsName||exports.localsName||_DEFAULT_LOCALS_NAME;options.views=opts.views;options.async=opts.async;options.destructuredLocals=opts.destructuredLocals;options.legacyInclude=typeof opts.legacyInclude!="undefined"?!!opts.legacyInclude:true;if(options.strict){options._with=false}else{options._with=typeof opts._with!="undefined"?opts._with:true}this.opts=options;this.regex=this.createRegex()}Template.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};Template.prototype={createRegex:function(){var str=_REGEX_STRING;var delim=utils.escapeRegExpChars(this.opts.delimiter);var open=utils.escapeRegExpChars(this.opts.openDelimiter);var close=utils.escapeRegExpChars(this.opts.closeDelimiter);str=str.replace(/%/g,delim).replace(//g,close);return new RegExp(str)},compile:function(){var src;var fn;var opts=this.opts;var prepended="";var appended="";var escapeFn=opts.escapeFunction;var ctor;var sanitizedFilename=opts.filename?JSON.stringify(opts.filename):"undefined";if(!this.source){this.generateSource();prepended+=' var __output = "";\n'+" function __append(s) { if (s !== undefined && s !== null) __output += s }\n";if(opts.outputFunctionName){if(!_JS_IDENTIFIER.test(opts.outputFunctionName)){throw new Error("outputFunctionName is not a valid JS identifier.")}prepended+=" var "+opts.outputFunctionName+" = __append;"+"\n"}if(opts.localsName&&!_JS_IDENTIFIER.test(opts.localsName)){throw new Error("localsName is not a valid JS identifier.")}if(opts.destructuredLocals&&opts.destructuredLocals.length){var destructuring=" var __locals = ("+opts.localsName+" || {}),\n";for(var i=0;i0){destructuring+=",\n "}destructuring+=name+" = __locals."+name}prepended+=destructuring+";\n"}if(opts._with!==false){prepended+=" with ("+opts.localsName+" || {}) {"+"\n";appended+=" }"+"\n"}appended+=" return __output;"+"\n";this.source=prepended+this.source+appended}if(opts.compileDebug){src="var __line = 1"+"\n"+" , __lines = "+JSON.stringify(this.templateText)+"\n"+" , __filename = "+sanitizedFilename+";"+"\n"+"try {"+"\n"+this.source+"} catch (e) {"+"\n"+" rethrow(e, __lines, __filename, __line, escapeFn);"+"\n"+"}"+"\n"}else{src=this.source}if(opts.client){src="escapeFn = escapeFn || "+escapeFn.toString()+";"+"\n"+src;if(opts.compileDebug){src="rethrow = rethrow || "+rethrow.toString()+";"+"\n"+src}}if(opts.strict){src='"use strict";\n'+src}if(opts.debug){console.log(src)}if(opts.compileDebug&&opts.filename){src=src+"\n"+"//# sourceURL="+sanitizedFilename+"\n"}try{if(opts.async){try{ctor=new Function("return (async function(){}).constructor;")()}catch(e){if(e instanceof SyntaxError){throw new Error("This environment does not support async/await")}else{throw e}}}else{ctor=Function}fn=new ctor(opts.localsName+", escapeFn, include, rethrow",src)}catch(e){if(e instanceof SyntaxError){if(opts.filename){e.message+=" in "+opts.filename}e.message+=" while compiling ejs\n\n";e.message+="If the above error is not helpful, you may want to try EJS-Lint:\n";e.message+="https://github.com/RyanZim/EJS-Lint";if(!opts.async){e.message+="\n";e.message+="Or, if you meant to create an async function, pass `async: true` as an option."}}throw e}var returnedFn=opts.client?fn:function anonymous(data){var include=function(path,includeData){var d=utils.shallowCopy(utils.createNullProtoObjWherePossible(),data);if(includeData){d=utils.shallowCopy(d,includeData)}return includeFile(path,opts)(d)};return fn.apply(opts.context,[data||utils.createNullProtoObjWherePossible(),escapeFn,include,rethrow])};if(opts.filename&&typeof Object.defineProperty==="function"){var filename=opts.filename;var basename=path.basename(filename,path.extname(filename));try{Object.defineProperty(returnedFn,"name",{value:basename,writable:false,enumerable:false,configurable:true})}catch(e){}}return returnedFn},generateSource:function(){var opts=this.opts;if(opts.rmWhitespace){this.templateText=this.templateText.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")}this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var self=this;var matches=this.parseTemplateText();var d=this.opts.delimiter;var o=this.opts.openDelimiter;var c=this.opts.closeDelimiter;if(matches&&matches.length){matches.forEach(function(line,index){var closing;if(line.indexOf(o+d)===0&&line.indexOf(o+d+d)!==0){closing=matches[index+2];if(!(closing==d+c||closing=="-"+d+c||closing=="_"+d+c)){throw new Error('Could not find matching close tag for "'+line+'".')}}self.scanLine(line)})}},parseTemplateText:function(){var str=this.templateText;var pat=this.regex;var result=pat.exec(str);var arr=[];var firstPos;while(result){firstPos=result.index;if(firstPos!==0){arr.push(str.substring(0,firstPos));str=str.slice(firstPos)}arr.push(result[0]);str=str.slice(result[0].length);result=pat.exec(str)}if(str){arr.push(str)}return arr},_addOutput:function(line){if(this.truncate){line=line.replace(/^(?:\r\n|\r|\n)/,"");this.truncate=false}if(!line){return line}line=line.replace(/\\/g,"\\\\");line=line.replace(/\n/g,"\\n");line=line.replace(/\r/g,"\\r");line=line.replace(/"/g,'\\"');this.source+=' ; __append("'+line+'")'+"\n"},scanLine:function(line){var self=this;var d=this.opts.delimiter;var o=this.opts.openDelimiter;var c=this.opts.closeDelimiter;var newLineCount=0;newLineCount=line.split("\n").length-1;switch(line){case o+d:case o+d+"_":this.mode=Template.modes.EVAL;break;case o+d+"=":this.mode=Template.modes.ESCAPED;break;case o+d+"-":this.mode=Template.modes.RAW;break;case o+d+"#":this.mode=Template.modes.COMMENT;break;case o+d+d:this.mode=Template.modes.LITERAL;this.source+=' ; __append("'+line.replace(o+d+d,o+d)+'")'+"\n";break;case d+d+c:this.mode=Template.modes.LITERAL;this.source+=' ; __append("'+line.replace(d+d+c,d+c)+'")'+"\n";break;case d+c:case"-"+d+c:case"_"+d+c:if(this.mode==Template.modes.LITERAL){this._addOutput(line)}this.mode=null;this.truncate=line.indexOf("-")===0||line.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case Template.modes.EVAL:case Template.modes.ESCAPED:case Template.modes.RAW:if(line.lastIndexOf("//")>line.lastIndexOf("\n")){line+="\n"}}switch(this.mode){case Template.modes.EVAL:this.source+=" ; "+line+"\n";break;case Template.modes.ESCAPED:this.source+=" ; __append(escapeFn("+stripSemi(line)+"))"+"\n";break;case Template.modes.RAW:this.source+=" ; __append("+stripSemi(line)+")"+"\n";break;case Template.modes.COMMENT:break;case Template.modes.LITERAL:this._addOutput(line);break}}else{this._addOutput(line)}}if(self.opts.compileDebug&&newLineCount){this.currentLine+=newLineCount;this.source+=" ; __line = "+this.currentLine+"\n"}}};exports.escapeXML=utils.escapeXML;exports.__express=exports.renderFile;exports.VERSION=_VERSION_STRING;exports.name=_NAME;if(typeof window!="undefined"){window.ejs=exports}},{"../package.json":6,"./utils":2,fs:3,path:4}],2:[function(require,module,exports){"use strict";var regExpChars=/[|\\{}()[\]^$+*?.]/g;var hasOwnProperty=Object.prototype.hasOwnProperty;var hasOwn=function(obj,key){return hasOwnProperty.apply(obj,[key])};exports.escapeRegExpChars=function(string){if(!string){return""}return String(string).replace(regExpChars,"\\$&")};var _ENCODE_HTML_RULES={"&":"&","<":"<",">":">",'"':""","'":"'"};var _MATCH_HTML=/[&<>'"]/g;function encode_char(c){return _ENCODE_HTML_RULES[c]||c}var escapeFuncStr="var _ENCODE_HTML_RULES = {\n"+' "&": "&"\n'+' , "<": "<"\n'+' , ">": ">"\n'+' , \'"\': """\n'+' , "\'": "'"\n'+" }\n"+" , _MATCH_HTML = /[&<>'\"]/g;\n"+"function encode_char(c) {\n"+" return _ENCODE_HTML_RULES[c] || c;\n"+"};\n";exports.escapeXML=function(markup){return markup==undefined?"":String(markup).replace(_MATCH_HTML,encode_char)};function escapeXMLToString(){return Function.prototype.toString.call(this)+";\n"+escapeFuncStr}try{if(typeof Object.defineProperty==="function"){Object.defineProperty(exports.escapeXML,"toString",{value:escapeXMLToString})}else{exports.escapeXML.toString=escapeXMLToString}}catch(err){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}exports.shallowCopy=function(to,from){from=from||{};if(to!==null&&to!==undefined){for(var p in from){if(!hasOwn(from,p)){continue}if(p==="__proto__"||p==="constructor"){continue}to[p]=from[p]}}return to};exports.shallowCopyFromList=function(to,from,list){list=list||[];from=from||{};if(to!==null&&to!==undefined){for(var i=0;i=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up--;up){parts.unshift("..")}}return parts}exports.resolve=function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:process.cwd();if(typeof path!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){continue}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=path.charAt(0)==="/"}resolvedPath=normalizeArray(filter(resolvedPath.split("/"),function(p){return!!p}),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."};exports.normalize=function(path){var isAbsolute=exports.isAbsolute(path),trailingSlash=substr(path,-1)==="/";path=normalizeArray(filter(path.split("/"),function(p){return!!p}),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path};exports.isAbsolute=function(path){return path.charAt(0)==="/"};exports.join=function(){var paths=Array.prototype.slice.call(arguments,0);return exports.normalize(filter(paths,function(p,index){if(typeof p!=="string"){throw new TypeError("Arguments to path.join must be strings")}return p}).join("/"))};exports.relative=function(from,to){from=exports.resolve(from).substr(1);to=exports.resolve(to).substr(1);function trim(arr){var start=0;for(;start=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i=1;--i){code=path.charCodeAt(i);if(code===47){if(!matchedSlash){end=i;break}}else{matchedSlash=false}}if(end===-1)return hasRoot?"/":".";if(hasRoot&&end===1){return"/"}return path.slice(0,end)};function basename(path){if(typeof path!=="string")path=path+"";var start=0;var end=-1;var matchedSlash=true;var i;for(i=path.length-1;i>=0;--i){if(path.charCodeAt(i)===47){if(!matchedSlash){start=i+1;break}}else if(end===-1){matchedSlash=false;end=i+1}}if(end===-1)return"";return path.slice(start,end)}exports.basename=function(path,ext){var f=basename(path);if(ext&&f.substr(-1*ext.length)===ext){f=f.substr(0,f.length-ext.length)}return f};exports.extname=function(path){if(typeof path!=="string")path=path+"";var startDot=-1;var startPart=0;var end=-1;var matchedSlash=true;var preDotState=0;for(var i=path.length-1;i>=0;--i){var code=path.charCodeAt(i);if(code===47){if(!matchedSlash){startPart=i+1;break}continue}if(end===-1){matchedSlash=false;end=i+1}if(code===46){if(startDot===-1)startDot=i;else if(preDotState!==1)preDotState=1}else if(startDot!==-1){preDotState=-1}}if(startDot===-1||end===-1||preDotState===0||preDotState===1&&startDot===end-1&&startDot===startPart+1){return""}return path.slice(startDot,end)};function filter(xs,f){if(xs.filter)return xs.filter(f);var res=[];for(var i=0;i1){for(var i=1;i (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"mocha -u tdd"}}},{}]},{},[1])(1)}); diff --git a/smart-setting-components/package-lock.json b/smart-setting-components/package-lock.json deleted file mode 100644 index d9027ab0..00000000 --- a/smart-setting-components/package-lock.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "smart-setting", - "version": "1.0.1", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "smart-setting", - "version": "1.0.1", - "license": "MIT" - }, - "../ejs.min": { - "extraneous": true - }, - "../ejs.min.js": { - "extraneous": true - } - } -} diff --git a/smart-setting-components/package.json b/smart-setting-components/package.json deleted file mode 100644 index d037cc28..00000000 --- a/smart-setting-components/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "smart-setting", - "author": "Brian Joseph Petro (🌴 Brian)", - "license": "MIT", - "type": "module", - "version": "1.0.1", - "description": "Minimal dependency renderer for settings components designed for Smart Environments.", - "main": "smart_settings.js", - "repository": { - "type": "git", - "url": "brianpetro/jsbrains" - }, - "bugs": { - "url": "https://github.com/brianpetro/jsbrains/issues" - }, - "scripts": { - "test": "npx ava --verbose" - }, - "homepage": "https://jsbrains.org" -} diff --git a/smart-setting-components/smart_setting.js b/smart-setting-components/smart_setting.js deleted file mode 100644 index baee35cc..00000000 --- a/smart-setting-components/smart_setting.js +++ /dev/null @@ -1,198 +0,0 @@ -export class SmartSetting { - constructor(element) { - this.element = element; - this.container = this.createSettingItemContainer(); - } - add_text(configurator) { - const controlContainer = this.container.querySelector('.control'); - const textInput = document.createElement('input'); - textInput.type = 'text'; - textInput.spellcheck = false; - controlContainer.appendChild(textInput); - configurator({ - inputEl: textInput, - setPlaceholder: (placeholder) => textInput.placeholder = placeholder, - setValue: (value) => textInput.value = value, - onChange: (callback) => textInput.addEventListener('change', () => callback(textInput.value)) - }); - this.element.appendChild(this.container); - } - add_dropdown(configurator) { - const controlContainer = this.container.querySelector('.control'); - const select = document.createElement('select'); - controlContainer.appendChild(select); - configurator({ - inputEl: select, - addOption: (value, name, selected = false) => { - const option = document.createElement('option'); - option.value = value; - option.textContent = name; - select.appendChild(option); - if (selected) { - option.selected = true; - option.classList.add("selected"); - } - if (value === "") option.disabled = true; - }, - onChange: (callback) => select.addEventListener('change', () => callback(select.value)), - setValue: (value) => select.value = value - }); - this.element.appendChild(this.container); - } - add_button(configurator) { - const controlContainer = this.container.querySelector('.control'); - const button = document.createElement('button'); - controlContainer.appendChild(button); - configurator({ - inputEl: button, - setButtonText: (text) => button.textContent = text, - onClick: (callback) => button.addEventListener('click', callback) - }); - this.element.appendChild(this.container); - } - create_setting_item_container() { - const container = document.createElement('div'); - container.classList.add('setting-item'); - const infoContainer = document.createElement('div'); - infoContainer.classList.add('info'); - container.appendChild(infoContainer); - // Placeholders for name and description - const namePlaceholder = document.createElement('div'); - namePlaceholder.classList.add('name'); - infoContainer.appendChild(namePlaceholder); - // const tagPlaceholder = document.createElement('div'); - // tagPlaceholder.classList.add('tag'); - // infoContainer.appendChild(tagPlaceholder); - // const descPlaceholder = document.createElement('div'); - // descPlaceholder.classList.add('description'); - // infoContainer.appendChild(descPlaceholder); - const controlContainer = document.createElement('div'); - controlContainer.classList.add('control'); - container.appendChild(controlContainer); - return container; - } - add_toggle(configurator) { - const controlContainer = this.container.querySelector('.control'); - const checkboxContainer = document.createElement('div'); - checkboxContainer.classList.add('checkbox-container'); - controlContainer.appendChild(checkboxContainer); - const checkbox = document.createElement('input'); - checkbox.type = 'checkbox'; - checkbox.tabIndex = 0; - checkboxContainer.appendChild(checkbox); - configurator({ - setValue: (value) => { - checkbox.checked = value; - checkbox.value = value; - checkboxContainer.classList.toggle('is-enabled', value); - }, - onChange: (callback) => checkbox.addEventListener('change', () => { - callback(checkbox.checked); - checkboxContainer.classList.toggle('is-enabled', checkbox.checked); - }) - }); - this.element.appendChild(this.container); - } - add_text_area(configurator) { - const controlContainer = this.container.querySelector('.control'); - const textarea = document.createElement('textarea'); - textarea.spellcheck = false; - controlContainer.appendChild(textarea); - configurator({ - inputEl: textarea, - setPlaceholder: (placeholder) => textarea.placeholder = placeholder, - setValue: (value) => textarea.value = value, - onChange: (callback) => textarea.addEventListener('change', () => callback(textarea.value)) - }); - this.element.appendChild(this.container); - } - add_folder_select(configurator) { - const container = this.container.querySelector('.control'); - const folder_select = document.createElement('div'); - folder_select.classList.add('folder-select'); - container.appendChild(folder_select); - const currentFolder = document.createElement('span'); - // currentFolder.type = 'text'; - currentFolder.classList.add('current'); - container.appendChild(currentFolder); - const browse_btn = document.createElement('button'); - browse_btn.textContent = 'Browse'; - browse_btn.classList.add('browse-button'); - container.appendChild(browse_btn); - configurator({ - inputEl: currentFolder, - setPlaceholder: (placeholder) => currentFolder.placeholder = placeholder, - setValue: (value) => currentFolder.innerText = value, - }); - this.element.appendChild(this.container); - } - add_file_select(configurator) { - const container = this.container.querySelector('.control'); - const file_select = document.createElement('div'); - file_select.classList.add('file-select'); - container.appendChild(file_select); - const current_file = document.createElement('span'); - // current_file.type = 'text'; - current_file.classList.add('current'); - container.appendChild(current_file); - const browse_btn = document.createElement('button'); - browse_btn.textContent = 'Browse'; - browse_btn.classList.add('browse-button'); - container.appendChild(browse_btn); - configurator({ - inputEl: current_file, - setPlaceholder: (placeholder) => current_file.placeholder = placeholder, - setValue: (value) => current_file.innerText = value, - }); - this.element.appendChild(this.container); - } - set_name(name) { - const nameElement = this.container.querySelector('.name'); - if (nameElement) { - nameElement.innerHTML = name; - } else { - // Create the element if it doesn't exist - const newNameElement = document.createElement('div'); - newNameElement.classList.add('name'); - newNameElement.innerHTML = name; - // this.element.appendChild(newNameElement); - const info_container = this.container.querySelector('.info'); - info_container.prepend(newNameElement); - } - } - set_desc(description) { - const descElement = this.container.querySelector('.description'); - if (descElement) { - descElement.innerHTML = description; - } else { - // Create the element if it doesn't exist - const newDescElement = document.createElement('div'); - newDescElement.classList.add('description'); - newDescElement.innerHTML = description; - // this.element.appendChild(newDescElement); - const info_container = this.container.querySelector('.info'); - info_container.appendChild(newDescElement); - } - } - set_tooltip(tooltip) { - const elm = this.container; - const control_element = elm.querySelector('.control'); - control_element.setAttribute('title', tooltip); - elm.setAttribute('title', tooltip); - const tooltip_container = document.createElement('div'); - tooltip_container.classList.add('tooltip'); - tooltip_container.innerHTML = tooltip; - elm.insertAdjacentElement('afterend', tooltip_container); - } - // aliases - addText(configurator) { return this.add_text(configurator); } - addDropdown(configurator) { return this.add_dropdown(configurator); } - addButton(configurator) { return this.add_button(configurator); } - createSettingItemContainer() { return this.create_setting_item_container(); } - addToggle(configurator) { return this.add_toggle(configurator); } - addTextArea(configurator) { return this.add_text_area(configurator); } - addFolderSelect(configurator) { return this.add_folder_select(configurator); } - addFileSelect(configurator) { return this.add_file_select(configurator); } - setName(name) { return this.set_name(name); } - setDesc(description) { return this.set_desc(description); } -} diff --git a/smart-setting-components/smart_settings.js b/smart-setting-components/smart_settings.js deleted file mode 100644 index ed257f88..00000000 --- a/smart-setting-components/smart_settings.js +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) Brian Joseph Petro - -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: - -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -export class SmartSettings { - constructor(main, opts={}) { - this.main = main; - this.opts = { - ...(this.main.smart_env_config || this.main.opts || {}), - ...opts, - }; - this._container = null; - this.debouncer = {}; // debounce changes - } - get rel_instance() { return this.opts.rel_instance ?? this; } - get setting_class() { return this.opts.smart_setting_class; } - get settings() { return this.main.settings; } - set settings(settings) { this.main.settings = settings; } - async render_components(container) { - const components = container.querySelectorAll(".setting-component"); - await Promise.all(Array.from(components).map(async (elm) => { - await this.render_component(new this.setting_class(elm), elm); - })); - } - get_callback_fx(callback_str) { - return this.rel_instance[callback_str]; - } - async render_component(setting_elm, elm) { - if (elm.dataset.name) setting_elm.setName(elm.dataset.name); - if (elm.dataset.description) setting_elm.setDesc(elm.dataset.description); - const setting = elm.dataset.setting; - if (elm.dataset.type === "text" || elm.dataset.type === "string") { - setting_elm.addText(text => { - text.setPlaceholder(elm.dataset.placeholder || ""); - const setting_value = elm.dataset.value || this.get_setting(setting) || ""; - if(setting_value) text.setValue(setting_value); - if (!elm.dataset.btn) { - text.onChange(async (value) => { - if (elm.dataset.format === "array") value = value.split(","); - else value = value.trim(); - this.handle_on_change(setting, value, elm); - }); - } - }); - } else if (elm.dataset.type === "password") { - setting_elm.addText(text => { - text.inputEl.type = "password"; - text.setPlaceholder(elm.dataset.placeholder || ""); - const setting_value = this.get_setting(setting); - if(setting_value) text.setValue(setting_value); - text.onChange(async (value) => this.handle_on_change(setting, value, elm)); - }); - } else if (elm.dataset.type === "number") { - setting_elm.addText(number => { - number.inputEl.type = "number"; - number.setPlaceholder(elm.dataset.placeholder || ""); - const setting_value = this.get_setting(setting); - if(typeof setting_value !== 'undefined') number.inputEl.value = parseInt(this.get_setting(setting)); - number.inputEl.min = elm.dataset.min || 0; - if (elm.dataset.max) number.inputEl.max = elm.dataset.max; - number.onChange(async (value) => this.handle_on_change(setting, parseInt(value), elm)); - }); - } else if (elm.dataset.type === "dropdown") { - const setting_value = this.get_setting(setting); - const options = elm.dataset.optionsCallback - ? await this.get_callback_fx(elm.dataset.optionsCallback)() - : Object.entries(elm.dataset).reduce((acc, [k, v]) => { - if (!k.startsWith('option')) return acc; - const [value, name] = v.split("|"); - acc.push({ value, name: name || value }); - return acc; - }, []) - ; - setting_elm.addDropdown(dropdown => { - if(elm.dataset.required) dropdown.inputEl.setAttribute("required", true); - options.forEach(option => dropdown.addOption(option.value, option.name ?? option.value, option.value === setting_value)); - dropdown.onChange(async (value) => this.handle_on_change(setting, value, elm)); - dropdown.setValue(setting_value); - }); - } else if (elm.dataset.type === "button") { - setting_elm.addButton(button => { - button.setButtonText(elm.dataset.btnText || elm.dataset.name); - button.onClick(async () => { - if (elm.dataset.confirm) { - const confirmation_message = elm.dataset.confirm; - if (!confirm(confirmation_message)) return; - } - if (elm.dataset.href) this.open_url(elm.dataset.href); - if (elm.dataset.callback) this.get_callback_fx(elm.dataset.callback)(setting, null, setting_elm); - }); - }); - } else if (elm.dataset.type === "toggle") { - setting_elm.addToggle(toggle => { - let checkbox_val = elm.dataset.value ?? this.get_setting(setting) ?? true; - if (typeof checkbox_val === 'string') { - checkbox_val = checkbox_val.toLowerCase() === 'true'; - } - toggle.setValue(checkbox_val); - toggle.onChange(async (value) => this.handle_on_change(setting, value, elm)); - }); - } else if (elm.dataset.type === "textarea") { - setting_elm.addTextArea(textarea => { - textarea.setPlaceholder(elm.dataset.placeholder || ""); - const current_setting_value = this.get_setting(setting); - textarea.setValue(elm.dataset.value || current_setting_value || ""); - textarea.onChange(async (value) => { - console.log("textarea value changed"); - // if(elm.dataset.format === "array") value = value.split("\n"); - value = value.split("\n").map(v => v.trim()).filter(v => v).join("\n"); - this.handle_on_change(setting, value, elm); - }); - }); - } else if (elm.dataset.type === "folder") { - setting_elm.addFolderSelect(folder_select => { - folder_select.setPlaceholder(elm.dataset.placeholder || ""); - const value = this.get_setting(setting); - if(typeof value !== 'undefined') folder_select.setValue(value); - folder_select.inputEl.closest('div').addEventListener("click", () => { - this.handle_folder_select(setting, value, elm); - }); - }); - } else if (elm.dataset.type === "text-file") { - setting_elm.addFileSelect(file_select => { - file_select.setPlaceholder(elm.dataset.placeholder || ""); - const value = this.get_setting(setting); - if(typeof value !== 'undefined') file_select.setValue(value); - file_select.inputEl.closest('div').addEventListener("click", () => { - this.handle_file_select(setting, value, elm); - }); - }); - } - if(elm.dataset.tooltip) setting_elm.set_tooltip(elm.dataset.tooltip); - // add button to any setting - if (elm.dataset.btn) { - setting_elm.addButton(button => { - button.setButtonText(elm.dataset.btn); - button.inputEl.addEventListener("click", (e) => { - if (elm.dataset.btnCallback && typeof this[elm.dataset.btnCallback] === "function") this[elm.dataset.btnCallback](setting, null, setting_elm); - else if (elm.dataset.btnHref) this.open_url(elm.dataset.btnHref); - else if (elm.dataset.callback && typeof this.get_callback_fx(elm.dataset.callback) === "function") this.get_callback_fx(elm.dataset.callback)(setting, null, setting_elm); - else if (elm.dataset.href) this.open_url(elm.dataset.href); - else console.error("No callback or href found for button."); - }); - if (elm.dataset.btnDisabled || (elm.dataset.disabled && elm.dataset.btnDisabled !== "false")) button.inputEl.disabled = true; - }); - } - if (elm.dataset.disabled && elm.dataset.disabled !== "false") { - elm.classList.add("disabled"); - elm.querySelector("input, select, textarea, button").disabled = true; - } - if (elm.dataset.hidden && elm.dataset.hidden !== "false") elm.style.display = "none"; - } - open_url(url) { window.open(url); } - handle_on_change(setting, value, elm=null) { - // debounce - if(this.debouncer[setting]) clearTimeout(this.debouncer[setting]); - this.debouncer[setting] = setTimeout(async () => { - const changed = await this.update(setting, value, elm); // save setting - console.log("setting changed: " + changed); - if(changed && elm?.dataset.callback){ // call callback if setting changed - if(!this.get_callback_fx(elm.dataset.callback)) return console.error(`Callback ${elm.dataset.callback} not found.`); - this.get_callback_fx(elm.dataset.callback)(setting, value, elm); - } - if(elm?.dataset.isScope) this.re_render(); - this.debouncer[setting] = null; - }, 300); - } - re_render() { this.opts['re_render']?.(); } - get_setting(setting_path) { - // should handle progress_labels.success.msg_vars.1 - const setting_keys = setting_path.split("."); - let value = this.settings; - for (const key of setting_keys) { - if (typeof value[key] === 'undefined'){ - console.log(`missing key: ${key} in` + setting_path); - return null; // Handle missing nested properties - } - value = value[key]; - } - if(Array.isArray(value)) return value.join("\n"); - return value; - } - async update(setting_path, value, elm) { - const setting_keys = setting_path.split("."); // should handle progress_labels.success.msg_vars.1 - let setting_obj = this.settings; - let og; - setting_keys.forEach((key, i) => { - if(i === setting_keys.length - 1) { - og = setting_obj[key]; - setting_obj[key] = value; - } - if(setting_obj[key] === undefined) setting_obj[key] = {}; // create missing nested properties - setting_obj = setting_obj[key]; - }); - console.log("saving setting: " + setting_path); - this.save_settings(); - console.log("saved settings"); - const changed = og !== value; - this.after_update(setting_path, value, elm, changed); - return changed; // return true if value changed - } - after_update(setting, value, elm, changed) { } // override in subclass - add_listeners() { } // override in subclass - save_settings() { } // override in subclass - settings_filter(setting_name) { return true; } // override in subclass (return false to hide setting) - // onchange callbacks created in subclass - handle_folder_select(setting, value, elm) { } // override in subclass - handle_file_select(setting, value, elm) { } // override in subclass -} - diff --git a/smart-setting/README.md b/smart-setting/README.md deleted file mode 100644 index d7d546c5..00000000 --- a/smart-setting/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# Smart Settings - -Smart Settings is a minimal dependency renderer for settings components designed for Smart Environments. It allows developers to create customizable settings interfaces with ease, leveraging the power of EJS templates and a flexible component system. - -## Features - -- **Minimal Dependency**: Designed to operate with low to no external dependencies, ensuring lightweight and secure integration. -- **Customizable Templates**: Use EJS templates to render settings interfaces, allowing for highly customizable and dynamic UIs. -- **Component-Based**: Provides a variety of components such as text inputs, dropdowns, toggles, and more to build settings interfaces. -- **Extendable**: Easily extend the base functionality to meet specific needs and requirements. -- **Ease of Development**: Simplifies the process of creating and managing settings interfaces, making it accessible for developers at various skill levels. - -## Installation - -To install Smart Settings, include it in your project dependencies: - -``` -npm install smart-setting -``` - -## Usage - -To use Smart Settings, create an instance of the `SmartSettings` class and call the `render` method to display the settings interface. Customize the behavior by overriding methods and providing your own templates. - -``` -const settings = new SmartSettings(env, container, template_name); -settings.render(); -``` - -## API - -### SmartSettings - -#### Constructor - -`new SmartSettings(env, container, template_name)` - -- `env`: The environment object containing necessary dependencies. -- `container`: The DOM element where the settings interface will be rendered. -- `template_name`: The name of the EJS template to use for rendering. - -#### Methods - -- `render()`: Renders the settings interface. -- `render_template(view_data)`: Renders the EJS template with the provided view data. -- `update(setting, value)`: Updates a setting with the given value and saves it. -- `render_components()`: Renders the individual components within the settings interface. -- `handle_on_change(setting, value, elm)`: Handles changes to settings and updates the interface accordingly. -- `get_setting(setting)`: Retrieves the value of a setting, falling back to defaults if necessary. - -## License - -Smart Settings is licensed under the MIT License. - - -## Acknowledgements - -Smart Settings is developed and maintained by Brian Joseph Petro (🌴 Brian). Special thanks to all contributors and the open-source community for their support. diff --git a/smart-setting/ejs.min.cjs b/smart-setting/ejs.min.cjs deleted file mode 100644 index 5d3c90d8..00000000 --- a/smart-setting/ejs.min.cjs +++ /dev/null @@ -1 +0,0 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ejs=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i1;if(options.cache){if(!filename){throw new Error("cache option requires a filename")}func=exports.cache.get(filename);if(func){return func}if(!hasTemplate){template=fileLoader(filename).toString().replace(_BOM,"")}}else if(!hasTemplate){if(!filename){throw new Error("Internal EJS error: no file name or template "+"provided")}template=fileLoader(filename).toString().replace(_BOM,"")}func=exports.compile(template,options);if(options.cache){exports.cache.set(filename,func)}return func}function tryHandleCache(options,data,cb){var result;if(!cb){if(typeof exports.promiseImpl=="function"){return new exports.promiseImpl(function(resolve,reject){try{result=handleCache(options)(data);resolve(result)}catch(err){reject(err)}})}else{throw new Error("Please provide a callback function")}}else{try{result=handleCache(options)(data)}catch(err){return cb(err)}cb(null,result)}}function fileLoader(filePath){return exports.fileLoader(filePath)}function includeFile(path,options){var opts=utils.shallowCopy(utils.createNullProtoObjWherePossible(),options);opts.filename=getIncludePath(path,opts);if(typeof options.includer==="function"){var includerResult=options.includer(path,opts.filename);if(includerResult){if(includerResult.filename){opts.filename=includerResult.filename}if(includerResult.template){return handleCache(opts,includerResult.template)}}}return handleCache(opts)}function rethrow(err,str,flnm,lineno,esc){var lines=str.split("\n");var start=Math.max(lineno-3,0);var end=Math.min(lines.length,lineno+3);var filename=esc(flnm);var context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" >> ":" ")+curr+"| "+line}).join("\n");err.path=filename;err.message=(filename||"ejs")+":"+lineno+"\n"+context+"\n\n"+err.message;throw err}function stripSemi(str){return str.replace(/;(\s*$)/,"$1")}exports.compile=function compile(template,opts){var templ;if(opts&&opts.scope){if(!scopeOptionWarned){console.warn("`scope` option is deprecated and will be removed in EJS 3");scopeOptionWarned=true}if(!opts.context){opts.context=opts.scope}delete opts.scope}templ=new Template(template,opts);return templ.compile()};exports.render=function(template,d,o){var data=d||utils.createNullProtoObjWherePossible();var opts=o||utils.createNullProtoObjWherePossible();if(arguments.length==2){utils.shallowCopyFromList(opts,data,_OPTS_PASSABLE_WITH_DATA)}return handleCache(opts,template)(data)};exports.renderFile=function(){var args=Array.prototype.slice.call(arguments);var filename=args.shift();var cb;var opts={filename:filename};var data;var viewOpts;if(typeof arguments[arguments.length-1]=="function"){cb=args.pop()}if(args.length){data=args.shift();if(args.length){utils.shallowCopy(opts,args.pop())}else{if(data.settings){if(data.settings.views){opts.views=data.settings.views}if(data.settings["view cache"]){opts.cache=true}viewOpts=data.settings["view options"];if(viewOpts){utils.shallowCopy(opts,viewOpts)}}utils.shallowCopyFromList(opts,data,_OPTS_PASSABLE_WITH_DATA_EXPRESS)}opts.filename=filename}else{data=utils.createNullProtoObjWherePossible()}return tryHandleCache(opts,data,cb)};exports.Template=Template;exports.clearCache=function(){exports.cache.reset()};function Template(text,opts){opts=opts||utils.createNullProtoObjWherePossible();var options=utils.createNullProtoObjWherePossible();this.templateText=text;this.mode=null;this.truncate=false;this.currentLine=1;this.source="";options.client=opts.client||false;options.escapeFunction=opts.escape||opts.escapeFunction||utils.escapeXML;options.compileDebug=opts.compileDebug!==false;options.debug=!!opts.debug;options.filename=opts.filename;options.openDelimiter=opts.openDelimiter||exports.openDelimiter||_DEFAULT_OPEN_DELIMITER;options.closeDelimiter=opts.closeDelimiter||exports.closeDelimiter||_DEFAULT_CLOSE_DELIMITER;options.delimiter=opts.delimiter||exports.delimiter||_DEFAULT_DELIMITER;options.strict=opts.strict||false;options.context=opts.context;options.cache=opts.cache||false;options.rmWhitespace=opts.rmWhitespace;options.root=opts.root;options.includer=opts.includer;options.outputFunctionName=opts.outputFunctionName;options.localsName=opts.localsName||exports.localsName||_DEFAULT_LOCALS_NAME;options.views=opts.views;options.async=opts.async;options.destructuredLocals=opts.destructuredLocals;options.legacyInclude=typeof opts.legacyInclude!="undefined"?!!opts.legacyInclude:true;if(options.strict){options._with=false}else{options._with=typeof opts._with!="undefined"?opts._with:true}this.opts=options;this.regex=this.createRegex()}Template.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",COMMENT:"comment",LITERAL:"literal"};Template.prototype={createRegex:function(){var str=_REGEX_STRING;var delim=utils.escapeRegExpChars(this.opts.delimiter);var open=utils.escapeRegExpChars(this.opts.openDelimiter);var close=utils.escapeRegExpChars(this.opts.closeDelimiter);str=str.replace(/%/g,delim).replace(//g,close);return new RegExp(str)},compile:function(){var src;var fn;var opts=this.opts;var prepended="";var appended="";var escapeFn=opts.escapeFunction;var ctor;var sanitizedFilename=opts.filename?JSON.stringify(opts.filename):"undefined";if(!this.source){this.generateSource();prepended+=' var __output = "";\n'+" function __append(s) { if (s !== undefined && s !== null) __output += s }\n";if(opts.outputFunctionName){if(!_JS_IDENTIFIER.test(opts.outputFunctionName)){throw new Error("outputFunctionName is not a valid JS identifier.")}prepended+=" var "+opts.outputFunctionName+" = __append;"+"\n"}if(opts.localsName&&!_JS_IDENTIFIER.test(opts.localsName)){throw new Error("localsName is not a valid JS identifier.")}if(opts.destructuredLocals&&opts.destructuredLocals.length){var destructuring=" var __locals = ("+opts.localsName+" || {}),\n";for(var i=0;i0){destructuring+=",\n "}destructuring+=name+" = __locals."+name}prepended+=destructuring+";\n"}if(opts._with!==false){prepended+=" with ("+opts.localsName+" || {}) {"+"\n";appended+=" }"+"\n"}appended+=" return __output;"+"\n";this.source=prepended+this.source+appended}if(opts.compileDebug){src="var __line = 1"+"\n"+" , __lines = "+JSON.stringify(this.templateText)+"\n"+" , __filename = "+sanitizedFilename+";"+"\n"+"try {"+"\n"+this.source+"} catch (e) {"+"\n"+" rethrow(e, __lines, __filename, __line, escapeFn);"+"\n"+"}"+"\n"}else{src=this.source}if(opts.client){src="escapeFn = escapeFn || "+escapeFn.toString()+";"+"\n"+src;if(opts.compileDebug){src="rethrow = rethrow || "+rethrow.toString()+";"+"\n"+src}}if(opts.strict){src='"use strict";\n'+src}if(opts.debug){console.log(src)}if(opts.compileDebug&&opts.filename){src=src+"\n"+"//# sourceURL="+sanitizedFilename+"\n"}try{if(opts.async){try{ctor=new Function("return (async function(){}).constructor;")()}catch(e){if(e instanceof SyntaxError){throw new Error("This environment does not support async/await")}else{throw e}}}else{ctor=Function}fn=new ctor(opts.localsName+", escapeFn, include, rethrow",src)}catch(e){if(e instanceof SyntaxError){if(opts.filename){e.message+=" in "+opts.filename}e.message+=" while compiling ejs\n\n";e.message+="If the above error is not helpful, you may want to try EJS-Lint:\n";e.message+="https://github.com/RyanZim/EJS-Lint";if(!opts.async){e.message+="\n";e.message+="Or, if you meant to create an async function, pass `async: true` as an option."}}throw e}var returnedFn=opts.client?fn:function anonymous(data){var include=function(path,includeData){var d=utils.shallowCopy(utils.createNullProtoObjWherePossible(),data);if(includeData){d=utils.shallowCopy(d,includeData)}return includeFile(path,opts)(d)};return fn.apply(opts.context,[data||utils.createNullProtoObjWherePossible(),escapeFn,include,rethrow])};if(opts.filename&&typeof Object.defineProperty==="function"){var filename=opts.filename;var basename=path.basename(filename,path.extname(filename));try{Object.defineProperty(returnedFn,"name",{value:basename,writable:false,enumerable:false,configurable:true})}catch(e){}}return returnedFn},generateSource:function(){var opts=this.opts;if(opts.rmWhitespace){this.templateText=this.templateText.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")}this.templateText=this.templateText.replace(/[ \t]*<%_/gm,"<%_").replace(/_%>[ \t]*/gm,"_%>");var self=this;var matches=this.parseTemplateText();var d=this.opts.delimiter;var o=this.opts.openDelimiter;var c=this.opts.closeDelimiter;if(matches&&matches.length){matches.forEach(function(line,index){var closing;if(line.indexOf(o+d)===0&&line.indexOf(o+d+d)!==0){closing=matches[index+2];if(!(closing==d+c||closing=="-"+d+c||closing=="_"+d+c)){throw new Error('Could not find matching close tag for "'+line+'".')}}self.scanLine(line)})}},parseTemplateText:function(){var str=this.templateText;var pat=this.regex;var result=pat.exec(str);var arr=[];var firstPos;while(result){firstPos=result.index;if(firstPos!==0){arr.push(str.substring(0,firstPos));str=str.slice(firstPos)}arr.push(result[0]);str=str.slice(result[0].length);result=pat.exec(str)}if(str){arr.push(str)}return arr},_addOutput:function(line){if(this.truncate){line=line.replace(/^(?:\r\n|\r|\n)/,"");this.truncate=false}if(!line){return line}line=line.replace(/\\/g,"\\\\");line=line.replace(/\n/g,"\\n");line=line.replace(/\r/g,"\\r");line=line.replace(/"/g,'\\"');this.source+=' ; __append("'+line+'")'+"\n"},scanLine:function(line){var self=this;var d=this.opts.delimiter;var o=this.opts.openDelimiter;var c=this.opts.closeDelimiter;var newLineCount=0;newLineCount=line.split("\n").length-1;switch(line){case o+d:case o+d+"_":this.mode=Template.modes.EVAL;break;case o+d+"=":this.mode=Template.modes.ESCAPED;break;case o+d+"-":this.mode=Template.modes.RAW;break;case o+d+"#":this.mode=Template.modes.COMMENT;break;case o+d+d:this.mode=Template.modes.LITERAL;this.source+=' ; __append("'+line.replace(o+d+d,o+d)+'")'+"\n";break;case d+d+c:this.mode=Template.modes.LITERAL;this.source+=' ; __append("'+line.replace(d+d+c,d+c)+'")'+"\n";break;case d+c:case"-"+d+c:case"_"+d+c:if(this.mode==Template.modes.LITERAL){this._addOutput(line)}this.mode=null;this.truncate=line.indexOf("-")===0||line.indexOf("_")===0;break;default:if(this.mode){switch(this.mode){case Template.modes.EVAL:case Template.modes.ESCAPED:case Template.modes.RAW:if(line.lastIndexOf("//")>line.lastIndexOf("\n")){line+="\n"}}switch(this.mode){case Template.modes.EVAL:this.source+=" ; "+line+"\n";break;case Template.modes.ESCAPED:this.source+=" ; __append(escapeFn("+stripSemi(line)+"))"+"\n";break;case Template.modes.RAW:this.source+=" ; __append("+stripSemi(line)+")"+"\n";break;case Template.modes.COMMENT:break;case Template.modes.LITERAL:this._addOutput(line);break}}else{this._addOutput(line)}}if(self.opts.compileDebug&&newLineCount){this.currentLine+=newLineCount;this.source+=" ; __line = "+this.currentLine+"\n"}}};exports.escapeXML=utils.escapeXML;exports.__express=exports.renderFile;exports.VERSION=_VERSION_STRING;exports.name=_NAME;if(typeof window!="undefined"){window.ejs=exports}},{"../package.json":6,"./utils":2,fs:3,path:4}],2:[function(require,module,exports){"use strict";var regExpChars=/[|\\{}()[\]^$+*?.]/g;var hasOwnProperty=Object.prototype.hasOwnProperty;var hasOwn=function(obj,key){return hasOwnProperty.apply(obj,[key])};exports.escapeRegExpChars=function(string){if(!string){return""}return String(string).replace(regExpChars,"\\$&")};var _ENCODE_HTML_RULES={"&":"&","<":"<",">":">",'"':""","'":"'"};var _MATCH_HTML=/[&<>'"]/g;function encode_char(c){return _ENCODE_HTML_RULES[c]||c}var escapeFuncStr="var _ENCODE_HTML_RULES = {\n"+' "&": "&"\n'+' , "<": "<"\n'+' , ">": ">"\n'+' , \'"\': """\n'+' , "\'": "'"\n'+" }\n"+" , _MATCH_HTML = /[&<>'\"]/g;\n"+"function encode_char(c) {\n"+" return _ENCODE_HTML_RULES[c] || c;\n"+"};\n";exports.escapeXML=function(markup){return markup==undefined?"":String(markup).replace(_MATCH_HTML,encode_char)};function escapeXMLToString(){return Function.prototype.toString.call(this)+";\n"+escapeFuncStr}try{if(typeof Object.defineProperty==="function"){Object.defineProperty(exports.escapeXML,"toString",{value:escapeXMLToString})}else{exports.escapeXML.toString=escapeXMLToString}}catch(err){console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)")}exports.shallowCopy=function(to,from){from=from||{};if(to!==null&&to!==undefined){for(var p in from){if(!hasOwn(from,p)){continue}if(p==="__proto__"||p==="constructor"){continue}to[p]=from[p]}}return to};exports.shallowCopyFromList=function(to,from,list){list=list||[];from=from||{};if(to!==null&&to!==undefined){for(var i=0;i=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up--;up){parts.unshift("..")}}return parts}exports.resolve=function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:process.cwd();if(typeof path!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){continue}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=path.charAt(0)==="/"}resolvedPath=normalizeArray(filter(resolvedPath.split("/"),function(p){return!!p}),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."};exports.normalize=function(path){var isAbsolute=exports.isAbsolute(path),trailingSlash=substr(path,-1)==="/";path=normalizeArray(filter(path.split("/"),function(p){return!!p}),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path};exports.isAbsolute=function(path){return path.charAt(0)==="/"};exports.join=function(){var paths=Array.prototype.slice.call(arguments,0);return exports.normalize(filter(paths,function(p,index){if(typeof p!=="string"){throw new TypeError("Arguments to path.join must be strings")}return p}).join("/"))};exports.relative=function(from,to){from=exports.resolve(from).substr(1);to=exports.resolve(to).substr(1);function trim(arr){var start=0;for(;start=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i=1;--i){code=path.charCodeAt(i);if(code===47){if(!matchedSlash){end=i;break}}else{matchedSlash=false}}if(end===-1)return hasRoot?"/":".";if(hasRoot&&end===1){return"/"}return path.slice(0,end)};function basename(path){if(typeof path!=="string")path=path+"";var start=0;var end=-1;var matchedSlash=true;var i;for(i=path.length-1;i>=0;--i){if(path.charCodeAt(i)===47){if(!matchedSlash){start=i+1;break}}else if(end===-1){matchedSlash=false;end=i+1}}if(end===-1)return"";return path.slice(start,end)}exports.basename=function(path,ext){var f=basename(path);if(ext&&f.substr(-1*ext.length)===ext){f=f.substr(0,f.length-ext.length)}return f};exports.extname=function(path){if(typeof path!=="string")path=path+"";var startDot=-1;var startPart=0;var end=-1;var matchedSlash=true;var preDotState=0;for(var i=path.length-1;i>=0;--i){var code=path.charCodeAt(i);if(code===47){if(!matchedSlash){startPart=i+1;break}continue}if(end===-1){matchedSlash=false;end=i+1}if(code===46){if(startDot===-1)startDot=i;else if(preDotState!==1)preDotState=1}else if(startDot!==-1){preDotState=-1}}if(startDot===-1||end===-1||preDotState===0||preDotState===1&&startDot===end-1&&startDot===startPart+1){return""}return path.slice(startDot,end)};function filter(xs,f){if(xs.filter)return xs.filter(f);var res=[];for(var i=0;i1){for(var i=1;i (http://fleegix.org)",license:"Apache-2.0",bin:{ejs:"./bin/cli.js"},main:"./lib/ejs.js",jsdelivr:"ejs.min.js",unpkg:"ejs.min.js",repository:{type:"git",url:"git://github.com/mde/ejs.git"},bugs:"https://github.com/mde/ejs/issues",homepage:"https://github.com/mde/ejs",dependencies:{jake:"^10.8.5"},devDependencies:{browserify:"^16.5.1",eslint:"^6.8.0","git-directory-deploy":"^1.5.1",jsdoc:"^4.0.2","lru-cache":"^4.0.1",mocha:"^10.2.0","uglify-js":"^3.3.16"},engines:{node:">=0.10.0"},scripts:{test:"mocha -u tdd"}}},{}]},{},[1])(1)}); diff --git a/smart-setting/package.json b/smart-setting/package.json deleted file mode 100644 index d037cc28..00000000 --- a/smart-setting/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "smart-setting", - "author": "Brian Joseph Petro (🌴 Brian)", - "license": "MIT", - "type": "module", - "version": "1.0.1", - "description": "Minimal dependency renderer for settings components designed for Smart Environments.", - "main": "smart_settings.js", - "repository": { - "type": "git", - "url": "brianpetro/jsbrains" - }, - "bugs": { - "url": "https://github.com/brianpetro/jsbrains/issues" - }, - "scripts": { - "test": "npx ava --verbose" - }, - "homepage": "https://jsbrains.org" -} diff --git a/smart-setting/smart_settings.js b/smart-setting/smart_settings.js deleted file mode 100644 index 5b1a514c..00000000 --- a/smart-setting/smart_settings.js +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) Brian Joseph Petro - -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: - -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -import ejs from "./ejs.min.cjs"; -class SmartSettings { - constructor(env, container, opts = { template_name: "smart_settings" }) { - this.env = env; - this.main = opts.main || this.env.plugin; // DEPRECATED in favor of snake_case name of plugin class - this.plugin = this.main; // DEPRECATED in favor of main - this.container = container; - if(typeof opts === 'string') opts = { template_name: opts }; // DEPRECATED handling - this.template_name = opts.template_name; - this.ejs = this.env.ejs || ejs; - this.templates = this.env.opts.templates; // DEPRECATE in favor of views??? - this.views = this.templates; - } - // get settings() { return this.main.settings; } - // set settings(settings) { this.main.settings = settings; } - get settings() { return this.env.settings; } - set settings(settings) { this.env.settings = settings; } - async render() { - const view_data = (typeof this.get_view_data === "function") ? await this.get_view_data() : this.view_data; - this.render_template(view_data); - await this.render_components(); - } - render_template(view_data = null) { - if (!this.template) throw new Error(`Settings template not found.`); - this.container.empty(); - this.container.innerHTML = this.ejs.render(this.template, view_data || this.view_data, { context: this }); - } - async update(setting, value) { - let settings = {...this.settings}; - if (setting.includes(".")) { - let parts = setting.split("."); - let obj = settings; - for (let i = 0; i < parts.length - 1; i++) { - if (!obj[parts[i]]) obj[parts[i]] = {}; - obj = obj[parts[i]]; - } - obj[parts[parts.length - 1]] = (typeof value === "string") ? value.trim() : value; - } else { - settings[setting] = (typeof value === "string") ? value.trim() : value; - } - await this.env.smart_settings.save(settings); - } - async render_components() { - if(!this.main.obsidian.Setting) console.warn("missing Obsidian Setting component"); - this.container.querySelectorAll(".setting-component").forEach(async elm => { - const setting_elm = new this.main.obsidian.Setting(elm); - if (elm.dataset.name) setting_elm.setName(elm.dataset.name); - if (elm.dataset.description) setting_elm.descEl.innerHTML = elm.dataset.description; - const setting = elm.dataset.setting; - if (elm.dataset.type === "text") { - setting_elm.addText(text => { - text.setPlaceholder(elm.dataset.placeholder || ""); - text.setValue(this.get_setting(setting)); - let debounceTimer; - if (elm.dataset.button) { - setting_elm.addButton(button => { - button.setButtonText(elm.dataset.button); - button.onClick(async () => this.handle_on_change(setting, text.getValue(), elm)); - }); - } else { - text.onChange(async (value) => { - clearTimeout(debounceTimer); - debounceTimer = setTimeout(() => this.handle_on_change(setting, value, elm), 2000); - }); - } - }); - } else if (elm.dataset.type === "password") { - setting_elm.addText(text => { - text.inputEl.type = "password"; - text.setPlaceholder(elm.dataset.placeholder || ""); - const setting_value = this.get_setting(setting); - if (setting_value) text.setValue(setting_value); - text.onChange(async (value) => this.handle_on_change(setting, value, elm)); - }); - } else if (elm.dataset.type === "number") { - setting_elm.addText(number => { - number.inputEl.type = "number"; - number.setPlaceholder(elm.dataset.placeholder || ""); - number.inputEl.value = parseInt(this.get_setting(setting)); - number.inputEl.min = elm.dataset.min || 0; - if (elm.dataset.max) number.inputEl.max = elm.dataset.max; - let debounceTimer; - number.onChange(async (value) => { - clearTimeout(debounceTimer); - debounceTimer = setTimeout(() => this.handle_on_change(setting, parseInt(value), elm), 2000); - }); - }); - } else if (elm.dataset.type === "dropdown") { - const setting_value = this.get_setting(setting) || elm.dataset.value; - let options; - if (elm.dataset.optionsCallback) { - if (typeof this[elm.dataset.optionsCallback] !== 'function') { - console.error(`Options callback ${elm.dataset.optionsCallback} is not a function.`); - options = []; - } else { - options = await this[elm.dataset.optionsCallback](); - } - } else { - options = Object.entries(elm.dataset) - .filter(([k, v]) => k.startsWith("option")) - .map(([k, v]) => { - const [value, name] = v.split("|"); - return { value, name: name || value }; - }); - } - setting_elm.addDropdown(dropdown => { - options.forEach(option => dropdown.addOption(option.value, option.name)); - dropdown.onChange(async (value) => this.handle_on_change(setting, value, elm)); - dropdown.setValue(setting_value); - }); - } else if (elm.dataset.type === "button") { - setting_elm.addButton(button => { - button.setButtonText(elm.dataset.btnText || elm.dataset.name); - button.onClick(async () => { - if (elm.dataset.confirm) { - const confirmation_message = elm.dataset.confirm; - if (!confirm(confirmation_message)) return; - } - if (elm.dataset.href) window.open(elm.dataset.href); - if (elm.dataset.callback) this[elm.dataset.callback](setting, null, elm); - }); - }); - } else if (elm.dataset.type === "toggle") { - setting_elm.addToggle(toggle => { - toggle.setValue(this.get_setting(setting)); - toggle.onChange(async (value) => this.handle_on_change(setting, value, elm)); - }); - } else if (elm.dataset.type === "textarea") { - setting_elm.addTextArea(textarea => { - textarea.setValue(this.get_setting(setting)); - textarea.onChange(async (value) => this.handle_on_change(setting, value, elm)); - if (elm.dataset.maxLength) textarea.inputEl.maxLength = elm.dataset.maxLength; - }); - } - if (elm.dataset.disabled) setting_elm.setDisabled(true); - }); - } - async handle_on_change(setting, value, elm) { - await this.update(setting, value); - if (elm.dataset.callback) this[elm.dataset.callback](setting, value, elm); - } - get_setting(setting) { - if (setting.includes(".")) { - let parts = setting.split("."); - // let obj = this.plugin.settings; - let obj = this.settings; - for (let part of parts.slice(0, -1)) { - if (obj[part] === undefined) return this.plugin.constructor.defaults[setting]; // Fallback to default if path is broken - obj = obj[part]; - } - return obj[parts[parts.length - 1]] ?? this.plugin.constructor.defaults[setting]; - } else { - // return this.plugin.settings[setting] ?? this.plugin.constructor.defaults[setting]; - return this.settings[setting] ?? this.plugin.constructor.defaults[setting]; - } - } - // override in subclass (required) - get template() { return ""; } // ejs template string - get view_data() { return {}; } // object properties available in template -} -export { SmartSettings }; \ No newline at end of file diff --git a/smart-views/package.json b/smart-views/package.json deleted file mode 100644 index d687583b..00000000 --- a/smart-views/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "smart-views", - "author": "Brian Joseph Petro (🌴 Brian)", - "license": "MIT", - "type": "module", - "version": "1.0.1", - "description": "Minimal dependency renderer for settings components designed for Smart Environments.", - "main": "smart_settings.js", - "repository": { - "type": "git", - "url": "brianpetro/jsbrains" - }, - "bugs": { - "url": "https://github.com/brianpetro/jsbrains/issues" - }, - "scripts": { - "test": "npx ava --verbose" - }, - "dependencies": { - "lucide-static": "^0.414.0" - }, - "homepage": "https://jsbrains.org" -} diff --git a/smart-views/smart_views.js b/smart-views/smart_views.js deleted file mode 100644 index 7e79e4f7..00000000 --- a/smart-views/smart_views.js +++ /dev/null @@ -1,42 +0,0 @@ -import * as lucide from 'lucide-static'; -export class SmartViews { - constructor(main, opts={}) { - this.main = main; - // support main as Main or Env - this.opts = { - ...(this.main.smart_env_config || this.main.opts || {}), - ...opts, - }; - } - get ejs() { return this.opts.ejs; } - get template() { return this.opts.templates[this.opts.template_name]; } - get templates() { return this.opts.templates; } - render(template_name, data, opts={}) { - const template = this.templates[template_name]; - const html = this.ejs.render( - template, - { - ...this.default_template_data, - ...data, - }, - { - context: this, - ...opts - } - ); - if(opts.container) opts.container.innerHTML = html; - return html; - } - get default_template_data() { - return { - include: (template_name, data, options={}) => { - const template = this.templates[template_name]; - return this.ejs.render(template, data, options); - } - }; - } - add_icon(icon_name) { - const icon = lucide[icon_name]; - return icon; - } -} \ No newline at end of file