@casl/react
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -5,2 +5,43 @@ # Change Log | ||
# [2.2.0](https://github.com/stalniy/casl/compare/@casl/react@2.1.1...@casl/react@2.2.0) (2020-12-26) | ||
### Bug Fixes | ||
* **angular:** fixes sourcemap generation for the code built by ngc ([7715263](https://github.com/stalniy/casl/commit/771526379ff8203170a433d71b68644a48ff44eb)), closes [#387](https://github.com/stalniy/casl/issues/387) [#382](https://github.com/stalniy/casl/issues/382) | ||
* **package:** removes `engine` section that points to npm@6 ([eecd12a](https://github.com/stalniy/casl/commit/eecd12ac49f56d6a0f57d1a57fb37487335b5f03)), closes [#417](https://github.com/stalniy/casl/issues/417) | ||
### Features | ||
* **builder:** improves typings for AbilityBuilder [skip release] ([ebd4d17](https://github.com/stalniy/casl/commit/ebd4d17a355a2646467033118a3d6efee4321d27)), closes [#379](https://github.com/stalniy/casl/issues/379) | ||
* **esm:** adds ESM support for latest Node.js through `exports` prop in package.json ([cac2506](https://github.com/stalniy/casl/commit/cac2506a80c18f194210c2d89108d1d094751fa4)), closes [#331](https://github.com/stalniy/casl/issues/331) | ||
### BREAKING CHANGES | ||
* **builder:** changes main generic parameter to be a class instead of instance and makes `defineAbility` to accept options as the 2nd argument. | ||
**Before** | ||
```ts | ||
import { AbilityBuilder, defineAbility, Ability } from '@casl/ability'; | ||
const resolveAction = (action: string) => {/* custom implementation */ }; | ||
const ability = defineAbility({ resolveAction }, (can) => can('read', 'Item')); | ||
const builder = new AbilityBuilder<Ability>(Ability); | ||
``` | ||
**After** | ||
```ts | ||
import { AbilityBuilder, defineAbility, Ability } from '@casl/ability'; | ||
const resolveAction = (action: string) => {/* custom implementation */ }; | ||
const ability = defineAbility((can) => can('read', 'Item'), { resolveAction }); | ||
const builder = new AbilityBuilder(Ability); // first argument is now mandatory! | ||
``` | ||
The 1st parameter to `AbilityBuilder` is now madatory. This allows to infer generic parameters from it and makes AbilityType that is built to be explicit. | ||
## [2.1.1](https://github.com/stalniy/casl/compare/@casl/react@2.1.0...@casl/react@2.1.1) (2020-06-09) | ||
@@ -7,0 +48,0 @@ |
@@ -1,2 +0,2 @@ | ||
import t,{Fragment as n,createElement as r,Children as i,PureComponent as u}from"react";function o(t,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function e(){return(e=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function c(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}var f=function(){},s=n?function(t){return t?t.length>1?r.apply(void 0,[n,null].concat(t)):i.only(t):null}:i.only,a=function(t){function n(){for(var n,r=arguments.length,i=new Array(r),u=0;u<r;u++)i[u]=arguments[u];return(n=t.call.apply(t,[this].concat(i))||this).t=!1,n.i=null,n.u=f,n}c(n,t);var r,i,u,e=n.prototype;return e.componentWillUnmount=function(){this.u()},e.o=function(t){var n=this;t!==this.i&&(this.u(),this.i=null,t&&(this.i=t,this.u=t.on("updated",(function(){return n.forceUpdate()}))))},e.s=function(){var t=this.props,n=t.of||t.a||t.an||t.this||t.on,r=t.not?"cannot":"can";return t.ability[r](t.I||t.do,n,t.field)},e.render=function(){return this.o(this.props.ability),this.t=this.s(),this.props.passThrough||this.t?this.h():null},e.h=function(){var t=this.props,n=t.children,r=t.ability,i="function"==typeof n?n(this.t,r):n;return s(i)},r=n,(i=[{key:"allowed",get:function(){return this.t}}])&&o(r.prototype,i),u&&o(r,u),n}(u);function h(t){var n,r;return r=n=function(t){function n(){return t.apply(this,arguments)||this}return c(n,t),n}(a),n.defaultProps={ability:t},r}function l(t){return function(n){return r(t,null,(function(t){return r(a,e({ability:t},n))}))}}function v(n){if("production"!==process.env.NODE_ENV&&"function"!=typeof t.useContext)throw new Error("You must use React >= 16.8 in order to use useAbility()");var r=t.useContext(n),i=t.useState(),u=i[0],o=i[1];return t.useEffect((function(){return r.on("updated",(function(t){t.rules!==u&&o(t.rules)}))}),[]),r}export{a as Can,h as createCanBoundTo,l as createContextualCan,v as useAbility}; | ||
import t,{Fragment as n,createElement as r,Children as i,PureComponent as u}from"react";function e(t,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||false;i.configurable=true;if("value"in i)i.writable=true;Object.defineProperty(t,i.key,i)}}function o(t,n,r){if(n)e(t.prototype,n);if(r)e(t,r);return t}function f(){f=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)if(Object.prototype.hasOwnProperty.call(r,i))t[i]=r[i]}return t};return f.apply(this,arguments)}function c(t,n){t.prototype=Object.create(n.prototype);t.prototype.constructor=t;t.__proto__=n}var a=function t(){};var s=n?function(t){if(!t)return null;return t.length>1?r.apply(void 0,[n,null].concat(t)):i.only(t)}:i.only;var h=function(t){c(n,t);function n(){var n;for(var r=arguments.length,i=new Array(r),u=0;u<r;u++)i[u]=arguments[u];n=t.call.apply(t,[this].concat(i))||this;n.t=false;n.i=null;n.u=a;return n}var r=n.prototype;r.componentWillUnmount=function t(){this.u()};r.o=function _connectToAbility(t){var n=this;if(t===this.i)return;this.u();this.i=null;if(t){this.i=t;this.u=t.on("updated",(function(){return n.forceUpdate()}))}};r.h=function t(){var n=this.props;var r=n.of||n.a||n.an||n.this||n.on;var i=n.not?"cannot":"can";return n.ability[i](n.I||n.do,r,n.field)};r.render=function t(){this.o(this.props.ability);this.t=this.h();return this.props.passThrough||this.t?this.l():null};r.l=function t(){var n=this.props,r=n.children,i=n.ability;var u="function"===typeof r?r(this.t,i):r;return s(u)};o(n,[{key:"allowed",get:function t(){return this.t}}]);return n}(u);function l(t){var n,r;return r=n=function(t){c(n,t);function n(){return t.apply(this,arguments)||this}return n}(h),n.defaultProps={ability:t},r}function v(t){return function(n){return r(t,null,(function(t){return r(h,f({ability:t},n))}))}}function useAbility(n){if("production"!==process.env.NODE_ENV&&"function"!==typeof t.useContext)throw new Error("You must use React >= 16.8 in order to use useAbility()");var r=t.useContext(n);var i=t.useState(),u=i[0],e=i[1];t.useEffect((function(){return r.on("updated",(function(t){if(t.rules!==u)e(t.rules)}))}),[]);return r}export{h as Can,l as createCanBoundTo,v as createContextualCan,useAbility}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n(((t=t||self).casl=t.casl||{},t.casl.react={}),t.React)}(this,(function(t,n){"use strict";var i="default"in n?n.default:n;function r(t,n){for(var i=0;i<n.length;i++){var r=n[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(){return(u=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t}).apply(this,arguments)}function e(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}var o=function(){},f=n.Fragment?function(t){return t?t.length>1?n.createElement.apply(void 0,[n.Fragment,null].concat(t)):n.Children.only(t):null}:n.Children.only,c=function(t){function n(){for(var n,i=arguments.length,r=new Array(i),u=0;u<i;u++)r[u]=arguments[u];return(n=t.call.apply(t,[this].concat(r))||this).t=!1,n.i=null,n.u=o,n}e(n,t);var i,u,c,s=n.prototype;return s.componentWillUnmount=function(){this.u()},s.o=function(t){var n=this;t!==this.i&&(this.u(),this.i=null,t&&(this.i=t,this.u=t.on("updated",(function(){return n.forceUpdate()}))))},s.s=function(){var t=this.props,n=t.of||t.a||t.an||t.this||t.on,i=t.not?"cannot":"can";return t.ability[i](t.I||t.do,n,t.field)},s.render=function(){return this.o(this.props.ability),this.t=this.s(),this.props.passThrough||this.t?this.h():null},s.h=function(){var t=this.props,n=t.children,i=t.ability,r="function"==typeof n?n(this.t,i):n;return f(r)},i=n,(u=[{key:"allowed",get:function(){return this.t}}])&&r(i.prototype,u),c&&r(i,c),n}(n.PureComponent);t.Can=c,t.createCanBoundTo=function(t){var n,i;return i=n=function(t){function n(){return t.apply(this,arguments)||this}return e(n,t),n}(c),n.defaultProps={ability:t},i},t.createContextualCan=function(t){return function(i){return n.createElement(t,null,(function(t){return n.createElement(c,u({ability:t},i))}))}},t.useAbility=function(t){if("production"!==process.env.NODE_ENV&&"function"!=typeof i.useContext)throw new Error("You must use React >= 16.8 in order to use useAbility()");var n=i.useContext(t),r=i.useState(),u=r[0],e=r[1];return i.useEffect((function(){return n.on("updated",(function(t){t.rules!==u&&e(t.rules)}))}),[]),n},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
(function(t,n){"object"===typeof exports&&"undefined"!==typeof module?n(exports,require("react")):"function"===typeof define&&define.amd?define(["exports","react"],n):(t="undefined"!==typeof globalThis?globalThis:t||self,n((t.casl=t.casl||{},t.casl.react={}),t.React))})(this,(function(t,n){"use strict";function i(t){return t&&"object"===typeof t&&"default"in t?t:{default:t}}var r=i(n);function e(t,n){for(var i=0;i<n.length;i++){var r=n[i];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(t,r.key,r)}}function u(t,n,i){if(n)e(t.prototype,n);if(i)e(t,i);return t}function o(){o=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var r in i)if(Object.prototype.hasOwnProperty.call(i,r))t[r]=i[r]}return t};return o.apply(this,arguments)}function f(t,n){t.prototype=Object.create(n.prototype);t.prototype.constructor=t;t.__proto__=n}var c=function t(){};var s=n.Fragment?function(t){if(!t)return null;return t.length>1?n.createElement.apply(void 0,[n.Fragment,null].concat(t)):n.Children.only(t)}:n.Children.only;var a=function(t){f(n,t);function n(){var n;for(var i=arguments.length,r=new Array(i),e=0;e<i;e++)r[e]=arguments[e];n=t.call.apply(t,[this].concat(r))||this;n.t=false;n.i=null;n.u=c;return n}var i=n.prototype;i.componentWillUnmount=function t(){this.u()};i.o=function _connectToAbility(t){var n=this;if(t===this.i)return;this.u();this.i=null;if(t){this.i=t;this.u=t.on("updated",(function(){return n.forceUpdate()}))}};i.l=function t(){var n=this.props;var i=n.of||n.a||n.an||n.this||n.on;var r=n.not?"cannot":"can";return n.ability[r](n.I||n.do,i,n.field)};i.render=function t(){this.o(this.props.ability);this.t=this.l();return this.props.passThrough||this.t?this.h():null};i.h=function t(){var n=this.props,i=n.children,r=n.ability;var e="function"===typeof i?i(this.t,r):i;return s(e)};u(n,[{key:"allowed",get:function t(){return this.t}}]);return n}(n.PureComponent);function l(t){var n,i;return i=n=function(t){f(n,t);function n(){return t.apply(this,arguments)||this}return n}(a),n.defaultProps={ability:t},i}function h(t){return function(i){return n.createElement(t,null,(function(t){return n.createElement(a,o({ability:t},i))}))}}function useAbility(t){if("production"!==process.env.NODE_ENV&&"function"!==typeof r["default"].useContext)throw new Error("You must use React >= 16.8 in order to use useAbility()");var n=r["default"].useContext(t);var i=r["default"].useState(),e=i[0],u=i[1];r["default"].useEffect((function(){return n.on("updated",(function(t){if(t.rules!==e)u(t.rules)}))}),[]);return n}t.Can=a;t.createCanBoundTo=l;t.createContextualCan=h;t.useAbility=useAbility;Object.defineProperty(t,"__esModule",{value:true})})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@casl/react", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "React component for CASL which makes it easy to add permissions in any React application", | ||
"main": "dist/umd/index.js", | ||
"module": "dist/es5m/index.js", | ||
"es2015": "dist/es6/index.js", | ||
"es2015": "dist/es6m/index.mjs", | ||
"typings": "./index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/es6m/index.mjs", | ||
"require": "./dist/umd/index.js" | ||
} | ||
}, | ||
"repository": { | ||
@@ -13,2 +19,3 @@ "type": "git", | ||
}, | ||
"homepage": "https://casl.js.org", | ||
"publishConfig": { | ||
@@ -18,5 +25,5 @@ "access": "public" | ||
"scripts": { | ||
"prebuild": "npm run build.types", | ||
"build": "rollup -c ../../rollup.config.js -n casl.react -g react:React,prop-types:React.PropTypes,@casl/ability:casl", | ||
"build.types": "rm -rf dist/types/* && tsc", | ||
"prebuild": "rm -rf dist/* && npm run build.types", | ||
"build": "BUILD_TYPES=es5m,es6m,umd rollup -c ../../rollup.config.js -n casl.react -g react:React,prop-types:React.PropTypes,@casl/ability:casl", | ||
"build.types": "tsc", | ||
"lint": "eslint --ext .ts,.js src/ spec/", | ||
@@ -37,9 +44,6 @@ "test": "NODE_ENV=test jest --config ../../tools/jest.config.js", | ||
], | ||
"author": "Sergii Stotskyi <sergiy.stotskiy@freaksidea.com>", | ||
"author": "Sergii Stotskyi <sergiy.stotskiy@gmail.com>", | ||
"license": "MIT", | ||
"engines": { | ||
"npm": "^6.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@casl/ability": "^2.0.0 || ^3.0.0 || ^4.0.0", | ||
"@casl/ability": "^3.0.0 || ^4.0.0 || ^5.1.0", | ||
"react": "^15.0.0 || ^16.0.0" | ||
@@ -53,12 +57,13 @@ }, | ||
"@babel/preset-env": "^7.8.4", | ||
"@casl/ability": "^4.0.0", | ||
"@casl/ability": "^5.1.0", | ||
"@rollup/plugin-babel": "^5.0.2", | ||
"@rollup/plugin-node-resolve": "^8.0.0", | ||
"@semantic-release/changelog": "^3.0.0", | ||
"@semantic-release/git": "^7.0.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@semantic-release/changelog": "^5.0.1", | ||
"@semantic-release/git": "^9.0.0", | ||
"@semantic-release/github": "^7.0.7", | ||
"@semantic-release/npm": "^7.0.5", | ||
"@testing-library/react-hooks": "^3.2.1", | ||
"@types/node": "^14.0.5", | ||
"@types/react": "^16.9.19", | ||
"@typescript-eslint/eslint-plugin": "2.24.0", | ||
"babel-jest": "^26.0.0", | ||
"@typescript-eslint/eslint-plugin": "4.7.0", | ||
"chai": "^4.1.0", | ||
@@ -68,3 +73,3 @@ "chai-spies": "^1.0.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-config-airbnb-typescript": "^7.2.1", | ||
"eslint-config-airbnb-typescript": "^12.0.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
@@ -75,5 +80,7 @@ "jest": "^26.0.0", | ||
"rollup": "^2.10.9", | ||
"rollup-plugin-terser": "^6.1.0", | ||
"semantic-release": "15.9.17", | ||
"typescript": "~3.8.0" | ||
"rollup-plugin-sourcemaps": "^0.6.2", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"semantic-release": "17.1.1", | ||
"ts-jest": "^26.4.4", | ||
"typescript": "~4.0.3" | ||
}, | ||
@@ -80,0 +87,0 @@ "files": [ |
@@ -9,2 +9,4 @@ # CASL React | ||
> `@casl/react` perfectly works with [React Native](https://reactnative.dev/) | ||
## Installation | ||
@@ -69,3 +71,3 @@ | ||
> it's better to pass children as a render function because it will not create additional React elements if user doesn't have ability to do some action (in the case above `read Post`) | ||
> it's better to pass children as a render function because it will not create additional React elements if user doesn't have ability to do some action (in the case above `create Post`) | ||
@@ -117,3 +119,3 @@ Don't be scared by the amount of properties component takes, we will talk about how to bind some of them. | ||
> See [CASL guide](https://stalniy.github.io/casl/v4/en/guide/intro) to learn how to define `Ability` instance. | ||
> See [CASL guide](https://casl.js.org/v5/en/guide/intro) to learn how to define `Ability` instance. | ||
@@ -267,3 +269,3 @@ and use our `Can` component: | ||
```ts @{data-filename="Login.jsx"} | ||
import { AbilityBuilder } from '@casl/ability'; | ||
import { AbilityBuilder, Ability } from '@casl/ability'; | ||
import React, { useState, useContext } from 'react'; | ||
@@ -273,3 +275,3 @@ import { AbilityContext } from './Can'; | ||
function updateAbility(ability, user) { | ||
const { can, rules } = new AbilityBuilder(); | ||
const { can, rules } = new AbilityBuilder(Ability); | ||
@@ -308,3 +310,3 @@ if (user.role === 'admin') { | ||
> See [Define rules](https://stalniy.github.io/casl/v4/en/guide/define-rules) to get more information of how to define `Ability` | ||
> See [Define rules](https://casl.js.org/v5/en/guide/define-rules) to get more information of how to define `Ability` | ||
@@ -317,3 +319,3 @@ ## Want to help? | ||
> See [Support CASL](https://stalniy.github.io/casl/v4/en/support-casljs) for details | ||
> See [Support CASL](https://casl.js.org/v5/en/support-casljs) for details | ||
@@ -320,0 +322,0 @@ ## License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
53018
20
98
1
322
31
1