@ckeditor/ckeditor5-widget 35.1.0 → 35.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +21 -21
- package/src/widgetresize/resizer.js +48 -10
- package/src/widgetresize.js +39 -16
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ckeditor/ckeditor5-widget",
|
3
|
-
"version": "35.
|
3
|
+
"version": "35.2.0",
|
4
4
|
"description": "Widget API for CKEditor 5.",
|
5
5
|
"keywords": [
|
6
6
|
"ckeditor",
|
@@ -11,29 +11,29 @@
|
|
11
11
|
],
|
12
12
|
"main": "src/index.js",
|
13
13
|
"dependencies": {
|
14
|
-
"@ckeditor/ckeditor5-core": "^35.
|
15
|
-
"@ckeditor/ckeditor5-engine": "^35.
|
16
|
-
"@ckeditor/ckeditor5-enter": "^35.
|
17
|
-
"@ckeditor/ckeditor5-ui": "^35.
|
18
|
-
"@ckeditor/ckeditor5-utils": "^35.
|
19
|
-
"@ckeditor/ckeditor5-typing": "^35.
|
14
|
+
"@ckeditor/ckeditor5-core": "^35.2.0",
|
15
|
+
"@ckeditor/ckeditor5-engine": "^35.2.0",
|
16
|
+
"@ckeditor/ckeditor5-enter": "^35.2.0",
|
17
|
+
"@ckeditor/ckeditor5-ui": "^35.2.0",
|
18
|
+
"@ckeditor/ckeditor5-utils": "^35.2.0",
|
19
|
+
"@ckeditor/ckeditor5-typing": "^35.2.0",
|
20
20
|
"lodash-es": "^4.17.15"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
|
-
"@ckeditor/ckeditor5-basic-styles": "^35.
|
24
|
-
"@ckeditor/ckeditor5-block-quote": "^35.
|
25
|
-
"@ckeditor/ckeditor5-clipboard": "^35.
|
26
|
-
"@ckeditor/ckeditor5-editor-balloon": "^35.
|
27
|
-
"@ckeditor/ckeditor5-editor-classic": "^35.
|
28
|
-
"@ckeditor/ckeditor5-essentials": "^35.
|
29
|
-
"@ckeditor/ckeditor5-heading": "^35.
|
30
|
-
"@ckeditor/ckeditor5-horizontal-line": "^35.
|
31
|
-
"@ckeditor/ckeditor5-image": "^35.
|
32
|
-
"@ckeditor/ckeditor5-link": "^35.
|
33
|
-
"@ckeditor/ckeditor5-media-embed": "^35.
|
34
|
-
"@ckeditor/ckeditor5-paragraph": "^35.
|
35
|
-
"@ckeditor/ckeditor5-table": "^35.
|
36
|
-
"@ckeditor/ckeditor5-undo": "^35.
|
23
|
+
"@ckeditor/ckeditor5-basic-styles": "^35.2.0",
|
24
|
+
"@ckeditor/ckeditor5-block-quote": "^35.2.0",
|
25
|
+
"@ckeditor/ckeditor5-clipboard": "^35.2.0",
|
26
|
+
"@ckeditor/ckeditor5-editor-balloon": "^35.2.0",
|
27
|
+
"@ckeditor/ckeditor5-editor-classic": "^35.2.0",
|
28
|
+
"@ckeditor/ckeditor5-essentials": "^35.2.0",
|
29
|
+
"@ckeditor/ckeditor5-heading": "^35.2.0",
|
30
|
+
"@ckeditor/ckeditor5-horizontal-line": "^35.2.0",
|
31
|
+
"@ckeditor/ckeditor5-image": "^35.2.0",
|
32
|
+
"@ckeditor/ckeditor5-link": "^35.2.0",
|
33
|
+
"@ckeditor/ckeditor5-media-embed": "^35.2.0",
|
34
|
+
"@ckeditor/ckeditor5-paragraph": "^35.2.0",
|
35
|
+
"@ckeditor/ckeditor5-table": "^35.2.0",
|
36
|
+
"@ckeditor/ckeditor5-undo": "^35.2.0"
|
37
37
|
},
|
38
38
|
"engines": {
|
39
39
|
"node": ">=14.0.0",
|
@@ -68,10 +68,27 @@ export default class Resizer {
|
|
68
68
|
*/
|
69
69
|
|
70
70
|
/**
|
71
|
+
* Flag that indicates whether resizer can be used.
|
72
|
+
*
|
71
73
|
* @observable
|
72
74
|
*/
|
73
75
|
this.set( 'isEnabled', true );
|
74
76
|
|
77
|
+
/**
|
78
|
+
* Flag that indicates that resizer is currently focused.
|
79
|
+
*
|
80
|
+
* @observable
|
81
|
+
*/
|
82
|
+
this.set( 'isSelected', false );
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Flag that indicates whether resizer is rendered (visible on the screen).
|
86
|
+
*
|
87
|
+
* @readonly
|
88
|
+
* @observable
|
89
|
+
*/
|
90
|
+
this.bind( 'isVisible' ).to( this, 'isEnabled', this, 'isSelected', ( isEnabled, isSelected ) => isEnabled && isSelected );
|
91
|
+
|
75
92
|
this.decorate( 'begin' );
|
76
93
|
this.decorate( 'cancel' );
|
77
94
|
this.decorate( 'commit' );
|
@@ -86,15 +103,38 @@ export default class Resizer {
|
|
86
103
|
}
|
87
104
|
}, { priority: 'high' } );
|
88
105
|
|
89
|
-
this.on( 'change:
|
90
|
-
|
91
|
-
|
92
|
-
if ( this.isEnabled ) {
|
106
|
+
this.on( 'change:isVisible', () => {
|
107
|
+
if ( this.isVisible ) {
|
108
|
+
this.show();
|
93
109
|
this.redraw();
|
110
|
+
} else {
|
111
|
+
this.hide();
|
94
112
|
}
|
95
113
|
} );
|
96
114
|
}
|
97
115
|
|
116
|
+
/**
|
117
|
+
* Makes resizer visible in the UI.
|
118
|
+
*/
|
119
|
+
show() {
|
120
|
+
const editingView = this._options.editor.editing.view;
|
121
|
+
|
122
|
+
editingView.change( writer => {
|
123
|
+
writer.removeClass( 'ck-hidden', this._viewResizerWrapper );
|
124
|
+
} );
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Hides resizer in the UI.
|
129
|
+
*/
|
130
|
+
hide() {
|
131
|
+
const editingView = this._options.editor.editing.view;
|
132
|
+
|
133
|
+
editingView.change( writer => {
|
134
|
+
writer.addClass( 'ck-hidden', this._viewResizerWrapper );
|
135
|
+
} );
|
136
|
+
}
|
137
|
+
|
98
138
|
/**
|
99
139
|
* Attaches the resizer to the DOM.
|
100
140
|
*/
|
@@ -112,12 +152,6 @@ export default class Resizer {
|
|
112
152
|
that._appendHandles( domElement );
|
113
153
|
that._appendSizeUI( domElement );
|
114
154
|
|
115
|
-
that.on( 'change:isEnabled', ( evt, propName, newValue ) => {
|
116
|
-
domElement.style.display = newValue ? '' : 'none';
|
117
|
-
} );
|
118
|
-
|
119
|
-
domElement.style.display = that.isEnabled ? '' : 'none';
|
120
|
-
|
121
155
|
return domElement;
|
122
156
|
} );
|
123
157
|
|
@@ -126,6 +160,10 @@ export default class Resizer {
|
|
126
160
|
writer.addClass( 'ck-widget_with-resizer', widgetElement );
|
127
161
|
|
128
162
|
this._viewResizerWrapper = viewResizerWrapper;
|
163
|
+
|
164
|
+
if ( !this.isVisible ) {
|
165
|
+
this.hide();
|
166
|
+
}
|
129
167
|
} );
|
130
168
|
}
|
131
169
|
|
package/src/widgetresize.js
CHANGED
@@ -42,12 +42,12 @@ export default class WidgetResize extends Plugin {
|
|
42
42
|
const domDocument = global.window.document;
|
43
43
|
|
44
44
|
/**
|
45
|
-
* The currently
|
45
|
+
* The currently selected resizer.
|
46
46
|
*
|
47
47
|
* @observable
|
48
|
-
* @member {module:widget/widgetresize/resizer~Resizer|null} #
|
48
|
+
* @member {module:widget/widgetresize/resizer~Resizer|null} #selectedResizer
|
49
49
|
*/
|
50
|
-
this.set( '
|
50
|
+
this.set( 'selectedResizer', null );
|
51
51
|
|
52
52
|
/**
|
53
53
|
* References an active resizer.
|
@@ -77,20 +77,16 @@ export default class WidgetResize extends Plugin {
|
|
77
77
|
this._observer.listenTo( domDocument, 'mousemove', this._mouseMoveListener.bind( this ) );
|
78
78
|
this._observer.listenTo( domDocument, 'mouseup', this._mouseUpListener.bind( this ) );
|
79
79
|
|
80
|
-
const
|
81
|
-
if ( this.
|
82
|
-
this.
|
80
|
+
const redrawSelectedResizer = () => {
|
81
|
+
if ( this.selectedResizer && this.selectedResizer.isVisible ) {
|
82
|
+
this.selectedResizer.redraw();
|
83
83
|
}
|
84
84
|
};
|
85
85
|
|
86
|
-
this.
|
87
|
-
|
88
|
-
// Redraws occurring upon a change of visible resizer must not be throttled, as it is crucial for the initial
|
89
|
-
// render. Without it the resizer frame would be misaligned with resizing host for a fraction of second.
|
90
|
-
this.on( 'change:visibleResizer', redrawFocusedResizer );
|
86
|
+
this._redrawSelectedResizerThrottled = throttle( redrawSelectedResizer, 200 );
|
91
87
|
|
92
88
|
// Redrawing on any change of the UI of the editor (including content changes).
|
93
|
-
this.editor.ui.on( 'update', this.
|
89
|
+
this.editor.ui.on( 'update', this._redrawSelectedResizerThrottled );
|
94
90
|
|
95
91
|
// Remove view widget-resizer mappings for widgets that have been removed from the document.
|
96
92
|
// https://github.com/ckeditor/ckeditor5/issues/10156
|
@@ -105,14 +101,19 @@ export default class WidgetResize extends Plugin {
|
|
105
101
|
}, { priority: 'lowest' } );
|
106
102
|
|
107
103
|
// Resizers need to be redrawn upon window resize, because new window might shrink resize host.
|
108
|
-
this._observer.listenTo( global.window, 'resize', this.
|
104
|
+
this._observer.listenTo( global.window, 'resize', this._redrawSelectedResizerThrottled );
|
109
105
|
|
110
106
|
const viewSelection = this.editor.editing.view.document.selection;
|
111
107
|
|
112
108
|
viewSelection.on( 'change', () => {
|
113
109
|
const selectedElement = viewSelection.getSelectedElement();
|
114
110
|
|
115
|
-
|
111
|
+
const resizer = this.getResizerByViewElement( selectedElement ) || null;
|
112
|
+
if ( resizer ) {
|
113
|
+
this.select( resizer );
|
114
|
+
} else {
|
115
|
+
this.deselect();
|
116
|
+
}
|
116
117
|
} );
|
117
118
|
}
|
118
119
|
|
@@ -126,7 +127,29 @@ export default class WidgetResize extends Plugin {
|
|
126
127
|
resizer.destroy();
|
127
128
|
}
|
128
129
|
|
129
|
-
this.
|
130
|
+
this._redrawSelectedResizerThrottled.cancel();
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Marks resizer as selected.
|
135
|
+
*
|
136
|
+
* @param {module:widget/widgetresize/resizer~Resizer} resizer
|
137
|
+
*/
|
138
|
+
select( resizer ) {
|
139
|
+
this.deselect();
|
140
|
+
this.selectedResizer = resizer;
|
141
|
+
this.selectedResizer.isSelected = true;
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Deselects currently set resizer.
|
146
|
+
*/
|
147
|
+
deselect() {
|
148
|
+
if ( this.selectedResizer ) {
|
149
|
+
this.selectedResizer.isSelected = false;
|
150
|
+
}
|
151
|
+
|
152
|
+
this.selectedResizer = null;
|
130
153
|
}
|
131
154
|
|
132
155
|
/**
|
@@ -164,7 +187,7 @@ export default class WidgetResize extends Plugin {
|
|
164
187
|
|
165
188
|
// If the element the resizer is created for is currently focused, it should become visible.
|
166
189
|
if ( this.getResizerByViewElement( selectedElement ) == resizer ) {
|
167
|
-
this.
|
190
|
+
this.select( resizer );
|
168
191
|
}
|
169
192
|
|
170
193
|
return resizer;
|