UNPKG

@atlaskit/editor-plugin-user-preferences

Version:

UserPreferences plugin for @atlaskit/editor-core

66 lines (65 loc) 1.66 kB
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics'; import { logException } from '@atlaskit/editor-common/monitoring'; import { userPreferencesPluginKey } from './main'; export const overrideUserPreference = ({ key, value }) => ({ tr }) => { tr.setMeta(userPreferencesPluginKey, { override: { key, value } }); return tr; }; export const clearOverrideUserPreference = ({ key }) => ({ tr }) => { tr.setMeta(userPreferencesPluginKey, { override: { key, value: null } }); return tr; }; export const updateUserPreference = ({ key, value, userPreferencesProvider, editorAnalyticsApi }) => ({ tr }) => { try { userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.updatePreference(key, value); } catch (error) { logException(error, { location: 'editor-plugin-user-preferences/userPreferencesPlugin' }); } // If the userPreferencesProvider is not available, // the plugin's state will be updated to operate in 'in memory' mode. tr.setMeta(userPreferencesPluginKey, { preferences: { [key]: value } }); if (key === 'toolbarDockingPosition') { editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({ action: ACTION.UPDATED, actionSubject: ACTION_SUBJECT.USER_PREFERENCES, actionSubjectId: ACTION_SUBJECT_ID.SELECTION_TOOLBAR_PREFERENCES, attributes: { toolbarDocking: value }, eventType: EVENT_TYPE.TRACK })(tr); } return tr; };