@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
352 lines (344 loc) • 19.4 kB
TypeScript
import { ApplicationOptions, OptionsService, GainsightService, ZipService, AppStateService, ThemeSwitcherService } from '@c8y/ngx-components';
import * as _angular_forms from '@angular/forms';
import { FormBuilder, FormControl } from '@angular/forms';
import * as i0 from '@angular/core';
import { IApplication, ApplicationType, ApplicationAvailability, ApplicationService, InventoryService, InventoryBinaryService, FetchClient, IApplicationBinary } from '@c8y/client';
import { BehaviorSubject, Observable } from 'rxjs';
import { StaticAssetsService, StaticAsset } from '@c8y/ngx-components/static-assets/data';
type BrandingFormValue = ReturnType<typeof createGenericBrandingForm>['value'];
type BrandingFormKeys = keyof BrandingFormValue;
type BrandingFormTopLevelKeys = (typeof brandingFormGroupTopLevelEntries)[number];
type BrandingFormTopLevelKeysToUnpack = (typeof brandingFormGroupTopLevelEntriesToUnpack)[number];
type TopLevelFormKeysNotToUnpack = Exclude<BrandingFormTopLevelKeys, BrandingFormTopLevelKeysToUnpack>;
type UnpackedTopLevelFormKeys = Pick<BrandingFormValue, BrandingFormTopLevelKeysToUnpack>[keyof Pick<BrandingFormValue, BrandingFormTopLevelKeysToUnpack>];
type NotUnpackedTopLevelFormKeys = Pick<BrandingFormValue, TopLevelFormKeysNotToUnpack>;
type TopLevelForm = NotUnpackedTopLevelFormKeys & UnpackedTopLevelFormKeys;
type TopLevelValues = TopLevelForm;
type BrandingCSSVarsForm = Omit<BrandingFormValue, BrandingFormTopLevelKeys>;
type LightBrandingCSSVarsValues = ReturnType<typeof createBrandingForm>['value'] & BrandingCSSVarsForm[keyof BrandingCSSVarsForm];
type addPrefixToObject<T, P extends string> = {
[K in keyof T as K extends string ? `${P}${K}` : never]: T[K];
};
type DarkBrandingCSSVarsValues = addPrefixToObject<LightBrandingCSSVarsValues, 'dark-'>;
type BrandingCSSVarsValues = LightBrandingCSSVarsValues & DarkBrandingCSSVarsValues;
type BrandingOptionsJson = TopLevelValues & {
brandingCssVars?: BrandingCSSVarsValues & {
[key: string]: any;
};
} & Omit<Partial<ApplicationOptions>, 'brandingCssVars'> & {
[key: string]: any;
};
declare const brandingFormGroupTopLevelEntries: readonly ["cookieBanner", "genericApplicationOptions", "darkThemeAvailable", "messageBanner"];
declare const brandingFormGroupTopLevelEntriesToUnpack: readonly ["genericApplicationOptions"];
declare const numberBrandingVars: readonly ["brand-logo-img-height", "btn-border-radius-base"];
declare const colorBrandingVars: readonly ["brand-dark", "brand-light", "brand-primary", "c8y-brand-10", "c8y-brand-20", "c8y-brand-30", "c8y-brand-40", "c8y-brand-50", "c8y-brand-60", "c8y-brand-70", "c8y-brand-80", "palette-status-info", "palette-status-warning", "palette-status-success", "palette-status-danger", "palette-status-info-light", "palette-status-warning-light", "palette-status-success-light", "palette-status-danger-light", "palette-status-info-dark", "palette-status-warning-dark", "palette-status-success-dark", "palette-status-danger-dark", "body-background-color", "text-color", "text-muted", "link-color", "link-hover-color", "action-bar-background-default", "action-bar-color-actions-hover", "action-bar-color-actions", "action-bar-color-default", "action-bar-icon-color", "header-color", "header-text-color", "header-hover-color", "navigator-bg-color", "navigator-active-bg", "navigator-border-active", "navigator-header-bg", "navigator-title-color", "navigator-separator-color", "navigator-text-color", "navigator-color-active", "right-drawer-background-default", "right-drawer-text-color-default", "right-drawer-separator-color", "right-drawer-link-color", "right-drawer-link-color-hover", "right-drawer-text-color-muted"];
declare const stringBrandingVars: readonly ["brand-logo-img", "navigator-platform-logo", "login-platform-animation-img"];
declare const stringOrNumberBrandingVars: readonly ["navigator-platform-logo-height"];
declare const allBrandingCSSVars: readonly ["brand-logo-img-height", "btn-border-radius-base", "brand-logo-img", "navigator-platform-logo", "login-platform-animation-img", "brand-dark", "brand-light", "brand-primary", "c8y-brand-10", "c8y-brand-20", "c8y-brand-30", "c8y-brand-40", "c8y-brand-50", "c8y-brand-60", "c8y-brand-70", "c8y-brand-80", "palette-status-info", "palette-status-warning", "palette-status-success", "palette-status-danger", "palette-status-info-light", "palette-status-warning-light", "palette-status-success-light", "palette-status-danger-light", "palette-status-info-dark", "palette-status-warning-dark", "palette-status-success-dark", "palette-status-danger-dark", "body-background-color", "text-color", "text-muted", "link-color", "link-hover-color", "action-bar-background-default", "action-bar-color-actions-hover", "action-bar-color-actions", "action-bar-color-default", "action-bar-icon-color", "header-color", "header-text-color", "header-hover-color", "navigator-bg-color", "navigator-active-bg", "navigator-border-active", "navigator-header-bg", "navigator-title-color", "navigator-separator-color", "navigator-text-color", "navigator-color-active", "right-drawer-background-default", "right-drawer-text-color-default", "right-drawer-separator-color", "right-drawer-link-color", "right-drawer-link-color-hover", "right-drawer-text-color-muted"];
declare function createGenericBrandingForm(formBuilder: FormBuilder): _angular_forms.FormGroup<{
darkThemeAvailable: FormControl<boolean>;
cookieBanner: _angular_forms.FormGroup<{
cookieBannerTitle: FormControl<string>;
cookieBannerText: FormControl<string>;
cookieBannerDisabled: FormControl<boolean>;
policyUrl: FormControl<string>;
policyVersion: FormControl<string>;
}>;
messageBanner: _angular_forms.FormGroup<{
messageBannerEnabled: FormControl<boolean>;
messageBannerContent: FormControl<string>;
messageBannerType: FormControl<"success" | "warning" | "danger" | "info" | "system">;
messageBannerId: FormControl<string>;
}>;
baseTypography: _angular_forms.FormGroup<{
'font-url': FormControl<string>;
'font-family-base': FormControl<string>;
}>;
headingsAndNavigatorTypography: _angular_forms.FormGroup<{
'font-family-headings': FormControl<string>;
'navigator-font-family': FormControl<string>;
}>;
genericApplicationOptions: _angular_forms.FormGroup<{
globalTitle: FormControl<string>;
faviconUrl: FormControl<string>;
}>;
}>;
declare function createBrandingForm(formBuilder: FormBuilder): _angular_forms.FormGroup<{
"navigator-platform-logo-height": FormControl<string | number>;
"brand-logo-img-height": FormControl<number>;
"btn-border-radius-base": FormControl<number>;
"brand-logo-img": FormControl<string>;
"navigator-platform-logo": FormControl<string>;
"login-platform-animation-img": FormControl<string>;
"brand-dark": FormControl<string>;
"brand-light": FormControl<string>;
"brand-primary": FormControl<string>;
"c8y-brand-10": FormControl<string>;
"c8y-brand-20": FormControl<string>;
"c8y-brand-30": FormControl<string>;
"c8y-brand-40": FormControl<string>;
"c8y-brand-50": FormControl<string>;
"c8y-brand-60": FormControl<string>;
"c8y-brand-70": FormControl<string>;
"c8y-brand-80": FormControl<string>;
"palette-status-info": FormControl<string>;
"palette-status-warning": FormControl<string>;
"palette-status-success": FormControl<string>;
"palette-status-danger": FormControl<string>;
"palette-status-info-light": FormControl<string>;
"palette-status-warning-light": FormControl<string>;
"palette-status-success-light": FormControl<string>;
"palette-status-danger-light": FormControl<string>;
"palette-status-info-dark": FormControl<string>;
"palette-status-warning-dark": FormControl<string>;
"palette-status-success-dark": FormControl<string>;
"palette-status-danger-dark": FormControl<string>;
"body-background-color": FormControl<string>;
"text-color": FormControl<string>;
"text-muted": FormControl<string>;
"link-color": FormControl<string>;
"link-hover-color": FormControl<string>;
"action-bar-background-default": FormControl<string>;
"action-bar-color-actions-hover": FormControl<string>;
"action-bar-color-actions": FormControl<string>;
"action-bar-color-default": FormControl<string>;
"action-bar-icon-color": FormControl<string>;
"header-color": FormControl<string>;
"header-text-color": FormControl<string>;
"header-hover-color": FormControl<string>;
"navigator-bg-color": FormControl<string>;
"navigator-active-bg": FormControl<string>;
"navigator-border-active": FormControl<string>;
"navigator-header-bg": FormControl<string>;
"navigator-title-color": FormControl<string>;
"navigator-separator-color": FormControl<string>;
"navigator-text-color": FormControl<string>;
"navigator-color-active": FormControl<string>;
"right-drawer-background-default": FormControl<string>;
"right-drawer-text-color-default": FormControl<string>;
"right-drawer-separator-color": FormControl<string>;
"right-drawer-link-color": FormControl<string>;
"right-drawer-link-color-hover": FormControl<string>;
"right-drawer-text-color-muted": FormControl<string>;
}>;
declare class ApplyBrandingLocallyService {
private options;
private keysToRemove;
constructor(options: OptionsService);
applyBranding(optionsJson?: BrandingOptionsJson): void;
resetBranding(): void;
private applyApplicationOptions;
private removeKeysFromOptions;
private combineOptions;
static ɵfac: i0.ɵɵFactoryDeclaration<ApplyBrandingLocallyService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ApplyBrandingLocallyService>;
}
declare class BrandingShadesService {
getShadeColorBrandingCssVars(newBrandPrimary: string): Record<`c8y-brand-${number}0`, string>;
isValidShadeColor(color: string): boolean;
hasCustomShadesSet(previousBrandPrimary: string, otherVars: Record<string, string | number>): boolean;
private shadesToObject;
private generateShades;
static ɵfac: i0.ɵɵFactoryDeclaration<BrandingShadesService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<BrandingShadesService>;
}
/**
* Service for creating and manipulating branding versions.
*/
declare class BrandingVersionService {
static readonly nameAndIterationSeparator = "-";
/**
* Creates the initial branding version for a given name.
* @param name The name of the branding.
* @returns The initial branding version.
*/
createInitialBrandingVersion<T extends string>(name: T): `${T}-1`;
/**
* Splits a branding version into its name and iteration.
* @param version The branding version to split.
* @returns The name and iteration of the branding version.
*
* Errors are thrown if the version is not in the expected format.
*/
splitBrandingIntoNameAndIteration(version: string): {
name: string;
iteration: number;
};
/**
* Bumps the iteration of a branding version.
* @param version The branding version to bump.
* @returns The bumped branding version.
*
* Errors are thrown if the version is not in the expected format.
*/
bumpBrandingIteration(version: string): `${string}-${number}`;
static ɵfac: i0.ɵɵFactoryDeclaration<BrandingVersionService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<BrandingVersionService>;
}
declare class BrandingTrackingService {
private gainsight;
readonly prefix = "brandingManager";
constructor(gainsight: GainsightService);
getStartedUsingBranding(): void;
deleteAllBrandings(): void;
exportBranding(): void;
addNewVersion(): void;
duplicateVersion(): void;
applyToApps(apps: string[]): void;
importBranding(): void;
deleteBrandingVariant(): void;
openPreviewForBranding(): void;
private triggerEvent;
static ɵfac: i0.ɵɵFactoryDeclaration<BrandingTrackingService, [{ optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<BrandingTrackingService>;
}
interface BrandVersion {
name: string;
id: string;
revision: number;
version: string;
tags: string[];
owner?: string;
lastUpdated?: string;
publicOptionsApp?: IApplication;
}
interface BrandingFileDetails {
fileName: string;
blob: Blob;
jsonContent?: any;
}
interface BrandingFileDetailsLegacy {
path: string;
value: string;
blob?: Blob;
fileName: string;
urlWrapped: boolean;
}
/**
* Service to load and store the branding of the tenant.
*/
declare class StoreBrandingService {
private applicationService;
private inventory;
private binary;
private zip;
private fetch;
private brandingVersionService;
private appState;
private staticAssets;
private themeSwitcher;
private brandingTracking;
readonly fileNames: {
readonly options: "options.json";
readonly manifest: "cumulocity.json";
readonly exportZipName: "public-options.zip";
};
readonly manifestValues: {
readonly name: "public-options";
readonly contextPath: "public-options";
readonly key: "public-options-key";
readonly description: "Application containing static assets used by e.g. branding.";
readonly noAppSwitcher: true;
readonly type: ApplicationType.HOSTED;
readonly availability: ApplicationAvailability.SHARED;
};
refreshTriggerBrandingVariants: BehaviorSubject<void>;
constructor(applicationService: ApplicationService, inventory: InventoryService, binary: InventoryBinaryService, zip: ZipService, fetch: FetchClient, brandingVersionService: BrandingVersionService, appState: AppStateService, staticAssets: StaticAssetsService, themeSwitcher: ThemeSwitcherService, brandingTracking: BrandingTrackingService);
/**
* Sets the `latest` tag on the provided branding version. Making it the global active branding.
*/
markAsActive(brandingVersion: BrandVersion, app?: IApplication): Promise<void>;
/**
* Opens a new tab with to preview the branding. The branding must have been saved beforehand.
* @param brandingName the name of the branding to be previewed
*/
openPreviewForBranding(brandingName: string): void;
/**
* Returns the brandings of the tenant.
* If no public options app is found, publicOptions will be undefined and variants an empty array.
* For old brandings (created without versioning) a default version is returned.
*/
loadBrandingVariants(app?: IApplication): Promise<{
publicOptions: IApplication | undefined;
variants: BrandVersion[];
}>;
/**
* As the branding is not immediately available after creation, this method will wait for the branding to be present.
* @param version The version of the branding to be retrieved.
*/
waitForBrandingToBePresent(version: string): Promise<void>;
/**
* Will create a the initial branding based on the currently applied CSS variables.
*/
getStartedUsingBranding(): Promise<void>;
getZipForBinary(binaryId: string, fileName?: string): Observable<File>;
/**
* Deletes the public options app and therefore all brandings.
* The public options app can be optionally provided to avoid another request for it.
*/
deleteAllBrandings(publicOptions?: IApplication): Promise<void>;
/**
* Enhances the provided branding versions with metadata from the linked binaries.
* It will add the owner and lastUpdated fields to the versions.
* The provided array is altered.
*/
getMetadataOfBrandingBinaries(versions: BrandVersion[]): Promise<BrandVersion[]>;
/**
* Saves the provided branding as a new version for the public options app.
* The public options app can be optionally provided to avoid another request for it.
*/
saveBranding(blob: Blob | File, version: string, tags?: string[], publicOptionsApp?: IApplication): Promise<{
version: string;
binary: IApplicationBinary;
tags: string[];
}>;
/**
* Removes a branding version from the public options app.
* The public options app can be optionally provided to avoid another request for it.
*/
deleteBrandingVersion(version: string, publicOptions?: IApplication): Promise<void>;
/**
* Returns the blob of a zip file containing the provided branding options (options.json) and the manifest (cumulocity.json).
*/
getBrandingZip(content?: Record<string, any>): Promise<Blob>;
/**
* Adds a new branding version to the public options app.
* The public options app can be optionally provided to avoid another request for it.
*/
addBranding(version: string, content?: BrandingOptionsJson, tags?: string[], publicOptionsApp?: IApplication): Promise<{
version: string;
binary: IApplicationBinary;
tags: string[];
}>;
/**
* Returns the branding options for the provided version.
* If no branding was found (e.g. status 404), an error is thrown.
*/
getBrandingOptionsForVersion(version?: string): Promise<BrandingOptionsJson>;
/**
* Saves a new iteration of an already existing branding.
*/
saveExistingBranding(branding: Record<string, any>, currentVersion: string, tagsOfCurrentVersion?: string[], newVersion?: string): Promise<string>;
/**
* Combines current branding options with the provided branding variables and creates a new public options app.
* Any assets in the branding will be cloned.
*/
createPublicOptionsAppFromInheritedOptions(brandingVars?: Record<string, string>): Promise<{
version: string;
binary: IApplicationBinary;
tags: string[];
}>;
/**
* Replaces the assets in the branding options with the new assets.
* Goes through the provided `oldAssets` and replaces their occurrences in the branding with the corresponding `newAssets` entry sharing the same fileName.
* Returns the updated branding options.
*/
replaceBrandingAssetsInBrandingOptions(branding: BrandingOptionsJson, oldAssets: StaticAsset[], newAssets: StaticAsset[]): BrandingOptionsJson;
private getPublicOptionsApp;
private createPublicOptionsApp;
static ɵfac: i0.ɵɵFactoryDeclaration<StoreBrandingService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<StoreBrandingService>;
}
export { ApplyBrandingLocallyService, BrandingShadesService, BrandingTrackingService, BrandingVersionService, StoreBrandingService, allBrandingCSSVars, brandingFormGroupTopLevelEntries, brandingFormGroupTopLevelEntriesToUnpack, colorBrandingVars, createBrandingForm, createGenericBrandingForm, numberBrandingVars, stringBrandingVars, stringOrNumberBrandingVars };
export type { BrandVersion, BrandingCSSVarsForm, BrandingCSSVarsValues, BrandingFileDetails, BrandingFileDetailsLegacy, BrandingFormKeys, BrandingFormTopLevelKeys, BrandingFormTopLevelKeysToUnpack, BrandingFormValue, BrandingOptionsJson, DarkBrandingCSSVarsValues, LightBrandingCSSVarsValues, NotUnpackedTopLevelFormKeys, TopLevelForm, TopLevelFormKeysNotToUnpack, TopLevelValues, UnpackedTopLevelFormKeys };
//# sourceMappingURL=index.d.ts.map