@atlaskit/editor-plugin-connectivity
Version:
Connectivity plugin for @atlaskit/editor-core
30 lines • 1.05 kB
JavaScript
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
export const key = new PluginKey('offlineMode');
export const createPlugin = () => {
return new SafePlugin({
key,
state: {
init() {
return {
browserState: 'online',
externalState: undefined
};
},
apply: (tr, pluginState) => {
const meta = tr.getMeta(key);
if (meta) {
const {
externalState,
browserState
} = meta;
return {
browserState: browserState !== null && browserState !== void 0 ? browserState : pluginState === null || pluginState === void 0 ? void 0 : pluginState.browserState,
externalState: externalState === null ? undefined : externalState !== null && externalState !== void 0 ? externalState : pluginState === null || pluginState === void 0 ? void 0 : pluginState.externalState
};
}
return pluginState;
}
}
});
};