@saltcorn/markup
Advanced tools
Comparing version 0.6.0-beta.1 to 0.6.0-beta.2
@@ -237,5 +237,5 @@ const { | ||
fieldview = hdr.fieldviewObj; | ||
} else if (hdr.fieldview && hdr.type.fieldviews[hdr.fieldview]) | ||
} else if (hdr.fieldview && hdr.type && hdr.type.fieldviews[hdr.fieldview]) | ||
fieldview = hdr.type.fieldviews[hdr.fieldview]; | ||
else { | ||
else if (hdr.type && hdr.type.fieldviews) { | ||
//first isedit fieldview | ||
@@ -246,2 +246,7 @@ fieldview = Object.entries(hdr.type.fieldviews).find( | ||
} | ||
if (!fieldview) { | ||
if (!hdr.type) | ||
throw new Error(`Unknown type ${hdr.typename} in field ${name}`); | ||
else throw new Error(`Cannot find fieldview for field ${name}`); | ||
} | ||
if (fieldview.isEdit) | ||
@@ -248,0 +253,0 @@ return fieldview.run( |
@@ -20,2 +20,3 @@ const { contract, is } = require("contractis"); | ||
i, | ||
genericElement, | ||
} = require("./tags"); | ||
@@ -258,2 +259,3 @@ const { alert, breadcrumbs } = require("./layout_utils"); | ||
onclick: segment.url ? `location.href='${segment.url}'` : false, | ||
style: segment.style, | ||
}, | ||
@@ -314,2 +316,3 @@ segment.title && | ||
style, | ||
htmlElement, | ||
} = segment; | ||
@@ -353,3 +356,4 @@ if (hide) return ""; | ||
ix, | ||
div( | ||
genericElement( | ||
htmlElement || "div", | ||
{ | ||
@@ -356,0 +360,0 @@ class: [ |
@@ -1,2 +0,12 @@ | ||
const { a, input, div, ul, text, text_attr, i, hr } = require("./tags"); | ||
const { | ||
a, | ||
input, | ||
div, | ||
ul, | ||
text, | ||
text_attr, | ||
i, | ||
hr, | ||
genericElement, | ||
} = require("./tags"); | ||
@@ -29,2 +39,5 @@ describe("tags", () => { | ||
); | ||
expect(genericElement("div", { class: "foo" }, "Hello")).toBe( | ||
'<div class="foo">Hello</div>' | ||
); | ||
}); | ||
@@ -31,0 +44,0 @@ |
{ | ||
"name": "@saltcorn/markup", | ||
"version": "0.6.0-beta.1", | ||
"version": "0.6.0-beta.2", | ||
"description": "Markup for Saltcorn, open-source no-code platform", | ||
@@ -5,0 +5,0 @@ "homepage": "https://saltcorn.com", |
65
tags.js
@@ -5,66 +5,4 @@ const xss = require("xss"); | ||
const voidHtmlTags = new Set(require("html-tags/void")); | ||
const mkTag = require("./mktag"); | ||
//https://stackoverflow.com/a/54246501 | ||
const camelToCssCase = (str) => | ||
str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`); | ||
const ppClasses = (cs) => | ||
typeof cs === "string" ? cs : !cs ? "" : cs.filter((c) => c).join(" "); | ||
const ppClass = (c) => { | ||
const clss = ppClasses(c); | ||
return clss ? `class="${clss}"` : ""; | ||
}; | ||
const ppStyles = (cs) => | ||
typeof cs === "string" | ||
? cs | ||
: !cs | ||
? "" | ||
: Array.isArray(cs) | ||
? cs.filter((c) => c).join(";") | ||
: typeof cs === "object" | ||
? Object.entries(cs) | ||
.map(([k, v]) => `${camelToCssCase(k)}:${v}`) | ||
.join(";") | ||
: ""; | ||
const ppStyle = (c) => { | ||
const clss = ppStyles(c); | ||
return clss ? `style="${clss}"` : ""; | ||
}; | ||
const ppAttrib = ([k, v]) => | ||
typeof v === "boolean" | ||
? v | ||
? k | ||
: "" | ||
: typeof v === "undefined" | ||
? "" | ||
: k === "class" | ||
? ppClass(v) | ||
: k === "style" | ||
? ppStyle(v) | ||
: `${k}="${v}"`; | ||
const mkTag = (tnm, voidTag) => (...args) => { | ||
var body = ""; | ||
var attribs = " "; | ||
const argIter = (arg) => { | ||
if (typeof arg === "undefined" || arg === null || arg === false) { | ||
//do nothing | ||
} else if (typeof arg === "string") { | ||
body += arg; | ||
} else if (typeof arg === "object") { | ||
if (Array.isArray(arg)) { | ||
arg.forEach(argIter); | ||
} else { | ||
attribs += Object.entries(arg) | ||
.map(ppAttrib) | ||
.filter((s) => s) | ||
.join(" "); | ||
} | ||
} else body += arg; | ||
}; | ||
args.forEach(argIter); | ||
if (attribs === " ") attribs = ""; | ||
return voidTag ? `<${tnm}${attribs}>` : `<${tnm}${attribs}>${body}</${tnm}>`; | ||
}; | ||
//https://stackoverflow.com/a/59220393 | ||
@@ -85,2 +23,3 @@ const domReady = (js) => | ||
...allTags, | ||
genericElement: (tagName, ...rest) => mkTag(tagName, false)(...rest), | ||
domReady, | ||
@@ -87,0 +26,0 @@ text, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63350
16
2121