@ckeditor/ckeditor5-image 38.0.1 → 38.1.1

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 (109) hide show
  1. package/build/image.js +1 -1
  2. package/build/image.js.map +1 -0
  3. package/package.json +3 -42
  4. package/src/augmentation.d.ts +55 -55
  5. package/src/augmentation.js +5 -5
  6. package/src/autoimage.d.ts +52 -52
  7. package/src/autoimage.js +132 -132
  8. package/src/image/converters.d.ts +66 -66
  9. package/src/image/converters.js +242 -242
  10. package/src/image/imageblockediting.d.ts +55 -55
  11. package/src/image/imageblockediting.js +136 -136
  12. package/src/image/imageediting.d.ts +30 -30
  13. package/src/image/imageediting.js +74 -74
  14. package/src/image/imageinlineediting.d.ts +56 -56
  15. package/src/image/imageinlineediting.js +160 -160
  16. package/src/image/imageloadobserver.d.ts +48 -48
  17. package/src/image/imageloadobserver.js +52 -52
  18. package/src/image/imagetypecommand.d.ts +40 -40
  19. package/src/image/imagetypecommand.js +77 -77
  20. package/src/image/insertimagecommand.d.ts +66 -66
  21. package/src/image/insertimagecommand.js +120 -120
  22. package/src/image/replaceimagesourcecommand.d.ts +34 -34
  23. package/src/image/replaceimagesourcecommand.js +44 -44
  24. package/src/image/ui/utils.d.ts +25 -25
  25. package/src/image/ui/utils.js +44 -44
  26. package/src/image/utils.d.ts +52 -52
  27. package/src/image/utils.js +100 -100
  28. package/src/image.d.ts +34 -34
  29. package/src/image.js +38 -38
  30. package/src/imageblock.d.ts +33 -33
  31. package/src/imageblock.js +37 -37
  32. package/src/imagecaption/imagecaptionediting.d.ts +89 -89
  33. package/src/imagecaption/imagecaptionediting.js +225 -225
  34. package/src/imagecaption/imagecaptionui.d.ts +26 -26
  35. package/src/imagecaption/imagecaptionui.js +61 -61
  36. package/src/imagecaption/imagecaptionutils.d.ts +38 -38
  37. package/src/imagecaption/imagecaptionutils.js +62 -62
  38. package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
  39. package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
  40. package/src/imagecaption.d.ts +26 -26
  41. package/src/imagecaption.js +30 -30
  42. package/src/imageconfig.d.ts +713 -713
  43. package/src/imageconfig.js +5 -5
  44. package/src/imageinline.d.ts +33 -33
  45. package/src/imageinline.js +37 -37
  46. package/src/imageinsert/imageinsertui.d.ts +44 -44
  47. package/src/imageinsert/imageinsertui.js +141 -141
  48. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
  49. package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
  50. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
  51. package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
  52. package/src/imageinsert/utils.d.ts +25 -25
  53. package/src/imageinsert/utils.js +58 -58
  54. package/src/imageinsert.d.ts +33 -33
  55. package/src/imageinsert.js +37 -37
  56. package/src/imageinsertviaurl.d.ts +30 -30
  57. package/src/imageinsertviaurl.js +34 -34
  58. package/src/imageresize/imageresizebuttons.d.ts +67 -67
  59. package/src/imageresize/imageresizebuttons.js +217 -217
  60. package/src/imageresize/imageresizeediting.d.ts +37 -37
  61. package/src/imageresize/imageresizeediting.js +114 -114
  62. package/src/imageresize/imageresizehandles.d.ts +30 -30
  63. package/src/imageresize/imageresizehandles.js +107 -107
  64. package/src/imageresize/resizeimagecommand.d.ts +42 -42
  65. package/src/imageresize/resizeimagecommand.js +61 -61
  66. package/src/imageresize.d.ts +27 -27
  67. package/src/imageresize.js +31 -31
  68. package/src/imagestyle/converters.d.ts +24 -24
  69. package/src/imagestyle/converters.js +79 -79
  70. package/src/imagestyle/imagestylecommand.d.ts +65 -65
  71. package/src/imagestyle/imagestylecommand.js +101 -101
  72. package/src/imagestyle/imagestyleediting.d.ts +50 -50
  73. package/src/imagestyle/imagestyleediting.js +108 -108
  74. package/src/imagestyle/imagestyleui.d.ts +56 -56
  75. package/src/imagestyle/imagestyleui.js +192 -192
  76. package/src/imagestyle/utils.d.ts +101 -101
  77. package/src/imagestyle/utils.js +329 -329
  78. package/src/imagestyle.d.ts +32 -32
  79. package/src/imagestyle.js +36 -36
  80. package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
  81. package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
  82. package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
  83. package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
  84. package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
  85. package/src/imagetextalternative/imagetextalternativeui.js +173 -173
  86. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
  87. package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
  88. package/src/imagetextalternative.d.ts +29 -29
  89. package/src/imagetextalternative.js +33 -33
  90. package/src/imagetoolbar.d.ts +35 -35
  91. package/src/imagetoolbar.js +57 -57
  92. package/src/imageupload/imageuploadediting.d.ts +111 -111
  93. package/src/imageupload/imageuploadediting.js +335 -335
  94. package/src/imageupload/imageuploadprogress.d.ts +42 -42
  95. package/src/imageupload/imageuploadprogress.js +211 -211
  96. package/src/imageupload/imageuploadui.d.ts +23 -23
  97. package/src/imageupload/imageuploadui.js +57 -57
  98. package/src/imageupload/uploadimagecommand.d.ts +60 -60
  99. package/src/imageupload/uploadimagecommand.js +100 -100
  100. package/src/imageupload/utils.d.ts +33 -33
  101. package/src/imageupload/utils.js +112 -112
  102. package/src/imageupload.d.ts +32 -32
  103. package/src/imageupload.js +36 -36
  104. package/src/imageutils.d.ts +102 -102
  105. package/src/imageutils.js +248 -248
  106. package/src/index.d.ts +47 -47
  107. package/src/index.js +38 -38
  108. package/src/pictureediting.d.ts +88 -88
  109. package/src/pictureediting.js +130 -130
@@ -1,34 +1,34 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import { Command } from 'ckeditor5/src/core';
6
- /**
7
- * @module image/image/replaceimagesourcecommand
8
- */
9
- /**
10
- * Replace image source command.
11
- *
12
- * Changes image source to the one provided. Can be executed as follows:
13
- *
14
- * ```ts
15
- * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
16
- * ```
17
- */
18
- export default class ReplaceImageSourceCommand extends Command {
19
- value: string | null;
20
- /**
21
- * @inheritDoc
22
- */
23
- refresh(): void;
24
- /**
25
- * Executes the command.
26
- *
27
- * @fires execute
28
- * @param options Options for the executed command.
29
- * @param options.source The image source to replace.
30
- */
31
- execute(options: {
32
- source: string;
33
- }): void;
34
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Command } from 'ckeditor5/src/core';
6
+ /**
7
+ * @module image/image/replaceimagesourcecommand
8
+ */
9
+ /**
10
+ * Replace image source command.
11
+ *
12
+ * Changes image source to the one provided. Can be executed as follows:
13
+ *
14
+ * ```ts
15
+ * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
16
+ * ```
17
+ */
18
+ export default class ReplaceImageSourceCommand extends Command {
19
+ value: string | null;
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ refresh(): void;
24
+ /**
25
+ * Executes the command.
26
+ *
27
+ * @fires execute
28
+ * @param options Options for the executed command.
29
+ * @param options.source The image source to replace.
30
+ */
31
+ execute(options: {
32
+ source: string;
33
+ }): void;
34
+ }
@@ -1,44 +1,44 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import { Command } from 'ckeditor5/src/core';
6
- /**
7
- * @module image/image/replaceimagesourcecommand
8
- */
9
- /**
10
- * Replace image source command.
11
- *
12
- * Changes image source to the one provided. Can be executed as follows:
13
- *
14
- * ```ts
15
- * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
16
- * ```
17
- */
18
- export default class ReplaceImageSourceCommand extends Command {
19
- /**
20
- * @inheritDoc
21
- */
22
- refresh() {
23
- const editor = this.editor;
24
- const imageUtils = editor.plugins.get('ImageUtils');
25
- const element = this.editor.model.document.selection.getSelectedElement();
26
- this.isEnabled = imageUtils.isImage(element);
27
- this.value = this.isEnabled ? element.getAttribute('src') : null;
28
- }
29
- /**
30
- * Executes the command.
31
- *
32
- * @fires execute
33
- * @param options Options for the executed command.
34
- * @param options.source The image source to replace.
35
- */
36
- execute(options) {
37
- const image = this.editor.model.document.selection.getSelectedElement();
38
- this.editor.model.change(writer => {
39
- writer.setAttribute('src', options.source, image);
40
- writer.removeAttribute('srcset', image);
41
- writer.removeAttribute('sizes', image);
42
- });
43
- }
44
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { Command } from 'ckeditor5/src/core';
6
+ /**
7
+ * @module image/image/replaceimagesourcecommand
8
+ */
9
+ /**
10
+ * Replace image source command.
11
+ *
12
+ * Changes image source to the one provided. Can be executed as follows:
13
+ *
14
+ * ```ts
15
+ * editor.execute( 'replaceImageSource', { source: 'http://url.to.the/image' } );
16
+ * ```
17
+ */
18
+ export default class ReplaceImageSourceCommand extends Command {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ refresh() {
23
+ const editor = this.editor;
24
+ const imageUtils = editor.plugins.get('ImageUtils');
25
+ const element = this.editor.model.document.selection.getSelectedElement();
26
+ this.isEnabled = imageUtils.isImage(element);
27
+ this.value = this.isEnabled ? element.getAttribute('src') : null;
28
+ }
29
+ /**
30
+ * Executes the command.
31
+ *
32
+ * @fires execute
33
+ * @param options Options for the executed command.
34
+ * @param options.source The image source to replace.
35
+ */
36
+ execute(options) {
37
+ const image = this.editor.model.document.selection.getSelectedElement();
38
+ this.editor.model.change(writer => {
39
+ writer.setAttribute('src', options.source, image);
40
+ writer.removeAttribute('srcset', image);
41
+ writer.removeAttribute('sizes', image);
42
+ });
43
+ }
44
+ }
@@ -1,25 +1,25 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module image/image/ui/utils
7
- */
8
- import type { PositionOptions } from 'ckeditor5/src/utils';
9
- import type { Editor } from 'ckeditor5/src/core';
10
- /**
11
- * A helper utility that positions the
12
- * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
13
- * with respect to the image in the editor content, if one is selected.
14
- *
15
- * @param editor The editor instance.
16
- */
17
- export declare function repositionContextualBalloon(editor: Editor): void;
18
- /**
19
- * Returns the positioning options that control the geometry of the
20
- * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
21
- * to the selected element in the editor content.
22
- *
23
- * @param editor The editor instance.
24
- */
25
- export declare function getBalloonPositionData(editor: Editor): Partial<PositionOptions>;
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module image/image/ui/utils
7
+ */
8
+ import type { PositionOptions } from 'ckeditor5/src/utils';
9
+ import type { Editor } from 'ckeditor5/src/core';
10
+ /**
11
+ * A helper utility that positions the
12
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
13
+ * with respect to the image in the editor content, if one is selected.
14
+ *
15
+ * @param editor The editor instance.
16
+ */
17
+ export declare function repositionContextualBalloon(editor: Editor): void;
18
+ /**
19
+ * Returns the positioning options that control the geometry of the
20
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
21
+ * to the selected element in the editor content.
22
+ *
23
+ * @param editor The editor instance.
24
+ */
25
+ export declare function getBalloonPositionData(editor: Editor): Partial<PositionOptions>;
@@ -1,44 +1,44 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import { BalloonPanelView } from 'ckeditor5/src/ui';
6
- /**
7
- * A helper utility that positions the
8
- * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
9
- * with respect to the image in the editor content, if one is selected.
10
- *
11
- * @param editor The editor instance.
12
- */
13
- export function repositionContextualBalloon(editor) {
14
- const balloon = editor.plugins.get('ContextualBalloon');
15
- const imageUtils = editor.plugins.get('ImageUtils');
16
- if (imageUtils.getClosestSelectedImageWidget(editor.editing.view.document.selection)) {
17
- const position = getBalloonPositionData(editor);
18
- balloon.updatePosition(position);
19
- }
20
- }
21
- /**
22
- * Returns the positioning options that control the geometry of the
23
- * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
24
- * to the selected element in the editor content.
25
- *
26
- * @param editor The editor instance.
27
- */
28
- export function getBalloonPositionData(editor) {
29
- const editingView = editor.editing.view;
30
- const defaultPositions = BalloonPanelView.defaultPositions;
31
- const imageUtils = editor.plugins.get('ImageUtils');
32
- return {
33
- target: editingView.domConverter.mapViewToDom(imageUtils.getClosestSelectedImageWidget(editingView.document.selection)),
34
- positions: [
35
- defaultPositions.northArrowSouth,
36
- defaultPositions.northArrowSouthWest,
37
- defaultPositions.northArrowSouthEast,
38
- defaultPositions.southArrowNorth,
39
- defaultPositions.southArrowNorthWest,
40
- defaultPositions.southArrowNorthEast,
41
- defaultPositions.viewportStickyNorth
42
- ]
43
- };
44
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { BalloonPanelView } from 'ckeditor5/src/ui';
6
+ /**
7
+ * A helper utility that positions the
8
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
9
+ * with respect to the image in the editor content, if one is selected.
10
+ *
11
+ * @param editor The editor instance.
12
+ */
13
+ export function repositionContextualBalloon(editor) {
14
+ const balloon = editor.plugins.get('ContextualBalloon');
15
+ const imageUtils = editor.plugins.get('ImageUtils');
16
+ if (imageUtils.getClosestSelectedImageWidget(editor.editing.view.document.selection)) {
17
+ const position = getBalloonPositionData(editor);
18
+ balloon.updatePosition(position);
19
+ }
20
+ }
21
+ /**
22
+ * Returns the positioning options that control the geometry of the
23
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
24
+ * to the selected element in the editor content.
25
+ *
26
+ * @param editor The editor instance.
27
+ */
28
+ export function getBalloonPositionData(editor) {
29
+ const editingView = editor.editing.view;
30
+ const defaultPositions = BalloonPanelView.defaultPositions;
31
+ const imageUtils = editor.plugins.get('ImageUtils');
32
+ return {
33
+ target: editingView.domConverter.mapViewToDom(imageUtils.getClosestSelectedImageWidget(editingView.document.selection)),
34
+ positions: [
35
+ defaultPositions.northArrowSouth,
36
+ defaultPositions.northArrowSouthWest,
37
+ defaultPositions.northArrowSouthEast,
38
+ defaultPositions.southArrowNorth,
39
+ defaultPositions.southArrowNorthWest,
40
+ defaultPositions.southArrowNorthEast,
41
+ defaultPositions.viewportStickyNorth
42
+ ]
43
+ };
44
+ }
@@ -1,52 +1,52 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module image/image/utils
7
- */
8
- import type { DocumentSelection, MatcherPattern, Schema, Selection, ViewContainerElement, DowncastWriter } from 'ckeditor5/src/engine';
9
- import type { Editor } from 'ckeditor5/src/core';
10
- /**
11
- * Creates a view element representing the inline image.
12
- *
13
- * ```html
14
- * <span class="image-inline"><img></img></span>
15
- * ```
16
- *
17
- * Note that `alt` and `src` attributes are converted separately, so they are not included.
18
- *
19
- * @internal
20
- */
21
- export declare function createInlineImageViewElement(writer: DowncastWriter): ViewContainerElement;
22
- /**
23
- * Creates a view element representing the block image.
24
- *
25
- * ```html
26
- * <figure class="image"><img></img></figure>
27
- * ```
28
- *
29
- * Note that `alt` and `src` attributes are converted separately, so they are not included.
30
- *
31
- * @internal
32
- */
33
- export declare function createBlockImageViewElement(writer: DowncastWriter): ViewContainerElement;
34
- /**
35
- * A function returning a `MatcherPattern` for a particular type of View images.
36
- *
37
- * @internal
38
- * @param matchImageType The type of created image.
39
- */
40
- export declare function getImgViewElementMatcher(editor: Editor, matchImageType: 'imageBlock' | 'imageInline'): MatcherPattern;
41
- /**
42
- * Considering the current model selection, it returns the name of the model image element
43
- * (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
44
- * image was inserted (also: uploaded, dropped, pasted) at that selection.
45
- *
46
- * The assumption is that inserting images into empty blocks or on other block widgets should
47
- * produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
48
- * that already contain some text.
49
- *
50
- * @internal
51
- */
52
- export declare function determineImageTypeForInsertionAtSelection(schema: Schema, selection: Selection | DocumentSelection): 'imageBlock' | 'imageInline';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module image/image/utils
7
+ */
8
+ import type { DocumentSelection, MatcherPattern, Schema, Selection, ViewContainerElement, DowncastWriter } from 'ckeditor5/src/engine';
9
+ import type { Editor } from 'ckeditor5/src/core';
10
+ /**
11
+ * Creates a view element representing the inline image.
12
+ *
13
+ * ```html
14
+ * <span class="image-inline"><img></img></span>
15
+ * ```
16
+ *
17
+ * Note that `alt` and `src` attributes are converted separately, so they are not included.
18
+ *
19
+ * @internal
20
+ */
21
+ export declare function createInlineImageViewElement(writer: DowncastWriter): ViewContainerElement;
22
+ /**
23
+ * Creates a view element representing the block image.
24
+ *
25
+ * ```html
26
+ * <figure class="image"><img></img></figure>
27
+ * ```
28
+ *
29
+ * Note that `alt` and `src` attributes are converted separately, so they are not included.
30
+ *
31
+ * @internal
32
+ */
33
+ export declare function createBlockImageViewElement(writer: DowncastWriter): ViewContainerElement;
34
+ /**
35
+ * A function returning a `MatcherPattern` for a particular type of View images.
36
+ *
37
+ * @internal
38
+ * @param matchImageType The type of created image.
39
+ */
40
+ export declare function getImgViewElementMatcher(editor: Editor, matchImageType: 'imageBlock' | 'imageInline'): MatcherPattern;
41
+ /**
42
+ * Considering the current model selection, it returns the name of the model image element
43
+ * (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
44
+ * image was inserted (also: uploaded, dropped, pasted) at that selection.
45
+ *
46
+ * The assumption is that inserting images into empty blocks or on other block widgets should
47
+ * produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
48
+ * that already contain some text.
49
+ *
50
+ * @internal
51
+ */
52
+ export declare function determineImageTypeForInsertionAtSelection(schema: Schema, selection: Selection | DocumentSelection): 'imageBlock' | 'imageInline';
@@ -1,100 +1,100 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import { first } from 'ckeditor5/src/utils';
6
- /**
7
- * Creates a view element representing the inline image.
8
- *
9
- * ```html
10
- * <span class="image-inline"><img></img></span>
11
- * ```
12
- *
13
- * Note that `alt` and `src` attributes are converted separately, so they are not included.
14
- *
15
- * @internal
16
- */
17
- export function createInlineImageViewElement(writer) {
18
- return writer.createContainerElement('span', { class: 'image-inline' }, writer.createEmptyElement('img'));
19
- }
20
- /**
21
- * Creates a view element representing the block image.
22
- *
23
- * ```html
24
- * <figure class="image"><img></img></figure>
25
- * ```
26
- *
27
- * Note that `alt` and `src` attributes are converted separately, so they are not included.
28
- *
29
- * @internal
30
- */
31
- export function createBlockImageViewElement(writer) {
32
- return writer.createContainerElement('figure', { class: 'image' }, [
33
- writer.createEmptyElement('img'),
34
- writer.createSlot('children')
35
- ]);
36
- }
37
- /**
38
- * A function returning a `MatcherPattern` for a particular type of View images.
39
- *
40
- * @internal
41
- * @param matchImageType The type of created image.
42
- */
43
- export function getImgViewElementMatcher(editor, matchImageType) {
44
- const imageUtils = editor.plugins.get('ImageUtils');
45
- const areBothImagePluginsLoaded = editor.plugins.has('ImageInlineEditing') && editor.plugins.has('ImageBlockEditing');
46
- return element => {
47
- // Check if the matched view element is an <img>.
48
- if (!imageUtils.isInlineImageView(element)) {
49
- return null;
50
- }
51
- // If just one of the plugins is loaded (block or inline), it will match all kinds of images.
52
- if (!areBothImagePluginsLoaded) {
53
- return getPositiveMatchPattern(element);
54
- }
55
- // The <img> can be standalone, wrapped in <figure>...</figure> (ImageBlock plugin) or
56
- // wrapped in <figure><a>...</a></figure> (LinkImage plugin).
57
- const imageType = element.getStyle('display') == 'block' || element.findAncestor(imageUtils.isBlockImageView) ?
58
- 'imageBlock' :
59
- 'imageInline';
60
- if (imageType !== matchImageType) {
61
- return null;
62
- }
63
- return getPositiveMatchPattern(element);
64
- };
65
- function getPositiveMatchPattern(element) {
66
- const pattern = {
67
- name: true
68
- };
69
- // This will trigger src consumption (See https://github.com/ckeditor/ckeditor5/issues/11530).
70
- if (element.hasAttribute('src')) {
71
- pattern.attributes = ['src'];
72
- }
73
- return pattern;
74
- }
75
- }
76
- /**
77
- * Considering the current model selection, it returns the name of the model image element
78
- * (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
79
- * image was inserted (also: uploaded, dropped, pasted) at that selection.
80
- *
81
- * The assumption is that inserting images into empty blocks or on other block widgets should
82
- * produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
83
- * that already contain some text.
84
- *
85
- * @internal
86
- */
87
- export function determineImageTypeForInsertionAtSelection(schema, selection) {
88
- const firstBlock = first(selection.getSelectedBlocks());
89
- // Insert a block image if the selection is not in/on block elements or it's on a block widget.
90
- if (!firstBlock || schema.isObject(firstBlock)) {
91
- return 'imageBlock';
92
- }
93
- // A block image should also be inserted into an empty block element
94
- // (that is not an empty list item so the list won't get split).
95
- if (firstBlock.isEmpty && firstBlock.name != 'listItem') {
96
- return 'imageBlock';
97
- }
98
- // Otherwise insert an inline image.
99
- return 'imageInline';
100
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import { first } from 'ckeditor5/src/utils';
6
+ /**
7
+ * Creates a view element representing the inline image.
8
+ *
9
+ * ```html
10
+ * <span class="image-inline"><img></img></span>
11
+ * ```
12
+ *
13
+ * Note that `alt` and `src` attributes are converted separately, so they are not included.
14
+ *
15
+ * @internal
16
+ */
17
+ export function createInlineImageViewElement(writer) {
18
+ return writer.createContainerElement('span', { class: 'image-inline' }, writer.createEmptyElement('img'));
19
+ }
20
+ /**
21
+ * Creates a view element representing the block image.
22
+ *
23
+ * ```html
24
+ * <figure class="image"><img></img></figure>
25
+ * ```
26
+ *
27
+ * Note that `alt` and `src` attributes are converted separately, so they are not included.
28
+ *
29
+ * @internal
30
+ */
31
+ export function createBlockImageViewElement(writer) {
32
+ return writer.createContainerElement('figure', { class: 'image' }, [
33
+ writer.createEmptyElement('img'),
34
+ writer.createSlot('children')
35
+ ]);
36
+ }
37
+ /**
38
+ * A function returning a `MatcherPattern` for a particular type of View images.
39
+ *
40
+ * @internal
41
+ * @param matchImageType The type of created image.
42
+ */
43
+ export function getImgViewElementMatcher(editor, matchImageType) {
44
+ const imageUtils = editor.plugins.get('ImageUtils');
45
+ const areBothImagePluginsLoaded = editor.plugins.has('ImageInlineEditing') && editor.plugins.has('ImageBlockEditing');
46
+ return element => {
47
+ // Check if the matched view element is an <img>.
48
+ if (!imageUtils.isInlineImageView(element)) {
49
+ return null;
50
+ }
51
+ // If just one of the plugins is loaded (block or inline), it will match all kinds of images.
52
+ if (!areBothImagePluginsLoaded) {
53
+ return getPositiveMatchPattern(element);
54
+ }
55
+ // The <img> can be standalone, wrapped in <figure>...</figure> (ImageBlock plugin) or
56
+ // wrapped in <figure><a>...</a></figure> (LinkImage plugin).
57
+ const imageType = element.getStyle('display') == 'block' || element.findAncestor(imageUtils.isBlockImageView) ?
58
+ 'imageBlock' :
59
+ 'imageInline';
60
+ if (imageType !== matchImageType) {
61
+ return null;
62
+ }
63
+ return getPositiveMatchPattern(element);
64
+ };
65
+ function getPositiveMatchPattern(element) {
66
+ const pattern = {
67
+ name: true
68
+ };
69
+ // This will trigger src consumption (See https://github.com/ckeditor/ckeditor5/issues/11530).
70
+ if (element.hasAttribute('src')) {
71
+ pattern.attributes = ['src'];
72
+ }
73
+ return pattern;
74
+ }
75
+ }
76
+ /**
77
+ * Considering the current model selection, it returns the name of the model image element
78
+ * (`'imageBlock'` or `'imageInline'`) that will make most sense from the UX perspective if a new
79
+ * image was inserted (also: uploaded, dropped, pasted) at that selection.
80
+ *
81
+ * The assumption is that inserting images into empty blocks or on other block widgets should
82
+ * produce block images. Inline images should be inserted in other cases, e.g. in paragraphs
83
+ * that already contain some text.
84
+ *
85
+ * @internal
86
+ */
87
+ export function determineImageTypeForInsertionAtSelection(schema, selection) {
88
+ const firstBlock = first(selection.getSelectedBlocks());
89
+ // Insert a block image if the selection is not in/on block elements or it's on a block widget.
90
+ if (!firstBlock || schema.isObject(firstBlock)) {
91
+ return 'imageBlock';
92
+ }
93
+ // A block image should also be inserted into an empty block element
94
+ // (that is not an empty list item so the list won't get split).
95
+ if (firstBlock.isEmpty && firstBlock.name != 'listItem') {
96
+ return 'imageBlock';
97
+ }
98
+ // Otherwise insert an inline image.
99
+ return 'imageInline';
100
+ }