Issue #3248425 by nod_, yogeshmpawar, Wim Leers, lauriii, bnjmnm, marcvangend: Ensure that all classes and functions in Drupal-specific CKEditor 5 plugins are documented

(cherry picked from commit ad44453c64)
merge-requests/2181/head
catch 2022-04-27 12:54:38 +01:00
parent 0f24b084d2
commit 5b666681f3
46 changed files with 397 additions and 168 deletions

View File

@ -1,6 +1,6 @@
/**
* @file
* Provides admin UI for the CKEditor 5.
* Provides the admin UI for CKEditor 5.
*/
((Drupal, drupalSettings, $, JSON, once, Sortable, { tabbable }) => {
@ -49,14 +49,14 @@
}
/**
* Notifies subscribers about new value.
* Notifies subscribers about new values.
*/
notify() {
this._listeners.forEach((listener) => listener(this._value));
}
/**
* Subscribes to be notified for changes.
* Subscribes a listener callback to changes.
*
* @param {Function} listener
* The function to be called when a new value is set.
@ -862,7 +862,7 @@
* @return {string}
* The selected buttons markup.
*
* @internal
* @private
*/
Drupal.theme.ckeditor5SelectedButtons = ({ buttons }) => {
return `
@ -886,7 +886,7 @@
* @return {string}
* The CKEditor 5 divider buttons markup.
*
* @internal
* @private
*/
Drupal.theme.ckeditor5DividerButtons = ({ buttons }) => {
return `
@ -910,7 +910,7 @@
* @return {string}
* The CKEditor 5 available buttons markup.
*
* @internal
* @private
*/
Drupal.theme.ckeditor5AvailableButtons = ({ buttons }) => {
return `
@ -940,7 +940,7 @@
* @return {string}
* The CKEditor 5 buttons markup.
*
* @internal
* @private
*/
Drupal.theme.ckeditor5Button = ({ button: { label, id }, listType }) => {
const buttonInstructions = {
@ -986,7 +986,7 @@
* @return {string}
* The CKEditor 5 admin UI markup.
*
* @internal
* @private
*/
Drupal.theme.ckeditor5Admin = ({
availableButtons,

View File

@ -5,7 +5,9 @@ import { Plugin } from 'ckeditor5/src/core';
import DrupalEmphasisEditing from './drupalemphasisediting';
/**
* @internal
* Drupal-specific plugin to alter the CKEditor 5 italic command.
*
* @private
*/
class DrupalEmphasis extends Plugin {
/**

View File

@ -2,10 +2,9 @@
import { Plugin } from 'ckeditor5/src/core';
/**
* @internal
*/
/**
* Converts italic text into em.
* Alters the italic command to output `<em>` instead of `<i>`.
*
* @private
*/
class DrupalEmphasisEditing extends Plugin {
/**

View File

@ -3,7 +3,7 @@
import DrupalEmphasis from './drupalemphasis';
/**
* @internal
* @private
*/
export default {
DrupalEmphasis,

View File

@ -3,7 +3,15 @@
/**
* HTML builder that converts document fragments into strings.
*
* @internal
* Escapes ampersand characters (`&`) and angle brackets (`<` and `>`) when
* transforming data to HTML. This is required because
* \Drupal\Component\Utility\Xss::filter fails to parse element attributes
* values containing unescaped HTML entities.
*
* @see https://www.drupal.org/project/drupal/issues/3227831
* @see DrupalHtmlBuilder._escapeAttribute
*
* @private
*/
export default class DrupalHtmlBuilder {
/**
@ -41,7 +49,7 @@ export default class DrupalHtmlBuilder {
}
/**
* Converts document fragment into HTML string and appends to the value.
* Converts a document fragment into an HTML string appended to the value.
*
* @param {DocumentFragment} node
* A document fragment to be appended to the value.
@ -57,7 +65,7 @@ export default class DrupalHtmlBuilder {
}
/**
* Appends element node to the value.
* Appends an element node to the value.
*
* @param {DocumentFragment} node
* A document fragment to be appended to the value.
@ -122,7 +130,9 @@ export default class DrupalHtmlBuilder {
* @private
*/
_appendText(node) {
// Text node doesn't have innerHTML property and textContent doesn't encode
// Repack the text into another node and extract using innerHTML. This
// works around text nodes not having an innerHTML property and textContent
// not encoding entities.
// entities. That's why the text is repacked into another node and extracted
// using innerHTML.
const doc = document.implementation.createHTMLDocument('');
@ -133,7 +143,7 @@ export default class DrupalHtmlBuilder {
}
/**
* Appends string to the value.
* Appends a string to the value.
*
* @param {string} str
* A string to be appended to the value.
@ -157,6 +167,9 @@ export default class DrupalHtmlBuilder {
* @param {string} text
* A string to be escaped.
*
* @return {string}
* Escaped string.
*
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
* @see https://html.spec.whatwg.org/multipage/parsing.html#attribute-value-(single-quoted)-state
* @see https://www.drupal.org/project/drupal/issues/3227831

View File

@ -6,15 +6,13 @@ import DrupalHtmlWriter from './drupalhtmlwriter';
/**
* A plugin that overrides the CKEditor HTML writer.
*
* Override the CKEditor 5 HTML writer to escape ampersand characters (&) and
* the angle brackets (< and >). This is required because
* \Drupal\Component\Utility\Xss::filter fails to parse element attributes with
* unescaped entities in value.
* Overrides the CKEditor 5 HTML writer to account for Drupal XSS filtering
* needs.
*
* @see https://www.drupal.org/project/drupal/issues/3227831
* @see DrupalHtmlBuilder._escapeAttribute
*
* @internal
* @private
*/
class DrupalHtmlEngine extends Plugin {
/**

View File

@ -8,11 +8,11 @@ import DrupalHtmlBuilder from './drupalhtmlbuilder';
* attributes.
*
* @see module:engine/dataprocessor/basichtmlwriter~BasicHtmlWriter
* @implements {module:engine/dataprocessor/htmlwriter~HtmlWriter}
* @implements module:engine/dataprocessor/htmlwriter~HtmlWriter
*
* @see https://www.drupal.org/project/drupal/issues/3227831
*
* @internal
* @private
*/
export default class DrupalHtmlWriter {
/**

View File

@ -2,7 +2,7 @@
import DrupalHtmlEngine from './drupalhtmlengine';
/**
* @internal
* @private
*/
export default {
DrupalHtmlEngine,

View File

@ -1,16 +0,0 @@
# ckeditor5-drupal-image
Drupal image plugin for CKEditor5
Provides required attributes `data-entity-uuid` and `data-entity-type`.
## Usage
This project is for creating minified js for [Drupal CKEditor5](http://drupal.org/project/ckeditor5)
## Build
Run `npm run build:dll` to create the minified js.
Check the file path in `webpack.config.js` to ensure it points to the dll
manifest in your copy of `ckeditor5`.

View File

@ -6,7 +6,7 @@ import DrupalImageEditing from './drupalimageediting';
import DrupalImageAlternativeText from './drupalimagealternativetext';
/**
* @internal
* @private
*/
class DrupalImage extends Plugin {
/**

View File

@ -25,14 +25,14 @@ import DrupalImageAlternativeTextUi from './imagealternativetext/drupalimagealte
*/
export default class DrupalImageAlternativeText extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [DrupalImageAlternativeTextEditing, DrupalImageAlternativeTextUi];
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'DrupalImageAlternativeText';

View File

@ -1,25 +1,77 @@
/* eslint-disable import/no-extraneous-dependencies */
// cSpell:words conversionutils downcasted linkimageediting
// cSpell:words conversionutils downcasted linkimageediting emptyelement downcastdispatcher
import { Plugin } from 'ckeditor5/src/core';
import { setViewAttributes } from '@ckeditor/ckeditor5-html-support/src/conversionutils';
/**
* @typedef {function} converterHandler
*
* Callback for a CKEditor 5 event.
*
* @param {Event} event
* The CKEditor 5 event object.
* @param {object} data
* The data associated with the event.
* @param {module:engine/conversion/downcastdispatcher~DowncastConversionApi} conversionApi
* The CKEditor 5 conversion API object.
*/
/**
* Provides an empty image element.
*
* @param {writer} writer
* The CKEditor 5 writer object.
*
* @return {module:engine/view/emptyelement~EmptyElement}
* The empty image element.
*
* @private
*/
function createImageViewElement(writer) {
return writer.createEmptyElement('img');
}
// A simple helper method to detect number strings.
/**
* A simple helper method to detect number strings.
*
* @param {*} value
* The value to test.
*
* @return {boolean}
* True if the value is a string containing a number.
*
* @private
*/
function isNumberString(value) {
const parsedValue = parseFloat(value);
return !Number.isNaN(parsedValue) && value === String(parsedValue);
}
/**
* Generates a callback that saves the entity UUID to an attribute on data
* downcast.
*
* @return {function}
* Callback that binds an event to its parameter.
*
* @private
*/
function modelEntityUuidToDataAttribute() {
function converter(evt, data, conversionApi) {
/**
* Callback for the attribute:dataEntityUuid event.
*
* Saves the UUID value to the data-entity-uuid attribute.
*
* @param {Event} event
* @param {object} data
* @param {module:engine/conversion/downcastdispatcher~DowncastConversionApi} conversionApi
*/
function converter(event, data, conversionApi) {
const { item } = data;
const { consumable, writer } = conversionApi;
if (!consumable.consume(item, evt.name)) {
if (!consumable.consume(item, event.name)) {
return;
}
@ -40,6 +92,9 @@ function modelEntityUuidToDataAttribute() {
};
}
/**
* @type {Array.<{dataValue: string, modelValue: string}>}
*/
const alignmentMapping = [
{
modelValue: 'alignCenter',
@ -55,16 +110,31 @@ const alignmentMapping = [
},
];
// Downcast `caption` model to `data-caption` attribute with its content
// downcasted to plain HTML. This is needed because CKEditor 5 uses <caption>
// element internally in various places, which differs from Drupal which uses
// an attribute. For now to support that we have to manually repeat work done in
// the DowncastDispatcher's private methods.
/**
* Downcasts `caption` model to `data-caption` attribute with its content
* downcasted to plain HTML.
*
* This is needed because CKEditor 5 uses the `<caption>` element internally in
* various places, which differs from Drupal which uses an attribute. For now
* to support that we have to manually repeat work done in the
* DowncastDispatcher's private methods.
*
* @param {module:core/editor/editor~Editor} editor
* The editor instance to use.
*
* @return {function}
* Callback that binds an event to its parameter.
*
* @private
*/
function viewCaptionToCaptionAttribute(editor) {
return (dispatcher) => {
dispatcher.on(
'insert:caption',
(evt, data, conversionApi) => {
/**
* @type {converterHandler}
*/
(event, data, conversionApi) => {
const { consumable, writer, mapper } = conversionApi;
const imageUtils = editor.plugins.get('ImageUtils');
@ -142,12 +212,28 @@ function viewCaptionToCaptionAttribute(editor) {
};
}
/**
* Generates a callback that saves the entity type value to an attribute on
* data downcast.
*
* @return {function}
* Callback that binds an event to it's parameter.
*
* @private
*/
function modelEntityTypeToDataAttribute() {
function converter(evt, data, conversionApi) {
/**
* Callback for the attribute:dataEntityType event.
*
* Saves the UUID value to the data-entity-type attribute.
*
* @type {converterHandler}
*/
function converter(event, data, conversionApi) {
const { item } = data;
const { consumable, writer } = conversionApi;
if (!consumable.consume(item, evt.name)) {
if (!consumable.consume(item, event.name)) {
return;
}
@ -168,8 +254,24 @@ function modelEntityTypeToDataAttribute() {
};
}
/**
* Generates a callback that saves the align value to an attribute on
* data downcast.
*
* @return {function}
* Callback that binds an event to its parameter.
*
* @private
*/
function modelImageStyleToDataAttribute() {
function converter(evt, data, conversionApi) {
/**
* Callback for the attribute:imageStyle event.
*
* Saves the alignment value to the data-align attribute.
*
* @type {converterHandler}
*/
function converter(event, data, conversionApi) {
const { item } = data;
const { consumable, writer } = conversionApi;
@ -178,7 +280,7 @@ function modelImageStyleToDataAttribute() {
);
// Consume only for the values that can be converted into data-align.
if (!mappedAlignment || !consumable.consume(item, evt.name)) {
if (!mappedAlignment || !consumable.consume(item, event.name)) {
return;
}
@ -199,12 +301,28 @@ function modelImageStyleToDataAttribute() {
};
}
/**
* Generates a callback that saves the width value to an attribute on
* data downcast.
*
* @return {function}
* Callback that binds an event to its parameter.
*
* @private
*/
function modelImageWidthToAttribute() {
function converter(evt, data, conversionApi) {
/**
* Callback for the attribute:width event.
*
* Saves the width value to the width attribute.
*
* @type {converterHandler}
*/
function converter(event, data, conversionApi) {
const { item } = data;
const { consumable, writer } = conversionApi;
if (!consumable.consume(item, evt.name)) {
if (!consumable.consume(item, event.name)) {
return;
}
@ -230,12 +348,28 @@ function modelImageWidthToAttribute() {
};
}
/**
* Generates a callback that saves the height value to an attribute on
* data downcast.
*
* @return {function}
* Callback that binds an event to its parameter.
*
* @private
*/
function modelImageHeightToAttribute() {
function converter(evt, data, conversionApi) {
/**
* Callback for the attribute:height event.
*
* Saves the height value to the height attribute.
*
* @type {converterHandler}
*/
function converter(event, data, conversionApi) {
const { item } = data;
const { consumable, writer } = conversionApi;
if (!consumable.consume(item, evt.name)) {
if (!consumable.consume(item, event.name)) {
return;
}
@ -261,8 +395,23 @@ function modelImageHeightToAttribute() {
};
}
/**
* Generates a callback that handles the data downcast for the img element.
*
* @return {function}
* Callback that binds an event to its parameter.
*
* @private
*/
function viewImageToModelImage(editor) {
function converter(evt, data, conversionApi) {
/**
* Callback for the element:img event.
*
* Handles the Drupal specific attributes.
*
* @type {converterHandler}
*/
function converter(event, data, conversionApi) {
const { viewItem } = data;
const { writer, consumable, safeInsert, updateConversionResult, schema } =
conversionApi;
@ -396,10 +545,22 @@ function viewImageToModelImage(editor) {
};
}
// Modified alternative implementation of linkimageediting.js' downcastImageLink.
/**
* Modified alternative implementation of linkimageediting.js' downcastImageLink.
*
* @return {function}
* Callback that binds an event to its parameter.
*
* @private
*/
function downcastBlockImageLink() {
function converter(evt, data, conversionApi) {
if (!conversionApi.consumable.consume(data.item, evt.name)) {
/**
* Callback for the attribute:linkHref event.
*
* @type {converterHandler}
*/
function converter(event, data, conversionApi) {
if (!conversionApi.consumable.consume(data.item, event.name)) {
return;
}
@ -444,9 +605,15 @@ function downcastBlockImageLink() {
}
/**
* @internal
* Add handling of 'dataEntityUuid', 'dataEntityType', 'isDecorative', 'width',
* 'height' attributes on image elements.
*
* @private
*/
export default class DrupalImageEditing extends Plugin {
/**
* @inheritdoc
*/
static get requires() {
return ['ImageUtils'];
}

View File

@ -19,14 +19,14 @@ import ImageTextAlternativeCommand from '@ckeditor/ckeditor5-image/src/imagetext
*/
export default class DrupalImageTextAlternativeEditing extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return ['ImageUtils'];
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'DrupalImageAlternativeTextEditing';
@ -45,7 +45,7 @@ export default class DrupalImageTextAlternativeEditing extends Plugin {
}
/**
* @inheritDoc
* @inheritdoc
*/
init() {
const editor = this.editor;

View File

@ -40,21 +40,21 @@ import MissingAlternativeTextView from './ui/missingalternativetextview';
*/
export default class DrupalImageAlternativeTextUi extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [ContextualBalloon];
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'DrupalImageTextAlternativeUI';
}
/**
* @inheritDoc
* @inheritdoc
*/
init() {
this._createButton();
@ -112,7 +112,7 @@ export default class DrupalImageAlternativeTextUi extends Plugin {
}
/**
* @inheritDoc
* @inheritdoc
*/
destroy() {
super.destroy();

View File

@ -28,7 +28,7 @@ import { icons } from 'ckeditor5/src/core';
*/
export default class ImageAlternativeTextFormView extends View {
/**
* @inheritDoc
* @inheritdoc
*/
constructor(locale) {
super(locale);
@ -163,7 +163,7 @@ export default class ImageAlternativeTextFormView extends View {
}
/**
* @inheritDoc
* @inheritdoc
*/
render() {
super.render();
@ -187,7 +187,7 @@ export default class ImageAlternativeTextFormView extends View {
}
/**
* @inheritDoc
* @inheritdoc
*/
destroy() {
super.destroy();

View File

@ -16,7 +16,7 @@ import { View, ButtonView } from 'ckeditor5/src/ui';
*/
export default class MissingAlternativeTextView extends View {
/**
* @inheritDoc
* @inheritdoc
*/
constructor(locale) {
super(locale);

View File

@ -7,7 +7,9 @@ import { logWarning } from 'ckeditor5/src/utils';
import DrupalImageUploadAdapter from './drupalimageuploadadapter';
/**
* @internal
* Provides a Drupal upload adapter.
*
* @private
*/
export default class DrupalFileRepository extends Plugin {
/**

View File

@ -6,9 +6,9 @@ import DrupalImageUploadEditing from './drupalimageuploadediting';
import DrupalFileRepository from './drupalfilerepository';
/**
* Integrates the CKEditor image upload with the Drupal.
* Integrates the CKEditor image upload with Drupal.
*
* @internal
* @private
*/
class DrupalImageUpload extends Plugin {
/**

View File

@ -2,10 +2,17 @@
/* cspell:words simpleuploadadapter filerepository */
/**
* Upload adapter. Copied from @ckeditor5/ckeditor5-upload/src/adapters/simpleuploadadapter
* Upload adapter.
*
* @internal
* @implements {module:upload/filerepository~UploadAdapter}
* Copied from @ckeditor5/ckeditor5-upload/src/adapters/simpleuploadadapter
* Adds a mapping from `response.uuid` to `dataEntityUuid` and
* `response.entity_type` to `dataEntityType` for the callback after the file
* upload in the `_initListeners` method.
*
* @todo use response.entity_type directly instead of converting it https://www.drupal.org/project/drupal/issues/3275237
*
* @private
* @implements module:upload/filerepository~UploadAdapter
*/
export default class DrupalImageUploadAdapter {
/**
@ -78,9 +85,13 @@ export default class DrupalImageUploadAdapter {
* Initializes XMLHttpRequest listeners
*
* @private
* @param {Function} resolve Callback function to be called when the request is successful.
* @param {Function} reject Callback function to be called when the request cannot be completed.
* @param {File} file Native File object.
*
* @param {Function} resolve
* Callback function to be called when the request is successful.
* @param {Function} reject
* Callback function to be called when the request cannot be completed.
* @param {File} file
* Native File object.
*/
_initListeners(resolve, reject, file) {
const xhr = this.xhr;
@ -99,7 +110,6 @@ export default class DrupalImageUploadAdapter {
: genericErrorText,
);
}
resolve({
urls: { default: response.url },
dataEntityUuid: response.uuid ? response.uuid : '',

View File

@ -2,7 +2,9 @@
import { Plugin } from 'ckeditor5/src/core';
/**
* @internal
* Adds Drupal-specific attributes to the CKEditor 5 image element.
*
* @private
*/
export default class DrupalImageUploadEditing extends Plugin {
/**

View File

@ -4,7 +4,7 @@ import DrupalImage from './drupalimage';
import DrupalImageUpload from './imageupload/drupalimageupload';
/**
* @internal
* @private
*/
export default {
DrupalImage,

View File

@ -30,11 +30,11 @@ import DrupalElementStyleEditing from './drupalelementstyle/drupalelementstyleed
* @see module:drupalMedia/drupalmediaediting~DrupalMediaEditing
* @see module:drupalMedia/drupalmediatoolbar~DrupalMediaToolbar
*
* @internal
* @private
*/
export default class DrupalElementStyle extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [DrupalElementStyleEditing, DrupalElementStyleUi];

View File

@ -15,7 +15,7 @@ import { groupNameToModelAttributeKey } from '../utils';
*
* @extends module:core/command~Command
*
* @internal
* @private
*/
export default class DrupalElementStyleCommand extends Command {
/**
@ -46,7 +46,7 @@ export default class DrupalElementStyleCommand extends Command {
}
/**
* @inheritDoc
* @inheritdoc
*/
refresh() {
const { editor } = this;

View File

@ -14,7 +14,7 @@ import { groupNameToModelAttributeKey } from '../utils';
*
* @param {string} name
* The name of the style definition.
* @param styles
* @param {object} styles
* The styles to search from.
* @return {Drupal.CKEditor5~DrupalElementStyle}
*/
@ -34,6 +34,9 @@ function getStyleDefinitionByName(name, styles) {
* or attribute.
*
* Note that only one style can be applied to a single model element.
*
* @param {object} styles
* Existing styles.
*/
function modelToViewStyleAttribute(styles) {
return (evt, data, conversionApi) => {
@ -192,11 +195,11 @@ function viewToModelStyleAttribute(styles, modelAttribute) {
*
* @extends module:core/plugin~Plugin
*
* @internal
* @private
*/
export default class DrupalElementStyleEditing extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
init() {
const { editor } = this;
@ -339,7 +342,7 @@ export default class DrupalElementStyleEditing extends Plugin {
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'DrupalElementStyleEditing';

View File

@ -70,18 +70,18 @@ function getUIComponentName(name, group) {
*
* @extends module:core/plugin~Plugin
*
* @internal
* @private
*/
export default class DrupalElementStyleUi extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [DrupalElementStyleEditing];
}
/**
* @inheritDoc
* @inheritdoc
*/
init() {
const { plugins } = this.editor;
@ -548,7 +548,7 @@ export default class DrupalElementStyleUi extends Plugin {
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'DrupalElementStyleUi';

View File

@ -6,7 +6,7 @@ import DrupalLinkMediaEditing from './drupallinkmediaediting';
import DrupalLinkMediaUI from './drupallinkmediaui';
/**
* @internal
* @private
*/
export default class DrupalLinkMedia extends Plugin {
/**

View File

@ -319,7 +319,7 @@ function upcastMediaLinkManualDecorator(editor, decorator) {
/**
* Model to view and view to model conversions for linked media elements.
*
* @internal
* @private
*
* @see https://github.com/ckeditor/ckeditor5/blob/v31.0.0/packages/ckeditor5-link/src/linkimage.js
*/

View File

@ -8,7 +8,7 @@ import linkIcon from '../../../../../icons/link.svg';
/**
* The link media UI plugin.
*
* @internal
* @private
*/
export default class DrupalLinkMediaUI extends Plugin {
/**

View File

@ -10,9 +10,21 @@ import MediaImageTextAlternative from './mediaimagetextalternative';
import DrupalMediaGeneralHtmlSupport from './drupalmediageneralhtmlsupport';
/**
* @internal
* Main entrypoint to the Drupal media widget.
*
* See individual capabilities for details:
* - {@link DrupalMediaEditing}
* - {@link DrupalMediaGeneralHtmlSupport}
* - {@link DrupalMediaUI}
* - {@link DrupalMediaToolbar}
* - {@link MediaImageTextAlternative}
*
* @private
*/
export default class DrupalMedia extends Plugin {
/**
* @inheritdoc
*/
static get requires() {
return [
DrupalMediaEditing,

View File

@ -5,13 +5,21 @@ import DrupalMediaCaptionEditing from './drupalmediacaption/drupalmediacaptioned
import DrupalMediaCaptionUI from './drupalmediacaption/drupalmediacaptionui';
/**
* @internal
* Provides the caption feature on Drupal media elements.
*
* @private
*/
export default class DrupalMediaCaption extends Plugin {
/**
* @inheritdoc
*/
static get requires() {
return [DrupalMediaCaptionEditing, DrupalMediaCaptionUI];
}
/**
* @inheritdoc
*/
static get pluginName() {
return 'DrupalMediaCaption';
}

View File

@ -36,11 +36,11 @@ function getCaptionFromDrupalMediaModelElement(drupalMediaModelElement) {
*
* @extends module:core/command~Command
*
* @internal
* @private
*/
export default class ToggleDrupalMediaCaptionCommand extends Command {
/**
* @inheritDoc
* @inheritdoc
*/
refresh() {
const selection = this.editor.model.document.selection;

View File

@ -174,25 +174,25 @@ function modelCaptionToCaptionAttribute(editor) {
*
* @extends module:core/plugin~Plugin
*
* @internal
* @private
*/
export default class DrupalMediaCaptionEditing extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [];
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'DrupalMediaCaptionEditing';
}
/**
* @inheritDoc
* @inheritdoc
*/
constructor(editor) {
super(editor);
@ -208,7 +208,7 @@ export default class DrupalMediaCaptionEditing extends Plugin {
}
/**
* @inheritDoc
* @inheritdoc
*/
init() {
const editor = this.editor;

View File

@ -6,7 +6,7 @@ import { getMediaCaptionFromModelSelection } from './utils';
/**
* The caption media UI plugin.
*
* @internal
* @private
*/
export default class DrupalMediaCaptionUI extends Plugin {
/**

View File

@ -13,13 +13,23 @@ import { METADATA_ERROR } from './mediaimagetextalternative/utils';
*/
/**
* @internal
* The Drupal Media Editing plugin.
*
* Handles the transformation from the CKEditor 5 UI to Drupal-specific markup.
*
* @private
*/
export default class DrupalMediaEditing extends Plugin {
/**
* @inheritdoc
*/
static get requires() {
return [Widget];
}
/**
* @inheritdoc
*/
init() {
this.attrs = {
drupalMediaAlt: 'alt',
@ -105,16 +115,6 @@ export default class DrupalMediaEditing extends Plugin {
*
* @param {module:engine/model/node~Node} modelElement
* The `drupalMedia` model element.
* @param {module:core/editor/editor~Editor} editor
* The editor instance.
* @param {Drupal.CKEditor5~DrupalElementStyle[]} definedStyles
* A list of defined styles.
* @param {string} style
* The style to check be checked against the bundle specific styles.
* @param {<module:ui/dropdown/utils~ListDropdownItemDefinition>} definition
* Dropdown item definition.
* @param {string} modelAttribute
* The model attribute name of the drupalElementStyle.
*
* @see module:drupalMedia/drupalmediametadatarepository~DrupalMediaMetadataRepository
*
@ -188,6 +188,11 @@ export default class DrupalMediaEditing extends Plugin {
return { label: this.labelError, preview: this.themeError };
}
/**
* Registers drupalMedia as a block element in the DOM converter.
*
* @private
*/
_defineSchema() {
const schema = this.editor.model.schema;
schema.register('drupalMedia', {
@ -203,6 +208,11 @@ export default class DrupalMediaEditing extends Plugin {
this.editor.editing.view.domConverter.blockElements.push('drupal-media');
}
/**
* Defines handling of drupal media element in the content lifecycle.
*
* @private
*/
_defineConverters() {
const conversion = this.editor.conversion;
const metadataRepository = this.editor.plugins.get(
@ -422,11 +432,18 @@ export default class DrupalMediaEditing extends Plugin {
});
}
/**
* Defines behavior when an drupalMedia element is inserted.
*
* Listen to `insertContent` event on the model to set `drupalMediaIsImage`
* and `drupalMediaType` attribute when `drupalMedia` model element is
* inserted directly to the model.
*
* @see module:drupalMedia/insertdrupalmediacommand~InsertDrupalMediaCommand
*
* @private
*/
_defineListeners() {
// Listen to `insertContent` event on the model to set `drupalMediaIsImage` and `drupalMediaType`
// attribute when `drupalMedia` model element is inserted directly to the
// model.
// @see module:drupalMedia/insertdrupalmediacommand~InsertDrupalMediaCommand
this.editor.model.on('insertContent', (eventInfo, [modelElement]) => {
if (!isDrupalMedia(modelElement)) {
return;

View File

@ -4,13 +4,14 @@ import { Plugin } from 'ckeditor5/src/core';
import { setViewAttributes } from '@ckeditor/ckeditor5-html-support/src/conversionutils';
/**
* View-to-model conversion helper preserving allowed attributes on the Drupal Media model.
* View-to-model conversion helper for Drupal Media.
* Used for preserving allowed attributes on the Drupal Media model.
*
* @param {module:html-support/datafilter~DataFilter} dataFilter
* The General HTML support data filter.
*
* @return {function}
* function that adds an event listener to upcastDispatcher.
* Function that adds an event listener to upcastDispatcher.
*/
function viewToModelDrupalMediaAttributeConverter(dataFilter) {
return (dispatcher) => {
@ -134,7 +135,7 @@ function modelToEditingViewAttributeConverter() {
* Model to data view attribute converter.
*
* @return {function}
* function that adds an event listener to downcastDispatcher.
* Function that adds an event listener to downcastDispatcher.
*/
function modelToDataViewAttributeConverter() {
return (dispatcher) => {
@ -172,7 +173,7 @@ function modelToDataViewAttributeConverter() {
/**
* Integrates Drupal Media with General HTML Support.
*
* @internal
* @private
*/
export default class DrupalMediaGeneralHtmlSupport extends Plugin {
/**

View File

@ -27,7 +27,7 @@ const _fetchMetadata = async (url) => {
};
/**
* @internal
* @private
*/
export default class DrupalMediaMetadataRepository extends Plugin {
/**
@ -38,10 +38,11 @@ export default class DrupalMediaMetadataRepository extends Plugin {
}
/**
* Gets metadata for `drupalMedia` model element.
* Gets metadata for a `drupalMedia` model element.
*
* @param {module:engine/model/element~Element} modelElement
* The model element which metadata should be retrieved.
* The model element from which metadata should be retrieved.
*
* @return {Promise<Object>}
*/
getMetadata(modelElement) {

View File

@ -26,17 +26,26 @@ function normalizeDeclarativeConfig(config) {
}
/**
* @internal
* @private
*/
export default class DrupalMediaToolbar extends Plugin {
/**
* @inheritdoc
*/
static get requires() {
return [WidgetToolbarRepository];
}
/**
* @inheritdoc
*/
static get pluginName() {
return 'DrupalMediaToolbar';
}
/**
* @inheritdoc
*/
afterInit() {
const { editor } = this;
const widgetToolbarRepository = editor.plugins.get(WidgetToolbarRepository);

View File

@ -7,7 +7,9 @@ import { ButtonView } from 'ckeditor5/src/ui';
import mediaIcon from '../theme/icons/medialibrary.svg';
/**
* @internal
* Provides the toolbar button to insert a Drupal media element.
*
* @private
*/
export default class DrupalMediaUI extends Plugin {
init() {

View File

@ -17,7 +17,7 @@ import MediaImageTextAlternativeEditing from './mediaimagetextalternative/mediai
import MediaImageTextAlternativeUi from './mediaimagetextalternative/mediaimagetextalternativeui';
/**
* @internal
* @private
*/
export default {
DrupalMedia,

View File

@ -12,9 +12,6 @@ function createDrupalMedia(writer, attributes) {
return drupalMedia;
}
/**
* @internal
*/
/**
* The insert media command.
*
@ -24,6 +21,7 @@ function createDrupalMedia(writer, attributes) {
* In order to insert media at the current selection position, execute the
* command and pass the attributes desired in the drupal-media element:
*
* @example
* editor.execute('insertDrupalMedia', {
* 'alt': 'Alt text',
* 'data-align': 'left',
@ -32,6 +30,8 @@ function createDrupalMedia(writer, attributes) {
* 'data-entity-uuid': 'media-entity-uuid',
* 'data-view-mode': 'default',
* });
*
* @private
*/
export default class InsertDrupalMediaCommand extends Command {
execute(attributes) {

View File

@ -3,22 +3,21 @@ import { Plugin } from 'ckeditor5/src/core';
import MediaImageTextAlternativeEditing from './mediaimagetextalternative/mediaimagetextalternativeediting';
import MediaImageTextAlternativeUi from './mediaimagetextalternative/mediaimagetextalternativeui';
/**
* @internal
*/
/**
* The media image text alternative plugin.
*
* @private
*/
export default class MediaImageTextAlternative extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [MediaImageTextAlternativeEditing, MediaImageTextAlternativeUi];
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'MediaImageTextAlternative';

View File

@ -15,7 +15,7 @@ export default class MediaImageTextAlternativeCommand extends Command {
* The command value: `false` if there is no `alt` attribute, otherwise the value of the `alt` attribute.
/**
* @inheritDoc
* @inheritdoc
*/
refresh() {
const drupalMediaElement = getClosestSelectedDrupalMediaElement(

View File

@ -16,21 +16,21 @@ import { METADATA_ERROR } from './utils';
*/
export default class MediaImageTextAlternativeEditing extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [DrupalMediaMetadataRepository];
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'MediaImageTextAlternativeEditing';
}
/**
* @inheritDoc
* @inheritdoc
*/
init() {
const {

View File

@ -23,21 +23,21 @@ import TextAlternativeFormView from './ui/textalternativeformview';
*/
export default class MediaImageTextAlternativeUi extends Plugin {
/**
* @inheritDoc
* @inheritdoc
*/
static get requires() {
return [ContextualBalloon];
}
/**
* @inheritDoc
* @inheritdoc
*/
static get pluginName() {
return 'MediaImageTextAlternativeUi';
}
/**
* @inheritDoc
* @inheritdoc
*/
init() {
this._createButton();
@ -45,7 +45,7 @@ export default class MediaImageTextAlternativeUi extends Plugin {
}
/**
* @inheritDoc
* @inheritdoc
*/
destroy() {
super.destroy();

View File

@ -12,7 +12,7 @@ import { getClosestSelectedDrupalMediaWidget } from '../utils';
* @return {Object}
* The options.
*
* @internal
* @private
*/
export function getBalloonPositionData(editor) {
const editingView = editor.editing.view;
@ -40,7 +40,7 @@ export function getBalloonPositionData(editor) {
* @param {module:core/editor/editor~Editor} editor
* The editor instance.
*
* @internal
* @private
*/
export function repositionContextualBalloon(editor) {
const balloon = editor.plugins.get('ContextualBalloon');

View File

@ -8,9 +8,9 @@ import { isWidget } from 'ckeditor5/src/widget';
* @param {module:engine/model/element~Element} modelElement
* The model element to be checked.
* @return {boolean}
* A boolean indicating whether element is drupalMedia element.
* A boolean indicating if the element is a drupalMedia element.
*
* @internal
* @private
*/
export function isDrupalMedia(modelElement) {
return !!modelElement && modelElement.is('element', 'drupalMedia');
@ -22,9 +22,9 @@ export function isDrupalMedia(modelElement) {
* @param {module:engine/view/element~Element} viewElement
* The view element.
* @return {boolean}
* A boolean indicating whether element is <drupal-media> element.
* A boolean indicating if the element is a <drupal-media> element.
*
* @internal
* @private
*/
export function isDrupalMediaWidget(viewElement) {
return (
@ -37,12 +37,12 @@ export function isDrupalMediaWidget(viewElement) {
*
* @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
* The current selection.
* @returns {module:engine/model/element~Element|null}
* @return {module:engine/model/element~Element|null}
* The `drupalMedia` element which could be either the current selected an
* ancestor of the selection. Returns null if the selection has no Drupal
* Media element.
*
* @internal
* @private
*/
export function getClosestSelectedDrupalMediaElement(selection) {
const selectedElement = selection.getSelectedElement();
@ -60,7 +60,7 @@ export function getClosestSelectedDrupalMediaElement(selection) {
* @return {module:engine/view/element~Element|null}
* The currently selected Drupal Media widget or null.
*
* @internal
* @private
*/
export function getClosestSelectedDrupalMediaWidget(selection) {
const viewElement = selection.getSelectedElement();
@ -98,7 +98,7 @@ export function isObject(value) {
}
/**
* Gets preview container element from the media element.
* Gets the preview container element from the media element.
*
* @param {Iterable.<module:engine/view/element~Element>} children
* The child elements.