@endorphinjs/template-runtime
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -122,3 +122,3 @@ import { Component } from './component'; | ||
*/ | ||
export declare function classNames(str: string): string[]; | ||
export declare function classNames(str: string): string; | ||
export {}; |
@@ -40,3 +40,3 @@ declare type TextNode = Text & { | ||
*/ | ||
export declare function isolateElement<T extends Element>(el: T, cssScope?: string): T; | ||
export declare function isolateElement<T extends Element>(el: T, cssScope: string): T; | ||
/** | ||
@@ -43,0 +43,0 @@ * @returns Inserted item |
@@ -12,3 +12,4 @@ /** | ||
function elem(tagName, cssScope) { | ||
return isolateElement(document.createElement(tagName), cssScope); | ||
const el = document.createElement(tagName); | ||
return cssScope ? isolateElement(el, cssScope) : el; | ||
} | ||
@@ -20,3 +21,4 @@ /** | ||
function elemNS(tagName, ns, cssScope) { | ||
return isolateElement(document.createElementNS(ns, tagName), cssScope); | ||
const el = document.createElementNS(ns, tagName); | ||
return cssScope ? isolateElement(el, cssScope) : el; | ||
} | ||
@@ -72,3 +74,3 @@ /** | ||
function isolateElement(el, cssScope) { | ||
cssScope && el.setAttribute(cssScope, ''); | ||
el.setAttribute(cssScope, ''); | ||
return el; | ||
@@ -480,3 +482,3 @@ } | ||
if (key === 'class') { | ||
elem.className = classNames(curValue).join(' '); | ||
elem.className = classNames(curValue); | ||
} | ||
@@ -523,13 +525,6 @@ else { | ||
function classNames(str) { | ||
const out = []; | ||
if (isDefined(str)) { | ||
const parts = String(str).split(/\s+/); | ||
for (let i = 0, cl; i < parts.length; i++) { | ||
cl = parts[i]; | ||
if (cl && out.indexOf(cl) === -1) { | ||
out.push(cl); | ||
} | ||
} | ||
return String(str).split(/\s+/).filter(uniqueClassFilter).join(' '); | ||
} | ||
return out; | ||
return ''; | ||
} | ||
@@ -570,2 +565,5 @@ /** | ||
} | ||
function uniqueClassFilter(cl, index, arr) { | ||
return cl ? arr.indexOf(cl) === index : false; | ||
} | ||
@@ -754,3 +752,3 @@ /** | ||
// @ts-ignore: Nulling disposed object | ||
block.start = block.end = null; | ||
block.start = block.end = block.scope = null; | ||
} | ||
@@ -881,3 +879,4 @@ function isElement(obj) { | ||
function createSlot(host, name, cssScope) { | ||
return isolateElement(getSlotContext(host.componentModel.input, name).element, cssScope); | ||
const el = getSlotContext(host.componentModel.input, name).element; | ||
return cssScope ? isolateElement(el, cssScope) : el; | ||
} | ||
@@ -988,2 +987,4 @@ /** | ||
let renderQueue = null; | ||
/** A lookup of normalized attributes */ | ||
const attributeLookup = {}; | ||
/** | ||
@@ -1170,10 +1171,12 @@ * Creates Endorphin DOM component with given definition | ||
const { defaultProps } = component.componentModel; | ||
let prev; | ||
let current; | ||
for (const p in nextProps) { | ||
const prev = props[p]; | ||
let current = nextProps[p]; | ||
if (current == null) { | ||
nextProps[p] = current = defaultProps[p]; | ||
prev = props[p]; | ||
current = nextProps[p]; | ||
if (current == null && p in defaultProps) { | ||
current = defaultProps[p]; | ||
} | ||
if (p === 'class' && current != null) { | ||
current = classNames(current).join(' '); | ||
current = classNames(current); | ||
} | ||
@@ -1187,3 +1190,3 @@ if (current !== prev) { | ||
if (!/^partial:/.test(p)) { | ||
setAttributeExpression(component, p.replace(/[A-Z]/g, kebabCase), current); | ||
setAttributeExpression(component, normalizeAttribute(p), current); | ||
} | ||
@@ -1308,2 +1311,11 @@ } | ||
} | ||
/** | ||
* Normalizes given attribute name: converts `camelCase` to `kebab-case` | ||
*/ | ||
function normalizeAttribute(attr) { | ||
if (!(attr in attributeLookup)) { | ||
attributeLookup[attr] = attr.replace(/[A-Z]/g, kebabCase); | ||
} | ||
return attributeLookup[attr]; | ||
} | ||
@@ -1310,0 +1322,0 @@ function mountBlock(host, injector, get) { |
{ | ||
"name": "@endorphinjs/template-runtime", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "EndorphinJS template runtime, embedded with template bundles", | ||
@@ -52,3 +52,3 @@ "main": "./dist/runtime.cjs.js", | ||
}, | ||
"gitHead": "dac024b0d362eb1175b7d535c1eaecc3d9a262f3" | ||
"gitHead": "834344db094c7b60dc593899060bdc25eca80172" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
443757
5279