@fluid-topics/ft-search-context 1.0.14 → 1.0.16
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
|
`,n={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}},h=e.css`
|
|
3
3
|
`,o=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 r{static build(t){const{baseUrl:s,apiIntegrationIdentifier:e}=o.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?r.build(t):null!==(s=r.API)&&void 0!==s?s:r.API=r.build()}static await(t){return new Promise((s=>{let e=r.get(t);if(e)s(e);else{const i=o.subscribe((()=>{e=r.get(t),e&&(i(),s(e))}))}}))}}var l;const c=Symbol("clearAfterUnitTest");class u{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={},this.currentUiLocale="",this[l]=()=>{this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={}},this.currentUiLocale=o.getState().uiLocale,o.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=o.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,n,h;t=t.toLowerCase(),this.fetchContext(t);const o=null!==(n=null===(a=this.cache.getNow(t))||void 0===a?void 0:a.messages)&&void 0!==n?n:{};return new s.ParametrizedLabelResolver(null!==(h=this.defaultMessages[t])&&void 0!==h?h:{},o).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)))))}}l=c,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new u((async(t,s)=>(await r.await()).getFluidTopicsMessageContext(t,s)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new u((async(t,s)=>(await r.await()).getCustomMessageContext(t,s))));const d=window.FluidTopicsI18nService;var v=function(t,s,e,i){for(var a,n=arguments.length,h=n<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,o=t.length-1;o>=0;o--)(a=t[o])&&(h=(n<3?a(h):n>3?a(s,e,h):a(s,e))||h);return n>3&&h&&Object.defineProperty(s,e,h),h};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=()=>r.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")&&o.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&o.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&o.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&o.actions.setNoCustom(this.noCustom),t.has("editorMode")&&o.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&o.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&o.actions.setSession(this.session),t.has("availableUiLocales")&&o.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=h,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 r.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:n}))(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
|
|
5
|
+
`}updated(t){super.updated(t),t.has("baseUrl")&&o.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&o.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&o.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&o.actions.setNoCustom(this.noCustom),t.has("editorMode")&&o.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&o.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&o.actions.setSession(this.session),t.has("availableUiLocales")&&o.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=h,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 r.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:n}))(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.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(t),this.store.actions.setPageNumber(1),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()}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,n=arguments.length,h=n<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,o=t.length-1;o>=0;o--)(a=t[o])&&(h=(n<3?a(h):n>3?a(s,e,h):a(s,e))||h);return n>3&&h&&Object.defineProperty(s,e,h),h};class b extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const y=Symbol("registerInterval");class m 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[y]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[y]):this.dispatchEvent(new b)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return s=y,p([i.state()],e.prototype,"stateManager",void 0),e}(s.FtLitElementRedux)){}var S=function(t,s,e,i){for(var a,n=arguments.length,h=n<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,o=t.length-1;o>=0;o--)(a=t[o])&&(h=(n<3?a(h):n>3?a(s,e,h):a(s,e))||h);return n>3&&h&&Object.defineProperty(s,e,h),h};class C extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class L extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class x 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.contentLocale="en-US",this.pageSize=20,this.filters=[],this.sort=[],this.addStore(o)}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(),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 L(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 C(t))}}x.elementDefinitions={},x.styles=a,S([i.property()],x.prototype,"query",void 0),S([i.property()],x.prototype,"contentLocale",void 0),S([i.property({type:Number})],x.prototype,"pageSize",void 0),S([s.jsonProperty([])],x.prototype,"filters",void 0),S([s.jsonProperty([])],x.prototype,"sort",void 0),S([s.redux({store:"search"})],x.prototype,"request",void 0),S([s.redux({store:o.name})],x.prototype,"session",void 0),s.customElement("ft-search-context")(x),t.FtSearchContext=x,t.FtSearchContextCssVariables={},t.LoadErrorEvent=C,t.SearchRequestChangeEvent=L,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
|
`,En={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}},Cn=m`
|
|
88
88
|
`,Nn=xn.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 Rn{static build(t){const{baseUrl:e,apiIntegrationIdentifier:n}=Nn.getState(),i=null!=t?t:n;if(e&&i&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(e,i,!0)}static get(t){var e;return null!=t?Rn.build(t):null!==(e=Rn.API)&&void 0!==e?e:Rn.API=Rn.build()}static await(t){return new Promise((e=>{let n=Rn.get(t);if(n)e(n);else{const i=Nn.subscribe((()=>{n=Rn.get(t),n&&(i(),e(n))}))}}))}}var Mn;const An=Symbol("clearAfterUnitTest");class Un{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new i,this.listeners={},this.currentUiLocale="",this[Mn]=()=>{this.defaultMessages={},this.cache=new i,this.listeners={}},this.currentUiLocale=Nn.getState().uiLocale,Nn.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=Nn.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 n;if(t=t.toLowerCase(),Object.keys(e).length>0){const i={...null!==(n=this.defaultMessages[t])&&void 0!==n?n:{},...e};l(this.defaultMessages[t],i)||(this.defaultMessages[t]=i,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,e,...n){var i,r,o;t=t.toLowerCase(),this.fetchContext(t);const s=null!==(r=null===(i=this.cache.getNow(t))||void 0===i?void 0:i.messages)&&void 0!==r?r:{};return new Et(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},s).resolve(e,...n)}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 n;return t=t.toLowerCase(),this.listeners[t]=null!==(n=this.listeners[t])&&void 0!==n?n:new Set,this.listeners[t].add(e),()=>{var n;return null===(n=this.listeners[t])||void 0===n?void 0:n.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)))))}}Mn=An,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new Un((async(t,e)=>(await Rn.await()).getFluidTopicsMessageContext(t,e)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new Un((async(t,e)=>(await Rn.await()).getCustomMessageContext(t,e))));const kn=window.FluidTopicsI18nService;var Ln=function(t,e,n,i){for(var r,o=arguments.length,s=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i,u=t.length-1;u>=0;u--)(r=t[u])&&(s=(o<3?r(s):o>3?r(e,n,s):r(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s};class Pn 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=()=>Rn.get(),this.cache=new i,this.cleanSessionDebouncer=new r}render(){return X`
|
|
89
89
|
<slot></slot>
|
|
90
|
-
`}updated(t){super.updated(t),t.has("baseUrl")&&Nn.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&Nn.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&Nn.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&Nn.actions.setNoCustom(this.noCustom),t.has("editorMode")&&Nn.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&Nn.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&Nn.actions.setSession(this.session),t.has("availableUiLocales")&&Nn.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>kn.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()))))}}Pn.elementDefinitions={},Pn.styles=Cn,Ln([s()],Pn.prototype,"baseUrl",void 0),Ln([s()],Pn.prototype,"apiIntegrationIdentifier",void 0),Ln([s()],Pn.prototype,"uiLocale",void 0),Ln([f([])],Pn.prototype,"availableUiLocales",void 0),Ln([s({type:Boolean})],Pn.prototype,"editorMode",void 0),Ln([s({type:Boolean})],Pn.prototype,"noCustom",void 0),Ln([s({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],Pn.prototype,"noCustomComponent",void 0),Ln([s({type:Boolean})],Pn.prototype,"withManualResources",void 0),Ln([f([])],Pn.prototype,"messageContexts",void 0),Ln([f(void 0)],Pn.prototype,"session",void 0),Ln([s({type:Object})],Pn.prototype,"apiProvider",void 0),h("ft-app-context")(Pn);class $n{static async build(){return new $n(await Rn.await())}constructor(t){this.api=t,this.cache=new i,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 Fn{static build(t){return new Fn((t=>xn.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:En}))(t.trim()||"context"),$n.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,n=this.store.getState().request.contentLocale;if(t!=n){if(e){const i=t=>e.some((e=>e.lang
|
|
90
|
+
`}updated(t){super.updated(t),t.has("baseUrl")&&Nn.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&Nn.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&Nn.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&Nn.actions.setNoCustom(this.noCustom),t.has("editorMode")&&Nn.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&Nn.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&Nn.actions.setSession(this.session),t.has("availableUiLocales")&&Nn.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>kn.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()))))}}Pn.elementDefinitions={},Pn.styles=Cn,Ln([s()],Pn.prototype,"baseUrl",void 0),Ln([s()],Pn.prototype,"apiIntegrationIdentifier",void 0),Ln([s()],Pn.prototype,"uiLocale",void 0),Ln([f([])],Pn.prototype,"availableUiLocales",void 0),Ln([s({type:Boolean})],Pn.prototype,"editorMode",void 0),Ln([s({type:Boolean})],Pn.prototype,"noCustom",void 0),Ln([s({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],Pn.prototype,"noCustomComponent",void 0),Ln([s({type:Boolean})],Pn.prototype,"withManualResources",void 0),Ln([f([])],Pn.prototype,"messageContexts",void 0),Ln([f(void 0)],Pn.prototype,"session",void 0),Ln([s({type:Object})],Pn.prototype,"apiProvider",void 0),h("ft-app-context")(Pn);class $n{static async build(){return new $n(await Rn.await())}constructor(t){this.api=t,this.cache=new i,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 Fn{static build(t){return new Fn((t=>xn.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:En}))(t.trim()||"context"),$n.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,n=this.store.getState().request.contentLocale;if(t!=n){if(e){const i=t=>e.some((e=>e.lang==t));i(t)||(t=i(n)?n:e[0].lang)}this.store.actions.setRequestContentLocale(t),this.store.actions.setPageNumber(1),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(t),this.store.actions.setPageNumber(1),this.launchSearch()}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,e){let n=this.facetIds.filter((e=>e!=t));e&&n.push(e),this.facetIds=n,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 n=this.store.getState().request.filters,i={key:t,values:e,negative:!1},r=[...n.filter((e=>e.key!==t)),i];this.setFilters(r)}setLiveQuery(t){this.store.actions.setLiveQuery(t),this.launchSuggest()}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 n=(null!==(t=this.store.getState().results)&&void 0!==t?t:[]).concat(e.results);this.store.actions.setResults(n)}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 In=function(t,e,n,i){for(var r,o=arguments.length,s=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i,u=t.length-1;u>=0;u--)(r=t[u])&&(s=(o<3?r(s):o>3?r(e,n,s):r(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s};class _n extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const Tn=Symbol("registerInterval");class Bn extends(function(t){var e;class n 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[Tn]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[Tn]):this.dispatchEvent(new _n)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return e=Tn,In([u()],n.prototype,"stateManager",void 0),n}(mn)){}var Wn=function(t,e,n,i){for(var r,o=arguments.length,s=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i,u=t.length-1;u>=0;u--)(r=t[u])&&(s=(o<3?r(s):o>3?r(e,n,s):r(e,n))||s);return o>3&&s&&Object.defineProperty(e,n,s),s};class qn extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class Kn extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class Dn extends mn{get stateManager(){return null==this._stateManager&&(this._stateManager=Fn.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.contentLocale="en-US",this.pageSize=20,this.filters=[],this.sort=[],this.addStore(Nn)}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(),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 Kn(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 qn(t))}}Dn.elementDefinitions={},Dn.styles=jn,Wn([s()],Dn.prototype,"query",void 0),Wn([s()],Dn.prototype,"contentLocale",void 0),Wn([s({type:Number})],Dn.prototype,"pageSize",void 0),Wn([f([])],Dn.prototype,"filters",void 0),Wn([f([])],Dn.prototype,"sort",void 0),Wn([bn({store:"search"})],Dn.prototype,"request",void 0),Wn([bn({store:Nn.name})],Dn.prototype,"session",void 0),h("ft-search-context")(Dn),t.FtSearchContext=Dn,t.FtSearchContextCssVariables={},t.LoadErrorEvent=qn,t.SearchRequestChangeEvent=Kn,t.styles=jn}({});
|
|
@@ -33,7 +33,7 @@ export class FtSearchStateManager {
|
|
|
33
33
|
let previousContentLocale = this.store.getState().request.contentLocale;
|
|
34
34
|
if (contentLocale != previousContentLocale) {
|
|
35
35
|
if (locales) {
|
|
36
|
-
const isKnown = (locale) => locales.some(l => l.lang
|
|
36
|
+
const isKnown = (locale) => locales.some(l => l.lang == locale);
|
|
37
37
|
if (!isKnown(contentLocale)) {
|
|
38
38
|
contentLocale = isKnown(previousContentLocale) ? previousContentLocale : locales[0].lang;
|
|
39
39
|
}
|
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.16",
|
|
4
4
|
"description": "Context block for integrated search components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lit"
|
|
@@ -19,8 +19,8 @@
|
|
|
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.16",
|
|
23
|
+
"@fluid-topics/ft-wc-utils": "1.0.16",
|
|
24
24
|
"lit": "2.7.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@fluid-topics/public-api": "1.0.34"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "7be717d495eed779d0d9ffc489451b28b47df314"
|
|
33
33
|
}
|