@mornya/react-social-libs
Version:
The project of React.js Social Share and Widget modules.
1 lines • 5.24 kB
JavaScript
var n,e,t=this&&this.__extends||(n=function(t,e){return(n=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}))(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function __(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}),a=this&&this.__assign||function(){return(a=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},r=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseShareComponent=void 0,require("@mornya/platform-libs")),s=o(require("react")),o=o(require("./BaseComponent")),o=(e=o.default,t(BaseShareComponent,e),BaseShareComponent.getDerivedStateFromProps=function(t){t=null!=(t=t.defaultIconSize)?t:BaseShareComponent.defaultProps.defaultIconSize;return t<8?t=8:128<t&&(t=128),{defaultIconScale:t/128,defaultIconPos:(t-128)/2}},BaseShareComponent.prototype.componentDidMount=function(){var t,e=this,n=(this.deviceInfo=r.Platform.getInfo(window.navigator.userAgent),this.getDefaultMetaContent()),o=a(a({},this.defaultExtra),this.props.extra);null!=(t=o.hashtags)&&t.length||(o.hashtags=this.getDefaultHashtags(n.keywords)),this.setState({OG:n,extra:o},function(){return e.onMount(o)})},BaseShareComponent.prototype.componentDidUpdate=function(t,e){e.OG===this.state.OG&&t.extra===this.props.extra||this.onMount(this.state.extra)},BaseShareComponent.prototype.componentWillUnmount=function(){this.onUnmount(this.state.extra)},BaseShareComponent.prototype.initialize=function(t,e){this.shareName=t,this.shareId=t.toLowerCase(),this.defaultExtra=e},BaseShareComponent.prototype.getApiStep=function(){return this.state.apiStep},BaseShareComponent.prototype.setApiStep=function(t){this.setState({apiStep:this.state.apiStep+1},t)},BaseShareComponent.prototype.onInit=function(){},BaseShareComponent.prototype.onMount=function(t){},BaseShareComponent.prototype.onShare=function(t,e){},BaseShareComponent.prototype.onComplete=function(t,e){var n,o;this.setState({isRunning:!1}),null!=(o=(n=this.props).onComplete)&&o.call(n,t,e)},BaseShareComponent.prototype.onError=function(t){var e,n;this.onComplete(!1,null),null!=(n=(e=this.props).onError)&&n.call(e,{type:t,message:this.SHARE_ERRORS[t]})},BaseShareComponent.prototype.onClickShare=function(){var t,e,n=this;0<this.state.apiStep?this.state.isRunning?this.onError("SHARE_IN_PROGRESS"):!1!==(null==(e=(t=this.props).onBefore)?void 0:e.call(t))&&(this.setState({isRunning:!0}),setTimeout(function(){return n.setState({isRunning:!1})},2e3),this.onShare(this.state.extra,this.state.OG)):this.onError("SHARE_API_NOT_READY")},BaseShareComponent.prototype.onUnmount=function(t){},BaseShareComponent.prototype.render=function(){var t,e,n;return this.state.apiStep&&this.state.extra&&this.state.OG?(t=null!=(t=this.props.title)?t:"Share ".concat(this.shareName),e=["mornya-lib","sns-share",this.shareId,this.props.className].filter(Boolean).join(" "),n=this.props.style,this.props.children?s.default.createElement("button",{id:this.id,"aria-label":t,className:e,style:n,onClick:this.onClickShare},this.props.children):this.renderShareButton({id:this.id,label:t,className:e,style:n})):null},BaseShareComponent.defaultProps={defaultIconSize:24,onBefore:function(){},onComplete:function(){},onError:function(t){console.error(t.message)}},BaseShareComponent);function BaseShareComponent(t){var o=e.call(this,t)||this;return o.state={OG:void 0,extra:void 0,defaultIconScale:0,defaultIconPos:0,apiStep:0,isRunning:!1},o.shareId="",o.shareName="",o.SHARE_ERRORS={SHARE_IN_PROGRESS:"공유하기 진행 중 입니다. 잠시만 기다려주세요.",SHARE_API_NOT_READY:"공유하기 API가 아직 로딩되지 않았습니다. 잠시만 기다려주세요.",SHARE_SMS_ONLY_MOBILE:"문자메시지 공유는 모바일 환경에서만 가능합니다.",SHARE_CLIPBOARD_ERROR:"클립보드 복사가 실패했습니다."},o.renderShareButton=function(t){var e=t.id,n=t.label;return s.default.createElement("button",{id:e,"aria-label":n,className:t.className,style:t.style,onClick:o.onClickShare},s.default.createElement("span",{title:n,className:"share-default-button x128",style:{width:o.props.defaultIconSize,height:o.props.defaultIconSize}},s.default.createElement("span",{className:o.shareId,style:{transform:1<=o.state.defaultIconScale?void 0:"scale(".concat(o.state.defaultIconScale,")"),top:o.state.defaultIconPos,left:o.state.defaultIconPos}})))},o.initialize=o.initialize.bind(o),o.getApiStep=o.getApiStep.bind(o),o.setApiStep=o.setApiStep.bind(o),o.onInit=o.onInit.bind(o),o.onMount=o.onMount.bind(o),o.onShare=o.onShare.bind(o),o.onComplete=o.onComplete.bind(o),o.onError=o.onError.bind(o),o.onClickShare=o.onClickShare.bind(o),o.onUnmount=o.onUnmount.bind(o),o.id="share-".concat(e.prototype.getUID.call(o)).concat(e.prototype.getUID.call(o)),o.defaultExtra={},o.onInit(),o}exports.BaseShareComponent=o;