@web-atoms/core
Version:
157 lines (156 loc) • 5.83 kB
JavaScript
System.register(["./Bind"], function (_export, _context) {
"use strict";
var bindSymbol, RootObject, XNode, xnodeSymbol, isControl, elementFactorySymbol, isFactorySymbol, attachedSymbol, isTemplateSymbol, constructorNeedsArgumentsSymbol, attachedProperties, attachedId, attach;
_export("RootObject", void 0);
return {
setters: [function (_Bind) {
bindSymbol = _Bind.bindSymbol;
}],
execute: function () {
_export("RootObject", RootObject = class RootObject {
get vsProps() {
return undefined;
}
addEventListener(name, handler) {
return bridge.addEventHandler(this, name, handler);
}
appendChild(e) {
bridge.appendChild(this, e);
}
dispatchEvent(evt) {
bridge.dispatchEvent(evt);
}
});
_export("xnodeSymbol", xnodeSymbol = Symbol("XNode"));
_export("isControl", isControl = Symbol("isControl"));
_export("elementFactorySymbol", elementFactorySymbol = Symbol("elementFactory"));
_export("isFactorySymbol", isFactorySymbol = Symbol("isFactory"));
_export("attachedSymbol", attachedSymbol = Symbol("attached"));
_export("isTemplateSymbol", isTemplateSymbol = Symbol("isTemplate"));
_export("constructorNeedsArgumentsSymbol", constructorNeedsArgumentsSymbol = Symbol("constructorNeedsArguments"));
_export("attachedProperties", attachedProperties = {});
attachedId = 1;
attach = (name, attacher) => {
const key = `:${attachedId++}`;
const fx = v => {
return {
[key]: v
};
};
attachedProperties[key] = attacher;
fx[attachedSymbol] = attacher;
fx[isFactorySymbol] = key;
return fx;
};
XNode = class XNode {
static attach(n, tag) {
return {
factory: (attributes, ...nodes) => new XNode(n, attributes ? Object.assign(Object.assign({}, attributes), {
for: tag
}) : {
for: tag
}, nodes)
};
}
static prepare(n, isProperty, isTemplate) {
function px(v) {
return {
[n]: v
};
}
px.factory = (a, ...nodes) => {
return new XNode(n, a, nodes, isProperty, isTemplate);
};
px.toString = () => n;
return px;
}
static getClass(fullTypeName, assemblyName) {
const n = fullTypeName + ";" + assemblyName;
const cx = XNode.classes[n] || (XNode.classes[n] = bridge.getClass(fullTypeName, assemblyName, RootObject, (name, isProperty, isTemplate) => (a, ...nodes) => new XNode(name, a, nodes, isProperty, isTemplate)));
return cx;
}
static namespace(ns, assemblyName) {
return (type, isTemplate) => {
return c => {
for (const key in c) {
if (c.hasOwnProperty(key)) {
const element = c[key];
if (element) {
const n = ns + "." + type + ":" + key + ";" + assemblyName;
const af = a => {
const r = {
[n]: a
};
Object.defineProperty(r, "toString", {
value: () => n,
enumerable: false,
configurable: false
});
return r;
};
af.factory = (a, ...nodes) => new XNode(n, a, nodes, true, element.isTemplate);
af.toString = () => n;
c[key] = af;
}
}
}
const tn = ns + "." + type + ";" + assemblyName;
c.factory = (a, ...nodes) => {
return new XNode(tn, a, nodes, false, isTemplate);
};
c.toString = () => tn;
};
};
}
static create(name, attributes, ...children) {
if (typeof name === "string") {
return new XNode(name, attributes, children);
}
if (name[isFactorySymbol]) {
return new XNode(name, attributes, children);
}
if (name.factory) {
return name.factory(attributes, ...children);
}
switch (typeof name) {
case "object":
name = name.toString();
break;
case "function":
return name(attributes || {}, ...children);
}
return new XNode(name, attributes, children);
}
constructor(name, attributes, children, isProperty, isTemplate) {
this.name = name;
this.attributes = attributes;
this.children = children;
this.isProperty = isProperty;
this.isTemplate = isTemplate;
this[xnodeSymbol] = true;
}
toString() {
if (typeof this.name === "string") {
return `name is of type string and value is ${this.name}`;
}
return `name is of type ${typeof this.name}`;
}
};
XNode.isFactory = isFactorySymbol;
XNode.elementFactory = elementFactorySymbol;
XNode.bindSymbol = bindSymbol;
XNode.isTemplate = isTemplateSymbol;
XNode.prepareAttached = attach;
XNode.constructorNeedsArguments = constructorNeedsArgumentsSymbol;
XNode.classes = {};
XNode.factory = (name, isProperty, isTemplate) => (a, ...nodes) => {
return new XNode(name, a, nodes, isProperty, isTemplate);
};
_export("default", XNode);
if (typeof bridge !== "undefined") {
bridge.XNode = XNode;
}
}
};
});
//# sourceMappingURL=XNode.js.map