@skele/core
Version:
Core package of the Skele framework. Element definitions, registrations and traversal.
1 lines • 3.36 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});exports.select=exports.isLocationSeq=exports.isStringArray=void 0;var _ramda=_interopRequireDefault(require("ramda"));var _immutable=_interopRequireDefault(require("immutable"));var zip=_interopRequireWildcard(require("./impl"));var _selector=require("./skele/selector");var _data=require("../data");function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj;}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){var desc=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):{};if(desc.get||desc.set){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}}newObj.default=obj;return newObj;}}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance");}function _iterableToArray(iter){if((typeof Symbol==="function"?Symbol.iterator:"@@iterator")in Object(iter)||Object.prototype.toString.call(iter)==="[object Arguments]")return Array.from(iter);}function _arrayWithoutHoles(arr){if(Array.isArray(arr)){for(var i=0,arr2=new Array(arr.length);i<arr.length;i++){arr2[i]=arr[i];}return arr2;}}var isStringArray=_ramda.default.allPass([_ramda.default.is(Array),_ramda.default.or(_ramda.default.all(_ramda.default.is(String)),_ramda.default.propEq('length',0))]);exports.isStringArray=isStringArray;var isTrue=_ramda.default.allPass([_ramda.default.is(Boolean),_ramda.default.equals(true)]);var isLocation=function isLocation(loc){return loc&&loc.meta&&loc.meta.isBranch&&loc.meta.children&&loc.meta.makeNode;};var isLocationSeq=_ramda.default.allPass([_immutable.default.Iterable.isIterable,function(locSeq){return _ramda.default.complement(_ramda.default.isEmpty)(_toConsumableArray(locSeq));},function(locSeq){return _ramda.default.all(isLocation)(_toConsumableArray(locSeq));}]);exports.isLocationSeq=isLocationSeq;var select=function select(){var predicates=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var location=arguments.length>1?arguments[1]:undefined;var result=_immutable.default.Seq.of(location);var _loop=function _loop(pred){if(_ramda.default.is(String,pred)){result=result.flatMap(function(loc){return(0,_selector.childrenAt)(pred,loc);}).filter(function(l){return!!l;});}else if(isStringArray(pred)){result=result.filter(function(loc){return(0,_data.isOfKind)(pred,zip.node(loc));});}else if(_ramda.default.is(Function,pred)){result=result.flatMap(function(loc){var res=pred(loc);if(isLocationSeq(res)||isLocation(res)){return res;}else if(isTrue(res)){return _immutable.default.Seq.of(loc);}else{return null;}}).filter(function(l){return!!l;});}else{return{v:_immutable.default.Seq()};}};for(var _iterator=predicates,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var _ref;if(_isArray){if(_i>=_iterator.length)break;_ref=_iterator[_i++];}else{_i=_iterator.next();if(_i.done)break;_ref=_i.value;}var pred=_ref;var _ret=_loop(pred);if(typeof _ret==="object")return _ret.v;}return result;};exports.select=select;