|
|
@@ -17,28 +17,28 @@ import { get, isObject, merge, set, unset } from 'lodash-es';
|
|
|
export default class StylesMap {
|
|
|
/**
|
|
|
* Creates Styles instance.
|
|
|
+ *
|
|
|
+ * @param {module:engine/view/stylesmap~StylesProcessor} styleProcessor
|
|
|
*/
|
|
|
- constructor() {
|
|
|
+ constructor( styleProcessor ) {
|
|
|
/**
|
|
|
* Keeps an internal representation of styles map. Normalized styles are kept as object tree to allow unified modification and
|
|
|
* value access model using lodash's get, set, unset, etc methods.
|
|
|
*
|
|
|
* When no style processor rules are defined the it acts as simple key-value storage.
|
|
|
*
|
|
|
- * @type {Object}
|
|
|
* @private
|
|
|
+ * @type {Object}
|
|
|
*/
|
|
|
this._styles = {};
|
|
|
|
|
|
- // Hide _styleProcessor from the watchdog by making this property non-enumarable. Watchdog checks errors for their editor origin
|
|
|
- // by checking if two objects are connected through properties. Using singleton is against this check as it would detect
|
|
|
- // that two editors are connected through single style processor instance.
|
|
|
- Object.defineProperty( this, '_styleProcessor', {
|
|
|
- get() {
|
|
|
- return StylesMap._styleProcessor;
|
|
|
- },
|
|
|
- enumerable: false
|
|
|
- } );
|
|
|
+ /**
|
|
|
+ * An instance of the {@link module:engine/view/stylesmap~StylesProcessor}.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @member {module:engine/view/stylesmap~StylesProcessor}
|
|
|
+ */
|
|
|
+ this._styleProcessor = styleProcessor;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -372,28 +372,6 @@ export default class StylesMap {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns related style names.
|
|
|
- *
|
|
|
- * // Enable 'margin' shorthand processing:
|
|
|
- * editor.editing.view.document.addStyleProcessorRules( addMarginRules );
|
|
|
- *
|
|
|
- * StylesMap.getRelatedStyles( 'margin' );
|
|
|
- * // will return: [ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left' ];
|
|
|
- *
|
|
|
- * StylesMap.getRelatedStyles( 'margin-top' );
|
|
|
- * // will return: [ 'margin' ];
|
|
|
- *
|
|
|
- * **Note**: To define new style relations load an existing style processor (as shown above) or use
|
|
|
- * {@link module:engine/view/stylesmap~StylesProcessor#setStyleRelation `StylesProcessor.setStyleRelation()`}.
|
|
|
- *
|
|
|
- * @param {String} name
|
|
|
- * @returns {Array.<String>}
|
|
|
- */
|
|
|
- static getRelatedStyles( name ) {
|
|
|
- return this._styleProcessor.getRelatedStyles( name );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* Returns normalized styles entries for further processing.
|
|
|
*
|
|
|
* @private
|
|
|
@@ -439,32 +417,6 @@ export default class StylesMap {
|
|
|
this.remove( parentPath );
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns global StylesProcessor instance.
|
|
|
- *
|
|
|
- * @returns {module:engine/view/stylesmap~StylesProcessor}
|
|
|
- * @private
|
|
|
- */
|
|
|
- static get _styleProcessor() {
|
|
|
- if ( !this._processor ) {
|
|
|
- this._processor = new StylesProcessor();
|
|
|
- }
|
|
|
-
|
|
|
- return this._processor;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Set new StylesProcessor instance.
|
|
|
- *
|
|
|
- * This is an internal method used mostly in tests.
|
|
|
- *
|
|
|
- * @param processor
|
|
|
- * @protected
|
|
|
- */
|
|
|
- static _setProcessor( processor ) {
|
|
|
- this._processor = processor;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|