@fluid-topics/ft-app-context 1.1.81 → 1.1.83

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.
package/build/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./mixins/withDateFormat";
1
2
  export * from "./redux-stores/FtAppInfoStore";
2
3
  export * from "./redux-stores/FtUserAssetsStore";
3
4
  export * from "./services";
package/build/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { customElement } from "@fluid-topics/ft-wc-utils";
2
2
  import { FtAppContext } from "./ft-app-context";
3
+ export * from "./mixins/withDateFormat";
3
4
  export * from "./redux-stores/FtAppInfoStore";
4
5
  export * from "./redux-stores/FtUserAssetsStore";
5
6
  export * from "./services";
@@ -0,0 +1,11 @@
1
+ import { FtLitElementRedux } from "@fluid-topics/ft-wc-utils/build/redux";
2
+ import { PropertyValues } from "lit";
3
+ import { Constructor } from "@fluid-topics/ft-wc-utils/build/generic-types";
4
+ import { FtMetadata } from "@fluid-topics/public-api";
5
+ export type FtLitElementWithDateFormatInterface = {
6
+ dateFormatOptionsChanged(props: PropertyValues): boolean;
7
+ formatDateValues(metadata?: FtMetadata): FtMetadata | undefined;
8
+ };
9
+ type FtLitElementWithDateFormatType<T extends Constructor<FtLitElementRedux>> = T & Constructor<FtLitElementWithDateFormatInterface>;
10
+ export declare function withDateFormat<T extends Constructor<FtLitElementRedux>>(Class: T): FtLitElementWithDateFormatType<T>;
11
+ export {};
@@ -0,0 +1,54 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { property } from "lit/decorators.js";
8
+ import { redux } from "@fluid-topics/ft-wc-utils/build/redux";
9
+ import { DateFormatter } from "@fluid-topics/ft-wc-utils/build/DateFormatter";
10
+ import { ftAppInfoStore } from "../redux-stores/FtAppInfoStore";
11
+ export function withDateFormat(Class) {
12
+ class FtLitElementWithDateFormatClass extends Class {
13
+ constructor(...props) {
14
+ super(props);
15
+ this.useLongDateFormat = false;
16
+ this.useDateTimeFormat = false;
17
+ this.metadataDescriptors = [];
18
+ this.uiLocale = "en-US";
19
+ this.addStore(ftAppInfoStore);
20
+ }
21
+ dateFormatOptionsChanged(props) {
22
+ return props.has("metadataDescriptors")
23
+ || props.has("useLongDateFormat")
24
+ || props.has("useDateTimeFormat")
25
+ || props.has("uiLocale");
26
+ }
27
+ formatDateValues(metadata) {
28
+ var _a, _b;
29
+ const isDateMetadata = (_b = (_a = this.metadataDescriptors.find(descriptor => descriptor.key === (metadata === null || metadata === void 0 ? void 0 : metadata.key))) === null || _a === void 0 ? void 0 : _a.date) !== null && _b !== void 0 ? _b : false;
30
+ return isDateMetadata ? this.formatMetadataDates(metadata) : metadata;
31
+ }
32
+ formatMetadataDates(metadata) {
33
+ return {
34
+ key: metadata.key,
35
+ label: metadata.label,
36
+ values: metadata.values.map(date => DateFormatter.format(date, this.uiLocale, this.useLongDateFormat, this.useDateTimeFormat)),
37
+ hierarchicalValues: metadata.hierarchicalValues
38
+ };
39
+ }
40
+ }
41
+ __decorate([
42
+ property({ type: Boolean })
43
+ ], FtLitElementWithDateFormatClass.prototype, "useLongDateFormat", void 0);
44
+ __decorate([
45
+ property({ type: Boolean })
46
+ ], FtLitElementWithDateFormatClass.prototype, "useDateTimeFormat", void 0);
47
+ __decorate([
48
+ redux({ store: ftAppInfoStore.name, selector: (s) => { var _a, _b; return (_b = (_a = s.metadataConfiguration) === null || _a === void 0 ? void 0 : _a.descriptors) !== null && _b !== void 0 ? _b : []; } })
49
+ ], FtLitElementWithDateFormatClass.prototype, "metadataDescriptors", void 0);
50
+ __decorate([
51
+ redux({ store: ftAppInfoStore.name })
52
+ ], FtLitElementWithDateFormatClass.prototype, "uiLocale", void 0);
53
+ return FtLitElementWithDateFormatClass;
54
+ }
@@ -1,5 +1,6 @@
1
1
  import { FtReduxStore, Optional } from "@fluid-topics/ft-wc-utils";
2
2
  import { FtMetadataConfiguration, FtSession, FtUiLocale } from "@fluid-topics/public-api";
3
+ import { PayloadAction } from "@reduxjs/toolkit";
3
4
  export declare const FtAppInfoStoreName = "ft-app-info";
4
5
  export interface FtAppInfoState {
5
6
  baseUrl: Optional<string>;
@@ -15,7 +16,12 @@ export interface FtAppInfoState {
15
16
  navigatorOnline: boolean;
16
17
  forcedOffline: boolean;
17
18
  }
18
- declare const reducers: {};
19
+ export declare class AuthenticationChangeEvent extends CustomEvent<Optional<FtSession>> {
20
+ constructor(session: Optional<FtSession>);
21
+ }
22
+ declare const reducers: {
23
+ session: (state: FtAppInfoState, action: PayloadAction<Optional<FtSession>>) => void;
24
+ };
19
25
  export type FtAppInfoStateReducers = typeof reducers;
20
26
  export type FtAppInfoStore = FtReduxStore<FtAppInfoState, FtAppInfoStateReducers>;
21
27
  export declare const ftAppInfoStore: FtAppInfoStore;
@@ -1,6 +1,18 @@
1
- import { FtReduxStore } from "@fluid-topics/ft-wc-utils";
1
+ import { deepEqual, FtReduxStore } from "@fluid-topics/ft-wc-utils";
2
2
  export const FtAppInfoStoreName = "ft-app-info";
3
- const reducers = {};
3
+ export class AuthenticationChangeEvent extends CustomEvent {
4
+ constructor(session) {
5
+ super("authentication-change", { detail: session });
6
+ }
7
+ }
8
+ const reducers = {
9
+ session: (state, action) => {
10
+ if (!deepEqual(state.session, action.payload)) {
11
+ state.session = action.payload;
12
+ setTimeout(() => ftAppInfoStore.eventBus.dispatchEvent(new AuthenticationChangeEvent(action.payload)), 0);
13
+ }
14
+ }
15
+ };
4
16
  export const ftAppInfoStore = FtReduxStore.get({
5
17
  name: FtAppInfoStoreName,
6
18
  reducers: reducers,
@@ -0,0 +1,15 @@
1
+ declare global {
2
+ interface Window {
3
+ FluidTopicsDateService: DateService;
4
+ }
5
+ }
6
+ interface DateServiceFormatOptions {
7
+ locale?: string;
8
+ longFormat?: boolean;
9
+ withTime?: boolean;
10
+ }
11
+ export declare class DateService {
12
+ isDate(metadataKey: string): boolean;
13
+ format(date: string, options?: DateServiceFormatOptions): string;
14
+ }
15
+ export {};
@@ -0,0 +1,14 @@
1
+ import { DateFormatter } from "@fluid-topics/ft-wc-utils";
2
+ import { ftAppInfoStore } from "../redux-stores/FtAppInfoStore";
3
+ export class DateService {
4
+ isDate(metadataKey) {
5
+ var _a, _b, _c, _d;
6
+ const descriptors = (_b = (_a = ftAppInfoStore.getState().metadataConfiguration) === null || _a === void 0 ? void 0 : _a.descriptors) !== null && _b !== void 0 ? _b : [];
7
+ return (_d = (_c = descriptors.find(descriptor => descriptor.key === metadataKey)) === null || _c === void 0 ? void 0 : _c.date) !== null && _d !== void 0 ? _d : false;
8
+ }
9
+ format(date, options) {
10
+ var _a, _b, _c;
11
+ return DateFormatter.format(date, (_a = options === null || options === void 0 ? void 0 : options.locale) !== null && _a !== void 0 ? _a : ftAppInfoStore.getState().uiLocale, (_b = options === null || options === void 0 ? void 0 : options.longFormat) !== null && _b !== void 0 ? _b : false, (_c = options === null || options === void 0 ? void 0 : options.withTime) !== null && _c !== void 0 ? _c : false);
12
+ }
13
+ }
14
+ window.FluidTopicsDateService = new DateService();
@@ -16,6 +16,10 @@ export declare class FtI18nServiceInternalClass extends FtServiceWithCache {
16
16
  constructor(messageContextProvider: (locale: string, name: string) => Promise<FtMessageContext>);
17
17
  [clearAfterUnitTest]: () => void;
18
18
  private clearWhenUiLocaleChanges;
19
+ /**
20
+ * ⚠️ Only use in GWT or unit test contexts
21
+ * @param context
22
+ */
19
23
  addContext(context: FtMessageContext): void;
20
24
  getAllContexts(): Array<FtMessageContext>;
21
25
  prepareContext(name: string, defaultMessages: Record<string, string>): Promise<void>;
@@ -26,6 +26,10 @@ export class FtI18nServiceInternalClass extends FtServiceWithCache {
26
26
  this.notifyAll();
27
27
  }
28
28
  }
29
+ /**
30
+ * ⚠️ Only use in GWT or unit test contexts
31
+ * @param context
32
+ */
29
33
  addContext(context) {
30
34
  const name = context.name.toLowerCase();
31
35
  this.cache.setFinal(name, context);
@@ -1,11 +1,11 @@
1
1
  import { CacheRegistry } from "@fluid-topics/ft-wc-utils";
2
- import { FluidTopicsApi } from "@fluid-topics/public-api";
2
+ import type { FluidTopicsApi } from "@fluid-topics/public-api";
3
3
  export declare class FtServiceWithCache {
4
4
  private overrideApi?;
5
5
  static commonCache: CacheRegistry;
6
6
  cache: CacheRegistry;
7
7
  constructor(withCommonCache?: boolean, overrideApi?: FluidTopicsApi | undefined);
8
8
  protected get api(): FluidTopicsApi;
9
- protected get awaitApi(): FluidTopicsApi | Promise<FluidTopicsApi>;
9
+ protected get awaitApi(): Promise<FluidTopicsApi>;
10
10
  clearCache(): void;
11
11
  }
@@ -14,8 +14,7 @@ export class FtServiceWithCache {
14
14
  return (_a = this.overrideApi) !== null && _a !== void 0 ? _a : FluidTopicsApiProvider.get();
15
15
  }
16
16
  get awaitApi() {
17
- var _a;
18
- return (_a = this.overrideApi) !== null && _a !== void 0 ? _a : FluidTopicsApiProvider.await();
17
+ return this.overrideApi ? Promise.resolve(this.overrideApi) : FluidTopicsApiProvider.await();
19
18
  }
20
19
  clearCache() {
21
20
  this.cache.clearAll();
@@ -5,3 +5,4 @@ export * from "./FtI18nService";
5
5
  export * from "./FtServiceWithCache";
6
6
  export * from "./HighlightHtmlService";
7
7
  export * from "./SavedSearchesService";
8
+ export * from "./DateService";
@@ -5,3 +5,4 @@ export * from "./FtI18nService";
5
5
  export * from "./FtServiceWithCache";
6
6
  export * from "./HighlightHtmlService";
7
7
  export * from "./SavedSearchesService";
8
+ export * from "./DateService";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-app-context",
3
- "version": "1.1.81",
3
+ "version": "1.1.83",
4
4
  "description": "Global application context for Fluid Topics integrations",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,11 +19,11 @@
19
19
  "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
20
  },
21
21
  "dependencies": {
22
- "@fluid-topics/ft-wc-utils": "1.1.81",
22
+ "@fluid-topics/ft-wc-utils": "1.1.83",
23
23
  "lit": "3.1.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@fluid-topics/public-api": "1.0.70"
26
+ "@fluid-topics/public-api": "1.0.71"
27
27
  },
28
- "gitHead": "5dea8a4771738158973c6e7abcd669b1ba24d778"
28
+ "gitHead": "2ca7449aa6df93b0b6ba0794e695aa3f605f38bf"
29
29
  }