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

I/6106: Introduced color pickers in the table and table cell property forms #244

Merged
merged 41 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
42fc63c
Refactor setting borderColor in TableCellPropertiesView
panr Feb 10, 2020
e136f40
Merge branch 'master' into i/6106
oleq Feb 10, 2020
2d0595c
Code refactoring.
oleq Feb 10, 2020
7262d18
Fix initial value binding for color input
panr Feb 11, 2020
51fef8d
Move color input view to table
panr Feb 11, 2020
b8ec5e6
Add table cell properties config & add private helper to parse color …
panr Feb 11, 2020
9c9415a
Code refactoring.
oleq Feb 11, 2020
fe3e929
Merge branch 'master' into i/6106
oleq Feb 11, 2020
5ca1879
Docs, code refactoring.
oleq Feb 11, 2020
8c311ed
Added docs and tests for the ColorInputView.
oleq Feb 11, 2020
5ea17f6
Aligned TableCellProperties to the latest helpers\' API.
oleq Feb 11, 2020
22f69a5
Code refactoring: renamed CSS file.
oleq Feb 11, 2020
f3217b7
Docs: Improved TableColorConfig documentation.
oleq Feb 11, 2020
548766a
Docs: Improved docs of the TableColorConfig.
oleq Feb 11, 2020
40aa84b
Docs: Improved docs.
oleq Feb 11, 2020
7d7e783
Make removeColorButton firing an input event
panr Feb 12, 2020
d545935
Fix binding for borderColorInput.view #value
panr Feb 12, 2020
9379e37
Create color fileds in table properties from factory
panr Feb 12, 2020
7f6c442
Merge branch 'master' into i/6106
oleq Feb 12, 2020
9e5284d
Tests and code refactoring.
oleq Feb 12, 2020
3271108
Adjusted styles. Code refactoring in styles.
oleq Feb 12, 2020
0390493
Docs: Added more missing docs.
oleq Feb 12, 2020
dbf3d00
Docs: Fixed broken links.
oleq Feb 12, 2020
44287f9
Code refactoring.
oleq Feb 12, 2020
4b1be39
Add test for no-color preview in color input dropdown
panr Feb 12, 2020
2c59c9c
Add "ck-hidden" class binding for no-color preview
panr Feb 12, 2020
360ac5b
Add removeColorIcon
panr Feb 12, 2020
613daae
Docs: Extended ColorInputView docs.
oleq Feb 12, 2020
af8ed4d
Docs: Improved docs in various modules.
oleq Feb 12, 2020
ffd0455
Rename css classes for color input
panr Feb 12, 2020
63ba203
Merge branch 'master' into i/6106
panr Feb 12, 2020
338b78c
Extracted no color indicator styles from theme-lark.
oleq Feb 12, 2020
c95ca29
Update src/ui/utils.js
oleq Feb 12, 2020
dc06333
Code refactoring in class naming and styles.
oleq Feb 12, 2020
501edd4
Removed trailing commas in the manual test.
oleq Feb 12, 2020
f251e96
Tests: Code refactoring in ColorInputView tests.
oleq Feb 12, 2020
03d493b
Merge branch 'master' into i/6106
Reinmar Feb 12, 2020
dfebee2
Unified the config.table.tableProperties and tableCellProperties conf…
oleq Feb 13, 2020
c06e83a
Added missing entries in contexts.json.
oleq Feb 13, 2020
3bb62eb
Merge branch 'master' into i/6106
oleq Feb 13, 2020
aa200b3
Merge branch 'master' into i/6106
Reinmar Feb 13, 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
3 changes: 2 additions & 1 deletion lang/contexts.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Cell properties": "The label describing the form allowing to specify the properties of a selected table cell.",
"Border": "The label describing a group of border–related form fields (border style, color, etc.).",
"Style": "The label for the dropdown that allows configuring the border style of a table or a table cell.",
"Width": "The label for the input that allows configuring the border width of a table or a table cell.",
"Width": "The label for the input that allows configuring the width of a table or a table cell or the width of a border.",
"Height": "The label for the input that allows configuring the height of a table or a table cell.",
"Color": "The label for the input that allows configuring the border color of a table or a table cell.",
"Background": "The label for the input that allows configuring the background color of a table or a table cell.",
Expand Down Expand Up @@ -52,6 +52,7 @@
"Align table to the left": "The label used by assistive technologies describing a button that aligns the table to the left.",
"Center table": "The label used by assistive technologies describing a button that centers the table.",
"Align table to the right": "The label used by assistive technologies describing a button that aligns the table to the right.",
"Remove color": "The label used by a button next to the color palette in the color picker that removes the color (resets it to an empty value).",
"The color is invalid. Try \"#FF0000\" or \"rgb(255,0,0)\" or \"red\".": "The localized error string that can be displayed next to color (background, border) fields that have an invalid value",
"The value is invalid. Try \"10px\" or \"2em\" or simply \"2\".": "The localized error string that can be displayed next to length (padding, border width) fields that have an invalid value."
}
28 changes: 28 additions & 0 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,31 @@ export default class Table extends Plugin {
*
* @member {module:table/table~TableConfig} module:core/editor/editorconfig~EditorConfig#table
*/

/**
* An array of colors definitions (either strings or objects).
*
* const colors = [
* {
* color: 'hsl(0, 0%, 60%)',
* label: 'Grey'
* },
* 'hsl(0, 0%, 80%)',
* {
* color: 'hsl(0, 0%, 90%)',
* label: 'Light grey'
* },
* {
* color: 'hsl(0, 0%, 100%)',
* label: 'White',
* hasBorder: true
* },
* '#FF0000'
* ]
*
* Usually used as a configuration parameter, for instance in
* {@link module:table/table~TableConfig#tableProperties `config.table.tableProperties`}
* or {@link module:table/table~TableConfig#tableCellProperties `config.table.tableCellProperties`}.
*
* @typedef {Array.<String|Object>} module:table/table~TableColorConfig
*/
40 changes: 40 additions & 0 deletions src/tablecellproperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,43 @@ export default class TableCellProperties extends Plugin {
return [ TableCellPropertiesEditing, TableCellPropertiesUI ];
}
}

/**
* A configuration of the table cell properties user interface (balloon). It allows to define:
*
* * the color palette for the cell border color style field (`tableCellProperties.borderColors`),
* * the color palette for the cell background style field (`tableCellProperties.backgroundColors`).
*
* const tableConfig = {
* tableCellProperties: {
* borderColors: [
* {
* color: 'hsl(0, 0%, 90%)',
* label: 'Light grey'
* },
* // ...
* ],
* backgroundColors: [
* {
* color: 'hsl(120, 75%, 60%)',
* label: 'Green'
* },
* // ...
* ]
* }
* };
*
* **Note**: The configurations do not impact the data being loaded into the editor,
* i.e. they do not limit or filter the colors in the data. They are used only in the user interface
* allowing users to pick colors in a more convenient way.
*
* The default color palettes for the cell background and the cell border are the same
* ({@link module:table/ui/utils~defaultColors check out their content}).
*
* Both color palette configurations must follow the
* {@link module:table/table~TableColorConfig table color configuration format}.
*
* Read more about configuring the table feature in {@link module:table/table~TableConfig}.
*
* @member {Object} module:table/table~TableConfig#tableCellProperties
*/
27 changes: 26 additions & 1 deletion src/tablecellproperties/tablecellpropertiesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ import {
getBalloonCellPositionData,
getLocalizedColorErrorText,
getLocalizedLengthErrorText,
defaultColors,
lengthFieldValidator,
lineWidthFieldValidator,
repositionContextualBalloon
} from '../ui/utils';
import {
getLocalizedColorOptions,
normalizeColorOptions
} from '@ckeditor/ckeditor5-ui/src/colorgrid/utils';
import { debounce } from 'lodash-es';

const ERROR_TEXT_TIMEOUT = 500;
Expand Down Expand Up @@ -51,6 +56,18 @@ export default class TableCellPropertiesUI extends Plugin {
return 'TableCellPropertiesUI';
}

/**
* @inheritDoc
*/
constructor( editor ) {
super( editor );

editor.config.define( 'table.tableCellProperties', {
borderColors: defaultColors,
backgroundColors: defaultColors
} );
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -118,7 +135,15 @@ export default class TableCellPropertiesUI extends Plugin {
_createPropertiesView() {
const editor = this.editor;
const viewDocument = editor.editing.view.document;
const view = new TableCellPropertiesView( editor.locale );
const config = editor.config.get( 'table.tableCellProperties' );
const borderColorsConfig = normalizeColorOptions( config.borderColors );
const localizedBorderColors = getLocalizedColorOptions( editor.locale, borderColorsConfig );
const backgroundColorsConfig = normalizeColorOptions( config.backgroundColors );
const localizedBackgroundColors = getLocalizedColorOptions( editor.locale, backgroundColorsConfig );
const view = new TableCellPropertiesView( editor.locale, {
borderColors: localizedBorderColors,
backgroundColors: localizedBackgroundColors
} );
const t = editor.t;

// Render the view so its #element is available for the clickOutsideHandler.
Expand Down
58 changes: 45 additions & 13 deletions src/tablecellproperties/ui/tablecellpropertiesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import LabelView from '@ckeditor/ckeditor5-ui/src/label/labelview';
import { addListToDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import { fillToolbar, getBorderStyleDefinitions, getBorderStyleLabels } from '../../ui/utils';
import {
fillToolbar,
getBorderStyleDefinitions,
getBorderStyleLabels,
getLabeledColorInputCreator,
} from '../../ui/utils';
import FormRowView from '../../ui/formrowview';
import FormHeaderView from '../../ui/formheaderview';

Expand Down Expand Up @@ -57,9 +62,16 @@ const ALIGNMENT_ICONS = {
*/
export default class TableCellPropertiesView extends View {
/**
* @inheritDoc
* @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
* @param {Object} options Additional configuration of the view.
* @param {module:table/table~TableColorConfig} options.borderColors A configuration of the border
* color palette used by the
* {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView#borderColorInput}.
* @param {module:table/table~TableColorConfig} options.backgroundColors A configuration of the background
* color palette used by the
* {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView#backgroundInput}.
*/
constructor( locale ) {
constructor( locale, options ) {
super( locale );

this.set( {
Expand Down Expand Up @@ -145,6 +157,13 @@ export default class TableCellPropertiesView extends View {
verticalAlignment: ''
} );

/**
* Options passed to the view. See {@link #constructor} to learn more.
*
* @member {Object}
*/
this.options = options;

const { borderStyleDropdown, borderWidthInput, borderColorInput, borderRowLabel } = this._createBorderFields();
const { widthInput, operatorLabel, heightInput, dimensionsLabel } = this._createDimensionFields();
const { horizontalAlignmentToolbar, verticalAlignmentToolbar, alignmentLabel } = this._createAlignmentFields();
Expand Down Expand Up @@ -193,15 +212,15 @@ export default class TableCellPropertiesView extends View {
* An input that allows specifying the color of the table cell border.
*
* @readonly
* @member {module:ui/inputtext/inputtextview~InputTextView}
* @member {module:table/ui/colorinputview~ColorInputView}
*/
this.borderColorInput = borderColorInput;

/**
* An input that allows specifying the table cell background color.
*
* @readonly
* @member {module:ui/inputtext/inputtextview~InputTextView}
* @member {module:table/ui/colorinputview~ColorInputView}
*/
this.backgroundInput = this._createBackgroundField();

Expand Down Expand Up @@ -329,7 +348,7 @@ export default class TableCellPropertiesView extends View {
operatorLabel,
heightInput
],
class: 'ck-table-cell-properties-form__dimensions-row'
class: 'ck-table-form__dimensions-row'
} ),
// Padding row.
new FormRowView( locale, {
Expand Down Expand Up @@ -431,6 +450,10 @@ export default class TableCellPropertiesView extends View {
* @returns {Object.<String,module:ui/view~View>}
*/
_createBorderFields() {
const colorInputCreator = getLabeledColorInputCreator( {
colorConfig: this.options.borderColors,
columns: 5
} );
const locale = this.locale;
const t = this.t;

Expand Down Expand Up @@ -481,13 +504,18 @@ export default class TableCellPropertiesView extends View {

// -- Color ---------------------------------------------------

const borderColorInput = new LabeledView( locale, createLabeledInputText );
borderColorInput.label = t( 'Color' );
const borderColorInput = new LabeledView( locale, colorInputCreator );

borderColorInput.set( {
label: t( 'Color' ),
class: 'ck-table-form__border-color',
} );

borderColorInput.view.bind( 'value' ).to( this, 'borderColor' );
borderColorInput.bind( 'isEnabled' ).to( this, 'borderStyle', isBorderStyleSet );

borderColorInput.view.on( 'input', () => {
this.borderColor = borderColorInput.view.element.value;
this.borderColor = borderColorInput.view.value;
} );

// Reset the border color and width fields when style is "none".
Expand Down Expand Up @@ -518,8 +546,12 @@ export default class TableCellPropertiesView extends View {
_createBackgroundField() {
const locale = this.locale;
const t = this.t;
const colorInputCreator = getLabeledColorInputCreator( {
colorConfig: this.options.backgroundColors,
columns: 5
} );

const backgroundInput = new LabeledView( locale, createLabeledInputText );
const backgroundInput = new LabeledView( locale, colorInputCreator );

backgroundInput.set( {
label: t( 'Background' ),
Expand All @@ -528,7 +560,7 @@ export default class TableCellPropertiesView extends View {

backgroundInput.view.bind( 'value' ).to( this, 'backgroundColor' );
backgroundInput.view.on( 'input', () => {
this.backgroundColor = backgroundInput.view.element.value;
this.backgroundColor = backgroundInput.view.value;
} );

return backgroundInput;
Expand Down Expand Up @@ -558,7 +590,7 @@ export default class TableCellPropertiesView extends View {

widthInput.set( {
label: t( 'Width' ),
class: 'ck-table-cell-properties-form__width',
class: 'ck-table-form__dimensions-row__width',
} );

widthInput.view.bind( 'value' ).to( this, 'width' );
Expand Down Expand Up @@ -587,7 +619,7 @@ export default class TableCellPropertiesView extends View {

heightInput.set( {
label: t( 'Height' ),
class: 'ck-table-cell-properties-form__height',
class: 'ck-table-form__dimensions-row__height',
} );

heightInput.view.bind( 'value' ).to( this, 'height' );
Expand Down
40 changes: 40 additions & 0 deletions src/tableproperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,43 @@ export default class TableProperties extends Plugin {
return [ TablePropertiesEditing, TablePropertiesUI ];
}
}

/**
* A configuration of the table properties user interface (balloon). It allows to define:
*
* * the color palette for the table border color style field (`tableProperties.borderColors`),
* * the color palette for the table background style field (`tableProperties.backgroundColors`).
*
* const tableConfig = {
* tableProperties: {
* borderColors: [
* {
* color: 'hsl(0, 0%, 90%)',
* label: 'Light grey'
* },
* // ...
* ],
* backgroundColors: [
* {
* color: 'hsl(120, 75%, 60%)',
* label: 'Green'
* },
* // ...
* ]
* }
* };
*
* **Note**: The configurations do not impact the data being loaded into the editor,
* i.e. they do not limit or filter the colors in the data. They are used only in the user interface
* allowing users to pick colors in a more convenient way.
*
* The default color palettes for the table background and the table border are the same
* ({@link module:table/ui/utils~defaultColors check out their content}).
*
* Both color palette configurations must follow the
* {@link module:table/table~TableColorConfig table color configuration format}.
*
* Read more about configuring the table feature in {@link module:table/table~TableConfig}.
*
* @member {Object} module:table/table~TableConfig#tableProperties
*/
29 changes: 27 additions & 2 deletions src/tableproperties/tablepropertiesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import {
getLocalizedLengthErrorText,
lengthFieldValidator,
lineWidthFieldValidator,
repositionContextualBalloon
repositionContextualBalloon,
defaultColors,
} from '../ui/utils';
import {
getLocalizedColorOptions,
normalizeColorOptions
} from '@ckeditor/ckeditor5-ui/src/colorgrid/utils';
import { debounce } from 'lodash-es';

const ERROR_TEXT_TIMEOUT = 500;
Expand Down Expand Up @@ -51,6 +56,18 @@ export default class TablePropertiesUI extends Plugin {
return 'TablePropertiesUI';
}

/**
* @inheritDoc
*/
constructor( editor ) {
super( editor );

editor.config.define( 'table.tableProperties', {
borderColors: defaultColors,
backgroundColors: defaultColors
} );
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -118,7 +135,15 @@ export default class TablePropertiesUI extends Plugin {
_createPropertiesView() {
const editor = this.editor;
const viewDocument = editor.editing.view.document;
const view = new TablePropertiesView( editor.locale );
const config = editor.config.get( 'table.tableProperties' );
const borderColorsConfig = normalizeColorOptions( config.borderColors );
const localizedBorderColors = getLocalizedColorOptions( editor.locale, borderColorsConfig );
const backgroundColorsConfig = normalizeColorOptions( config.backgroundColors );
const localizedBackgroundColors = getLocalizedColorOptions( editor.locale, backgroundColorsConfig );
const view = new TablePropertiesView( editor.locale, {
borderColors: localizedBorderColors,
backgroundColors: localizedBackgroundColors
} );
const t = editor.t;

// Render the view so its #element is available for the clickOutsideHandler.
Expand Down
Loading