UNPKG

@o3r/dynamic-content

Version:

This module provides a mechanism to retrieve media and data depending on the host or a server specific url.

408 lines (391 loc) 16.7 kB
import * as i0 from '@angular/core'; import { PipeTransform, OnDestroy, ChangeDetectorRef, ModuleWithProviders, Provider, EnvironmentProviders, InjectionToken } from '@angular/core'; import * as rxjs from 'rxjs'; import { Subscription } from 'rxjs'; import * as _ngrx_store from '@ngrx/store'; import { ActionReducer, Action, ReducerTypes, ActionCreator } from '@ngrx/store'; import { SetStateActionPayload, Serializer } from '@o3r/core'; /** * Service for getting dynamic content path */ declare class DynamicContentService { private readonly cmsOnlyAssetsPath; private readonly store; readonly basePath: string; private readonly mediaFolder; constructor(); private normalizePath; private getContentPath; private getMediaPath; /** * Gets the full path of a content relative to the root * Content path doesn't consider any override, you will always get the same file * @param assetPath asset location in the root folder * @example * ```typescript * getMediaPath('assets/imgs/my-image.png') // will give you the basePath + 'assets/imgs/my-image.png' * ``` */ getContentPathStream(assetPath?: string): rxjs.Observable<string>; /** * Gets the stream that provides the full path of a media content * A Media content is always stored in the 'assets' media folder, no external content will be accessible through this function * If any override is applied to the content, returns the override path instead * @param assetPath asset location in the media folder (e.g imgs/my-image.png) * @example * ```typescript * getMediaPathStream('imgs/my-image.png') // will give you the basePath + mediaFolder + 'imgs/my-image.png' * ``` */ getMediaPathStream(assetPath?: string): rxjs.Observable<string>; static ɵfac: i0.ɵɵFactoryDeclaration<DynamicContentService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<DynamicContentService>; } declare class O3rDynamicContentPipe implements PipeTransform, OnDestroy { protected readonly service: DynamicContentService; protected readonly cd: ChangeDetectorRef; /** Last query value */ protected lastQuery?: string; /** Subscription to retrieve media path */ protected onMediaPathChange?: Subscription; /** Path to the media */ protected mediaPath: string; /** @inheritDoc */ transform(query?: string): string; /** @inheritDoc */ ngOnDestroy(): void; static ɵfac: i0.ɵɵFactoryDeclaration<O3rDynamicContentPipe, never>; static ɵpipe: i0.ɵɵPipeDeclaration<O3rDynamicContentPipe, "o3rDynamicContent", true>; } /** * Function to get dynamic content from body dataset */ declare function getDynamicContent(): string; /** * Function to get the cms assets from body dataset * This will be used only in a CMS context(not in local or prod) to display correctly the assets in the editor */ declare function getCmsAssets(): string; /** * DynamicContent module * @deprecated Will be removed in v14. */ declare class DynamicContentModule { /** * Customize the location where the application will search for the base path of dynamic content * @param dynamicPath Configuration for dynamic content path * @param dynamicPath.content The string will be used as base path of dynamic content * @param dynamicPath.cmsAssets The string will be used for the the base path of cms assets * @note The cmsAssets will be used only in the cms editor mode and it will take priority over dynamic content * @deprecated Please use {@link provideDynamicContent} instead. Will be removed in v14. */ static forRoot(dynamicPath: { content: string; } | { cmsAssets: string; }): ModuleWithProviders<DynamicContentModule>; static ɵfac: i0.ɵɵFactoryDeclaration<DynamicContentModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<DynamicContentModule, never, [typeof O3rDynamicContentPipe], [typeof O3rDynamicContentPipe]>; static ɵinj: i0.ɵɵInjectorDeclaration<DynamicContentModule>; } type DynamicContentFeatureKind = 'base-path' | 'cms-assets-path'; interface DynamicContentFeature<FeatureKind extends DynamicContentFeatureKind> { ɵkind: FeatureKind; ɵproviders: Provider[]; } type BasePathFeature = DynamicContentFeature<'base-path'>; type CmsAssetsPathFeature = DynamicContentFeature<'cms-assets-path'>; type DynamicContentFeatures = BasePathFeature | CmsAssetsPathFeature; /** * Specify a custom base path * @param basePath */ declare function withBasePath(basePath: string | (() => string)): BasePathFeature; /** * Specify a custom CMS assets path * @param cmsAssetsPath */ declare function withCmsAssetsPath(cmsAssetsPath: string | (() => string)): DynamicContentFeature<'cms-assets-path'>; /** * Provide dynamic content default configuration. * To customize the location where the application will search for the base path of dynamic content * @see {@link withBasePath} * @see {@link withCmsAssetsPath} * @note The cmsAssets will be used only in the cms editor mode and it will take priority over dynamic content * @param features * @example * ```typescript * bootstrapApplication(App, * { * providers: [ * provideDynamicContent( * withBasePath('custom/base/path'), * withCmsAssetsPath('custom/cms/assets/path'), * ) * ] * } * ); */ declare function provideDynamicContent(...features: DynamicContentFeatures[]): EnvironmentProviders; /** * Injection token for the rootpath of dynamic content */ declare const DYNAMIC_CONTENT_BASE_PATH_TOKEN: InjectionToken<string>; /** * Injection token for the assets path injected by the cms * This token will be injected only in editor mode */ declare const CMS_ASSETS_PATH_TOKEN: InjectionToken<string>; /** * Strategies available to read / write data in the RequestParameters service. * Rehydrate: if the storage already have data, those will be used by the service, ignoring new data. Otherwise set the storage * Merge: storage data will be merged with the ones provided. (provided data has priority) * Replace: storage data will be completely replaced by the ones provided * ReplaceIfNotEmpty: If no parameters are provided, use the content from storage. Otherwise use the ones provided and update the storage with them. */ declare enum StorageStrategy { Rehydrate = 0, Merge = 1, Replace = 2, ReplaceIfNotEmpty = 3 } /** * Configuration used by a user to feed the request parameters service. */ interface RequestParametersConfig { /** * Strategy used by the RequestParameters Service. See StorageStrategy for more info */ strategy: StorageStrategy; /** * Storage used by the RequestParameters service */ storage?: Storage; /** * Value of the DOM element containing your query parameters (e.g. `document.body.dataset.query`) */ queryParamsValue: string; /** * Value of the DOM element containing your post parameters (e.g. `document.body.dataset.post`) */ postParamsValue: string; } declare const defaultRequestParametersConfig: Readonly<RequestParametersConfig>; /** * Empty configuration factory, used when config is not provided. It needs a separate function for AOT. */ declare function defaultConfigFactory(): {}; /** * RequestParametersService Module * @deprecated Will be removed in v14. */ declare class RequestParametersModule { /** * Provide request parameters config * @param config * @deprecated Please use {@link provideRequestParameters} instead. Will be removed in v14. */ static forRoot(config?: () => Partial<RequestParametersConfig>): ModuleWithProviders<RequestParametersModule>; static ɵfac: i0.ɵɵFactoryDeclaration<RequestParametersModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<RequestParametersModule, never, never, never>; static ɵinj: i0.ɵɵInjectorDeclaration<RequestParametersModule>; } /** * Provide request parameters config * We don't provide directly the value and use a factory because otherwise AOT compilation will resolve to undefined whatever is taken from window * @param config */ declare function provideRequestParameters(config?: () => Partial<RequestParametersConfig>): i0.EnvironmentProviders; type ParamsList = 'query' | 'post'; type ParamsType = { [k in ParamsList]: { [key: string]: string; }; }; /** * Partial configuration for RequestParameters Service */ interface PartialRequestParametersConfig extends Partial<RequestParametersConfig> { } /** * Service used to store the request parameters of your requests so that subsequent calls or refresh the page will preserve * them. */ declare class RequestParametersService implements ParamsType { private _query; private _post; private readonly config; constructor(); /** * Depending on the strategy, set the internal values for the parameters. * See StorageStrategy for more info. * @param key * @param value */ private setParameters; /** * Get all the query parameters in a map. */ get query(): { [key: string]: any; }; /** * Get all the post parameters in a map. */ get post(): { [key: string]: any; }; /** * Get a specific query parameter value, given the key. * @param key */ getQueryParameter(key: string): string | undefined; /** * Get a specific query parameter value as boolean, given the key. * @param key */ getQueryParameterAsBoolean(key: string): boolean | undefined; /** * Get a specific post parameter value, given the key. * @param key */ getPostParameter(key: string): string | undefined; /** * Get a specific post parameter value as boolean, given the key. * @param key */ getPostParameterAsBoolean(key: string): boolean | undefined; /** * Get a specific parameter value, given the key. * @param key */ getParameter(key: string): string | undefined; /** * Get a specific parameter value as boolean, given the key. * @param key */ getParameterAsBoolean(key: string): boolean | undefined; /** * Clear GET parameters from the storage * @param paramsToClear the list on key that you want to clear in get parameters */ clearQueryParameters(paramsToClear?: string[]): void; /** * Clear POST parameters from the storage * @param paramsToClear the list on key that you want to clean in post parameters */ clearPostParameters(paramsToClear?: string[]): void; /** * Get all the parameters in a map. * @param priority the parameter to be given priority in case same key is in get and post params. */ getParams(priority?: ParamsList): { [x: string]: any; }; /** * Filter Parameters(both Query/POST) from the storage * @param paramstoFilter the list on key that you want to filter from parameters * @param priority the priorty of the parameter type(POST/Query) */ getFilteredParameters(paramstoFilter?: string[], priority?: ParamsList): { [x: string]: any; }; static ɵfac: i0.ɵɵFactoryDeclaration<RequestParametersService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<RequestParametersService>; } declare class StyleLazyLoaderModule { static ɵfac: i0.ɵɵFactoryDeclaration<StyleLazyLoaderModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<StyleLazyLoaderModule, never, [typeof DynamicContentModule], never>; static ɵinj: i0.ɵɵInjectorDeclaration<StyleLazyLoaderModule>; } /** * Interface to describe a style to lazy load from a url. */ interface StyleURL { /** url to file */ href: string; /** id of the HTML element */ id?: string; /** html integrity attribute to verify fetched resources */ integrity?: string; /** html crossOrigin attribute for CORS support. */ crossOrigin?: 'anonymous' | 'use-credentials' | ''; } /** * Service to lazy load a CSS file */ declare class StyleLazyLoader { private readonly dcService; private readonly DEFAULT_STYLE_ELEMENT_ID; /** * Load a new CSS from an absolute URL, if we already HTML element exists with the url, otherwise * @param styleUrlConfig object containing CSS File absolute URL to load, integrity and crossOrigin attributes * and the styleId id of the dynamic style in the body tag. */ loadStyleFromURL(styleUrlConfig: StyleURL): HTMLLinkElement; /** * Load a new CSS File * @param styleUrlConfig CSS File config containing URL to load, integrity and crossOrigin attributes * and the styleId id of the dynamic style in the body tag */ asyncLoadStyleFromDynamicContent(styleUrlConfig: StyleURL): Promise<void>; static ɵfac: i0.ɵɵFactoryDeclaration<StyleLazyLoader, never>; static ɵprov: i0.ɵɵInjectableDeclaration<StyleLazyLoader>; } /** * AssetPathOverride store state */ interface AssetPathOverrideState { /** Mapping of asset path (key) and its override (value)*/ assetPathOverrides: Record<string, string>; } /** * Name of the AssetPathOverride Store */ declare const ASSET_PATH_OVERRIDE_STORE_NAME = "assetPathOverride"; /** * AssetPathOverride Store Interface */ interface AssetPathOverrideStore { /** AssetPathOverride state */ [ASSET_PATH_OVERRIDE_STORE_NAME]: AssetPathOverrideState; } /** * Clear all overrides and fill the store with the payload */ declare const setAssetPathOverride: _ngrx_store.ActionCreator<"[AssetPathOverride] set entities", (props: SetStateActionPayload<AssetPathOverrideState>) => SetStateActionPayload<AssetPathOverrideState> & _ngrx_store.Action<"[AssetPathOverride] set entities">>; /** Token of the AssetPathOverride reducer */ declare const ASSET_PATH_OVERRIDE_REDUCER_TOKEN: InjectionToken<ActionReducer<AssetPathOverrideState, Action<string>>>; /** Provide default reducer for AssetPathOverride store */ declare function getDefaultAssetPathOverrideReducer(): ActionReducer<AssetPathOverrideState, Action<string>>; declare class AssetPathOverrideStoreModule { static forRoot<T extends AssetPathOverrideState>(reducerFactory: () => ActionReducer<T, Action>): ModuleWithProviders<AssetPathOverrideStoreModule>; static ɵfac: i0.ɵɵFactoryDeclaration<AssetPathOverrideStoreModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<AssetPathOverrideStoreModule, never, [typeof _ngrx_store.StoreFeatureModule], never>; static ɵinj: i0.ɵɵInjectorDeclaration<AssetPathOverrideStoreModule>; } /** * AssetPathOverride Store initial value */ declare const assetPathOverrideInitialState: AssetPathOverrideState; /** * List of basic actions for AssetPathOverride Store */ declare const assetPathOverrideReducerFeatures: ReducerTypes<AssetPathOverrideState, ActionCreator[]>[]; /** * AssetPathOverride Store reducer */ declare const assetPathOverrideReducer: _ngrx_store.ActionReducer<AssetPathOverrideState, _ngrx_store.Action<string>>; /** Select AssetPathOverride State */ declare const selectAssetPathOverrideState: _ngrx_store.MemoizedSelector<object, AssetPathOverrideState, _ngrx_store.DefaultProjectorFn<AssetPathOverrideState>>; /** Select all assetPath override map */ declare const selectAssetPathOverride: _ngrx_store.MemoizedSelector<object, Record<string, string>, (s1: AssetPathOverrideState) => Record<string, string>>; /** * Deserializer * @param rawObject */ declare const assetPathOverrideStorageDeserializer: (rawObject: any) => any; declare const assetPathOverrideStorageSync: Serializer<AssetPathOverrideState>; export { ASSET_PATH_OVERRIDE_REDUCER_TOKEN, ASSET_PATH_OVERRIDE_STORE_NAME, AssetPathOverrideStoreModule, CMS_ASSETS_PATH_TOKEN, DYNAMIC_CONTENT_BASE_PATH_TOKEN, DynamicContentModule, DynamicContentService, O3rDynamicContentPipe, RequestParametersModule, RequestParametersService, StorageStrategy, StyleLazyLoader, StyleLazyLoaderModule, assetPathOverrideInitialState, assetPathOverrideReducer, assetPathOverrideReducerFeatures, assetPathOverrideStorageDeserializer, assetPathOverrideStorageSync, defaultConfigFactory, defaultRequestParametersConfig, getCmsAssets, getDefaultAssetPathOverrideReducer, getDynamicContent, provideDynamicContent, provideRequestParameters, selectAssetPathOverride, selectAssetPathOverrideState, setAssetPathOverride, withBasePath, withCmsAssetsPath }; export type { AssetPathOverrideState, AssetPathOverrideStore, ParamsList, ParamsType, PartialRequestParametersConfig, RequestParametersConfig, StyleURL }; //# sourceMappingURL=index.d.ts.map