Comparing version 0.4.24 to 0.4.25-0
@@ -132,5 +132,5 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
render() { | ||
return getSlot(this.$slots); | ||
return getSlot('binder', this.$slots); | ||
} | ||
}); | ||
export default Binder; |
@@ -26,6 +26,8 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
if (syncTarget) { | ||
return withDirectives(getFirstVNode(this.$slots), [[setTargetDirective]]); | ||
return withDirectives(getFirstVNode('follower', this.$slots), [ | ||
[setTargetDirective] | ||
]); | ||
} | ||
return getFirstVNode(this.$slots); | ||
return getFirstVNode('follower', this.$slots); | ||
} | ||
}); |
@@ -29,9 +29,9 @@ import { Teleport, h, toRef, computed, defineComponent } from 'vue'; | ||
? this.disabled | ||
? getSlot(this.$slots) | ||
? getSlot('lazy-teleport', this.$slots) | ||
: h(Teleport, { | ||
disabled: this.disabled, | ||
to: this.mergedTo | ||
}, getSlot(this.$slots)) | ||
}, getSlot('lazy-teleport', this.$slots)) | ||
: null; | ||
} | ||
}); |
@@ -1,3 +0,4 @@ | ||
import { Slots, VNode } from 'vue'; | ||
export declare function getSlot(slots: Slots, slotName?: string): VNode[]; | ||
export declare function getFirstVNode(slots: Slots, slotName?: string): VNode; | ||
import { VNodeChild, VNode, Slots } from 'vue'; | ||
export declare function getSlot(scope: string, slots: Slots, slotName?: string): VNode[]; | ||
export declare function flatten(vNodes: VNodeChild[], filterCommentNode?: boolean, result?: VNode[]): VNode[]; | ||
export declare function getFirstVNode(scope: string, slots: Slots, slotName?: string): VNode; |
@@ -1,14 +0,44 @@ | ||
export function getSlot(slots, slotName = 'default') { | ||
import { Fragment, createTextVNode, Comment } from 'vue'; | ||
export function getSlot(scope, slots, slotName = 'default') { | ||
const slot = slots[slotName]; | ||
if (slot === undefined) { | ||
throw new Error(`[vueuc/binder]: slot[${slotName}] is empty.`); | ||
throw new Error(`[vueuc/${scope}]: slot[${slotName}] is empty.`); | ||
} | ||
return slot(); | ||
} | ||
export function getFirstVNode(slots, slotName = 'default') { | ||
// o(n) flatten | ||
export function flatten(vNodes, filterCommentNode = true, result = []) { | ||
vNodes.forEach((vNode) => { | ||
if (vNode === null) | ||
return; | ||
if (typeof vNode !== 'object') { | ||
if (typeof vNode === 'string' || typeof vNode === 'number') { | ||
result.push(createTextVNode(String(vNode))); | ||
} | ||
return; | ||
} | ||
if (Array.isArray(vNode)) { | ||
flatten(vNode, filterCommentNode, result); | ||
return; | ||
} | ||
if (vNode.type === Fragment) { | ||
if (vNode.children === null) | ||
return; | ||
if (Array.isArray(vNode.children)) { | ||
flatten(vNode.children, filterCommentNode, result); | ||
} | ||
// rawSlot | ||
} | ||
else if (vNode.type !== Comment) { | ||
result.push(vNode); | ||
} | ||
}); | ||
return result; | ||
} | ||
export function getFirstVNode(scope, slots, slotName = 'default') { | ||
const slot = slots[slotName]; | ||
if (slot === undefined) { | ||
throw new Error(`[vueuc/binder]: slot[${slotName}] is empty.`); | ||
throw new Error(`[vueuc/${scope}]: slot[${slotName}] is empty.`); | ||
} | ||
const content = slot(); | ||
const content = flatten(slot()); | ||
// vue will normalize the slot, so slot must be an array | ||
@@ -19,4 +49,4 @@ if (content.length === 1) { | ||
else { | ||
throw new Error(`[vueuc/binder]: slot[${slotName}] should have exactly one child.`); | ||
throw new Error(`[vueuc/${scope}]: slot[${slotName}] should have exactly one child.`); | ||
} | ||
} |
@@ -134,5 +134,5 @@ "use strict"; | ||
render() { | ||
return (0, v_node_1.getSlot)(this.$slots); | ||
return (0, v_node_1.getSlot)('binder', this.$slots); | ||
} | ||
}); | ||
exports.default = Binder; |
@@ -28,6 +28,8 @@ "use strict"; | ||
if (syncTarget) { | ||
return (0, vue_1.withDirectives)((0, v_node_1.getFirstVNode)(this.$slots), [[setTargetDirective]]); | ||
return (0, vue_1.withDirectives)((0, v_node_1.getFirstVNode)('follower', this.$slots), [ | ||
[setTargetDirective] | ||
]); | ||
} | ||
return (0, v_node_1.getFirstVNode)(this.$slots); | ||
return (0, v_node_1.getFirstVNode)('follower', this.$slots); | ||
} | ||
}); |
@@ -31,9 +31,9 @@ "use strict"; | ||
? this.disabled | ||
? (0, v_node_1.getSlot)(this.$slots) | ||
? (0, v_node_1.getSlot)('lazy-teleport', this.$slots) | ||
: (0, vue_1.h)(vue_1.Teleport, { | ||
disabled: this.disabled, | ||
to: this.mergedTo | ||
}, (0, v_node_1.getSlot)(this.$slots)) | ||
}, (0, v_node_1.getSlot)('lazy-teleport', this.$slots)) | ||
: null; | ||
} | ||
}); |
@@ -1,3 +0,4 @@ | ||
import { Slots, VNode } from 'vue'; | ||
export declare function getSlot(slots: Slots, slotName?: string): VNode[]; | ||
export declare function getFirstVNode(slots: Slots, slotName?: string): VNode; | ||
import { VNodeChild, VNode, Slots } from 'vue'; | ||
export declare function getSlot(scope: string, slots: Slots, slotName?: string): VNode[]; | ||
export declare function flatten(vNodes: VNodeChild[], filterCommentNode?: boolean, result?: VNode[]): VNode[]; | ||
export declare function getFirstVNode(scope: string, slots: Slots, slotName?: string): VNode; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFirstVNode = exports.getSlot = void 0; | ||
function getSlot(slots, slotName = 'default') { | ||
exports.getFirstVNode = exports.flatten = exports.getSlot = void 0; | ||
const vue_1 = require("vue"); | ||
function getSlot(scope, slots, slotName = 'default') { | ||
const slot = slots[slotName]; | ||
if (slot === undefined) { | ||
throw new Error(`[vueuc/binder]: slot[${slotName}] is empty.`); | ||
throw new Error(`[vueuc/${scope}]: slot[${slotName}] is empty.`); | ||
} | ||
@@ -12,8 +13,38 @@ return slot(); | ||
exports.getSlot = getSlot; | ||
function getFirstVNode(slots, slotName = 'default') { | ||
// o(n) flatten | ||
function flatten(vNodes, filterCommentNode = true, result = []) { | ||
vNodes.forEach((vNode) => { | ||
if (vNode === null) | ||
return; | ||
if (typeof vNode !== 'object') { | ||
if (typeof vNode === 'string' || typeof vNode === 'number') { | ||
result.push((0, vue_1.createTextVNode)(String(vNode))); | ||
} | ||
return; | ||
} | ||
if (Array.isArray(vNode)) { | ||
flatten(vNode, filterCommentNode, result); | ||
return; | ||
} | ||
if (vNode.type === vue_1.Fragment) { | ||
if (vNode.children === null) | ||
return; | ||
if (Array.isArray(vNode.children)) { | ||
flatten(vNode.children, filterCommentNode, result); | ||
} | ||
// rawSlot | ||
} | ||
else if (vNode.type !== vue_1.Comment) { | ||
result.push(vNode); | ||
} | ||
}); | ||
return result; | ||
} | ||
exports.flatten = flatten; | ||
function getFirstVNode(scope, slots, slotName = 'default') { | ||
const slot = slots[slotName]; | ||
if (slot === undefined) { | ||
throw new Error(`[vueuc/binder]: slot[${slotName}] is empty.`); | ||
throw new Error(`[vueuc/${scope}]: slot[${slotName}] is empty.`); | ||
} | ||
const content = slot(); | ||
const content = flatten(slot()); | ||
// vue will normalize the slot, so slot must be an array | ||
@@ -24,5 +55,5 @@ if (content.length === 1) { | ||
else { | ||
throw new Error(`[vueuc/binder]: slot[${slotName}] should have exactly one child.`); | ||
throw new Error(`[vueuc/${scope}]: slot[${slotName}] should have exactly one child.`); | ||
} | ||
} | ||
exports.getFirstVNode = getFirstVNode; |
{ | ||
"name": "vueuc", | ||
"version": "0.4.24", | ||
"version": "0.4.25-0", | ||
"description": "Util Components for Vue", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214893
5621