8
0

cloudservices.js 5.3 KB

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