UNPKG

@opentiny/vue-renderless

Version:

An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.

40 lines (39 loc) 1.41 kB
import "../chunk-G2ADBYYC.js"; import { getGapStyle } from "./index"; const api = ["state", "orderedChildren"]; function isVNodeFn(node) { return !!(node && (node.__v_isVNode || node.componentOptions)); } const renderless = (props, hooks, { slots }) => { const { reactive, computed } = hooks; const state = reactive({ gapStyle: computed(() => getGapStyle(props)) }); const orderedChildren = computed(() => { var _a, _b; const children = ((_a = slots.default) == null ? void 0 : _a.call(slots)) || []; const validChildren = children.filter((v) => { if (!isVNodeFn(v)) return false; const type = v.type; return type !== "Comment" && type !== Symbol.for("v-comment"); }); if (!((_b = props.order) == null ? void 0 : _b.length)) return validChildren; const map = {}; validChildren.forEach((child) => { var _a2, _b2, _c; const key = (_c = child.key) != null ? _c : Array.isArray((_a2 = child.props) == null ? void 0 : _a2.class) ? child.props.class.join(" ") : (_b2 = child.props) == null ? void 0 : _b2.class; if (key) map[String(key)] = child; }); const sorted = props.order.map((k) => map[k]).filter(Boolean); const rest = validChildren.filter((v) => !props.order.includes(String(v.key))); return [...sorted, ...rest]; }); return { state, orderedChildren }; }; export { api, renderless };