@ckeditor/ckeditor5-image 48.0.1 → 48.1.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.
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
-
import { Command, type Editor } from '@ckeditor/ckeditor5-core';
|
|
6
|
-
import type { ModelWriter, ModelElement } from '@ckeditor/ckeditor5-engine';
|
|
7
5
|
/**
|
|
8
6
|
* @module image/image/replaceimagesourcecommand
|
|
9
7
|
*/
|
|
8
|
+
import { Command, type Editor } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import type { ModelWriter, ModelElement } from '@ckeditor/ckeditor5-engine';
|
|
10
10
|
/**
|
|
11
11
|
* Replace image source command.
|
|
12
12
|
*
|
|
@@ -5,9 +5,6 @@
|
|
|
5
5
|
import type { DowncastAttributeEvent, UpcastElementEvent } from '@ckeditor/ckeditor5-engine';
|
|
6
6
|
import { type GetCallback } from '@ckeditor/ckeditor5-utils';
|
|
7
7
|
import type { ImageStyleOptionDefinition } from '../imageconfig.js';
|
|
8
|
-
/**
|
|
9
|
-
* @module image/imagestyle/converters
|
|
10
|
-
*/
|
|
11
8
|
/**
|
|
12
9
|
* Returns a converter for the `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
|
|
13
10
|
*
|
|
@@ -50,6 +50,12 @@ export declare const DEFAULT_ICONS: Record<string, string>;
|
|
|
50
50
|
* @internal
|
|
51
51
|
*/
|
|
52
52
|
export declare const DEFAULT_DROPDOWN_DEFINITIONS: Array<ImageStyleDropdownDefinition>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the style with a given `name` from an array of styles.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare function getStyleDefinitionByName(name: string, styles: Array<ImageStyleOptionDefinition>): ImageStyleOptionDefinition | undefined;
|
|
53
59
|
/**
|
|
54
60
|
* Returns a list of the normalized and validated image style options.
|
|
55
61
|
*
|
package/dist/index.js
CHANGED
|
@@ -382,7 +382,7 @@ const IMAGE_WIDGETS_CLASSES_MATCH_REGEXP = /^(image|image-inline)$/;
|
|
|
382
382
|
*/ function getInsertImageParent(selection, model) {
|
|
383
383
|
const insertionRange = findOptimalInsertionRange(selection, model);
|
|
384
384
|
const parent = insertionRange.start.parent;
|
|
385
|
-
if (parent.isEmpty && !parent.is('
|
|
385
|
+
if (parent.isEmpty && !parent.is('rootElement')) {
|
|
386
386
|
return parent.parent;
|
|
387
387
|
}
|
|
388
388
|
return parent;
|
|
@@ -1419,8 +1419,6 @@ const IMAGE_URL_REGEXP = new RegExp(String(/^(http(s)?:\/\/)?[\w-]+\.[\w.~:/[\]@
|
|
|
1419
1419
|
}
|
|
1420
1420
|
|
|
1421
1421
|
/**
|
|
1422
|
-
* @module image/image/replaceimagesourcecommand
|
|
1423
|
-
*/ /**
|
|
1424
1422
|
* Replace image source command.
|
|
1425
1423
|
*
|
|
1426
1424
|
* Changes image source to the one provided. Can be executed as follows:
|
|
@@ -3481,8 +3479,6 @@ const IMAGE_URL_REGEXP = new RegExp(String(/^(http(s)?:\/\/)?[\w-]+\.[\w.~:/[\]@
|
|
|
3481
3479
|
}
|
|
3482
3480
|
|
|
3483
3481
|
/**
|
|
3484
|
-
* @module image/imageupload/uploadimagecommand
|
|
3485
|
-
*/ /**
|
|
3486
3482
|
* The upload image command.
|
|
3487
3483
|
*
|
|
3488
3484
|
* The command is registered by the {@link module:image/imageupload/imageuploadediting~ImageUploadEditing} plugin as `uploadImage`
|
|
@@ -5877,6 +5873,17 @@ const RESIZED_IMAGE_CLASS = 'image_resized';
|
|
|
5877
5873
|
]
|
|
5878
5874
|
}
|
|
5879
5875
|
];
|
|
5876
|
+
/**
|
|
5877
|
+
* Returns the style with a given `name` from an array of styles.
|
|
5878
|
+
*
|
|
5879
|
+
* @internal
|
|
5880
|
+
*/ function getStyleDefinitionByName(name, styles) {
|
|
5881
|
+
for (const style of styles){
|
|
5882
|
+
if (style.name === name) {
|
|
5883
|
+
return style;
|
|
5884
|
+
}
|
|
5885
|
+
}
|
|
5886
|
+
}
|
|
5880
5887
|
/**
|
|
5881
5888
|
* Returns a list of the normalized and validated image style options.
|
|
5882
5889
|
*
|
|
@@ -6063,8 +6070,6 @@ const RESIZED_IMAGE_CLASS = 'image_resized';
|
|
|
6063
6070
|
};
|
|
6064
6071
|
|
|
6065
6072
|
/**
|
|
6066
|
-
* @module image/imagestyle/converters
|
|
6067
|
-
*/ /**
|
|
6068
6073
|
* Returns a converter for the `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
|
|
6069
6074
|
*
|
|
6070
6075
|
* @param styles An array containing available image style options.
|
|
@@ -6169,15 +6174,6 @@ const RESIZED_IMAGE_CLASS = 'image_resized';
|
|
|
6169
6174
|
]
|
|
6170
6175
|
});
|
|
6171
6176
|
}
|
|
6172
|
-
/**
|
|
6173
|
-
* Returns the style with a given `name` from an array of styles.
|
|
6174
|
-
*/ function getStyleDefinitionByName(name, styles) {
|
|
6175
|
-
for (const style of styles){
|
|
6176
|
-
if (style.name === name) {
|
|
6177
|
-
return style;
|
|
6178
|
-
}
|
|
6179
|
-
}
|
|
6180
|
-
}
|
|
6181
6177
|
|
|
6182
6178
|
/**
|
|
6183
6179
|
* The image style engine plugin. It sets the default configuration, creates converters and registers
|
|
@@ -6246,7 +6242,8 @@ const RESIZED_IMAGE_CLASS = 'image_resized';
|
|
|
6246
6242
|
allowAttributes: 'imageStyle'
|
|
6247
6243
|
});
|
|
6248
6244
|
schema.setAttributeProperties('imageStyle', {
|
|
6249
|
-
isFormatting: true
|
|
6245
|
+
isFormatting: true,
|
|
6246
|
+
blockAlignment: getBlockAlignmentAttributeProperty(this.normalizedStyles)
|
|
6250
6247
|
});
|
|
6251
6248
|
// Converter for figure element from view to model.
|
|
6252
6249
|
editor.data.upcastDispatcher.on('element:figure', viewToModelConverter, {
|
|
@@ -6303,6 +6300,47 @@ const RESIZED_IMAGE_CLASS = 'image_resized';
|
|
|
6303
6300
|
});
|
|
6304
6301
|
}
|
|
6305
6302
|
}
|
|
6303
|
+
/**
|
|
6304
|
+
* Returns a mapping of generic alignment values ('left', 'right', 'center') to their corresponding
|
|
6305
|
+
* block image alignment style names.
|
|
6306
|
+
*
|
|
6307
|
+
* This function is particularly useful for scenarios like `td[align]` conversion, which needs to know
|
|
6308
|
+
* exactly how to map a generic `align` attribute to the correct alignment value. This mapping is necessary
|
|
6309
|
+
* because the actual alignment value can differ depending on the target element type (e.g., block images
|
|
6310
|
+
* vs. tables).
|
|
6311
|
+
*
|
|
6312
|
+
* @param styles An array of available image style option definitions.
|
|
6313
|
+
* @returns A record mapping basic alignments to their valid, block-specific style names.
|
|
6314
|
+
*/ function getBlockAlignmentAttributeProperty(styles) {
|
|
6315
|
+
const pickFirstSupported = (...names)=>{
|
|
6316
|
+
const found = names.map((name)=>getStyleDefinitionByName(name, styles)).find((definition)=>definition?.modelElements.includes('imageBlock'));
|
|
6317
|
+
if (!found) {
|
|
6318
|
+
return;
|
|
6319
|
+
}
|
|
6320
|
+
return {
|
|
6321
|
+
isDefault: !!found.isDefault,
|
|
6322
|
+
value: found.name
|
|
6323
|
+
};
|
|
6324
|
+
};
|
|
6325
|
+
const candidates = {
|
|
6326
|
+
left: [
|
|
6327
|
+
'alignBlockLeft',
|
|
6328
|
+
'alignLeft'
|
|
6329
|
+
],
|
|
6330
|
+
right: [
|
|
6331
|
+
'alignBlockRight',
|
|
6332
|
+
'alignRight'
|
|
6333
|
+
],
|
|
6334
|
+
center: [
|
|
6335
|
+
'block',
|
|
6336
|
+
'alignCenter'
|
|
6337
|
+
]
|
|
6338
|
+
};
|
|
6339
|
+
return Object.fromEntries(Object.entries(candidates).map(([align, names])=>[
|
|
6340
|
+
align,
|
|
6341
|
+
pickFirstSupported(...names)
|
|
6342
|
+
]).filter(([, resolved])=>resolved !== undefined));
|
|
6343
|
+
}
|
|
6306
6344
|
|
|
6307
6345
|
/**
|
|
6308
6346
|
* The image style UI plugin.
|