Socket
Socket
Sign inDemoInstall

react-facebook

Package Overview
Dependencies
5
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 9.0.8 to 9.0.9

dist/cjs/types/components/Comments.d.ts

1399

dist/cjs/index.js

@@ -1,2 +0,1399 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e),n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},n(e,t)};var i,o=function(){return o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};function a(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function s(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}function u(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function c(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}!function(e){e.CONNECTED="connected",e.AUTHORIZATION_EXPIRED="authorization_expired",e.NOT_AUTHORIZED="not_authorized",e.UNKNOWN="unknown"}(i||(i={}));var d,l,f=i,h=function(e){function t(t,r,n){var i=e.call(this,t)||this;return i.code=r,i.type=n,i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(t,e),t}(Error);!function(e){e.GET="get",e.POST="post",e.DELETE="delete"}(d||(d={})),function(e){e.UI="ui",e.API="api",e.LOGIN="login",e.LOGOUT="logout",e.GET_LOGIN_STATUS="getLoginStatus",e.GET_AUTH_RESPONSE="getAuthResponse"}(l||(l={}));var p,v={domain:"connect.facebook.net",version:"v14.0",cookie:!1,status:!1,xfbml:!1,language:"en_US",frictionlessRequests:!1,debug:!1,chatSupport:!1,autoLogAppEvents:!0,lazy:!1},m=function(){function e(e){if(!e.appId)throw new Error("You need to set appId");this.options=o(o({},v),e),this.options.lazy||this.init()}return e.prototype.getAppId=function(){return this.options.appId},e.prototype.getFB=function(){return window.FB},e.prototype.init=function(){return s(this,void 0,void 0,(function(){var e=this;return u(this,(function(t){return this.loadingPromise||(this.loadingPromise=new Promise((function(t){var r=e.options,n=r.domain,i=r.language,o=r.debug,s=r.chatSupport,u=a(r,["domain","language","debug","chatSupport"]);if(window.fbAsyncInit=function(){window.FB.init({appId:u.appId,version:u.version,cookie:u.cookie,status:u.status,xfbml:u.xfbml,frictionlessRequests:u.frictionlessRequests}),t(e)},window.document.getElementById("facebook-jssdk"))return t(window.FB);var c=window.document.createElement("script");c.id="facebook-jssdk",c.async=!0,c.defer=!0,c.crossOrigin="anonymous",c.src="https://".concat(n,"/").concat(i,"/sdk").concat(s?"/xfbml.customerchat":"").concat(o?"/debug":"",".js"),window.document.body.appendChild(c)}))),[2,this.loadingPromise]}))}))},e.prototype.process=function(e,t,r){return void 0===t&&(t=[]),void 0===r&&(r=[]),s(this,void 0,void 0,(function(){var n;return u(this,(function(i){switch(i.label){case 0:return[4,this.init()];case 1:return n=i.sent(),[2,new Promise((function(i,o){n[e].apply(n,c(c(c([],t,!1),[function(t){if(t)if("error"in t){var r=t.error,n=r.code,a=r.type,s=r.message;o(new h(s,n,a))}else i(t);else{if(e===l.UI)return;o(new Error("Response is undefined"))}}],!1),r,!1))}))]}}))}))},e.prototype.ui=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(t){return[2,this.process(l.UI,[e])]}))}))},e.prototype.api=function(e,t,r){return void 0===t&&(t=d.GET),void 0===r&&(r={}),s(this,void 0,void 0,(function(){return u(this,(function(n){return[2,this.process(l.API,[e,t,r])]}))}))},e.prototype.login=function(e){return s(this,void 0,void 0,(function(){var t,r,n,i,o,a,s;return u(this,(function(u){return t=e.scope,r=e.authType,n=void 0===r?[]:r,i=e.returnScopes,o=e.rerequest,a=e.reauthorize,s={scope:t},i&&(s.return_scopes=!0),o&&n.push("rerequest"),a&&n.push("reauthenticate"),n.length&&(s.auth_type=n.join(",")),[2,this.process(l.LOGIN,[],[s])]}))}))},e.prototype.logout=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){return[2,this.process(l.LOGOUT)]}))}))},e.prototype.getLoginStatus=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){return[2,this.process(l.GET_LOGIN_STATUS)]}))}))},e.prototype.getAuthResponse=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){return[2,this.process(l.GET_AUTH_RESPONSE)]}))}))},e.prototype.getTokenDetail=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(r){switch(r.label){case 0:return(null==e?void 0:e.status)===f.CONNECTED?[2,e.authResponse]:[4,this.getLoginStatus()];case 1:if((t=r.sent()).status===f.CONNECTED)return[2,t.authResponse];throw new Error("Token is undefined")}}))}))},e.prototype.getProfile=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(t){return[2,this.api("/me",d.GET,e)]}))}))},e.prototype.getTokenDetailWithProfile=function(e,t){return s(this,void 0,void 0,(function(){var r;return u(this,(function(n){switch(n.label){case 0:return[4,this.getTokenDetail(t)];case 1:return r=n.sent(),[4,this.getProfile(e)];case 2:return[2,{profile:n.sent(),tokenDetail:r}]}}))}))},e.prototype.getToken=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.getTokenDetail()];case 1:return[2,e.sent().accessToken]}}))}))},e.prototype.getUserId=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.getTokenDetail()];case 1:return[2,e.sent().userID]}}))}))},e.prototype.sendInvite=function(e,t){return s(this,void 0,void 0,(function(){return u(this,(function(r){return[2,this.ui(o({to:e,method:"apprequests"},t))]}))}))},e.prototype.postAction=function(e,t,r,n,i){return void 0===i&&(i=!1),s(this,void 0,void 0,(function(){var o;return u(this,(function(a){return o="/me/".concat(e,":").concat(t,"?").concat(r,"=").concat(encodeURIComponent(n)),!0===i&&(o+="&no_feed_story=true"),[2,this.api(o,d.POST)]}))}))},e.prototype.getPermissions=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.api("/me/permissions")];case 1:return[2,e.sent().data]}}))}))},e.prototype.hasPermissions=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(r){switch(r.label){case 0:return[4,this.getPermissions()];case 1:return t=r.sent(),[2,e.filter((function(e){return!!t.find((function(t){var r=t.permission;return"granted"===t.status&&r===e}))})).length===e.length]}}))}))},e.prototype.subscribe=function(e,t){return s(this,void 0,void 0,(function(){var r=this;return u(this,(function(n){switch(n.label){case 0:return[4,this.init()];case 1:return n.sent(),this.getFB().Event.subscribe(e,t),[2,function(){return r.unsubscribe(e,t)}]}}))}))},e.prototype.unsubscribe=function(e,t){return s(this,void 0,void 0,(function(){return u(this,(function(r){switch(r.label){case 0:return[4,this.init()];case 1:return r.sent(),this.getFB().Event.unsubscribe(e,t),[2]}}))}))},e.prototype.parse=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.init()];case 1:return t.sent(),void 0===e?this.getFB().XFBML.parse():this.getFB().XFBML.parse(e),[2]}}))}))},e.prototype.getRequests=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){return[2,this.api("/me/apprequests")]}))}))},e.prototype.removeRequest=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(t){return[2,this.api(e,d.DELETE)]}))}))},e.prototype.setAutoGrow=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.init()];case 1:return e.sent(),this.getFB().Canvas.setAutoGrow(),[2]}}))}))},e.prototype.paySimple=function(e,t){return void 0===t&&(t=1),s(this,void 0,void 0,(function(){return u(this,(function(r){return[2,this.ui({method:"pay",action:"purchaseitem",product:e,quantity:t})]}))}))},e.prototype.pay=function(e,t){return s(this,void 0,void 0,(function(){return u(this,(function(r){return[2,this.ui(o({method:"pay",action:"purchaseitem",product:e},t))]}))}))},e}(),g=e.createContext(void 0);function w(t){void 0===t&&(t={});var r=t.lazy,n=void 0!==r&&r,i=e.useContext(g);if(!i)throw new Error("useFacebook must be used within a FacebookProvider");return e.useEffect((function(){n||i.init()}),[n]),i}var b=e.memo(e.forwardRef((function(e,t){var n=e.inline,i=e.children,s=a(e,["inline","children"]),u=n?"span":"div";return r.default.createElement(u,o({},s,{ref:t}),i)})));var y=e.memo((function(t){var n=t.children,i=t.inline,s=a(t,["children","inline"]),u=w().parse,c=e.useState(null),d=c[0],l=c[1],f=e.useCallback((function(e){l(e)}),[]);return e.useEffect((function(){d&&u(d)}),[d]),r.default.createElement(b,o({inline:i},s,{ref:f}),n)})),E=!("undefined"==typeof window||!window.document||!window.document.createElement);function S(){return E?window.location.href:"https://www.facebook.com"}var _=e.memo(e.forwardRef((function(e,t){var n=e.href,i=void 0===n?S():n,s=e.layout,u=e.colorScheme,c=e.action,d=e.showFaces,l=e.share,f=e.children,h=e.width,p=e.size,v=e.kidDirectedSite,m=e.referral,g=a(e,["href","layout","colorScheme","action","showFaces","share","children","width","size","kidDirectedSite","referral"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-like","data-ref":m,"data-href":i,"data-layout":s,"data-colorscheme":u,"data-action":c,"data-show-faces":d,"data-share":l,"data-width":h,"data-size":p,"data-kid-directed-site":v},g,{ref:t}),f))})));function k(){var t=w().init,r=e.useState(!1),n=r[0],i=r[1],c=e.useState(void 0),d=c[0],l=c[1];return{isLoading:n,error:d,share:function(e){return s(this,void 0,void 0,(function(){var r,n,s,c,d,f,h;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,2,3,4]),r=e.href,n=e.display,s=e.hashtag,c=e.redirectUri,d=a(e,["href","display","hashtag","redirectUri"]),l(void 0),i(!0),[4,t()];case 1:if(!(f=u.sent()))throw new Error("Facebook API is not initialized");return[2,f.ui((p=o({method:"share",href:r,display:n,app_id:f.getAppId(),hashtag:s,redirect_uri:c},d),Object.fromEntries(Object.entries(p).filter((function(e){return void 0!==e[1]})))))];case 2:return h=u.sent(),l(h),[3,4];case 3:return i(!1),[7];case 4:return[2]}var p}))}))}}}var x=e.memo(e.forwardRef((function(e,t){var n=e.style,i=e.href,s=void 0===i?S():i,u=e.tabs,c=e.hideCover,d=e.width,l=e.height,f=e.showFacepile,h=e.hideCTA,p=e.smallHeader,v=e.adaptContainerWidth,m=e.children,g=a(e,["style","href","tabs","hideCover","width","height","showFacepile","hideCTA","smallHeader","adaptContainerWidth","children"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-page",style:n,"data-tabs":u,"data-hide-cover":c,"data-show-facepile":f,"data-hide-cta":h,"data-href":s,"data-small-header":p,"data-adapt-container-width":v,"data-height":l,"data-width":d},g,{ref:t}),m))})));function T(){var t=w(),r=t.api,n=t.isLoading,i=e.useState(void 0),o=i[0],a=i[1],c=e.useState(!1),d=c[0],l=c[1],h=e.useState(),p=h[0],v=h[1];return{login:function(e,t){return s(this,void 0,void 0,(function(){var n,i;return u(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,2,3,4]),!r)throw new Error("Facebook API is not initialized");return l(!0),[4,r.login(e)];case 1:if((n=o.sent()).status!==f.CONNECTED)throw new Error("Unauthorized user");return v(n),null==t||t(n),[2,n];case 2:throw i=o.sent(),a(i),i;case 3:return l(!1),[7];case 4:return[2]}}))}))},error:o,isLoading:n||d,status:null==p?void 0:p.status}}var C=e.memo(e.forwardRef((function(e,t){var n=e.href,i=e.width,s=e.showText,u=e.children,c=a(e,["href","width","showText","children"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-post","data-href":n,"data-width":i,"data-show-text":s},c,{ref:t}),u))})));var I=e.memo(e.forwardRef((function(e,t){var n=e.href,i=e.width,s=e.showText,u=e.allowFullScreen,c=e.autoPlay,d=e.showCaptions,l=e.children,f=a(e,["href","width","showText","allowFullScreen","autoPlay","showCaptions","children"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-video","data-href":n,"data-width":i,"data-show-text":s,"data-show-captions":d,"data-autoplay":c,"data-allowfullscreen":u},f,{ref:t}),l))})));var O=e.memo(e.forwardRef((function(e,t){var n=e.colorScheme,i=e.href,s=void 0===i?S():i,u=e.numPosts,c=e.orderBy,d=e.width,l=e.children,f=e.mobile,h=a(e,["colorScheme","href","numPosts","orderBy","width","children","mobile"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-comments","data-colorscheme":n,"data-numposts":u,"data-href":s,"data-order-by":c,"data-width":d,"data-skin":n,"data-mobile":f},h,{ref:t}),l))})));var A=e.memo(e.forwardRef((function(e,t){var n=e.href,i=void 0===n?S():n,s=e.children,u=a(e,["href","children"]);return r.default.createElement(y,{inline:!0},r.default.createElement("span",o({className:"fb-comments-count","data-href":i},u,{ref:t}),s))})));var L=e.memo(e.forwardRef((function(e,t){var n=e.style,i=e.href,s=void 0===i?S():i,u=e.width,c=e.showSocialContext,d=e.showMetaData,l=e.children,f=e.skin,h=a(e,["style","href","width","showSocialContext","showMetaData","children","skin"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-group",style:n,"data-href":s,"data-width":u,"data-show-social-context":c,"data-show-metadata":d,"data-skin":f},h,{ref:t}),l))})));var R=e.memo(e.forwardRef((function(e,t){var n=e.children,i=e.pageId,s=e.themeColor,u=e.loggedInGreeting,c=e.loggedOutGreeting,d=e.dataRef,l=e.greetingDialogDisplay,f=e.greetingDialogDelay,h=e.minimized,p=a(e,["children","pageId","themeColor","loggedInGreeting","loggedOutGreeting","dataRef","greetingDialogDisplay","greetingDialogDelay","minimized"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-customerchat",page_id:i,theme_color:s,logged_in_greeting:u,logged_out_greeting:c,greeting_dialog_display:l,greeting_dialog_delay:f,"data-ref":d,minimized:h},p,{ref:t}),n))})));var N=e.memo(e.forwardRef((function(e,t){var n=e.color,i=e.messengerAppId,s=e.pageId,u=e.children,c=e.size,d=e.dataRef,l=a(e,["color","messengerAppId","pageId","children","size","dataRef"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-messengermessageus",messenger_app_id:i,page_id:s,"data-color":n,"data-size":c,"data-ref":d},l,{ref:t}),u))})));var P=e.memo(e.forwardRef((function(e,t){var n=e.origin,i=e.prechecked,s=e.allowLogin,u=e.userRef,c=e.messengerAppId,d=e.pageId,l=e.children,f=e.size,h=e.centerAlign,p=e.skin,v=a(e,["origin","prechecked","allowLogin","userRef","messengerAppId","pageId","children","size","centerAlign","skin"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-messenger-checkbox",messenger_app_id:c,page_id:d,size:f,origin:n,user_ref:u,prechecked:i,allow_login:s,skin:p,center_align:h},v,{ref:t}),l))})));var D,z=e.memo(e.forwardRef((function(e,t){var n=e.color,i=e.messengerAppId,s=e.pageId,u=e.children,c=e.dataRef,d=e.size,l=e.enforceLogin,f=a(e,["color","messengerAppId","pageId","children","dataRef","size","enforceLogin"]);return r.default.createElement(y,null,r.default.createElement("div",o({className:"fb-send-to-messenger",messenger_app_id:i,page_id:s,"data-color":n,"data-size":d,"data-ref":c,enforce_login:l},f,{ref:t}),u))})));!function(e){e.SMALL="small",e.LARGE="large"}(D||(D={}));var U,F=D;!function(e){e.STANDARD="standard",e.BUTTON_COUNT="button_count",e.BUTTON="button",e.BOX_COUNT="box_count"}(U||(U={}));var G,B=U;!function(e){e.LIGHT="light",e.DARK="dark"}(G||(G={}));var M,j=G;!function(e){e.LIKE="like",e.RECOMMEND="recommend"}(M||(M={}));var q,H=M;!function(e){e.SOCIAL="social",e.REVERSE_TIME="reverse_time",e.TIME="time"}(q||(q={}));var W,X=q;!function(e){e.SMALL="small",e.MEDIUM="medium",e.STANDARD="standard",e.LARGE="large",e.XLARGE="xlarge"}(W||(W={}));var K,V=W;!function(e){e.BLUE="blue",e.WHITE="white"}(K||(K={}));var Z=K;function Y(t,r){var n=this,i=e.useState(void 0),o=i[0],a=i[1],c=w().init,d=e.useCallback((function(e){a(e),null==r||r(o)}),[r]),l=e.useCallback((function(){return s(n,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return[4,c()];case 1:return(e=r.sent())?[4,e.subscribe(t,d)]:[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))}),[t,d]),f=e.useCallback((function(){return s(n,void 0,void 0,(function(){var e;return u(this,(function(r){switch(r.label){case 0:return[4,c()];case 1:return(e=r.sent())?[4,e.unsubscribe(t,d)]:[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))}),[t,d]);return e.useEffect((function(){return l(),function(){f()}}),[l]),o}function J(){var t=w().init,r=e.useState(!0),n=r[0],i=r[1],o=e.useState(void 0),a=o[0],c=o[1],d=e.useState(f.UNKNOWN),l=d[0],h=d[1];return Y("auth.statusChange",e.useCallback((function(e){h(e.status)}),[])),e.useEffect((function(){!function(){s(this,void 0,void 0,(function(){var e,r,n;return u(this,(function(o){switch(o.label){case 0:return o.trys.push([0,3,4,5]),i(!0),[4,t()];case 1:if(!(e=o.sent()))throw new Error("Facebook API is not initialized");return[4,e.getLoginStatus()];case 2:return r=o.sent().status,h(r),[3,5];case 3:return n=o.sent(),c(n),[3,5];case 4:return i(!1),[7];case 5:return[2]}}))}))}()}),[]),{isLoading:n,error:a,status:l}}exports.ColorScheme=j,exports.Comments=O,exports.CommentsCount=A,exports.CommentsOrderBy=X,exports.CustomChat=R,exports.EmbeddedPost=C,exports.EmbeddedVideo=I,exports.FacebookContext=g,exports.FacebookProvider=function(t){var n=t.children,i=a(t,["children"]),o=e.useState(!0),c=o[0],d=o[1],l=e.useState(!1),f=l[0],h=l[1],v=e.useState(),w=v[0],b=v[1];function y(){return s(this,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,3,4]),p?[2,p.init()]:(h(!1),d(!0),[4,(p=new m(i)).init()]);case 1:return t.sent(),h(!0),[3,4];case 2:return e=t.sent(),b(e),[3,4];case 3:return d(!1),[7];case 4:return[2,p]}}))}))}e.useEffect((function(){i.lazy||y()}),[]);var E={isLoading:c,error:w,init:y,api:f?p:void 0,parse:function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(r){switch(r.label){case 0:return[4,y()];case 1:return(t=r.sent())?[4,t.parse(e)]:[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))}};return r.default.createElement(g.Provider,{value:E},n)},exports.Fields=["id","first_name","last_name","middle_name","name","name_format","picture","short_name","email"],exports.Group=L,exports.Like=_,exports.LikeAction=H,exports.LikeLayout=B,exports.LikeSize=F,exports.LoginButton=function(e){var t=e.children,n=e.asChild,i=void 0===n?"button":n;e.disabled;var c=e.scope,d=e.returnScopes,l=e.authType,f=e.rerequest,h=e.reauthorize,p=e.onError,v=e.onSuccess,m=a(e,["children","asChild","disabled","scope","returnScopes","authType","rerequest","reauthorize","onError","onSuccess"]),g=T(),w=g.isLoading,b=g.login;return r.default.createElement(i,o({onClick:function(){return s(this,void 0,void 0,(function(){var e,t;return u(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),w?[2]:[4,b({scope:c,returnScopes:d,authType:l,rerequest:f,reauthorize:h})];case 1:return e=r.sent(),null==v||v(e),[3,3];case 2:return t=r.sent(),null==p||p(t),[3,3];case 3:return[2]}}))}))},disabled:w},m),t)},exports.LoginStatus=f,exports.MessageUs=N,exports.MessengerCheckbox=P,exports.MessengerColor=Z,exports.MessengerSize=V,exports.Page=x,exports.Parser=y,exports.SendToMessenger=z,exports.ShareButton=function(e){var t=e.children,n=e.asChild,i=void 0===n?"button":n;e.disabled;var s=e.href,u=e.display,c=e.hashtag,d=e.redirectUri,l=a(e,["children","asChild","disabled","href","display","hashtag","redirectUri"]),f=k(),h=f.isLoading,p=f.share;return r.default.createElement(i,o({onClick:function(){h||p({href:s,display:u,hashtag:c,redirectUri:d})},disabled:h},l),t)},exports.useFacebook=w,exports.useLogin=T,exports.useLoginStatus=J,exports.useProfile=function(t){var r=w().init,n=J().status,i=e.useState(!0),o=i[0],a=i[1],c=e.useState(void 0),d=c[0],l=c[1],h=e.useState(void 0),p=h[0],v=h[1];return e.useEffect((function(){!function(){s(this,void 0,void 0,(function(){var e,i,o;return u(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,5,6]),v(void 0),a(!0),[4,r()];case 1:if(!(e=s.sent()))throw new Error("Facebook API is not initialized");return n!==f.CONNECTED?[3,3]:[4,e.getProfile({fields:t})];case 2:i=s.sent(),l(i),s.label=3;case 3:return[3,6];case 4:return o=s.sent(),v(o),[3,6];case 5:return a(!1),[7];case 6:return[2]}}))}))}()}),[n,t]),{isLoading:o,error:p,profile:d}},exports.useShare=k,exports.useSubscribe=Y;
'use strict';
var React = require('react');
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var LoginStatus;
(function (LoginStatus) {
LoginStatus["CONNECTED"] = "connected";
LoginStatus["AUTHORIZATION_EXPIRED"] = "authorization_expired";
LoginStatus["NOT_AUTHORIZED"] = "not_authorized";
LoginStatus["UNKNOWN"] = "unknown";
})(LoginStatus || (LoginStatus = {}));
var LoginStatus$1 = LoginStatus;
var FBError = /** @class */ (function (_super) {
__extends(FBError, _super);
function FBError(message, code, type) {
var _this = _super.call(this, message) || this;
_this.code = code;
_this.type = type;
return _this;
}
return FBError;
}(Error));
var Method;
(function (Method) {
Method["GET"] = "get";
Method["POST"] = "post";
Method["DELETE"] = "delete";
})(Method || (Method = {}));
var Namespace;
(function (Namespace) {
Namespace["UI"] = "ui";
Namespace["API"] = "api";
Namespace["LOGIN"] = "login";
Namespace["LOGOUT"] = "logout";
Namespace["GET_LOGIN_STATUS"] = "getLoginStatus";
Namespace["GET_AUTH_RESPONSE"] = "getAuthResponse";
})(Namespace || (Namespace = {}));
var defaultOptions = {
domain: 'connect.facebook.net',
version: 'v15.0',
cookie: false,
status: false,
xfbml: true,
language: 'en_US',
frictionlessRequests: false,
debug: false,
chatSupport: false,
autoLogAppEvents: true,
lazy: false,
};
var Facebook = /** @class */ (function () {
function Facebook(options) {
if (!options.appId) {
throw new Error('You need to set appId');
}
this.options = __assign(__assign({}, defaultOptions), options);
if (!this.options.lazy) {
this.init();
}
}
Facebook.prototype.getAppId = function () {
return this.options.appId;
};
Facebook.prototype.getFB = function () {
return window.FB;
};
Facebook.prototype.init = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
if (this.loadingPromise) {
return [2 /*return*/, this.loadingPromise];
}
this.loadingPromise = new Promise(function (resolve) {
var _a = _this.options, domain = _a.domain, language = _a.language, debug = _a.debug, chatSupport = _a.chatSupport, restOptions = __rest(_a, ["domain", "language", "debug", "chatSupport"]);
window.fbAsyncInit = function () {
window.FB.init({
appId: restOptions.appId,
version: restOptions.version,
cookie: restOptions.cookie,
status: restOptions.status,
xfbml: restOptions.xfbml,
frictionlessRequests: restOptions.frictionlessRequests,
});
resolve(_this);
};
if (window.document.getElementById('facebook-jssdk')) {
return resolve(_this);
}
var js = window.document.createElement('script');
js.id = 'facebook-jssdk';
js.async = true;
js.defer = true;
js.crossOrigin = 'anonymous';
js.src = "https://".concat(domain, "/").concat(language, "/sdk").concat(chatSupport ? '/xfbml.customerchat' : '').concat(debug ? '/debug' : '', ".js");
window.document.body.appendChild(js);
});
return [2 /*return*/, this.loadingPromise];
});
});
};
Facebook.prototype.process = function (namespace, before, after) {
if (before === void 0) { before = []; }
if (after === void 0) { after = []; }
return __awaiter(this, void 0, void 0, function () {
var fb;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
fb = this.getFB();
return [2 /*return*/, new Promise(function (resolve, reject) {
// @ts-ignore
fb[namespace].apply(fb, __spreadArray(__spreadArray(__spreadArray([], before, false), [function (response) {
if (!response) {
if (namespace === Namespace.UI)
return;
reject(new Error('Response is undefined'));
}
else if (!!response && 'error' in response) {
var _a = response.error, code = _a.code, type = _a.type, message = _a.message;
reject(new FBError(message, code, type));
}
else {
resolve(response);
}
}], false), after, false));
})];
}
});
});
};
Facebook.prototype.ui = function (options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.UI, [options])];
});
});
};
Facebook.prototype.api = function (path, method, params) {
if (method === void 0) { method = Method.GET; }
if (params === void 0) { params = {}; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.API, [path, method, params])];
});
});
};
Facebook.prototype.login = function (options) {
return __awaiter(this, void 0, void 0, function () {
var scope, _a, authType, returnScopes, rerequest, reauthorize, loginOptions;
return __generator(this, function (_b) {
scope = options.scope, _a = options.authType, authType = _a === void 0 ? [] : _a, returnScopes = options.returnScopes, rerequest = options.rerequest, reauthorize = options.reauthorize;
loginOptions = {
scope: scope,
};
if (returnScopes) {
loginOptions.return_scopes = true;
}
if (rerequest) {
authType.push('rerequest');
}
if (reauthorize) {
authType.push('reauthenticate');
}
if (authType.length) {
loginOptions.auth_type = authType.join(',');
}
return [2 /*return*/, this.process(Namespace.LOGIN, [], [loginOptions])];
});
});
};
Facebook.prototype.logout = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.LOGOUT)];
});
});
};
Facebook.prototype.getLoginStatus = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.GET_LOGIN_STATUS)];
});
});
};
Facebook.prototype.getAuthResponse = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.GET_AUTH_RESPONSE)];
});
});
};
Facebook.prototype.getTokenDetail = function (loginResponse) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if ((loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.status) === LoginStatus$1.CONNECTED) {
return [2 /*return*/, loginResponse.authResponse];
}
return [4 /*yield*/, this.getLoginStatus()];
case 1:
response = _a.sent();
if (response.status === LoginStatus$1.CONNECTED) {
return [2 /*return*/, response.authResponse];
}
throw new Error('Token is undefined');
}
});
});
};
Facebook.prototype.getProfile = function (params) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.api('/me', Method.GET, params)];
});
});
};
Facebook.prototype.getTokenDetailWithProfile = function (params, response) {
return __awaiter(this, void 0, void 0, function () {
var tokenDetail, profile;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getTokenDetail(response)];
case 1:
tokenDetail = _a.sent();
return [4 /*yield*/, this.getProfile(params)];
case 2:
profile = _a.sent();
return [2 /*return*/, {
profile: profile,
tokenDetail: tokenDetail,
}];
}
});
});
};
Facebook.prototype.getToken = function () {
return __awaiter(this, void 0, void 0, function () {
var authResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getTokenDetail()];
case 1:
authResponse = _a.sent();
return [2 /*return*/, authResponse.accessToken];
}
});
});
};
Facebook.prototype.getUserId = function () {
return __awaiter(this, void 0, void 0, function () {
var authResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getTokenDetail()];
case 1:
authResponse = _a.sent();
return [2 /*return*/, authResponse.userID];
}
});
});
};
Facebook.prototype.sendInvite = function (to, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ui(__assign({ to: to, method: 'apprequests' }, options))];
});
});
};
Facebook.prototype.postAction = function (ogNamespace, ogAction, ogObject, ogObjectUrl, noFeedStory) {
if (noFeedStory === void 0) { noFeedStory = false; }
return __awaiter(this, void 0, void 0, function () {
var url;
return __generator(this, function (_a) {
url = "/me/".concat(ogNamespace, ":").concat(ogAction, "?").concat(ogObject, "=").concat(encodeURIComponent(ogObjectUrl));
if (noFeedStory === true) {
url += '&no_feed_story=true';
}
return [2 /*return*/, this.api(url, Method.POST)];
});
});
};
Facebook.prototype.getPermissions = function () {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.api('/me/permissions')];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
};
Facebook.prototype.hasPermissions = function (permissions) {
return __awaiter(this, void 0, void 0, function () {
var usersPermissions, findedPermissions;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getPermissions()];
case 1:
usersPermissions = _a.sent();
findedPermissions = permissions.filter(function (p) {
var currentPermission = usersPermissions.find(function (row) {
var permission = row.permission, status = row.status;
return status === 'granted' && permission === p;
});
return !!currentPermission;
});
return [2 /*return*/, findedPermissions.length === permissions.length];
}
});
});
};
Facebook.prototype.subscribe = function (eventName, callback) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
this.getFB().Event.subscribe(eventName, callback);
return [2 /*return*/, function () { return _this.unsubscribe(eventName, callback); }];
}
});
});
};
Facebook.prototype.unsubscribe = function (eventName, callback) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
this.getFB().Event.unsubscribe(eventName, callback);
return [2 /*return*/];
}
});
});
};
Facebook.prototype.parse = function (parentNode) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
if (typeof parentNode === 'undefined') {
this.getFB().XFBML.parse();
}
else {
this.getFB().XFBML.parse(parentNode);
}
return [2 /*return*/];
}
});
});
};
Facebook.prototype.getRequests = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.api('/me/apprequests')];
});
});
};
Facebook.prototype.removeRequest = function (requestId) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.api(requestId, Method.DELETE)];
});
});
};
Facebook.prototype.setAutoGrow = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
this.getFB().Canvas.setAutoGrow();
return [2 /*return*/];
}
});
});
};
Facebook.prototype.paySimple = function (product, quantity) {
if (quantity === void 0) { quantity = 1; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ui({
method: 'pay',
action: 'purchaseitem',
product: product,
quantity: quantity,
})];
});
});
};
Facebook.prototype.pay = function (product, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ui(__assign({ method: 'pay', action: 'purchaseitem', product: product }, options))];
});
});
};
return Facebook;
}());
/*
sendToFriends: function(options, callback) {
if(!options) {
options = {};
}
options.method = 'send';
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.ui(options, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
sendMessage: function(message, name, caption, description, url, imgUrl, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.ui({
method: 'stream.publish',
message: message,
attachment: {
name: name,
caption: caption,
description: description,
href: url,
media:[{
type: 'image',
src: imgUrl,
href: url
}]
},
action_links: [{
text: 'Code',
href: url
}],
user_prompt_message: message
},
function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
sendInviteForm: function(options, callback) {
if(typeof options === 'function') {
callback = options;
options = {};
}
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
options.method = options.method || 'apprequests';
FB.ui(options, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
checkPageLike: function(pageID, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
fbApi.getUserID(function(err, userID) {
if(err) {
return callback(err);
}
var fqlQuery = `SELECT uid FROM page_fan WHERE page_id = ${pageID} and uid = ${userID}`;
var query = FB.Data.query(fqlQuery);
query.wait(function(rows) {
if (rows.length === 1 && rows[0].uid === userID) {
callback(null, true, query);
}
else {
callback(null, false, query);
}
});
});
});
},
sendMessageToFriend: function (friendID, link, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.ui({
to: friendID,
method: 'send',
link: link
}, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
_prepareUsers: function(data) {
var users=[];
for(var index in data) {
var userData=data[index];
var user = {
provider_uid: 'facebook'+'_'+userData.uid,
provider: 'facebook',
id: userData.uid,
name: userData.name,
first_name: userData.first_name,
last_name: userData.last_name,
status: (userData.status!==null) ? userData.status : null,
image: '//graph.facebook.com/'+userData.uid+'/picture?'
};
users.push(user);
}
return users;
},
getUserList: function(callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('fql', {
q: `
SELECT uid, name, first_name, last_name, online_presence, status
FROM user
WHERE uid IN
( SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY name
`,
}, function (response)
{
var users = fbApi._prepareUsers(response.data);
callback(null, users, response);
});
});
},
postFeed: function(options, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
options.method='feed';
FB.ui(options, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//need publish_stream
createAlbum: function(name, description, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/me/albums', 'post', {
name: name,
description: description
},function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//need publish_stream
addImageToAlbum: function(albumID, imageURL, message, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/'+albumID+'/photos', 'post', {
message: message,
url: imageURL
}, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'user_photos'
getAlbums: function(callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/me/albums', function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'user_photos'
getAlbumPhotos: function(albumID, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/'+albumID+'/photos', function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'user_photos'
getAlbumCoverPicture: function(albumID, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/'+albumID+'/picture', function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'publish_stream'
postPhoto: function(photoUrl, message, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/me/photos', 'post', {
message: message,
url: photoUrl
},function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
getPageInfo: function(callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.Canvas.getPageInfo(function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
}
*/
var FacebookContext = React.createContext(undefined);
var api;
function FacebookProvider(props) {
var children = props.children, options = __rest(props, ["children"]);
var _a = React.useState(true), isLoading = _a[0], setIsLoading = _a[1];
var _b = React.useState(false), isReady = _b[0], setIsReady = _b[1];
var _c = React.useState(), error = _c[0], setError = _c[1];
function init() {
return __awaiter(this, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, 3, 4]);
if (api) {
return [2 /*return*/, api.init()];
}
setIsReady(false);
setIsLoading(true);
api = new Facebook(options);
return [4 /*yield*/, api.init()];
case 1:
_a.sent();
setIsReady(true);
return [3 /*break*/, 4];
case 2:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 4];
case 3:
setIsLoading(false);
return [7 /*endfinally*/];
case 4: return [2 /*return*/, api];
}
});
});
}
function parse(element) {
return __awaiter(this, void 0, void 0, function () {
var api;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) return [3 /*break*/, 3];
return [4 /*yield*/, api.parse(element)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
}
React.useEffect(function () {
var lazy = options.lazy;
if (!lazy) {
init();
}
}, []);
var value = {
isLoading: isLoading,
error: error,
init: init,
api: isReady ? api : undefined,
parse: parse,
};
return (React.createElement(FacebookContext.Provider, { value: value }, children));
}
function useFacebook(props) {
if (props === void 0) { props = {}; }
var _a = props.lazy, lazy = _a === void 0 ? false : _a;
var context = React.useContext(FacebookContext);
if (!context) {
throw new Error('useFacebook must be used within a FacebookProvider');
}
React.useEffect(function () {
if (!lazy) {
context.init();
}
}, [lazy]);
return context;
}
var ParserInternal = React.memo(React.forwardRef(function (props, ref) {
var inline = props.inline, children = props.children, rest = __rest(props, ["inline", "children"]);
var Tag = inline ? 'span' : 'div';
return (
// @ts-ignore
React.createElement(Tag, __assign({}, rest, { ref: ref }), children));
}));
function Parser(props) {
var children = props.children, inline = props.inline, rest = __rest(props, ["children", "inline"]);
var parse = useFacebook().parse;
var _a = React.useState(null), element = _a[0], setElement = _a[1];
var handleRef = React.useCallback(function (element) {
setElement(element);
}, []);
React.useEffect(function () {
if (element) {
parse(element);
}
}, [element]);
return (React.createElement(ParserInternal, __assign({ inline: inline }, rest, { ref: handleRef }), children));
}
var Parser$1 = React.memo(Parser);
var canUseDOM = !!(typeof window !== 'undefined' &&
window.document &&
window.document.createElement);
function getCurrentHref() {
if (!canUseDOM) {
return 'https://www.facebook.com';
}
return window.location.href;
}
function Like(props, ref) {
var _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, layout = props.layout, colorScheme = props.colorScheme, action = props.action, showFaces = props.showFaces, share = props.share, children = props.children, width = props.width, size = props.size, kidDirectedSite = props.kidDirectedSite, referral = props.referral, lazy = props.lazy, rest = __rest(props, ["href", "layout", "colorScheme", "action", "showFaces", "share", "children", "width", "size", "kidDirectedSite", "referral", "lazy"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-like", "data-ref": referral, "data-href": href, "data-layout": layout, "data-colorscheme": colorScheme, "data-action": action, "data-show-faces": showFaces, "data-share": share, "data-width": width, "data-size": size, "data-lazy": lazy, "data-kid-directed-site": kidDirectedSite }, rest, { ref: ref }), children)));
}
var Like$1 = React.memo(React.forwardRef(Like));
function clearUndefinedProperties(obj) {
return Object.fromEntries(Object.entries(obj).filter(function (_a) {
var value = _a[1];
return value !== undefined;
}));
}
function useShare() {
var init = useFacebook().init;
var _a = React.useState(false), isLoading = _a[0], setIsLoading = _a[1];
var _b = React.useState(undefined), error = _b[0], setError = _b[1];
function handleShare(options) {
return __awaiter(this, void 0, void 0, function () {
var href, display, hashtag, redirectUri, rest, api, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, 3, 4]);
href = options.href, display = options.display, hashtag = options.hashtag, redirectUri = options.redirectUri, rest = __rest(options, ["href", "display", "hashtag", "redirectUri"]);
setError(undefined);
setIsLoading(true);
return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) {
throw new Error('Facebook API is not initialized');
}
return [2 /*return*/, api.ui(clearUndefinedProperties(__assign({ method: 'share', href: href, display: display, app_id: api.getAppId(), hashtag: hashtag, redirect_uri: redirectUri }, rest)))];
case 2:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 4];
case 3:
setIsLoading(false);
return [7 /*endfinally*/];
case 4: return [2 /*return*/];
}
});
});
}
return {
isLoading: isLoading,
error: error,
share: handleShare,
};
}
function ShareButton(props) {
var children = props.children, _a = props.asChild, AsChild = _a === void 0 ? 'button' : _a; props.disabled; var href = props.href, display = props.display, hashtag = props.hashtag, redirectUri = props.redirectUri, rest = __rest(props, ["children", "asChild", "disabled", "href", "display", "hashtag", "redirectUri"]);
var _b = useShare(), isLoading = _b.isLoading, share = _b.share;
function handleShare() {
if (isLoading) {
return;
}
share({
href: href,
display: display,
hashtag: hashtag,
redirectUri: redirectUri,
});
}
return (React.createElement(AsChild, __assign({ onClick: handleShare, disabled: isLoading }, rest), children));
}
function Page(props, ref) {
var style = props.style, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, tabs = props.tabs, hideCover = props.hideCover, width = props.width, height = props.height, showFacepile = props.showFacepile, hideCTA = props.hideCTA, smallHeader = props.smallHeader, adaptContainerWidth = props.adaptContainerWidth, children = props.children, lazy = props.lazy, rest = __rest(props, ["style", "href", "tabs", "hideCover", "width", "height", "showFacepile", "hideCTA", "smallHeader", "adaptContainerWidth", "children", "lazy"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-page", style: style, "data-tabs": tabs, "data-hide-cover": hideCover, "data-show-facepile": showFacepile, "data-hide-cta": hideCTA, "data-href": href, "data-small-header": smallHeader, "data-adapt-container-width": adaptContainerWidth, "data-height": height, "data-width": width, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Page$1 = React.memo(React.forwardRef(Page));
function useLogin() {
var _a = useFacebook(), api = _a.api, isLoading = _a.isLoading;
var _b = React.useState(undefined), error = _b[0], setError = _b[1];
var _c = React.useState(false), isLoadingLogin = _c[0], setIsLoadingLogin = _c[1];
var _d = React.useState(), latestResponse = _d[0], setLatestResponse = _d[1];
function handleLogin(loginOptions, callback) {
return __awaiter(this, void 0, void 0, function () {
var response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, 3, 4]);
if (!api) {
throw new Error('Facebook API is not initialized');
}
setIsLoadingLogin(true);
return [4 /*yield*/, api.login(loginOptions)];
case 1:
response = _a.sent();
if (response.status !== LoginStatus$1.CONNECTED) {
throw new Error('Unauthorized user');
}
setLatestResponse(response);
callback === null || callback === void 0 ? void 0 : callback(response);
return [2 /*return*/, response];
case 2:
error_1 = _a.sent();
setError(error_1);
throw (error_1);
case 3:
setIsLoadingLogin(false);
return [7 /*endfinally*/];
case 4: return [2 /*return*/];
}
});
});
}
return {
login: handleLogin,
error: error,
isLoading: isLoading || isLoadingLogin,
status: latestResponse === null || latestResponse === void 0 ? void 0 : latestResponse.status,
};
}
function LoginButton(props) {
var children = props.children, _a = props.asChild, AsChild = _a === void 0 ? 'button' : _a; props.disabled; var scope = props.scope, returnScopes = props.returnScopes, authType = props.authType, rerequest = props.rerequest, reauthorize = props.reauthorize, onError = props.onError, onSuccess = props.onSuccess, rest = __rest(props, ["children", "asChild", "disabled", "scope", "returnScopes", "authType", "rerequest", "reauthorize", "onError", "onSuccess"]);
var _b = useLogin(), isLoading = _b.isLoading, login = _b.login;
function handleLogin() {
return __awaiter(this, void 0, void 0, function () {
var response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (isLoading) {
return [2 /*return*/];
}
return [4 /*yield*/, login({
scope: scope,
returnScopes: returnScopes,
authType: authType,
rerequest: rerequest,
reauthorize: reauthorize,
})];
case 1:
response = _a.sent();
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
return [3 /*break*/, 3];
case 2:
error_1 = _a.sent();
onError === null || onError === void 0 ? void 0 : onError(error_1);
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
});
}
return (React.createElement(AsChild, __assign({ onClick: handleLogin, disabled: isLoading }, rest), children));
}
function EmbeddedPost(props, ref) {
var href = props.href, width = props.width, showText = props.showText, lazy = props.lazy, children = props.children, rest = __rest(props, ["href", "width", "showText", "lazy", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-post", "data-href": href, "data-width": width, "data-lazy": lazy, "data-show-text": showText }, rest, { ref: ref }), children)));
}
var EmbeddedPost$1 = React.memo(React.forwardRef(EmbeddedPost));
function EmbeddedVideo(props, ref) {
var href = props.href, width = props.width, showText = props.showText, allowFullScreen = props.allowFullScreen, autoPlay = props.autoPlay, lazy = props.lazy, showCaptions = props.showCaptions, children = props.children, rest = __rest(props, ["href", "width", "showText", "allowFullScreen", "autoPlay", "lazy", "showCaptions", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-video", "data-href": href, "data-width": width, "data-show-text": showText, "data-show-captions": showCaptions, "data-autoplay": autoPlay, "data-lazy": lazy, "data-allowfullscreen": allowFullScreen }, rest, { ref: ref }), children)));
}
var EmbeddedVideo$1 = React.memo(React.forwardRef(EmbeddedVideo));
function Comments(props, ref) {
var colorScheme = props.colorScheme, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, numPosts = props.numPosts, orderBy = props.orderBy, width = props.width, children = props.children, mobile = props.mobile, lazy = props.lazy, rest = __rest(props, ["colorScheme", "href", "numPosts", "orderBy", "width", "children", "mobile", "lazy"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-comments", "data-colorscheme": colorScheme, "data-numposts": numPosts, "data-href": href, "data-order-by": orderBy, "data-width": width, "data-skin": colorScheme, "data-mobile": mobile, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Comments$1 = React.memo(React.forwardRef(Comments));
function CommentsCount(props, ref) {
var _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, children = props.children, rest = __rest(props, ["href", "children"]);
return (React.createElement(Parser$1, { inline: true },
React.createElement("span", __assign({ className: "fb-comments-count", "data-href": href }, rest, { ref: ref }), children)));
}
var CommentsCount$1 = React.memo(React.forwardRef(CommentsCount));
function Group(props, ref) {
var style = props.style, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, width = props.width, lazy = props.lazy, showSocialContext = props.showSocialContext, showMetaData = props.showMetaData, children = props.children, skin = props.skin, rest = __rest(props, ["style", "href", "width", "lazy", "showSocialContext", "showMetaData", "children", "skin"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-group", style: style, "data-href": href, "data-width": width, "data-show-social-context": showSocialContext, "data-show-metadata": showMetaData, "data-skin": skin, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Group$1 = React.memo(React.forwardRef(Group));
function Save(props, ref) {
var style = props.style, _a = props.uri, uri = _a === void 0 ? getCurrentHref() : _a, lazy = props.lazy, children = props.children, rest = __rest(props, ["style", "uri", "lazy", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-save", style: style, "data-uri": uri, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Save$1 = React.memo(React.forwardRef(Save));
function Share(props, ref) {
var style = props.style, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, lazy = props.lazy, layout = props.layout, size = props.size, children = props.children, rest = __rest(props, ["style", "href", "lazy", "layout", "size", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-share-button", style: style, "data-href": href, "data-lazy": lazy, "data-size": size, "data-layout": layout }, rest, { ref: ref }), children)));
}
var Share$1 = React.memo(React.forwardRef(Share));
function CustomChat(props, ref) {
var children = props.children, pageId = props.pageId, themeColor = props.themeColor, loggedInGreeting = props.loggedInGreeting, loggedOutGreeting = props.loggedOutGreeting, dataRef = props.dataRef, greetingDialogDisplay = props.greetingDialogDisplay, greetingDialogDelay = props.greetingDialogDelay, minimized = props.minimized, rest = __rest(props, ["children", "pageId", "themeColor", "loggedInGreeting", "loggedOutGreeting", "dataRef", "greetingDialogDisplay", "greetingDialogDelay", "minimized"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-customerchat",
// @ts-ignore
page_id: pageId, theme_color: themeColor, logged_in_greeting: loggedInGreeting, logged_out_greeting: loggedOutGreeting, greeting_dialog_display: greetingDialogDisplay, greeting_dialog_delay: greetingDialogDelay, "data-ref": dataRef, minimized: minimized }, rest, { ref: ref }), children)));
}
var CustomChat$1 = React.memo(React.forwardRef(CustomChat));
function MessageUs(props, ref) {
var color = props.color, messengerAppId = props.messengerAppId, pageId = props.pageId, children = props.children, size = props.size, dataRef = props.dataRef, rest = __rest(props, ["color", "messengerAppId", "pageId", "children", "size", "dataRef"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-messengermessageus",
// @ts-ignore
messenger_app_id: messengerAppId, page_id: pageId, "data-color": color, "data-size": size, "data-ref": dataRef }, rest, { ref: ref }), children)));
}
var MessageUs$1 = React.memo(React.forwardRef(MessageUs));
function MessengerCheckbox(props, ref) {
var origin = props.origin, prechecked = props.prechecked, allowLogin = props.allowLogin, userRef = props.userRef, messengerAppId = props.messengerAppId, pageId = props.pageId, children = props.children, size = props.size, centerAlign = props.centerAlign, skin = props.skin, rest = __rest(props, ["origin", "prechecked", "allowLogin", "userRef", "messengerAppId", "pageId", "children", "size", "centerAlign", "skin"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-messenger-checkbox",
// @ts-ignore
messenger_app_id: messengerAppId, page_id: pageId, size: size, origin: origin, user_ref: userRef, prechecked: prechecked, allow_login: allowLogin, skin: skin, center_align: centerAlign }, rest, { ref: ref }), children)));
}
var MessengerCheckbox$1 = React.memo(React.forwardRef(MessengerCheckbox));
function SendToMessenger(props, ref) {
var color = props.color, messengerAppId = props.messengerAppId, pageId = props.pageId, children = props.children, dataRef = props.dataRef, size = props.size, enforceLogin = props.enforceLogin, rest = __rest(props, ["color", "messengerAppId", "pageId", "children", "dataRef", "size", "enforceLogin"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-send-to-messenger",
// @ts-ignore
messenger_app_id: messengerAppId, page_id: pageId, "data-color": color, "data-size": size, "data-ref": dataRef, enforce_login: enforceLogin }, rest, { ref: ref }), children)));
}
var SendToMessenger$1 = React.memo(React.forwardRef(SendToMessenger));
var LikeSize;
(function (LikeSize) {
LikeSize["SMALL"] = "small";
LikeSize["LARGE"] = "large";
})(LikeSize || (LikeSize = {}));
var LikeSize$1 = LikeSize;
var LikeLayout;
(function (LikeLayout) {
LikeLayout["STANDARD"] = "standard";
LikeLayout["BUTTON_COUNT"] = "button_count";
LikeLayout["BUTTON"] = "button";
LikeLayout["BOX_COUNT"] = "box_count";
})(LikeLayout || (LikeLayout = {}));
var LikeLayout$1 = LikeLayout;
var ColorScheme;
(function (ColorScheme) {
ColorScheme["LIGHT"] = "light";
ColorScheme["DARK"] = "dark";
})(ColorScheme || (ColorScheme = {}));
var ColorScheme$1 = ColorScheme;
var LikeAction;
(function (LikeAction) {
LikeAction["LIKE"] = "like";
LikeAction["RECOMMEND"] = "recommend";
})(LikeAction || (LikeAction = {}));
var LikeAction$1 = LikeAction;
var CommentsOrderBy;
(function (CommentsOrderBy) {
CommentsOrderBy["SOCIAL"] = "social";
CommentsOrderBy["REVERSE_TIME"] = "reverse_time";
CommentsOrderBy["TIME"] = "time";
})(CommentsOrderBy || (CommentsOrderBy = {}));
var CommentsOrderBy$1 = CommentsOrderBy;
var MessengerSize;
(function (MessengerSize) {
MessengerSize["SMALL"] = "small";
MessengerSize["MEDIUM"] = "medium";
MessengerSize["STANDARD"] = "standard";
MessengerSize["LARGE"] = "large";
MessengerSize["XLARGE"] = "xlarge";
})(MessengerSize || (MessengerSize = {}));
var MessengerSize$1 = MessengerSize;
var MessengerColor;
(function (MessengerColor) {
MessengerColor["BLUE"] = "blue";
MessengerColor["WHITE"] = "white";
})(MessengerColor || (MessengerColor = {}));
var MessengerColor$1 = MessengerColor;
// @flow
// 3.0 fields without app review https://developers.facebook.com/docs/facebook-login/permissions/?locale=en_US#reference-default
var Fields = [
'id', 'first_name', 'last_name', 'middle_name',
'name', 'name_format', 'picture', 'short_name', 'email',
];
function useSubscribe(event, callback) {
var _this = this;
var _a = React.useState(undefined), lastValue = _a[0], setLastValue = _a[1];
var init = useFacebook().init;
var handleResponse = React.useCallback(function (value) {
setLastValue(value);
callback === null || callback === void 0 ? void 0 : callback(lastValue);
}, [callback]);
var handleSubscribe = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
var api;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) return [3 /*break*/, 3];
return [4 /*yield*/, api.subscribe(event, handleResponse)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
}); }, [event, handleResponse]);
var handleUnsubscribe = React.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
var api;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) return [3 /*break*/, 3];
return [4 /*yield*/, api.unsubscribe(event, handleResponse)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
}); }, [event, handleResponse]);
React.useEffect(function () {
handleSubscribe();
return function () {
handleUnsubscribe();
};
}, [handleSubscribe]);
return lastValue;
}
function useLoginStatus() {
var init = useFacebook().init;
var _a = React.useState(true), isLoading = _a[0], setIsLoading = _a[1];
var _b = React.useState(undefined), error = _b[0], setError = _b[1];
var _c = React.useState(LoginStatus$1.UNKNOWN), status = _c[0], setStatus = _c[1];
var handleStatusChanges = React.useCallback(function (response) {
setStatus(response.status);
}, []);
useSubscribe('auth.statusChange', handleStatusChanges);
function handleGetInitState() {
return __awaiter(this, void 0, void 0, function () {
var api, status_1, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, 4, 5]);
setIsLoading(true);
return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) {
throw new Error('Facebook API is not initialized');
}
return [4 /*yield*/, api.getLoginStatus()];
case 2:
status_1 = (_a.sent()).status;
setStatus(status_1);
return [3 /*break*/, 5];
case 3:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 5];
case 4:
setIsLoading(false);
return [7 /*endfinally*/];
case 5: return [2 /*return*/];
}
});
});
}
React.useEffect(function () {
handleGetInitState();
}, []);
return {
isLoading: isLoading,
error: error,
status: status,
};
}
function useProfile(fields) {
var init = useFacebook().init;
var status = useLoginStatus().status;
var _a = React.useState(true), isLoading = _a[0], setIsLoading = _a[1];
var _b = React.useState(undefined), profile = _b[0], setProfile = _b[1];
var _c = React.useState(undefined), error = _c[0], setError = _c[1];
function updateProfile() {
return __awaiter(this, void 0, void 0, function () {
var api, profile_1, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 4, 5, 6]);
setError(undefined);
setIsLoading(true);
return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) {
throw new Error('Facebook API is not initialized');
}
if (!(status === LoginStatus$1.CONNECTED)) return [3 /*break*/, 3];
return [4 /*yield*/, api.getProfile({
fields: fields,
})];
case 2:
profile_1 = _a.sent();
setProfile(profile_1);
_a.label = 3;
case 3: return [3 /*break*/, 6];
case 4:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 6];
case 5:
setIsLoading(false);
return [7 /*endfinally*/];
case 6: return [2 /*return*/];
}
});
});
}
React.useEffect(function () {
updateProfile();
}, [status, fields]);
return {
isLoading: isLoading,
error: error,
profile: profile,
};
}
exports.ColorScheme = ColorScheme$1;
exports.Comments = Comments$1;
exports.CommentsCount = CommentsCount$1;
exports.CommentsOrderBy = CommentsOrderBy$1;
exports.CustomChat = CustomChat$1;
exports.EmbeddedPost = EmbeddedPost$1;
exports.EmbeddedVideo = EmbeddedVideo$1;
exports.FacebookContext = FacebookContext;
exports.FacebookProvider = FacebookProvider;
exports.Fields = Fields;
exports.Group = Group$1;
exports.Like = Like$1;
exports.LikeAction = LikeAction$1;
exports.LikeLayout = LikeLayout$1;
exports.LikeSize = LikeSize$1;
exports.LoginButton = LoginButton;
exports.LoginStatus = LoginStatus$1;
exports.MessageUs = MessageUs$1;
exports.MessengerCheckbox = MessengerCheckbox$1;
exports.MessengerColor = MessengerColor$1;
exports.MessengerSize = MessengerSize$1;
exports.Page = Page$1;
exports.Parser = Parser$1;
exports.Save = Save$1;
exports.SendToMessenger = SendToMessenger$1;
exports.Share = Share$1;
exports.ShareButton = ShareButton;
exports.useFacebook = useFacebook;
exports.useLogin = useLogin;
exports.useLoginStatus = useLoginStatus;
exports.useProfile = useProfile;
exports.useShare = useShare;
exports.useSubscribe = useSubscribe;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,1365 @@

import e,{createContext as t,useState as n,useEffect as r,useContext as i,memo as o,forwardRef as a,useCallback as s}from"react";var u=function(e,t){return u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},u(e,t)};var c,d=function(){return d=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},d.apply(this,arguments)};function l(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}function h(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))}function f(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function p(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}!function(e){e.CONNECTED="connected",e.AUTHORIZATION_EXPIRED="authorization_expired",e.NOT_AUTHORIZED="not_authorized",e.UNKNOWN="unknown"}(c||(c={}));var v,g,m=c,w=function(e){function t(t,n,r){var i=e.call(this,t)||this;return i.code=n,i.type=r,i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t}(Error);!function(e){e.GET="get",e.POST="post",e.DELETE="delete"}(v||(v={})),function(e){e.UI="ui",e.API="api",e.LOGIN="login",e.LOGOUT="logout",e.GET_LOGIN_STATUS="getLoginStatus",e.GET_AUTH_RESPONSE="getAuthResponse"}(g||(g={}));var y,b={domain:"connect.facebook.net",version:"v14.0",cookie:!1,status:!1,xfbml:!1,language:"en_US",frictionlessRequests:!1,debug:!1,chatSupport:!1,autoLogAppEvents:!0,lazy:!1},E=function(){function e(e){if(!e.appId)throw new Error("You need to set appId");this.options=d(d({},b),e),this.options.lazy||this.init()}return e.prototype.getAppId=function(){return this.options.appId},e.prototype.getFB=function(){return window.FB},e.prototype.init=function(){return h(this,void 0,void 0,(function(){var e=this;return f(this,(function(t){return this.loadingPromise||(this.loadingPromise=new Promise((function(t){var n=e.options,r=n.domain,i=n.language,o=n.debug,a=n.chatSupport,s=l(n,["domain","language","debug","chatSupport"]);if(window.fbAsyncInit=function(){window.FB.init({appId:s.appId,version:s.version,cookie:s.cookie,status:s.status,xfbml:s.xfbml,frictionlessRequests:s.frictionlessRequests}),t(e)},window.document.getElementById("facebook-jssdk"))return t(window.FB);var u=window.document.createElement("script");u.id="facebook-jssdk",u.async=!0,u.defer=!0,u.crossOrigin="anonymous",u.src="https://".concat(r,"/").concat(i,"/sdk").concat(a?"/xfbml.customerchat":"").concat(o?"/debug":"",".js"),window.document.body.appendChild(u)}))),[2,this.loadingPromise]}))}))},e.prototype.process=function(e,t,n){return void 0===t&&(t=[]),void 0===n&&(n=[]),h(this,void 0,void 0,(function(){var r;return f(this,(function(i){switch(i.label){case 0:return[4,this.init()];case 1:return r=i.sent(),[2,new Promise((function(i,o){r[e].apply(r,p(p(p([],t,!1),[function(t){if(t)if("error"in t){var n=t.error,r=n.code,a=n.type,s=n.message;o(new w(s,r,a))}else i(t);else{if(e===g.UI)return;o(new Error("Response is undefined"))}}],!1),n,!1))}))]}}))}))},e.prototype.ui=function(e){return h(this,void 0,void 0,(function(){return f(this,(function(t){return[2,this.process(g.UI,[e])]}))}))},e.prototype.api=function(e,t,n){return void 0===t&&(t=v.GET),void 0===n&&(n={}),h(this,void 0,void 0,(function(){return f(this,(function(r){return[2,this.process(g.API,[e,t,n])]}))}))},e.prototype.login=function(e){return h(this,void 0,void 0,(function(){var t,n,r,i,o,a,s;return f(this,(function(u){return t=e.scope,n=e.authType,r=void 0===n?[]:n,i=e.returnScopes,o=e.rerequest,a=e.reauthorize,s={scope:t},i&&(s.return_scopes=!0),o&&r.push("rerequest"),a&&r.push("reauthenticate"),r.length&&(s.auth_type=r.join(",")),[2,this.process(g.LOGIN,[],[s])]}))}))},e.prototype.logout=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){return[2,this.process(g.LOGOUT)]}))}))},e.prototype.getLoginStatus=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){return[2,this.process(g.GET_LOGIN_STATUS)]}))}))},e.prototype.getAuthResponse=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){return[2,this.process(g.GET_AUTH_RESPONSE)]}))}))},e.prototype.getTokenDetail=function(e){return h(this,void 0,void 0,(function(){var t;return f(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.status)===m.CONNECTED?[2,e.authResponse]:[4,this.getLoginStatus()];case 1:if((t=n.sent()).status===m.CONNECTED)return[2,t.authResponse];throw new Error("Token is undefined")}}))}))},e.prototype.getProfile=function(e){return h(this,void 0,void 0,(function(){return f(this,(function(t){return[2,this.api("/me",v.GET,e)]}))}))},e.prototype.getTokenDetailWithProfile=function(e,t){return h(this,void 0,void 0,(function(){var n;return f(this,(function(r){switch(r.label){case 0:return[4,this.getTokenDetail(t)];case 1:return n=r.sent(),[4,this.getProfile(e)];case 2:return[2,{profile:r.sent(),tokenDetail:n}]}}))}))},e.prototype.getToken=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){switch(e.label){case 0:return[4,this.getTokenDetail()];case 1:return[2,e.sent().accessToken]}}))}))},e.prototype.getUserId=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){switch(e.label){case 0:return[4,this.getTokenDetail()];case 1:return[2,e.sent().userID]}}))}))},e.prototype.sendInvite=function(e,t){return h(this,void 0,void 0,(function(){return f(this,(function(n){return[2,this.ui(d({to:e,method:"apprequests"},t))]}))}))},e.prototype.postAction=function(e,t,n,r,i){return void 0===i&&(i=!1),h(this,void 0,void 0,(function(){var o;return f(this,(function(a){return o="/me/".concat(e,":").concat(t,"?").concat(n,"=").concat(encodeURIComponent(r)),!0===i&&(o+="&no_feed_story=true"),[2,this.api(o,v.POST)]}))}))},e.prototype.getPermissions=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){switch(e.label){case 0:return[4,this.api("/me/permissions")];case 1:return[2,e.sent().data]}}))}))},e.prototype.hasPermissions=function(e){return h(this,void 0,void 0,(function(){var t;return f(this,(function(n){switch(n.label){case 0:return[4,this.getPermissions()];case 1:return t=n.sent(),[2,e.filter((function(e){return!!t.find((function(t){var n=t.permission;return"granted"===t.status&&n===e}))})).length===e.length]}}))}))},e.prototype.subscribe=function(e,t){return h(this,void 0,void 0,(function(){var n=this;return f(this,(function(r){switch(r.label){case 0:return[4,this.init()];case 1:return r.sent(),this.getFB().Event.subscribe(e,t),[2,function(){return n.unsubscribe(e,t)}]}}))}))},e.prototype.unsubscribe=function(e,t){return h(this,void 0,void 0,(function(){return f(this,(function(n){switch(n.label){case 0:return[4,this.init()];case 1:return n.sent(),this.getFB().Event.unsubscribe(e,t),[2]}}))}))},e.prototype.parse=function(e){return h(this,void 0,void 0,(function(){return f(this,(function(t){switch(t.label){case 0:return[4,this.init()];case 1:return t.sent(),void 0===e?this.getFB().XFBML.parse():this.getFB().XFBML.parse(e),[2]}}))}))},e.prototype.getRequests=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){return[2,this.api("/me/apprequests")]}))}))},e.prototype.removeRequest=function(e){return h(this,void 0,void 0,(function(){return f(this,(function(t){return[2,this.api(e,v.DELETE)]}))}))},e.prototype.setAutoGrow=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){switch(e.label){case 0:return[4,this.init()];case 1:return e.sent(),this.getFB().Canvas.setAutoGrow(),[2]}}))}))},e.prototype.paySimple=function(e,t){return void 0===t&&(t=1),h(this,void 0,void 0,(function(){return f(this,(function(n){return[2,this.ui({method:"pay",action:"purchaseitem",product:e,quantity:t})]}))}))},e.prototype.pay=function(e,t){return h(this,void 0,void 0,(function(){return f(this,(function(n){return[2,this.ui(d({method:"pay",action:"purchaseitem",product:e},t))]}))}))},e}(),T=t(void 0);function _(t){var i=t.children,o=l(t,["children"]),a=n(!0),s=a[0],u=a[1],c=n(!1),d=c[0],p=c[1],v=n(),g=v[0],m=v[1];function w(){return h(this,void 0,void 0,(function(){var e;return f(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,3,4]),y?[2,y.init()]:(p(!1),u(!0),[4,(y=new E(o)).init()]);case 1:return t.sent(),p(!0),[3,4];case 2:return e=t.sent(),m(e),[3,4];case 3:return u(!1),[7];case 4:return[2,y]}}))}))}r((function(){o.lazy||w()}),[]);var b={isLoading:s,error:g,init:w,api:d?y:void 0,parse:function(e){return h(this,void 0,void 0,(function(){var t;return f(this,(function(n){switch(n.label){case 0:return[4,w()];case 1:return(t=n.sent())?[4,t.parse(e)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))}};return e.createElement(T.Provider,{value:b},i)}function k(e){void 0===e&&(e={});var t=e.lazy,n=void 0!==t&&t,o=i(T);if(!o)throw new Error("useFacebook must be used within a FacebookProvider");return r((function(){n||o.init()}),[n]),o}var I=o(a((function(t,n){var r=t.inline,i=t.children,o=l(t,["inline","children"]),a=r?"span":"div";return e.createElement(a,d({},o,{ref:n}),i)})));var O=o((function(t){var i=t.children,o=t.inline,a=l(t,["children","inline"]),u=k().parse,c=n(null),h=c[0],f=c[1],p=s((function(e){f(e)}),[]);return r((function(){h&&u(h)}),[h]),e.createElement(I,d({inline:o},a,{ref:p}),i)})),S=!("undefined"==typeof window||!window.document||!window.document.createElement);function A(){return S?window.location.href:"https://www.facebook.com"}var C=o(a((function(t,n){var r=t.href,i=void 0===r?A():r,o=t.layout,a=t.colorScheme,s=t.action,u=t.showFaces,c=t.share,h=t.children,f=t.width,p=t.size,v=t.kidDirectedSite,g=t.referral,m=l(t,["href","layout","colorScheme","action","showFaces","share","children","width","size","kidDirectedSite","referral"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-like","data-ref":g,"data-href":i,"data-layout":o,"data-colorscheme":a,"data-action":s,"data-show-faces":u,"data-share":c,"data-width":f,"data-size":p,"data-kid-directed-site":v},m,{ref:n}),h))})));function L(){var e=k().init,t=n(!1),r=t[0],i=t[1],o=n(void 0),a=o[0],s=o[1];return{isLoading:r,error:a,share:function(t){return h(this,void 0,void 0,(function(){var n,r,o,a,u,c,h;return f(this,(function(f){switch(f.label){case 0:return f.trys.push([0,2,3,4]),n=t.href,r=t.display,o=t.hashtag,a=t.redirectUri,u=l(t,["href","display","hashtag","redirectUri"]),s(void 0),i(!0),[4,e()];case 1:if(!(c=f.sent()))throw new Error("Facebook API is not initialized");return[2,c.ui((p=d({method:"share",href:n,display:r,app_id:c.getAppId(),hashtag:o,redirect_uri:a},u),Object.fromEntries(Object.entries(p).filter((function(e){return void 0!==e[1]})))))];case 2:return h=f.sent(),s(h),[3,4];case 3:return i(!1),[7];case 4:return[2]}var p}))}))}}}function N(t){var n=t.children,r=t.asChild,i=void 0===r?"button":r;t.disabled;var o=t.href,a=t.display,s=t.hashtag,u=t.redirectUri,c=l(t,["children","asChild","disabled","href","display","hashtag","redirectUri"]),h=L(),f=h.isLoading,p=h.share;return e.createElement(i,d({onClick:function(){f||p({href:o,display:a,hashtag:s,redirectUri:u})},disabled:f},c),n)}var P=o(a((function(t,n){var r=t.style,i=t.href,o=void 0===i?A():i,a=t.tabs,s=t.hideCover,u=t.width,c=t.height,h=t.showFacepile,f=t.hideCTA,p=t.smallHeader,v=t.adaptContainerWidth,g=t.children,m=l(t,["style","href","tabs","hideCover","width","height","showFacepile","hideCTA","smallHeader","adaptContainerWidth","children"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-page",style:r,"data-tabs":a,"data-hide-cover":s,"data-show-facepile":h,"data-hide-cta":f,"data-href":o,"data-small-header":p,"data-adapt-container-width":v,"data-height":c,"data-width":u},m,{ref:n}),g))})));function D(){var e=k(),t=e.api,r=e.isLoading,i=n(void 0),o=i[0],a=i[1],s=n(!1),u=s[0],c=s[1],d=n(),l=d[0],p=d[1];return{login:function(e,n){return h(this,void 0,void 0,(function(){var r,i;return f(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,2,3,4]),!t)throw new Error("Facebook API is not initialized");return c(!0),[4,t.login(e)];case 1:if((r=o.sent()).status!==m.CONNECTED)throw new Error("Unauthorized user");return p(r),null==n||n(r),[2,r];case 2:throw i=o.sent(),a(i),i;case 3:return c(!1),[7];case 4:return[2]}}))}))},error:o,isLoading:r||u,status:null==l?void 0:l.status}}function R(t){var n=t.children,r=t.asChild,i=void 0===r?"button":r;t.disabled;var o=t.scope,a=t.returnScopes,s=t.authType,u=t.rerequest,c=t.reauthorize,p=t.onError,v=t.onSuccess,g=l(t,["children","asChild","disabled","scope","returnScopes","authType","rerequest","reauthorize","onError","onSuccess"]),m=D(),w=m.isLoading,y=m.login;return e.createElement(i,d({onClick:function(){return h(this,void 0,void 0,(function(){var e,t;return f(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),w?[2]:[4,y({scope:o,returnScopes:a,authType:s,rerequest:u,reauthorize:c})];case 1:return e=n.sent(),null==v||v(e),[3,3];case 2:return t=n.sent(),null==p||p(t),[3,3];case 3:return[2]}}))}))},disabled:w},g),n)}var z=o(a((function(t,n){var r=t.href,i=t.width,o=t.showText,a=t.children,s=l(t,["href","width","showText","children"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-post","data-href":r,"data-width":i,"data-show-text":o},s,{ref:n}),a))})));var U=o(a((function(t,n){var r=t.href,i=t.width,o=t.showText,a=t.allowFullScreen,s=t.autoPlay,u=t.showCaptions,c=t.children,h=l(t,["href","width","showText","allowFullScreen","autoPlay","showCaptions","children"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-video","data-href":r,"data-width":i,"data-show-text":o,"data-show-captions":u,"data-autoplay":s,"data-allowfullscreen":a},h,{ref:n}),c))})));var x=o(a((function(t,n){var r=t.colorScheme,i=t.href,o=void 0===i?A():i,a=t.numPosts,s=t.orderBy,u=t.width,c=t.children,h=t.mobile,f=l(t,["colorScheme","href","numPosts","orderBy","width","children","mobile"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-comments","data-colorscheme":r,"data-numposts":a,"data-href":o,"data-order-by":s,"data-width":u,"data-skin":r,"data-mobile":h},f,{ref:n}),c))})));var G=o(a((function(t,n){var r=t.href,i=void 0===r?A():r,o=t.children,a=l(t,["href","children"]);return e.createElement(O,{inline:!0},e.createElement("span",d({className:"fb-comments-count","data-href":i},a,{ref:n}),o))})));var F=o(a((function(t,n){var r=t.style,i=t.href,o=void 0===i?A():i,a=t.width,s=t.showSocialContext,u=t.showMetaData,c=t.children,h=t.skin,f=l(t,["style","href","width","showSocialContext","showMetaData","children","skin"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-group",style:r,"data-href":o,"data-width":a,"data-show-social-context":s,"data-show-metadata":u,"data-skin":h},f,{ref:n}),c))})));var B=o(a((function(t,n){var r=t.children,i=t.pageId,o=t.themeColor,a=t.loggedInGreeting,s=t.loggedOutGreeting,u=t.dataRef,c=t.greetingDialogDisplay,h=t.greetingDialogDelay,f=t.minimized,p=l(t,["children","pageId","themeColor","loggedInGreeting","loggedOutGreeting","dataRef","greetingDialogDisplay","greetingDialogDelay","minimized"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-customerchat",page_id:i,theme_color:o,logged_in_greeting:a,logged_out_greeting:s,greeting_dialog_display:c,greeting_dialog_delay:h,"data-ref":u,minimized:f},p,{ref:n}),r))})));var M=o(a((function(t,n){var r=t.color,i=t.messengerAppId,o=t.pageId,a=t.children,s=t.size,u=t.dataRef,c=l(t,["color","messengerAppId","pageId","children","size","dataRef"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-messengermessageus",messenger_app_id:i,page_id:o,"data-color":r,"data-size":s,"data-ref":u},c,{ref:n}),a))})));var j=o(a((function(t,n){var r=t.origin,i=t.prechecked,o=t.allowLogin,a=t.userRef,s=t.messengerAppId,u=t.pageId,c=t.children,h=t.size,f=t.centerAlign,p=t.skin,v=l(t,["origin","prechecked","allowLogin","userRef","messengerAppId","pageId","children","size","centerAlign","skin"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-messenger-checkbox",messenger_app_id:s,page_id:u,size:h,origin:r,user_ref:a,prechecked:i,allow_login:o,skin:p,center_align:f},v,{ref:n}),c))})));var q,H=o(a((function(t,n){var r=t.color,i=t.messengerAppId,o=t.pageId,a=t.children,s=t.dataRef,u=t.size,c=t.enforceLogin,h=l(t,["color","messengerAppId","pageId","children","dataRef","size","enforceLogin"]);return e.createElement(O,null,e.createElement("div",d({className:"fb-send-to-messenger",messenger_app_id:i,page_id:o,"data-color":r,"data-size":u,"data-ref":s,enforce_login:c},h,{ref:n}),a))})));!function(e){e.SMALL="small",e.LARGE="large"}(q||(q={}));var W,X=q;!function(e){e.STANDARD="standard",e.BUTTON_COUNT="button_count",e.BUTTON="button",e.BOX_COUNT="box_count"}(W||(W={}));var K,V=W;!function(e){e.LIGHT="light",e.DARK="dark"}(K||(K={}));var Z,Y=K;!function(e){e.LIKE="like",e.RECOMMEND="recommend"}(Z||(Z={}));var J,Q=Z;!function(e){e.SOCIAL="social",e.REVERSE_TIME="reverse_time",e.TIME="time"}(J||(J={}));var $,ee=J;!function(e){e.SMALL="small",e.MEDIUM="medium",e.STANDARD="standard",e.LARGE="large",e.XLARGE="xlarge"}($||($={}));var te,ne=$;!function(e){e.BLUE="blue",e.WHITE="white"}(te||(te={}));var re=te,ie=["id","first_name","last_name","middle_name","name","name_format","picture","short_name","email"];function oe(e,t){var i=this,o=n(void 0),a=o[0],u=o[1],c=k().init,d=s((function(e){u(e),null==t||t(a)}),[t]),l=s((function(){return h(i,void 0,void 0,(function(){var t;return f(this,(function(n){switch(n.label){case 0:return[4,c()];case 1:return(t=n.sent())?[4,t.subscribe(e,d)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))}),[e,d]),p=s((function(){return h(i,void 0,void 0,(function(){var t;return f(this,(function(n){switch(n.label){case 0:return[4,c()];case 1:return(t=n.sent())?[4,t.unsubscribe(e,d)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))}),[e,d]);return r((function(){return l(),function(){p()}}),[l]),a}function ae(){var e=k().init,t=n(!0),i=t[0],o=t[1],a=n(void 0),u=a[0],c=a[1],d=n(m.UNKNOWN),l=d[0],p=d[1];return oe("auth.statusChange",s((function(e){p(e.status)}),[])),r((function(){!function(){h(this,void 0,void 0,(function(){var t,n,r;return f(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,4,5]),o(!0),[4,e()];case 1:if(!(t=i.sent()))throw new Error("Facebook API is not initialized");return[4,t.getLoginStatus()];case 2:return n=i.sent().status,p(n),[3,5];case 3:return r=i.sent(),c(r),[3,5];case 4:return o(!1),[7];case 5:return[2]}}))}))}()}),[]),{isLoading:i,error:u,status:l}}function se(e){var t=k().init,i=ae().status,o=n(!0),a=o[0],s=o[1],u=n(void 0),c=u[0],d=u[1],l=n(void 0),p=l[0],v=l[1];return r((function(){!function(){h(this,void 0,void 0,(function(){var n,r,o;return f(this,(function(a){switch(a.label){case 0:return a.trys.push([0,4,5,6]),v(void 0),s(!0),[4,t()];case 1:if(!(n=a.sent()))throw new Error("Facebook API is not initialized");return i!==m.CONNECTED?[3,3]:[4,n.getProfile({fields:e})];case 2:r=a.sent(),d(r),a.label=3;case 3:return[3,6];case 4:return o=a.sent(),v(o),[3,6];case 5:return s(!1),[7];case 6:return[2]}}))}))}()}),[i,e]),{isLoading:a,error:p,profile:c}}export{Y as ColorScheme,x as Comments,G as CommentsCount,ee as CommentsOrderBy,B as CustomChat,z as EmbeddedPost,U as EmbeddedVideo,T as FacebookContext,_ as FacebookProvider,ie as Fields,F as Group,C as Like,Q as LikeAction,V as LikeLayout,X as LikeSize,R as LoginButton,m as LoginStatus,M as MessageUs,j as MessengerCheckbox,re as MessengerColor,ne as MessengerSize,P as Page,O as Parser,H as SendToMessenger,N as ShareButton,k as useFacebook,D as useLogin,ae as useLoginStatus,se as useProfile,L as useShare,oe as useSubscribe};
import React, { createContext, useState, useEffect, useContext, memo, forwardRef, useCallback } from 'react';
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
var LoginStatus;
(function (LoginStatus) {
LoginStatus["CONNECTED"] = "connected";
LoginStatus["AUTHORIZATION_EXPIRED"] = "authorization_expired";
LoginStatus["NOT_AUTHORIZED"] = "not_authorized";
LoginStatus["UNKNOWN"] = "unknown";
})(LoginStatus || (LoginStatus = {}));
var LoginStatus$1 = LoginStatus;
var FBError = /** @class */ (function (_super) {
__extends(FBError, _super);
function FBError(message, code, type) {
var _this = _super.call(this, message) || this;
_this.code = code;
_this.type = type;
return _this;
}
return FBError;
}(Error));
var Method;
(function (Method) {
Method["GET"] = "get";
Method["POST"] = "post";
Method["DELETE"] = "delete";
})(Method || (Method = {}));
var Namespace;
(function (Namespace) {
Namespace["UI"] = "ui";
Namespace["API"] = "api";
Namespace["LOGIN"] = "login";
Namespace["LOGOUT"] = "logout";
Namespace["GET_LOGIN_STATUS"] = "getLoginStatus";
Namespace["GET_AUTH_RESPONSE"] = "getAuthResponse";
})(Namespace || (Namespace = {}));
var defaultOptions = {
domain: 'connect.facebook.net',
version: 'v15.0',
cookie: false,
status: false,
xfbml: true,
language: 'en_US',
frictionlessRequests: false,
debug: false,
chatSupport: false,
autoLogAppEvents: true,
lazy: false,
};
var Facebook = /** @class */ (function () {
function Facebook(options) {
if (!options.appId) {
throw new Error('You need to set appId');
}
this.options = __assign(__assign({}, defaultOptions), options);
if (!this.options.lazy) {
this.init();
}
}
Facebook.prototype.getAppId = function () {
return this.options.appId;
};
Facebook.prototype.getFB = function () {
return window.FB;
};
Facebook.prototype.init = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
if (this.loadingPromise) {
return [2 /*return*/, this.loadingPromise];
}
this.loadingPromise = new Promise(function (resolve) {
var _a = _this.options, domain = _a.domain, language = _a.language, debug = _a.debug, chatSupport = _a.chatSupport, restOptions = __rest(_a, ["domain", "language", "debug", "chatSupport"]);
window.fbAsyncInit = function () {
window.FB.init({
appId: restOptions.appId,
version: restOptions.version,
cookie: restOptions.cookie,
status: restOptions.status,
xfbml: restOptions.xfbml,
frictionlessRequests: restOptions.frictionlessRequests,
});
resolve(_this);
};
if (window.document.getElementById('facebook-jssdk')) {
return resolve(_this);
}
var js = window.document.createElement('script');
js.id = 'facebook-jssdk';
js.async = true;
js.defer = true;
js.crossOrigin = 'anonymous';
js.src = "https://".concat(domain, "/").concat(language, "/sdk").concat(chatSupport ? '/xfbml.customerchat' : '').concat(debug ? '/debug' : '', ".js");
window.document.body.appendChild(js);
});
return [2 /*return*/, this.loadingPromise];
});
});
};
Facebook.prototype.process = function (namespace, before, after) {
if (before === void 0) { before = []; }
if (after === void 0) { after = []; }
return __awaiter(this, void 0, void 0, function () {
var fb;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
fb = this.getFB();
return [2 /*return*/, new Promise(function (resolve, reject) {
// @ts-ignore
fb[namespace].apply(fb, __spreadArray(__spreadArray(__spreadArray([], before, false), [function (response) {
if (!response) {
if (namespace === Namespace.UI)
return;
reject(new Error('Response is undefined'));
}
else if (!!response && 'error' in response) {
var _a = response.error, code = _a.code, type = _a.type, message = _a.message;
reject(new FBError(message, code, type));
}
else {
resolve(response);
}
}], false), after, false));
})];
}
});
});
};
Facebook.prototype.ui = function (options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.UI, [options])];
});
});
};
Facebook.prototype.api = function (path, method, params) {
if (method === void 0) { method = Method.GET; }
if (params === void 0) { params = {}; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.API, [path, method, params])];
});
});
};
Facebook.prototype.login = function (options) {
return __awaiter(this, void 0, void 0, function () {
var scope, _a, authType, returnScopes, rerequest, reauthorize, loginOptions;
return __generator(this, function (_b) {
scope = options.scope, _a = options.authType, authType = _a === void 0 ? [] : _a, returnScopes = options.returnScopes, rerequest = options.rerequest, reauthorize = options.reauthorize;
loginOptions = {
scope: scope,
};
if (returnScopes) {
loginOptions.return_scopes = true;
}
if (rerequest) {
authType.push('rerequest');
}
if (reauthorize) {
authType.push('reauthenticate');
}
if (authType.length) {
loginOptions.auth_type = authType.join(',');
}
return [2 /*return*/, this.process(Namespace.LOGIN, [], [loginOptions])];
});
});
};
Facebook.prototype.logout = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.LOGOUT)];
});
});
};
Facebook.prototype.getLoginStatus = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.GET_LOGIN_STATUS)];
});
});
};
Facebook.prototype.getAuthResponse = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.process(Namespace.GET_AUTH_RESPONSE)];
});
});
};
Facebook.prototype.getTokenDetail = function (loginResponse) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if ((loginResponse === null || loginResponse === void 0 ? void 0 : loginResponse.status) === LoginStatus$1.CONNECTED) {
return [2 /*return*/, loginResponse.authResponse];
}
return [4 /*yield*/, this.getLoginStatus()];
case 1:
response = _a.sent();
if (response.status === LoginStatus$1.CONNECTED) {
return [2 /*return*/, response.authResponse];
}
throw new Error('Token is undefined');
}
});
});
};
Facebook.prototype.getProfile = function (params) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.api('/me', Method.GET, params)];
});
});
};
Facebook.prototype.getTokenDetailWithProfile = function (params, response) {
return __awaiter(this, void 0, void 0, function () {
var tokenDetail, profile;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getTokenDetail(response)];
case 1:
tokenDetail = _a.sent();
return [4 /*yield*/, this.getProfile(params)];
case 2:
profile = _a.sent();
return [2 /*return*/, {
profile: profile,
tokenDetail: tokenDetail,
}];
}
});
});
};
Facebook.prototype.getToken = function () {
return __awaiter(this, void 0, void 0, function () {
var authResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getTokenDetail()];
case 1:
authResponse = _a.sent();
return [2 /*return*/, authResponse.accessToken];
}
});
});
};
Facebook.prototype.getUserId = function () {
return __awaiter(this, void 0, void 0, function () {
var authResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getTokenDetail()];
case 1:
authResponse = _a.sent();
return [2 /*return*/, authResponse.userID];
}
});
});
};
Facebook.prototype.sendInvite = function (to, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ui(__assign({ to: to, method: 'apprequests' }, options))];
});
});
};
Facebook.prototype.postAction = function (ogNamespace, ogAction, ogObject, ogObjectUrl, noFeedStory) {
if (noFeedStory === void 0) { noFeedStory = false; }
return __awaiter(this, void 0, void 0, function () {
var url;
return __generator(this, function (_a) {
url = "/me/".concat(ogNamespace, ":").concat(ogAction, "?").concat(ogObject, "=").concat(encodeURIComponent(ogObjectUrl));
if (noFeedStory === true) {
url += '&no_feed_story=true';
}
return [2 /*return*/, this.api(url, Method.POST)];
});
});
};
Facebook.prototype.getPermissions = function () {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.api('/me/permissions')];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
};
Facebook.prototype.hasPermissions = function (permissions) {
return __awaiter(this, void 0, void 0, function () {
var usersPermissions, findedPermissions;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getPermissions()];
case 1:
usersPermissions = _a.sent();
findedPermissions = permissions.filter(function (p) {
var currentPermission = usersPermissions.find(function (row) {
var permission = row.permission, status = row.status;
return status === 'granted' && permission === p;
});
return !!currentPermission;
});
return [2 /*return*/, findedPermissions.length === permissions.length];
}
});
});
};
Facebook.prototype.subscribe = function (eventName, callback) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
this.getFB().Event.subscribe(eventName, callback);
return [2 /*return*/, function () { return _this.unsubscribe(eventName, callback); }];
}
});
});
};
Facebook.prototype.unsubscribe = function (eventName, callback) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
this.getFB().Event.unsubscribe(eventName, callback);
return [2 /*return*/];
}
});
});
};
Facebook.prototype.parse = function (parentNode) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
if (typeof parentNode === 'undefined') {
this.getFB().XFBML.parse();
}
else {
this.getFB().XFBML.parse(parentNode);
}
return [2 /*return*/];
}
});
});
};
Facebook.prototype.getRequests = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.api('/me/apprequests')];
});
});
};
Facebook.prototype.removeRequest = function (requestId) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.api(requestId, Method.DELETE)];
});
});
};
Facebook.prototype.setAutoGrow = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.init()];
case 1:
_a.sent();
this.getFB().Canvas.setAutoGrow();
return [2 /*return*/];
}
});
});
};
Facebook.prototype.paySimple = function (product, quantity) {
if (quantity === void 0) { quantity = 1; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ui({
method: 'pay',
action: 'purchaseitem',
product: product,
quantity: quantity,
})];
});
});
};
Facebook.prototype.pay = function (product, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ui(__assign({ method: 'pay', action: 'purchaseitem', product: product }, options))];
});
});
};
return Facebook;
}());
/*
sendToFriends: function(options, callback) {
if(!options) {
options = {};
}
options.method = 'send';
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.ui(options, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
sendMessage: function(message, name, caption, description, url, imgUrl, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.ui({
method: 'stream.publish',
message: message,
attachment: {
name: name,
caption: caption,
description: description,
href: url,
media:[{
type: 'image',
src: imgUrl,
href: url
}]
},
action_links: [{
text: 'Code',
href: url
}],
user_prompt_message: message
},
function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
sendInviteForm: function(options, callback) {
if(typeof options === 'function') {
callback = options;
options = {};
}
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
options.method = options.method || 'apprequests';
FB.ui(options, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
checkPageLike: function(pageID, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
fbApi.getUserID(function(err, userID) {
if(err) {
return callback(err);
}
var fqlQuery = `SELECT uid FROM page_fan WHERE page_id = ${pageID} and uid = ${userID}`;
var query = FB.Data.query(fqlQuery);
query.wait(function(rows) {
if (rows.length === 1 && rows[0].uid === userID) {
callback(null, true, query);
}
else {
callback(null, false, query);
}
});
});
});
},
sendMessageToFriend: function (friendID, link, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.ui({
to: friendID,
method: 'send',
link: link
}, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
_prepareUsers: function(data) {
var users=[];
for(var index in data) {
var userData=data[index];
var user = {
provider_uid: 'facebook'+'_'+userData.uid,
provider: 'facebook',
id: userData.uid,
name: userData.name,
first_name: userData.first_name,
last_name: userData.last_name,
status: (userData.status!==null) ? userData.status : null,
image: '//graph.facebook.com/'+userData.uid+'/picture?'
};
users.push(user);
}
return users;
},
getUserList: function(callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('fql', {
q: `
SELECT uid, name, first_name, last_name, online_presence, status
FROM user
WHERE uid IN
( SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY name
`,
}, function (response)
{
var users = fbApi._prepareUsers(response.data);
callback(null, users, response);
});
});
},
postFeed: function(options, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
options.method='feed';
FB.ui(options, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//need publish_stream
createAlbum: function(name, description, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/me/albums', 'post', {
name: name,
description: description
},function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//need publish_stream
addImageToAlbum: function(albumID, imageURL, message, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/'+albumID+'/photos', 'post', {
message: message,
url: imageURL
}, function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'user_photos'
getAlbums: function(callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/me/albums', function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'user_photos'
getAlbumPhotos: function(albumID, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/'+albumID+'/photos', function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'user_photos'
getAlbumCoverPicture: function(albumID, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/'+albumID+'/picture', function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
//'publish_stream'
postPhoto: function(photoUrl, message, callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.api('/me/photos', 'post', {
message: message,
url: photoUrl
},function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
},
getPageInfo: function(callback) {
this.afterLoad(function(err, fbApi) {
if(err) {
return callback(err);
}
FB.Canvas.getPageInfo(function(response) {
fbApi._callCallbackByResponse(callback, response);
});
});
}
*/
var FacebookContext = createContext(undefined);
var api;
function FacebookProvider(props) {
var children = props.children, options = __rest(props, ["children"]);
var _a = useState(true), isLoading = _a[0], setIsLoading = _a[1];
var _b = useState(false), isReady = _b[0], setIsReady = _b[1];
var _c = useState(), error = _c[0], setError = _c[1];
function init() {
return __awaiter(this, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, 3, 4]);
if (api) {
return [2 /*return*/, api.init()];
}
setIsReady(false);
setIsLoading(true);
api = new Facebook(options);
return [4 /*yield*/, api.init()];
case 1:
_a.sent();
setIsReady(true);
return [3 /*break*/, 4];
case 2:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 4];
case 3:
setIsLoading(false);
return [7 /*endfinally*/];
case 4: return [2 /*return*/, api];
}
});
});
}
function parse(element) {
return __awaiter(this, void 0, void 0, function () {
var api;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) return [3 /*break*/, 3];
return [4 /*yield*/, api.parse(element)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
}
useEffect(function () {
var lazy = options.lazy;
if (!lazy) {
init();
}
}, []);
var value = {
isLoading: isLoading,
error: error,
init: init,
api: isReady ? api : undefined,
parse: parse,
};
return (React.createElement(FacebookContext.Provider, { value: value }, children));
}
function useFacebook(props) {
if (props === void 0) { props = {}; }
var _a = props.lazy, lazy = _a === void 0 ? false : _a;
var context = useContext(FacebookContext);
if (!context) {
throw new Error('useFacebook must be used within a FacebookProvider');
}
useEffect(function () {
if (!lazy) {
context.init();
}
}, [lazy]);
return context;
}
var ParserInternal = memo(forwardRef(function (props, ref) {
var inline = props.inline, children = props.children, rest = __rest(props, ["inline", "children"]);
var Tag = inline ? 'span' : 'div';
return (
// @ts-ignore
React.createElement(Tag, __assign({}, rest, { ref: ref }), children));
}));
function Parser(props) {
var children = props.children, inline = props.inline, rest = __rest(props, ["children", "inline"]);
var parse = useFacebook().parse;
var _a = useState(null), element = _a[0], setElement = _a[1];
var handleRef = useCallback(function (element) {
setElement(element);
}, []);
useEffect(function () {
if (element) {
parse(element);
}
}, [element]);
return (React.createElement(ParserInternal, __assign({ inline: inline }, rest, { ref: handleRef }), children));
}
var Parser$1 = memo(Parser);
var canUseDOM = !!(typeof window !== 'undefined' &&
window.document &&
window.document.createElement);
function getCurrentHref() {
if (!canUseDOM) {
return 'https://www.facebook.com';
}
return window.location.href;
}
function Like(props, ref) {
var _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, layout = props.layout, colorScheme = props.colorScheme, action = props.action, showFaces = props.showFaces, share = props.share, children = props.children, width = props.width, size = props.size, kidDirectedSite = props.kidDirectedSite, referral = props.referral, lazy = props.lazy, rest = __rest(props, ["href", "layout", "colorScheme", "action", "showFaces", "share", "children", "width", "size", "kidDirectedSite", "referral", "lazy"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-like", "data-ref": referral, "data-href": href, "data-layout": layout, "data-colorscheme": colorScheme, "data-action": action, "data-show-faces": showFaces, "data-share": share, "data-width": width, "data-size": size, "data-lazy": lazy, "data-kid-directed-site": kidDirectedSite }, rest, { ref: ref }), children)));
}
var Like$1 = memo(forwardRef(Like));
function clearUndefinedProperties(obj) {
return Object.fromEntries(Object.entries(obj).filter(function (_a) {
var value = _a[1];
return value !== undefined;
}));
}
function useShare() {
var init = useFacebook().init;
var _a = useState(false), isLoading = _a[0], setIsLoading = _a[1];
var _b = useState(undefined), error = _b[0], setError = _b[1];
function handleShare(options) {
return __awaiter(this, void 0, void 0, function () {
var href, display, hashtag, redirectUri, rest, api, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, 3, 4]);
href = options.href, display = options.display, hashtag = options.hashtag, redirectUri = options.redirectUri, rest = __rest(options, ["href", "display", "hashtag", "redirectUri"]);
setError(undefined);
setIsLoading(true);
return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) {
throw new Error('Facebook API is not initialized');
}
return [2 /*return*/, api.ui(clearUndefinedProperties(__assign({ method: 'share', href: href, display: display, app_id: api.getAppId(), hashtag: hashtag, redirect_uri: redirectUri }, rest)))];
case 2:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 4];
case 3:
setIsLoading(false);
return [7 /*endfinally*/];
case 4: return [2 /*return*/];
}
});
});
}
return {
isLoading: isLoading,
error: error,
share: handleShare,
};
}
function ShareButton(props) {
var children = props.children, _a = props.asChild, AsChild = _a === void 0 ? 'button' : _a; props.disabled; var href = props.href, display = props.display, hashtag = props.hashtag, redirectUri = props.redirectUri, rest = __rest(props, ["children", "asChild", "disabled", "href", "display", "hashtag", "redirectUri"]);
var _b = useShare(), isLoading = _b.isLoading, share = _b.share;
function handleShare() {
if (isLoading) {
return;
}
share({
href: href,
display: display,
hashtag: hashtag,
redirectUri: redirectUri,
});
}
return (React.createElement(AsChild, __assign({ onClick: handleShare, disabled: isLoading }, rest), children));
}
function Page(props, ref) {
var style = props.style, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, tabs = props.tabs, hideCover = props.hideCover, width = props.width, height = props.height, showFacepile = props.showFacepile, hideCTA = props.hideCTA, smallHeader = props.smallHeader, adaptContainerWidth = props.adaptContainerWidth, children = props.children, lazy = props.lazy, rest = __rest(props, ["style", "href", "tabs", "hideCover", "width", "height", "showFacepile", "hideCTA", "smallHeader", "adaptContainerWidth", "children", "lazy"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-page", style: style, "data-tabs": tabs, "data-hide-cover": hideCover, "data-show-facepile": showFacepile, "data-hide-cta": hideCTA, "data-href": href, "data-small-header": smallHeader, "data-adapt-container-width": adaptContainerWidth, "data-height": height, "data-width": width, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Page$1 = memo(forwardRef(Page));
function useLogin() {
var _a = useFacebook(), api = _a.api, isLoading = _a.isLoading;
var _b = useState(undefined), error = _b[0], setError = _b[1];
var _c = useState(false), isLoadingLogin = _c[0], setIsLoadingLogin = _c[1];
var _d = useState(), latestResponse = _d[0], setLatestResponse = _d[1];
function handleLogin(loginOptions, callback) {
return __awaiter(this, void 0, void 0, function () {
var response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, 3, 4]);
if (!api) {
throw new Error('Facebook API is not initialized');
}
setIsLoadingLogin(true);
return [4 /*yield*/, api.login(loginOptions)];
case 1:
response = _a.sent();
if (response.status !== LoginStatus$1.CONNECTED) {
throw new Error('Unauthorized user');
}
setLatestResponse(response);
callback === null || callback === void 0 ? void 0 : callback(response);
return [2 /*return*/, response];
case 2:
error_1 = _a.sent();
setError(error_1);
throw (error_1);
case 3:
setIsLoadingLogin(false);
return [7 /*endfinally*/];
case 4: return [2 /*return*/];
}
});
});
}
return {
login: handleLogin,
error: error,
isLoading: isLoading || isLoadingLogin,
status: latestResponse === null || latestResponse === void 0 ? void 0 : latestResponse.status,
};
}
function LoginButton(props) {
var children = props.children, _a = props.asChild, AsChild = _a === void 0 ? 'button' : _a; props.disabled; var scope = props.scope, returnScopes = props.returnScopes, authType = props.authType, rerequest = props.rerequest, reauthorize = props.reauthorize, onError = props.onError, onSuccess = props.onSuccess, rest = __rest(props, ["children", "asChild", "disabled", "scope", "returnScopes", "authType", "rerequest", "reauthorize", "onError", "onSuccess"]);
var _b = useLogin(), isLoading = _b.isLoading, login = _b.login;
function handleLogin() {
return __awaiter(this, void 0, void 0, function () {
var response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (isLoading) {
return [2 /*return*/];
}
return [4 /*yield*/, login({
scope: scope,
returnScopes: returnScopes,
authType: authType,
rerequest: rerequest,
reauthorize: reauthorize,
})];
case 1:
response = _a.sent();
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
return [3 /*break*/, 3];
case 2:
error_1 = _a.sent();
onError === null || onError === void 0 ? void 0 : onError(error_1);
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
});
}
return (React.createElement(AsChild, __assign({ onClick: handleLogin, disabled: isLoading }, rest), children));
}
function EmbeddedPost(props, ref) {
var href = props.href, width = props.width, showText = props.showText, lazy = props.lazy, children = props.children, rest = __rest(props, ["href", "width", "showText", "lazy", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-post", "data-href": href, "data-width": width, "data-lazy": lazy, "data-show-text": showText }, rest, { ref: ref }), children)));
}
var EmbeddedPost$1 = memo(forwardRef(EmbeddedPost));
function EmbeddedVideo(props, ref) {
var href = props.href, width = props.width, showText = props.showText, allowFullScreen = props.allowFullScreen, autoPlay = props.autoPlay, lazy = props.lazy, showCaptions = props.showCaptions, children = props.children, rest = __rest(props, ["href", "width", "showText", "allowFullScreen", "autoPlay", "lazy", "showCaptions", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-video", "data-href": href, "data-width": width, "data-show-text": showText, "data-show-captions": showCaptions, "data-autoplay": autoPlay, "data-lazy": lazy, "data-allowfullscreen": allowFullScreen }, rest, { ref: ref }), children)));
}
var EmbeddedVideo$1 = memo(forwardRef(EmbeddedVideo));
function Comments(props, ref) {
var colorScheme = props.colorScheme, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, numPosts = props.numPosts, orderBy = props.orderBy, width = props.width, children = props.children, mobile = props.mobile, lazy = props.lazy, rest = __rest(props, ["colorScheme", "href", "numPosts", "orderBy", "width", "children", "mobile", "lazy"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-comments", "data-colorscheme": colorScheme, "data-numposts": numPosts, "data-href": href, "data-order-by": orderBy, "data-width": width, "data-skin": colorScheme, "data-mobile": mobile, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Comments$1 = memo(forwardRef(Comments));
function CommentsCount(props, ref) {
var _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, children = props.children, rest = __rest(props, ["href", "children"]);
return (React.createElement(Parser$1, { inline: true },
React.createElement("span", __assign({ className: "fb-comments-count", "data-href": href }, rest, { ref: ref }), children)));
}
var CommentsCount$1 = memo(forwardRef(CommentsCount));
function Group(props, ref) {
var style = props.style, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, width = props.width, lazy = props.lazy, showSocialContext = props.showSocialContext, showMetaData = props.showMetaData, children = props.children, skin = props.skin, rest = __rest(props, ["style", "href", "width", "lazy", "showSocialContext", "showMetaData", "children", "skin"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-group", style: style, "data-href": href, "data-width": width, "data-show-social-context": showSocialContext, "data-show-metadata": showMetaData, "data-skin": skin, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Group$1 = memo(forwardRef(Group));
function Save(props, ref) {
var style = props.style, _a = props.uri, uri = _a === void 0 ? getCurrentHref() : _a, lazy = props.lazy, children = props.children, rest = __rest(props, ["style", "uri", "lazy", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-save", style: style, "data-uri": uri, "data-lazy": lazy }, rest, { ref: ref }), children)));
}
var Save$1 = memo(forwardRef(Save));
function Share(props, ref) {
var style = props.style, _a = props.href, href = _a === void 0 ? getCurrentHref() : _a, lazy = props.lazy, layout = props.layout, size = props.size, children = props.children, rest = __rest(props, ["style", "href", "lazy", "layout", "size", "children"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-share-button", style: style, "data-href": href, "data-lazy": lazy, "data-size": size, "data-layout": layout }, rest, { ref: ref }), children)));
}
var Share$1 = memo(forwardRef(Share));
function CustomChat(props, ref) {
var children = props.children, pageId = props.pageId, themeColor = props.themeColor, loggedInGreeting = props.loggedInGreeting, loggedOutGreeting = props.loggedOutGreeting, dataRef = props.dataRef, greetingDialogDisplay = props.greetingDialogDisplay, greetingDialogDelay = props.greetingDialogDelay, minimized = props.minimized, rest = __rest(props, ["children", "pageId", "themeColor", "loggedInGreeting", "loggedOutGreeting", "dataRef", "greetingDialogDisplay", "greetingDialogDelay", "minimized"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-customerchat",
// @ts-ignore
page_id: pageId, theme_color: themeColor, logged_in_greeting: loggedInGreeting, logged_out_greeting: loggedOutGreeting, greeting_dialog_display: greetingDialogDisplay, greeting_dialog_delay: greetingDialogDelay, "data-ref": dataRef, minimized: minimized }, rest, { ref: ref }), children)));
}
var CustomChat$1 = memo(forwardRef(CustomChat));
function MessageUs(props, ref) {
var color = props.color, messengerAppId = props.messengerAppId, pageId = props.pageId, children = props.children, size = props.size, dataRef = props.dataRef, rest = __rest(props, ["color", "messengerAppId", "pageId", "children", "size", "dataRef"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-messengermessageus",
// @ts-ignore
messenger_app_id: messengerAppId, page_id: pageId, "data-color": color, "data-size": size, "data-ref": dataRef }, rest, { ref: ref }), children)));
}
var MessageUs$1 = memo(forwardRef(MessageUs));
function MessengerCheckbox(props, ref) {
var origin = props.origin, prechecked = props.prechecked, allowLogin = props.allowLogin, userRef = props.userRef, messengerAppId = props.messengerAppId, pageId = props.pageId, children = props.children, size = props.size, centerAlign = props.centerAlign, skin = props.skin, rest = __rest(props, ["origin", "prechecked", "allowLogin", "userRef", "messengerAppId", "pageId", "children", "size", "centerAlign", "skin"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-messenger-checkbox",
// @ts-ignore
messenger_app_id: messengerAppId, page_id: pageId, size: size, origin: origin, user_ref: userRef, prechecked: prechecked, allow_login: allowLogin, skin: skin, center_align: centerAlign }, rest, { ref: ref }), children)));
}
var MessengerCheckbox$1 = memo(forwardRef(MessengerCheckbox));
function SendToMessenger(props, ref) {
var color = props.color, messengerAppId = props.messengerAppId, pageId = props.pageId, children = props.children, dataRef = props.dataRef, size = props.size, enforceLogin = props.enforceLogin, rest = __rest(props, ["color", "messengerAppId", "pageId", "children", "dataRef", "size", "enforceLogin"]);
return (React.createElement(Parser$1, null,
React.createElement("div", __assign({ className: "fb-send-to-messenger",
// @ts-ignore
messenger_app_id: messengerAppId, page_id: pageId, "data-color": color, "data-size": size, "data-ref": dataRef, enforce_login: enforceLogin }, rest, { ref: ref }), children)));
}
var SendToMessenger$1 = memo(forwardRef(SendToMessenger));
var LikeSize;
(function (LikeSize) {
LikeSize["SMALL"] = "small";
LikeSize["LARGE"] = "large";
})(LikeSize || (LikeSize = {}));
var LikeSize$1 = LikeSize;
var LikeLayout;
(function (LikeLayout) {
LikeLayout["STANDARD"] = "standard";
LikeLayout["BUTTON_COUNT"] = "button_count";
LikeLayout["BUTTON"] = "button";
LikeLayout["BOX_COUNT"] = "box_count";
})(LikeLayout || (LikeLayout = {}));
var LikeLayout$1 = LikeLayout;
var ColorScheme;
(function (ColorScheme) {
ColorScheme["LIGHT"] = "light";
ColorScheme["DARK"] = "dark";
})(ColorScheme || (ColorScheme = {}));
var ColorScheme$1 = ColorScheme;
var LikeAction;
(function (LikeAction) {
LikeAction["LIKE"] = "like";
LikeAction["RECOMMEND"] = "recommend";
})(LikeAction || (LikeAction = {}));
var LikeAction$1 = LikeAction;
var CommentsOrderBy;
(function (CommentsOrderBy) {
CommentsOrderBy["SOCIAL"] = "social";
CommentsOrderBy["REVERSE_TIME"] = "reverse_time";
CommentsOrderBy["TIME"] = "time";
})(CommentsOrderBy || (CommentsOrderBy = {}));
var CommentsOrderBy$1 = CommentsOrderBy;
var MessengerSize;
(function (MessengerSize) {
MessengerSize["SMALL"] = "small";
MessengerSize["MEDIUM"] = "medium";
MessengerSize["STANDARD"] = "standard";
MessengerSize["LARGE"] = "large";
MessengerSize["XLARGE"] = "xlarge";
})(MessengerSize || (MessengerSize = {}));
var MessengerSize$1 = MessengerSize;
var MessengerColor;
(function (MessengerColor) {
MessengerColor["BLUE"] = "blue";
MessengerColor["WHITE"] = "white";
})(MessengerColor || (MessengerColor = {}));
var MessengerColor$1 = MessengerColor;
// @flow
// 3.0 fields without app review https://developers.facebook.com/docs/facebook-login/permissions/?locale=en_US#reference-default
var Fields = [
'id', 'first_name', 'last_name', 'middle_name',
'name', 'name_format', 'picture', 'short_name', 'email',
];
function useSubscribe(event, callback) {
var _this = this;
var _a = useState(undefined), lastValue = _a[0], setLastValue = _a[1];
var init = useFacebook().init;
var handleResponse = useCallback(function (value) {
setLastValue(value);
callback === null || callback === void 0 ? void 0 : callback(lastValue);
}, [callback]);
var handleSubscribe = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
var api;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) return [3 /*break*/, 3];
return [4 /*yield*/, api.subscribe(event, handleResponse)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
}); }, [event, handleResponse]);
var handleUnsubscribe = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
var api;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) return [3 /*break*/, 3];
return [4 /*yield*/, api.unsubscribe(event, handleResponse)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
}); }, [event, handleResponse]);
useEffect(function () {
handleSubscribe();
return function () {
handleUnsubscribe();
};
}, [handleSubscribe]);
return lastValue;
}
function useLoginStatus() {
var init = useFacebook().init;
var _a = useState(true), isLoading = _a[0], setIsLoading = _a[1];
var _b = useState(undefined), error = _b[0], setError = _b[1];
var _c = useState(LoginStatus$1.UNKNOWN), status = _c[0], setStatus = _c[1];
var handleStatusChanges = useCallback(function (response) {
setStatus(response.status);
}, []);
useSubscribe('auth.statusChange', handleStatusChanges);
function handleGetInitState() {
return __awaiter(this, void 0, void 0, function () {
var api, status_1, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, 4, 5]);
setIsLoading(true);
return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) {
throw new Error('Facebook API is not initialized');
}
return [4 /*yield*/, api.getLoginStatus()];
case 2:
status_1 = (_a.sent()).status;
setStatus(status_1);
return [3 /*break*/, 5];
case 3:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 5];
case 4:
setIsLoading(false);
return [7 /*endfinally*/];
case 5: return [2 /*return*/];
}
});
});
}
useEffect(function () {
handleGetInitState();
}, []);
return {
isLoading: isLoading,
error: error,
status: status,
};
}
function useProfile(fields) {
var init = useFacebook().init;
var status = useLoginStatus().status;
var _a = useState(true), isLoading = _a[0], setIsLoading = _a[1];
var _b = useState(undefined), profile = _b[0], setProfile = _b[1];
var _c = useState(undefined), error = _c[0], setError = _c[1];
function updateProfile() {
return __awaiter(this, void 0, void 0, function () {
var api, profile_1, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 4, 5, 6]);
setError(undefined);
setIsLoading(true);
return [4 /*yield*/, init()];
case 1:
api = _a.sent();
if (!api) {
throw new Error('Facebook API is not initialized');
}
if (!(status === LoginStatus$1.CONNECTED)) return [3 /*break*/, 3];
return [4 /*yield*/, api.getProfile({
fields: fields,
})];
case 2:
profile_1 = _a.sent();
setProfile(profile_1);
_a.label = 3;
case 3: return [3 /*break*/, 6];
case 4:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 6];
case 5:
setIsLoading(false);
return [7 /*endfinally*/];
case 6: return [2 /*return*/];
}
});
});
}
useEffect(function () {
updateProfile();
}, [status, fields]);
return {
isLoading: isLoading,
error: error,
profile: profile,
};
}
export { ColorScheme$1 as ColorScheme, Comments$1 as Comments, CommentsCount$1 as CommentsCount, CommentsOrderBy$1 as CommentsOrderBy, CustomChat$1 as CustomChat, EmbeddedPost$1 as EmbeddedPost, EmbeddedVideo$1 as EmbeddedVideo, FacebookContext, FacebookProvider, Fields, Group$1 as Group, Like$1 as Like, LikeAction$1 as LikeAction, LikeLayout$1 as LikeLayout, LikeSize$1 as LikeSize, LoginButton, LoginStatus$1 as LoginStatus, MessageUs$1 as MessageUs, MessengerCheckbox$1 as MessengerCheckbox, MessengerColor$1 as MessengerColor, MessengerSize$1 as MessengerSize, Page$1 as Page, Parser$1 as Parser, Save$1 as Save, SendToMessenger$1 as SendToMessenger, Share$1 as Share, ShareButton, useFacebook, useLogin, useLoginStatus, useProfile, useShare, useSubscribe };
//# sourceMappingURL=index.js.map

48

dist/index.d.ts

@@ -111,3 +111,3 @@ /// <reference types="react" />

declare function Parser(props: ParserProps): JSX.Element;
declare const _default$d: React__default.MemoExoticComponent<typeof Parser>;
declare const _default$f: React__default.MemoExoticComponent<typeof Parser>;

@@ -117,3 +117,3 @@ declare type LikeProps = {

href?: string;
layout?: string;
layout?: 'standard' | 'button_count' | 'button' | 'box_count';
showFaces?: boolean;

@@ -127,4 +127,5 @@ colorScheme?: string;

kidDirectedSite?: boolean;
lazy?: boolean;
};
declare const _default$c: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<LikeProps & React__default.RefAttributes<unknown>>>;
declare const _default$e: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<LikeProps & React__default.RefAttributes<unknown>>>;

@@ -160,6 +161,7 @@ declare type ShareOptions = {

adaptContainerWidth?: boolean;
lazy?: boolean;
children?: ReactNode;
style?: Object;
};
declare const _default$b: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<PageProps & React__default.RefAttributes<unknown>>>;
declare const _default$d: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<PageProps & React__default.RefAttributes<unknown>>>;

@@ -196,5 +198,6 @@ declare type LoginOptions = {

showText?: boolean;
lazy?: boolean;
children?: ReactNode;
};
declare const _default$a: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<EmbeddedPostProps & React__default.RefAttributes<unknown>>>;
declare const _default$c: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<EmbeddedPostProps & React__default.RefAttributes<unknown>>>;

@@ -208,5 +211,6 @@ declare type EmbeddedVideoProps = {

showCaptions?: boolean;
lazy?: boolean;
children?: ReactNode;
};
declare const _default$9: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<EmbeddedVideoProps & React__default.RefAttributes<unknown>>>;
declare const _default$b: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<EmbeddedVideoProps & React__default.RefAttributes<unknown>>>;

@@ -216,9 +220,10 @@ declare type CommentsProps = {

numPosts?: number;
orderBy?: string;
orderBy?: 'reverse_time' | 'time';
width?: number | string;
colorScheme?: string;
colorScheme?: 'light' | 'dark';
children?: ReactNode;
mobile?: boolean;
lazy?: boolean;
};
declare const _default$8: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<CommentsProps & React__default.RefAttributes<unknown>>>;
declare const _default$a: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<CommentsProps & React__default.RefAttributes<unknown>>>;

@@ -229,3 +234,3 @@ declare type CommentsCountProps = {

};
declare const _default$7: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<CommentsCountProps & React__default.RefAttributes<unknown>>>;
declare const _default$9: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<CommentsCountProps & React__default.RefAttributes<unknown>>>;

@@ -238,7 +243,26 @@ declare type GroupProps = {

width?: number | string;
lazy?: boolean;
children?: ReactNode;
style?: Object;
};
declare const _default$6: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<GroupProps & React__default.RefAttributes<unknown>>>;
declare const _default$8: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<GroupProps & React__default.RefAttributes<unknown>>>;
declare type SaveProps = {
uri?: string;
lazy?: boolean;
children?: ReactNode;
style?: Object;
};
declare const _default$7: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<SaveProps & React__default.RefAttributes<unknown>>>;
declare type ShareProps = {
href?: string;
lazy?: boolean;
size?: 'small' | 'large';
layout?: 'box_count' | 'button_count' | 'button' | 'icon_link';
children?: ReactNode;
style?: Object;
};
declare const _default$6: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<ShareProps & React__default.RefAttributes<unknown>>>;
declare type CustomChatProps = {

@@ -363,2 +387,2 @@ pageId: string;

export { ColorScheme, _default$8 as Comments, _default$7 as CommentsCount, CommentsOrderBy, _default$5 as CustomChat, _default$a as EmbeddedPost, _default$9 as EmbeddedVideo, _default$1 as FacebookContext, FacebookProvider, _default as Fields, _default$6 as Group, _default$c as Like, LikeAction, LikeLayout, LikeSize, LoginButton, LoginStatus, _default$4 as MessageUs, _default$3 as MessengerCheckbox, MessengerColor, MessengerSize, _default$b as Page, _default$d as Parser, _default$2 as SendToMessenger, ShareButton, useFacebook, useLogin, useLoginStatus, useProfile, useShare, useSubscribe };
export { ColorScheme, _default$a as Comments, _default$9 as CommentsCount, CommentsOrderBy, _default$5 as CustomChat, _default$c as EmbeddedPost, _default$b as EmbeddedVideo, _default$1 as FacebookContext, FacebookProvider, _default as Fields, _default$8 as Group, _default$e as Like, LikeAction, LikeLayout, LikeSize, LoginButton, LoginStatus, _default$4 as MessageUs, _default$3 as MessengerCheckbox, MessengerColor, MessengerSize, _default$d as Page, _default$f as Parser, _default$7 as Save, _default$2 as SendToMessenger, _default$6 as Share, ShareButton, useFacebook, useLogin, useLoginStatus, useProfile, useShare, useSubscribe };
{
"name": "react-facebook",
"version": "9.0.8",
"version": "9.0.9",
"description": "Facebook components like a Login button, Like, Share, Comments, Embedded Post/Video, Messenger Chat and others",

@@ -58,3 +58,3 @@ "author": {

"scripts": {
"build": "rollup -c",
"build": "rollup -c --bundleConfigAsCjs",
"test": "cypress open",

@@ -65,13 +65,14 @@ "size": "size-limit",

"dependencies": {
"@babel/runtime": "^7.19.0"
"@babel/runtime": "^7.20.6"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^14.1.0",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-typescript": "^8.5.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-commonjs": "^23.0.3",
"@rollup/plugin-terser": "^0.1.0",
"@rollup/plugin-typescript": "^10.0.1",
"@size-limit/preset-small-lib": "^8.1.0",
"@types/react": "^18.0.21",
"@vitejs/plugin-react": "^2.1.0",
"@types/react": "^18.0.26",
"@vitejs/plugin-react": "^2.2.0",
"cross-env": "^7.0.3",
"cypress": "^10.9.0",
"cypress": "^11.2.0",
"cypress-iframe": "^1.0.1",

@@ -81,9 +82,8 @@ "react": "^18.2.0",

"react-test-renderer": "^18.2.0",
"rollup": "^2.79.1",
"rollup-plugin-dts": "^4.2.2",
"rollup": "^3.5.1",
"rollup-plugin-dts": "^5.0.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-terser": "^7.0.2",
"size-limit": "^8.1.0",
"typescript": "^4.8.4",
"vite": "^3.1.3"
"typescript": "~4.8.4",
"vite": "^3.2.4"
},

@@ -90,0 +90,0 @@ "peerDependencies": {

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
import terser from '@rollup/plugin-terser';
import external from 'rollup-plugin-peer-deps-external';

@@ -31,11 +31,11 @@ import dts from 'rollup-plugin-dts';

typescript({ tsconfig: './tsconfig.json' }),
terser()
// terser()
],
},
{
input: 'dist/esm/index.d.ts',
input: 'dist/esm/types/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: "esm" }],
external: [/\.css$/],
plugins: [dts()],
plugins: [dts.default()],
},
];

@@ -14,2 +14,4 @@ export { default as FacebookProvider } from './FacebookProvider';

export { default as Save } from './Save';
export { default as Share } from './Share';
export { default as CustomChat } from './CustomChat';

@@ -16,0 +18,0 @@ export { default as MessageUs } from './MessageUs';

@@ -34,3 +34,3 @@ import { useState } from 'react';

}
return api.ui(clearUndefinedProperties({

@@ -37,0 +37,0 @@ method: 'share',

@@ -62,6 +62,6 @@ import LoginStatus from '../constants/LoginStatus';

domain: 'connect.facebook.net',
version: 'v14.0',
version: 'v15.0',
cookie: false,
status: false,
xfbml: false,
xfbml: true,
language: 'en_US',

@@ -130,3 +130,3 @@ frictionlessRequests: false,

if (window.document.getElementById('facebook-jssdk')) {
return resolve(window.FB);
return resolve(this);
}

@@ -148,4 +148,6 @@

async process<Response>(namespace: Namespace, before: any[] = [], after: any[] = []): Promise<Response> {
const fb = await this.init();
await this.init();
const fb = this.getFB();
return new Promise((resolve, reject) => {

@@ -157,3 +159,3 @@ // @ts-ignore

reject(new Error('Response is undefined'));
} else if ('error' in response) {
} else if (!!response && 'error' in response) {
const { code, type, message } = response.error;

@@ -160,0 +162,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc