FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-dashboard-downloads-list.js
import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{a as apiFetch}from"./fetch.js";import{o as onFirstVisible}from"./lazy.js";import{d as defineCustomElement$j}from"./sc-alert2.js";import{d as defineCustomElement$i}from"./sc-block-ui2.js";import{d as defineCustomElement$h}from"./sc-button2.js";import{d as defineCustomElement$g}from"./sc-card2.js";import{d as defineCustomElement$f}from"./sc-dashboard-module2.js";import{d as defineCustomElement$e}from"./sc-divider2.js";import{d as defineCustomElement$d}from"./sc-empty2.js";import{d as defineCustomElement$c}from"./sc-flex2.js";import{d as defineCustomElement$b}from"./sc-format-bytes2.js";import{d as defineCustomElement$a}from"./sc-icon2.js";import{d as defineCustomElement$9}from"./sc-pagination2.js";import{d as defineCustomElement$8}from"./sc-purchase-downloads-list2.js";import{d as defineCustomElement$7}from"./sc-skeleton2.js";import{d as defineCustomElement$6}from"./sc-spacing2.js";import{d as defineCustomElement$5}from"./sc-spinner2.js";import{d as defineCustomElement$4}from"./sc-stacked-list2.js";import{d as defineCustomElement$3}from"./sc-stacked-list-row2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";import{a as addQueryArgs}from"./add-query-args.js";const scDashboardDownloadsListCss=":host{display:block}.download__details{opacity:0.75}",ScDashboardDownloadsListStyle0=scDashboardDownloadsListCss,ScDownloadsList=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.query={page:1,per_page:10},this.allLink=void 0,this.heading=void 0,this.isCustomer=void 0,this.requestNonce=void 0,this.purchases=[],this.loading=void 0,this.busy=void 0,this.error=void 0,this.pagination={total:0,total_pages:0}}componentWillLoad(){onFirstVisible(this.el,(()=>{this.initialFetch()}))}async initialFetch(){if(this.isCustomer)try{this.loading=!0,await this.getItems()}catch(e){console.error(this.error),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}async fetchItems(){if(this.isCustomer)try{this.busy=!0,await this.getItems()}catch(e){console.error(this.error),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=!1}}async getItems(){const e=await await apiFetch({path:addQueryArgs("surecart/v1/purchases/",{expand:["product","product.downloads","download.media"],downloadable:!0,revoked:!1,...this.query}),parse:!1});return this.pagination={total:parseInt(e.headers.get("X-WP-Total")),total_pages:parseInt(e.headers.get("X-WP-TotalPages"))},this.purchases=await e.json(),this.purchases}nextPage(){this.query.page=this.query.page+1,this.fetchItems()}prevPage(){this.query.page=this.query.page-1,this.fetchItems()}render(){var e;return h("sc-purchase-downloads-list",{key:"c0dd0e760d5cf286e50a4e31e9dce207556da2b0",heading:this.heading,allLink:this.allLink&&this.pagination.total_pages>1?this.allLink:"",loading:this.loading,busy:this.busy,requestNonce:this.requestNonce,error:this.error,purchases:this.purchases},h("span",{key:"02b04ae7544a1ef891780953d8b07bb01acdd068",slot:"heading"},h("slot",{key:"03745b18a6a5f656d4d3eb268969ac08b42fdd99",name:"heading"},this.heading||wp.i18n.__("Downloads","surecart"))),h("sc-pagination",{key:"8ca0f52229ada26f1b3c495fb1a30cc0e9f1d54b",slot:"after",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:null===(e=null==this?void 0:this.purchases)||void 0===e?void 0:e.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}))}get el(){return this}static get style(){return ScDashboardDownloadsListStyle0}},[1,"sc-dashboard-downloads-list",{query:[1032],allLink:[1,"all-link"],heading:[1],isCustomer:[4,"is-customer"],requestNonce:[1,"request-nonce"],purchases:[32],loading:[32],busy:[32],error:[32],pagination:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-dashboard-downloads-list","sc-alert","sc-block-ui","sc-button","sc-card","sc-dashboard-module","sc-divider","sc-empty","sc-flex","sc-format-bytes","sc-icon","sc-pagination","sc-purchase-downloads-list","sc-skeleton","sc-spacing","sc-spinner","sc-stacked-list","sc-stacked-list-row","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-dashboard-downloads-list":customElements.get(e)||customElements.define(e,ScDownloadsList);break;case"sc-alert":customElements.get(e)||defineCustomElement$j();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$i();break;case"sc-button":customElements.get(e)||defineCustomElement$h();break;case"sc-card":customElements.get(e)||defineCustomElement$g();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$f();break;case"sc-divider":customElements.get(e)||defineCustomElement$e();break;case"sc-empty":customElements.get(e)||defineCustomElement$d();break;case"sc-flex":customElements.get(e)||defineCustomElement$c();break;case"sc-format-bytes":customElements.get(e)||defineCustomElement$b();break;case"sc-icon":customElements.get(e)||defineCustomElement$a();break;case"sc-pagination":customElements.get(e)||defineCustomElement$9();break;case"sc-purchase-downloads-list":customElements.get(e)||defineCustomElement$8();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$7();break;case"sc-spacing":customElements.get(e)||defineCustomElement$6();break;case"sc-spinner":customElements.get(e)||defineCustomElement$5();break;case"sc-stacked-list":customElements.get(e)||defineCustomElement$4();break;case"sc-stacked-list-row":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}const ScDashboardDownloadsList=ScDownloadsList,defineCustomElement=defineCustomElement$1;export{ScDashboardDownloadsList,defineCustomElement};
Save
Back