@fluid-topics/ft-app-context 1.1.69 → 1.1.71
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
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";(()=>{var q=Object.create;var L=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var x=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var J=(s,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of V(e))!N.call(s,i)&&i!==t&&L(s,i,{get:()=>e[i],enumerable:!(a=H(e,i))||a.enumerable});return s};var d=(s,e,t)=>(t=s!=null?q(z(s)):{},J(e||!s||!s.__esModule?L(t,"default",{value:s,enumerable:!0}):t,s));var u=x(($,T)=>{T.exports=ftGlobals.wcUtils});var k=x((ee,B)=>{B.exports=ftGlobals.lit});var O=x((te,F)=>{F.exports=ftGlobals.litDecorators});var G=d(u());var j=d(k()),c=d(O()),h=d(u());var P=d(k()),se={},_=P.css`
|
|
2
|
+
`;var D=d(u()),K="ft-app-info",Q={},o=D.FtReduxStore.get({name:K,reducers:Q,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}});var m=d(u());var I=d(u());var v=class s{static get(e){let{baseUrl:t,apiIntegrationIdentifier:a}=o.getState(),i=e??a;if(t&&i&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(t,i,!0)}static await(e){return new Promise(t=>{let a=s.get(e);if(a)t(a);else{let i=o.subscribe(()=>{a=s.get(e),a&&(i(),t(a))})}})}};var p=class{constructor(e=!0,t){var a;this.overrideApi=t;let i=this.constructor;i.commonCache=(a=i.commonCache)!==null&&a!==void 0?a:new I.CacheRegistry,this.cache=e?i.commonCache:new I.CacheRegistry}get api(){var e;return(e=this.overrideApi)!==null&&e!==void 0?e:v.get()}get awaitApi(){var e;return(e=this.overrideApi)!==null&&e!==void 0?e:v.await()}clearCache(){this.cache.clearAll()}};var E,X=Symbol("clearAfterUnitTest"),w=class extends p{constructor(e){super(),this.messageContextProvider=e,this.defaultMessages={},this.listeners={},this.currentUiLocale="",this[E]=()=>{this.defaultMessages={},this.cache=new m.CacheRegistry,this.listeners={}},this.currentUiLocale=o.getState().uiLocale,o.subscribe(()=>this.clearWhenUiLocaleChanges())}clearWhenUiLocaleChanges(){let{uiLocale:e}=o.getState();this.currentUiLocale!==e&&(this.currentUiLocale=e,this.cache.clearAll(),this.notifyAll())}addContext(e){let t=e.name.toLowerCase();this.cache.setFinal(t,e),this.notify(t)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(e,t){var a;if(e=e.toLowerCase(),Object.keys(t).length>0){let i={...(a=this.defaultMessages[e])!==null&&a!==void 0?a:{},...t};(0,m.deepEqual)(this.defaultMessages[e],i)||(this.defaultMessages[e]=i,await this.notify(e))}await this.fetchContext(e)}resolveMessage(e,t,...a){var i,l,f;e=e.toLowerCase(),this.fetchContext(e);let g=(l=(i=this.cache.getNow(e))===null||i===void 0?void 0:i.messages)!==null&&l!==void 0?l:{};return new m.ParametrizedLabelResolver((f=this.defaultMessages[e])!==null&&f!==void 0?f:{},g).resolve(t,...a)}async fetchContext(e){if(!this.cache.has(e))try{await this.cache.get(e,()=>this.messageContextProvider(this.currentUiLocale,e)),await this.notify(e)}catch(t){console.error(t)}}subscribe(e,t){var a;return e=e.toLowerCase(),this.listeners[e]=(a=this.listeners[e])!==null&&a!==void 0?a:new Set,this.listeners[e].add(t),()=>{var i;return(i=this.listeners[e])===null||i===void 0?void 0:i.delete(t)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map(e=>this.notify(e)))}async notify(e){this.listeners[e]!=null&&await Promise.all([...this.listeners[e].values()].map(t=>(0,m.delay)(0).then(()=>t()).catch(()=>null)))}};E=X;window.FluidTopicsI18nService==null&&(window.FluidTopicsI18nService=new class extends w{constructor(){super(async(s,e)=>(await this.awaitApi).getFluidTopicsMessageContext(s,e))}});window.FluidTopicsCustomI18nService==null&&(window.FluidTopicsCustomI18nService=new class extends w{constructor(){super(async(s,e)=>(await this.awaitApi).getCustomMessageContext(s,e))}});var R=window.FluidTopicsI18nService,de=window.FluidTopicsCustomI18nService;var n=function(s,e,t,a){var i=arguments.length,l=i<3?e:a===null?a=Object.getOwnPropertyDescriptor(e,t):a,f;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")l=Reflect.decorate(s,e,t,a);else for(var g=s.length-1;g>=0;g--)(f=s[g])&&(l=(i<3?f(l):i>3?f(e,t,l):f(e,t))||l);return i>3&&l&&Object.defineProperty(e,t,l),l},r=class extends h.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=()=>v.get(),this.messageContexts=[],this.cache=new h.CacheRegistry,this.cleanSessionDebouncer=new h.Debouncer}render(){return j.html`
|
|
3
3
|
<slot></slot>
|
|
4
|
-
`}update(
|
|
4
|
+
`}update(e){super.update(e),e.has("baseUrl")&&(o.actions.baseUrl(this.baseUrl),window.fluidTopicsBaseUrl=this.baseUrl),e.has("apiIntegrationIdentifier")&&o.actions.apiIntegrationIdentifier(this.apiIntegrationIdentifier),e.has("uiLocale")&&o.actions.uiLocale(this.uiLocale),e.has("metadataConfiguration")&&o.actions.metadataConfiguration(this.metadataConfiguration),e.has("noCustom")&&o.actions.noCustom(this.noCustom),e.has("editorMode")&&o.actions.editorMode(this.editorMode),e.has("noCustomComponent")&&o.actions.noCustomComponent(this.noCustomComponent),e.has("session")&&o.actions.session(this.session),e.has("availableUiLocales")&&o.actions.availableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),e.has("messageContexts")&&this.messageContexts!=null&&this.messageContexts.forEach(t=>R.addContext(t)),e.has("openExternalDocumentInNewTab")&&o.actions.openExternalDocumentInNewTab(this.openExternalDocumentInNewTab),e.has("navigatorOnline")&&o.actions.navigatorOnline(this.navigatorOnline),e.has("forcedOffline")&&o.actions.forcedOffline(this.forcedOffline),setTimeout(()=>this.updateIfNeeded())}async updateIfNeeded(){!this.withManualResources&&this.apiProvider()&&(this.session==null&&this.updateSession(),this.availableUiLocales==null&&this.updateUiLocales(),this.metadataConfiguration==null&&this.updateMetadataConfiguration())}async updateSession(){this.session=await this.cache.get("session",async()=>{let e=await this.apiProvider().getCurrentSession();return e.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run(()=>{this.cache.clear("session"),this.session=void 0},e.idleTimeoutInMillis),e})}async updateUiLocales(){this.availableUiLocales=await this.cache.get("availableUiLocales",()=>this.apiProvider().getAvailableUiLocales())}async updateMetadataConfiguration(){this.metadataConfiguration=await this.cache.get("metadataConfiguration",()=>this.apiProvider().getMetadataConfiguration())}};r.elementDefinitions={};r.styles=_;n([(0,c.property)()],r.prototype,"baseUrl",void 0);n([(0,c.property)()],r.prototype,"apiIntegrationIdentifier",void 0);n([(0,c.property)()],r.prototype,"uiLocale",void 0);n([(0,h.jsonProperty)(null)],r.prototype,"availableUiLocales",void 0);n([(0,h.jsonProperty)(null)],r.prototype,"metadataConfiguration",void 0);n([(0,c.property)({type:Boolean})],r.prototype,"editorMode",void 0);n([(0,c.property)({type:Boolean})],r.prototype,"noCustom",void 0);n([(0,c.property)({type:Boolean})],r.prototype,"openExternalDocumentInNewTab",void 0);n([(0,c.property)({converter:{fromAttribute(s){return s==="false"?!1:s==="true"||(s??!1)}}})],r.prototype,"noCustomComponent",void 0);n([(0,c.property)({type:Boolean})],r.prototype,"withManualResources",void 0);n([(0,c.property)({type:Boolean})],r.prototype,"navigatorOnline",void 0);n([(0,c.property)({type:Boolean})],r.prototype,"forcedOffline",void 0);n([(0,c.property)({type:Object})],r.prototype,"apiProvider",void 0);n([(0,h.jsonProperty)([])],r.prototype,"messageContexts",void 0);n([(0,h.jsonProperty)(void 0)],r.prototype,"session",void 0);var b=d(u());var y=class extends p{async listMySearches(){let e=o.getState().session;return e?.sessionAuthenticated?this.cache.get("my-searches",async()=>(await this.awaitApi).listMySearches(e.profile.userId),5*60*1e3):[]}};var C=class extends p{async listMyBookmarks(){let e=o.getState().session;return e?.sessionAuthenticated?this.cache.get("my-bookmarks",async()=>(await this.awaitApi).listMyBookmarks(e.profile.userId),5*60*1e3):[]}};var Y="ft-user-assets",S=b.FtReduxStore.get({name:Y,initialState:{savedSearches:void 0,bookmarks:void 0}}),U=class{constructor(){this.currentSession=o.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new C,this.savedSearchesService=new y,o.subscribe(()=>this.reloadWhenUserSessionChanges())}reloadWhenUserSessionChanges(){var e;let{session:t}=o.getState();(0,b.deepEqual)((e=this.currentSession)===null||e===void 0?void 0:e.profile,t?.profile)||(this.currentSession=t,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){this.savedSearchesService.clearCache(),S.actions.savedSearches(void 0)}clearMyBookmarks(){this.bookmarksService.clearCache(),S.actions.bookmarks(void 0)}async reloadMySearches(){this.savedSearchesService.clearCache();let e=await this.savedSearchesService.listMySearches();S.actions.savedSearches(e)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var e;if(this.bookmarksAreUsed){let t=!((e=this.currentSession)===null||e===void 0)&&e.sessionAuthenticated?await this.bookmarksService.listMyBookmarks():void 0;S.actions.bookmarks(t)}}},Le=new U;var A=class{addCommand(e,t=!1){o.commands.add(e,t)}consumeCommand(e){return o.commands.consume(e)}};window.FluidTopicsAppInfoStoreService=new A;var W=d(u()),M=class{highlightHtml(e,t){(0,W.highlightHtml)(e,t)}};window.FluidTopicsHighlightHtmlService=new M;(0,G.customElement)("ft-app-context")(r);})();
|