UNPKG

@mornya/react-social-libs

Version:

The project of React.js Social Share and Widget modules.

89 lines (88 loc) 3.87 kB
var __extends = (this && this.__extends) || (function () { 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); }; return function (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 = (this && this.__assign) || function () { __assign = Object.assign || function(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); }; import React from 'react'; import BaseComponent from './BaseComponent'; var BaseWidgetComponent = (function (_super) { __extends(BaseWidgetComponent, _super); function BaseWidgetComponent(props) { var _this = _super.call(this, props) || this; _this.state = { OG: undefined, extra: undefined, apiStep: 0, }; _this.widgetId = ''; _this.initialize = _this.initialize.bind(_this); _this.getApiStep = _this.getApiStep.bind(_this); _this.setApiStep = _this.setApiStep.bind(_this); _this.onInit = _this.onInit.bind(_this); _this.onMount = _this.onMount.bind(_this); _this.onRender = _this.onRender.bind(_this); _this.onUnmount = _this.onUnmount.bind(_this); _this.id = "widget-".concat(_super.prototype.getUID.call(_this)).concat(_super.prototype.getUID.call(_this)); _this.defaultExtra = {}; _this.onInit(); return _this; } BaseWidgetComponent.prototype.componentDidMount = function () { var _this = this; var _a; var OG = this.getDefaultMetaContent(); var extra = __assign(__assign({}, this.defaultExtra), this.props.extra); if (!((_a = extra.hashtags) === null || _a === void 0 ? void 0 : _a.length)) { extra.hashtags = this.getDefaultHashtags(OG.keywords); } this.setState({ OG: OG, extra: extra }, function () { return _this.onMount(extra); }); }; BaseWidgetComponent.prototype.componentWillUnmount = function () { this.onUnmount(this.state.extra); }; BaseWidgetComponent.prototype.initialize = function (widgetId, defaultExtra) { this.widgetId = widgetId.toLowerCase(); this.defaultExtra = defaultExtra; }; BaseWidgetComponent.prototype.getApiStep = function () { return this.state.apiStep; }; BaseWidgetComponent.prototype.setApiStep = function (callback) { this.setState({ apiStep: this.state.apiStep + 1 }, callback); }; BaseWidgetComponent.prototype.onInit = function () { }; BaseWidgetComponent.prototype.onRender = function (_extra, _OG) { return null; }; BaseWidgetComponent.prototype.onMount = function (_extra) { }; BaseWidgetComponent.prototype.onUnmount = function (_extra) { }; BaseWidgetComponent.prototype.render = function () { if (!this.state.extra || !this.state.OG) { return null; } return (React.createElement("div", { className: "mornya-lib sns-widget ".concat(this.widgetId) }, this.onRender(this.state.extra, this.state.OG))); }; return BaseWidgetComponent; }(BaseComponent)); export { BaseWidgetComponent };