@digital-blueprint/sublibrary-app
Version:
[GitHub Repository](https://github.com/digital-blueprint/sublibrary-app) | [npmjs package](https://www.npmjs.com/package/@digital-blueprint/sublibrary-app) | [Unpkg CDN](https://unpkg.com/browse/@digital-blueprint/sublibrary-app/) | [Sublibrary Bundle](ht
108 lines (101 loc) • 15.1 kB
JavaScript
let e=e=>e,t,n;function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?r(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function a(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e){var t=s(e,`string`);return typeof t==`symbol`?t:t+``}function s(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@ must return a primitive value.`)}return(t===`string`?String:Number)(e)}
/*!
* License: LGPL-2.1-or-later
* Dependencies:
*
* @webcomponents/scoped-custom-element-registry: BSD-3-Clause
* @dbp-toolkit/app-shell: LGPL-2.1-or-later
* @dbp-toolkit/language-select: LGPL-2.1-or-later
* @dbp-toolkit/auth: LGPL-2.1-or-later
* lit-html: BSD-3-Clause
* @dbp-toolkit/notification: LGPL-2.1-or-later
* @dbp-toolkit/theme-switcher: LGPL-2.1-or-later
* universal-router: MIT
* @dbp-toolkit/matomo: LGPL-2.1-or-later
* xtend: MIT
* fuzzy: (MIT)
* suggestions: ISC
*/
import{a as c,d as l,i as u,l as d,s as f,t as p}from"./shared/library-select.BChQfqNA.js";import{B as m,D as h,E as g,M as _,N as v,S as y,T as b,V as x,_ as S,b as C,d as w,t as T}from"./shared/styles.D8JNhv4k.js";import{t as E}from"./shared/library-book-offer-select.p6M2VRoA.js";import{t as D}from"./shared/reload-button.CTl4Zz6a.js";var O=d((e,t)=>{t.exports=r;var n=Object.prototype.hasOwnProperty;function r(){for(var e={},t=0;t<arguments.length;t++){var r=arguments[t];for(var i in r)n.call(r,i)&&(e[i]=r[i])}return e}}),k=d((e,t)=>{(function(){var n=this,r={};e===void 0?n.fuzzy=r:t.exports=r,r.simpleFilter=function(e,t){return t.filter(function(t){return r.test(e,t)})},r.test=function(e,t){return r.match(e,t)!==null},r.match=function(e,t,n){n||={};var r=0,i=[],a=t.length,o=0,s=0,c=n.pre||``,l=n.post||``,u=n.caseSensitive&&t||t.toLowerCase(),d;e=n.caseSensitive&&e||e.toLowerCase();for(var f=0;f<a;f++)d=t[f],u[f]===e[r]?(d=c+d+l,r+=1,s+=1+s):s=0,o+=s,i[i.length]=d;return r===e.length?(o=u===e?1/0:o,{rendered:i.join(``),score:o}):null},r.filter=function(e,t,n){return!t||t.length===0?[]:typeof e==`string`?(n||={},t.reduce(function(t,i,a,o){var s=i;n.extract&&(s=n.extract(i));var c=r.match(e,s,n);return c!=null&&(t[t.length]={string:c.rendered,score:c.score,index:a,original:i}),t},[]).sort(function(e,t){return t.score-e.score||e.index-t.index})):t}})()}),A=d((e,t)=>{var n=function(e){return this.component=e,this.items=[],this.active=0,this.wrapper=document.createElement(`div`),this.wrapper.className=`suggestions-wrapper`,this.element=document.createElement(`ul`),this.element.className=`suggestions`,this.wrapper.appendChild(this.element),this.selectingListItem=!1,e.el.parentNode.insertBefore(this.wrapper,e.el.nextSibling),this};n.prototype.show=function(){this.element.style.display=`block`},n.prototype.hide=function(){this.element.style.display=`none`},n.prototype.add=function(e){this.items.push(e)},n.prototype.clear=function(){this.items=[],this.active=0},n.prototype.isEmpty=function(){return!this.items.length},n.prototype.isVisible=function(){return this.element.style.display===`block`},n.prototype.draw=function(){if(this.element.innerHTML=``,this.items.length===0){this.hide();return}for(var e=0;e<this.items.length;e++)this.drawItem(this.items[e],this.active===e);this.show()},n.prototype.drawItem=function(e,t){var n=document.createElement(`li`),r=document.createElement(`a`);t&&(n.className+=` active`),r.innerHTML=e.string,n.appendChild(r),this.element.appendChild(n),n.addEventListener(`mousedown`,function(){this.selectingListItem=!0}.bind(this)),n.addEventListener(`mouseup`,function(){this.handleMouseUp.call(this,e)}.bind(this))},n.prototype.handleMouseUp=function(e){this.selectingListItem=!1,this.component.value(e.original),this.clear(),this.draw()},n.prototype.move=function(e){this.active=e,this.draw()},n.prototype.previous=function(){this.move(this.active===0?this.items.length-1:this.active-1)},n.prototype.next=function(){this.move(this.active===this.items.length-1?0:this.active+1)},n.prototype.drawError=function(e){var t=document.createElement(`li`);t.innerHTML=e,this.element.appendChild(t),this.show()},t.exports=n}),j=d((e,t)=>{var n=O(),r=k(),i=A(),a=function(e,t,r){return r||={},this.options=n({minLength:2,limit:5,filter:!0,hideOnBlur:!0},r),this.el=e,this.data=t||[],this.list=new i(this),this.query=``,this.selected=null,this.list.draw(),this.el.addEventListener(`keyup`,function(e){this.handleKeyUp(e.keyCode)}.bind(this),!1),this.el.addEventListener(`keydown`,function(e){this.handleKeyDown(e)}.bind(this)),this.el.addEventListener(`focus`,function(){this.handleFocus()}.bind(this)),this.el.addEventListener(`blur`,function(){this.handleBlur()}.bind(this)),this.el.addEventListener(`paste`,function(e){this.handlePaste(e)}.bind(this)),this.render=this.options.render?this.options.render.bind(this):this.render.bind(this),this.getItemValue=this.options.getItemValue?this.options.getItemValue.bind(this):this.getItemValue.bind(this),this};a.prototype.handleKeyUp=function(e){e===40||e===38||e===27||e===13||e===9||this.handleInputChange(this.el.value)},a.prototype.handleKeyDown=function(e){switch(e.keyCode){case 13:case 9:this.list.isEmpty()||(this.list.isVisible()&&e.preventDefault(),this.value(this.list.items[this.list.active].original),this.list.hide());break;case 27:this.list.isEmpty()||this.list.hide();break;case 38:this.list.previous();break;case 40:this.list.next();break}},a.prototype.handleBlur=function(){!this.list.selectingListItem&&this.options.hideOnBlur&&this.list.hide()},a.prototype.handlePaste=function(e){if(e.clipboardData)this.handleInputChange(e.clipboardData.getData(`Text`));else{var t=this;setTimeout(function(){t.handleInputChange(e.target.value)},100)}},a.prototype.handleInputChange=function(e){if(this.query=this.normalize(e),this.list.clear(),this.query.length<this.options.minLength){this.list.draw();return}this.getCandidates(function(e){for(var t=0;t<e.length&&(this.list.add(e[t]),t!==this.options.limit-1);t++);this.list.draw()}.bind(this))},a.prototype.handleFocus=function(){this.list.isEmpty()||this.list.show(),this.list.selectingListItem=!1},a.prototype.update=function(e){this.data=e,this.handleKeyUp()},a.prototype.clear=function(){this.data=[],this.list.clear()},a.prototype.normalize=function(e){return e=e.toLowerCase(),e},a.prototype.match=function(e,t){return e.indexOf(t)>-1},a.prototype.value=function(e){if(this.selected=e,this.el.value=this.getItemValue(e),document.createEvent){var t=document.createEvent(`HTMLEvents`);t.initEvent(`change`,!0,!1),this.el.dispatchEvent(t)}else this.el.fireEvent(`onchange`)},a.prototype.getCandidates=function(e){var t={pre:`<strong>`,post:`</strong>`,extract:function(e){return this.getItemValue(e)}.bind(this)},n;this.options.filter?(n=r.filter(this.query,this.data,t),n=n.map(function(e){return{original:e.original,string:this.render(e.original,e.string)}}.bind(this))):n=this.data.map(function(e){return{original:e,string:this.render(e)}}.bind(this)),e(n)},a.prototype.getItemValue=function(e){return e},a.prototype.render=function(e,t){if(t)return t;for(var n=e.original?this.getItemValue(e.original):this.getItemValue(e),r=this.normalize(n),i=r.lastIndexOf(this.query);i>-1;){var a=i+this.query.length;n=n.slice(0,i)+`<strong>`+n.slice(i,a)+`</strong>`+n.slice(a),i=r.slice(0,i).lastIndexOf(this.query)}return n},a.prototype.renderError=function(e){this.list.drawError(e)},t.exports=a}),M=l(d((e,t)=>{var n=j();t.exports=n,typeof window<`u`&&(window.Suggestions=n)})(),1),N=l(u(),1),P=`shared/suggestions.668c8aad3ba887d2.css`;_(`dbp-sublibrary-shelving`,class extends g(c){constructor(){super(),this.auth={},this._i18n=f(),this.lang=this._i18n.language,this.entryPointUrl=``,this.bookOfferId=``,this.bookOffer=null,this.sublibraryIri=``,this.sublibrary=null}static get scopedElements(){return{"dbp-library-select":p,"dbp-sublibrary-book-offer-select":E,"dbp-button":S,"dbp-mini-spinner":h,"dbp-reload-button":D}}static get properties(){return i(i({},super.properties),{},{lang:{type:String},entryPointUrl:{type:String,attribute:`entry-point-url`},bookOfferId:{type:String,attribute:`book-offer-id`,reflect:!0},bookOffer:{type:Object,attribute:!1},sublibraryIri:{type:String,attribute:`sublibrary-iri`,reflect:!0},auth:{type:Object}})}getSublibraryCode(){return this.sublibrary.code}$(e){return(0,N.default)(this._(e))}connectedCallback(){super.connectedCallback();let e=this,t=this._i18n;this.updateComplete.then(()=>{let n=e.$(`dbp-sublibrary-book-offer-select`),r=e.$(`#location-identifier`),i=e._(`#location-identifier`),a=e.$(`#location-identifier-block`);n.change(function(){console.log(`change`),console.log(n.val()),console.log(n.attr(`value`)),console.log(n.prop(`value`)),e.bookOffer=(0,N.default)(this).data(`object`),e.bookOfferId=e.bookOffer[``],r.val(e.bookOffer.locationIdentifier).trigger(`input`),a.show();let t=e.entryPointUrl+e.bookOfferId+`/location-identifiers`;e.setAttribute(`book-offer-id`,e.bookOfferId),e.dispatchEvent(new CustomEvent(`change`,{detail:{type:`book-offer-id`,value:e.bookOfferId}})),fetch(t,{headers:{"Content-Type":`application/ld+json`,Authorization:`Bearer `+e.auth.token}}).then(e=>e.json()).then(e=>{new M.default(i,e[`hydra:member`].map(e=>e.identifier))})}).on(`unselect`,function(t){console.log(`unselect`),e.bookOffer=null,e.bookOfferId=``,(0,N.default)(e).attr(`book-offer-id`,null),a.hide()}),r.on(`input`,function(){e.$(`#send`).prop(`disabled`,(0,N.default)(this).val()===``)}),e.$(`#send`).click(i=>{i.preventDefault(),console.log(`send`);let a=e.entryPointUrl+n.val()+`?library=`+e.getSublibraryCode();console.log(a),console.log(r);let o={locationIdentifier:r.val()};console.log(o),console.log(JSON.stringify(o)),N.default.ajax({url:a,type:`PATCH`,contentType:`application/merge-patch+json`,beforeSend:function(t){t.setRequestHeader(`Authorization`,`Bearer `+e.auth.token)},data:JSON.stringify(o),success:function(r){T({summary:t.t(`success-summary`),body:t.t(`success-body`,{name:e.bookOffer.name||``}),type:`success`,timeout:5}),n[0].clear()},error:(t,n,r)=>{e.handleXhrError(t,n,r)},complete:function(t,n,r){e._(`#send`).stop()}})})})}update(e){e.forEach((e,t)=>{t===`lang`&&this._i18n.changeLanguage(this.lang)}),super.update(e)}onLanguageChanged(e){this.lang=e.detail.lang}static get styles(){return x(t||=e`
${0}
${0}
${0}
.hidden {
display: none;
}
#location-identifier-block {
display: none;
}
#location-identifier-block input {
width: 100%;
border-radius: var(--dbp-border-radius);
}
dbp-sublibrary-book-offer-select {
width: 100%;
margin-right: 4px;
}
.book-offer-select-container {
display: flex;
}
`,b(),C(),y())}onSublibraryChanged(e){this.sublibraryIri=e.detail.value,this.sublibrary=e.detail.object}onReloadButtonClicked(e){this.$(`dbp-sublibrary-book-offer-select`).trigger(`change`)}_onLoginClicked(e){this.sendSetPropertyEvent(`requested-login-status`,`logged-in`),e.preventDefault()}render(){let t=v(P),r=this._i18n;return m(n||=e`
<link rel="stylesheet" href="${0}" />
<form
class="${0}">
<div class="field">
<label class="label">${0}</label>
<div class="control">
<dbp-library-select
subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth"
value="${0}"
="${0}"></dbp-library-select>
</div>
</div>
<div class="field">
<label class="label">${0}</label>
<div class="control book-offer-select-container">
<dbp-sublibrary-book-offer-select
subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth"
value="${0}"
sublibrary-iri="${0}"></dbp-sublibrary-book-offer-select>
<dbp-reload-button
?disabled=${0}
=${0}
title="${0}"></dbp-reload-button>
</div>
</div>
<div id="location-identifier-block">
<div class="field">
<label class="label">${0}</label>
<div class="control">
<input
class="input"
id="location-identifier"
type="text"
placeholder="${0}" />
</div>
</div>
<div class="field">
<div class="control">
<dbp-button
id="send"
disabled="disabled"
value="${0}"
type=""></dbp-button>
</div>
</div>
</div>
</form>
<div
class="notification is-warning ${0}">
${0}
<a href="#" ="${0}">${0}</a>
</div>
<div
class="notification is-danger ${0}">
${0}
</div>
<div class="${0}">
<dbp-mini-spinner></dbp-mini-spinner>
</div>
`,t,w({hidden:!this.isLoggedIn()||!this.hasLibraryPermissions()||this.isLoading()}),r.t(`organization-select.label`),this.sublibraryIri,this.onSublibraryChanged,r.t(`library-book-offer-select.headline`),this.bookOfferId,this.sublibraryIri,!this.bookOffer,this.onReloadButtonClicked,this.bookOffer?r.t(`shelving.button-refresh-title`,{name:this.bookOffer.name}):``,r.t(`location-identifier.headline`),r.t(`location-identifier.placeholder`),r.t(`location-identifier.submit`),w({hidden:this.isLoggedIn()||this.isLoading()}),r.t(`error-login-message`),this._onLoginClicked,r.t(`error-login-link`),w({hidden:this.hasLibraryPermissions()||!this.isLoggedIn()||this.isLoading()}),r.t(`error-permission-message`),w({hidden:!this.isLoading()}))}});
//# sourceMappingURL=dbp-sublibrary-shelving.js.map