@erickmerchant/framework
Advanced tools
Comparing version 43.2.0 to 43.3.0
@@ -27,5 +27,3 @@ import {tokenTypes} from './html.js' | ||
if (map && map[type]) { | ||
map[type](e) | ||
} | ||
map?.[type]?.(e) | ||
}, | ||
@@ -84,14 +82,12 @@ {capture: true} | ||
const append = !isExistingElement || childNode == null | ||
let mode = !isExistingElement || childNode == null ? 2 : !isSameView ? 1 : 0 | ||
let replace = false | ||
let currentChild = childNode | ||
if (next.type === tokenTypes.text) { | ||
if (!append && childNode.nodeType !== 3) { | ||
replace = true | ||
if (!mode && childNode.nodeType !== 3) { | ||
mode = 1 | ||
} | ||
if (append || replace) { | ||
if (mode) { | ||
currentChild = document.createTextNode(next.value) | ||
@@ -103,10 +99,10 @@ } else if (childNode.data !== next.value) { | ||
if ( | ||
!append && | ||
!mode && | ||
(childNode.nodeType !== 1 || | ||
childNode.nodeName.toLowerCase() !== next.tag) | ||
) { | ||
replace = true | ||
mode = 1 | ||
} | ||
if (append || replace) { | ||
if (mode) { | ||
const isSvg = next.tag === 'svg' || target.namespaceURI === svgNamespace | ||
@@ -119,12 +115,12 @@ | ||
if (next.view != null) { | ||
morphRoot(currentChild, next, !(append || replace)) | ||
} else if (append || replace || !isSameView || next.dynamic) { | ||
morph(currentChild, next, variables, !(append || replace), isSameView) | ||
if (next.view) { | ||
morphRoot(currentChild, next, !mode) | ||
} else if (mode || next.dynamic) { | ||
morph(currentChild, next, variables, !mode, isSameView) | ||
} | ||
} | ||
if (append) { | ||
if (mode === 2) { | ||
target.appendChild(currentChild) | ||
} else if (replace) { | ||
} else if (mode === 1) { | ||
target.replaceChild(currentChild, childNode) | ||
@@ -137,4 +133,2 @@ } | ||
const morph = (target, next, variables, isExistingElement, isSameView) => { | ||
const attrNames = [] | ||
let attributeIndex = 0 | ||
@@ -161,4 +155,2 @@ | ||
morphAttribute(target, attribute.key, value, isExistingElement) | ||
attrNames.push(attribute.key) | ||
} else { | ||
@@ -171,4 +163,2 @@ const keys = Object.keys(value) | ||
morphAttribute(target, key, value[key], isExistingElement) | ||
attrNames.push(key) | ||
} | ||
@@ -178,10 +168,2 @@ } | ||
if (isExistingElement && !isSameView) { | ||
for (const attr of target.attributes) { | ||
if (!~attrNames.indexOf(attr.name)) { | ||
target.removeAttribute(attr.name) | ||
} | ||
} | ||
} | ||
let childNode | ||
@@ -207,4 +189,9 @@ | ||
if (typeof child === 'string' || child?.[Symbol.iterator] == null) { | ||
const isIterator = child?.[Symbol.iterator] | ||
const isArray = Array.isArray(child) | ||
if (typeof child === 'string' || !isIterator) { | ||
child = [child] | ||
} else if (isIterator && !isArray) { | ||
child = Array.from(child) | ||
} | ||
@@ -215,5 +202,7 @@ } else { | ||
for (let grand of child) { | ||
if (grand == null || grand.type == null) { | ||
grand = {type: tokenTypes.text, value: grand == null ? '' : grand} | ||
for (let i = 0; i < child.length; i++) { | ||
let grand = child[i] | ||
if (!grand?.type) { | ||
grand = {type: tokenTypes.text, value: grand ?? ''} | ||
} | ||
@@ -249,8 +238,11 @@ | ||
const isSameView = next.view === meta.view | ||
let doMorph = next.dynamic | ||
if (!isExistingElement || !isSameView) { | ||
meta.view = next.view | ||
doMorph = true | ||
} | ||
if (!isExistingElement || !isSameView || next.dynamic) { | ||
if (doMorph) { | ||
morph(target, next, next.variables, isExistingElement, isSameView) | ||
@@ -257,0 +249,0 @@ } |
90
html.js
@@ -32,42 +32,59 @@ const weakMap = new WeakMap() | ||
let afterVar = false | ||
const current = () => str.charAt(i) | ||
const next = () => str.charAt(i + 1) | ||
let str | ||
let i | ||
for (let index = 0, length = strs.length; index < length; index++) { | ||
const str = strs[index] | ||
str = strs[index] | ||
i = 0 | ||
let tag = acc.tag | ||
let i = 0 | ||
const current = () => str.charAt(i) | ||
const next = () => str.charAt(i + 1) | ||
while (current()) { | ||
if (!tag && current() === '<') { | ||
if (!tag) { | ||
let value = '' | ||
let end = false | ||
if (next() === '/') { | ||
end = true | ||
if (current() === '<') { | ||
let end = false | ||
i++ | ||
} | ||
if (next() === '/') { | ||
end = true | ||
while (next() && isOfTag(next())) { | ||
i++ | ||
i++ | ||
} | ||
value += current() | ||
} | ||
while (next() && isOfTag(next())) { | ||
i++ | ||
afterVar = false | ||
value += current() | ||
} | ||
yield { | ||
type: !end ? tokenTypes.tag : tokenTypes.endtag, | ||
value | ||
} | ||
afterVar = false | ||
tag = value | ||
yield { | ||
type: !end ? tokenTypes.tag : tokenTypes.endtag, | ||
value | ||
} | ||
tag = value | ||
i++ | ||
} else { | ||
while (current() && current() !== '<') { | ||
value += current() | ||
i++ | ||
} | ||
if (value.trim() || (afterVar && current() !== '<')) { | ||
yield { | ||
type: tokenTypes.text, | ||
value | ||
} | ||
} | ||
} | ||
} else if (isSpaceChar(current())) { | ||
i++ | ||
} else if (tag && isSpaceChar(current())) { | ||
i++ | ||
} else if (tag && current() === '/' && next() === '>') { | ||
} else if (current() === '/' && next() === '>') { | ||
yield* [ | ||
@@ -85,3 +102,3 @@ END, | ||
i += 2 | ||
} else if (tag && current() === '>') { | ||
} else if (current() === '>') { | ||
yield END | ||
@@ -92,3 +109,3 @@ | ||
i++ | ||
} else if (tag && isOfKey(current())) { | ||
} else if (isOfKey(current())) { | ||
let value = '' | ||
@@ -144,17 +161,2 @@ | ||
i++ | ||
} else if (!tag) { | ||
let value = '' | ||
while (current() && current() !== '<') { | ||
value += current() | ||
i++ | ||
} | ||
if (value.trim() || (afterVar && current() !== '<')) { | ||
yield { | ||
type: tokenTypes.text, | ||
value | ||
} | ||
} | ||
} | ||
@@ -191,3 +193,3 @@ } | ||
if (token == null || token === END) break | ||
if (!token || token === END) break | ||
@@ -244,3 +246,3 @@ let key = false | ||
if (token == null) break | ||
if (!token) break | ||
@@ -301,3 +303,3 @@ if (token.type === tokenTypes.endtag && token.value === child.tag) { | ||
if (token == null) break | ||
if (!token) break | ||
@@ -304,0 +306,0 @@ if (token.type === tokenTypes.tag) { |
{ | ||
"name": "@erickmerchant/framework", | ||
"version": "43.2.0", | ||
"version": "43.3.0", | ||
"description": "A front-end framework.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/erickmerchant/framework#readme", |
@@ -85,3 +85,3 @@ import {escape} from './escape.js' | ||
if (child?.[Symbol.iterator] == null || typeof child === 'string') { | ||
if (!child?.[Symbol.iterator] || typeof child === 'string') { | ||
child = [child] | ||
@@ -100,4 +100,4 @@ } | ||
if (child != null) { | ||
if (child.type != null) { | ||
if (child) { | ||
if (child.type) { | ||
switch (child.type) { | ||
@@ -111,3 +111,3 @@ case tokenTypes.text: | ||
Object.assign({}, child, { | ||
variables: child.view != null ? child.variables : variables | ||
variables: child.view ? child.variables : variables | ||
}) | ||
@@ -114,0 +114,0 @@ ) |
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
18430
599