@ckeditor/ckeditor5-widget 35.2.1 → 35.3.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-widget",
3
- "version": "35.2.1",
3
+ "version": "35.3.1",
4
4
  "description": "Widget API for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -11,29 +11,32 @@
11
11
  ],
12
12
  "main": "src/index.js",
13
13
  "dependencies": {
14
- "@ckeditor/ckeditor5-core": "^35.2.1",
15
- "@ckeditor/ckeditor5-engine": "^35.2.1",
16
- "@ckeditor/ckeditor5-enter": "^35.2.1",
17
- "@ckeditor/ckeditor5-ui": "^35.2.1",
18
- "@ckeditor/ckeditor5-utils": "^35.2.1",
19
- "@ckeditor/ckeditor5-typing": "^35.2.1",
14
+ "@ckeditor/ckeditor5-core": "^35.3.1",
15
+ "@ckeditor/ckeditor5-engine": "^35.3.1",
16
+ "@ckeditor/ckeditor5-enter": "^35.3.1",
17
+ "@ckeditor/ckeditor5-ui": "^35.3.1",
18
+ "@ckeditor/ckeditor5-utils": "^35.3.1",
19
+ "@ckeditor/ckeditor5-typing": "^35.3.1",
20
20
  "lodash-es": "^4.17.15"
21
21
  },
22
22
  "devDependencies": {
23
- "@ckeditor/ckeditor5-basic-styles": "^35.2.1",
24
- "@ckeditor/ckeditor5-block-quote": "^35.2.1",
25
- "@ckeditor/ckeditor5-clipboard": "^35.2.1",
26
- "@ckeditor/ckeditor5-editor-balloon": "^35.2.1",
27
- "@ckeditor/ckeditor5-editor-classic": "^35.2.1",
28
- "@ckeditor/ckeditor5-essentials": "^35.2.1",
29
- "@ckeditor/ckeditor5-heading": "^35.2.1",
30
- "@ckeditor/ckeditor5-horizontal-line": "^35.2.1",
31
- "@ckeditor/ckeditor5-image": "^35.2.1",
32
- "@ckeditor/ckeditor5-link": "^35.2.1",
33
- "@ckeditor/ckeditor5-media-embed": "^35.2.1",
34
- "@ckeditor/ckeditor5-paragraph": "^35.2.1",
35
- "@ckeditor/ckeditor5-table": "^35.2.1",
36
- "@ckeditor/ckeditor5-undo": "^35.2.1"
23
+ "@ckeditor/ckeditor5-basic-styles": "^35.3.1",
24
+ "@ckeditor/ckeditor5-block-quote": "^35.3.1",
25
+ "@ckeditor/ckeditor5-clipboard": "^35.3.1",
26
+ "@ckeditor/ckeditor5-editor-balloon": "^35.3.1",
27
+ "@ckeditor/ckeditor5-editor-classic": "^35.3.1",
28
+ "@ckeditor/ckeditor5-essentials": "^35.3.1",
29
+ "@ckeditor/ckeditor5-heading": "^35.3.1",
30
+ "@ckeditor/ckeditor5-horizontal-line": "^35.3.1",
31
+ "@ckeditor/ckeditor5-image": "^35.3.1",
32
+ "@ckeditor/ckeditor5-link": "^35.3.1",
33
+ "@ckeditor/ckeditor5-media-embed": "^35.3.1",
34
+ "@ckeditor/ckeditor5-paragraph": "^35.3.1",
35
+ "@ckeditor/ckeditor5-table": "^35.3.1",
36
+ "@ckeditor/ckeditor5-undo": "^35.3.1",
37
+ "typescript": "^4.8.4",
38
+ "webpack": "^5.58.1",
39
+ "webpack-cli": "^4.9.0"
37
40
  },
38
41
  "engines": {
39
42
  "node": ">=14.0.0",
@@ -50,9 +53,14 @@
50
53
  },
51
54
  "files": [
52
55
  "lang",
53
- "src",
56
+ "src/**/*.js",
57
+ "src/**/*.d.ts",
54
58
  "theme",
55
59
  "ckeditor5-metadata.json",
56
60
  "CHANGELOG.md"
57
- ]
61
+ ],
62
+ "scripts": {
63
+ "build": "tsc -p ./tsconfig.release.json",
64
+ "postversion": "npm run build"
65
+ }
58
66
  }
@@ -2,14 +2,10 @@
2
2
  * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module widget/highlightstack
8
7
  */
9
-
10
- import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
11
- import mix from '@ckeditor/ckeditor5-utils/src/mix';
12
-
8
+ import { Emitter } from '@ckeditor/ckeditor5-utils/src/emittermixin';
13
9
  /**
14
10
  * Class used to handle correct order of highlights on elements.
15
11
  *
@@ -21,156 +17,126 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
21
17
  *
22
18
  * This way, highlight will be applied with the same rules it is applied on texts.
23
19
  */
24
- export default class HighlightStack {
25
- /**
26
- * Creates class instance.
27
- */
28
- constructor() {
29
- this._stack = [];
30
- }
31
-
32
- /**
33
- * Adds highlight descriptor to the stack.
34
- *
35
- * @fires change:top
36
- * @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} descriptor
37
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer
38
- */
39
- add( descriptor, writer ) {
40
- const stack = this._stack;
41
-
42
- // Save top descriptor and insert new one. If top is changed - fire event.
43
- const oldTop = stack[ 0 ];
44
- this._insertDescriptor( descriptor );
45
- const newTop = stack[ 0 ];
46
-
47
- // When new object is at the top and stores different information.
48
- if ( oldTop !== newTop && !compareDescriptors( oldTop, newTop ) ) {
49
- this.fire( 'change:top', {
50
- oldDescriptor: oldTop,
51
- newDescriptor: newTop,
52
- writer
53
- } );
54
- }
55
- }
56
-
57
- /**
58
- * Removes highlight descriptor from the stack.
59
- *
60
- * @fires change:top
61
- * @param {String} id Id of the descriptor to remove.
62
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer
63
- */
64
- remove( id, writer ) {
65
- const stack = this._stack;
66
-
67
- const oldTop = stack[ 0 ];
68
- this._removeDescriptor( id );
69
- const newTop = stack[ 0 ];
70
-
71
- // When new object is at the top and stores different information.
72
- if ( oldTop !== newTop && !compareDescriptors( oldTop, newTop ) ) {
73
- this.fire( 'change:top', {
74
- oldDescriptor: oldTop,
75
- newDescriptor: newTop,
76
- writer
77
- } );
78
- }
79
- }
80
-
81
- /**
82
- * Inserts given descriptor in correct place in the stack. It also takes care about updating information when
83
- * descriptor with same id is already present.
84
- *
85
- * @private
86
- * @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} descriptor
87
- */
88
- _insertDescriptor( descriptor ) {
89
- const stack = this._stack;
90
- const index = stack.findIndex( item => item.id === descriptor.id );
91
-
92
- // Inserting exact same descriptor - do nothing.
93
- if ( compareDescriptors( descriptor, stack[ index ] ) ) {
94
- return;
95
- }
96
-
97
- // If descriptor with same id but with different information is on the stack - remove it.
98
- if ( index > -1 ) {
99
- stack.splice( index, 1 );
100
- }
101
-
102
- // Find correct place to insert descriptor in the stack.
103
- // It have different information (for example priority) so it must be re-inserted in correct place.
104
- let i = 0;
105
-
106
- while ( stack[ i ] && shouldABeBeforeB( stack[ i ], descriptor ) ) {
107
- i++;
108
- }
109
-
110
- stack.splice( i, 0, descriptor );
111
- }
112
-
113
- /**
114
- * Removes descriptor with given id from the stack.
115
- *
116
- * @private
117
- * @param {String} id Descriptor's id.
118
- */
119
- _removeDescriptor( id ) {
120
- const stack = this._stack;
121
- const index = stack.findIndex( item => item.id === id );
122
-
123
- // If descriptor with same id is on the list - remove it.
124
- if ( index > -1 ) {
125
- stack.splice( index, 1 );
126
- }
127
- }
20
+ export default class HighlightStack extends Emitter {
21
+ /**
22
+ * Creates class instance.
23
+ */
24
+ constructor() {
25
+ super();
26
+ this._stack = [];
27
+ }
28
+ /**
29
+ * Adds highlight descriptor to the stack.
30
+ *
31
+ * @fires change:top
32
+ * @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} descriptor
33
+ * @param {module:engine/view/downcastwriter~DowncastWriter} writer
34
+ */
35
+ add(descriptor, writer) {
36
+ const stack = this._stack;
37
+ // Save top descriptor and insert new one. If top is changed - fire event.
38
+ const oldTop = stack[0];
39
+ this._insertDescriptor(descriptor);
40
+ const newTop = stack[0];
41
+ // When new object is at the top and stores different information.
42
+ if (oldTop !== newTop && !compareDescriptors(oldTop, newTop)) {
43
+ this.fire('change:top', {
44
+ oldDescriptor: oldTop,
45
+ newDescriptor: newTop,
46
+ writer
47
+ });
48
+ }
49
+ }
50
+ /**
51
+ * Removes highlight descriptor from the stack.
52
+ *
53
+ * @fires change:top
54
+ * @param {String} id Id of the descriptor to remove.
55
+ * @param {module:engine/view/downcastwriter~DowncastWriter} writer
56
+ */
57
+ remove(id, writer) {
58
+ const stack = this._stack;
59
+ const oldTop = stack[0];
60
+ this._removeDescriptor(id);
61
+ const newTop = stack[0];
62
+ // When new object is at the top and stores different information.
63
+ if (oldTop !== newTop && !compareDescriptors(oldTop, newTop)) {
64
+ this.fire('change:top', {
65
+ oldDescriptor: oldTop,
66
+ newDescriptor: newTop,
67
+ writer
68
+ });
69
+ }
70
+ }
71
+ /**
72
+ * Inserts given descriptor in correct place in the stack. It also takes care about updating information when
73
+ * descriptor with same id is already present.
74
+ *
75
+ * @private
76
+ * @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} descriptor
77
+ */
78
+ _insertDescriptor(descriptor) {
79
+ const stack = this._stack;
80
+ const index = stack.findIndex(item => item.id === descriptor.id);
81
+ // Inserting exact same descriptor - do nothing.
82
+ if (compareDescriptors(descriptor, stack[index])) {
83
+ return;
84
+ }
85
+ // If descriptor with same id but with different information is on the stack - remove it.
86
+ if (index > -1) {
87
+ stack.splice(index, 1);
88
+ }
89
+ // Find correct place to insert descriptor in the stack.
90
+ // It have different information (for example priority) so it must be re-inserted in correct place.
91
+ let i = 0;
92
+ while (stack[i] && shouldABeBeforeB(stack[i], descriptor)) {
93
+ i++;
94
+ }
95
+ stack.splice(i, 0, descriptor);
96
+ }
97
+ /**
98
+ * Removes descriptor with given id from the stack.
99
+ *
100
+ * @private
101
+ * @param {String} id Descriptor's id.
102
+ */
103
+ _removeDescriptor(id) {
104
+ const stack = this._stack;
105
+ const index = stack.findIndex(item => item.id === id);
106
+ // If descriptor with same id is on the list - remove it.
107
+ if (index > -1) {
108
+ stack.splice(index, 1);
109
+ }
110
+ }
128
111
  }
129
-
130
- mix( HighlightStack, EmitterMixin );
131
-
132
112
  // Compares two descriptors by checking their priority and class list.
133
113
  //
134
114
  // @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} a
135
115
  // @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} b
136
116
  // @returns {Boolean} Returns true if both descriptors are defined and have same priority and classes.
137
- function compareDescriptors( a, b ) {
138
- return a && b && a.priority == b.priority && classesToString( a.classes ) == classesToString( b.classes );
117
+ function compareDescriptors(a, b) {
118
+ return a && b && a.priority == b.priority && classesToString(a.classes) == classesToString(b.classes);
139
119
  }
140
-
141
120
  // Checks whenever first descriptor should be placed in the stack before second one.
142
121
  //
143
122
  // @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} a
144
123
  // @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} b
145
124
  // @returns {Boolean}
146
- function shouldABeBeforeB( a, b ) {
147
- if ( a.priority > b.priority ) {
148
- return true;
149
- } else if ( a.priority < b.priority ) {
150
- return false;
151
- }
152
-
153
- // When priorities are equal and names are different - use classes to compare.
154
- return classesToString( a.classes ) > classesToString( b.classes );
125
+ function shouldABeBeforeB(a, b) {
126
+ if (a.priority > b.priority) {
127
+ return true;
128
+ }
129
+ else if (a.priority < b.priority) {
130
+ return false;
131
+ }
132
+ // When priorities are equal and names are different - use classes to compare.
133
+ return classesToString(a.classes) > classesToString(b.classes);
155
134
  }
156
-
157
135
  // Converts CSS classes passed with {@link module:engine/conversion/downcasthelpers~HighlightDescriptor} to
158
136
  // sorted string.
159
137
  //
160
138
  // @param {String|Array<String>} descriptor
161
139
  // @returns {String}
162
- function classesToString( classes ) {
163
- return Array.isArray( classes ) ? classes.sort().join( ',' ) : classes;
140
+ function classesToString(classes) {
141
+ return Array.isArray(classes) ? classes.sort().join(',') : classes;
164
142
  }
165
-
166
- /**
167
- * Fired when top element on {@link module:widget/highlightstack~HighlightStack} has been changed
168
- *
169
- * @event change:top
170
- * @param {Object} data Additional information about the change.
171
- * @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} [data.newDescriptor] New highlight
172
- * descriptor. It will be `undefined` when last descriptor is removed from the stack.
173
- * @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} [data.oldDescriptor] Old highlight
174
- * descriptor. It will be `undefined` when first descriptor is added to the stack.
175
- * @param {module:engine/view/downcastwriter~DowncastWriter} writer View writer that can be used to modify element.
176
- */
package/src/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  export { default as Widget } from './widget';
7
6
  export { default as WidgetToolbarRepository } from './widgettoolbarrepository';
8
7
  export { default as WidgetResize } from './widgetresize';