@ckeditor/ckeditor5-ckbox 47.6.1-alpha.1 → 48.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +4 -4
  3. package/{src → dist}/ckbox.d.ts +1 -1
  4. package/{src → dist}/ckboxcommand.d.ts +1 -1
  5. package/{src → dist}/ckboxconfig.d.ts +1 -1
  6. package/{src → dist}/ckboxediting.d.ts +4 -2
  7. package/{src → dist}/ckboximageedit/ckboximageeditcommand.d.ts +1 -1
  8. package/{src → dist}/ckboximageedit/ckboximageeditediting.d.ts +4 -3
  9. package/{src → dist}/ckboximageedit/ckboximageeditui.d.ts +1 -1
  10. package/{src → dist}/ckboximageedit/utils.d.ts +1 -1
  11. package/{src → dist}/ckboximageedit.d.ts +1 -1
  12. package/{src → dist}/ckboxui.d.ts +1 -1
  13. package/{src → dist}/ckboxuploadadapter.d.ts +4 -3
  14. package/{src → dist}/ckboxutils.d.ts +3 -3
  15. package/dist/index-editor.css +24 -28
  16. package/dist/index.css +25 -36
  17. package/dist/index.css.map +1 -1
  18. package/dist/index.js +14 -10
  19. package/dist/index.js.map +1 -1
  20. package/package.json +28 -51
  21. package/build/ckbox.js +0 -5
  22. package/build/translations/af.js +0 -1
  23. package/build/translations/ar.js +0 -1
  24. package/build/translations/ast.js +0 -1
  25. package/build/translations/az.js +0 -1
  26. package/build/translations/be.js +0 -1
  27. package/build/translations/bg.js +0 -1
  28. package/build/translations/bn.js +0 -1
  29. package/build/translations/bs.js +0 -1
  30. package/build/translations/ca.js +0 -1
  31. package/build/translations/cs.js +0 -1
  32. package/build/translations/da.js +0 -1
  33. package/build/translations/de-ch.js +0 -1
  34. package/build/translations/de.js +0 -1
  35. package/build/translations/el.js +0 -1
  36. package/build/translations/en-au.js +0 -1
  37. package/build/translations/en-gb.js +0 -1
  38. package/build/translations/eo.js +0 -1
  39. package/build/translations/es-co.js +0 -1
  40. package/build/translations/es.js +0 -1
  41. package/build/translations/et.js +0 -1
  42. package/build/translations/eu.js +0 -1
  43. package/build/translations/fa.js +0 -1
  44. package/build/translations/fi.js +0 -1
  45. package/build/translations/fr.js +0 -1
  46. package/build/translations/gl.js +0 -1
  47. package/build/translations/gu.js +0 -1
  48. package/build/translations/he.js +0 -1
  49. package/build/translations/hi.js +0 -1
  50. package/build/translations/hr.js +0 -1
  51. package/build/translations/hu.js +0 -1
  52. package/build/translations/hy.js +0 -1
  53. package/build/translations/id.js +0 -1
  54. package/build/translations/it.js +0 -1
  55. package/build/translations/ja.js +0 -1
  56. package/build/translations/jv.js +0 -1
  57. package/build/translations/kk.js +0 -1
  58. package/build/translations/km.js +0 -1
  59. package/build/translations/kn.js +0 -1
  60. package/build/translations/ko.js +0 -1
  61. package/build/translations/ku.js +0 -1
  62. package/build/translations/lt.js +0 -1
  63. package/build/translations/lv.js +0 -1
  64. package/build/translations/ms.js +0 -1
  65. package/build/translations/nb.js +0 -1
  66. package/build/translations/ne.js +0 -1
  67. package/build/translations/nl.js +0 -1
  68. package/build/translations/no.js +0 -1
  69. package/build/translations/oc.js +0 -1
  70. package/build/translations/pl.js +0 -1
  71. package/build/translations/pt-br.js +0 -1
  72. package/build/translations/pt.js +0 -1
  73. package/build/translations/ro.js +0 -1
  74. package/build/translations/ru.js +0 -1
  75. package/build/translations/si.js +0 -1
  76. package/build/translations/sk.js +0 -1
  77. package/build/translations/sl.js +0 -1
  78. package/build/translations/sq.js +0 -1
  79. package/build/translations/sr-latn.js +0 -1
  80. package/build/translations/sr.js +0 -1
  81. package/build/translations/sv.js +0 -1
  82. package/build/translations/th.js +0 -1
  83. package/build/translations/ti.js +0 -1
  84. package/build/translations/tk.js +0 -1
  85. package/build/translations/tr.js +0 -1
  86. package/build/translations/tt.js +0 -1
  87. package/build/translations/ug.js +0 -1
  88. package/build/translations/uk.js +0 -1
  89. package/build/translations/ur.js +0 -1
  90. package/build/translations/uz.js +0 -1
  91. package/build/translations/vi.js +0 -1
  92. package/build/translations/zh-cn.js +0 -1
  93. package/build/translations/zh.js +0 -1
  94. package/lang/contexts.json +0 -10
  95. package/lang/translations/af.po +0 -44
  96. package/lang/translations/ar.po +0 -44
  97. package/lang/translations/ast.po +0 -44
  98. package/lang/translations/az.po +0 -44
  99. package/lang/translations/be.po +0 -44
  100. package/lang/translations/bg.po +0 -44
  101. package/lang/translations/bn.po +0 -44
  102. package/lang/translations/bs.po +0 -44
  103. package/lang/translations/ca.po +0 -44
  104. package/lang/translations/cs.po +0 -44
  105. package/lang/translations/da.po +0 -44
  106. package/lang/translations/de-ch.po +0 -44
  107. package/lang/translations/de.po +0 -44
  108. package/lang/translations/el.po +0 -44
  109. package/lang/translations/en-au.po +0 -44
  110. package/lang/translations/en-gb.po +0 -44
  111. package/lang/translations/en.po +0 -44
  112. package/lang/translations/eo.po +0 -44
  113. package/lang/translations/es-co.po +0 -44
  114. package/lang/translations/es.po +0 -44
  115. package/lang/translations/et.po +0 -44
  116. package/lang/translations/eu.po +0 -44
  117. package/lang/translations/fa.po +0 -44
  118. package/lang/translations/fi.po +0 -44
  119. package/lang/translations/fr.po +0 -44
  120. package/lang/translations/gl.po +0 -44
  121. package/lang/translations/gu.po +0 -44
  122. package/lang/translations/he.po +0 -44
  123. package/lang/translations/hi.po +0 -44
  124. package/lang/translations/hr.po +0 -44
  125. package/lang/translations/hu.po +0 -44
  126. package/lang/translations/hy.po +0 -44
  127. package/lang/translations/id.po +0 -44
  128. package/lang/translations/it.po +0 -44
  129. package/lang/translations/ja.po +0 -44
  130. package/lang/translations/jv.po +0 -44
  131. package/lang/translations/kk.po +0 -44
  132. package/lang/translations/km.po +0 -44
  133. package/lang/translations/kn.po +0 -44
  134. package/lang/translations/ko.po +0 -44
  135. package/lang/translations/ku.po +0 -44
  136. package/lang/translations/lt.po +0 -44
  137. package/lang/translations/lv.po +0 -44
  138. package/lang/translations/ms.po +0 -44
  139. package/lang/translations/nb.po +0 -44
  140. package/lang/translations/ne.po +0 -44
  141. package/lang/translations/nl.po +0 -44
  142. package/lang/translations/no.po +0 -44
  143. package/lang/translations/oc.po +0 -44
  144. package/lang/translations/pl.po +0 -44
  145. package/lang/translations/pt-br.po +0 -44
  146. package/lang/translations/pt.po +0 -44
  147. package/lang/translations/ro.po +0 -44
  148. package/lang/translations/ru.po +0 -44
  149. package/lang/translations/si.po +0 -44
  150. package/lang/translations/sk.po +0 -44
  151. package/lang/translations/sl.po +0 -44
  152. package/lang/translations/sq.po +0 -44
  153. package/lang/translations/sr-latn.po +0 -44
  154. package/lang/translations/sr.po +0 -44
  155. package/lang/translations/sv.po +0 -44
  156. package/lang/translations/th.po +0 -44
  157. package/lang/translations/ti.po +0 -44
  158. package/lang/translations/tk.po +0 -44
  159. package/lang/translations/tr.po +0 -44
  160. package/lang/translations/tt.po +0 -44
  161. package/lang/translations/ug.po +0 -44
  162. package/lang/translations/uk.po +0 -44
  163. package/lang/translations/ur.po +0 -44
  164. package/lang/translations/uz.po +0 -44
  165. package/lang/translations/vi.po +0 -44
  166. package/lang/translations/zh-cn.po +0 -44
  167. package/lang/translations/zh.po +0 -44
  168. package/src/augmentation.js +0 -5
  169. package/src/ckbox.js +0 -43
  170. package/src/ckboxcommand.js +0 -382
  171. package/src/ckboxconfig.js +0 -5
  172. package/src/ckboxediting.js +0 -388
  173. package/src/ckboximageedit/ckboximageeditcommand.js +0 -318
  174. package/src/ckboximageedit/ckboximageeditediting.js +0 -42
  175. package/src/ckboximageedit/ckboximageeditui.js +0 -57
  176. package/src/ckboximageedit/utils.js +0 -48
  177. package/src/ckboximageedit.js +0 -34
  178. package/src/ckboxui.js +0 -139
  179. package/src/ckboxuploadadapter.js +0 -159
  180. package/src/ckboxutils.js +0 -215
  181. package/src/index.js +0 -21
  182. package/src/utils.js +0 -188
  183. package/theme/ckboximageedit.css +0 -53
  184. /package/{src → dist}/augmentation.d.ts +0 -0
  185. /package/{src → dist}/index.d.ts +0 -0
  186. /package/{src → dist}/utils.d.ts +0 -0
@@ -1,159 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module ckbox/ckboxuploadadapter
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { FileRepository } from 'ckeditor5/src/upload.js';
10
- import { CKBoxEditing } from './ckboxediting.js';
11
- import { getImageUrls, sendHttpRequest } from './utils.js';
12
- import { CKBoxUtils } from './ckboxutils.js';
13
- /**
14
- * A plugin that enables file uploads in CKEditor 5 using the CKBox server–side connector.
15
- * See the {@glink features/file-management/ckbox CKBox file manager integration} guide to learn how to configure
16
- * and use this feature as well as find out more about the full integration with the file manager
17
- * provided by the {@link module:ckbox/ckbox~CKBox} plugin.
18
- *
19
- * Check out the {@glink features/images/image-upload/image-upload Image upload overview} guide to learn about
20
- * other ways to upload images into CKEditor 5.
21
- */
22
- export class CKBoxUploadAdapter extends Plugin {
23
- /**
24
- * @inheritDoc
25
- */
26
- static get requires() {
27
- return ['ImageUploadEditing', 'ImageUploadProgress', FileRepository, CKBoxEditing];
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get pluginName() {
33
- return 'CKBoxUploadAdapter';
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- static get isOfficialPlugin() {
39
- return true;
40
- }
41
- /**
42
- * @inheritDoc
43
- */
44
- async afterInit() {
45
- const editor = this.editor;
46
- const hasConfiguration = !!editor.config.get('ckbox');
47
- const isLibraryLoaded = !!window.CKBox;
48
- // Editor supports only one upload adapter. Register the CKBox upload adapter (and potentially overwrite other one) only when the
49
- // integrator intentionally wants to use the CKBox plugin, i.e. when the `config.ckbox` exists or the CKBox JavaScript library is
50
- // loaded.
51
- if (!hasConfiguration && !isLibraryLoaded) {
52
- return;
53
- }
54
- const fileRepository = editor.plugins.get(FileRepository);
55
- const ckboxUtils = editor.plugins.get(CKBoxUtils);
56
- fileRepository.createUploadAdapter = loader => new Adapter(loader, editor, ckboxUtils);
57
- const shouldInsertDataId = !editor.config.get('ckbox.ignoreDataId');
58
- const imageUploadEditing = editor.plugins.get('ImageUploadEditing');
59
- // Mark uploaded assets with the `ckboxImageId` attribute. Its value represents an ID in CKBox.
60
- if (shouldInsertDataId) {
61
- imageUploadEditing.on('uploadComplete', (evt, { imageElement, data }) => {
62
- editor.model.change(writer => {
63
- writer.setAttribute('ckboxImageId', data.ckboxImageId, imageElement);
64
- });
65
- });
66
- }
67
- }
68
- }
69
- /**
70
- * Upload adapter for CKBox.
71
- */
72
- class Adapter {
73
- /**
74
- * FileLoader instance to use during the upload.
75
- */
76
- loader;
77
- /**
78
- * CKEditor Cloud Services access token.
79
- */
80
- token;
81
- /**
82
- * The editor instance.
83
- */
84
- editor;
85
- /**
86
- * The abort controller for aborting asynchronous processes.
87
- */
88
- controller;
89
- /**
90
- * The base URL where all requests should be sent.
91
- */
92
- serviceOrigin;
93
- /**
94
- * The reference to CKBoxUtils plugin.
95
- */
96
- ckboxUtils;
97
- /**
98
- * Creates a new adapter instance.
99
- */
100
- constructor(loader, editor, ckboxUtils) {
101
- this.loader = loader;
102
- this.token = ckboxUtils.getToken();
103
- this.ckboxUtils = ckboxUtils;
104
- this.editor = editor;
105
- this.controller = new AbortController();
106
- this.serviceOrigin = editor.config.get('ckbox.serviceOrigin');
107
- }
108
- /**
109
- * Starts the upload process.
110
- *
111
- * @see module:upload/filerepository~UploadAdapter#upload
112
- */
113
- async upload() {
114
- const ckboxUtils = this.ckboxUtils;
115
- const t = this.editor.t;
116
- const file = (await this.loader.file);
117
- const category = await ckboxUtils.getCategoryIdForFile(file, { signal: this.controller.signal });
118
- const uploadUrl = new URL('assets', this.serviceOrigin);
119
- const formData = new FormData();
120
- uploadUrl.searchParams.set('workspaceId', await ckboxUtils.getWorkspaceId());
121
- formData.append('categoryId', category);
122
- formData.append('file', file);
123
- const requestConfig = {
124
- method: 'POST',
125
- url: uploadUrl,
126
- data: formData,
127
- onUploadProgress: (evt) => {
128
- /* istanbul ignore else -- @preserve */
129
- if (evt.lengthComputable) {
130
- this.loader.uploadTotal = evt.total;
131
- this.loader.uploaded = evt.loaded;
132
- }
133
- },
134
- signal: this.controller.signal,
135
- authorization: (await this.token).value
136
- };
137
- return sendHttpRequest(requestConfig)
138
- .then(async (data) => {
139
- const imageUrls = getImageUrls(data.imageUrls);
140
- return {
141
- ckboxImageId: data.id,
142
- default: imageUrls.imageFallbackUrl,
143
- sources: imageUrls.imageSources
144
- };
145
- })
146
- .catch(() => {
147
- const genericError = t('Cannot upload file:') + ` ${file.name}.`;
148
- return Promise.reject(genericError);
149
- });
150
- }
151
- /**
152
- * Aborts the upload process.
153
- *
154
- * @see module:upload/filerepository~UploadAdapter#abort
155
- */
156
- abort() {
157
- this.controller.abort();
158
- }
159
- }
package/src/ckboxutils.js DELETED
@@ -1,215 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { CKEditorError, logError } from 'ckeditor5/src/utils.js';
6
- import { Plugin } from 'ckeditor5/src/core.js';
7
- import { convertMimeTypeToExtension, getContentTypeOfUrl, getFileExtension, getWorkspaceId, sendHttpRequest } from './utils.js';
8
- const DEFAULT_CKBOX_THEME_NAME = 'lark';
9
- /**
10
- * The CKBox utilities plugin.
11
- */
12
- export class CKBoxUtils extends Plugin {
13
- /**
14
- * CKEditor Cloud Services access token.
15
- */
16
- _token;
17
- /**
18
- * @inheritDoc
19
- */
20
- static get pluginName() {
21
- return 'CKBoxUtils';
22
- }
23
- /**
24
- * @inheritDoc
25
- */
26
- static get isOfficialPlugin() {
27
- return true;
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get requires() {
33
- return ['CloudServices'];
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- const editor = this.editor;
40
- const hasConfiguration = !!editor.config.get('ckbox');
41
- const isLibraryLoaded = !!window.CKBox;
42
- // Proceed with plugin initialization only when the integrator intentionally wants to use it, i.e. when the `config.ckbox` exists or
43
- // the CKBox JavaScript library is loaded.
44
- if (!hasConfiguration && !isLibraryLoaded) {
45
- return;
46
- }
47
- editor.config.define('ckbox', {
48
- serviceOrigin: 'https://api.ckbox.io',
49
- defaultUploadCategories: null,
50
- ignoreDataId: false,
51
- language: editor.locale.uiLanguage,
52
- theme: DEFAULT_CKBOX_THEME_NAME,
53
- tokenUrl: editor.config.get('cloudServices.tokenUrl')
54
- });
55
- const cloudServices = editor.plugins.get('CloudServices');
56
- const cloudServicesTokenUrl = editor.config.get('cloudServices.tokenUrl');
57
- const ckboxTokenUrl = editor.config.get('ckbox.tokenUrl');
58
- if (!ckboxTokenUrl) {
59
- /**
60
- * The {@link module:ckbox/ckboxconfig~CKBoxConfig#tokenUrl `config.ckbox.tokenUrl`} or the
61
- * {@link module:cloud-services/cloudservicesconfig~CloudServicesConfig#tokenUrl `config.cloudServices.tokenUrl`}
62
- * configuration is required for the CKBox plugin.
63
- *
64
- * ```ts
65
- * ClassicEditor.create( document.createElement( 'div' ), {
66
- * ckbox: {
67
- * tokenUrl: "YOUR_TOKEN_URL"
68
- * // ...
69
- * }
70
- * // ...
71
- * } );
72
- * ```
73
- *
74
- * @error ckbox-plugin-missing-token-url
75
- */
76
- throw new CKEditorError('ckbox-plugin-missing-token-url', this);
77
- }
78
- if (ckboxTokenUrl == cloudServicesTokenUrl) {
79
- this._token = Promise.resolve(cloudServices.token);
80
- }
81
- else {
82
- this._token = cloudServices.registerTokenUrl(ckboxTokenUrl);
83
- }
84
- // Grant access to private categories after token is fetched. This is done within the same promise chain
85
- // to ensure all services using the token have access to private categories.
86
- // This step is critical as previewing images from private categories requires proper cookies.
87
- this._token = this._token.then(async (token) => {
88
- await this._authorizePrivateCategoriesAccess(token.value);
89
- return token;
90
- });
91
- }
92
- /**
93
- * Returns a token used by the CKBox plugin for communication with the CKBox service.
94
- */
95
- getToken() {
96
- return this._token;
97
- }
98
- /**
99
- * The ID of workspace to use when uploading an image.
100
- */
101
- async getWorkspaceId() {
102
- const t = this.editor.t;
103
- const cannotAccessDefaultWorkspaceError = t('Cannot access default workspace.');
104
- const defaultWorkspaceId = this.editor.config.get('ckbox.defaultUploadWorkspaceId');
105
- const workspaceId = getWorkspaceId(await this._token, defaultWorkspaceId);
106
- if (workspaceId == null) {
107
- /**
108
- * The user is not authorized to access the workspace defined in the`ckbox.defaultUploadWorkspaceId` configuration.
109
- *
110
- * @error ckbox-access-default-workspace-error
111
- */
112
- logError('ckbox-access-default-workspace-error');
113
- throw cannotAccessDefaultWorkspaceError;
114
- }
115
- return workspaceId;
116
- }
117
- /**
118
- * Resolves a promise with an object containing a category with which the uploaded file is associated or an error code.
119
- */
120
- async getCategoryIdForFile(fileOrUrl, options) {
121
- const t = this.editor.t;
122
- const cannotFindCategoryError = t('Cannot determine a category for the uploaded file.');
123
- const defaultCategories = this.editor.config.get('ckbox.defaultUploadCategories');
124
- const allCategoriesPromise = this._getAvailableCategories(options);
125
- const extension = typeof fileOrUrl == 'string' ?
126
- convertMimeTypeToExtension(await getContentTypeOfUrl(fileOrUrl, options)) :
127
- getFileExtension(fileOrUrl);
128
- const allCategories = await allCategoriesPromise;
129
- // Couldn't fetch all categories. Perhaps the authorization token is invalid.
130
- if (!allCategories) {
131
- throw cannotFindCategoryError;
132
- }
133
- // If a user specifies the plugin configuration, find the first category that accepts the uploaded file.
134
- if (defaultCategories) {
135
- const userCategory = Object.keys(defaultCategories).find(category => {
136
- return defaultCategories[category].find(e => e.toLowerCase() == extension);
137
- });
138
- // If found, return its ID if the category exists on the server side.
139
- if (userCategory) {
140
- const serverCategory = allCategories.find(category => category.id === userCategory || category.name === userCategory);
141
- if (!serverCategory) {
142
- throw cannotFindCategoryError;
143
- }
144
- return serverCategory.id;
145
- }
146
- }
147
- // Otherwise, find the first category that accepts the uploaded file and returns its ID.
148
- const category = allCategories.find(category => category.extensions.find(e => e.toLowerCase() == extension));
149
- if (!category) {
150
- throw cannotFindCategoryError;
151
- }
152
- return category.id;
153
- }
154
- /**
155
- * Resolves a promise with an array containing available categories with which the uploaded file can be associated.
156
- *
157
- * If the API returns limited results, the method will collect all items.
158
- */
159
- async _getAvailableCategories(options) {
160
- const ITEMS_PER_REQUEST = 50;
161
- const editor = this.editor;
162
- const token = this._token;
163
- const { signal } = options;
164
- const serviceOrigin = editor.config.get('ckbox.serviceOrigin');
165
- const workspaceId = await this.getWorkspaceId();
166
- try {
167
- const result = [];
168
- let offset = 0;
169
- let remainingItems;
170
- do {
171
- const data = await fetchCategories(offset);
172
- result.push(...data.items);
173
- remainingItems = data.totalCount - (offset + ITEMS_PER_REQUEST);
174
- offset += ITEMS_PER_REQUEST;
175
- } while (remainingItems > 0);
176
- return result;
177
- }
178
- catch {
179
- signal.throwIfAborted();
180
- /**
181
- * Fetching a list of available categories with which an uploaded file can be associated failed.
182
- *
183
- * @error ckbox-fetch-category-http-error
184
- */
185
- logError('ckbox-fetch-category-http-error');
186
- return undefined;
187
- }
188
- async function fetchCategories(offset) {
189
- const categoryUrl = new URL('categories', serviceOrigin);
190
- categoryUrl.searchParams.set('limit', String(ITEMS_PER_REQUEST));
191
- categoryUrl.searchParams.set('offset', String(offset));
192
- categoryUrl.searchParams.set('workspaceId', workspaceId);
193
- return sendHttpRequest({
194
- url: categoryUrl,
195
- signal,
196
- authorization: (await token).value
197
- });
198
- }
199
- }
200
- /**
201
- * Authorize private categories access to the CKBox service. Request sets cookie for the current domain,
202
- * that allows user to preview images from private categories.
203
- */
204
- async _authorizePrivateCategoriesAccess(token) {
205
- const serviceUrl = this.editor.config.get('ckbox.serviceOrigin');
206
- const formData = new FormData();
207
- formData.set('token', token);
208
- await fetch(`${serviceUrl}/categories/authorizePrivateAccess`, {
209
- method: 'POST',
210
- credentials: 'include',
211
- mode: 'no-cors',
212
- body: formData
213
- });
214
- }
215
- }
package/src/index.js DELETED
@@ -1,21 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module ckbox
7
- */
8
- export { CKBox } from './ckbox.js';
9
- export { CKBoxEditing } from './ckboxediting.js';
10
- export { CKBoxUI } from './ckboxui.js';
11
- export { CKBoxImageEditEditing } from './ckboximageedit/ckboximageeditediting.js';
12
- export { CKBoxImageEditUI } from './ckboximageedit/ckboximageeditui.js';
13
- export { CKBoxImageEdit } from './ckboximageedit.js';
14
- export { CKBoxCommand } from './ckboxcommand.js';
15
- export { CKBoxImageEditCommand } from './ckboximageedit/ckboximageeditcommand.js';
16
- export { CKBoxUploadAdapter } from './ckboxuploadadapter.js';
17
- export { CKBoxUtils } from './ckboxutils.js';
18
- export { getImageUrls as _getCKBoxImageUrls, getWorkspaceId as _getCKBoxWorkspaceId, blurHashToDataUrl as _ckboxBlurHashToDataUrl, sendHttpRequest as _sendCKBoxHttpRequest, convertMimeTypeToExtension as _ckBoxConvertMimeTypeToExtension, getContentTypeOfUrl as _getCKBoxContentTypeOfUrl, getFileExtension as _getCKBoxFileExtension } from './utils.js';
19
- export { createEditabilityChecker as _createCKBoxEditabilityChecker } from './ckboximageedit/utils.js';
20
- export { prepareImageAssetAttributes as _prepareCKBoxImageAssetAttributes } from './ckboxcommand.js';
21
- import './augmentation.js';
package/src/utils.js DELETED
@@ -1,188 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { decode } from 'blurhash';
6
- /**
7
- * Converts image source set provided by the CKBox into an object containing:
8
- * - responsive URLs for the "webp" image format,
9
- * - one fallback URL for browsers that do not support the "webp" format.
10
- *
11
- * @internal
12
- */
13
- export function getImageUrls(imageUrls) {
14
- const responsiveUrls = [];
15
- let maxWidth = 0;
16
- for (const key in imageUrls) {
17
- const width = parseInt(key, 10);
18
- if (!isNaN(width)) {
19
- if (width > maxWidth) {
20
- maxWidth = width;
21
- }
22
- responsiveUrls.push(`${imageUrls[key]} ${key}w`);
23
- }
24
- }
25
- const imageSources = [{
26
- srcset: responsiveUrls.join(','),
27
- sizes: `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`,
28
- type: 'image/webp'
29
- }];
30
- return {
31
- imageFallbackUrl: imageUrls.default,
32
- imageSources
33
- };
34
- }
35
- /**
36
- * Returns a workspace id to use for communication with the CKBox service.
37
- *
38
- * @param defaultWorkspaceId The default workspace to use taken from editor config.
39
- * @internal
40
- */
41
- export function getWorkspaceId(token, defaultWorkspaceId) {
42
- const [, binaryTokenPayload] = token.value.split('.');
43
- const payload = JSON.parse(atob(binaryTokenPayload));
44
- const workspaces = payload.auth?.ckbox?.workspaces || [payload.aud];
45
- if (!defaultWorkspaceId) {
46
- return workspaces[0];
47
- }
48
- if (payload.auth?.ckbox?.role == 'superadmin' || workspaces.includes(defaultWorkspaceId)) {
49
- return defaultWorkspaceId;
50
- }
51
- return null;
52
- }
53
- /**
54
- * Default resolution for decoding blurhash values.
55
- * Relatively small values must be used in order to ensure acceptable performance.
56
- */
57
- const BLUR_RESOLUTION = 32;
58
- /**
59
- * Generates an image data URL from its `blurhash` representation.
60
- *
61
- * @internal
62
- */
63
- export function blurHashToDataUrl(hash) {
64
- if (!hash) {
65
- return;
66
- }
67
- try {
68
- const resolutionInPx = `${BLUR_RESOLUTION}px`;
69
- const canvas = document.createElement('canvas');
70
- canvas.setAttribute('width', resolutionInPx);
71
- canvas.setAttribute('height', resolutionInPx);
72
- const ctx = canvas.getContext('2d');
73
- /* istanbul ignore next -- @preserve */
74
- if (!ctx) {
75
- return;
76
- }
77
- const imageData = ctx.createImageData(BLUR_RESOLUTION, BLUR_RESOLUTION);
78
- const decoded = decode(hash, BLUR_RESOLUTION, BLUR_RESOLUTION);
79
- imageData.data.set(decoded);
80
- ctx.putImageData(imageData, 0, 0);
81
- return canvas.toDataURL();
82
- }
83
- catch {
84
- return undefined;
85
- }
86
- }
87
- /**
88
- * Sends the HTTP request.
89
- *
90
- * @internal
91
- * @param options Configuration options
92
- * @param options.url The URL where the request will be sent.
93
- * @param options.signal The AbortSignal to abort the request when needed.
94
- * @param options.authorization The authorization token for the request.
95
- * @param options.method The HTTP method (default: 'GET').
96
- * @param options.data Additional data to send.
97
- * @param options.onUploadProgress A callback informing about the upload progress.
98
- */
99
- export function sendHttpRequest({ url, method = 'GET', data, onUploadProgress, signal, authorization }) {
100
- const xhr = new XMLHttpRequest();
101
- xhr.open(method, url.toString());
102
- xhr.setRequestHeader('Authorization', authorization);
103
- xhr.setRequestHeader('CKBox-Version', 'CKEditor 5');
104
- xhr.responseType = 'json';
105
- // The callback is attached to the `signal#abort` event.
106
- const abortCallback = () => {
107
- xhr.abort();
108
- };
109
- return new Promise((resolve, reject) => {
110
- signal.throwIfAborted();
111
- signal.addEventListener('abort', abortCallback);
112
- xhr.addEventListener('loadstart', () => {
113
- signal.addEventListener('abort', abortCallback);
114
- });
115
- xhr.addEventListener('loadend', () => {
116
- signal.removeEventListener('abort', abortCallback);
117
- });
118
- xhr.addEventListener('error', () => {
119
- reject();
120
- });
121
- xhr.addEventListener('abort', () => {
122
- reject();
123
- });
124
- xhr.addEventListener('load', () => {
125
- const response = xhr.response;
126
- if (!response || response.statusCode >= 400) {
127
- return reject(response && response.message);
128
- }
129
- resolve(response);
130
- });
131
- /* istanbul ignore else -- @preserve */
132
- if (onUploadProgress) {
133
- xhr.upload.addEventListener('progress', evt => {
134
- onUploadProgress(evt);
135
- });
136
- }
137
- // Send the request.
138
- xhr.send(data);
139
- });
140
- }
141
- const MIME_TO_EXTENSION = {
142
- 'image/gif': 'gif',
143
- 'image/jpeg': 'jpg',
144
- 'image/png': 'png',
145
- 'image/webp': 'webp',
146
- 'image/bmp': 'bmp',
147
- 'image/tiff': 'tiff'
148
- };
149
- /**
150
- * Returns an extension a typical file in the specified `mimeType` format would have.
151
- *
152
- * @internal
153
- */
154
- export function convertMimeTypeToExtension(mimeType) {
155
- return MIME_TO_EXTENSION[mimeType];
156
- }
157
- /**
158
- * Tries to fetch the given `url` and returns 'content-type' of the response.
159
- *
160
- * @internal
161
- */
162
- export async function getContentTypeOfUrl(url, options) {
163
- try {
164
- const response = await fetch(url, {
165
- method: 'HEAD',
166
- cache: 'force-cache',
167
- ...options
168
- });
169
- if (!response.ok) {
170
- return '';
171
- }
172
- return response.headers.get('content-type') || '';
173
- }
174
- catch {
175
- return '';
176
- }
177
- }
178
- /**
179
- * Returns an extension from the given value.
180
- *
181
- * @internal
182
- */
183
- export function getFileExtension(file) {
184
- const fileName = file.name;
185
- const extensionRegExp = /\.(?<ext>[^.]+)$/;
186
- const match = fileName.match(extensionRegExp);
187
- return match.groups.ext.toLowerCase();
188
- }
@@ -1,53 +0,0 @@
1
- /*
2
- * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
-
6
- :root {
7
- /* Based on default CKBox theme colors */
8
- --ck-image-processing-highlight-color: hsl(220, 10%, 98%);
9
- --ck-image-processing-background-color: hsl(220, 10%, 90%);
10
- }
11
-
12
- .ck.ck-editor__editable {
13
- & .image {
14
- &.image-processing {
15
- position: relative;
16
-
17
- &:before {
18
- content: '';
19
-
20
- position: absolute;
21
- top: 0;
22
- left: 0;
23
- z-index: 1;
24
-
25
- height: 100%;
26
- width: 100%;
27
-
28
- background: linear-gradient(
29
- 90deg,
30
- var(--ck-image-processing-background-color),
31
- var(--ck-image-processing-highlight-color),
32
- var(--ck-image-processing-background-color)
33
- );
34
- background-size: 200% 100%;
35
-
36
- animation: ck-image-processing-animation 2s linear infinite;
37
- }
38
-
39
- & img {
40
- height: 100%;
41
- }
42
- }
43
- }
44
- }
45
-
46
- @keyframes ck-image-processing-animation {
47
- 0% {
48
- background-position: 200% 0;
49
- }
50
- 100% {
51
- background-position: -200% 0;
52
- }
53
- }
File without changes
File without changes
File without changes