UNPKG

@visactor/openinula-vtable

Version:

The openinula version of VTable

75 lines (59 loc) 3.43 kB
"use strict"; var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) { void 0 === k2 && (k2 = k); var desc = Object.getOwnPropertyDescriptor(m, k); desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = { enumerable: !0, get: function() { return m[k]; } }), Object.defineProperty(o, k2, desc); } : function(o, m, k, k2) { void 0 === k2 && (k2 = k), o[k2] = m[k]; }), __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) { Object.defineProperty(o, "default", { enumerable: !0, value: v }); } : function(o, v) { o.default = v; }), __importStar = this && this.__importStar || function(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (null != mod) for (var k in mod) "default" !== k && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k); return __setModuleDefault(result, mod), result; }; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.findChildByType = exports.findAllByType = exports.toArray = exports.typeOfComponent = exports.getDisplayName = exports.uid = void 0; const vutils_1 = require("@visactor/vutils"), openinula_1 = __importStar(require("openinula")); let id = 0; const uid = prefix => prefix ? `${prefix}-${id++}` : "" + id++; exports.uid = uid; const getDisplayName = Comp => "string" == typeof Comp ? Comp : Comp ? Comp.displayName || Comp.name : ""; exports.getDisplayName = getDisplayName; const typeOfComponent = (component, customTypeKey = "__TYPE") => (null == component ? void 0 : component.props) && component.props[customTypeKey] || "string" == typeof (null == component ? void 0 : component.type) && component.type || (null == component ? void 0 : component.type) && "symbol" == typeof component.type && "Symbol(inula.fragment)" === component.type.toString() && "inula.fragment" || "function" == typeof (null == component ? void 0 : component.type) && component.type || "object" == typeof (null == component ? void 0 : component.type) && "Symbol(inula.forward_ref)" === component.type.$$typeof.toString() && "inula.forward_ref" || "string" == typeof component && "string" || "function" == typeof component && "function" || void 0; exports.typeOfComponent = typeOfComponent; const toArray = children => { let result = []; return openinula_1.default.Children.forEach(children, (child => { (0, vutils_1.isNil)(child) || ((0, openinula_1.isFragment)(child) ? result = result.concat((0, exports.toArray)(child.props.children)) : result.push(child)); })), result; }; exports.toArray = toArray; const findAllByType = (children, type) => { const result = []; let types = []; return types = (0, vutils_1.isArray)(type) ? type.map((t => (0, exports.getDisplayName)(t))) : [ (0, exports.getDisplayName)(type) ], (0, exports.toArray)(children).forEach((child => { const childType = (0, exports.getDisplayName)((0, exports.typeOfComponent)(child)); -1 !== types.indexOf(childType) && result.push(child); })), result; }; exports.findAllByType = findAllByType; const findChildByType = (children, type) => { const result = (0, exports.findAllByType)(children, type); return null == result ? void 0 : result[0]; }; exports.findChildByType = findChildByType;