lib/editor/tiny/plugins/h5p/amd/src/plugin.js

  1. // This file is part of Moodle - http://moodle.org/
  2. //
  3. // Moodle is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // Moodle is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * Tiny H5P plugin for Moodle.
  17. *
  18. * @module tiny_h5p/plugin
  19. * @copyright 2022 Andrew Lyons <andrew@nicols.co.uk>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. import {getTinyMCE} from 'editor_tiny/loader';
  23. import {getPluginMetadata} from 'editor_tiny/utils';
  24. import {component, pluginName} from './common';
  25. import * as FilterContent from './filtercontent';
  26. import * as Commands from './commands';
  27. import * as Configuration from './configuration';
  28. import * as Options from './options';
  29. // Setup the H5P Plugin to add a button and menu option.
  30. // eslint-disable-next-line no-async-promise-executor
  31. export default new Promise(async(resolve) => {
  32. const [
  33. tinyMCE,
  34. setupCommands,
  35. pluginMetadata,
  36. ] = await Promise.all([
  37. getTinyMCE(),
  38. Commands.getSetup(),
  39. getPluginMetadata(component, pluginName),
  40. ]);
  41. // Note: The PluginManager.add function does not accept a Promise.
  42. // Any asynchronous code must be run before this point.
  43. tinyMCE.PluginManager.add(`${component}/plugin`, (editor) => {
  44. // Register options.
  45. Options.register(editor);
  46. // Setup the Formatter.
  47. FilterContent.setup(editor);
  48. // Setup the Commands (buttons, menu items, and so on).
  49. setupCommands(editor);
  50. return pluginMetadata;
  51. });
  52. // Resolve the H5P Plugin and include configuration.
  53. resolve([`${component}/plugin`, Configuration]);
  54. });