Browse Source

MINOR,REFA,DOC,INDENT: Autoformatted code, added some doc

master
chris 4 months ago
parent
commit
fc2c6b15c0
  1. 3
      src/arrangement.js
  2. 42
      src/builder.js
  3. 39
      src/context.js

3
src/arrangement.js

@ -15,5 +15,4 @@ const Arrangement = Object.freeze({
SPACE_BETWEEN: "space-between", SPACE_BETWEEN: "space-between",
SPACE_EVENLY: "space-evenly", SPACE_EVENLY: "space-evenly",
SPACE_AROUND: "space-around", SPACE_AROUND: "space-around",
});
})

42
src/builder.js

@ -115,7 +115,7 @@ const builder = {
* @returns {Component} * @returns {Component}
*/ */
img: function (attr = {}) { return builder.genTag("img", attr); }, img: function (attr = {}) { return builder.genTag("img", attr); },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
@ -129,42 +129,42 @@ const builder = {
* @returns {Component} * @returns {Component}
*/ */
table: function (attr = {}) { return builder.genTag("table", attr) }, table: function (attr = {}) { return builder.genTag("table", attr) },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
* @returns {Component} * @returns {Component}
*/ */
tableRow: function (attr = {}) { return builder.genTag("tr", attr) }, tableRow: function (attr = {}) { return builder.genTag("tr", attr) },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
* @returns {Component} * @returns {Component}
*/ */
tableCell: function (attr = {}) { return builder.genTag("td", attr) }, tableCell: function (attr = {}) { return builder.genTag("td", attr) },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
* @returns {Component} * @returns {Component}
*/ */
tableCaption: function (attr = {}) { return builder.genTag("caption", attr) }, tableCaption: function (attr = {}) { return builder.genTag("caption", attr) },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
* @returns {Component} * @returns {Component}
*/ */
tableHeadCell: function (attr = {}) { return builder.genTag("th", attr) }, tableHeadCell: function (attr = {}) { return builder.genTag("th", attr) },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
* @returns {Component} * @returns {Component}
*/ */
tableBody: function (attr = {}) { return builder.genTag("tbody", attr) }, tableBody: function (attr = {}) { return builder.genTag("tbody", attr) },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
@ -177,19 +177,25 @@ const builder = {
* @returns {Component} * @returns {Component}
*/ */
tableFooter: function (attr = {}) { return builder.genTag("tfoot", attr) }, tableFooter: function (attr = {}) { return builder.genTag("tfoot", attr) },
/**
*
* @param {Map<string,string>} attr
* @returns {Component}
*/
iframe: function (attr = {}) { return builder.genTag("iframe", attr) },
/** /**
* *
* @param {Map<string,string>} attr * @param {Map<string,string>} attr
* @returns {Component} * @returns {Component}
*/ */
form: function (attr = {}) { form: function (attr = {}) {
return builder.genTag("form", attr) return builder.genTag("form", attr)
.addStyleClass("flex-container-component") .addStyleClass("flex-container-component")
.chainModifier() .chainModifier()
.setStyleRule("flex-direction", "column") .setStyleRule("flex-direction", "column")
.ensureModifier() .ensureModifier()
.toComponent() .toComponent()
}, },
/** /**
@ -212,14 +218,14 @@ const builder = {
*/ */
page: function (innerComponents) { page: function (innerComponents) {
let main = document.querySelector('main') let main = document.querySelector('main')
main.parentElement.insertAdjacentElement( main.parentElement.insertAdjacentElement(
"afterbegin", "afterbegin",
builder.genTag("main") builder.genTag("main")
.alignment(Alignment.CENTER) .alignment(Alignment.CENTER)
.arrangement(Arrangement.CENTER) .arrangement(Arrangement.CENTER)
.childContext(innerComponents) .childContext(innerComponents)
.generate() .generate()
) )
Page.generate(); Page.generate();
main.remove(); main.remove();

39
src/context.js

@ -8,6 +8,11 @@
/** /**
* The class provides overreaching options for building the website. * The class provides overreaching options for building the website.
*/ */
/**
* The class provides overreaching options for building the website.
* @property {Array<string>} #functionNames
*
*/
class PageBuilder { class PageBuilder {
#cssClasses; #cssClasses;
#functions; #functions;
@ -27,6 +32,14 @@ class PageBuilder {
* Registers a function to be added later in a script tag in the head of the document. * Registers a function to be added later in a script tag in the head of the document.
* @ATTENTION Be careful with intended empty strings (e.g. in variable values), * @ATTENTION Be careful with intended empty strings (e.g. in variable values),
* empty strings within the function code will be shrunk. * empty strings within the function code will be shrunk.
/**
* Registers a function to be added later in a script tag in the head of the document.
* @ATTENTION Be careful with intended empty strings (e.g. in variable values),
* empty strings within the function code will be shrunk.
* @deprecated 'registerFunction' will bew removed.
* 'registerNamedFunction' will be removed.
* Use 'registerPageFunction' it fully supports registration/adding of functions.
* All variations of named, unnamed and reassigned, arrow or brakets notation.
* @param {string} name * @param {string} name
* @param {function} fun * @param {function} fun
*/ */
@ -36,7 +49,7 @@ class PageBuilder {
* @param {string} text * @param {string} text
* @returns {string} * @returns {string}
*/ */
function shrinkEmptyStrings(text){ function shrinkEmptyStrings(text) {
for (let i = 1; i < 10; i++) { for (let i = 1; i < 10; i++) {
text = text.replaceAll(" ".slice(i), ' '); text = text.replaceAll(" ".slice(i), ' ');
} }
@ -49,15 +62,15 @@ class PageBuilder {
.replaceAll('\r\n', ' ') .replaceAll('\r\n', ' ')
.replaceAll('\n\r', ' ') .replaceAll('\n\r', ' ')
); );
let isFuncWritten = clearedFuncText.startsWith('function'); let isFuncWritten = clearedFuncText.startsWith('function');
let funcHasName = fun.name && fun.name.trim() !== ''; let funcHasName = fun.name && fun.name.trim() !== '';
if(isFuncWritten){ if (isFuncWritten) {
let isNameInFuncText = clearedFuncText.startsWith(`function ${name}`); let isNameInFuncText = clearedFuncText.startsWith(`function ${name}`);
this.#functions.innerText += (funcHasName && isNameInFuncText this.#functions.innerText += (funcHasName && isNameInFuncText
? clearedFuncText ? clearedFuncText
: clearedFuncText.replace('function ', 'function '+name) : clearedFuncText.replace('function ', 'function ' + name)
)+'; '; ) + '; ';
}else{ } else {
this.#functions.innerText += `const ${name} = ${clearedFuncText}; ` this.#functions.innerText += `const ${name} = ${clearedFuncText}; `
} }
this.#functionNames.push(name); this.#functionNames.push(name);
@ -65,7 +78,14 @@ class PageBuilder {
return this; return this;
} }
/**
* @deprecated 'registerFunction' will bew removed.
* 'registerNamedFunction' will be removed.
* Use 'registerPageFunction' it fully supports registration of functions.
* All variations of named, unnamed and reassigned, arrow or brakets notation.
* @param {Function} namedFunction
* @returns
*/
registerNamedFunction(namedFunction) { registerNamedFunction(namedFunction) {
return this.registerFunction(namedFunction.name, namedFunction) return this.registerFunction(namedFunction.name, namedFunction)
} }
@ -158,6 +178,11 @@ class PageBuilder {
/** /**
* *
/**
* Little helper function.
* If a single page application is in development.
* This method sets an autoreload interval for the page.
* @param {number} relaunchSeconds timeinterval for page to reload (changes) * @param {number} relaunchSeconds timeinterval for page to reload (changes)
*/ */
inDev(relaunchSeconds = 20) { inDev(relaunchSeconds = 20) {

Loading…
Cancel
Save