UNPKG

@tarojs/components

Version:
74 lines (73 loc) 2.04 kB
import { Host, h } from '@stencil/core'; const nativeCloneNode = Node.prototype.cloneNode; function cloneNode(node, deep) { const clonedNode = nativeCloneNode.call(node, false); const srcChildNodes = childNodes(node); if (deep) { for (let i = 0; i < srcChildNodes.length; i++) { const srcNode = srcChildNodes[i]; let srcDeep = deep; if (srcNode.nodeType !== 2 && srcNode.nodeType !== 8) { // Note: 没有引用节点(s-cr[reference comment])的情况下,不复制子节点避免冗余(例如:Image 组件) if (!srcNode['s-cr']) { srcDeep = false; } const childClone = cloneNode(srcNode, srcDeep); clonedNode.appendChild(childClone); } } } return clonedNode; } function childNodes(node) { const childNodes = node.childNodes; // check if element is stencil element without shadow dom // and then detect elements that were slotted into the element if (node['s-sc']) { const result = []; for (let i = 0; i < childNodes.length; i++) { const slot = childNodes[i]['s-nr']; if (slot) { result.push(slot); } } return result; } return Array.from(childNodes); } export class SwiperItem { constructor() { this.itemId = undefined; } componentDidRender() { this.el.cloneNode = (deep = false) => { return cloneNode.call(null, this.el, deep); }; } render() { return (h(Host, { class: 'swiper-slide', "item-id": this.itemId })); } static get is() { return "taro-swiper-item-core"; } static get properties() { return { "itemId": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "item-id", "reflect": false } }; } static get elementRef() { return "el"; } }