cloudservices.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module cloud-services/cloudservices
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import Token from '@ckeditor/ckeditor-cloud-services-core/src/token/token';
  10. /**
  11. * Plugin introducing CKEditor 5's Cloud Services integration.
  12. *
  13. * It initializes the token provider based on
  14. * the {@link module:cloud-services/cloudservices~CloudServicesConfig `config.cloudService`}.
  15. *
  16. * @extends module:core/plugin~Plugin
  17. */
  18. export default class CloudServices extends Plugin {
  19. /**
  20. * @inheritDoc
  21. */
  22. init() {
  23. const editor = this.editor;
  24. const config = editor.config;
  25. const options = config.get( 'cloudServices' ) || {};
  26. for ( const optionName in options ) {
  27. this[ optionName ] = options[ optionName ];
  28. }
  29. /**
  30. * The authentication token URL for CKEditor Cloud Services.
  31. *
  32. * @readonly
  33. * @member {String|undefined} #tokenUrl
  34. */
  35. /**
  36. * The URL to which the files should be uploaded.
  37. *
  38. * @readonly
  39. * @member {String} #uploadUrl
  40. */
  41. /**
  42. * Other plugins use this token for the authorization process. It handles token requesting and refreshing.
  43. * Its value is `null` when {@link module:cloud-services/cloudservices~CloudServicesConfig#tokenUrl} is not provided.
  44. *
  45. * @readonly
  46. * @member {Object|null} #token
  47. */
  48. if ( !this.tokenUrl ) {
  49. this.token = null;
  50. return;
  51. }
  52. this.token = new CloudServices.Token( this.tokenUrl );
  53. return this.token.init();
  54. }
  55. }
  56. CloudServices.Token = Token;
  57. /**
  58. * The configuration of CKEditor Cloud Services. Introduced by the {@link module:cloud-services/cloudservices~CloudServices} plugin.
  59. *
  60. * Read more in {@link module:cloud-services/cloudservices~CloudServicesConfig}.
  61. *
  62. * @member {module:cloud-services/cloudservices~CloudServicesConfig} module:core/editor/editorconfig~EditorConfig#cloudServices
  63. */
  64. /**
  65. * The configuration for all plugins using CKEditor Cloud Services.
  66. *
  67. * ClassicEditor
  68. * .create( document.querySelector( '#editor' ), {
  69. * cloudServices: {
  70. * tokenUrl: 'https://example.com/cs-token-endpoint',
  71. * uploadUrl: 'https://your-organization-id.cke-cs.com/easyimage/upload/'
  72. * }
  73. * } )
  74. * .then( ... )
  75. * .catch( ... );
  76. *
  77. * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
  78. *
  79. * @interface CloudServicesConfig
  80. */
  81. /**
  82. * The URL to the security token endpoint in your application. The role of this endpoint is to securely authorize the
  83. * end users of your application to use [CKEditor Cloud Services](https://ckeditor.com/ckeditor-cloud-services), only
  84. * if they should have access e.g. to upload files with Easy Image or to access the Collaboraation service.
  85. *
  86. * You can find more information about token endpoints in the
  87. * {@glink @cs guides/quick-start#create-token-endpoint Cloud Services - Quick start}
  88. * and {@glink @cs guides/token-endpoints/tokenendpoint Cloud Services - Creating token endpoint} documentation.
  89. *
  90. * Without a properly working token endpoint (token URL) CKEditor plugins will not be able to connect to CKEditor Cloud Services.
  91. *
  92. * @member {String} module:cloud-services/cloudservices~CloudServicesConfig#tokenUrl
  93. */
  94. /**
  95. * The endpoint URL for [CKEditor Cloud Services](https://ckeditor.com/ckeditor-cloud-services) uploads.
  96. * This option must be set for Easy Image to work correctly.
  97. *
  98. * The upload URL is unique for each customer and can be found in the [CKEditor Ecosystem dashboard](https://dashboard.ckeditor.com)
  99. * after subscribing to Easy Image service.
  100. * To learn how to start using Easy Image check {@glink @cs guides/easy-image/quick-start Easy Image - Quick start} documentation.
  101. *
  102. * Note: Make sure to also set the {@link module:cloud-services/cloudservices~CloudServicesConfig#tokenUrl} configuration option.
  103. *
  104. * @member {String} module:cloud-services/cloudservices~CloudServicesConfig#uploadUrl
  105. */
  106. /**
  107. * The URL for web socket communication, used by `CollaborativeEditing` plugin. Every customer (organization in the CKEditor
  108. * Ecosystem dashboard) has its own, unique URLs to communicate with CKEditor Cloud Services. The URL can be found in the
  109. * CKEditor Ecosystem dashboard.
  110. *
  111. * Note: unlike most plugins, `CollaborativeEditing` is not included in any CKEditor 5 build and has to be installed manually.
  112. * Check [Collaboration overview](https://ckeditor.com/docs/ckeditor5/latest/features/collaboration/overview.html) for more details.
  113. *
  114. * @member {String} module:cloud-services/cloudservices~CloudServicesConfig#webSocketUrl
  115. */
  116. /**
  117. * Document ID, used by `CollaborativeEditing` plugin. All editor instances created with the same document ID will collaborate.
  118. * It means that each document needs a different document ID if you do not want to start collaboration between these documents.
  119. * The ID is usually a primary key of the document in the database, but you are free to provide whatever identifier fits your scenario.
  120. *
  121. * Note: unlike most plugins, `CollaborativeEditing` is not included in any CKEditor 5 build and has to be installed manually.
  122. * Check [Collaboration overview](https://ckeditor.com/docs/ckeditor5/latest/features/collaboration/overview.html) for more details.
  123. *
  124. * @member {String} module:cloud-services/cloudservices~CloudServicesConfig#documentId
  125. */