diff --git a/src/lib/js/common/dom.js b/src/lib/js/common/dom.js
index a255a123..3a2850c8 100644
--- a/src/lib/js/common/dom.js
+++ b/src/lib/js/common/dom.js
@@ -23,6 +23,8 @@ const iconFontTemplates = {
fontello: icon => `${icon}`,
}
+const inputTags = new Set(['input', 'textarea', 'select'])
+
/**
* General purpose markup utilities and generator.
*/
@@ -31,20 +33,12 @@ class DOM {
* Set defaults, store references to key elements
* like stages, rows, columns etc
*/
- constructor() {
- this.options = Object.create(null)
- this.styleSheet = (() => {
- const style = document.createElement('style')
- style.setAttribute('media', 'screen')
- style.setAttribute('type', 'text/css')
- style.appendChild(document.createTextNode(''))
- document.head.appendChild(style)
- return style.sheet
- })()
+ constructor(options = Object.create(null)) {
+ this.options = options
}
set setOptions(options) {
- this.options = merge(Object.assign({}, this.options, options))
+ this.options = merge(this.options, options)
}
/**
@@ -52,14 +46,18 @@ class DOM {
* @param {Object|String} elem
* @return {Object} valid element object
*/
- processTagName(elem) {
+ processTagName(elemArg) {
+ let elem = elemArg
let tagName
if (typeof elem === 'string') {
tagName = elem
elem = { tag: tagName }
+ return elem
}
+
if (elem.attrs) {
const { tag, ...restAttrs } = elem.attrs
+ // this is used for interchangeable tagNames like h1, h2, h3 etc
if (tag) {
if (typeof tag === 'string') {
tagName = tag
@@ -92,12 +90,11 @@ class DOM {
* @return {Object} DOM Object
*/
create = (elemArg, isPreview = false) => {
- let elem = elemArg
- if (!elem) {
+ if (!elemArg) {
return
}
- elem = this.processTagName(elem)
+ const { className, options, ...elem } = this.processTagName(elemArg)
const _this = this
let childType
const { tag } = elem
@@ -147,41 +144,29 @@ class DOM {
processed.push('tag')
// check for root className property
- if (elem.className) {
- const { className } = elem
- elem.attrs = Object.assign({}, elem.attrs, { className })
- delete elem.className
+ if (className) {
+ elem.attrs = { ...elem.attrs, className }
}
- // Append Element Content
- if (elem.options) {
- let { options } = elem
- options = this.processOptions(options, elem, isPreview)
+ if (options) {
+ const processedOptions = this.processOptions(options, elem, isPreview)
if (this.holdsContent(element) && tag !== 'button') {
// mainly used for