Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

I/3287: Styles normalization (part of table styles) #1807

Merged
merged 148 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
5403671
Add style normalization stub for borders.
jodator Sep 25, 2019
34c5687
Extract stylenormalizer.js.
jodator Sep 26, 2019
1e4d5aa
Define StyleProxy methods.
jodator Sep 26, 2019
893519e
Rewrite Element class to use Styles normalization class.
jodator Sep 26, 2019
6396311
Add style retrieval for model storage.
jodator Sep 26, 2019
d65236e
Add rule should accept object.
jodator Sep 26, 2019
eb9ff1d
Always add trailing semicolon to styles output.
jodator Sep 26, 2019
54b24ad
Organize tests for styles normalizer.
jodator Sep 26, 2019
8a65d99
Add support for border-color shorthand.
jodator Sep 26, 2019
3a9ee3e
Add support for border-style shorthand.
jodator Sep 26, 2019
dbd70bf
Add support for border-width shorthand.
jodator Sep 26, 2019
69167b9
Properly merge values in styles normalizer.
jodator Sep 26, 2019
b8138a6
Make tests compact.
jodator Sep 26, 2019
ca4bda8
Add support for margin shorthand.
jodator Sep 26, 2019
029efbd
Add support for padding shorthand.
jodator Sep 26, 2019
f7420b3
Add support for margin-* and padding-* shorthands.
jodator Sep 26, 2019
a78136c
Add margin output.
jodator Sep 27, 2019
28a6440
Add tests for margin style output.
jodator Sep 27, 2019
008c90d
Add get style names logic.
jodator Sep 27, 2019
a16afe6
Refactor Styles class to more instance based.
jodator Sep 27, 2019
5ac8b42
Add direct properties support.
jodator Sep 30, 2019
4cc9f15
Refactor internal parsing to object.
jodator Sep 30, 2019
7476ed0
Fix tests.
jodator Sep 30, 2019
de8f1bc
Fix output of undefined value for margin.
jodator Sep 30, 2019
0b710f1
Consume shorthand styles together with their counterpart properties.
jodator Sep 30, 2019
2eb54c2
Remove .only from tests.
jodator Sep 30, 2019
a3cfc0c
Add support for background-color in styles normalization.
jodator Oct 1, 2019
2cd6cb5
Refactor styles method names.
jodator Oct 1, 2019
197e99a
Refactor inline style parsing to be more declarative.
jodator Oct 2, 2019
45cdfd1
Remove private _parseStyle() method.
jodator Oct 2, 2019
7da4282
Add getNormalizedStyle to view/element.
jodator Oct 2, 2019
b88f747
Check how to stringify normalized model value.
jodator Oct 2, 2019
1bc367e
Change border normalized version.
jodator Oct 2, 2019
e2b793f
Remove unneeded styles normalizations.
jodator Oct 2, 2019
293b089
Fix tests.
jodator Oct 2, 2019
98df9e4
Stub proper styles signifying from normalized object.
jodator Oct 3, 2019
e0ee293
Refactor styles outputting.
jodator Oct 3, 2019
a380904
Add tests for styles class methods.
jodator Oct 3, 2019
50df1cb
Add more tests to the styles class.
jodator Oct 3, 2019
edf5e6b
Clarify naming of internal style normalization mechanisms.
jodator Oct 3, 2019
4acd303
Remove unused code.
jodator Oct 7, 2019
76edc1c
Add tests for background color.
jodator Oct 7, 2019
d95959b
Add more background shorthand values parsing.
jodator Oct 7, 2019
3455103
Add more tests for top-right-bottom-left shorthands.
jodator Oct 7, 2019
15de90c
Simplify code.
jodator Oct 7, 2019
26a616d
Remove unused code, add more tests, cleanup API.
jodator Oct 7, 2019
52dbcfe
View element clone should use normalized object.
jodator Oct 7, 2019
3227d86
Add tests for parsing top right bottom left empty value.
jodator Oct 7, 2019
68a2ddd
Add border-top,right,bottom,left as a default border output.
jodator Oct 8, 2019
5c3957d
Add padding reducer.
jodator Oct 8, 2019
ba78816
Add test for inline border position style.
jodator Oct 9, 2019
cbb220c
Convert borders to three separate values.
jodator Oct 14, 2019
986eba9
Create styles converter singleton.
jodator Oct 14, 2019
2760f89
Refactor styles extracting to events.
jodator Oct 14, 2019
8f08fda
Refactor styles reducing to events.
jodator Oct 14, 2019
0404fcf
Refactor styles extracting to events.
jodator Oct 15, 2019
365af42
Organize styles normalization to classes.
jodator Oct 15, 2019
0b9cb11
Extract BorderStyles normalizer.
jodator Oct 15, 2019
cec8026
Extract MarginStyles normalizer.
jodator Oct 15, 2019
98874d4
Extract PaddingStyles normalizer.
jodator Oct 15, 2019
e2d44b9
Extract BackgroundStyles normalizer.
jodator Oct 15, 2019
7eec7b2
Extract particular styles tests to own files.
jodator Oct 15, 2019
dcf0f1c
Parse styles independently.
jodator Oct 15, 2019
b63d527
Generalize tests for Styles class.
jodator Oct 15, 2019
43ea44e
Fix border styles normalization code. Add tests for utils methods.
jodator Oct 15, 2019
80f1a6b
Add more styles utils tests.
jodator Oct 15, 2019
88f83b5
Merge branch 'master' into i/3287
jodator Oct 16, 2019
4b7e26e
Fix isLength and isColor regexps.
jodator Oct 16, 2019
183b932
Refactor is*() util methods.
jodator Oct 16, 2019
ac84305
Change how hasStyle() is checked due to table border converter issues.
jodator Oct 22, 2019
2382e5f
Fix isColor RegExp.
jodator Oct 22, 2019
bbc931c
Make styles.hasProperty() check to be in line with styles.getProperty().
jodator Oct 22, 2019
64820f6
Merge branch 'master' into i/3287
jodator Oct 23, 2019
f7d0bec
Fix borders styles extracting.
jodator Oct 23, 2019
1e13aff
Merge branch 'master' into i/3287
jodator Oct 28, 2019
138737a
Hide style converter singleton from the watchdog.
jodator Oct 28, 2019
f73e754
Fix StyleConverter docs.
jodator Oct 28, 2019
544a9b1
Merge branch 'master' into i/3287
Reinmar Nov 18, 2019
cfa3460
Fix language in the styles doc.
jodator Nov 20, 2019
649f354
Merge branch 'master' into i/3287
jodator Jan 7, 2020
c2c6364
Merge remote-tracking branch 'origin/i/3287' into i/3287
jodator Jan 7, 2020
f268ecb
Rename StylesConverter to StyleProcessor.
jodator Jan 9, 2020
e0797de
Rename stylesConverter to stylesProcessor.
jodator Jan 9, 2020
0396b08
Remove export.
jodator Jan 9, 2020
09b3c6f
Change converter property descriptor to getter.
jodator Jan 9, 2020
dd85fc5
Make default style processor as a static class property.
jodator Jan 9, 2020
6371ec4
Move Styles class as a default export of view/styles.
jodator Jan 9, 2020
f6f1bba
Use method to attach border styles processor.
jodator Jan 9, 2020
f32690c
Use method to attach margin styles processor.
jodator Jan 9, 2020
8ca987e
Use method to attach padding styles processor.
jodator Jan 9, 2020
76d59ec
Use method to attach background styles processor.
jodator Jan 9, 2020
cb7ea99
Remove default processors from styles file.
jodator Jan 9, 2020
2073676
Rename style converter to processor.
jodator Jan 9, 2020
baeab18
Remove .skip from slow tests.
jodator Jan 10, 2020
e2dfe59
Introduce one-time callbacks registering for styles converter.
jodator Jan 10, 2020
727d143
Remove consuming shorthand style names while consuming longhand and v…
jodator Jan 13, 2020
9712d8d
Fix jsdoc for view element's _styles property.
jodator Jan 13, 2020
e19120c
Fix jsdoc of view/Element.getStyle().
jodator Jan 13, 2020
4c8e640
Remove sorting from Styles._getStylesEntries().
jodator Jan 13, 2020
2dadcd0
Rename styleProcessor to _styleProcessor in Styles.
jodator Jan 13, 2020
38cbc5a
Use map to store style converters.
jodator Jan 13, 2020
ef5083d
Simplify extractors.
jodator Jan 13, 2020
b6d03a3
Normalizer should only work on value.
jodator Jan 13, 2020
1a1b8a3
Reducer should only work on value.
jodator Jan 13, 2020
4c94d16
Rename Styles to StylesMap.
jodator Jan 14, 2020
3088102
Update docs of the Styles.getNormalized() method.
jodator Jan 14, 2020
45ad617
Add docs for the Element.getNormalizedStyle() method.
jodator Jan 14, 2020
56df0b4
Rename StylesMap.setStyle() to setTo().
jodator Jan 14, 2020
adc0f8f
Add StylesMap.hasProperty() documentation.
jodator Jan 14, 2020
87bc5e5
Fix StylesMap.hasProperty() tests.
jodator Jan 14, 2020
4ea5df6
Rename StylesMap.hasProperty() to has().
jodator Jan 14, 2020
8743d15
Rename StylesMap.insertProperty() to set().
jodator Jan 14, 2020
66e3cd1
Update StylesMap.set() docs.
jodator Jan 14, 2020
4fc65bd
Rename StylesMap.removeProperty() to remove().
jodator Jan 14, 2020
54c2a5a
Cross link view writer, element ans styles map docs.
jodator Jan 14, 2020
c33b187
StylesMap will return string when empty.
jodator Jan 14, 2020
41a55c6
Add StylesMap#isEmpty getter for fast checking if styles map has any …
jodator Jan 14, 2020
151c5c1
Rename StylesMap.getInlineProperty() to getAsString() and improve docs.
jodator Jan 14, 2020
affc228
Add docs for StylesMap._styles private property.
jodator Jan 14, 2020
611daa6
Reorder the static methods and getters of StylesMap.
jodator Jan 14, 2020
7fb72d7
Add docs to StylesProcessor.
jodator Jan 14, 2020
400305f
Simplify StylesConverter.getReducedForm() usage.
jodator Jan 14, 2020
b680fe2
Revert docs for setting object style.
jodator Jan 14, 2020
065dfcc
StylesMap.getAsString() will return undefined for missing properties.
jodator Jan 15, 2020
91fcf56
Add docs to StylesProcessor.
jodator Jan 15, 2020
6535fc2
Add docs to StylesMap and styles utils.
jodator Jan 15, 2020
a70c8ff
Refactor and add docs for styles processing rules.
jodator Jan 15, 2020
61eac43
Add missing link to line style CSS value.
jodator Jan 15, 2020
e4b3846
Add documentation about normalized styles values.
jodator Jan 15, 2020
3699473
Remove obsolete docs.
jodator Jan 15, 2020
2836d24
Add test for view/Document.addStyleProcessorRules().
jodator Jan 15, 2020
fef22a7
Add tests for view/Element.getNormalizedStyle().
jodator Jan 15, 2020
a391dbc
Add StylesMap._styleProcessor static getter tests.
jodator Jan 15, 2020
79b013d
Match test file names to source file names.
jodator Jan 15, 2020
391f960
Add tests for other padding values (increase coverage).
jodator Jan 15, 2020
87570d8
Add tests for border styles processing.
jodator Jan 15, 2020
c1f54be
Removing empty statement.
jodator Jan 15, 2020
b145b3b
Bump year in the PR files.
jodator Jan 16, 2020
e405be5
Fix docs links.
jodator Jan 16, 2020
546fd5b
Docs, docs, docs.
Reinmar Jan 16, 2020
8cd6ca9
Docs, docs, docs.
Reinmar Jan 16, 2020
a636db8
Docs, docs, docs.
Reinmar Jan 16, 2020
9d8df6d
Docs, docs, docs.
Reinmar Jan 16, 2020
709bbb2
Docs, docs, docs.
Reinmar Jan 16, 2020
589fb34
Docs, docs, docs.
Reinmar Jan 16, 2020
254203f
Introduce smart view style consuming.
jodator Jan 17, 2020
b8bb94c
Fix link in docs.
jodator Jan 20, 2020
13e5f7f
Docs.
Reinmar Jan 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default class DowncastHelpers extends ConversionHelpers {
* view: modelAttributeValue => ( { key: 'class', value: 'styled-' + modelAttributeValue } )
* } );
*
* *Note:* Downcasting to a style property requires providing `value` as an object:
* **Note**: Downcasting to a style property requires providing `value` as an object:
*
* editor.conversion.for( 'downcast' ).attributeToAttribute( {
* model: 'lineHeight',
Expand Down
13 changes: 13 additions & 0 deletions src/conversion/viewconsumable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { isArray } from 'lodash-es';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import StylesMap from '../view/stylesmap';

/**
* Class used for handling consumption of view {@link module:engine/view/element~Element elements},
Expand Down Expand Up @@ -507,6 +508,12 @@ class ViewElementConsumables {
}

consumables.set( name, true );

if ( type === 'styles' ) {
for ( const alsoName of StylesMap.getRelatedStyles( name ) ) {
consumables.set( alsoName, true );
}
}
}
}

Expand Down Expand Up @@ -568,6 +575,12 @@ class ViewElementConsumables {
this._consume( consumableName, [ ...this._consumables[ consumableName ].keys() ] );
} else {
consumables.set( name, false );

if ( type == 'styles' ) {
for ( const toConsume of StylesMap.getRelatedStyles( name ) ) {
consumables.set( toConsume, false );
}
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/view/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DocumentSelection from './documentselection';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
import StylesMap from './stylesmap';

// @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );

Expand Down Expand Up @@ -160,6 +161,22 @@ export default class Document {
this.stopListening();
}

/**
* Adds a style processor normalization rules.
*
* The available style processors:
*
* * background: {@link module:engine/view/styles/background~addBackgroundRules}
* * border: {@link module:engine/view/styles/border~addBorderRules}
* * margin: {@link module:engine/view/styles/margin~addMarginRules}
* * padding: {@link module:engine/view/styles/padding~addPaddingRules}
*
* @param {Function} callback
*/
addStyleProcessorRules( callback ) {
callback( StylesMap._styleProcessor );
}

/**
* Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
*
Expand Down
10 changes: 9 additions & 1 deletion src/view/downcastwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ export default class DowncastWriter {
* position: 'fixed'
* }, element );
*
* **Note**: The passed style can be normalized if
* {@link module:engine/view/document~Document#addStyleProcessorRules a particular style processor rule is enabled}.
* See {@link module:engine/view/stylesmap~StylesMap#set `StylesMap#set()`} for details.
*
* @param {String|Object} property Property name or object with key - value pairs.
* @param {String} [value] Value to set. This parameter is ignored if object is provided as the first parameter.
* @param {module:engine/view/element~Element} element Element to set styles on.
Expand All @@ -339,9 +343,13 @@ export default class DowncastWriter {
/**
* Removes specified style from the element.
*
* writer.removeStyle( 'color', element ); // Removes 'color' style.
* writer.removeStyle( 'color', element ); // Removes 'color' style.
* writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
*
* **Note**: This method can work with normalized style names if
* {@link module:engine/view/document~Document#addStyleProcessorRules a particular style processor rule is enabled}.
* See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
*
* @param {Array.<String>|String} property
* @param {module:engine/view/element~Element} element
*/
Expand Down
Loading