1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var snabbdom_1 = require("snabbdom");
|
4 | var snabbdom_selector_1 = require("snabbdom-selector");
|
5 | var utils_1 = require("./utils");
|
6 | var VNodeWrapper = (function () {
|
7 | function VNodeWrapper(rootElement) {
|
8 | this.rootElement = rootElement;
|
9 | }
|
10 | VNodeWrapper.prototype.call = function (vnode) {
|
11 | if (utils_1.isDocFrag(this.rootElement)) {
|
12 | return this.wrapDocFrag(vnode === null ? [] : [vnode]);
|
13 | }
|
14 | if (vnode === null) {
|
15 | return this.wrap([]);
|
16 | }
|
17 | var _a = snabbdom_selector_1.selectorParser(vnode), selTagName = _a.tagName, selId = _a.id;
|
18 | var vNodeClassName = snabbdom_selector_1.classNameFromVNode(vnode);
|
19 | var vNodeData = vnode.data || {};
|
20 | var vNodeDataProps = vNodeData.props || {};
|
21 | var _b = vNodeDataProps.id, vNodeId = _b === void 0 ? selId : _b;
|
22 | var isVNodeAndRootElementIdentical = typeof vNodeId === 'string' &&
|
23 | vNodeId.toUpperCase() === this.rootElement.id.toUpperCase() &&
|
24 | selTagName.toUpperCase() === this.rootElement.tagName.toUpperCase() &&
|
25 | vNodeClassName.toUpperCase() === this.rootElement.className.toUpperCase();
|
26 | if (isVNodeAndRootElementIdentical) {
|
27 | return vnode;
|
28 | }
|
29 | return this.wrap([vnode]);
|
30 | };
|
31 | VNodeWrapper.prototype.wrapDocFrag = function (children) {
|
32 | return snabbdom_1.vnode('', { isolate: [] }, children, undefined, this
|
33 | .rootElement);
|
34 | };
|
35 | VNodeWrapper.prototype.wrap = function (children) {
|
36 | var _a = this.rootElement, tagName = _a.tagName, id = _a.id, className = _a.className;
|
37 | var selId = id ? "#" + id : '';
|
38 | var selClass = className ? "." + className.split(" ").join(".") : '';
|
39 | var vnode = snabbdom_1.h("" + tagName.toLowerCase() + selId + selClass, {}, children);
|
40 | vnode.data = vnode.data || {};
|
41 | vnode.data.isolate = vnode.data.isolate || [];
|
42 | return vnode;
|
43 | };
|
44 | return VNodeWrapper;
|
45 | }());
|
46 | exports.VNodeWrapper = VNodeWrapper;
|
47 |
|
\ | No newline at end of file |