contextplugin.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module core/contextplugin
  7. */
  8. import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
  9. import mix from '@ckeditor/ckeditor5-utils/src/mix';
  10. /**
  11. * The base class for {@link module:core/context~Context} plugin classes.
  12. *
  13. * A context plugin can either be initialized for an {@link module:core/editor/editor~Editor editor} or for
  14. * a {@link module:core/context~Context context}. In other words, it can either
  15. * work within one editor instance or with one or more editor instances that use a single context.
  16. * It is the context plugin's role to implement handling for both modes.
  17. *
  18. * There are a few rules for interaction between the editor plugins and context plugins:
  19. *
  20. * * A context plugin can require another context plugin.
  21. * * An {@link module:core/plugin~Plugin editor plugin} can require a context plugin.
  22. * * A context plugin MUST NOT require an {@link module:core/plugin~Plugin editor plugin}.
  23. *
  24. * @implements module:core/plugin~PluginInterface
  25. * @mixes module:utils/observablemixin~ObservableMixin
  26. */
  27. export default class ContextPlugin {
  28. /**
  29. * Creates a new plugin instance.
  30. *
  31. * @param {module:core/context~Context|module:core/editor/editor~Editor} context
  32. */
  33. constructor( context ) {
  34. /**
  35. * The context instance.
  36. *
  37. * @readonly
  38. * @type {module:core/context~Context|module:core/editor/editor~Editor}
  39. */
  40. this.context = context;
  41. }
  42. /**
  43. * @inheritDoc
  44. */
  45. destroy() {
  46. this.stopListening();
  47. }
  48. /**
  49. * @inheritDoc
  50. */
  51. static get isContextPlugin() {
  52. return true;
  53. }
  54. }
  55. mix( ContextPlugin, ObservableMixin );