New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@casl/react

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@casl/react - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

index.d.ts

9

CHANGELOG.md

@@ -6,2 +6,11 @@ # Change Log

<a name="0.2.0"></a>
# 0.2.0 (2018-04-20)
### Features
* **react:** adds typescript definition for package [@casl](https://github.com/casl)/react ([37718fe](https://github.com/stalniy/casl/commit/37718fe)), closes [#54](https://github.com/stalniy/casl/issues/54)
<a name="0.1.0"></a>

@@ -8,0 +17,0 @@ # 0.1.0 (2018-03-23)

200

dist/umd/index.js

@@ -1,199 +0,1 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('prop-types'), require('@casl/ability')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'prop-types', '@casl/ability'], factory) :
(factory((global.casl = global.casl || {}, global.casl.react = {}),global.React,global.React.PropTypes,global.casl));
}(this, (function (exports,React,PropTypes,ability) { 'use strict';
var React__default = 'default' in React ? React['default'] : React;
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var noop = function noop() {};
var Can = function (_PureComponent) {
inherits(Can, _PureComponent);
function Can() {
var _ref;
classCallCheck(this, Can);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _this = possibleConstructorReturn(this, (_ref = Can.__proto__ || Object.getPrototypeOf(Can)).call.apply(_ref, [this].concat(args)));
_this.unsubscribeFromAbility = noop;
_this.state = {
ability: _this.props.ability,
allowed: false
};
return _this;
}
createClass(Can, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(props) {
if (props.ability && this.state.ability !== props.ability) {
this.connectToAbility(props.ability);
this.setState({ ability: props.ability });
}
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
this.connectToAbility(this.state.ability);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.unsubscribeFromAbility();
}
}, {
key: 'connectToAbility',
value: function connectToAbility(ability$$1) {
var _this2 = this;
this.unsubscribeFromAbility();
if (ability$$1) {
this.unsubscribeFromAbility = ability$$1.on('updated', function () {
return _this2.recheck();
});
this.recheck();
}
}
}, {
key: 'recheck',
value: function recheck() {
return this.setState({ allowed: this.check() });
}
}, {
key: 'check',
value: function check() {
return this.state.ability.can(this.props.do, this.props.on);
}
}, {
key: 'render',
value: function render() {
return this.state.allowed ? this.renderChildren() : '';
}
}, {
key: 'renderChildren',
value: function renderChildren() {
var children = this.props.children;
return typeof children === 'function' ? children(this.state.ability) : React__default.Children.only(children);
}
}, {
key: 'allowed',
get: function get$$1() {
return this.state.allowed;
}
}]);
return Can;
}(React.PureComponent);
Can.propTypes = {
do: PropTypes.string.isRequired,
on: PropTypes.oneOfType([PropTypes.object, PropTypes.string]).isRequired,
children: PropTypes.any.isRequired,
ability: PropTypes.instanceOf(ability.Ability).isRequired
};
function createCanBoundTo(ability$$1) {
var _class, _temp;
return _temp = _class = function (_Can) {
inherits(BoundCan, _Can);
function BoundCan() {
var _ref;
classCallCheck(this, BoundCan);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _this = possibleConstructorReturn(this, (_ref = BoundCan.__proto__ || Object.getPrototypeOf(BoundCan)).call.apply(_ref, [this].concat(args)));
_this.state.ability = _this.state.ability || ability$$1;
return _this;
}
return BoundCan;
}(Can), _class.propTypes = Object.assign({}, Can.propTypes, {
ability: PropTypes.instanceOf(ability.Ability)
}), _temp;
}
function createContextualCan(Consumer) {
return function ContextualCan(props) {
return React.createElement(Consumer, null, function (ability$$1) {
return React.createElement(Can, {
ability: props.ability || ability$$1,
do: props.do,
on: props.on,
children: props.children
});
});
};
}
exports.Can = Can;
exports.createCanBoundTo = createCanBoundTo;
exports.createContextualCan = createContextualCan;
Object.defineProperty(exports, '__esModule', { value: true });
})));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types"),require("@casl/ability")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","@casl/ability"],t):t((e.casl=e.casl||{},e.casl.react={}),e.React,e.React.PropTypes,e.casl)}(this,function(e,t,n,i){"use strict";var r="default"in t?t.default:t;n=n&&n.hasOwnProperty("default")?n.default:n;var o=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),c=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},l=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},u=function(){},s=function(e){function t(){var e;o(this,t);for(var n=arguments.length,i=Array(n),r=0;r<n;r++)i[r]=arguments[r];var a=l(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(i)));return a.unsubscribeFromAbility=u,a.state={ability:a.props.ability,allowed:!1},a}return c(t,e),a(t,[{key:"componentWillReceiveProps",value:function(e){e.ability&&this.state.ability!==e.ability&&(this.connectToAbility(e.ability),this.setState({ability:e.ability}))}},{key:"componentWillMount",value:function(){this.connectToAbility(this.state.ability)}},{key:"componentWillUnmount",value:function(){this.unsubscribeFromAbility()}},{key:"connectToAbility",value:function(e){var t=this;this.unsubscribeFromAbility(),e&&(this.unsubscribeFromAbility=e.on("updated",function(){return t.recheck()}),this.recheck())}},{key:"recheck",value:function(){return this.setState({allowed:this.check()})}},{key:"check",value:function(){return this.state.ability.can(this.props.do,this.props.on)}},{key:"render",value:function(){return this.state.allowed?this.renderChildren():""}},{key:"renderChildren",value:function(){var e=this.props.children;return"function"==typeof e?e(this.state.ability):r.Children.only(e)}},{key:"allowed",get:function(){return this.state.allowed}}]),t}(t.PureComponent);s.propTypes={do:n.string.isRequired,on:n.oneOfType([n.object,n.string]).isRequired,children:n.any.isRequired,ability:n.instanceOf(i.Ability).isRequired},e.Can=s,e.createCanBoundTo=function(e){var t,r;return r=t=function(t){function n(){var t;o(this,n);for(var i=arguments.length,r=Array(i),a=0;a<i;a++)r[a]=arguments[a];var c=l(this,(t=n.__proto__||Object.getPrototypeOf(n)).call.apply(t,[this].concat(r)));return c.state.ability=c.state.ability||e,c}return c(n,s),n}(),t.propTypes=Object.assign({},s.propTypes,{ability:n.instanceOf(i.Ability)}),r},e.createContextualCan=function(e){return function(n){return t.createElement(e,null,function(e){return t.createElement(s,{ability:n.ability||e,do:n.do,on:n.on,children:n.children})})}},Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "@casl/react",
"version": "0.1.1",
"version": "0.2.0",
"description": "React component for CASL which makes it easy to add permissions in any React application",

@@ -8,2 +8,3 @@ "main": "dist/umd/index.js",

"es2015": "dist/es6/index.js",
"typings": "./index.d.ts",
"repository": {

@@ -10,0 +11,0 @@ "type": "git",

@@ -1,7 +0,3 @@

# CASL React
# CASL React [![@casl/react NPM version](https://badge.fury.io/js/%40casl%2Freact.svg)](https://badge.fury.io/js/%40casl%2Freact) [![CASL Documentation](https://img.shields.io/badge/documentation-available-brightgreen.svg)](https://stalniy.github.io/casl/) [![CASL Join the chat at https://gitter.im/stalniy-casl/casl](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-casl/casl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![@casl/react NPM version](https://badge.fury.io/js/%40casl%2Freact.svg)](https://badge.fury.io/js/%40casl%2Freact)
[![CASL Documentation](https://img.shields.io/badge/documentation-available-brightgreen.svg)](https://stalniy.github.io/casl/)
[![CASL Join the chat at https://gitter.im/stalniy-casl/casl](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-casl/casl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This package allows to integrate [@casl/ability](/packages/casl-ability) into [React][react] application. So, you can show or hide UI elements based on user ability to see them.

@@ -139,3 +135,3 @@

To crete ability using `AbilityBuilder`
To create ability using `AbilityBuilder`

@@ -142,0 +138,0 @@ ```js

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc