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

Commit

Permalink
Merge tag 'v1.0.0-beta.1' into stable
Browse files Browse the repository at this point in the history
Release: v1.0.0-beta.1.
  • Loading branch information
Reinmar committed Mar 15, 2018
2 parents 05ce09f + 187f8db commit 5eb92af
Show file tree
Hide file tree
Showing 15 changed files with 711 additions and 717 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down
26 changes: 15 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
sudo: required
dist: trusty
addons:
firefox: "latest"
apt:
sources:
- google-chrome
- google-chrome
packages:
- google-chrome-stable
- google-chrome-stable
language: node_js
node_js:
- "6"
- '6'
cache:
- node_modules
- node_modules
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
install:
- npm install @ckeditor/ckeditor5-dev-tests
- ckeditor5-dev-tests-install-dependencies
- npm install @ckeditor/ckeditor5-dev-tests
- ckeditor5-dev-tests-install-dependencies
script:
- ckeditor5-dev-tests-travis
- ckeditor5-dev-tests-travis
after_success:
- codeclimate-test-reporter < coverage/lcov.info
- ckeditor5-dev-tests-save-revision
- ckeditor5-dev-tests-save-revision
env:
global:
- secure: HvkSDjAVlYflmRnzq4WLYDccK+Ka44NfA7RVnycYmTzpviyjYSt1nSx6bMa/tmWbK+TCzjj6sA/B88Wn1udYe7K6SxZfz4zW1E3kPTgoT3mGuvhpaGfx4Fhbr8N1tXAJ/LCvwFbF5D5tMjMQs1CwCIirtBT8i5f6kqdbDAntA7xSq789yZTdAwgtqEVCOFyNHVKoCQdGmy+7u5rdRHFdTVWcO5k7m6qGeG0L7BOGRQrC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22TNwGaqwmYAzHrpqYf/FViUlGmJCUuJfC9/EWm3fF09o2BqyDu7ZTk=
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
=========

## [1.0.0-beta.1](https://github.com/ckeditor/ckeditor5-widget/compare/v1.0.0-alpha.2...v1.0.0-beta.1) (2018-03-15)

### Other changes

* Aligned feature class naming to the new scheme. ([23991a4](https://github.com/ckeditor/ckeditor5-widget/commit/23991a4))
* Migrated package styles to PostCSS. Moved visual styles to `@ckeditor/ckeditor5-theme-lark` (see [ckeditor/ckeditor5-ui#144](https://github.com/ckeditor/ckeditor5-ui/issues/144)). ([857d6d4](https://github.com/ckeditor/ckeditor5-widget/commit/857d6d4))
* Switched to handling deletion around widgets by using the `delete` event instead of listening directly on key events. Closes [#29](https://github.com/ckeditor/ckeditor5-widget/issues/29). ([ee6cc95](https://github.com/ckeditor/ckeditor5-widget/commit/ee6cc95))


## [1.0.0-alpha.2](https://github.com/ckeditor/ckeditor5-widget/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2017-11-14)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Software License Agreement
==========================

**CKEditor 5 widget API**https://github.com/ckeditor/ckeditor5-image <br>
Copyright (c) 2003-2017, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
Copyright (c) 2003-2018, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.

Licensed under the terms of any of the following licenses at your choice:

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ CKEditor 5 widget API
[![Join the chat at https://gitter.im/ckeditor/ckeditor5](https://badges.gitter.im/ckeditor/ckeditor5.svg)](https://gitter.im/ckeditor/ckeditor5?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-widget.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-widget)
[![Build Status](https://travis-ci.org/ckeditor/ckeditor5-widget.svg)](https://travis-ci.org/ckeditor/ckeditor5-widget)
[![Test Coverage](https://codeclimate.com/github/ckeditor/ckeditor5-widget/badges/coverage.svg)](https://codeclimate.com/github/ckeditor/ckeditor5-widget/coverage)
[![BrowserStack Status](https://www.browserstack.com/automate/badge.svg?badge_key=d3hvenZqQVZERFQ5d09FWXdyT0ozVXhLaVltRFRjTTUyZGpvQWNmWVhUUT0tLUZqNlJ1YWRUd0RvdEVOaEptM1B2Q0E9PQ==--c9d3dee40b9b4471ff3fb516d9ecf8d09292c7e0)](https://www.browserstack.com/automate/public-build/d3hvenZqQVZERFQ5d09FWXdyT0ozVXhLaVltRFRjTTUyZGpvQWNmWVhUUT0tLUZqNlJ1YWRUd0RvdEVOaEptM1B2Q0E9PQ==--c9d3dee40b9b4471ff3fb516d9ecf8d09292c7e0)
[![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5-widget/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5-widget?branch=master)
<br>
[![Dependency Status](https://david-dm.org/ckeditor/ckeditor5-widget/status.svg)](https://david-dm.org/ckeditor/ckeditor5-widget)
[![devDependency Status](https://david-dm.org/ckeditor/ckeditor5-widget/dev-status.svg)](https://david-dm.org/ckeditor/ckeditor5-widget?type=dev)

Expand Down
2 changes: 1 addition & 1 deletion docs/api/widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Browse the API documentation of this package by using the module tree on the lef
<info-box>
The widget API is proposed in a very different way than it was in CKEditor 4. It is just a set of utilities that allow you to implement typical object-like entities. Most of the work actually happens in the {@link api/engine engine} and this API's role is only to properly conduct the engine.

Therefore, this is just one of the ways how widgets can be proposed. This API can be expected to change (grow) and for now, the only available documentation is in the {@link module:image/image/imageengine~ImageEngine}'s code (which is the only widget API consumer at this stage).
Therefore, this is just one of the ways how widgets can be proposed. This API can be expected to change (grow) and for now, the only available documentation is in the {@link module:image/image/imageediting~ImageEditing}'s code (which is the only widget API consumer at this stage).
</info-box>

## Installation
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"name": "@ckeditor/ckeditor5-widget",
"version": "1.0.0-alpha.2",
"version": "1.0.0-beta.1",
"description": "Widget API for CKEditor 5.",
"keywords": [
"ckeditor5",
"ckeditor5-lib"
],
"dependencies": {
"@ckeditor/ckeditor5-core": "^1.0.0-alpha.2",
"@ckeditor/ckeditor5-engine": "^1.0.0-alpha.2",
"@ckeditor/ckeditor5-utils": "^1.0.0-alpha.2",
"@ckeditor/ckeditor5-theme-lark": "^1.0.0-alpha.2"
"@ckeditor/ckeditor5-core": "^1.0.0-beta.1",
"@ckeditor/ckeditor5-engine": "^1.0.0-beta.1",
"@ckeditor/ckeditor5-utils": "^1.0.0-beta.1",
"@ckeditor/ckeditor5-theme-lark": "^1.0.0-beta.1"
},
"devDependencies": {
"eslint": "^4.8.0",
"eslint-config-ckeditor5": "^1.0.6",
"@ckeditor/ckeditor5-typing": "^1.0.0-beta.1",
"eslint": "^4.15.0",
"eslint-config-ckeditor5": "^1.0.7",
"husky": "^0.14.3",
"lint-staged": "^4.2.3"
"lint-staged": "^6.0.0"
},
"engines": {
"node": ">=6.0.0",
Expand Down
43 changes: 25 additions & 18 deletions src/highlightstack.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand All @@ -11,12 +11,14 @@ import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
import mix from '@ckeditor/ckeditor5-utils/src/mix';

/**
* Class used to handle correct order of
* {@link module:engine/conversion/buildmodelconverter~ModelConverterBuilder#toHighlight highlights} on
* elements. When different highlights are applied to same element correct order should be preserved:
* Class used to handle correct order of highlights on elements.
*
* When different highlights are applied to same element correct order should be preserved:
*
* * highlight with highest priority should be applied,
* * if two highlights have same priority - sort by CSS class provided in
* {@link module:engine/conversion/model-to-view-converters~HighlightDescriptor}.
* {@link module:engine/conversion/downcast-converters~HighlightDescriptor}.
*
* This way, highlight will be applied with the same rules it is applied on texts.
*/
export default class HighlightStack {
Expand All @@ -31,9 +33,10 @@ export default class HighlightStack {
* Adds highlight descriptor to the stack.
*
* @fires change:top
* @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor
* @param {module:engine/conversion/downcast-converters~HighlightDescriptor} descriptor
* @param {module:engine/view/writer~Writer} writer
*/
add( descriptor ) {
add( descriptor, writer ) {
const stack = this._stack;

// Save top descriptor and insert new one. If top is changed - fire event.
Expand All @@ -45,7 +48,8 @@ export default class HighlightStack {
if ( oldTop !== newTop && !compareDescriptors( oldTop, newTop ) ) {
this.fire( 'change:top', {
oldDescriptor: oldTop,
newDescriptor: newTop
newDescriptor: newTop,
writer
} );
}
}
Expand All @@ -55,8 +59,9 @@ export default class HighlightStack {
*
* @fires change:top
* @param {String} id Id of the descriptor to remove.
* @param {module:engine/view/writer~Writer} writer
*/
remove( id ) {
remove( id, writer ) {
const stack = this._stack;

const oldTop = stack[ 0 ];
Expand All @@ -67,7 +72,8 @@ export default class HighlightStack {
if ( oldTop !== newTop && !compareDescriptors( oldTop, newTop ) ) {
this.fire( 'change:top', {
oldDescriptor: oldTop,
newDescriptor: newTop
newDescriptor: newTop,
writer
} );
}
}
Expand All @@ -77,7 +83,7 @@ export default class HighlightStack {
* descriptor with same id is already present.
*
* @private
* @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor
* @param {module:engine/conversion/downcast-converters~HighlightDescriptor} descriptor
*/
_insertDescriptor( descriptor ) {
const stack = this._stack;
Expand Down Expand Up @@ -125,17 +131,17 @@ mix( HighlightStack, EmitterMixin );

// Compares two descriptors by checking their priority and class list.
//
// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} a
// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} b
// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} a
// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} b
// @returns {Boolean} Returns true if both descriptors are defined and have same priority and classes.
function compareDescriptors( a, b ) {
return a && b && a.priority == b.priority && classesToString( a.class ) == classesToString( b.class );
}

// Checks whenever first descriptor should be placed in the stack before second one.
//
// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} a
// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} b
// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} a
// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} b
// @returns {Boolean}
function shouldABeBeforeB( a, b ) {
if ( a.priority > b.priority ) {
Expand All @@ -148,7 +154,7 @@ function shouldABeBeforeB( a, b ) {
return classesToString( a.class ) > classesToString( b.class );
}

// Converts CSS classes passed with {@link module:engine/conversion/model-to-view-converters~HighlightDescriptor} to
// Converts CSS classes passed with {@link module:engine/conversion/downcast-converters~HighlightDescriptor} to
// sorted string.
//
// @param {String|Array<String>} descriptor
Expand All @@ -162,8 +168,9 @@ function classesToString( classes ) {
*
* @event change:top
* @param {Object} data Additional information about the change.
* @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} [data.newDescriptor] New highlight
* @param {module:engine/conversion/downcast-converters~HighlightDescriptor} [data.newDescriptor] New highlight
* descriptor. It will be `undefined` when last descriptor is removed from the stack.
* @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} [data.oldDescriptor] Old highlight
* @param {module:engine/conversion/downcast-converters~HighlightDescriptor} [data.oldDescriptor] Old highlight
* descriptor. It will be `undefined` when first descriptor is added to the stack.
* @param {module:engine/view/writer~Writer} writer View writer that can be used to modify element.
*/
46 changes: 25 additions & 21 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

Expand Down Expand Up @@ -45,25 +45,27 @@ export function isWidget( element ) {
* * implements `addHighlight` and `removeHighlight` custom properties to handle view highlight on widgets.
*
* @param {module:engine/view/element~Element} element
* @param {module:engine/view/writer~Writer} writer
* @param {Object} [options={}]
* @param {String|Function} [options.label] Element's label provided to {@link ~setLabel} function. It can be passed as
* a plain string or a function returning a string.
* @returns {module:engine/view/element~Element} Returns same element.
*/
export function toWidget( element, options = {} ) {
element.setAttribute( 'contenteditable', 'false' );
export function toWidget( element, writer, options = {} ) {
writer.setAttribute( 'contenteditable', 'false', element );
writer.addClass( WIDGET_CLASS_NAME, element );
writer.setCustomProperty( widgetSymbol, true, element );
element.getFillerOffset = getFillerOffset;
element.addClass( WIDGET_CLASS_NAME );
element.setCustomProperty( widgetSymbol, true );

if ( options.label ) {
setLabel( element, options.label );
setLabel( element, options.label, writer );
}

setHighlightHandling(
element,
( element, descriptor ) => element.addClass( ...normalizeToArray( descriptor.class ) ),
( element, descriptor ) => element.removeClass( ...normalizeToArray( descriptor.class ) )
writer,
( element, descriptor, writer ) => writer.addClass( normalizeToArray( descriptor.class ), element ),
( element, descriptor, writer ) => writer.removeClass( normalizeToArray( descriptor.class ), element )
);

return element;
Expand All @@ -79,24 +81,25 @@ export function toWidget( element, options = {} ) {
* properly determine which highlight descriptor should be used at given time.
*
* @param {module:engine/view/element~Element} element
* @param {module:engine/view/writer~Writer} writer
* @param {Function} add
* @param {Function} remove
*/
export function setHighlightHandling( element, add, remove ) {
export function setHighlightHandling( element, writer, add, remove ) {
const stack = new HighlightStack();

stack.on( 'change:top', ( evt, data ) => {
if ( data.oldDescriptor ) {
remove( element, data.oldDescriptor );
remove( element, data.oldDescriptor, data.writer );
}

if ( data.newDescriptor ) {
add( element, data.newDescriptor );
add( element, data.newDescriptor, data.writer );
}
} );

element.setCustomProperty( 'addHighlight', ( element, descriptor ) => stack.add( descriptor ) );
element.setCustomProperty( 'removeHighlight', ( element, id ) => stack.remove( id ) );
writer.setCustomProperty( 'addHighlight', ( element, descriptor, writer ) => stack.add( descriptor, writer ), element );
writer.setCustomProperty( 'removeHighlight', ( element, id, writer ) => stack.remove( id, writer ), element );
}

/**
Expand All @@ -106,9 +109,10 @@ export function setHighlightHandling( element, add, remove ) {
*
* @param {module:engine/view/element~Element} element
* @param {String|Function} labelOrCreator
* * @param {module:engine/view/writer~Writer} writer
*/
export function setLabel( element, labelOrCreator ) {
element.setCustomProperty( labelSymbol, labelOrCreator );
export function setLabel( element, labelOrCreator, writer ) {
writer.setCustomProperty( labelSymbol, labelOrCreator, element );
}

/**
Expand Down Expand Up @@ -137,22 +141,22 @@ export function getLabel( element ) {
* @param {module:engine/view/editableelement~EditableElement} editable
* @returns {module:engine/view/editableelement~EditableElement} Returns same element that was provided in `editable` param.
*/
export function toWidgetEditable( editable ) {
editable.addClass( 'ck-editable' );
export function toWidgetEditable( editable, writer ) {
writer.addClass( 'ck-editable', editable );

// Set initial contenteditable value.
editable.setAttribute( 'contenteditable', editable.isReadOnly ? 'false' : 'true' );
writer.setAttribute( 'contenteditable', editable.isReadOnly ? 'false' : 'true', editable );

// Bind contenteditable property to element#isReadOnly.
editable.on( 'change:isReadOnly', ( evt, property, is ) => {
editable.setAttribute( 'contenteditable', is ? 'false' : 'true' );
writer.setAttribute( 'contenteditable', is ? 'false' : 'true', editable );
} );

editable.on( 'change:isFocused', ( evt, property, is ) => {
if ( is ) {
editable.addClass( 'ck-editable_focused' );
writer.addClass( 'ck-editable_focused', editable );
} else {
editable.removeClass( 'ck-editable_focused' );
writer.removeClass( 'ck-editable_focused', editable );
}
} );

Expand Down
Loading

0 comments on commit 5eb92af

Please sign in to comment.