@fluid-topics/ft-search-context 1.0.61 → 1.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
`,r={setRequest:(t,s)=>{t.request=s.payload},setRequestQuery:(t,s)=>{t.request.query=s.payload},setRequestContentLocale:(t,s)=>{t.request.contentLocale=s.payload},setPageSize:(t,s)=>{t.request.paging.perPage=s.payload},setPageNumber:(t,s)=>{t.request.paging.page=s.payload},setRequestSort:(t,s)=>{t.request.sort=s.payload},setRequestFilters:(t,s)=>{t.request.filters=s.payload},setRequestFacets:(t,s)=>{t.request.facets=s.payload},setRequestVirtualField:(t,s)=>{t.request.virtualField=s.payload},setRequestScope:(t,s)=>{t.request.scope=s.payload},setResults:(t,s)=>{t.results=s.payload},setFacets:(t,s)=>{t.facets=s.payload},setSpellcheck:(t,s)=>{t.spellcheck=s.payload},setLocales:(t,s)=>{t.locales=s.payload},setPaging:(t,s)=>{t.paging=s.payload},setLiveQuery:(t,s)=>{t.liveQuery=s.payload},setSuggestResults:(t,s)=>{t.suggestResults=s.payload}};var o,a,h,c,u,l,f,d,v,w,y,E,S,b;!function(t){!function(s){var i={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(i.arrayBuffer)var e=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&e.indexOf(Object.prototype.toString.call(t))>-1};function r(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var s={next:function(){var s=t.shift();return{done:void 0===s,value:s}}};return i.iterable&&(s[Symbol.iterator]=function(){return s}),s}function h(t){this.map={},t instanceof h?t.forEach((function(t,s){this.append(s,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(s){this.append(s,t[s])}),this)}function c(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function u(t){return new Promise((function(s,i){t.onload=function(){s(t.result)},t.onerror=function(){i(t.error)}}))}function l(t){var s=new FileReader,i=u(s);return s.readAsArrayBuffer(t),i}function f(t){if(t.slice)return t.slice(0);var s=new Uint8Array(t.byteLength);return s.set(new Uint8Array(t)),s.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(t){var s;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():i.arrayBuffer&&i.blob&&((s=t)&&DataView.prototype.isPrototypeOf(s))?(this._bodyArrayBuffer=f(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=f(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i.blob&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(l)}),this.text=function(){var t,s,i,e=c(this);if(e)return e;if(this._bodyBlob)return t=this._bodyBlob,s=new FileReader,i=u(s),s.readAsText(t),i;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var s=new Uint8Array(t),i=new Array(s.length),e=0;e<s.length;e++)i[e]=String.fromCharCode(s[e]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i.formData&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,s){t=r(t),s=o(s);var i=this.map[t];this.map[t]=i?i+", "+s:s},h.prototype.delete=function(t){delete this.map[r(t)]},h.prototype.get=function(t){return t=r(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(r(t))},h.prototype.set=function(t,s){this.map[r(t)]=o(s)},h.prototype.forEach=function(t,s){for(var i in this.map)this.map.hasOwnProperty(i)&&t.call(s,this.map[i],i,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(s,i){t.push(i)})),a(t)},h.prototype.values=function(){var t=[];return this.forEach((function(s){t.push(s)})),a(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(s,i){t.push([i,s])})),a(t)},i.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,s){var i,e,n=(s=s||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,s.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=s.credentials||this.credentials||"same-origin",!s.headers&&this.headers||(this.headers=new h(s.headers)),this.method=(i=s.method||this.method||"GET",e=i.toUpperCase(),v.indexOf(e)>-1?e:i),this.mode=s.mode||this.mode||null,this.signal=s.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function y(t){var s=new FormData;return t.trim().split("&").forEach((function(t){if(t){var i=t.split("="),e=i.shift().replace(/\+/g," "),n=i.join("=").replace(/\+/g," ");s.append(decodeURIComponent(e),decodeURIComponent(n))}})),s}function E(t,s){s||(s={}),this.type="default",this.status=void 0===s.status?200:s.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in s?s.statusText:"OK",this.headers=new h(s.headers),this.url=s.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},d.call(w.prototype),d.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var S=[301,302,303,307,308];E.redirect=function(t,s){if(-1===S.indexOf(s))throw new RangeError("Invalid status code");return new E(null,{status:s,headers:{location:t}})},s.DOMException=t.DOMException;try{new s.DOMException}catch(t){s.DOMException=function(t,s){this.message=t,this.name=s;var i=Error(t);this.stack=i.stack},s.DOMException.prototype=Object.create(Error.prototype),s.DOMException.prototype.constructor=s.DOMException}function b(t,e){return new Promise((function(n,r){var o=new w(t,e);if(o.signal&&o.signal.aborted)return r(new s.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var t,s,i={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",s=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var i=t.split(":"),e=i.shift().trim();if(e){var n=i.join(":").trim();s.append(e,n)}})),s)};i.url="responseURL"in a?a.responseURL:i.headers.get("X-Request-URL");var e="response"in a?a.response:a.responseText;n(new E(e,i))},a.onerror=function(){r(new TypeError("Network request failed"))},a.ontimeout=function(){r(new TypeError("Network request failed"))},a.onabort=function(){r(new s.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&i.blob&&(a.responseType="blob"),o.headers.forEach((function(t,s){a.setRequestHeader(s,t)})),o.signal&&(o.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",c)}),a.send(void 0===o._bodyInit?null:o._bodyInit)}))}b.polyfill=!0,t.fetch||(t.fetch=b,t.Headers=h,t.Request=w,t.Response=E),s.Headers=h,s.Request=w,s.Response=E,s.fetch=b,Object.defineProperty(s,"t",{value:!0})}({})}("undefined"!=typeof self?self:void 0),function(t){t.black="black",t.green="green",t.blue="blue",t.purple="purple",t.red="red",t.orange="orange",t.yellow="yellow"}(o||(o={})),function(t){t.OFFICIAL="OFFICIAL",t.PERSONAL="PERSONAL",t.SHARED="SHARED"}(a||(a={})),function(t){t.THIRD_PARTY="THIRD_PARTY",t.OFF_THE_GRID="OFF_THE_GRID",t.CONTENT_PACKAGER="CONTENT_PACKAGER",t.PAGES="PAGES",t.DESIGNED_READER="DESIGNED_READER"}(h||(h={})),function(t){t.STARS="STARS",t.LIKE="LIKE",t.DICHOTOMOUS="DICHOTOMOUS",t.NO_RATING="NO_RATING"}(c||(c={})),function(t){t.LAST_WEEK="LAST_WEEK",t.LAST_MONTH="LAST_MONTH",t.LAST_YEAR="LAST_YEAR",t.CUSTOM="CUSTOM"}(u||(u={})),function(t){t.ASC="ASC",t.DESC="DESC"}(l||(l={})),function(t){t.ALPHA="ALPHA",t.NATURAL="NATURAL"}(f||(f={})),function(t){t.EVERYWHERE="EVERYWHERE",t.TITLE_ONLY="TITLE_ONLY",t.NONE="NONE"}(d||(d={})),function(t){t.ARTICLE="ARTICLE",t.BOOK="BOOK",t.SHARED_BOOK="SHARED_BOOK"}(v||(v={})),function(t){t.FLUIDTOPICS="FLUIDTOPICS",t.EXTERNAL="EXTERNAL"}(w||(w={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC",t.PERSONAL_BOOK="PERSONAL_BOOK",t.SHARED_BOOK="SHARED_BOOK"}(y||(y={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC"}(E||(E={})),function(t){t.DEFAULT="DEFAULT",t.DOCUMENTS="DOCUMENTS"}(S||(S={})),function(t){t.PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",t.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",t.HTML_EXPORT_USER="HTML_EXPORT_USER",t.PDF_EXPORT_USER="PDF_EXPORT_USER",t.SAVED_SEARCH_USER="SAVED_SEARCH_USER",t.COLLECTION_USER="COLLECTION_USER",t.OFFLINE_USER="OFFLINE_USER",t.ANALYTICS_USER="ANALYTICS_USER",t.BETA_USER="BETA_USER",t.DEBUG_USER="DEBUG_USER",t.PRINT_USER="PRINT_USER",t.RATING_USER="RATING_USER",t.FEEDBACK_USER="FEEDBACK_USER",t.CONTENT_PUBLISHER="CONTENT_PUBLISHER",t.KHUB_ADMIN="KHUB_ADMIN",t.USERS_ADMIN="USERS_ADMIN",t.PORTAL_ADMIN="PORTAL_ADMIN",t.ADMIN="ADMIN",t.DEVELOPER="DEVELOPER"}(b||(b={})),b.PERSONAL_BOOK_SHARE_USER,b.PERSONAL_BOOK_USER,b.HTML_EXPORT_USER,b.PERSONAL_BOOK_USER,b.PDF_EXPORT_USER,b.PERSONAL_BOOK_USER,b.KHUB_ADMIN,b.CONTENT_PUBLISHER,b.ADMIN,b.KHUB_ADMIN,b.USERS_ADMIN,b.PORTAL_ADMIN,b.DEVELOPER,b.BETA_USER,b.DEBUG_USER;const p=i.css`
|
|
3
3
|
`,m=s.FtReduxStore.get({name:"ft-app-info",reducers:{setBaseUrl:(t,s)=>{t.baseUrl=s.payload},setApiIntegrationIdentifier:(t,s)=>{t.apiIntegrationIdentifier=s.payload},setUiLocale:(t,s)=>{t.uiLocale=s.payload},setAvailableUiLocales:(t,s)=>{t.availableUiLocales=s.payload},setEditorMode:(t,s)=>{t.editorMode=s.payload},setNoCustom:(t,s)=>{t.noCustom=s.payload},setNoCustomComponent:(t,s)=>{t.noCustomComponent=s.payload},setSession:(t,s)=>{t.session=s.payload}},initialState:{uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],editorMode:!1,noCustom:!1,noCustomComponent:!1}});class A{static build(t){const{baseUrl:s,apiIntegrationIdentifier:i}=m.getState(),e=null!=t?t:i;if(s&&e&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(s,e,!0)}static get(t){var s;return null!=t?A.build(t):null!==(s=A.API)&&void 0!==s?s:A.API=A.build()}static await(t){return new Promise((s=>{let i=A.get(t);if(i)s(i);else{const e=m.subscribe((()=>{i=A.get(t),i&&(e(),s(i))}))}}))}}var g;const R=Symbol("clearAfterUnitTest");class T{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={},this.currentUiLocale="",this[g]=()=>{this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={}},this.currentUiLocale=m.getState().uiLocale,m.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=m.getState();this.currentUiLocale!==t&&(this.currentUiLocale=t,this.cache.clearAll(),this.notifyAll())}addContext(t){const s=t.name.toLowerCase();this.cache.setFinal(s,t),this.notify(s)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(t,i){var e;if(t=t.toLowerCase(),Object.keys(i).length>0){const n={...null!==(e=this.defaultMessages[t])&&void 0!==e?e:{},...i};s.deepEqual(this.defaultMessages[t],n)||(this.defaultMessages[t]=n,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,i,...e){var n,r,o;t=t.toLowerCase(),this.fetchContext(t);const a=null!==(r=null===(n=this.cache.getNow(t))||void 0===n?void 0:n.messages)&&void 0!==r?r:{};return new s.ParametrizedLabelResolver(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},a).resolve(i,...e)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,s){var i;return t=t.toLowerCase(),this.listeners[t]=null!==(i=this.listeners[t])&&void 0!==i?i:new Set,this.listeners[t].add(s),()=>{var i;return null===(i=this.listeners[t])||void 0===i?void 0:i.delete(s)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>s.delay(0).then((()=>t())).catch((()=>null)))))}}g=R,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new T((async(t,s)=>(await A.await()).getFluidTopicsMessageContext(t,s)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new T((async(t,s)=>(await A.await()).getCustomMessageContext(t,s))));const O=window.FluidTopicsI18nService;var U=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class C extends s.FtLitElement{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.availableUiLocales=[],this.editorMode=!1,this.noCustom=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>A.get(),this.cache=new s.CacheRegistry,this.cleanSessionDebouncer=new s.Debouncer}render(){return i.html`
|
|
4
4
|
<slot></slot>
|
|
5
|
-
`}update(t){super.update(t),t.has("baseUrl")&&m.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&m.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&m.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&m.actions.setNoCustom(this.noCustom),t.has("editorMode")&&m.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&m.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&m.actions.setSession(this.session),t.has("availableUiLocales")&&m.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>O.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const s=await t.getCurrentSession();return s.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),s.idleTimeoutInMillis),s}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}C.elementDefinitions={},C.styles=p,U([e.property()],C.prototype,"baseUrl",void 0),U([e.property()],C.prototype,"apiIntegrationIdentifier",void 0),U([e.property()],C.prototype,"uiLocale",void 0),U([s.jsonProperty([])],C.prototype,"availableUiLocales",void 0),U([e.property({type:Boolean})],C.prototype,"editorMode",void 0),U([e.property({type:Boolean})],C.prototype,"noCustom",void 0),U([e.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],C.prototype,"noCustomComponent",void 0),U([e.property({type:Boolean})],C.prototype,"withManualResources",void 0),U([s.jsonProperty([])],C.prototype,"messageContexts",void 0),U([s.jsonProperty(void 0)],C.prototype,"session",void 0),U([e.property({type:Object})],C.prototype,"apiProvider",void 0);class L{async listMySearches(){var t;return(null===(t=m.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await A.await()).listMySearches(m.getState().session.profile.userId):[]}}const I=new s.CacheRegistry;class P{async listMyBookmarks(){return I.get("bookmarks",(async()=>(await A.await()).listMyBookmarks(m.getState().session.profile.userId)))}clearCache(){I.clear("bookmarks")}}const D=s.FtReduxStore.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const N=new class{constructor(){this.currentSession=m.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new P,m.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:i}=m.getState();s.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==i?void 0:i.profile)||(this.currentSession=i,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){D.actions.savedSearches(void 0)}clearMyBookmarks(){D.actions.bookmarks(void 0)}async reloadMySearches(){const t=new L,s=await t.listMySearches();D.actions.savedSearches(s)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const s=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;D.actions.bookmarks(s)}}};s.customElement("ft-app-context")(C);class _{static async build(){return new _(await A.await())}constructor(t){this.api=t,this.cache=new s.CacheRegistry,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.api.search(t)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}}const B=t=>t.request.virtualField===d.TITLE_ONLY&&t.request.scope===S.DOCUMENTS;class M extends Event{constructor(){super(M.eventName)}}M.eventName="search-context-clear-all-filters";class F{static build(t){return new F((t=>s.FtReduxStore.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:r}))(t.trim()||"context"),_.build)}constructor(t,i){this.store=t,this.serviceProvider=i,this.searchDebouncer=new s.Debouncer(100),this.suggestDebouncer=new s.Debouncer(300)}async initService(){return this.service=await this.serviceProvider(),this.store.actions.setLocales((await this.service.getAvailableSearchLocales()).contentLocales),this.launchSearch()}async awaitService(){for(;null==this.service;)await s.delay(5);return this.service}setQuery(t){this.store.actions.setRequestQuery(t),this.store.actions.setLiveQuery(t),this.store.actions.setPageNumber(1),this.launchSearch()}setContentLocale(t){let s=this.store.getState().locales,i=this.store.getState().request.contentLocale;if(t!=i){if(s){const e=t=>s.some((s=>s.lang==t));e(t)||(t=e(i)?i:s[0].lang)}this.store.actions.setRequestContentLocale(t),this.store.actions.setPageNumber(1),this.store.actions.setRequestFilters([]),this.launchSearch()}return t}setPageSize(t){this.store.actions.setPageSize(t),this.launchSearch()}setPageNumber(t){this.store.actions.setPageNumber(t),this.launchSearch()}setSort(t){this.store.actions.setRequestSort(t),this.store.actions.setPageNumber(1),this.launchSearch()}setFilters(t){const s=t.filter((t=>t.values.length>0));this.store.actions.setRequestFilters(s),this.store.actions.setPageNumber(1),s.forEach((t=>{this.facetIds.includes(t.key)||(this.facetIds=[...this.facetIds,t.key])})),this.launchSearch()}setSearchInDocumentTitlesOnly(t){t?(this.store.actions.setRequestVirtualField(d.TITLE_ONLY),this.store.actions.setRequestScope(S.DOCUMENTS)):(this.store.actions.setRequestVirtualField(d.EVERYWHERE),this.store.actions.setRequestScope(S.DEFAULT)),this.launchSearch()}get searchInDocumentTitlesOnly(){return B(this.store.getState())}clearAllFilters(){this.setFilters([]),this.store.eventBus.dispatchEvent(new M)}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,s){let i=this.facetIds.filter((s=>s!=t));s&&i.push(s),this.facetIds=i,this.launchSearch()}get facetIds(){return this.store.getState().request.facets.map((t=>t.id))}set facetIds(t){let s=[...new Set(t)].map((t=>({id:t})));this.store.actions.setRequestFacets(s)}setFilter(t,s){let i=this.store.getState().request.filters,e={key:t,values:s,negative:!1},n=[...i.filter((s=>s.key!==t)),e];this.setFilters(n)}setLiveQuery(t){this.store.actions.setLiveQuery(t),this.launchSuggest()}setRequest(t){this.store.actions.setRequest(t),this.store.actions.setLiveQuery(t.query),this.store.actions.setPageNumber(1),this.launchSearch()}async launchSearch(){return await this.awaitService(),this.searchDebouncer.run((()=>this.fetchSearchData()))}async launchSuggest(){await this.awaitService(),this.suggestDebouncer.run((()=>this.fetchSuggestData()))}async fetchSearchData(){var t,i;try{null===(t=this.cancelableSearch)||void 0===t||t.cancel(),this.cancelableSearch=s.cancelable(this.service.launchSearch(this.store.getState().request));const e=await this.cancelableSearch;if(e.paging.currentPage<=1)this.store.actions.setResults(e.results),this.store.actions.setFacets(e.facets),this.store.actions.setSpellcheck(e.spellcheck);else{let t=(null!==(i=this.store.getState().results)&&void 0!==i?i:[]).concat(e.results);this.store.actions.setResults(t)}this.store.actions.setPaging(e.paging)}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}async fetchSuggestData(){var t;try{let i={input:this.store.getState().liveQuery,filters:this.store.getState().request.filters,sort:this.store.getState().request.sort,contentLocale:this.store.getState().request.contentLocale};null===(t=this.cancelableSuggest)||void 0===t||t.cancel(),this.cancelableSuggest=s.cancelable(this.service.launchSuggest(i));let e=await this.cancelableSuggest;this.store.actions.setSuggestResults(e.suggestions)}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}}var x=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class k extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const j=Symbol("registerInterval");class q extends(function(t){var s;class i extends t{constructor(){super(...arguments),this[s]=0}setSearchStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"search")}clearStateManager(){this.stateManager&&(this.removeStore(this.stateManager.store),this.stateManager=void 0)}connectedCallback(){super.connectedCallback(),this[j]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[j]):this.dispatchEvent(new k)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return s=j,x([e.state()],i.prototype,"stateManager",void 0),i}(s.FtLitElementRedux)){}var H=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class G extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class K extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class z extends CustomEvent{constructor(t,s,i){super("ft-search-results-change",{detail:{request:t,paging:s,spellcheck:i}})}}class Q extends s.FtLitElementRedux{get stateManager(){return null==this._stateManager&&(this._stateManager=F.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"search")),this._stateManager}constructor(){super(),this.query="",this.pageSize=20,this.searchInDocumentTitlesOnly=!1,this.filters=[],this.sort=[],this.addStore(m)}render(){return i.html`
|
|
5
|
+
`}update(t){super.update(t),t.has("baseUrl")&&m.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&m.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&m.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&m.actions.setNoCustom(this.noCustom),t.has("editorMode")&&m.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&m.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&m.actions.setSession(this.session),t.has("availableUiLocales")&&m.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>O.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const s=await t.getCurrentSession();return s.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),s.idleTimeoutInMillis),s}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}C.elementDefinitions={},C.styles=p,U([e.property()],C.prototype,"baseUrl",void 0),U([e.property()],C.prototype,"apiIntegrationIdentifier",void 0),U([e.property()],C.prototype,"uiLocale",void 0),U([s.jsonProperty([])],C.prototype,"availableUiLocales",void 0),U([e.property({type:Boolean})],C.prototype,"editorMode",void 0),U([e.property({type:Boolean})],C.prototype,"noCustom",void 0),U([e.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],C.prototype,"noCustomComponent",void 0),U([e.property({type:Boolean})],C.prototype,"withManualResources",void 0),U([s.jsonProperty([])],C.prototype,"messageContexts",void 0),U([s.jsonProperty(void 0)],C.prototype,"session",void 0),U([e.property({type:Object})],C.prototype,"apiProvider",void 0);class L{async listMySearches(){var t;return(null===(t=m.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await A.await()).listMySearches(m.getState().session.profile.userId):[]}}const I=new s.CacheRegistry;class P{async listMyBookmarks(){return I.get("bookmarks",(async()=>(await A.await()).listMyBookmarks(m.getState().session.profile.userId)))}clearCache(){I.clear("bookmarks")}}const D=s.FtReduxStore.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const N=new class{constructor(){this.currentSession=m.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new P,m.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:i}=m.getState();s.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==i?void 0:i.profile)||(this.currentSession=i,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){D.actions.savedSearches(void 0)}clearMyBookmarks(){D.actions.bookmarks(void 0)}async reloadMySearches(){const t=new L,s=await t.listMySearches();D.actions.savedSearches(s)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const s=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;D.actions.bookmarks(s)}}};s.customElement("ft-app-context")(C);class _{static async build(){return new _(await A.await())}constructor(t){this.api=t,this.cache=new s.CacheRegistry,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.api.search(t)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}}const B=t=>t.request.virtualField===d.TITLE_ONLY&&t.request.scope===S.DOCUMENTS;class M extends Event{constructor(){super(M.eventName)}}M.eventName="search-context-clear-all-filters";class F{static build(t){return new F((t=>s.FtReduxStore.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:r}))(t.trim()||"context"),_.build)}constructor(t,i){this.store=t,this.serviceProvider=i,this.searchDebouncer=new s.Debouncer(100),this.suggestDebouncer=new s.Debouncer(300)}async initService(){return this.service=await this.serviceProvider(),this.store.actions.setLocales((await this.service.getAvailableSearchLocales()).contentLocales),this.launchSearch()}async awaitService(){for(;null==this.service;)await s.delay(5);return this.service}setQuery(t){this.store.actions.setRequestQuery(t),this.store.actions.setLiveQuery(t),this.store.actions.setPageNumber(1),this.launchSearch()}setContentLocale(t){let s=this.store.getState().locales,i=this.store.getState().request.contentLocale;if(t!=i){if(s){const e=t=>s.some((s=>s.lang==t));e(t)||(t=e(i)?i:s[0].lang)}this.store.actions.setRequestContentLocale(t),this.store.actions.setPageNumber(1),this.store.actions.setRequestFilters([]),this.launchSearch()}return t}setPageSize(t){this.store.actions.setPageSize(t),this.launchSearch()}setPageNumber(t){this.store.actions.setPageNumber(t),this.launchSearch()}setSort(t){this.store.actions.setRequestSort(t),this.store.actions.setPageNumber(1),this.launchSearch()}setFilters(t){const s=t.filter((t=>t.values.length>0));this.store.actions.setRequestFilters(s),this.store.actions.setPageNumber(1),s.forEach((t=>{this.facetIds.includes(t.key)||(this.facetIds=[...this.facetIds,t.key])})),this.launchSearch()}setSearchInDocumentTitlesOnly(t){t?(this.store.actions.setRequestVirtualField(d.TITLE_ONLY),this.store.actions.setRequestScope(S.DOCUMENTS)):(this.store.actions.setRequestVirtualField(d.EVERYWHERE),this.store.actions.setRequestScope(S.DEFAULT)),this.launchSearch()}get searchInDocumentTitlesOnly(){return B(this.store.getState())}clearAllFilters(){this.setFilters([]),this.store.eventBus.dispatchEvent(new M)}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,s){let i=this.facetIds.filter((s=>s!=t));s&&i.push(s),this.facetIds=i,this.launchSearch()}get facetIds(){return this.store.getState().request.facets.map((t=>t.id))}set facetIds(t){let s=[...new Set(t)].map((t=>({id:t})));this.store.actions.setRequestFacets(s)}setFilter(t,s){let i=this.store.getState().request.filters,e={key:t,values:s,negative:!1},n=[...i.filter((s=>s.key!==t)),e];this.setFilters(n)}setLiveQuery(t){this.store.actions.setLiveQuery(t),this.launchSuggest()}setRequest(t){this.store.actions.setRequest(t),this.store.actions.setLiveQuery(t.query),this.store.actions.setPageNumber(1),this.launchSearch()}async launchSearch(){return await this.awaitService(),this.searchDebouncer.run((()=>this.fetchSearchData()))}async launchSuggest(){await this.awaitService(),this.suggestDebouncer.run((()=>this.fetchSuggestData()))}async fetchSearchData(){var t,i;try{null===(t=this.cancelableSearch)||void 0===t||t.cancel(),this.cancelableSearch=s.cancelable(this.service.launchSearch(this.store.getState().request));const e=await this.cancelableSearch;if(e.paging.currentPage<=1)this.store.actions.setResults(e.results),this.store.actions.setFacets(e.facets),this.store.actions.setSpellcheck(e.spellcheck);else{let t=(null!==(i=this.store.getState().results)&&void 0!==i?i:[]).concat(e.results);this.store.actions.setResults(t)}this.store.actions.setPaging(e.paging)}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}async fetchSuggestData(){var t;try{const i=this.store.getState(),e=i.request,n={input:i.liveQuery,filters:e.filters,sort:e.sort,contentLocale:e.contentLocale,scope:e.scope};null===(t=this.cancelableSuggest)||void 0===t||t.cancel(),this.cancelableSuggest=s.cancelable(this.service.launchSuggest(n));let r=await this.cancelableSuggest;this.store.actions.setSuggestResults(r.suggestions)}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}}var x=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class k extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const j=Symbol("registerInterval");class q extends(function(t){var s;class i extends t{constructor(){super(...arguments),this[s]=0}setSearchStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"search")}clearStateManager(){this.stateManager&&(this.removeStore(this.stateManager.store),this.stateManager=void 0)}connectedCallback(){super.connectedCallback(),this[j]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[j]):this.dispatchEvent(new k)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return s=j,x([e.state()],i.prototype,"stateManager",void 0),i}(s.FtLitElementRedux)){}var H=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class G extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class K extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class z extends CustomEvent{constructor(t,s,i){super("ft-search-results-change",{detail:{request:t,paging:s,spellcheck:i}})}}class Q extends s.FtLitElementRedux{get stateManager(){return null==this._stateManager&&(this._stateManager=F.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"search")),this._stateManager}constructor(){super(),this.query="",this.pageSize=20,this.searchInDocumentTitlesOnly=!1,this.filters=[],this.sort=[],this.addStore(m)}render(){return i.html`
|
|
6
6
|
<slot @register-ft-search-component=${this.registerComponent}></slot>
|
|
7
7
|
`}update(t){super.update(t),t.has("query")&&void 0!==this.query&&this.stateManager.setQuery(this.query),t.has("contentLocale")&&void 0!==this.contentLocale&&this.stateManager.setContentLocale(this.contentLocale),t.has("session")&&this.session&&this.stateManager.initService(),t.has("filters")&&void 0!==this.filters&&this.stateManager.setFilters(this.filters),t.has("sort")&&void 0!==this.sort&&this.stateManager.setSort(this.sort),t.has("pageSize")&&void 0!==this.pageSize&&this.stateManager.setPageSize(this.pageSize),t.has("searchInDocumentTitlesOnly")&&void 0!==this.searchInDocumentTitlesOnly&&this.stateManager.setSearchInDocumentTitlesOnly(this.searchInDocumentTitlesOnly)}connectedCallback(){super.connectedCallback(),this.stateManager.setQuery(this.query),this.stateManager.setContentLocale(this.contentLocale),this.stateManager.setFilters(this.filters),this.stateManager.setPageSize(this.pageSize),this.stateManager.setSort(this.sort)}contentAvailableCallback(t){super.contentAvailableCallback(t),t.has("request")&&this.request&&this.dispatchEvent(new K(this.request)),t.has("paging")&&void 0!==this.paging&&this.dispatchEvent(new z(this.request,this.paging,this.autocorrect))}registerComponent(t){t.stopPropagation();const s=t.composedPath()[0];this.register(s)}register(t){t.setSearchStateManager(this.stateManager)}handleLoadError(t){this.dispatchEvent(new G(t))}reloadSavedSearches(){N.clearMySearches()}}Q.elementDefinitions={},Q.styles=n,H([e.property()],Q.prototype,"query",void 0),H([e.property()],Q.prototype,"contentLocale",void 0),H([e.property({type:Number})],Q.prototype,"pageSize",void 0),H([e.property({type:Boolean})],Q.prototype,"searchInDocumentTitlesOnly",void 0),H([s.jsonProperty([])],Q.prototype,"filters",void 0),H([s.jsonProperty([])],Q.prototype,"sort",void 0),H([s.redux({store:"search"})],Q.prototype,"request",void 0),H([s.redux({store:"search"})],Q.prototype,"paging",void 0),H([s.redux({store:"search",selector:t=>t.spellcheck})],Q.prototype,"autocorrect",void 0),H([s.redux({store:m.name})],Q.prototype,"session",void 0),s.customElement("ft-search-context")(Q),t.ClearAllFiltersEvent=M,t.FtSearchContext=Q,t.FtSearchContextCssVariables={},t.FtSearchStateManager=F,t.LoadErrorEvent=G,t.SearchRequestChangeEvent=K,t.SearchResultsChangeEvent=z,t.searchInDocumentTitlesOnlySelector=B,t.styles=n}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);
|
|
@@ -87,6 +87,6 @@ var pt,yt;let bt=class extends A{constructor(){super(...arguments),this.renderOp
|
|
|
87
87
|
`,Ar={setRequest:(t,o)=>{t.request=o.payload},setRequestQuery:(t,o)=>{t.request.query=o.payload},setRequestContentLocale:(t,o)=>{t.request.contentLocale=o.payload},setPageSize:(t,o)=>{t.request.paging.perPage=o.payload},setPageNumber:(t,o)=>{t.request.paging.page=o.payload},setRequestSort:(t,o)=>{t.request.sort=o.payload},setRequestFilters:(t,o)=>{t.request.filters=o.payload},setRequestFacets:(t,o)=>{t.request.facets=o.payload},setRequestVirtualField:(t,o)=>{t.request.virtualField=o.payload},setRequestScope:(t,o)=>{t.request.scope=o.payload},setResults:(t,o)=>{t.results=o.payload},setFacets:(t,o)=>{t.facets=o.payload},setSpellcheck:(t,o)=>{t.spellcheck=o.payload},setLocales:(t,o)=>{t.locales=o.payload},setPaging:(t,o)=>{t.paging=o.payload},setLiveQuery:(t,o)=>{t.liveQuery=o.payload},setSuggestResults:(t,o)=>{t.suggestResults=o.payload}};var Wr,kr,Kr,jr,Fr,Zr,Mr,Pr,Tr,Br,Dr,_r,zr,$r;!function(t){!function(o){var r={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(r.arrayBuffer)var e=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&e.indexOf(Object.prototype.toString.call(t))>-1};function i(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function a(t){return"string"!=typeof t&&(t=String(t)),t}function s(t){var o={next:function(){var o=t.shift();return{done:void 0===o,value:o}}};return r.iterable&&(o[Symbol.iterator]=function(){return o}),o}function c(t){this.map={},t instanceof c?t.forEach((function(t,o){this.append(o,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(o){this.append(o,t[o])}),this)}function l(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function f(t){return new Promise((function(o,r){t.onload=function(){o(t.result)},t.onerror=function(){r(t.error)}}))}function u(t){var o=new FileReader,r=f(o);return o.readAsArrayBuffer(t),r}function h(t){if(t.slice)return t.slice(0);var o=new Uint8Array(t.byteLength);return o.set(new Uint8Array(t)),o.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(t){var o;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:r.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:r.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():r.arrayBuffer&&r.blob&&((o=t)&&DataView.prototype.isPrototypeOf(o))?(this._bodyArrayBuffer=h(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=h(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var t=l(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?l(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(u)}),this.text=function(){var t=l(this);if(t)return t;if(this._bodyBlob)return function(t){var o=new FileReader,r=f(o);return o.readAsText(t),r}(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var o=new Uint8Array(t),r=new Array(o.length),e=0;e<o.length;e++)r[e]=String.fromCharCode(o[e]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r.formData&&(this.formData=function(){return this.text().then(b)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(t,o){t=i(t),o=a(o);var r=this.map[t];this.map[t]=r?r+", "+o:o},c.prototype.delete=function(t){delete this.map[i(t)]},c.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},c.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},c.prototype.set=function(t,o){this.map[i(t)]=a(o)},c.prototype.forEach=function(t,o){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(o,this.map[r],r,this)},c.prototype.keys=function(){var t=[];return this.forEach((function(o,r){t.push(r)})),s(t)},c.prototype.values=function(){var t=[];return this.forEach((function(o){t.push(o)})),s(t)},c.prototype.entries=function(){var t=[];return this.forEach((function(o,r){t.push([r,o])})),s(t)},r.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var p=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,o){var r,e,n=(o=o||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,o.headers||(this.headers=new c(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=o.credentials||this.credentials||"same-origin",!o.headers&&this.headers||(this.headers=new c(o.headers)),this.method=(r=o.method||this.method||"GET",e=r.toUpperCase(),p.indexOf(e)>-1?e:r),this.mode=o.mode||this.mode||null,this.signal=o.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function b(t){var o=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),e=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");o.append(decodeURIComponent(e),decodeURIComponent(n))}})),o}function g(t,o){o||(o={}),this.type="default",this.status=void 0===o.status?200:o.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in o?o.statusText:"OK",this.headers=new c(o.headers),this.url=o.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},d.call(y.prototype),d.call(g.prototype),g.prototype.clone=function(){return new g(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},g.error=function(){var t=new g(null,{status:0,statusText:""});return t.type="error",t};var m=[301,302,303,307,308];g.redirect=function(t,o){if(-1===m.indexOf(o))throw new RangeError("Invalid status code");return new g(null,{status:o,headers:{location:t}})},o.DOMException=t.DOMException;try{new o.DOMException}catch(t){o.DOMException=function(t,o){this.message=t,this.name=o;var r=Error(t);this.stack=r.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function v(t,e){return new Promise((function(n,i){var a=new y(t,e);if(a.signal&&a.signal.aborted)return i(new o.DOMException("Aborted","AbortError"));var s=new XMLHttpRequest;function l(){s.abort()}s.onload=function(){var t,o,r={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",o=new c,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),e=r.shift().trim();if(e){var n=r.join(":").trim();o.append(e,n)}})),o)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var e="response"in s?s.response:s.responseText;n(new g(e,r))},s.onerror=function(){i(new TypeError("Network request failed"))},s.ontimeout=function(){i(new TypeError("Network request failed"))},s.onabort=function(){i(new o.DOMException("Aborted","AbortError"))},s.open(a.method,a.url,!0),"include"===a.credentials?s.withCredentials=!0:"omit"===a.credentials&&(s.withCredentials=!1),"responseType"in s&&r.blob&&(s.responseType="blob"),a.headers.forEach((function(t,o){s.setRequestHeader(o,t)})),a.signal&&(a.signal.addEventListener("abort",l),s.onreadystatechange=function(){4===s.readyState&&a.signal.removeEventListener("abort",l)}),s.send(void 0===a._bodyInit?null:a._bodyInit)}))}v.polyfill=!0,t.fetch||(t.fetch=v,t.Headers=c,t.Request=y,t.Response=g),o.Headers=c,o.Request=y,o.Response=g,o.fetch=v,Object.defineProperty(o,"U",{value:!0})}({})}("undefined"!=typeof self?self:void 0),function(t){t.black="black",t.green="green",t.blue="blue",t.purple="purple",t.red="red",t.orange="orange",t.yellow="yellow"}(Wr||(Wr={})),function(t){t.OFFICIAL="OFFICIAL",t.PERSONAL="PERSONAL",t.SHARED="SHARED"}(kr||(kr={})),function(t){t.THIRD_PARTY="THIRD_PARTY",t.OFF_THE_GRID="OFF_THE_GRID",t.CONTENT_PACKAGER="CONTENT_PACKAGER",t.PAGES="PAGES",t.DESIGNED_READER="DESIGNED_READER"}(Kr||(Kr={})),function(t){t.STARS="STARS",t.LIKE="LIKE",t.DICHOTOMOUS="DICHOTOMOUS",t.NO_RATING="NO_RATING"}(jr||(jr={})),function(t){t.LAST_WEEK="LAST_WEEK",t.LAST_MONTH="LAST_MONTH",t.LAST_YEAR="LAST_YEAR",t.CUSTOM="CUSTOM"}(Fr||(Fr={})),function(t){t.ASC="ASC",t.DESC="DESC"}(Zr||(Zr={})),function(t){t.ALPHA="ALPHA",t.NATURAL="NATURAL"}(Mr||(Mr={})),function(t){t.EVERYWHERE="EVERYWHERE",t.TITLE_ONLY="TITLE_ONLY",t.NONE="NONE"}(Pr||(Pr={})),function(t){t.ARTICLE="ARTICLE",t.BOOK="BOOK",t.SHARED_BOOK="SHARED_BOOK"}(Tr||(Tr={})),function(t){t.FLUIDTOPICS="FLUIDTOPICS",t.EXTERNAL="EXTERNAL"}(Br||(Br={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC",t.PERSONAL_BOOK="PERSONAL_BOOK",t.SHARED_BOOK="SHARED_BOOK"}(Dr||(Dr={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC"}(_r||(_r={})),function(t){t.DEFAULT="DEFAULT",t.DOCUMENTS="DOCUMENTS"}(zr||(zr={})),function(t){t.PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",t.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",t.HTML_EXPORT_USER="HTML_EXPORT_USER",t.PDF_EXPORT_USER="PDF_EXPORT_USER",t.SAVED_SEARCH_USER="SAVED_SEARCH_USER",t.COLLECTION_USER="COLLECTION_USER",t.OFFLINE_USER="OFFLINE_USER",t.ANALYTICS_USER="ANALYTICS_USER",t.BETA_USER="BETA_USER",t.DEBUG_USER="DEBUG_USER",t.PRINT_USER="PRINT_USER",t.RATING_USER="RATING_USER",t.FEEDBACK_USER="FEEDBACK_USER",t.CONTENT_PUBLISHER="CONTENT_PUBLISHER",t.KHUB_ADMIN="KHUB_ADMIN",t.USERS_ADMIN="USERS_ADMIN",t.PORTAL_ADMIN="PORTAL_ADMIN",t.ADMIN="ADMIN",t.DEVELOPER="DEVELOPER"}($r||($r={})),$r.PERSONAL_BOOK_SHARE_USER,$r.PERSONAL_BOOK_USER,$r.HTML_EXPORT_USER,$r.PERSONAL_BOOK_USER,$r.PDF_EXPORT_USER,$r.PERSONAL_BOOK_USER,$r.KHUB_ADMIN,$r.CONTENT_PUBLISHER,$r.ADMIN,$r.KHUB_ADMIN,$r.USERS_ADMIN,$r.PORTAL_ADMIN,$r.DEVELOPER,$r.BETA_USER,$r.DEBUG_USER;const Gr=O`
|
|
88
88
|
`,Hr=Rr.get({name:"ft-app-info",reducers:{setBaseUrl:(t,o)=>{t.baseUrl=o.payload},setApiIntegrationIdentifier:(t,o)=>{t.apiIntegrationIdentifier=o.payload},setUiLocale:(t,o)=>{t.uiLocale=o.payload},setAvailableUiLocales:(t,o)=>{t.availableUiLocales=o.payload},setEditorMode:(t,o)=>{t.editorMode=o.payload},setNoCustom:(t,o)=>{t.noCustom=o.payload},setNoCustomComponent:(t,o)=>{t.noCustomComponent=o.payload},setSession:(t,o)=>{t.session=o.payload}},initialState:{uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],editorMode:!1,noCustom:!1,noCustomComponent:!1}});class qr{static build(t){const{baseUrl:o,apiIntegrationIdentifier:r}=Hr.getState(),e=null!=t?t:r;if(o&&e&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(o,e,!0)}static get(t){var o;return null!=t?qr.build(t):null!==(o=qr.API)&&void 0!==o?o:qr.API=qr.build()}static await(t){return new Promise((o=>{let r=qr.get(t);if(r)o(r);else{const e=Hr.subscribe((()=>{r=qr.get(t),r&&(e(),o(r))}))}}))}}var Yr;const Vr=Symbol("clearAfterUnitTest");class Xr{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new n,this.listeners={},this.currentUiLocale="",this[Yr]=()=>{this.defaultMessages={},this.cache=new n,this.listeners={}},this.currentUiLocale=Hr.getState().uiLocale,Hr.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=Hr.getState();this.currentUiLocale!==t&&(this.currentUiLocale=t,this.cache.clearAll(),this.notifyAll())}addContext(t){const o=t.name.toLowerCase();this.cache.setFinal(o,t),this.notify(o)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(t,o){var r;if(t=t.toLowerCase(),Object.keys(o).length>0){const e={...null!==(r=this.defaultMessages[t])&&void 0!==r?r:{},...o};u(this.defaultMessages[t],e)||(this.defaultMessages[t]=e,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,o,...r){var e,n,i;t=t.toLowerCase(),this.fetchContext(t);const a=null!==(n=null===(e=this.cache.getNow(t))||void 0===e?void 0:e.messages)&&void 0!==n?n:{};return new Lt(null!==(i=this.defaultMessages[t])&&void 0!==i?i:{},a).resolve(o,...r)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,o){var r;return t=t.toLowerCase(),this.listeners[t]=null!==(r=this.listeners[t])&&void 0!==r?r:new Set,this.listeners[t].add(o),()=>{var r;return null===(r=this.listeners[t])||void 0===r?void 0:r.delete(o)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>f(0).then((()=>t())).catch((()=>null)))))}}Yr=Vr,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new Xr((async(t,o)=>(await qr.await()).getFluidTopicsMessageContext(t,o)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new Xr((async(t,o)=>(await qr.await()).getCustomMessageContext(t,o))));const Jr=window.FluidTopicsI18nService;var Qr=function(t,o,r,e){for(var n,i=arguments.length,a=i<3?o:null===e?e=Object.getOwnPropertyDescriptor(o,r):e,s=t.length-1;s>=0;s--)(n=t[s])&&(a=(i<3?n(a):i>3?n(o,r,a):n(o,r))||a);return i>3&&a&&Object.defineProperty(o,r,a),a};class te extends Ut{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.availableUiLocales=[],this.editorMode=!1,this.noCustom=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>qr.get(),this.cache=new n,this.cleanSessionDebouncer=new i}render(){return J`
|
|
89
89
|
<slot></slot>
|
|
90
|
-
`}update(t){super.update(t),t.has("baseUrl")&&Hr.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&Hr.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&Hr.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&Hr.actions.setNoCustom(this.noCustom),t.has("editorMode")&&Hr.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&Hr.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&Hr.actions.setSession(this.session),t.has("availableUiLocales")&&Hr.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>Jr.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const o=await t.getCurrentSession();return o.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),o.idleTimeoutInMillis),o}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}te.elementDefinitions={},te.styles=Gr,Qr([s()],te.prototype,"baseUrl",void 0),Qr([s()],te.prototype,"apiIntegrationIdentifier",void 0),Qr([s()],te.prototype,"uiLocale",void 0),Qr([d([])],te.prototype,"availableUiLocales",void 0),Qr([s({type:Boolean})],te.prototype,"editorMode",void 0),Qr([s({type:Boolean})],te.prototype,"noCustom",void 0),Qr([s({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],te.prototype,"noCustomComponent",void 0),Qr([s({type:Boolean})],te.prototype,"withManualResources",void 0),Qr([d([])],te.prototype,"messageContexts",void 0),Qr([d(void 0)],te.prototype,"session",void 0),Qr([s({type:Object})],te.prototype,"apiProvider",void 0);class oe{async listMySearches(){var t;return(null===(t=Hr.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await qr.await()).listMySearches(Hr.getState().session.profile.userId):[]}}const re=new n;class ee{async listMyBookmarks(){return re.get("bookmarks",(async()=>(await qr.await()).listMyBookmarks(Hr.getState().session.profile.userId)))}clearCache(){re.clear("bookmarks")}}const ne=Rr.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const ie=new class{constructor(){this.currentSession=Hr.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new ee,Hr.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:o}=Hr.getState();u(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==o?void 0:o.profile)||(this.currentSession=o,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){ne.actions.savedSearches(void 0)}clearMyBookmarks(){ne.actions.bookmarks(void 0)}async reloadMySearches(){const t=new oe,o=await t.listMySearches();ne.actions.savedSearches(o)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const o=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;ne.actions.bookmarks(o)}}};h("ft-app-context")(te);class ae{static async build(){return new ae(await qr.await())}constructor(t){this.api=t,this.cache=new n,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.api.search(t)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}}const se=t=>t.request.virtualField===Pr.TITLE_ONLY&&t.request.scope===zr.DOCUMENTS;class ce extends Event{constructor(){super(ce.eventName)}}ce.eventName="search-context-clear-all-filters";class le{static build(t){return new le((t=>Rr.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:Ar}))(t.trim()||"context"),ae.build)}constructor(t,o){this.store=t,this.serviceProvider=o,this.searchDebouncer=new i(100),this.suggestDebouncer=new i(300)}async initService(){return this.service=await this.serviceProvider(),this.store.actions.setLocales((await this.service.getAvailableSearchLocales()).contentLocales),this.launchSearch()}async awaitService(){for(;null==this.service;)await f(5);return this.service}setQuery(t){this.store.actions.setRequestQuery(t),this.store.actions.setLiveQuery(t),this.store.actions.setPageNumber(1),this.launchSearch()}setContentLocale(t){let o=this.store.getState().locales,r=this.store.getState().request.contentLocale;if(t!=r){if(o){const e=t=>o.some((o=>o.lang==t));e(t)||(t=e(r)?r:o[0].lang)}this.store.actions.setRequestContentLocale(t),this.store.actions.setPageNumber(1),this.store.actions.setRequestFilters([]),this.launchSearch()}return t}setPageSize(t){this.store.actions.setPageSize(t),this.launchSearch()}setPageNumber(t){this.store.actions.setPageNumber(t),this.launchSearch()}setSort(t){this.store.actions.setRequestSort(t),this.store.actions.setPageNumber(1),this.launchSearch()}setFilters(t){const o=t.filter((t=>t.values.length>0));this.store.actions.setRequestFilters(o),this.store.actions.setPageNumber(1),o.forEach((t=>{this.facetIds.includes(t.key)||(this.facetIds=[...this.facetIds,t.key])})),this.launchSearch()}setSearchInDocumentTitlesOnly(t){t?(this.store.actions.setRequestVirtualField(Pr.TITLE_ONLY),this.store.actions.setRequestScope(zr.DOCUMENTS)):(this.store.actions.setRequestVirtualField(Pr.EVERYWHERE),this.store.actions.setRequestScope(zr.DEFAULT)),this.launchSearch()}get searchInDocumentTitlesOnly(){return se(this.store.getState())}clearAllFilters(){this.setFilters([]),this.store.eventBus.dispatchEvent(new ce)}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,o){let r=this.facetIds.filter((o=>o!=t));o&&r.push(o),this.facetIds=r,this.launchSearch()}get facetIds(){return this.store.getState().request.facets.map((t=>t.id))}set facetIds(t){let o=[...new Set(t)].map((t=>({id:t})));this.store.actions.setRequestFacets(o)}setFilter(t,o){let r=this.store.getState().request.filters,e={key:t,values:o,negative:!1},n=[...r.filter((o=>o.key!==t)),e];this.setFilters(n)}setLiveQuery(t){this.store.actions.setLiveQuery(t),this.launchSuggest()}setRequest(t){this.store.actions.setRequest(t),this.store.actions.setLiveQuery(t.query),this.store.actions.setPageNumber(1),this.launchSearch()}async launchSearch(){return await this.awaitService(),this.searchDebouncer.run((()=>this.fetchSearchData()))}async launchSuggest(){await this.awaitService(),this.suggestDebouncer.run((()=>this.fetchSuggestData()))}async fetchSearchData(){var t,r;try{null===(t=this.cancelableSearch)||void 0===t||t.cancel(),this.cancelableSearch=e(this.service.launchSearch(this.store.getState().request));const o=await this.cancelableSearch;if(o.paging.currentPage<=1)this.store.actions.setResults(o.results),this.store.actions.setFacets(o.facets),this.store.actions.setSpellcheck(o.spellcheck);else{let t=(null!==(r=this.store.getState().results)&&void 0!==r?r:[]).concat(o.results);this.store.actions.setResults(t)}this.store.actions.setPaging(o.paging)}catch(t){t instanceof o||!this.errorHandler||this.errorHandler(t)}}async fetchSuggestData(){var t;try{let o={input:this.store.getState().liveQuery,filters:this.store.getState().request.filters,sort:this.store.getState().request.sort,contentLocale:this.store.getState().request.contentLocale};null===(t=this.cancelableSuggest)||void 0===t||t.cancel(),this.cancelableSuggest=e(this.service.launchSuggest(o));let r=await this.cancelableSuggest;this.store.actions.setSuggestResults(r.suggestions)}catch(t){t instanceof o||!this.errorHandler||this.errorHandler(t)}}}var fe=function(t,o,r,e){for(var n,i=arguments.length,a=i<3?o:null===e?e=Object.getOwnPropertyDescriptor(o,r):e,s=t.length-1;s>=0;s--)(n=t[s])&&(a=(i<3?n(a):i>3?n(o,r,a):n(o,r))||a);return i>3&&a&&Object.defineProperty(o,r,a),a};class ue extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const he=Symbol("registerInterval");class de extends(function(t){var o;class r extends t{constructor(){super(...arguments),this[o]=0}setSearchStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"search")}clearStateManager(){this.stateManager&&(this.removeStore(this.stateManager.store),this.stateManager=void 0)}connectedCallback(){super.connectedCallback(),this[he]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[he]):this.dispatchEvent(new ue)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return o=he,fe([c()],r.prototype,"stateManager",void 0),r}(Zt)){}var pe=function(t,o,r,e){for(var n,i=arguments.length,a=i<3?o:null===e?e=Object.getOwnPropertyDescriptor(o,r):e,s=t.length-1;s>=0;s--)(n=t[s])&&(a=(i<3?n(a):i>3?n(o,r,a):n(o,r))||a);return i>3&&a&&Object.defineProperty(o,r,a),a};class ye extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class be extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class ge extends CustomEvent{constructor(t,o,r){super("ft-search-results-change",{detail:{request:t,paging:o,spellcheck:r}})}}class me extends Zt{get stateManager(){return null==this._stateManager&&(this._stateManager=le.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"search")),this._stateManager}constructor(){super(),this.query="",this.pageSize=20,this.searchInDocumentTitlesOnly=!1,this.filters=[],this.sort=[],this.addStore(Hr)}render(){return J`
|
|
90
|
+
`}update(t){super.update(t),t.has("baseUrl")&&Hr.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&Hr.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&Hr.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&Hr.actions.setNoCustom(this.noCustom),t.has("editorMode")&&Hr.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&Hr.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&Hr.actions.setSession(this.session),t.has("availableUiLocales")&&Hr.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>Jr.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const o=await t.getCurrentSession();return o.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),o.idleTimeoutInMillis),o}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}te.elementDefinitions={},te.styles=Gr,Qr([s()],te.prototype,"baseUrl",void 0),Qr([s()],te.prototype,"apiIntegrationIdentifier",void 0),Qr([s()],te.prototype,"uiLocale",void 0),Qr([d([])],te.prototype,"availableUiLocales",void 0),Qr([s({type:Boolean})],te.prototype,"editorMode",void 0),Qr([s({type:Boolean})],te.prototype,"noCustom",void 0),Qr([s({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],te.prototype,"noCustomComponent",void 0),Qr([s({type:Boolean})],te.prototype,"withManualResources",void 0),Qr([d([])],te.prototype,"messageContexts",void 0),Qr([d(void 0)],te.prototype,"session",void 0),Qr([s({type:Object})],te.prototype,"apiProvider",void 0);class oe{async listMySearches(){var t;return(null===(t=Hr.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await qr.await()).listMySearches(Hr.getState().session.profile.userId):[]}}const re=new n;class ee{async listMyBookmarks(){return re.get("bookmarks",(async()=>(await qr.await()).listMyBookmarks(Hr.getState().session.profile.userId)))}clearCache(){re.clear("bookmarks")}}const ne=Rr.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const ie=new class{constructor(){this.currentSession=Hr.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new ee,Hr.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:o}=Hr.getState();u(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==o?void 0:o.profile)||(this.currentSession=o,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){ne.actions.savedSearches(void 0)}clearMyBookmarks(){ne.actions.bookmarks(void 0)}async reloadMySearches(){const t=new oe,o=await t.listMySearches();ne.actions.savedSearches(o)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const o=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;ne.actions.bookmarks(o)}}};h("ft-app-context")(te);class ae{static async build(){return new ae(await qr.await())}constructor(t){this.api=t,this.cache=new n,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.api.search(t)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}}const se=t=>t.request.virtualField===Pr.TITLE_ONLY&&t.request.scope===zr.DOCUMENTS;class ce extends Event{constructor(){super(ce.eventName)}}ce.eventName="search-context-clear-all-filters";class le{static build(t){return new le((t=>Rr.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:Ar}))(t.trim()||"context"),ae.build)}constructor(t,o){this.store=t,this.serviceProvider=o,this.searchDebouncer=new i(100),this.suggestDebouncer=new i(300)}async initService(){return this.service=await this.serviceProvider(),this.store.actions.setLocales((await this.service.getAvailableSearchLocales()).contentLocales),this.launchSearch()}async awaitService(){for(;null==this.service;)await f(5);return this.service}setQuery(t){this.store.actions.setRequestQuery(t),this.store.actions.setLiveQuery(t),this.store.actions.setPageNumber(1),this.launchSearch()}setContentLocale(t){let o=this.store.getState().locales,r=this.store.getState().request.contentLocale;if(t!=r){if(o){const e=t=>o.some((o=>o.lang==t));e(t)||(t=e(r)?r:o[0].lang)}this.store.actions.setRequestContentLocale(t),this.store.actions.setPageNumber(1),this.store.actions.setRequestFilters([]),this.launchSearch()}return t}setPageSize(t){this.store.actions.setPageSize(t),this.launchSearch()}setPageNumber(t){this.store.actions.setPageNumber(t),this.launchSearch()}setSort(t){this.store.actions.setRequestSort(t),this.store.actions.setPageNumber(1),this.launchSearch()}setFilters(t){const o=t.filter((t=>t.values.length>0));this.store.actions.setRequestFilters(o),this.store.actions.setPageNumber(1),o.forEach((t=>{this.facetIds.includes(t.key)||(this.facetIds=[...this.facetIds,t.key])})),this.launchSearch()}setSearchInDocumentTitlesOnly(t){t?(this.store.actions.setRequestVirtualField(Pr.TITLE_ONLY),this.store.actions.setRequestScope(zr.DOCUMENTS)):(this.store.actions.setRequestVirtualField(Pr.EVERYWHERE),this.store.actions.setRequestScope(zr.DEFAULT)),this.launchSearch()}get searchInDocumentTitlesOnly(){return se(this.store.getState())}clearAllFilters(){this.setFilters([]),this.store.eventBus.dispatchEvent(new ce)}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,o){let r=this.facetIds.filter((o=>o!=t));o&&r.push(o),this.facetIds=r,this.launchSearch()}get facetIds(){return this.store.getState().request.facets.map((t=>t.id))}set facetIds(t){let o=[...new Set(t)].map((t=>({id:t})));this.store.actions.setRequestFacets(o)}setFilter(t,o){let r=this.store.getState().request.filters,e={key:t,values:o,negative:!1},n=[...r.filter((o=>o.key!==t)),e];this.setFilters(n)}setLiveQuery(t){this.store.actions.setLiveQuery(t),this.launchSuggest()}setRequest(t){this.store.actions.setRequest(t),this.store.actions.setLiveQuery(t.query),this.store.actions.setPageNumber(1),this.launchSearch()}async launchSearch(){return await this.awaitService(),this.searchDebouncer.run((()=>this.fetchSearchData()))}async launchSuggest(){await this.awaitService(),this.suggestDebouncer.run((()=>this.fetchSuggestData()))}async fetchSearchData(){var t,r;try{null===(t=this.cancelableSearch)||void 0===t||t.cancel(),this.cancelableSearch=e(this.service.launchSearch(this.store.getState().request));const o=await this.cancelableSearch;if(o.paging.currentPage<=1)this.store.actions.setResults(o.results),this.store.actions.setFacets(o.facets),this.store.actions.setSpellcheck(o.spellcheck);else{let t=(null!==(r=this.store.getState().results)&&void 0!==r?r:[]).concat(o.results);this.store.actions.setResults(t)}this.store.actions.setPaging(o.paging)}catch(t){t instanceof o||!this.errorHandler||this.errorHandler(t)}}async fetchSuggestData(){var t;try{const o=this.store.getState(),r=o.request,n={input:o.liveQuery,filters:r.filters,sort:r.sort,contentLocale:r.contentLocale,scope:r.scope};null===(t=this.cancelableSuggest)||void 0===t||t.cancel(),this.cancelableSuggest=e(this.service.launchSuggest(n));let i=await this.cancelableSuggest;this.store.actions.setSuggestResults(i.suggestions)}catch(t){t instanceof o||!this.errorHandler||this.errorHandler(t)}}}var fe=function(t,o,r,e){for(var n,i=arguments.length,a=i<3?o:null===e?e=Object.getOwnPropertyDescriptor(o,r):e,s=t.length-1;s>=0;s--)(n=t[s])&&(a=(i<3?n(a):i>3?n(o,r,a):n(o,r))||a);return i>3&&a&&Object.defineProperty(o,r,a),a};class ue extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const he=Symbol("registerInterval");class de extends(function(t){var o;class r extends t{constructor(){super(...arguments),this[o]=0}setSearchStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"search")}clearStateManager(){this.stateManager&&(this.removeStore(this.stateManager.store),this.stateManager=void 0)}connectedCallback(){super.connectedCallback(),this[he]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[he]):this.dispatchEvent(new ue)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return o=he,fe([c()],r.prototype,"stateManager",void 0),r}(Zt)){}var pe=function(t,o,r,e){for(var n,i=arguments.length,a=i<3?o:null===e?e=Object.getOwnPropertyDescriptor(o,r):e,s=t.length-1;s>=0;s--)(n=t[s])&&(a=(i<3?n(a):i>3?n(o,r,a):n(o,r))||a);return i>3&&a&&Object.defineProperty(o,r,a),a};class ye extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class be extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class ge extends CustomEvent{constructor(t,o,r){super("ft-search-results-change",{detail:{request:t,paging:o,spellcheck:r}})}}class me extends Zt{get stateManager(){return null==this._stateManager&&(this._stateManager=le.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"search")),this._stateManager}constructor(){super(),this.query="",this.pageSize=20,this.searchInDocumentTitlesOnly=!1,this.filters=[],this.sort=[],this.addStore(Hr)}render(){return J`
|
|
91
91
|
<slot @register-ft-search-component=${this.registerComponent}></slot>
|
|
92
92
|
`}update(t){super.update(t),t.has("query")&&void 0!==this.query&&this.stateManager.setQuery(this.query),t.has("contentLocale")&&void 0!==this.contentLocale&&this.stateManager.setContentLocale(this.contentLocale),t.has("session")&&this.session&&this.stateManager.initService(),t.has("filters")&&void 0!==this.filters&&this.stateManager.setFilters(this.filters),t.has("sort")&&void 0!==this.sort&&this.stateManager.setSort(this.sort),t.has("pageSize")&&void 0!==this.pageSize&&this.stateManager.setPageSize(this.pageSize),t.has("searchInDocumentTitlesOnly")&&void 0!==this.searchInDocumentTitlesOnly&&this.stateManager.setSearchInDocumentTitlesOnly(this.searchInDocumentTitlesOnly)}connectedCallback(){super.connectedCallback(),this.stateManager.setQuery(this.query),this.stateManager.setContentLocale(this.contentLocale),this.stateManager.setFilters(this.filters),this.stateManager.setPageSize(this.pageSize),this.stateManager.setSort(this.sort)}contentAvailableCallback(t){super.contentAvailableCallback(t),t.has("request")&&this.request&&this.dispatchEvent(new be(this.request)),t.has("paging")&&void 0!==this.paging&&this.dispatchEvent(new ge(this.request,this.paging,this.autocorrect))}registerComponent(t){t.stopPropagation();const o=t.composedPath()[0];this.register(o)}register(t){t.setSearchStateManager(this.stateManager)}handleLoadError(t){this.dispatchEvent(new ye(t))}reloadSavedSearches(){ie.clearMySearches()}}me.elementDefinitions={},me.styles=Ir,pe([s()],me.prototype,"query",void 0),pe([s()],me.prototype,"contentLocale",void 0),pe([s({type:Number})],me.prototype,"pageSize",void 0),pe([s({type:Boolean})],me.prototype,"searchInDocumentTitlesOnly",void 0),pe([d([])],me.prototype,"filters",void 0),pe([d([])],me.prototype,"sort",void 0),pe([xr({store:"search"})],me.prototype,"request",void 0),pe([xr({store:"search"})],me.prototype,"paging",void 0),pe([xr({store:"search",selector:t=>t.spellcheck})],me.prototype,"autocorrect",void 0),pe([xr({store:Hr.name})],me.prototype,"session",void 0),h("ft-search-context")(me),t.ClearAllFiltersEvent=ce,t.FtSearchContext=me,t.FtSearchContextCssVariables={},t.FtSearchStateManager=le,t.LoadErrorEvent=ye,t.SearchRequestChangeEvent=be,t.SearchResultsChangeEvent=ge,t.searchInDocumentTitlesOnlySelector=se,t.styles=Ir}({});
|
|
@@ -168,11 +168,14 @@ export class FtSearchStateManager {
|
|
|
168
168
|
async fetchSuggestData() {
|
|
169
169
|
var _a;
|
|
170
170
|
try {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
const searchState = this.store.getState();
|
|
172
|
+
const searchRequest = searchState.request;
|
|
173
|
+
const request = {
|
|
174
|
+
input: searchState.liveQuery,
|
|
175
|
+
filters: searchRequest.filters,
|
|
176
|
+
sort: searchRequest.sort,
|
|
177
|
+
contentLocale: searchRequest.contentLocale,
|
|
178
|
+
scope: searchRequest.scope,
|
|
176
179
|
};
|
|
177
180
|
(_a = this.cancelableSuggest) === null || _a === void 0 ? void 0 : _a.cancel();
|
|
178
181
|
this.cancelableSuggest = cancelable(this.service.launchSuggest(request));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-search-context",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.63",
|
|
4
4
|
"description": "Context block for integrated search components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lit"
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fluid-topics/ft-app-context": "1.0.
|
|
23
|
-
"@fluid-topics/ft-wc-utils": "1.0.
|
|
22
|
+
"@fluid-topics/ft-app-context": "1.0.63",
|
|
23
|
+
"@fluid-topics/ft-wc-utils": "1.0.63",
|
|
24
24
|
"lit": "2.7.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@fluid-topics/public-api": "1.0.
|
|
27
|
+
"@fluid-topics/public-api": "1.0.50"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "020d13bf82a28437f4d7a7395ad9b628bc4342f1"
|
|
30
30
|
}
|