@endorphinjs/template-runtime
Advanced tools
Comparing version 0.1.15 to 0.1.16
@@ -989,2 +989,24 @@ 'use strict'; | ||
/** | ||
* Sets value of attribute `name` under namespace of `nsURI` to `value` | ||
* | ||
* @param {Injector} injector | ||
* @param {string} nsURI | ||
* @param {string} name | ||
* @param {*} value | ||
*/ | ||
function setAttributeNS(injector, nsURI, name, value) { | ||
if (!injector.attributesNS) { | ||
injector.attributesNS = obj(); | ||
} | ||
const { attributesNS } = injector; | ||
if (!attributesNS[nsURI]) { | ||
attributesNS[nsURI] = changeSet(); | ||
} | ||
attributesNS[nsURI].cur[name] = value; | ||
} | ||
/** | ||
* Updates `attrName` value in `elem`, if required | ||
@@ -1051,3 +1073,4 @@ * @param {HTMLElement} elem | ||
function finalizeAttributes(injector) { | ||
const { attributes } = injector; | ||
const { attributes, attributesNS } = injector; | ||
if (isDefined(attributes.cur['class'])) { | ||
@@ -1057,3 +1080,13 @@ attributes.cur['class'] = normalizeClassName(attributes.cur['class']); | ||
return finalizeItems(attributes, changeAttribute, injector.parentNode); | ||
let updated = finalizeItems(attributes, changeAttribute, injector.parentNode); | ||
if (attributesNS) { | ||
const ctx = { node: injector.parentNode, ns: null }; | ||
for (let ns in attributesNS) { | ||
ctx.ns = ns; | ||
updated |= finalizeItems(attributesNS[ns], changeAttributeNS, ctx); | ||
} | ||
} | ||
return updated; | ||
} | ||
@@ -1097,2 +1130,17 @@ | ||
/** | ||
* Callback for changing attribute value | ||
* @param {string} name | ||
* @param {*} prevValue | ||
* @param {*} newValue | ||
* @param {{node: Element, ns: string}} ctx | ||
*/ | ||
function changeAttributeNS(name, prevValue, newValue, ctx) { | ||
if (isDefined(newValue)) { | ||
ctx.node.setAttributeNS(ctx.ns, name, newValue); | ||
} else if (isDefined(prevValue)) { | ||
ctx.node.removeAttributeNS(ctx.ns, name); | ||
} | ||
} | ||
/** | ||
* Adds pending event `name` handler | ||
@@ -2182,2 +2230,3 @@ * @param {Injector} injector | ||
exports.setAttribute = setAttribute; | ||
exports.setAttributeNS = setAttributeNS; | ||
exports.updateAttribute = updateAttribute; | ||
@@ -2184,0 +2233,0 @@ exports.updateProps = updateProps; |
@@ -985,2 +985,24 @@ /** | ||
/** | ||
* Sets value of attribute `name` under namespace of `nsURI` to `value` | ||
* | ||
* @param {Injector} injector | ||
* @param {string} nsURI | ||
* @param {string} name | ||
* @param {*} value | ||
*/ | ||
function setAttributeNS(injector, nsURI, name, value) { | ||
if (!injector.attributesNS) { | ||
injector.attributesNS = obj(); | ||
} | ||
const { attributesNS } = injector; | ||
if (!attributesNS[nsURI]) { | ||
attributesNS[nsURI] = changeSet(); | ||
} | ||
attributesNS[nsURI].cur[name] = value; | ||
} | ||
/** | ||
* Updates `attrName` value in `elem`, if required | ||
@@ -1047,3 +1069,4 @@ * @param {HTMLElement} elem | ||
function finalizeAttributes(injector) { | ||
const { attributes } = injector; | ||
const { attributes, attributesNS } = injector; | ||
if (isDefined(attributes.cur['class'])) { | ||
@@ -1053,3 +1076,13 @@ attributes.cur['class'] = normalizeClassName(attributes.cur['class']); | ||
return finalizeItems(attributes, changeAttribute, injector.parentNode); | ||
let updated = finalizeItems(attributes, changeAttribute, injector.parentNode); | ||
if (attributesNS) { | ||
const ctx = { node: injector.parentNode, ns: null }; | ||
for (let ns in attributesNS) { | ||
ctx.ns = ns; | ||
updated |= finalizeItems(attributesNS[ns], changeAttributeNS, ctx); | ||
} | ||
} | ||
return updated; | ||
} | ||
@@ -1093,2 +1126,17 @@ | ||
/** | ||
* Callback for changing attribute value | ||
* @param {string} name | ||
* @param {*} prevValue | ||
* @param {*} newValue | ||
* @param {{node: Element, ns: string}} ctx | ||
*/ | ||
function changeAttributeNS(name, prevValue, newValue, ctx) { | ||
if (isDefined(newValue)) { | ||
ctx.node.setAttributeNS(ctx.ns, name, newValue); | ||
} else if (isDefined(prevValue)) { | ||
ctx.node.removeAttributeNS(ctx.ns, name); | ||
} | ||
} | ||
/** | ||
* Adds pending event `name` handler | ||
@@ -2147,3 +2195,3 @@ * @param {Injector} injector | ||
export { get, filter, addDisposeCallback, mountBlock, updateBlock, unmountBlock, mountIterator, updateIterator, unmountIterator, iteratorHost, trimIteratorItems, mountKeyIterator, updateKeyIterator, unmountKeyIterator, createInjector, insert, injectBlock, run, emptyBlockContent, move, disposeBlock, enterScope, exitScope, createScope, setScope, getScope, getProp, getState, getVar, setVar, setAttribute, updateAttribute, updateProps, addClass, finalizeAttributes, normalizeClassName, addEvent, addStaticEvent, finalizeEvents, getEventHandler, mountSlot, unmountSlot, updateSlots, markSlotUpdate, setRef, setStaticRef, finalizeRefs, createComponent, mountComponent, updateComponent, unmountComponent, subscribeStore, scheduleRender, renderComponent, mountInnerHTML, updateInnerHTML, unmountInnerHTML, elem, elemNS, elemWithText, elemNSWithText, text, updateText, domInsert, domRemove, mountPartial, updatePartial, unmountPartial, Store, animateIn, animateOut }; | ||
export { get, filter, addDisposeCallback, mountBlock, updateBlock, unmountBlock, mountIterator, updateIterator, unmountIterator, iteratorHost, trimIteratorItems, mountKeyIterator, updateKeyIterator, unmountKeyIterator, createInjector, insert, injectBlock, run, emptyBlockContent, move, disposeBlock, enterScope, exitScope, createScope, setScope, getScope, getProp, getState, getVar, setVar, setAttribute, setAttributeNS, updateAttribute, updateProps, addClass, finalizeAttributes, normalizeClassName, addEvent, addStaticEvent, finalizeEvents, getEventHandler, mountSlot, unmountSlot, updateSlots, markSlotUpdate, setRef, setStaticRef, finalizeRefs, createComponent, mountComponent, updateComponent, unmountComponent, subscribeStore, scheduleRender, renderComponent, mountInnerHTML, updateInnerHTML, unmountInnerHTML, elem, elemNS, elemWithText, elemNSWithText, text, updateText, domInsert, domRemove, mountPartial, updatePartial, unmountPartial, Store, animateIn, animateOut }; | ||
//# sourceMappingURL=runtime.es.js.map |
{ | ||
"name": "@endorphinjs/template-runtime", | ||
"version": "0.1.15", | ||
"version": "0.1.16", | ||
"description": "EndorphinJS template runtime, embedded with template bundles", | ||
@@ -5,0 +5,0 @@ "main": "./dist/runtime.cjs.js", |
@@ -305,2 +305,6 @@ import { Store } from './lib/store'; | ||
attributesNS?: { | ||
[uri: string]: ChangeSet | ||
} | ||
/** | ||
@@ -307,0 +311,0 @@ * Current event handlers |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
370944
5992