@fluid-topics/ft-search-context 1.0.28 → 1.0.30
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
|
`,h={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},setResults:(t,s)=>{t.results=s.payload},setFacets:(t,s)=>{t.facets=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}},n=e.css`
|
|
3
3
|
`,r=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 o{static build(t){const{baseUrl:s,apiIntegrationIdentifier:e}=r.getState(),i=null!=t?t:e;if(s&&i&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(s,i,!0)}static get(t){var s;return null!=t?o.build(t):null!==(s=o.API)&&void 0!==s?s:o.API=o.build()}static await(t){return new Promise((s=>{let e=o.get(t);if(e)s(e);else{const i=r.subscribe((()=>{e=o.get(t),e&&(i(),s(e))}))}}))}}var c;const l=Symbol("clearAfterUnitTest");class u{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={},this.currentUiLocale="",this[c]=()=>{this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={}},this.currentUiLocale=r.getState().uiLocale,r.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=r.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,e){var i;if(t=t.toLowerCase(),Object.keys(e).length>0){const a={...null!==(i=this.defaultMessages[t])&&void 0!==i?i:{},...e};s.deepEqual(this.defaultMessages[t],a)||(this.defaultMessages[t]=a,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,e,...i){var a,h,n;t=t.toLowerCase(),this.fetchContext(t);const r=null!==(h=null===(a=this.cache.getNow(t))||void 0===a?void 0:a.messages)&&void 0!==h?h:{};return new s.ParametrizedLabelResolver(null!==(n=this.defaultMessages[t])&&void 0!==n?n:{},r).resolve(e,...i)}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 e;return t=t.toLowerCase(),this.listeners[t]=null!==(e=this.listeners[t])&&void 0!==e?e:new Set,this.listeners[t].add(s),()=>{var e;return null===(e=this.listeners[t])||void 0===e?void 0:e.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)))))}}c=l,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new u((async(t,s)=>(await o.await()).getFluidTopicsMessageContext(t,s)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new u((async(t,s)=>(await o.await()).getCustomMessageContext(t,s))));const d=window.FluidTopicsI18nService;var v=function(t,s,e,i){for(var a,h=arguments.length,n=h<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,r=t.length-1;r>=0;r--)(a=t[r])&&(n=(h<3?a(n):h>3?a(s,e,n):a(s,e))||n);return h>3&&n&&Object.defineProperty(s,e,n),n};class w 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=()=>o.get(),this.cache=new s.CacheRegistry,this.cleanSessionDebouncer=new s.Debouncer}render(){return e.html`
|
|
4
4
|
<slot></slot>
|
|
5
|
-
`}updated(t){super.updated(t),t.has("baseUrl")&&r.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&r.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&r.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&r.actions.setNoCustom(this.noCustom),t.has("editorMode")&&r.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&r.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&r.actions.setSession(this.session),t.has("availableUiLocales")&&r.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>d.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()))))}}w.elementDefinitions={},w.styles=n,v([i.property()],w.prototype,"baseUrl",void 0),v([i.property()],w.prototype,"apiIntegrationIdentifier",void 0),v([i.property()],w.prototype,"uiLocale",void 0),v([s.jsonProperty([])],w.prototype,"availableUiLocales",void 0),v([i.property({type:Boolean})],w.prototype,"editorMode",void 0),v([i.property({type:Boolean})],w.prototype,"noCustom",void 0),v([i.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],w.prototype,"noCustomComponent",void 0),v([i.property({type:Boolean})],w.prototype,"withManualResources",void 0),v([s.jsonProperty([])],w.prototype,"messageContexts",void 0),v([s.jsonProperty(void 0)],w.prototype,"session",void 0),v([i.property({type:Object})],w.prototype,"apiProvider",void 0),s.customElement("ft-app-context")(w);class f{static async build(){return new f(await o.await())}constructor(t){this.api=t,this.cache=new s.CacheRegistry,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.cache.get(`search-${this.hash(t)}`,(()=>this.api.search(t)),18e4)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}hash(t){return JSON.stringify(t).split("").reduce(((t,s)=>(t<<5)-t+s.charCodeAt(0)|0),0)}}class g{static build(t){return new g((t=>s.FtReduxStore.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:h}))(t.trim()||"context"),f.build)}constructor(t,e){this.store=t,this.serviceProvider=e,this.searchDebouncer=new s.Debouncer(10),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,e=this.store.getState().request.contentLocale;if(t!=e){if(s){const i=t=>s.some((s=>s.lang==t));i(t)||(t=i(e)?e: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){this.store.actions.setRequestFilters(
|
|
5
|
+
`}updated(t){super.updated(t),t.has("baseUrl")&&r.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&r.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&r.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&r.actions.setNoCustom(this.noCustom),t.has("editorMode")&&r.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&r.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&r.actions.setSession(this.session),t.has("availableUiLocales")&&r.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>d.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()))))}}w.elementDefinitions={},w.styles=n,v([i.property()],w.prototype,"baseUrl",void 0),v([i.property()],w.prototype,"apiIntegrationIdentifier",void 0),v([i.property()],w.prototype,"uiLocale",void 0),v([s.jsonProperty([])],w.prototype,"availableUiLocales",void 0),v([i.property({type:Boolean})],w.prototype,"editorMode",void 0),v([i.property({type:Boolean})],w.prototype,"noCustom",void 0),v([i.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],w.prototype,"noCustomComponent",void 0),v([i.property({type:Boolean})],w.prototype,"withManualResources",void 0),v([s.jsonProperty([])],w.prototype,"messageContexts",void 0),v([s.jsonProperty(void 0)],w.prototype,"session",void 0),v([i.property({type:Object})],w.prototype,"apiProvider",void 0),s.customElement("ft-app-context")(w);class f{static async build(){return new f(await o.await())}constructor(t){this.api=t,this.cache=new s.CacheRegistry,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.cache.get(`search-${this.hash(t)}`,(()=>this.api.search(t)),18e4)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}hash(t){return JSON.stringify(t).split("").reduce(((t,s)=>(t<<5)-t+s.charCodeAt(0)|0),0)}}class g{static build(t){return new g((t=>s.FtReduxStore.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:h}))(t.trim()||"context"),f.build)}constructor(t,e){this.store=t,this.serviceProvider=e,this.searchDebouncer=new s.Debouncer(10),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,e=this.store.getState().request.contentLocale;if(t!=e){if(s){const i=t=>s.some((s=>s.lang==t));i(t)||(t=i(e)?e: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()}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,s){let e=this.facetIds.filter((s=>s!=t));s&&e.push(s),this.facetIds=e,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 e=this.store.getState().request.filters,i={key:t,values:s,negative:!1},a=[...e.filter((s=>s.key!==t)),i];this.setFilters(a)}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;try{let s=await this.service.launchSearch(this.store.getState().request);if(s.paging.currentPage<=1)this.store.actions.setResults(s.results),this.store.actions.setFacets(s.facets);else{let e=(null!==(t=this.store.getState().results)&&void 0!==t?t:[]).concat(s.results);this.store.actions.setResults(e)}this.store.actions.setPaging(s.paging)}catch(t){this.errorHandler&&this.errorHandler(t)}}async fetchSuggestData(){try{let t={input:this.store.getState().liveQuery,filters:this.store.getState().request.filters,sort:this.store.getState().request.sort,contentLocale:this.store.getState().request.contentLocale},s=await this.service.launchSuggest(t);this.store.actions.setSuggestResults(s.suggestions)}catch(t){this.errorHandler&&this.errorHandler(t)}}}var p=function(t,s,e,i){for(var a,h=arguments.length,n=h<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,r=t.length-1;r>=0;r--)(a=t[r])&&(n=(h<3?a(n):h>3?a(s,e,n):a(s,e))||n);return h>3&&n&&Object.defineProperty(s,e,n),n};class y extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const b=Symbol("registerInterval");class S extends(function(t){var s;class e 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[b]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[b]):this.dispatchEvent(new y)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return s=b,p([i.state()],e.prototype,"stateManager",void 0),e}(s.FtLitElementRedux)){}class m{async listMySearches(){var t;return(null===(t=r.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await o.await()).listMySearches(r.getState().session.profile.userId):[]}}const C=s.FtReduxStore.get({name:"ft-user-assets",reducers:{setSavedSearches:(t,s)=>{t.savedSearches=s.payload}},initialState:{savedSearches:void 0}});const L=new class{clear(){this.clearMySearches()}clearMySearches(){C.actions.setSavedSearches(void 0)}async reloadMySearches(){const t=new m,s=await t.listMySearches();C.actions.setSavedSearches(s)}};var x=function(t,s,e,i){for(var a,h=arguments.length,n=h<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,r=t.length-1;r>=0;r--)(a=t[r])&&(n=(h<3?a(n):h>3?a(s,e,n):a(s,e))||n);return h>3&&n&&Object.defineProperty(s,e,n),n};class M extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class q extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class U extends s.FtLitElementRedux{get stateManager(){return null==this._stateManager&&(this._stateManager=g.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.filters=[],this.sort=[],this.addStore(r)}render(){return e.html`
|
|
6
6
|
<slot @register-ft-search-component=${this.registerComponent}></slot>
|
|
7
7
|
`}updated(t){super.updated(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(),this.session.sessionAuthenticated||L.clear()),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)}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 q(this.request))}registerComponent(t){t.stopPropagation();const s=t.composedPath()[0];this.register(s)}register(t){t.setSearchStateManager(this.stateManager)}handleLoadError(t){this.dispatchEvent(new M(t))}reloadSavedSearches(){L.clearMySearches()}}U.elementDefinitions={},U.styles=a,x([i.property()],U.prototype,"query",void 0),x([i.property()],U.prototype,"contentLocale",void 0),x([i.property({type:Number})],U.prototype,"pageSize",void 0),x([s.jsonProperty([])],U.prototype,"filters",void 0),x([s.jsonProperty([])],U.prototype,"sort",void 0),x([s.redux({store:"search"})],U.prototype,"request",void 0),x([s.redux({store:r.name})],U.prototype,"session",void 0),s.customElement("ft-search-context")(U),t.FtSearchContext=U,t.FtSearchContextCssVariables={},t.LoadErrorEvent=M,t.SearchRequestChangeEvent=q,t.styles=a}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);
|
|
@@ -87,6 +87,6 @@ var dt,vt;let pt=class extends A{constructor(){super(...arguments),this.renderOp
|
|
|
87
87
|
`,ji={setRequest:(t,e)=>{t.request=e.payload},setRequestQuery:(t,e)=>{t.request.query=e.payload},setRequestContentLocale:(t,e)=>{t.request.contentLocale=e.payload},setPageSize:(t,e)=>{t.request.paging.perPage=e.payload},setPageNumber:(t,e)=>{t.request.paging.page=e.payload},setRequestSort:(t,e)=>{t.request.sort=e.payload},setRequestFilters:(t,e)=>{t.request.filters=e.payload},setRequestFacets:(t,e)=>{t.request.facets=e.payload},setResults:(t,e)=>{t.results=e.payload},setFacets:(t,e)=>{t.facets=e.payload},setLocales:(t,e)=>{t.locales=e.payload},setPaging:(t,e)=>{t.paging=e.payload},setLiveQuery:(t,e)=>{t.liveQuery=e.payload},setSuggestResults:(t,e)=>{t.suggestResults=e.payload}},Ei=m`
|
|
88
88
|
`,Ci=gi.get({name:"ft-app-info",reducers:{setBaseUrl:(t,e)=>{t.baseUrl=e.payload},setApiIntegrationIdentifier:(t,e)=>{t.apiIntegrationIdentifier=e.payload},setUiLocale:(t,e)=>{t.uiLocale=e.payload},setAvailableUiLocales:(t,e)=>{t.availableUiLocales=e.payload},setEditorMode:(t,e)=>{t.editorMode=e.payload},setNoCustom:(t,e)=>{t.noCustom=e.payload},setNoCustomComponent:(t,e)=>{t.noCustomComponent=e.payload},setSession:(t,e)=>{t.session=e.payload}},initialState:{uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],editorMode:!1,noCustom:!1,noCustomComponent:!1}});class Ri{static build(t){const{baseUrl:e,apiIntegrationIdentifier:i}=Ci.getState(),n=null!=t?t:i;if(e&&n&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(e,n,!0)}static get(t){var e;return null!=t?Ri.build(t):null!==(e=Ri.API)&&void 0!==e?e:Ri.API=Ri.build()}static await(t){return new Promise((e=>{let i=Ri.get(t);if(i)e(i);else{const n=Ci.subscribe((()=>{i=Ri.get(t),i&&(n(),e(i))}))}}))}}var Ni;const Mi=Symbol("clearAfterUnitTest");class Ai{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new n,this.listeners={},this.currentUiLocale="",this[Ni]=()=>{this.defaultMessages={},this.cache=new n,this.listeners={}},this.currentUiLocale=Ci.getState().uiLocale,Ci.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=Ci.getState();this.currentUiLocale!==t&&(this.currentUiLocale=t,this.cache.clearAll(),this.notifyAll())}addContext(t){const e=t.name.toLowerCase();this.cache.setFinal(e,t),this.notify(e)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(t,e){var i;if(t=t.toLowerCase(),Object.keys(e).length>0){const n={...null!==(i=this.defaultMessages[t])&&void 0!==i?i:{},...e};l(this.defaultMessages[t],n)||(this.defaultMessages[t]=n,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,e,...i){var n,r,o;t=t.toLowerCase(),this.fetchContext(t);const s=null!==(r=null===(n=this.cache.getNow(t))||void 0===n?void 0:n.messages)&&void 0!==r?r:{};return new Et(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},s).resolve(e,...i)}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,e){var i;return t=t.toLowerCase(),this.listeners[t]=null!==(i=this.listeners[t])&&void 0!==i?i:new Set,this.listeners[t].add(e),()=>{var i;return null===(i=this.listeners[t])||void 0===i?void 0:i.delete(e)}}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=>c(0).then((()=>t())).catch((()=>null)))))}}Ni=Mi,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new Ai((async(t,e)=>(await Ri.await()).getFluidTopicsMessageContext(t,e)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new Ai((async(t,e)=>(await Ri.await()).getCustomMessageContext(t,e))));const ki=window.FluidTopicsI18nService;var Ui=function(t,e,i,n){for(var r,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n,u=t.length-1;u>=0;u--)(r=t[u])&&(s=(o<3?r(s):o>3?r(e,i,s):r(e,i))||s);return o>3&&s&&Object.defineProperty(e,i,s),s};class Li extends jt{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=()=>Ri.get(),this.cache=new n,this.cleanSessionDebouncer=new r}render(){return X`
|
|
89
89
|
<slot></slot>
|
|
90
|
-
`}updated(t){super.updated(t),t.has("baseUrl")&&Ci.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&Ci.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&Ci.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&Ci.actions.setNoCustom(this.noCustom),t.has("editorMode")&&Ci.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&Ci.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&Ci.actions.setSession(this.session),t.has("availableUiLocales")&&Ci.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>ki.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 e=await t.getCurrentSession();return e.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),e.idleTimeoutInMillis),e}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}Li.elementDefinitions={},Li.styles=Ei,Ui([s()],Li.prototype,"baseUrl",void 0),Ui([s()],Li.prototype,"apiIntegrationIdentifier",void 0),Ui([s()],Li.prototype,"uiLocale",void 0),Ui([f([])],Li.prototype,"availableUiLocales",void 0),Ui([s({type:Boolean})],Li.prototype,"editorMode",void 0),Ui([s({type:Boolean})],Li.prototype,"noCustom",void 0),Ui([s({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],Li.prototype,"noCustomComponent",void 0),Ui([s({type:Boolean})],Li.prototype,"withManualResources",void 0),Ui([f([])],Li.prototype,"messageContexts",void 0),Ui([f(void 0)],Li.prototype,"session",void 0),Ui([s({type:Object})],Li.prototype,"apiProvider",void 0),h("ft-app-context")(Li);class Pi{static async build(){return new Pi(await Ri.await())}constructor(t){this.api=t,this.cache=new n,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.cache.get(`search-${this.hash(t)}`,(()=>this.api.search(t)),18e4)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}hash(t){return JSON.stringify(t).split("").reduce(((t,e)=>(t<<5)-t+e.charCodeAt(0)|0),0)}}class $i{static build(t){return new $i((t=>gi.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:ji}))(t.trim()||"context"),Pi.build)}constructor(t,e){this.store=t,this.serviceProvider=e,this.searchDebouncer=new r(10),this.suggestDebouncer=new r(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 c(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 e=this.store.getState().locales,i=this.store.getState().request.contentLocale;if(t!=i){if(e){const n=t=>e.some((e=>e.lang==t));n(t)||(t=n(i)?i:e[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){this.store.actions.setRequestFilters(
|
|
90
|
+
`}updated(t){super.updated(t),t.has("baseUrl")&&Ci.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&Ci.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&Ci.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&Ci.actions.setNoCustom(this.noCustom),t.has("editorMode")&&Ci.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&Ci.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&Ci.actions.setSession(this.session),t.has("availableUiLocales")&&Ci.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>ki.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 e=await t.getCurrentSession();return e.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),e.idleTimeoutInMillis),e}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}Li.elementDefinitions={},Li.styles=Ei,Ui([s()],Li.prototype,"baseUrl",void 0),Ui([s()],Li.prototype,"apiIntegrationIdentifier",void 0),Ui([s()],Li.prototype,"uiLocale",void 0),Ui([f([])],Li.prototype,"availableUiLocales",void 0),Ui([s({type:Boolean})],Li.prototype,"editorMode",void 0),Ui([s({type:Boolean})],Li.prototype,"noCustom",void 0),Ui([s({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],Li.prototype,"noCustomComponent",void 0),Ui([s({type:Boolean})],Li.prototype,"withManualResources",void 0),Ui([f([])],Li.prototype,"messageContexts",void 0),Ui([f(void 0)],Li.prototype,"session",void 0),Ui([s({type:Object})],Li.prototype,"apiProvider",void 0),h("ft-app-context")(Li);class Pi{static async build(){return new Pi(await Ri.await())}constructor(t){this.api=t,this.cache=new n,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.cache.get(`search-${this.hash(t)}`,(()=>this.api.search(t)),18e4)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}hash(t){return JSON.stringify(t).split("").reduce(((t,e)=>(t<<5)-t+e.charCodeAt(0)|0),0)}}class $i{static build(t){return new $i((t=>gi.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:ji}))(t.trim()||"context"),Pi.build)}constructor(t,e){this.store=t,this.serviceProvider=e,this.searchDebouncer=new r(10),this.suggestDebouncer=new r(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 c(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 e=this.store.getState().locales,i=this.store.getState().request.contentLocale;if(t!=i){if(e){const n=t=>e.some((e=>e.lang==t));n(t)||(t=n(i)?i:e[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 e=t.filter((t=>t.values.length>0));this.store.actions.setRequestFilters(e),this.store.actions.setPageNumber(1),e.forEach((t=>{this.facetIds.includes(t.key)||(this.facetIds=[...this.facetIds,t.key])})),this.launchSearch()}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,e){let i=this.facetIds.filter((e=>e!=t));e&&i.push(e),this.facetIds=i,this.launchSearch()}get facetIds(){return this.store.getState().request.facets.map((t=>t.id))}set facetIds(t){let e=[...new Set(t)].map((t=>({id:t})));this.store.actions.setRequestFacets(e)}setFilter(t,e){let i=this.store.getState().request.filters,n={key:t,values:e,negative:!1},r=[...i.filter((e=>e.key!==t)),n];this.setFilters(r)}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;try{let e=await this.service.launchSearch(this.store.getState().request);if(e.paging.currentPage<=1)this.store.actions.setResults(e.results),this.store.actions.setFacets(e.facets);else{let i=(null!==(t=this.store.getState().results)&&void 0!==t?t:[]).concat(e.results);this.store.actions.setResults(i)}this.store.actions.setPaging(e.paging)}catch(t){this.errorHandler&&this.errorHandler(t)}}async fetchSuggestData(){try{let t={input:this.store.getState().liveQuery,filters:this.store.getState().request.filters,sort:this.store.getState().request.sort,contentLocale:this.store.getState().request.contentLocale},e=await this.service.launchSuggest(t);this.store.actions.setSuggestResults(e.suggestions)}catch(t){this.errorHandler&&this.errorHandler(t)}}}var Fi=function(t,e,i,n){for(var r,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n,u=t.length-1;u>=0;u--)(r=t[u])&&(s=(o<3?r(s):o>3?r(e,i,s):r(e,i))||s);return o>3&&s&&Object.defineProperty(e,i,s),s};class Ii extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const _i=Symbol("registerInterval");class Ti extends(function(t){var e;class i extends t{constructor(){super(...arguments),this[e]=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[_i]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[_i]):this.dispatchEvent(new Ii)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return e=_i,Fi([u()],i.prototype,"stateManager",void 0),i}(wi)){}class Bi{async listMySearches(){var t;return(null===(t=Ci.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await Ri.await()).listMySearches(Ci.getState().session.profile.userId):[]}}const qi=gi.get({name:"ft-user-assets",reducers:{setSavedSearches:(t,e)=>{t.savedSearches=e.payload}},initialState:{savedSearches:void 0}});const Wi=new class{clear(){this.clearMySearches()}clearMySearches(){qi.actions.setSavedSearches(void 0)}async reloadMySearches(){const t=new Bi,e=await t.listMySearches();qi.actions.setSavedSearches(e)}};var Ki=function(t,e,i,n){for(var r,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n,u=t.length-1;u>=0;u--)(r=t[u])&&(s=(o<3?r(s):o>3?r(e,i,s):r(e,i))||s);return o>3&&s&&Object.defineProperty(e,i,s),s};class Di extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class zi extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class Hi extends wi{get stateManager(){return null==this._stateManager&&(this._stateManager=$i.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.filters=[],this.sort=[],this.addStore(Ci)}render(){return X`
|
|
91
91
|
<slot @register-ft-search-component=${this.registerComponent}></slot>
|
|
92
92
|
`}updated(t){super.updated(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(),this.session.sessionAuthenticated||Wi.clear()),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)}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 zi(this.request))}registerComponent(t){t.stopPropagation();const e=t.composedPath()[0];this.register(e)}register(t){t.setSearchStateManager(this.stateManager)}handleLoadError(t){this.dispatchEvent(new Di(t))}reloadSavedSearches(){Wi.clearMySearches()}}Hi.elementDefinitions={},Hi.styles=Si,Ki([s()],Hi.prototype,"query",void 0),Ki([s()],Hi.prototype,"contentLocale",void 0),Ki([s({type:Number})],Hi.prototype,"pageSize",void 0),Ki([f([])],Hi.prototype,"filters",void 0),Ki([f([])],Hi.prototype,"sort",void 0),Ki([pi({store:"search"})],Hi.prototype,"request",void 0),Ki([pi({store:Ci.name})],Hi.prototype,"session",void 0),h("ft-search-context")(Hi),t.FtSearchContext=Hi,t.FtSearchContextCssVariables={},t.LoadErrorEvent=Di,t.SearchRequestChangeEvent=zi,t.styles=Si}({});
|
|
@@ -59,9 +59,10 @@ export class FtSearchStateManager {
|
|
|
59
59
|
this.launchSearch();
|
|
60
60
|
}
|
|
61
61
|
setFilters(filters) {
|
|
62
|
-
|
|
62
|
+
const cleanFilters = filters.filter(filter => filter.values.length > 0);
|
|
63
|
+
this.store.actions.setRequestFilters(cleanFilters);
|
|
63
64
|
this.store.actions.setPageNumber(1);
|
|
64
|
-
|
|
65
|
+
cleanFilters.forEach(f => {
|
|
65
66
|
if (!this.facetIds.includes(f.key)) {
|
|
66
67
|
this.facetIds = [...this.facetIds, f.key];
|
|
67
68
|
}
|
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.30",
|
|
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.30",
|
|
23
|
+
"@fluid-topics/ft-wc-utils": "1.0.30",
|
|
24
24
|
"lit": "2.7.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@fluid-topics/public-api": "1.0.38"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "72be58696ee1a1c080a094809e9c20e47d9ead73"
|
|
30
30
|
}
|