@dotcms/uve
Version:
Official JavaScript library for interacting with Universal Visual Editor (UVE)
50 lines (49 loc) • 1.92 kB
TypeScript
import { UVEEventPayloadMap, UVEEventSubscription, UVEEventType, UVEState } from '@dotcms/types';
/**
* Gets the current state of the Universal Visual Editor (UVE).
*
* This function checks if the code is running inside the DotCMS Universal Visual Editor
* and returns information about its current state, including the editor mode.
*
* @export
* @return {UVEState | undefined} Returns the UVE state object if running inside the editor,
* undefined otherwise.
*
* The state includes:
* - mode: The current editor mode (preview, edit, live)
* - languageId: The language ID of the current page setted on the UVE
* - persona: The persona of the current page setted on the UVE
* - variantName: The name of the current variant
* - experimentId: The ID of the current experiment
* - publishDate: The publish date of the current page setted on the UVE
*
* @note The absence of any of these properties means that the value is the default one.
*
* @example
* ```ts
* const editorState = getUVEState();
* if (editorState?.mode === 'edit') {
* // Enable editing features
* }
* ```
*/
export declare function getUVEState(): UVEState | undefined;
/**
* Creates a subscription to a UVE event.
*
* @param eventType - The type of event to subscribe to
* @param callback - The callback function that will be called when the event occurs
* @returns An event subscription that can be used to unsubscribe
*
* @example
* ```ts
* // Subscribe to page changes
* const subscription = createUVESubscription(UVEEventType.CONTENT_CHANGES, (changes) => {
* console.log('Content changes:', changes);
* });
*
* // Later, unsubscribe when no longer needed
* subscription.unsubscribe();
* ```
*/
export declare function createUVESubscription<T extends UVEEventType>(eventType: T, callback: (payload: UVEEventPayloadMap[T] extends undefined ? void : UVEEventPayloadMap[T]) => void): UVEEventSubscription;