forked from ngReact/ngReact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngReact.min.js
1 lines (1 loc) · 2.69 KB
/
ngReact.min.js
1
!function(t,r){"undefined"!=typeof module&&module.exports?module.exports=r(require("react"),require("react-dom/client"),require("angular")):"function"==typeof define&&define.amd?define(["react","react-dom/client","angular"],function(e,n,angular){return t.ngReact=r(e,n,angular)}):t.ngReact=r(t.React,t.reactDOMClient,t.angular)}(this,function(React,s,angular){"use strict";function y(e,n){if(angular.isFunction(e))return e;if(!e)throw new Error("ReactComponent name attribute must be specified");var t;try{t=n.get(e)}catch(e){}if(!t)try{t=e.split(".").reduce(function(e,n){return e[n]},window)}catch(e){}if(t)return t;throw Error("Cannot find react component "+e)}function d(a,u,i){return Object.keys(a||{}).reduce(function(e,n){var t,r,o=a[n],c=(i||{})[n]||{};return e[n]=angular.isFunction(o)&&!1!==c.wrapApply?(r=u,(t=o).wrappedInApply?t:((n=function(){var e=arguments,n=r.$root.$$phase;return"$apply"===n||"$digest"===n?t.apply(null,e):r.$apply(function(){return t.apply(null,e)})}).wrappedInApply=!0,n)):o,e},{})}function m(r,o,e,c){var a=angular.isFunction(o.$watchCollection),u=angular.isFunction(o.$watchGroup),i=[];e.forEach(function(e){t=e;var n,t=Array.isArray(t)?t[0]:t,e=(n=r,e=e,Array.isArray(e)&&angular.isObject(e[1])&&e[1].watchDepth||n);"collection"===e&&a?o.$watchCollection(t,c):"reference"===e&&u?i.push(t):o.$watch(t,c,"reference"!==e)}),i.length&&o.$watchGroup(i,c)}function h(e,n,t){e.$evalAsync(function(){var e=React.createElement(React.StrictMode,{},n);t.render(e)})}function $(e){return Array.isArray(e)?e[0]:e}function v(e){return Array.isArray(e)?e[1]:{}}return angular.module("react",[]).directive("reactComponent",["$injector",function(a){return{restrict:"E",replace:!0,link:function(n,e,t){function r(){var e=d(n.$eval(t.props),n),e=React.createElement(o,e);h(n,e,c)}var o=y(t.name,a),c=s.createRoot(e[0]);t.props?m(t.watchDepth,n,[t.props],r):r(),n.$on("$destroy",function(){t.onScopeDestroy?n.$eval(t.onScopeDestroy,{unmountComponent:c.unmount()}):c.unmount()})}}}]).factory("reactDirective",["$injector",function(l){return function(r,o,e,f){return angular.extend({restrict:"E",replace:!0,link:function(c,e,a){function n(){var r={},o={},e=(p.forEach(function(e){var n,t=$(e);r[t]=c.$eval((n=t,a[Object.keys(a).filter(function(e){return e.toLowerCase()===n.toLowerCase()})[0]])),o[t]=v(e)}),r=d(r,c,o),r=angular.extend({},r,f),React.createElement(u,r));h(c,e,i)}var t,u=y(r,l),i=s.createRoot(e[0]),p=o||Object.keys(u.propTypes||{}),e=(p.length||(t=[],angular.forEach(a.$attr,function(e,n){t.push(n)}),p=t),p.map(function(e){return Array.isArray(e)?[a[$(e)],v(e)]:a[e]}));m(a.watchDepth,c,e,n),n(),c.$on("$destroy",function(){a.onScopeDestroy?c.$eval(a.onScopeDestroy,{unmountComponent:i.unmount()}):i.unmount()})}},e)}}])});