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 32 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
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
*/
42 changes: 42 additions & 0 deletions src/tablecellproperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ 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.border.colors`),
* * the color palette for the cell background style field (`tableCellProperties.backgroundColors`).
*
* const tableConfig = {
* tableCellProperties: {
* border: {
oleq marked this conversation as resolved.
Show resolved Hide resolved
* colors: [
* {
* 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
*/
31 changes: 29 additions & 2 deletions src/tablecellproperties/tablecellpropertiesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ import {
getLocalizedColorErrorText,
getLocalizedLengthErrorText,
colorFieldValidator,
lengthFieldValidator
lengthFieldValidator,
defaultColors
} from '../ui/utils';
import {
getLocalizedColorOptions,
normalizeColorOptions
} from '@ckeditor/ckeditor5-ui/src/colorgrid/utils';
import { debounce } from 'lodash-es';

const DEFAULT_BORDER_STYLE = 'none';
Expand Down Expand Up @@ -53,6 +58,20 @@ export default class TableCellPropertiesUI extends Plugin {
return 'TableCellPropertiesUI';
}

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

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

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -120,7 +139,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.border.colors );
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
59 changes: 46 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: 'middle'
} );

/**
* 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-properties-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 @@ -483,15 +506,21 @@ 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', value => {
return value !== 'none';
} );

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 @@ -522,8 +551,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 @@ -532,7 +565,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 @@ -562,7 +595,7 @@ export default class TableCellPropertiesView extends View {

widthInput.set( {
label: t( 'Width' ),
class: 'ck-table-cell-properties-form__width',
class: 'ck-table-properties-form__width',
jodator marked this conversation as resolved.
Show resolved Hide resolved
} );

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

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

heightInput.view.bind( 'value' ).to( this, 'height' );
Expand Down
42 changes: 42 additions & 0 deletions src/tableproperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,45 @@ 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.border.colors`),
* * the color palette for the table background style field (`tableProperties.backgroundColors`).
*
* const tableConfig = {
* tableProperties: {
* border: {
* colors: [
oleq marked this conversation as resolved.
Show resolved Hide resolved
* {
* 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
*/
31 changes: 29 additions & 2 deletions src/tableproperties/tablepropertiesui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ import {
getLocalizedColorErrorText,
getLocalizedLengthErrorText,
colorFieldValidator,
lengthFieldValidator
lengthFieldValidator,
defaultColors,
} from '../ui/utils';
import {
getLocalizedColorOptions,
normalizeColorOptions
} from '@ckeditor/ckeditor5-ui/src/colorgrid/utils';
import { debounce } from 'lodash-es';

const DEFAULT_BORDER_STYLE = 'none';
Expand Down Expand Up @@ -52,6 +57,20 @@ export default class TablePropertiesUI extends Plugin {
return 'TablePropertiesUI';
}

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

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

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -119,7 +138,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.border.colors );
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