@fluid-topics/ft-app-context 1.1.50 → 1.1.52

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,4 +1,4 @@
1
1
  !function(t,s,i,e){const a=i.css`
2
- `,n="ft-app-info",o=s.FtReduxStore.get({name:n,reducers:{},initialState:{baseUrl:void 0,apiIntegrationIdentifier:void 0,uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],metadataConfiguration:void 0,editorMode:!1,noCustom:!1,noCustomComponent:!1,session:void 0,openExternalDocumentInNewTab:!1}});class l{static build(t){const{baseUrl:s,apiIntegrationIdentifier:i}=o.getState(),e=null!=t?t:i;if(s&&e&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(s,e,!0)}static get(t){var s;return null!=t?l.build(t):null!==(s=l.API)&&void 0!==s?s:l.API=l.build()}static await(t){return new Promise((s=>{let i=l.get(t);if(i)s(i);else{const e=o.subscribe((()=>{i=l.get(t),i&&(e(),s(i))}))}}))}}class h{constructor(t=!0,i){var e;this.overrideApi=i;let a=this.constructor;a.commonCache=null!==(e=a.commonCache)&&void 0!==e?e:new s.CacheRegistry,this.cache=t?a.commonCache:new s.CacheRegistry}get api(){var t;return null!==(t=this.overrideApi)&&void 0!==t?t:l.get()}get awaitApi(){var t;return null!==(t=this.overrideApi)&&void 0!==t?t:l.await()}clearCache(){this.cache.clearAll()}}var r;const c=Symbol("clearAfterUnitTest");class d extends h{constructor(t){super(),this.messageContextProvider=t,this.defaultMessages={},this.listeners={},this.currentUiLocale="",this[r]=()=>{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,i){var e;if(t=t.toLowerCase(),Object.keys(i).length>0){const a={...null!==(e=this.defaultMessages[t])&&void 0!==e?e:{},...i};s.deepEqual(this.defaultMessages[t],a)||(this.defaultMessages[t]=a,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,i,...e){var a,n,o;t=t.toLowerCase(),this.fetchContext(t);const l=null!==(n=null===(a=this.cache.getNow(t))||void 0===a?void 0:a.messages)&&void 0!==n?n:{};return new s.ParametrizedLabelResolver(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},l).resolve(i,...e)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,s){var i;return t=t.toLowerCase(),this.listeners[t]=null!==(i=this.listeners[t])&&void 0!==i?i:new Set,this.listeners[t].add(s),()=>{var i;return null===(i=this.listeners[t])||void 0===i?void 0:i.delete(s)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>s.delay(0).then((()=>t())).catch((()=>null)))))}}r=c,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new class extends d{constructor(){super((async(t,s)=>(await this.awaitApi).getFluidTopicsMessageContext(t,s)))}}),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new class extends d{constructor(){super((async(t,s)=>(await this.awaitApi).getCustomMessageContext(t,s)))}});const u=window.FluidTopicsI18nService,v=window.FluidTopicsCustomI18nService;var w=function(t,s,i,e){for(var a,n=arguments.length,o=n<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,l=t.length-1;l>=0;l--)(a=t[l])&&(o=(n<3?a(o):n>3?a(s,i,o):a(s,i))||o);return n>3&&o&&Object.defineProperty(s,i,o),o};class m extends s.FtLitElement{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.editorMode=!1,this.noCustom=!1,this.openExternalDocumentInNewTab=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>l.get(),this.cache=new s.CacheRegistry,this.cleanSessionDebouncer=new s.Debouncer}render(){return i.html`
2
+ `,n="ft-app-info",o=s.FtReduxStore.get({name:n,reducers:{},initialState:{baseUrl:void 0,apiIntegrationIdentifier:void 0,uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],metadataConfiguration:void 0,editorMode:!1,noCustom:!1,noCustomComponent:!1,session:void 0,openExternalDocumentInNewTab:!1}});class h{static get(t){const{baseUrl:s,apiIntegrationIdentifier:i}=o.getState(),e=null!=t?t:i;if(s&&e&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(s,e,!0)}static await(t){return new Promise((s=>{let i=h.get(t);if(i)s(i);else{const e=o.subscribe((()=>{i=h.get(t),i&&(e(),s(i))}))}}))}}class r{constructor(t=!0,i){var e;this.overrideApi=i;let a=this.constructor;a.commonCache=null!==(e=a.commonCache)&&void 0!==e?e:new s.CacheRegistry,this.cache=t?a.commonCache:new s.CacheRegistry}get api(){var t;return null!==(t=this.overrideApi)&&void 0!==t?t:h.get()}get awaitApi(){var t;return null!==(t=this.overrideApi)&&void 0!==t?t:h.await()}clearCache(){this.cache.clearAll()}}var l;const c=Symbol("clearAfterUnitTest");class d extends r{constructor(t){super(),this.messageContextProvider=t,this.defaultMessages={},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,i){var e;if(t=t.toLowerCase(),Object.keys(i).length>0){const a={...null!==(e=this.defaultMessages[t])&&void 0!==e?e:{},...i};s.deepEqual(this.defaultMessages[t],a)||(this.defaultMessages[t]=a,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,i,...e){var a,n,o;t=t.toLowerCase(),this.fetchContext(t);const h=null!==(n=null===(a=this.cache.getNow(t))||void 0===a?void 0:a.messages)&&void 0!==n?n:{};return new s.ParametrizedLabelResolver(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},h).resolve(i,...e)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,s){var i;return t=t.toLowerCase(),this.listeners[t]=null!==(i=this.listeners[t])&&void 0!==i?i:new Set,this.listeners[t].add(s),()=>{var i;return null===(i=this.listeners[t])||void 0===i?void 0:i.delete(s)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>s.delay(0).then((()=>t())).catch((()=>null)))))}}l=c,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new class extends d{constructor(){super((async(t,s)=>(await this.awaitApi).getFluidTopicsMessageContext(t,s)))}}),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new class extends d{constructor(){super((async(t,s)=>(await this.awaitApi).getCustomMessageContext(t,s)))}});const u=window.FluidTopicsI18nService,v=window.FluidTopicsCustomI18nService;var w=function(t,s,i,e){for(var a,n=arguments.length,o=n<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,h=t.length-1;h>=0;h--)(a=t[h])&&(o=(n<3?a(o):n>3?a(s,i,o):a(s,i))||o);return n>3&&o&&Object.defineProperty(s,i,o),o};class m extends s.FtLitElement{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.editorMode=!1,this.noCustom=!1,this.openExternalDocumentInNewTab=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>h.get(),this.cache=new s.CacheRegistry,this.cleanSessionDebouncer=new s.Debouncer}render(){return i.html`
3
3
  <slot></slot>
4
- `}update(t){super.update(t),t.has("baseUrl")&&(o.actions.baseUrl(this.baseUrl),window.fluidTopicsBaseUrl=this.baseUrl),t.has("apiIntegrationIdentifier")&&o.actions.apiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&o.actions.uiLocale(this.uiLocale),t.has("metadataConfiguration")&&o.actions.metadataConfiguration(this.metadataConfiguration),t.has("noCustom")&&o.actions.noCustom(this.noCustom),t.has("editorMode")&&o.actions.editorMode(this.editorMode),t.has("noCustomComponent")&&o.actions.noCustomComponent(this.noCustomComponent),t.has("session")&&o.actions.session(this.session),t.has("availableUiLocales")&&o.actions.availableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>u.addContext(t))),t.has("openExternalDocumentInNewTab")&&o.actions.openExternalDocumentInNewTab(this.openExternalDocumentInNewTab),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){!this.withManualResources&&this.apiProvider()&&(null==this.session&&this.updateSession(),null==this.availableUiLocales&&this.updateUiLocales(),null==this.metadataConfiguration&&this.updateMetadataConfiguration())}async updateSession(){this.session=await this.cache.get("session",(async()=>{const t=await this.apiProvider().getCurrentSession();return t.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),t.idleTimeoutInMillis),t}))}async updateUiLocales(){this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>this.apiProvider().getAvailableUiLocales()))}async updateMetadataConfiguration(){this.metadataConfiguration=await this.cache.get("metadataConfiguration",(()=>this.apiProvider().getMetadataConfiguration()))}}m.elementDefinitions={},m.styles=a,w([e.property()],m.prototype,"baseUrl",void 0),w([e.property()],m.prototype,"apiIntegrationIdentifier",void 0),w([e.property()],m.prototype,"uiLocale",void 0),w([s.jsonProperty(null)],m.prototype,"availableUiLocales",void 0),w([s.jsonProperty(null)],m.prototype,"metadataConfiguration",void 0),w([e.property({type:Boolean})],m.prototype,"editorMode",void 0),w([e.property({type:Boolean})],m.prototype,"noCustom",void 0),w([e.property({type:Boolean})],m.prototype,"openExternalDocumentInNewTab",void 0),w([e.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],m.prototype,"noCustomComponent",void 0),w([e.property({type:Boolean})],m.prototype,"withManualResources",void 0),w([s.jsonProperty([])],m.prototype,"messageContexts",void 0),w([s.jsonProperty(void 0)],m.prototype,"session",void 0),w([e.property({type:Object})],m.prototype,"apiProvider",void 0);class p extends h{async listMySearches(){let t=o.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-searches",(async()=>(await this.awaitApi).listMySearches(t.profile.userId)),3e5):[]}}class y extends h{async listMyBookmarks(){let t=o.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-bookmarks",(async()=>(await this.awaitApi).listMyBookmarks(t.profile.userId)),3e5):[]}}const f="ft-user-assets",b=s.FtReduxStore.get({name:f,initialState:{savedSearches:void 0,bookmarks:void 0}});const C=new class{constructor(){this.currentSession=o.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new y,this.savedSearchesService=new p,o.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:i}=o.getState();s.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==i?void 0:i.profile)||(this.currentSession=i,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){this.savedSearchesService.clearCache(),b.actions.savedSearches(void 0)}clearMyBookmarks(){this.bookmarksService.clearCache(),b.actions.bookmarks(void 0)}async reloadMySearches(){this.savedSearchesService.clearCache();const t=await this.savedSearchesService.listMySearches();b.actions.savedSearches(t)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const s=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;b.actions.bookmarks(s)}}};s.customElement("ft-app-context")(m),t.FluidTopicsApiProvider=l,t.FtAppContext=m,t.FtAppContextCssVariables={},t.FtAppInfoStoreName=n,t.FtI18nServiceInternalClass=d,t.FtServiceWithCache=h,t.FtUserAssetsStoreName=f,t.clearAfterUnitTest=c,t.ftAppInfoStore=o,t.ftCustomI18nService=v,t.ftI18nService=u,t.ftUserAssetsStore=b,t.styles=a,t.userAssetsActions=C}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);
4
+ `}update(t){super.update(t),t.has("baseUrl")&&(o.actions.baseUrl(this.baseUrl),window.fluidTopicsBaseUrl=this.baseUrl),t.has("apiIntegrationIdentifier")&&o.actions.apiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&o.actions.uiLocale(this.uiLocale),t.has("metadataConfiguration")&&o.actions.metadataConfiguration(this.metadataConfiguration),t.has("noCustom")&&o.actions.noCustom(this.noCustom),t.has("editorMode")&&o.actions.editorMode(this.editorMode),t.has("noCustomComponent")&&o.actions.noCustomComponent(this.noCustomComponent),t.has("session")&&o.actions.session(this.session),t.has("availableUiLocales")&&o.actions.availableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>u.addContext(t))),t.has("openExternalDocumentInNewTab")&&o.actions.openExternalDocumentInNewTab(this.openExternalDocumentInNewTab),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){!this.withManualResources&&this.apiProvider()&&(null==this.session&&this.updateSession(),null==this.availableUiLocales&&this.updateUiLocales(),null==this.metadataConfiguration&&this.updateMetadataConfiguration())}async updateSession(){this.session=await this.cache.get("session",(async()=>{const t=await this.apiProvider().getCurrentSession();return t.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),t.idleTimeoutInMillis),t}))}async updateUiLocales(){this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>this.apiProvider().getAvailableUiLocales()))}async updateMetadataConfiguration(){this.metadataConfiguration=await this.cache.get("metadataConfiguration",(()=>this.apiProvider().getMetadataConfiguration()))}}m.elementDefinitions={},m.styles=a,w([e.property()],m.prototype,"baseUrl",void 0),w([e.property()],m.prototype,"apiIntegrationIdentifier",void 0),w([e.property()],m.prototype,"uiLocale",void 0),w([s.jsonProperty(null)],m.prototype,"availableUiLocales",void 0),w([s.jsonProperty(null)],m.prototype,"metadataConfiguration",void 0),w([e.property({type:Boolean})],m.prototype,"editorMode",void 0),w([e.property({type:Boolean})],m.prototype,"noCustom",void 0),w([e.property({type:Boolean})],m.prototype,"openExternalDocumentInNewTab",void 0),w([e.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],m.prototype,"noCustomComponent",void 0),w([e.property({type:Boolean})],m.prototype,"withManualResources",void 0),w([s.jsonProperty([])],m.prototype,"messageContexts",void 0),w([s.jsonProperty(void 0)],m.prototype,"session",void 0),w([e.property({type:Object})],m.prototype,"apiProvider",void 0);class p extends r{async listMySearches(){let t=o.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-searches",(async()=>(await this.awaitApi).listMySearches(t.profile.userId)),3e5):[]}}class y extends r{async listMyBookmarks(){let t=o.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-bookmarks",(async()=>(await this.awaitApi).listMyBookmarks(t.profile.userId)),3e5):[]}}const f="ft-user-assets",b=s.FtReduxStore.get({name:f,initialState:{savedSearches:void 0,bookmarks:void 0}});const C=new class{constructor(){this.currentSession=o.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new y,this.savedSearchesService=new p,o.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:i}=o.getState();s.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==i?void 0:i.profile)||(this.currentSession=i,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){this.savedSearchesService.clearCache(),b.actions.savedSearches(void 0)}clearMyBookmarks(){this.bookmarksService.clearCache(),b.actions.bookmarks(void 0)}async reloadMySearches(){this.savedSearchesService.clearCache();const t=await this.savedSearchesService.listMySearches();b.actions.savedSearches(t)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const s=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;b.actions.bookmarks(s)}}};s.customElement("ft-app-context")(m),t.FluidTopicsApiProvider=h,t.FtAppContext=m,t.FtAppContextCssVariables={},t.FtAppInfoStoreName=n,t.FtI18nServiceInternalClass=d,t.FtServiceWithCache=r,t.FtUserAssetsStoreName=f,t.clearAfterUnitTest=c,t.ftAppInfoStore=o,t.ftCustomI18nService=v,t.ftI18nService=u,t.ftUserAssetsStore=b,t.styles=a,t.userAssetsActions=C}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);