@ckeditor/ckeditor5-widget 40.0.0 → 40.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -24
- package/LICENSE.md +3 -3
- package/package.json +7 -7
- package/src/augmentation.d.ts +13 -13
- package/src/augmentation.js +5 -5
- package/src/highlightstack.d.ts +74 -74
- package/src/highlightstack.js +129 -129
- package/src/index.d.ts +13 -13
- package/src/index.js +13 -13
- package/src/utils.d.ts +198 -198
- package/src/utils.js +348 -348
- package/src/verticalnavigation.d.ts +15 -15
- package/src/verticalnavigation.js +196 -196
- package/src/widget.d.ts +95 -91
- package/src/widget.js +429 -380
- package/src/widgetresize/resizer.d.ts +177 -177
- package/src/widgetresize/resizer.js +372 -372
- package/src/widgetresize/resizerstate.d.ts +125 -125
- package/src/widgetresize/resizerstate.js +150 -150
- package/src/widgetresize/sizeview.d.ts +55 -55
- package/src/widgetresize/sizeview.js +63 -63
- package/src/widgetresize.d.ts +125 -125
- package/src/widgetresize.js +188 -188
- package/src/widgettoolbarrepository.d.ts +94 -94
- package/src/widgettoolbarrepository.js +268 -268
- package/src/widgettypearound/utils.d.ts +38 -38
- package/src/widgettypearound/utils.js +52 -52
- package/src/widgettypearound/widgettypearound.d.ts +229 -229
- package/src/widgettypearound/widgettypearound.js +773 -773
package/src/highlightstack.js
CHANGED
@@ -1,129 +1,129 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module widget/highlightstack
|
7
|
-
*/
|
8
|
-
import { EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
9
|
-
/**
|
10
|
-
* Class used to handle the correct order of highlights on elements.
|
11
|
-
*
|
12
|
-
* When different highlights are applied to same element the correct order should be preserved:
|
13
|
-
*
|
14
|
-
* * highlight with highest priority should be applied,
|
15
|
-
* * if two highlights have same priority - sort by CSS class provided in
|
16
|
-
* {@link module:engine/conversion/downcasthelpers~HighlightDescriptor}.
|
17
|
-
*
|
18
|
-
* This way, highlight will be applied with the same rules it is applied on texts.
|
19
|
-
*/
|
20
|
-
export default class HighlightStack extends EmitterMixin() {
|
21
|
-
constructor() {
|
22
|
-
super(...arguments);
|
23
|
-
this._stack = [];
|
24
|
-
}
|
25
|
-
/**
|
26
|
-
* Adds highlight descriptor to the stack.
|
27
|
-
*
|
28
|
-
* @fires change:top
|
29
|
-
*/
|
30
|
-
add(descriptor, writer) {
|
31
|
-
const stack = this._stack;
|
32
|
-
// Save top descriptor and insert new one. If top is changed - fire event.
|
33
|
-
const oldTop = stack[0];
|
34
|
-
this._insertDescriptor(descriptor);
|
35
|
-
const newTop = stack[0];
|
36
|
-
// When new object is at the top and stores different information.
|
37
|
-
if (oldTop !== newTop && !compareDescriptors(oldTop, newTop)) {
|
38
|
-
this.fire('change:top', {
|
39
|
-
oldDescriptor: oldTop,
|
40
|
-
newDescriptor: newTop,
|
41
|
-
writer
|
42
|
-
});
|
43
|
-
}
|
44
|
-
}
|
45
|
-
/**
|
46
|
-
* Removes highlight descriptor from the stack.
|
47
|
-
*
|
48
|
-
* @fires change:top
|
49
|
-
* @param id Id of the descriptor to remove.
|
50
|
-
*/
|
51
|
-
remove(id, writer) {
|
52
|
-
const stack = this._stack;
|
53
|
-
const oldTop = stack[0];
|
54
|
-
this._removeDescriptor(id);
|
55
|
-
const newTop = stack[0];
|
56
|
-
// When new object is at the top and stores different information.
|
57
|
-
if (oldTop !== newTop && !compareDescriptors(oldTop, newTop)) {
|
58
|
-
this.fire('change:top', {
|
59
|
-
oldDescriptor: oldTop,
|
60
|
-
newDescriptor: newTop,
|
61
|
-
writer
|
62
|
-
});
|
63
|
-
}
|
64
|
-
}
|
65
|
-
/**
|
66
|
-
* Inserts a given descriptor in correct place in the stack. It also takes care about updating information
|
67
|
-
* when descriptor with same id is already present.
|
68
|
-
*/
|
69
|
-
_insertDescriptor(descriptor) {
|
70
|
-
const stack = this._stack;
|
71
|
-
const index = stack.findIndex(item => item.id === descriptor.id);
|
72
|
-
// Inserting exact same descriptor - do nothing.
|
73
|
-
if (compareDescriptors(descriptor, stack[index])) {
|
74
|
-
return;
|
75
|
-
}
|
76
|
-
// If descriptor with same id but with different information is on the stack - remove it.
|
77
|
-
if (index > -1) {
|
78
|
-
stack.splice(index, 1);
|
79
|
-
}
|
80
|
-
// Find correct place to insert descriptor in the stack.
|
81
|
-
// It has different information (for example priority) so it must be re-inserted in correct place.
|
82
|
-
let i = 0;
|
83
|
-
while (stack[i] && shouldABeBeforeB(stack[i], descriptor)) {
|
84
|
-
i++;
|
85
|
-
}
|
86
|
-
stack.splice(i, 0, descriptor);
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* Removes descriptor with given id from the stack.
|
90
|
-
*
|
91
|
-
* @param id Descriptor's id.
|
92
|
-
*/
|
93
|
-
_removeDescriptor(id) {
|
94
|
-
const stack = this._stack;
|
95
|
-
const index = stack.findIndex(item => item.id === id);
|
96
|
-
// If descriptor with same id is on the list - remove it.
|
97
|
-
if (index > -1) {
|
98
|
-
stack.splice(index, 1);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
/**
|
103
|
-
* Compares two descriptors by checking their priority and class list.
|
104
|
-
*
|
105
|
-
* @returns Returns true if both descriptors are defined and have same priority and classes.
|
106
|
-
*/
|
107
|
-
function compareDescriptors(a, b) {
|
108
|
-
return a && b && a.priority == b.priority && classesToString(a.classes) == classesToString(b.classes);
|
109
|
-
}
|
110
|
-
/**
|
111
|
-
* Checks whenever first descriptor should be placed in the stack before second one.
|
112
|
-
*/
|
113
|
-
function shouldABeBeforeB(a, b) {
|
114
|
-
if (a.priority > b.priority) {
|
115
|
-
return true;
|
116
|
-
}
|
117
|
-
else if (a.priority < b.priority) {
|
118
|
-
return false;
|
119
|
-
}
|
120
|
-
// When priorities are equal and names are different - use classes to compare.
|
121
|
-
return classesToString(a.classes) > classesToString(b.classes);
|
122
|
-
}
|
123
|
-
/**
|
124
|
-
* Converts CSS classes passed with {@link module:engine/conversion/downcasthelpers~HighlightDescriptor} to
|
125
|
-
* sorted string.
|
126
|
-
*/
|
127
|
-
function classesToString(classes) {
|
128
|
-
return Array.isArray(classes) ? classes.sort().join(',') : classes;
|
129
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module widget/highlightstack
|
7
|
+
*/
|
8
|
+
import { EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
9
|
+
/**
|
10
|
+
* Class used to handle the correct order of highlights on elements.
|
11
|
+
*
|
12
|
+
* When different highlights are applied to same element the correct order should be preserved:
|
13
|
+
*
|
14
|
+
* * highlight with highest priority should be applied,
|
15
|
+
* * if two highlights have same priority - sort by CSS class provided in
|
16
|
+
* {@link module:engine/conversion/downcasthelpers~HighlightDescriptor}.
|
17
|
+
*
|
18
|
+
* This way, highlight will be applied with the same rules it is applied on texts.
|
19
|
+
*/
|
20
|
+
export default class HighlightStack extends EmitterMixin() {
|
21
|
+
constructor() {
|
22
|
+
super(...arguments);
|
23
|
+
this._stack = [];
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Adds highlight descriptor to the stack.
|
27
|
+
*
|
28
|
+
* @fires change:top
|
29
|
+
*/
|
30
|
+
add(descriptor, writer) {
|
31
|
+
const stack = this._stack;
|
32
|
+
// Save top descriptor and insert new one. If top is changed - fire event.
|
33
|
+
const oldTop = stack[0];
|
34
|
+
this._insertDescriptor(descriptor);
|
35
|
+
const newTop = stack[0];
|
36
|
+
// When new object is at the top and stores different information.
|
37
|
+
if (oldTop !== newTop && !compareDescriptors(oldTop, newTop)) {
|
38
|
+
this.fire('change:top', {
|
39
|
+
oldDescriptor: oldTop,
|
40
|
+
newDescriptor: newTop,
|
41
|
+
writer
|
42
|
+
});
|
43
|
+
}
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Removes highlight descriptor from the stack.
|
47
|
+
*
|
48
|
+
* @fires change:top
|
49
|
+
* @param id Id of the descriptor to remove.
|
50
|
+
*/
|
51
|
+
remove(id, writer) {
|
52
|
+
const stack = this._stack;
|
53
|
+
const oldTop = stack[0];
|
54
|
+
this._removeDescriptor(id);
|
55
|
+
const newTop = stack[0];
|
56
|
+
// When new object is at the top and stores different information.
|
57
|
+
if (oldTop !== newTop && !compareDescriptors(oldTop, newTop)) {
|
58
|
+
this.fire('change:top', {
|
59
|
+
oldDescriptor: oldTop,
|
60
|
+
newDescriptor: newTop,
|
61
|
+
writer
|
62
|
+
});
|
63
|
+
}
|
64
|
+
}
|
65
|
+
/**
|
66
|
+
* Inserts a given descriptor in correct place in the stack. It also takes care about updating information
|
67
|
+
* when descriptor with same id is already present.
|
68
|
+
*/
|
69
|
+
_insertDescriptor(descriptor) {
|
70
|
+
const stack = this._stack;
|
71
|
+
const index = stack.findIndex(item => item.id === descriptor.id);
|
72
|
+
// Inserting exact same descriptor - do nothing.
|
73
|
+
if (compareDescriptors(descriptor, stack[index])) {
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
// If descriptor with same id but with different information is on the stack - remove it.
|
77
|
+
if (index > -1) {
|
78
|
+
stack.splice(index, 1);
|
79
|
+
}
|
80
|
+
// Find correct place to insert descriptor in the stack.
|
81
|
+
// It has different information (for example priority) so it must be re-inserted in correct place.
|
82
|
+
let i = 0;
|
83
|
+
while (stack[i] && shouldABeBeforeB(stack[i], descriptor)) {
|
84
|
+
i++;
|
85
|
+
}
|
86
|
+
stack.splice(i, 0, descriptor);
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Removes descriptor with given id from the stack.
|
90
|
+
*
|
91
|
+
* @param id Descriptor's id.
|
92
|
+
*/
|
93
|
+
_removeDescriptor(id) {
|
94
|
+
const stack = this._stack;
|
95
|
+
const index = stack.findIndex(item => item.id === id);
|
96
|
+
// If descriptor with same id is on the list - remove it.
|
97
|
+
if (index > -1) {
|
98
|
+
stack.splice(index, 1);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
/**
|
103
|
+
* Compares two descriptors by checking their priority and class list.
|
104
|
+
*
|
105
|
+
* @returns Returns true if both descriptors are defined and have same priority and classes.
|
106
|
+
*/
|
107
|
+
function compareDescriptors(a, b) {
|
108
|
+
return a && b && a.priority == b.priority && classesToString(a.classes) == classesToString(b.classes);
|
109
|
+
}
|
110
|
+
/**
|
111
|
+
* Checks whenever first descriptor should be placed in the stack before second one.
|
112
|
+
*/
|
113
|
+
function shouldABeBeforeB(a, b) {
|
114
|
+
if (a.priority > b.priority) {
|
115
|
+
return true;
|
116
|
+
}
|
117
|
+
else if (a.priority < b.priority) {
|
118
|
+
return false;
|
119
|
+
}
|
120
|
+
// When priorities are equal and names are different - use classes to compare.
|
121
|
+
return classesToString(a.classes) > classesToString(b.classes);
|
122
|
+
}
|
123
|
+
/**
|
124
|
+
* Converts CSS classes passed with {@link module:engine/conversion/downcasthelpers~HighlightDescriptor} to
|
125
|
+
* sorted string.
|
126
|
+
*/
|
127
|
+
function classesToString(classes) {
|
128
|
+
return Array.isArray(classes) ? classes.sort().join(',') : classes;
|
129
|
+
}
|
package/src/index.d.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module widget
|
7
|
-
*/
|
8
|
-
export { default as Widget } from './widget';
|
9
|
-
export { default as WidgetToolbarRepository } from './widgettoolbarrepository';
|
10
|
-
export { default as WidgetResize } from './widgetresize';
|
11
|
-
export { default as WidgetTypeAround } from './widgettypearound/widgettypearound';
|
12
|
-
export * from './utils';
|
13
|
-
import './augmentation';
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module widget
|
7
|
+
*/
|
8
|
+
export { default as Widget } from './widget';
|
9
|
+
export { default as WidgetToolbarRepository } from './widgettoolbarrepository';
|
10
|
+
export { default as WidgetResize } from './widgetresize';
|
11
|
+
export { default as WidgetTypeAround } from './widgettypearound/widgettypearound';
|
12
|
+
export * from './utils';
|
13
|
+
import './augmentation';
|
package/src/index.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module widget
|
7
|
-
*/
|
8
|
-
export { default as Widget } from './widget';
|
9
|
-
export { default as WidgetToolbarRepository } from './widgettoolbarrepository';
|
10
|
-
export { default as WidgetResize } from './widgetresize';
|
11
|
-
export { default as WidgetTypeAround } from './widgettypearound/widgettypearound';
|
12
|
-
export * from './utils';
|
13
|
-
import './augmentation';
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module widget
|
7
|
+
*/
|
8
|
+
export { default as Widget } from './widget';
|
9
|
+
export { default as WidgetToolbarRepository } from './widgettoolbarrepository';
|
10
|
+
export { default as WidgetResize } from './widgetresize';
|
11
|
+
export { default as WidgetTypeAround } from './widgettypearound/widgettypearound';
|
12
|
+
export * from './utils';
|
13
|
+
import './augmentation';
|