@fluid-topics/ft-search-context 1.0.20 → 1.0.22
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
!function(t,s,e,i){const a=e.css`
|
|
2
|
-
`,
|
|
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
|
|
2
|
+
`,h={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
|
+
`,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,h,n;t=t.toLowerCase(),this.fetchContext(t);const o=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:{},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,h=arguments.length,n=h<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,o=t.length-1;o>=0;o--)(a=t[o])&&(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=()=>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=
|
|
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=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 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: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(t),this.store.actions.setPageNumber(1),t.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()}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,o=t.length-1;o>=0;o--)(a=t[o])&&(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 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,h=arguments.length,n=h<3?s:null===i?i=Object.getOwnPropertyDescriptor(s,e):i,o=t.length-1;o>=0;o--)(a=t[o])&&(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 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);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @see https://github.com/webcomponents/polyfills/tree/master/packages/scoped-custom-element-registry
|
|
16
16
|
*/
|
|
17
|
-
if(!ShadowRoot.prototype.createElement){const t=window.HTMLElement,e=window.customElements.define,n=window.customElements.get,i=window.customElements,r=new WeakMap,o=new WeakMap,s=new WeakMap,u=new WeakMap;let a;window.CustomElementRegistry=class{constructor(){this._definitionsByTag=new Map,this._definitionsByClass=new Map,this._whenDefinedPromises=new Map,this._awaitingUpgrade=new Map}define(t,r){if(t=t.toLowerCase(),void 0!==this._getDefinition(t))throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${t}" has already been used with this registry`);if(void 0!==this._definitionsByClass.get(r))throw new DOMException("Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry");const u=r.prototype.attributeChangedCallback,a=new Set(r.observedAttributes||[]);f(r,a,u);const c={elementClass:r,connectedCallback:r.prototype.connectedCallback,disconnectedCallback:r.prototype.disconnectedCallback,adoptedCallback:r.prototype.adoptedCallback,attributeChangedCallback:u,formAssociated:r.formAssociated,formAssociatedCallback:r.prototype.formAssociatedCallback,formDisabledCallback:r.prototype.formDisabledCallback,formResetCallback:r.prototype.formResetCallback,formStateRestoreCallback:r.prototype.formStateRestoreCallback,observedAttributes:a};this._definitionsByTag.set(t,c),this._definitionsByClass.set(r,c);let l=n.call(i,t);l||(l=h(t),e.call(i,t,l)),this===window.customElements&&(s.set(r,c),c.standInClass=l);const d=this._awaitingUpgrade.get(t);if(d){this._awaitingUpgrade.delete(t);for(const t of d)o.delete(t),v(t,c,!0)}const p=this._whenDefinedPromises.get(t);return void 0!==p&&(p.resolve(r),this._whenDefinedPromises.delete(t)),r}upgrade(){b.push(this),i.upgrade.apply(i,arguments),b.pop()}get(t){const e=this._definitionsByTag.get(t);return e?.elementClass}_getDefinition(t){return this._definitionsByTag.get(t)}whenDefined(t){const e=this._getDefinition(t);if(void 0!==e)return Promise.resolve(e.elementClass);let n=this._whenDefinedPromises.get(t);return void 0===n&&(n={},n.promise=new Promise((t=>n.resolve=t)),this._whenDefinedPromises.set(t,n)),n.promise}_upgradeWhenDefined(t,e,n){let i=this._awaitingUpgrade.get(e);i||this._awaitingUpgrade.set(e,i=new Set),n?i.add(t):i.delete(t)}},window.HTMLElement=function(){let e=a;if(e)return a=void 0,e;const n=s.get(this.constructor);if(!n)throw new TypeError("Illegal constructor (custom element class must be registered with global customElements registry to be newable)");return e=Reflect.construct(t,[],n.standInClass),Object.setPrototypeOf(e,this.constructor.prototype),r.set(e,n),e},window.HTMLElement.prototype=t.prototype;const c=t=>t===document||t instanceof ShadowRoot,l=t=>{let e=t.getRootNode();if(!c(e)){const t=b[b.length-1];if(t instanceof CustomElementRegistry)return t;e=t.getRootNode(),c(e)||(e=u.get(e)?.getRootNode()||document)}return e.customElements},h=e=>class{static get formAssociated(){return!0}constructor(){const n=Reflect.construct(t,[],this.constructor);Object.setPrototypeOf(n,HTMLElement.prototype);const i=l(n)||window.customElements,r=i._getDefinition(e);return r?v(n,r):o.set(n,i),n}connectedCallback(){const t=r.get(this);t?t.connectedCallback&&t.connectedCallback.apply(this,arguments):o.get(this)._upgradeWhenDefined(this,e,!0)}disconnectedCallback(){const t=r.get(this);t?t.disconnectedCallback&&t.disconnectedCallback.apply(this,arguments):o.get(this)._upgradeWhenDefined(this,e,!1)}adoptedCallback(){const t=r.get(this);t?.adoptedCallback?.apply(this,arguments)}formAssociatedCallback(){const t=r.get(this);t&&t.formAssociated&&t?.formAssociatedCallback?.apply(this,arguments)}formDisabledCallback(){const t=r.get(this);t?.formAssociated&&t?.formDisabledCallback?.apply(this,arguments)}formResetCallback(){const t=r.get(this);t?.formAssociated&&t?.formResetCallback?.apply(this,arguments)}formStateRestoreCallback(){const t=r.get(this);t?.formAssociated&&t?.formStateRestoreCallback?.apply(this,arguments)}},f=(t,e,n)=>{if(0===e.size||void 0===n)return;const i=t.prototype.setAttribute;i&&(t.prototype.setAttribute=function(t,r){const o=t.toLowerCase();if(e.has(o)){const t=this.getAttribute(o);i.call(this,o,r),n.call(this,o,t,r)}else i.call(this,o,r)});const r=t.prototype.removeAttribute;r&&(t.prototype.removeAttribute=function(t){const i=t.toLowerCase();if(e.has(i)){const t=this.getAttribute(i);r.call(this,i),n.call(this,i,t,null)}else r.call(this,i)})},d=e=>{const n=Object.getPrototypeOf(e);if(n!==window.HTMLElement)return n===t||"HTMLElement"===n?.prototype?.constructor?.name?Object.setPrototypeOf(e,window.HTMLElement):d(n)},v=(t,e,n=!1)=>{Object.setPrototypeOf(t,e.elementClass.prototype),r.set(t,e),a=t;try{new e.elementClass}catch(t){d(e.elementClass),new e.elementClass}e.observedAttributes.forEach((n=>{t.hasAttribute(n)&&e.attributeChangedCallback.call(t,n,null,t.getAttribute(n))})),n&&e.connectedCallback&&t.isConnected&&e.connectedCallback.call(t)},p=Element.prototype.attachShadow;Element.prototype.attachShadow=function(t){const e=p.apply(this,arguments);return t.customElements&&(e.customElements=t.customElements),e};let b=[document];const y=(t,e,n=void 0)=>{const i=(n?Object.getPrototypeOf(n):t.prototype)[e];t.prototype[e]=function(){b.push(this);const t=i.apply(n||this,arguments);return void 0!==t&&u.set(t,this),b.pop(),t}};y(ShadowRoot,"createElement",document),y(ShadowRoot,"importNode",document),y(Element,"insertAdjacentHTML");const w=(t,e)=>{const n=Object.getOwnPropertyDescriptor(t.prototype,e);Object.defineProperty(t.prototype,e,{...n,set(t){b.push(this),n.set.call(this,t),b.pop()}})};if(w(Element,"innerHTML"),w(ShadowRoot,"innerHTML"),Object.defineProperty(window,"customElements",{value:new CustomElementRegistry,configurable:!0,writable:!0}),window.ElementInternals&&window.ElementInternals.prototype.setFormValue){const t=new WeakMap,e=HTMLElement.prototype.attachInternals,n=["setFormValue","setValidity","checkValidity","reportValidity"];HTMLElement.prototype.attachInternals=function(...n){const i=e.call(this,...n);return t.set(i,this),i},n.forEach((e=>{const n=window.ElementInternals.prototype,i=n[e];n[e]=function(...e){const n=t.get(this);if(!0!==r.get(n).formAssociated)throw new DOMException(`Failed to execute ${i} on 'ElementInternals': The target element is not a form-associated custom element.`);i?.call(this,...e)}}));class i extends Array{constructor(t){super(...t),this._elements=t}get value(){return this._elements.find((t=>!0===t.checked))?.value||""}}class o{constructor(t){const e=new Map;t.forEach(((t,n)=>{const i=t.getAttribute("name"),r=e.get(i)||[];this[+n]=t,r.push(t),e.set(i,r)})),this.length=t.length,e.forEach(((t,e)=>{t&&(1===t.length?this[e]=t[0]:this[e]=new i(t))}))}namedItem(t){return this[t]}}const s=Object.getOwnPropertyDescriptor(HTMLFormElement.prototype,"elements");Object.defineProperty(HTMLFormElement.prototype,"elements",{get:function(){const t=s.get.call(this,[]),e=[];for(const n of t){const t=r.get(n);t&&!0!==t.formAssociated||e.push(n)}return new o(e)}})}}try{window.customElements.define("custom-element",null)}catch(P){const t=window.customElements.define;window.customElements.define=(e,n,i)=>{if(null!==n)try{t.bind(window.customElements)(e,n,i)}catch(t){console.info(e,n,i,t)}}}class e extends Error{constructor(t,e,n){super(t),this.canceledPromiseResult=e,this.canceledPromiseError=n}}class n extends Promise{constructor(t){super(((n,i)=>t((t=>{this.isCanceled?i(new e("Promise has been canceled",t)):n(t)}),(t=>{this.isCanceled?i(new e("Promise has been canceled",void 0,t)):i(t)})))),this.isCanceled=!1}cancel(){this.isCanceled=!0}}class i{constructor(){this.loaders={},this.content={},this.clearTimeouts={},this.finalContent=new Set}register(t,e){this.loaders[t]=e,this.finalContent.delete(t)}registerFinal(t,e){this.loaders[t]=e,this.finalContent.add(t)}clearAll(){for(let t in this.content)this.clear(t)}clear(t){this.finalContent.has(t)||this.forceClear(t)}forceClear(t){null!=this.clearTimeouts[t]&&(window.clearTimeout(this.clearTimeouts[t]),delete this.clearTimeouts[t]),this.content[t]instanceof n&&this.content[t].cancel(),delete this.content[t]}set(t,e){this.forceClear(t),this.register(t,(async()=>e)),this.content[t]=e}setFinal(t,e){this.forceClear(t),this.registerFinal(t,(async()=>e)),this.content[t]=e}async get(t,e,i){if(void 0===this.content[t]){if(null==(e=null!=e?e:this.loaders[t]))throw new Error("Unknown cache key "+t);const r=(t=>new n(((e,n)=>t.then(e).catch(n))))(e());return this.content[t]=r,r.then((e=>(this.content[t]=e,null!=i&&(this.clearTimeouts[t]=window.setTimeout((()=>this.clear(t)),i)),e)))}if(this.content[t]instanceof Error)throw this.content[t];return this.content[t]}isResolvedValue(t){return!(null==t||t instanceof Promise||t instanceof Error)}getNow(t){if(this.isResolvedValue(this.content[t]))return this.content[t]}has(t){return null!=this.content[t]}resolvedKeys(){return Object.keys(this.content).filter((t=>this.isResolvedValue(this.content[t])))}resolvedValues(){return Object.values(this.content).filter((t=>this.isResolvedValue(t)))}keys(){return Object.keys(this.content)}values(){return Object.values(this.content)}}class r{constructor(t=0){this.timeout=t,this.callbacks=[]}run(t,e){return this.callbacks=[t],this.debounce(e)}queue(t,e){return this.callbacks.push(t),this.debounce(e)}cancel(){this.clearTimeout(),this.resolvePromise&&this.resolvePromise(!1),this.clearPromise()}debounce(t){return null==this.promise&&(this.promise=new Promise(((t,e)=>{this.resolvePromise=t,this.rejectPromise=e}))),this.clearTimeout(),this._debounce=window.setTimeout((()=>this.runCallbacks()),null!=t?t:this.timeout),this.promise}async runCallbacks(){var t,e;const n=[...this.callbacks];this.callbacks=[];const i=null!==(t=this.rejectPromise)&&void 0!==t?t:()=>null,r=null!==(e=this.resolvePromise)&&void 0!==e?e:()=>null;this.clearPromise();for(let t of n)try{await t()}catch(t){return void i(t)}r(!0)}clearTimeout(){null!=this._debounce&&window.clearTimeout(this._debounce)}clearPromise(){this.promise=void 0,this.resolvePromise=void 0,this.rejectPromise=void 0}}
|
|
17
|
+
if(!ShadowRoot.prototype.createElement){const t=window.HTMLElement,e=window.customElements.define,n=window.customElements.get,i=window.customElements,r=new WeakMap,o=new WeakMap,s=new WeakMap,u=new WeakMap;let a;window.CustomElementRegistry=class{constructor(){this._definitionsByTag=new Map,this._definitionsByClass=new Map,this._whenDefinedPromises=new Map,this._awaitingUpgrade=new Map}define(t,r){if(t=t.toLowerCase(),void 0!==this._getDefinition(t))throw new DOMException(`Failed to execute 'define' on 'CustomElementRegistry': the name "${t}" has already been used with this registry`);if(void 0!==this._definitionsByClass.get(r))throw new DOMException("Failed to execute 'define' on 'CustomElementRegistry': this constructor has already been used with this registry");const u=r.prototype.attributeChangedCallback,a=new Set(r.observedAttributes||[]);f(r,a,u);const c={elementClass:r,connectedCallback:r.prototype.connectedCallback,disconnectedCallback:r.prototype.disconnectedCallback,adoptedCallback:r.prototype.adoptedCallback,attributeChangedCallback:u,formAssociated:r.formAssociated,formAssociatedCallback:r.prototype.formAssociatedCallback,formDisabledCallback:r.prototype.formDisabledCallback,formResetCallback:r.prototype.formResetCallback,formStateRestoreCallback:r.prototype.formStateRestoreCallback,observedAttributes:a};this._definitionsByTag.set(t,c),this._definitionsByClass.set(r,c);let l=n.call(i,t);l||(l=h(t),e.call(i,t,l)),this===window.customElements&&(s.set(r,c),c.standInClass=l);const d=this._awaitingUpgrade.get(t);if(d){this._awaitingUpgrade.delete(t);for(const t of d)o.delete(t),v(t,c,!0)}const p=this._whenDefinedPromises.get(t);return void 0!==p&&(p.resolve(r),this._whenDefinedPromises.delete(t)),r}upgrade(){b.push(this),i.upgrade.apply(i,arguments),b.pop()}get(t){const e=this._definitionsByTag.get(t);return e?.elementClass}_getDefinition(t){return this._definitionsByTag.get(t)}whenDefined(t){const e=this._getDefinition(t);if(void 0!==e)return Promise.resolve(e.elementClass);let n=this._whenDefinedPromises.get(t);return void 0===n&&(n={},n.promise=new Promise((t=>n.resolve=t)),this._whenDefinedPromises.set(t,n)),n.promise}_upgradeWhenDefined(t,e,n){let i=this._awaitingUpgrade.get(e);i||this._awaitingUpgrade.set(e,i=new Set),n?i.add(t):i.delete(t)}},window.HTMLElement=function(){let e=a;if(e)return a=void 0,e;const n=s.get(this.constructor);if(!n)throw new TypeError("Illegal constructor (custom element class must be registered with global customElements registry to be newable)");return e=Reflect.construct(t,[],n.standInClass),Object.setPrototypeOf(e,this.constructor.prototype),r.set(e,n),e},window.HTMLElement.prototype=t.prototype;const c=t=>t===document||t instanceof ShadowRoot,l=t=>{let e=t.getRootNode();if(!c(e)){const t=b[b.length-1];if(t instanceof CustomElementRegistry)return t;e=t.getRootNode(),c(e)||(e=u.get(e)?.getRootNode()||document)}return e.customElements},h=e=>class{static get formAssociated(){return!0}constructor(){const n=Reflect.construct(t,[],this.constructor);Object.setPrototypeOf(n,HTMLElement.prototype);const i=l(n)||window.customElements,r=i._getDefinition(e);return r?v(n,r):o.set(n,i),n}connectedCallback(){const t=r.get(this);t?t.connectedCallback&&t.connectedCallback.apply(this,arguments):o.get(this)._upgradeWhenDefined(this,e,!0)}disconnectedCallback(){const t=r.get(this);t?t.disconnectedCallback&&t.disconnectedCallback.apply(this,arguments):o.get(this)._upgradeWhenDefined(this,e,!1)}adoptedCallback(){const t=r.get(this);t?.adoptedCallback?.apply(this,arguments)}formAssociatedCallback(){const t=r.get(this);t&&t.formAssociated&&t?.formAssociatedCallback?.apply(this,arguments)}formDisabledCallback(){const t=r.get(this);t?.formAssociated&&t?.formDisabledCallback?.apply(this,arguments)}formResetCallback(){const t=r.get(this);t?.formAssociated&&t?.formResetCallback?.apply(this,arguments)}formStateRestoreCallback(){const t=r.get(this);t?.formAssociated&&t?.formStateRestoreCallback?.apply(this,arguments)}},f=(t,e,n)=>{if(0===e.size||void 0===n)return;const i=t.prototype.setAttribute;i&&(t.prototype.setAttribute=function(t,r){const o=t.toLowerCase();if(e.has(o)){const t=this.getAttribute(o);i.call(this,o,r),n.call(this,o,t,r)}else i.call(this,o,r)});const r=t.prototype.removeAttribute;r&&(t.prototype.removeAttribute=function(t){const i=t.toLowerCase();if(e.has(i)){const t=this.getAttribute(i);r.call(this,i),n.call(this,i,t,null)}else r.call(this,i)})},d=e=>{const n=Object.getPrototypeOf(e);if(n!==window.HTMLElement)return n===t||"HTMLElement"===n?.prototype?.constructor?.name?Object.setPrototypeOf(e,window.HTMLElement):d(n)},v=(t,e,n=!1)=>{Object.setPrototypeOf(t,e.elementClass.prototype),r.set(t,e),a=t;try{new e.elementClass}catch(t){d(e.elementClass),new e.elementClass}e.observedAttributes.forEach((n=>{t.hasAttribute(n)&&e.attributeChangedCallback.call(t,n,null,t.getAttribute(n))})),n&&e.connectedCallback&&t.isConnected&&e.connectedCallback.call(t)},p=Element.prototype.attachShadow;Element.prototype.attachShadow=function(t){const e=p.apply(this,arguments);return t.customElements&&(e.customElements=t.customElements),e};let b=[document];const y=(t,e,n=void 0)=>{const i=(n?Object.getPrototypeOf(n):t.prototype)[e];t.prototype[e]=function(){b.push(this);const t=i.apply(n||this,arguments);return void 0!==t&&u.set(t,this),b.pop(),t}};y(ShadowRoot,"createElement",document),y(ShadowRoot,"importNode",document),y(Element,"insertAdjacentHTML");const w=(t,e)=>{const n=Object.getOwnPropertyDescriptor(t.prototype,e);Object.defineProperty(t.prototype,e,{...n,set(t){b.push(this),n.set.call(this,t),b.pop()}})};if(w(Element,"innerHTML"),w(ShadowRoot,"innerHTML"),Object.defineProperty(window,"customElements",{value:new CustomElementRegistry,configurable:!0,writable:!0}),window.ElementInternals&&window.ElementInternals.prototype.setFormValue){const t=new WeakMap,e=HTMLElement.prototype.attachInternals,n=["setFormValue","setValidity","checkValidity","reportValidity"];HTMLElement.prototype.attachInternals=function(...n){const i=e.call(this,...n);return t.set(i,this),i},n.forEach((e=>{const n=window.ElementInternals.prototype,i=n[e];n[e]=function(...e){const n=t.get(this);if(!0!==r.get(n).formAssociated)throw new DOMException(`Failed to execute ${i} on 'ElementInternals': The target element is not a form-associated custom element.`);i?.call(this,...e)}}));class i extends Array{constructor(t){super(...t),this._elements=t}get value(){return this._elements.find((t=>!0===t.checked))?.value||""}}class o{constructor(t){const e=new Map;t.forEach(((t,n)=>{const i=t.getAttribute("name"),r=e.get(i)||[];this[+n]=t,r.push(t),e.set(i,r)})),this.length=t.length,e.forEach(((t,e)=>{t&&(1===t.length?this[e]=t[0]:this[e]=new i(t))}))}namedItem(t){return this[t]}}const s=Object.getOwnPropertyDescriptor(HTMLFormElement.prototype,"elements");Object.defineProperty(HTMLFormElement.prototype,"elements",{get:function(){const t=s.get.call(this,[]),e=[];for(const n of t){const t=r.get(n);t&&!0!==t.formAssociated||e.push(n)}return new o(e)}})}}try{window.customElements.define("custom-element",null)}catch(P){const t=window.customElements.define;window.customElements.define=(e,n,i)=>{if(null!==n)try{t.bind(window.customElements)(e,n,i)}catch(t){console.info(e,n,i,t)}}}class e extends Error{constructor(t,e,n){super(t),this.canceledPromiseResult=e,this.canceledPromiseError=n}}class n extends Promise{constructor(t){super(((n,i)=>t((t=>{this.isCanceled?i(new e("Promise has been canceled",t)):n(t)}),(t=>{this.isCanceled?i(new e("Promise has been canceled",void 0,t)):i(t)})))),this.isCanceled=!1}cancel(){this.isCanceled=!0}}class i{constructor(){this.loaders={},this.content={},this.clearTimeouts={},this.finalContent=new Set}register(t,e){this.loaders[t]=e,this.finalContent.delete(t)}registerFinal(t,e){this.loaders[t]=e,this.finalContent.add(t)}clearAll(){for(let t in this.content)this.clear(t)}clear(t){this.finalContent.has(t)||this.forceClear(t)}forceClear(t){this.clearClearTimeout(t),this.content[t]instanceof n&&this.content[t].cancel(),delete this.content[t]}clearClearTimeout(t){null!=this.clearTimeouts[t]&&(window.clearTimeout(this.clearTimeouts[t]),delete this.clearTimeouts[t])}set(t,e){this.forceClear(t),this.register(t,(async()=>e)),this.content[t]=e}setFinal(t,e){this.forceClear(t),this.registerFinal(t,(async()=>e)),this.content[t]=e}async get(t,e,i){if(void 0===this.content[t]){if(null==(e=null!=e?e:this.loaders[t]))throw new Error("Unknown cache key "+t);const r=(t=>new n(((e,n)=>t.then(e).catch(n))))(e());return this.content[t]=r,r.then((e=>(this.content[t]=e,null!=i&&(this.clearClearTimeout(t),this.clearTimeouts[t]=window.setTimeout((()=>this.clear(t)),i)),e)))}if(this.content[t]instanceof Error)throw this.content[t];return this.content[t]}isResolvedValue(t){return!(null==t||t instanceof Promise||t instanceof Error)}getNow(t){if(this.isResolvedValue(this.content[t]))return this.content[t]}has(t){return null!=this.content[t]}resolvedKeys(){return Object.keys(this.content).filter((t=>this.isResolvedValue(this.content[t])))}resolvedValues(){return Object.values(this.content).filter((t=>this.isResolvedValue(t)))}keys(){return Object.keys(this.content)}values(){return Object.values(this.content)}}class r{constructor(t=0){this.timeout=t,this.callbacks=[]}run(t,e){return this.callbacks=[t],this.debounce(e)}queue(t,e){return this.callbacks.push(t),this.debounce(e)}cancel(){this.clearTimeout(),this.resolvePromise&&this.resolvePromise(!1),this.clearPromise()}debounce(t){return null==this.promise&&(this.promise=new Promise(((t,e)=>{this.resolvePromise=t,this.rejectPromise=e}))),this.clearTimeout(),this._debounce=window.setTimeout((()=>this.runCallbacks()),null!=t?t:this.timeout),this.promise}async runCallbacks(){var t,e;const n=[...this.callbacks];this.callbacks=[];const i=null!==(t=this.rejectPromise)&&void 0!==t?t:()=>null,r=null!==(e=this.resolvePromise)&&void 0!==e?e:()=>null;this.clearPromise();for(let t of n)try{await t()}catch(t){return void i(t)}r(!0)}clearTimeout(){null!=this._debounce&&window.clearTimeout(this._debounce)}clearPromise(){this.promise=void 0,this.resolvePromise=void 0,this.rejectPromise=void 0}}
|
|
18
18
|
/**
|
|
19
19
|
* @license
|
|
20
20
|
* Copyright 2017 Google LLC
|
|
@@ -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==t));i(t)||(t=i(n)?n: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(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`
|
|
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.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(t),this.store.actions.setPageNumber(1),t.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 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}({});
|
|
@@ -61,6 +61,11 @@ export class FtSearchStateManager {
|
|
|
61
61
|
setFilters(filters) {
|
|
62
62
|
this.store.actions.setRequestFilters(filters);
|
|
63
63
|
this.store.actions.setPageNumber(1);
|
|
64
|
+
filters.forEach(f => {
|
|
65
|
+
if (!this.facetIds.includes(f.key)) {
|
|
66
|
+
this.facetIds = [...this.facetIds, f.key];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
64
69
|
this.launchSearch();
|
|
65
70
|
}
|
|
66
71
|
addFacet(id) {
|
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.22",
|
|
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.22",
|
|
23
|
+
"@fluid-topics/ft-wc-utils": "1.0.22",
|
|
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": "d68f9748c223f9e8eb8da2da4f410e02a2121d36"
|
|
33
33
|
}
|