@atlas-kitchen/adyen-web
Version:
3 lines (2 loc) • 2.84 kB
JavaScript
import{render as t}from"../../../external/preact/dist/preact.js";import e from"../../../utils/getProp.js";import o from"../../../utils/uuid.js";import s from"../../../core/Errors/AdyenCheckoutError.js";import{NO_CHECKOUT_ATTEMPT_ID as r,ANALYTICS_RENDERED_STR as n}from"../../../core/Analytics/constants.js";import{on as i,off as a}from"../../../utils/listenerUtils.js";import{AnalyticsInfoEvent as h}from"../../../core/Analytics/AnalyticsInfoEvent.js";function p(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}class c{buildElementProps(t){this.props=this.formatProps({...this.constructor.defaultProps,...t})}formatProps(t){return t}formatData(){return{}}setUpAnalytics(t){return null}submitAnalytics(t){return null}handleKeyPress(t){return null}setState(t){this.state={...this.state,...t}}get data(){const t=e(this.props,"modules.risk.data"),o=e(this.props,"modules.analytics.getCheckoutAttemptId")?.()??r,s=this.state.order||this.props.order,n=this.formatData();return n.paymentMethod&&o&&(n.paymentMethod.checkoutAttemptId=o),{...t&&{riskData:{clientData:t}},...s&&{order:{orderData:s.orderData,pspReference:s.pspReference}},...n,clientStateDataIndicator:!0}}activate(){}render(){throw new Error("Payment method cannot be rendered.")}mount(e){const o="string"==typeof e?document.querySelector(e):e;if(!o)throw new Error("Component could not mount. Root node was not found.");const s=!this._node;return this._node&&this.unmount(),this._node=o,i(this._node,"keypress",this.handleKeyPress,!1),this._component=this.render(),t(this._component,o),s&&this.props.modules&&this.props.modules.analytics&&this.setUpAnalytics({containerWidth:o&&o.offsetWidth,component:this.props.isDropin?"dropin":this.constructor.analyticsType??this.constructor.type,flavor:this.props.isDropin?"dropin":"components"}).then((()=>{if(!this.props.isDropin){const t=new h({type:n});this.submitAnalytics(t)}})),this}update(t){return this.props=this.formatProps({...this.props,...t}),this.state={},this.unmount().mount(this._node)}unmount(){return a(this._node,"keypress",this.handleKeyPress),this._node&&t(null,this._node),this}remove(){this.unmount(),this.core&&this.core.remove(this)}constructor(t,e){p(this,"_id",`${this.constructor.type}-${o()}`),p(this,"core",void 0),p(this,"props",void 0),p(this,"state",{}),p(this,"_component",void 0),p(this,"_node",null);const r=function(t){return!!t&&("function"==typeof t.initialize&&"function"==typeof t.createFromAction)}(t);if(!r)throw new s("IMPLEMENTATION_ERROR",`Trying to initialise the component '${this.constructor.type}' without a reference to an instance of AdyenCheckout`);this.core=t,this.buildElementProps(e),this.handleKeyPress=this.handleKeyPress.bind(this)}}p(c,"defaultProps",{});export{c as default};
//# sourceMappingURL=BaseElement.js.map