1 | /**
|
2 | * @license Copyright (c) 2003-2024, 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/imagecaption/imagecaptionediting
|
7 | */
|
8 | import { type Editor, Plugin } from 'ckeditor5/src/core.js';
|
9 | import { Element } from 'ckeditor5/src/engine.js';
|
10 | import ImageUtils from '../imageutils.js';
|
11 | import ImageCaptionUtils from './imagecaptionutils.js';
|
12 | /**
|
13 | * The image caption engine plugin. It is responsible for:
|
14 | *
|
15 | * * registering converters for the caption element,
|
16 | * * registering converters for the caption model attribute,
|
17 | * * registering the {@link module:image/imagecaption/toggleimagecaptioncommand~ToggleImageCaptionCommand `toggleImageCaption`} command.
|
18 | */
|
19 | export default class ImageCaptionEditing extends Plugin {
|
20 | /**
|
21 | * @inheritDoc
|
22 | */
|
23 | static get requires(): readonly [typeof ImageUtils, typeof ImageCaptionUtils];
|
24 | /**
|
25 | * @inheritDoc
|
26 | */
|
27 | static get pluginName(): "ImageCaptionEditing";
|
28 | /**
|
29 | * A map that keeps saved JSONified image captions and image model elements they are
|
30 | * associated with.
|
31 | *
|
32 | * To learn more about this system, see {@link #_saveCaption}.
|
33 | */
|
34 | private _savedCaptionsMap;
|
35 | /**
|
36 | * @inheritDoc
|
37 | */
|
38 | constructor(editor: Editor);
|
39 | /**
|
40 | * @inheritDoc
|
41 | */
|
42 | init(): void;
|
43 | /**
|
44 | * Configures conversion pipelines to support upcasting and downcasting
|
45 | * image captions.
|
46 | */
|
47 | private _setupConversion;
|
48 | /**
|
49 | * Integrates with {module:image/image/imagetypecommand~ImageTypeCommand image type commands}
|
50 | * to make sure the caption is preserved when the type of an image changes so it can be restored
|
51 | * in the future if the user decides they want their caption back.
|
52 | */
|
53 | private _setupImageTypeCommandsIntegration;
|
54 | /**
|
55 | * Returns the saved {module:engine/model/element~Element#toJSON JSONified} caption
|
56 | * of an image model element.
|
57 | *
|
58 | * See { #_saveCaption}.
|
59 | *
|
60 | *
|
61 | * for.
imageModelElement The model element the caption should be returned |
62 | * `null` if there is none.
The model caption element or |
63 | */
|
64 | _getSavedCaption(imageModelElement: Element): Element | null;
|
65 | /**
|
66 | * Saves a {@link module:engine/model/element~Element#toJSON JSONified} caption for
|
67 | * an image element to allow restoring it in the future.
|
68 | *
|
69 | * A caption is saved every time it gets hidden and/or the type of an image changes. The
|
70 | * user should be able to restore it on demand.
|
71 | *
|
72 | * **Note**: The caption cannot be stored in the image model element attribute because,
|
73 | * for instance, when the model state propagates to collaborators, the attribute would get
|
74 | * lost (mainly because it does not convert to anything when the caption is hidden) and
|
75 | * the states of collaborators' models would de-synchronize causing numerous issues.
|
76 | *
|
77 | * See {@link #_getSavedCaption}.
|
78 | *
|
79 | * @internal
|
80 | * @param imageModelElement The model element the caption is saved for.
|
81 | * @param caption The caption model element to be saved.
|
82 | */
|
83 | _saveCaption(imageModelElement: Element, caption: Element): void;
|
84 | /**
|
85 | * Reconverts image caption when image alt attribute changes.
|
86 | * The change of alt attribute is reflected in caption's aria-label attribute.
|
87 | */
|
88 | private _registerCaptionReconversion;
|
89 | }
|