import type { PersistenceAPI } from './persistence-api'; import type { ResolvedUserPreferences, UserPreferences } from './user-preferences'; type UpdateCallback = (userPreferences: UserPreferences) => void; /** * This class is used to manage user preferences in the editor. * It provides methods to load, update, and get user preferences, * as well as a way to subscribe to updates. * @example const userPreferencesProvider = new UserPreferencesProvider(persistenceAPI, defaultPreferences); */ export declare class UserPreferencesProvider { private updateCallbacks; private userPreferences; private defaultPreferences; private resolvedUserPreferences; private initialized; private persistenceAPI; /** * This is the constructor for the UserPreferencesProvider class. * @param persistenceAPI - The persistence API to use for loading and updating user preferences * @param defaultPreferences - The default user preferences to use * @param initialUserPreferences - The initial user preferences to use (optional) * @example const userPreferencesProvider = new UserPreferencesProvider(persistenceAPI, defaultPreferences); */ constructor(persistenceAPI: PersistenceAPI, defaultPreferences: ResolvedUserPreferences); /** * This method returns the initialized state of the user preferences provider * @returns true if the user preferences provider is initialized, false otherwise * @example userPreferencesProvider.isInitialized */ get isInitialized(): boolean; /** * This method fetches the latest user preferences * @returns a promise that resolves with the user preferences, or rejects if error occurs * @throws Error if there is an error loading user preferences * @example userPreferencesProvider.loadPreferences() */ loadPreferences(): Promise; /** * This method updates a user preference * @param key * @param value * @returns a promise that resolves when the user preference is updated * @throws Error if there is an error updating user preferences * @example userPreferencesProvider.updatePreference('toolbarDockingPosition', 'top') */ updatePreference(key: K, value: UserPreferences[K]): Promise; /** * get a user preference, Note that this function is a not async function, * meaning that consumers should prefetch the user preference and make it available initially * @param key * @returns the user preference * @example userPreferencesProvider.getPreference('toolbarDockingPosition') */ getPreference(key: K): ResolvedUserPreferences[K]; /** * get all user preferences * @returns the user preferences * @example userPreferencesProvider.getPreferences() */ getPreferences(): ResolvedUserPreferences; /** * This method fetches the latest user preferences * @param onUpdate * @returns a function to unsubscribe from the updates * @example */ onUpdate(onUpdate: UpdateCallback): () => void; /** * This method is used to set the default user preferences, * setting the default user preferences will also trigger an update * This is useful when the default user preferences dynamically based on the context * @param preferences * @example */ setDefaultPreferences(preferences: ResolvedUserPreferences): void; private setUserPreferences; /** * This method is used to notify the user preferences updated * @example userPreferencesProvider.notifyUserPreferencesUpdated() */ notifyUserPreferencesUpdated(): void; /** * This method resolves the user preferences by merging the default preferences * with the user preferences and filtering out any undefined or null values * to avoid overwriting default preferences with null values * @returns true if the user preferences were updated, false otherwise * @example userPreferencesProvider.resolveUserPreferences() */ private resolveUserPreferences; } export {};