import { Model } from './Model';
import { ModelClient } from './ModelClient';
import { ModelStore } from './ModelStore';
import { AuthoringUtils } from './AuthoringUtils';
export interface ModelManagerConfiguration {
forceReload?: boolean;
model?: Model;
modelClient?: ModelClient;
path?: string;
errorPageRoot?: string;
}
/**
* @private
*/
export declare type ListenerFunction = () => void;
/**
* ModelManager is main entry point of this module.
*
* Example:
*
* Boostrap: `index.html`
* ```
*
*
*
* ```
*
* Bootstrap: `index.js`
* ```
* import { ModelManager } from '@adobe/aem-spa-page-model-manager';
*
* ModelManager.initialize().then((model) => {
* // Render the App content using the provided model
* render(model);
* });
*
* // Loading a specific portion of model
* ModelManager.getData("/content/site/page/jcr:content/path/to/component").then(...);
* ```
*
*
* For asynchronous loading of root model/standalone item model
* ```
* import { ModelManager } from '@adobe/aem-spa-page-model-manager';
*
* ModelManager.initializeAsync();
* ...
* // Render the App independent of the model
* render();
*
* ```
* For root model, custom event is fired on window with fetched model - cq-pagemodel-loaded
*/
export declare class ModelManager {
private _modelClient;
private _modelStore;
private _listenersMap;
private _fetchPromises;
private _initPromise;
private _editorClient;
private _clientlibUtil;
private _modelPaths;
private _errorPageRoot;
get modelClient(): ModelClient;
get modelStore(): ModelStore;
get clientlibUtil(): AuthoringUtils;
/**
* Initializes the ModelManager using the given path to resolve a data model.
* If no path is provided, fallbacks are applied in the following order:
* - meta property: `cq:pagemodel_root_url`
* - current path of the page
*
* If page model does not contain information about current path it performs additional fetch.
*
* @fires cq-pagemodel-loaded
* @return {Promise}
*/
initialize(config?: ModelManagerConfiguration | string): Promise;
/**
* Initializes the ModelManager asynchronously using the given path to resolve a data model.
* Ideal use case would be for remote apps which do not need the page model to be passed down from the root.
* For remote apps with no model path, an empty store is initialized and data is fetched on demand by components.
*
* Once the initial model is loaded and if the data model doesn't contain the path of the current pathname,
* the library attempts to fetch a fragment of model.
*
* Root model path is resolved in the following order of preference:
* - page path provided via config
* - meta property: `cq:pagemodel_root_url`
* - current path of the page for default SPA
* - if none, it defaults to empty string
*
* @fires cq-pagemodel-loaded if root model path is available
*/
initializeAsync(config?: ModelManagerConfiguration | string): void;
/**
* Attaches detected in runtime required libraries to enable special AEM authoring capabilities.
*
* @private
*/
private _attachAEMLibraries;
/**
* Initializes the class fields for ModelManager
*/
private _initializeFields;
/**
* Returns paths required for fetching root model
*/
private _getPathsForModel;
/**
* Fetch page model from store and trigger cq-pagemodel-loaded event
* @returns Root page model
*/
private _fetchPageModelFromStore;
/**
* Sets initialization promise to fetch model if root path is available
* Also, to be returned on synchronous initialization
*/
private _setInitializationPromise;
/**
* Fetch model for the currently active page
*/
private _fetchActivePageModel;
/**
* Returns the path of the data model root.
* @returns Page model root path.
*/
get rootPath(): string;
/**
* Returns the model for the given configuration.
* @param [config] Either the path of the data model or a configuration object. If no parameter is provided the complete model is returned.
* @returns Model object for specific path.
*/
getData(config?: ModelManagerConfiguration | string): Promise;
/**
* Fetches the model for the given path.
* @param path Model path.
* @private
* @returns Model object for specific path.
*/
_fetchData(path: string): Promise;
/**
* Notifies the listeners for a given path.
* @param path Path of the data model.
* @private
*/
_notifyListeners(path: string): void;
/**
* Add the given callback as a listener for changes at the given path.
* @param path Absolute path of the resource (e.g., "/content/mypage"). If not provided, the root page path is used.
* @param callback Function to be executed listening to changes at given path.
*/
addListener(path: string, callback: ListenerFunction): void;
/**
* Remove the callback listener from the given path path.
* @param path Absolute path of the resource (e.g., "/content/mypage"). If not provided, the root page path is used.
* @param callback Listener function to be removed.
*/
removeListener(path: string, callback: ListenerFunction): void;
/**
* @private
*/
private destroy;
private _storeData;
/**
* Transforms the given path into a model URL.
* @private
* @return {*}
*/
private _toModelPath;
/**
* Transforms the given config into a ModelManagerConfiguration object
* Removes redundant string or object check for path
* @return {object}
* @private
*/
private _toModelConfig;
/**
* Verifies the integrity of the provided dependencies
*
* @return {Promise}
* @private
*/
private _checkDependencies;
/**
* Fetches parent page information of the given component path
* Returns object containing
* 1. Parent page path
* 2. Parent page data if already available in the store
* @return {object}
*/
private _getParentPage;
/**
* Checks if the currently open app in aem editor is a remote app
* @returns true if remote app
*/
_isRemoteApp(): boolean;
}
declare const _default: ModelManager;
export default _default;
//# sourceMappingURL=ModelManager.d.ts.map