@ckeditor/ckeditor5-ckbox 0.0.0-nightly-20250121.0 → 0.0.0-nightly-20250123.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.
- package/build/ckbox.js +1 -1
- package/dist/index.js +25 -8
- package/dist/index.js.map +1 -1
- package/package.json +9 -7
- package/src/ckboxcommand.js +26 -8
- package/src/ckboxconfig.d.ts +16 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-ckbox",
|
3
|
-
"version": "0.0.0-nightly-
|
3
|
+
"version": "0.0.0-nightly-20250123.0",
|
4
4
|
"description": "CKBox integration for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -13,12 +13,14 @@
|
|
13
13
|
"type": "module",
|
14
14
|
"main": "src/index.js",
|
15
15
|
"dependencies": {
|
16
|
-
"@ckeditor/ckeditor5-
|
17
|
-
"@ckeditor/ckeditor5-
|
18
|
-
"@ckeditor/ckeditor5-
|
19
|
-
"@ckeditor/ckeditor5-
|
20
|
-
"@ckeditor/ckeditor5-
|
21
|
-
"ckeditor5": "0.0.0-nightly-
|
16
|
+
"@ckeditor/ckeditor5-cloud-services": "0.0.0-nightly-20250123.0",
|
17
|
+
"@ckeditor/ckeditor5-core": "0.0.0-nightly-20250123.0",
|
18
|
+
"@ckeditor/ckeditor5-engine": "0.0.0-nightly-20250123.0",
|
19
|
+
"@ckeditor/ckeditor5-image": "0.0.0-nightly-20250123.0",
|
20
|
+
"@ckeditor/ckeditor5-ui": "0.0.0-nightly-20250123.0",
|
21
|
+
"@ckeditor/ckeditor5-upload": "0.0.0-nightly-20250123.0",
|
22
|
+
"@ckeditor/ckeditor5-utils": "0.0.0-nightly-20250123.0",
|
23
|
+
"ckeditor5": "0.0.0-nightly-20250123.0",
|
22
24
|
"blurhash": "2.0.5",
|
23
25
|
"lodash-es": "4.17.21"
|
24
26
|
},
|
package/src/ckboxcommand.js
CHANGED
@@ -154,6 +154,7 @@ export default class CKBoxCommand extends Command {
|
|
154
154
|
const editor = this.editor;
|
155
155
|
const model = editor.model;
|
156
156
|
const shouldInsertDataId = !editor.config.get('ckbox.ignoreDataId');
|
157
|
+
const downloadableFilesConfig = editor.config.get('ckbox.downloadableFiles');
|
157
158
|
// Refresh the command after firing the `ckbox:*` event.
|
158
159
|
this.on('ckbox', () => {
|
159
160
|
this.refresh();
|
@@ -185,6 +186,7 @@ export default class CKBoxCommand extends Command {
|
|
185
186
|
const linkCommand = editor.commands.get('link');
|
186
187
|
const assetsToProcess = prepareAssets({
|
187
188
|
assets,
|
189
|
+
downloadableFilesConfig,
|
188
190
|
isImageAllowed: imageCommand.isEnabled,
|
189
191
|
isLinkAllowed: linkCommand.isEnabled
|
190
192
|
});
|
@@ -298,7 +300,7 @@ export default class CKBoxCommand extends Command {
|
|
298
300
|
/**
|
299
301
|
* Parses the chosen assets into the internal data format. Filters out chosen assets that are not allowed.
|
300
302
|
*/
|
301
|
-
function prepareAssets({ assets, isImageAllowed, isLinkAllowed }) {
|
303
|
+
function prepareAssets({ downloadableFilesConfig, assets, isImageAllowed, isLinkAllowed }) {
|
302
304
|
return assets
|
303
305
|
.map(asset => isImage(asset) ?
|
304
306
|
{
|
@@ -309,7 +311,7 @@ function prepareAssets({ assets, isImageAllowed, isLinkAllowed }) {
|
|
309
311
|
{
|
310
312
|
id: asset.data.id,
|
311
313
|
type: 'link',
|
312
|
-
attributes: prepareLinkAssetAttributes(asset)
|
314
|
+
attributes: prepareLinkAssetAttributes(asset, downloadableFilesConfig)
|
313
315
|
})
|
314
316
|
.filter(asset => asset.type === 'image' ? isImageAllowed : isLinkAllowed);
|
315
317
|
}
|
@@ -334,12 +336,13 @@ export function prepareImageAssetAttributes(asset) {
|
|
334
336
|
/**
|
335
337
|
* Parses the assets attributes into the internal data format.
|
336
338
|
*
|
337
|
-
* @param
|
339
|
+
* @param asset The asset to prepare the attributes for.
|
340
|
+
* @param config The CKBox download asset configuration.
|
338
341
|
*/
|
339
|
-
function prepareLinkAssetAttributes(asset) {
|
342
|
+
function prepareLinkAssetAttributes(asset, config) {
|
340
343
|
return {
|
341
344
|
linkName: asset.data.name,
|
342
|
-
linkHref: getAssetUrl(asset)
|
345
|
+
linkHref: getAssetUrl(asset, config)
|
343
346
|
};
|
344
347
|
}
|
345
348
|
/**
|
@@ -355,10 +358,25 @@ function isImage(asset) {
|
|
355
358
|
/**
|
356
359
|
* Creates the URL for the asset.
|
357
360
|
*
|
358
|
-
* @param
|
361
|
+
* @param asset The asset to create the URL for.
|
362
|
+
* @param config The CKBox download asset configuration.
|
359
363
|
*/
|
360
|
-
function getAssetUrl(asset) {
|
364
|
+
function getAssetUrl(asset, config) {
|
361
365
|
const url = new URL(asset.data.url);
|
362
|
-
|
366
|
+
if (isDownloadableAsset(asset, config)) {
|
367
|
+
url.searchParams.set('download', 'true');
|
368
|
+
}
|
363
369
|
return url.toString();
|
364
370
|
}
|
371
|
+
/**
|
372
|
+
* Determines if download should be enabled for given asset based on configuration.
|
373
|
+
*
|
374
|
+
* @param asset The asset to check.
|
375
|
+
* @param config The CKBox download asset configuration.
|
376
|
+
*/
|
377
|
+
function isDownloadableAsset(asset, config) {
|
378
|
+
if (typeof config === 'function') {
|
379
|
+
return config(asset);
|
380
|
+
}
|
381
|
+
return true;
|
382
|
+
}
|
package/src/ckboxconfig.d.ts
CHANGED
@@ -156,6 +156,18 @@ export interface CKBoxConfig {
|
|
156
156
|
* ```
|
157
157
|
*/
|
158
158
|
choosableFileExtensions?: Array<string>;
|
159
|
+
/**
|
160
|
+
* Controls when to enable the download attribute for inserted links.
|
161
|
+
*
|
162
|
+
* By default, files are downloadable.
|
163
|
+
*
|
164
|
+
* ```ts
|
165
|
+
* const ckboxConfig = {
|
166
|
+
* downloadableFiles: asset => asset.data.extension !== 'pdf'
|
167
|
+
* };
|
168
|
+
* ```
|
169
|
+
*/
|
170
|
+
downloadableFiles?: (asset: CKBoxRawAssetDefinition) => boolean;
|
159
171
|
}
|
160
172
|
export interface CKBoxDialogConfig {
|
161
173
|
/**
|
@@ -402,6 +414,10 @@ export interface CKBoxRawAssetDataDefinition {
|
|
402
414
|
* The asset location.
|
403
415
|
*/
|
404
416
|
url: string;
|
417
|
+
/**
|
418
|
+
* The asset type.
|
419
|
+
*/
|
420
|
+
extension?: string;
|
405
421
|
}
|
406
422
|
/**
|
407
423
|
* Part of raw asset data that is received from the CKBox feature. Properties are set only if the chosen asset is an image.
|