@fluid-topics/ft-app-context 1.1.68 → 1.1.70

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