UNPKG

16.4 kBJavaScriptView Raw
1"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react"));function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),o.forEach(function(t){_defineProperty(e,t,n[t])})}return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}var VKContext=React.createContext(),VKApi=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,e),this.apiId=t,this.options=n,this.promise=null,this.init()}return _createClass(e,[{key:"init",value:function(){var e=this.apiId,t=this.options,n=t.version,o=t.onlyWidgets;return this.promise?this.promise:(this.promise=new Promise(function(t){var r="https://vk.com/js/api/openapi.js?".concat(n);if(window.vkAsyncInit=function(){e&&window.VK.init({apiId:e,onlyWidgets:o}),t(window.VK)},!document.getElementById("vk-openapi")){var i=document.createElement("script");i.type="text/javascript",i.id="vk-openapi",i.src=r,i.async=!0,document.head.appendChild(i)}}),this.promise)}}]),e}(),VKInstance=null,VK=function(e){function t(){var e,n;_classCallCheck(this,t);for(var o=arguments.length,r=new Array(o),i=0;i<o;i++)r[i]=arguments[i];return _defineProperty(_assertThisInitialized(_assertThisInitialized(n=_possibleConstructorReturn(this,(e=_getPrototypeOf(t)).call.apply(e,[this].concat(r))))),"_mounted",!0),_defineProperty(_assertThisInitialized(_assertThisInitialized(n)),"state",{vk:null}),n}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){var e=this,t=this.props,n=t.onApiAvailable,o=t.apiId;"undefined"!=typeof window&&window.document&&window.document.createElement&&this.VKinit().then(function(t){n(t),o&&t.init({apiId:o}),e._mounted&&e.setState({vk:t})})}},{key:"componentWillUnmount",value:function(){this._mounted=!1}},{key:"VKinit",value:function(){var e=this.props,t=e.apiId,n=e.options;return this.vk||(this.vk=VKInstance||new VKApi(t,n),VKInstance=this.vk),this.vk.init()}},{key:"render",value:function(){var e=this.state.vk,t=this.props.children;return e?React.createElement(VKContext.Provider,{value:{vk:e}},t):null}}]),t}();_defineProperty(VK,"defaultProps",{apiId:null,options:{version:160,onlyWidgets:!0},onApiAvailable:function(){}});var AllowMessagesFromCommunity=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"componentWillUnmount",value:function(){this.context.vk.Observer.unsubscribe("widgets.allowMessagesFromCommunity.allowed")}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=t.groupId,i=t.onAllow,s=t.onDeny;e.Widgets.AllowMessagesFromCommunity(n,o,r),e.Observer.subscribe("widgets.allowMessagesFromCommunity.allowed",function(e){return i(e)}),e.Observer.subscribe("widgets.allowMessagesFromCommunity.denied",function(e){return s(e)})}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(AllowMessagesFromCommunity,"contextType",VKContext),_defineProperty(AllowMessagesFromCommunity,"defaultProps",{elementId:"vk_send_message",options:{height:24},onAllow:function(){},onDeny:function(){}});var Application=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.appId,r=t.options;e.Widgets.App(n,o,r)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Application,"contextType",VKContext),_defineProperty(Application,"defaultProps",{elementId:"vk_app",options:{mode:1}});var Auth=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=_objectSpread({},o);r.onAuth=function(e,t,n,r,i,s){return o.onAuth(e,t,n,r,i,s)},e.Widgets.Auth(n,r)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Auth,"contextType",VKContext),_defineProperty(Auth,"defaultProps",{elementId:"vk_auth",options:{width:300,onAuth:function(){}}});var Comments=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"componentWillUnmount",value:function(){var e=this.context.vk;e.Observer.unsubscribe("widgets.comments.new_comment"),e.Observer.unsubscribe("widgets.comments.delete_comment")}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=t.pageId,i=t.onNewComment,s=t.onDeleteComment;e.Widgets.Comments(n,o,r),e.Observer.subscribe("widgets.comments.new_comment",function(e,t,n,o){return i(e,t,n,o)}),e.Observer.subscribe("widgets.comments.delete_comment",s)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Comments,"contextType",VKContext),_defineProperty(Comments,"defaultProps",{elementId:"vk_comments",options:{height:0,limit:10,attach:"*",autoPublish:0,mini:"auto",norealtime:0},pageId:null,onNewComment:function(){},onDeleteComment:function(){}});var CommentsBrowse=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options;e.Widgets.CommentsBrowse(n,o)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(CommentsBrowse,"contextType",VKContext),_defineProperty(CommentsBrowse,"defaultProps",{elementId:"vk_comments_browse",options:{height:0,limit:10,mini:"auto",norealtime:0}});var CommunityMessages=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.groupId,r=t.options;(0,t.onMount)(e.Widgets.CommunityMessages(n,o,r),n)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(CommunityMessages,"contextType",VKContext),_defineProperty(CommunityMessages,"defaultProps",{elementId:"vk_community_messages",options:{onCanNotWrite:function(){},welcomeScreen:1,expandTimeout:0,expanded:0,widgetPosition:"right",buttonType:"blue_circle",disableButtonTooltip:0},onMount:function(){}});var ContactUs=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=t.ownerId;e.Widgets.ContactUs(n,o,-r)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(ContactUs,"contextType",VKContext),_defineProperty(ContactUs,"defaultProps",{elementId:"vk_contact_us",options:{height:24}});var Group=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"componentWillUnmount",value:function(){var e=this.context.vk;e.Observer.unsubscribe("widgets.groups.joined"),e.Observer.unsubscribe("widgets.groups.leaved")}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=t.groupId,i=t.onJoin,s=t.onLeave;e.Widgets.Group(n,o,r),e.Observer.subscribe("widgets.groups.joined",i),e.Observer.subscribe("widgets.groups.leaved",s)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Group,"contextType",VKContext),_defineProperty(Group,"defaultProps",{elementId:"vk_groups",options:{width:"auto",mode:3,no_cover:1,wide:1},onJoin:function(){},onLeave:function(){}});var Like=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"componentWillUnmount",value:function(){var e=this.context.vk;e.Observer.unsubscribe("widgets.like.liked"),e.Observer.unsubscribe("widgets.like.unliked"),e.Observer.unsubscribe("widgets.like.shared"),e.Observer.unsubscribe("widgets.like.unshared")}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=t.pageId,i=t.onLike,s=t.onUnlike,u=t.onShare,c=t.onUnshare;r?e.Widgets.Like(n,o,r):e.Widgets.Like(n,o),e.Observer.subscribe("widgets.like.liked",function(e){return i(e)}),e.Observer.subscribe("widgets.like.unliked",function(e){return s(e)}),e.Observer.subscribe("widgets.like.shared",function(e){return u(e)}),e.Observer.subscribe("widgets.like.unshared",function(e){return c(e)})}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Like,"contextType",VKContext),_defineProperty(Like,"defaultProps",{elementId:"vk_like",options:{type:"full",width:350,height:22,verb:0},pageId:null,onLike:function(){},onUnlike:function(){},onShare:function(){},onUnshare:function(){}});var Playlist=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.ownerId,r=t.playlistId,i=t.hash,s=t.options;e.Widgets.Playlist(n,-o,r,i,s)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Playlist,"contextType",VKContext),_defineProperty(Playlist,"defaultProps",{elementId:"vk_playlist",options:{}});var Poll=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=t.pollId;e.Widgets.Poll(n,o,r)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Poll,"contextType",VKContext),_defineProperty(Poll,"defaultProps",{elementId:"vk_poll",options:{height:24}});var Post=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.ownerId,r=t.postId,i=t.hash,s=t.options;e.Widgets.Post(n,o,r,i,s)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Post,"contextType",VKContext),_defineProperty(Post,"defaultProps",{elementId:"vk_post",options:{}});var Recommended=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options;e.Widgets.Recommended(n,o)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Recommended,"contextType",VKContext),_defineProperty(Recommended,"defaultProps",{elementId:"vk_recommend",options:{limit:5,max:20,period:"week",sort:"friend_like",target:"parent"}});var Subscribe=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"componentWillUnmount",value:function(){var e=this.context.vk;e.Observer.unsubscribe("widgets.subscribed"),e.Observer.unsubscribe("widgets.unsubscribed")}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.options,r=t.ownerId,i=t.onSubscribe,s=t.onUnsubscribe;e.Widgets.Subscribe(n,o,r),e.Observer.subscribe("widgets.subscribed",i),e.Observer.subscribe("widgets.unsubscribed",s)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Subscribe,"contextType",VKContext),_defineProperty(Subscribe,"defaultProps",{elementId:"vk_subscribe",options:{mode:0,soft:0},onSubscribe:function(){},onUnsubscribe:function(){}});var Post$1=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,_getPrototypeOf(t).apply(this,arguments))}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.mount()}},{key:"mount",value:function(){var e=this.context.vk,t=this.props,n=t.elementId,o=t.articleUrl;e.Widgets.Article(n,o)}},{key:"render",value:function(){var e=this.props.elementId;return React.createElement("div",{id:e})}}]),t}();_defineProperty(Post$1,"contextType",VKContext),_defineProperty(Post$1,"defaultProps",{elementId:"vk_article"}),exports.default=VK,exports.AllowMessagesFromCommunity=AllowMessagesFromCommunity,exports.Application=Application,exports.Auth=Auth,exports.Comments=Comments,exports.CommentsBrowse=CommentsBrowse,exports.CommunityMessages=CommunityMessages,exports.ContactUs=ContactUs,exports.Group=Group,exports.Like=Like,exports.Playlist=Playlist,exports.Poll=Poll,exports.Post=Post,exports.Recommended=Recommended,exports.Subscribe=Subscribe,exports.Article=Post$1;
2//# sourceMappingURL=react-vk.cjs.production.min.js.map