@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.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/README.md +1 -1
- package/package.json +24 -23
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +62 -109
- package/src/controller/editingcontroller.d.ts +98 -0
- package/src/controller/editingcontroller.js +22 -46
- package/src/conversion/conversion.d.ts +476 -0
- package/src/conversion/conversion.js +328 -347
- package/src/conversion/conversionhelpers.d.ts +26 -0
- package/src/conversion/conversionhelpers.js +1 -5
- package/src/conversion/downcastdispatcher.d.ts +547 -0
- package/src/conversion/downcastdispatcher.js +74 -152
- package/src/conversion/downcasthelpers.d.ts +1226 -0
- package/src/conversion/downcasthelpers.js +843 -762
- package/src/conversion/mapper.d.ts +499 -0
- package/src/conversion/mapper.js +84 -99
- package/src/conversion/modelconsumable.d.ts +201 -0
- package/src/conversion/modelconsumable.js +96 -99
- package/src/conversion/upcastdispatcher.d.ts +492 -0
- package/src/conversion/upcastdispatcher.js +73 -100
- package/src/conversion/upcasthelpers.d.ts +499 -0
- package/src/conversion/upcasthelpers.js +406 -373
- package/src/conversion/viewconsumable.d.ts +177 -0
- package/src/conversion/viewconsumable.js +157 -162
- package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/src/dataprocessor/basichtmlwriter.js +0 -9
- package/src/dataprocessor/dataprocessor.d.ts +61 -0
- package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/src/dataprocessor/htmldataprocessor.js +6 -28
- package/src/dataprocessor/htmlwriter.d.ts +16 -0
- package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/src/dataprocessor/xmldataprocessor.js +8 -40
- package/src/dev-utils/model.d.ts +124 -0
- package/src/dev-utils/model.js +41 -38
- package/src/dev-utils/operationreplayer.d.ts +51 -0
- package/src/dev-utils/operationreplayer.js +6 -14
- package/src/dev-utils/utils.d.ts +37 -0
- package/src/dev-utils/utils.js +5 -18
- package/src/dev-utils/view.d.ts +319 -0
- package/src/dev-utils/view.js +205 -226
- package/src/index.d.ts +105 -0
- package/src/index.js +1 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +245 -0
- package/src/model/document.js +1 -1
- package/src/model/documentfragment.d.ts +196 -0
- package/src/model/documentfragment.js +2 -2
- package/src/model/documentselection.d.ts +420 -0
- package/src/model/element.d.ts +165 -0
- package/src/model/history.d.ts +114 -0
- package/src/model/item.d.ts +14 -0
- package/src/model/liveposition.d.ts +77 -0
- package/src/model/liverange.d.ts +102 -0
- package/src/model/markercollection.d.ts +335 -0
- package/src/model/model.d.ts +812 -0
- package/src/model/model.js +59 -30
- package/src/model/node.d.ts +256 -0
- package/src/model/nodelist.d.ts +91 -0
- package/src/model/operation/attributeoperation.d.ts +98 -0
- package/src/model/operation/detachoperation.d.ts +55 -0
- package/src/model/operation/insertoperation.d.ts +85 -0
- package/src/model/operation/markeroperation.d.ts +86 -0
- package/src/model/operation/mergeoperation.d.ts +95 -0
- package/src/model/operation/moveoperation.d.ts +91 -0
- package/src/model/operation/nooperation.d.ts +33 -0
- package/src/model/operation/operation.d.ts +89 -0
- package/src/model/operation/operationfactory.d.ts +18 -0
- package/src/model/operation/renameoperation.d.ts +78 -0
- package/src/model/operation/rootattributeoperation.d.ts +97 -0
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.d.ts +104 -0
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/position.d.ts +539 -0
- package/src/model/position.js +1 -1
- package/src/model/range.d.ts +458 -0
- package/src/model/range.js +1 -1
- package/src/model/rootelement.d.ts +40 -0
- package/src/model/schema.d.ts +1176 -0
- package/src/model/schema.js +15 -15
- package/src/model/selection.d.ts +472 -0
- package/src/model/text.d.ts +66 -0
- package/src/model/text.js +0 -2
- package/src/model/textproxy.d.ts +144 -0
- package/src/model/treewalker.d.ts +186 -0
- package/src/model/treewalker.js +19 -10
- package/src/model/typecheckable.d.ts +255 -0
- package/src/model/utils/autoparagraphing.d.ts +37 -0
- package/src/model/utils/deletecontent.d.ts +58 -0
- package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
- package/src/model/utils/getselectedcontent.d.ts +30 -0
- package/src/model/utils/insertcontent.d.ts +46 -0
- package/src/model/utils/insertcontent.js +2 -12
- package/src/model/utils/insertobject.d.ts +44 -0
- package/src/model/utils/insertobject.js +3 -14
- package/src/model/utils/modifyselection.d.ts +48 -0
- package/src/model/utils/selection-post-fixer.d.ts +65 -0
- package/src/model/writer.d.ts +726 -0
- package/src/model/writer.js +6 -4
- package/src/view/attributeelement.d.ts +108 -0
- package/src/view/attributeelement.js +25 -69
- package/src/view/containerelement.d.ts +49 -0
- package/src/view/containerelement.js +10 -43
- package/src/view/datatransfer.d.ts +75 -0
- package/src/view/document.d.ts +184 -0
- package/src/view/document.js +15 -84
- package/src/view/documentfragment.d.ts +150 -0
- package/src/view/documentfragment.js +40 -81
- package/src/view/documentselection.d.ts +219 -0
- package/src/view/documentselection.js +75 -121
- package/src/view/domconverter.d.ts +620 -0
- package/src/view/domconverter.js +159 -276
- package/src/view/downcastwriter.d.ts +804 -0
- package/src/view/downcastwriter.js +336 -380
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +466 -0
- package/src/view/element.js +150 -222
- package/src/view/elementdefinition.d.ts +87 -0
- package/src/view/emptyelement.d.ts +41 -0
- package/src/view/emptyelement.js +11 -44
- package/src/view/filler.d.ts +111 -0
- package/src/view/filler.js +24 -21
- package/src/view/item.d.ts +14 -0
- package/src/view/matcher.d.ts +486 -0
- package/src/view/matcher.js +247 -218
- package/src/view/node.d.ts +160 -0
- package/src/view/node.js +26 -100
- package/src/view/observer/arrowkeysobserver.d.ts +41 -0
- package/src/view/observer/arrowkeysobserver.js +0 -13
- package/src/view/observer/bubblingemittermixin.d.ts +166 -0
- package/src/view/observer/bubblingemittermixin.js +36 -25
- package/src/view/observer/bubblingeventinfo.d.ts +47 -0
- package/src/view/observer/bubblingeventinfo.js +3 -29
- package/src/view/observer/clickobserver.d.ts +43 -0
- package/src/view/observer/clickobserver.js +9 -19
- package/src/view/observer/compositionobserver.d.ts +82 -0
- package/src/view/observer/compositionobserver.js +13 -42
- package/src/view/observer/domeventdata.d.ts +50 -0
- package/src/view/observer/domeventdata.js +5 -30
- package/src/view/observer/domeventobserver.d.ts +69 -0
- package/src/view/observer/domeventobserver.js +19 -21
- package/src/view/observer/fakeselectionobserver.d.ts +46 -0
- package/src/view/observer/fakeselectionobserver.js +2 -15
- package/src/view/observer/focusobserver.d.ts +82 -0
- package/src/view/observer/focusobserver.js +14 -40
- package/src/view/observer/inputobserver.d.ts +86 -0
- package/src/view/observer/inputobserver.js +18 -64
- package/src/view/observer/keyobserver.d.ts +67 -0
- package/src/view/observer/keyobserver.js +8 -42
- package/src/view/observer/mouseobserver.d.ts +89 -0
- package/src/view/observer/mouseobserver.js +8 -28
- package/src/view/observer/mutationobserver.d.ts +82 -0
- package/src/view/observer/mutationobserver.js +7 -37
- package/src/view/observer/observer.d.ts +84 -0
- package/src/view/observer/observer.js +12 -25
- package/src/view/observer/selectionobserver.d.ts +143 -0
- package/src/view/observer/selectionobserver.js +9 -99
- package/src/view/observer/tabobserver.d.ts +42 -0
- package/src/view/observer/tabobserver.js +0 -14
- package/src/view/placeholder.d.ts +85 -0
- package/src/view/placeholder.js +26 -43
- package/src/view/position.d.ts +189 -0
- package/src/view/position.js +36 -83
- package/src/view/range.d.ts +279 -0
- package/src/view/range.js +79 -122
- package/src/view/rawelement.d.ts +73 -0
- package/src/view/rawelement.js +34 -48
- package/src/view/renderer.d.ts +265 -0
- package/src/view/renderer.js +105 -193
- package/src/view/rooteditableelement.d.ts +41 -0
- package/src/view/rooteditableelement.js +12 -40
- package/src/view/selection.d.ts +375 -0
- package/src/view/selection.js +79 -153
- package/src/view/styles/background.d.ts +33 -0
- package/src/view/styles/background.js +14 -12
- package/src/view/styles/border.d.ts +43 -0
- package/src/view/styles/border.js +58 -48
- package/src/view/styles/margin.d.ts +29 -0
- package/src/view/styles/margin.js +13 -11
- package/src/view/styles/padding.d.ts +29 -0
- package/src/view/styles/padding.js +13 -11
- package/src/view/styles/utils.d.ts +93 -0
- package/src/view/styles/utils.js +22 -48
- package/src/view/stylesmap.d.ts +675 -0
- package/src/view/stylesmap.js +249 -244
- package/src/view/text.d.ts +74 -0
- package/src/view/text.js +16 -46
- package/src/view/textproxy.d.ts +97 -0
- package/src/view/textproxy.js +10 -59
- package/src/view/treewalker.d.ts +195 -0
- package/src/view/treewalker.js +43 -106
- package/src/view/typecheckable.d.ts +401 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +28 -62
- package/src/view/upcastwriter.d.ts +328 -0
- package/src/view/upcastwriter.js +124 -134
- package/src/view/view.d.ts +327 -0
- package/src/view/view.js +79 -150
|
@@ -9,11 +9,20 @@ import { CKEditorError, EmitterMixin, EventInfo, toArray } from '@ckeditor/ckedi
|
|
|
9
9
|
import BubblingEventInfo from './bubblingeventinfo';
|
|
10
10
|
const contextsSymbol = Symbol('bubbling contexts');
|
|
11
11
|
/**
|
|
12
|
-
* Bubbling emitter mixin for the view document as described in the
|
|
13
|
-
* {@link ~BubblingEmitter} interface.
|
|
12
|
+
* Bubbling emitter mixin for the view document as described in the {@link ~BubblingEmitter} interface.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
14
|
+
* This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
|
|
15
|
+
* The base class must implement {@link module:utils/emittermixin~Emitter} interface.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* class BaseClass extends EmitterMixin() {
|
|
19
|
+
* // ...
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* class MyClass extends BubblingEmitterMixin( BaseClass ) {
|
|
23
|
+
* // This class derives from `BaseClass` and implements the `BubblingEmitter` interface.
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
17
26
|
*/
|
|
18
27
|
export default function BubblingEmitterMixin(base) {
|
|
19
28
|
class Mixin extends base {
|
|
@@ -100,25 +109,26 @@ export default function BubblingEmitterMixin(base) {
|
|
|
100
109
|
BubblingEmitterMixin[key] = mixin.prototype[key];
|
|
101
110
|
});
|
|
102
111
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Update the event info bubbling fields.
|
|
114
|
+
*
|
|
115
|
+
* @param eventInfo The event info object to update.
|
|
116
|
+
* @param eventPhase The current event phase.
|
|
117
|
+
* @param currentTarget The current bubbling target.
|
|
118
|
+
*/
|
|
108
119
|
function updateEventInfo(eventInfo, eventPhase, currentTarget) {
|
|
109
120
|
if (eventInfo instanceof BubblingEventInfo) {
|
|
110
121
|
eventInfo._eventPhase = eventPhase;
|
|
111
122
|
eventInfo._currentTarget = currentTarget;
|
|
112
123
|
}
|
|
113
124
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// @returns {Boolean} True if event stop was called.
|
|
125
|
+
/**
|
|
126
|
+
* Fires the listener for the specified context. Returns `true` if event was stopped.
|
|
127
|
+
*
|
|
128
|
+
* @param eventInfo The `EventInfo` object.
|
|
129
|
+
* @param eventArgs Additional arguments to be passed to the callbacks.
|
|
130
|
+
* @returns True if event stop was called.
|
|
131
|
+
*/
|
|
122
132
|
function fireListenerFor(eventContexts, context, eventInfo, ...eventArgs) {
|
|
123
133
|
const emitter = typeof context == 'string' ? eventContexts.get(context) : getCustomContext(eventContexts, context);
|
|
124
134
|
if (!emitter) {
|
|
@@ -127,12 +137,9 @@ function fireListenerFor(eventContexts, context, eventInfo, ...eventArgs) {
|
|
|
127
137
|
emitter.fire(eventInfo, ...eventArgs);
|
|
128
138
|
return eventInfo.stop.called;
|
|
129
139
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// @param {Map.<String|Function, module:utils/emittermixin~Emitter>} eventContexts
|
|
134
|
-
// @param {module:engine/view/node~Node} node
|
|
135
|
-
// @returns {module:utils/emittermixin~Emitter|null}
|
|
140
|
+
/**
|
|
141
|
+
* Returns an emitter for a specified view node.
|
|
142
|
+
*/
|
|
136
143
|
function getCustomContext(eventContexts, node) {
|
|
137
144
|
for (const [context, emitter] of eventContexts) {
|
|
138
145
|
if (typeof context == 'function' && context(node)) {
|
|
@@ -141,14 +148,18 @@ function getCustomContext(eventContexts, node) {
|
|
|
141
148
|
}
|
|
142
149
|
return null;
|
|
143
150
|
}
|
|
144
|
-
|
|
151
|
+
/**
|
|
152
|
+
* Returns bubbling contexts map for the source (emitter).
|
|
153
|
+
*/
|
|
145
154
|
function getBubblingContexts(source) {
|
|
146
155
|
if (!source[contextsSymbol]) {
|
|
147
156
|
source[contextsSymbol] = new Map();
|
|
148
157
|
}
|
|
149
158
|
return source[contextsSymbol];
|
|
150
159
|
}
|
|
151
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Returns the deeper parent element for the range.
|
|
162
|
+
*/
|
|
152
163
|
function getDeeperRangeParent(range) {
|
|
153
164
|
if (!range) {
|
|
154
165
|
return null;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 engine/view/observer/bubblingeventinfo
|
|
7
|
+
*/
|
|
8
|
+
import { EventInfo } from '@ckeditor/ckeditor5-utils';
|
|
9
|
+
import type Document from '../document';
|
|
10
|
+
import type Node from '../node';
|
|
11
|
+
import type Range from '../range';
|
|
12
|
+
/**
|
|
13
|
+
* The event object passed to bubbling event callbacks. It is used to provide information about the event as well as a tool to
|
|
14
|
+
* manipulate it.
|
|
15
|
+
*/
|
|
16
|
+
export default class BubblingEventInfo<TName extends string = string, TReturn = unknown> extends EventInfo<TName, TReturn> {
|
|
17
|
+
/**
|
|
18
|
+
* The view range that the bubbling should start from.
|
|
19
|
+
*/
|
|
20
|
+
readonly startRange: Range;
|
|
21
|
+
/**
|
|
22
|
+
* The current event phase.
|
|
23
|
+
*/
|
|
24
|
+
private _eventPhase;
|
|
25
|
+
/**
|
|
26
|
+
* The current bubbling target.
|
|
27
|
+
*/
|
|
28
|
+
private _currentTarget;
|
|
29
|
+
/**
|
|
30
|
+
* @param source The emitter.
|
|
31
|
+
* @param name The event name.
|
|
32
|
+
* @param startRange The view range that the bubbling should start from.
|
|
33
|
+
*/
|
|
34
|
+
constructor(source: object, name: TName, startRange: Range);
|
|
35
|
+
/**
|
|
36
|
+
* The current event phase.
|
|
37
|
+
*/
|
|
38
|
+
get eventPhase(): EventPhase;
|
|
39
|
+
/**
|
|
40
|
+
* The current bubbling target.
|
|
41
|
+
*/
|
|
42
|
+
get currentTarget(): Document | Node | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The phase the event is in.
|
|
46
|
+
*/
|
|
47
|
+
export type EventPhase = 'none' | 'capturing' | 'atTarget' | 'bubbling';
|
|
@@ -9,53 +9,27 @@ import { EventInfo } from '@ckeditor/ckeditor5-utils';
|
|
|
9
9
|
/**
|
|
10
10
|
* The event object passed to bubbling event callbacks. It is used to provide information about the event as well as a tool to
|
|
11
11
|
* manipulate it.
|
|
12
|
-
*
|
|
13
|
-
* @extends module:utils/eventinfo~EventInfo
|
|
14
12
|
*/
|
|
15
13
|
export default class BubblingEventInfo extends EventInfo {
|
|
16
14
|
/**
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
15
|
+
* @param source The emitter.
|
|
16
|
+
* @param name The event name.
|
|
17
|
+
* @param startRange The view range that the bubbling should start from.
|
|
20
18
|
*/
|
|
21
19
|
constructor(source, name, startRange) {
|
|
22
20
|
super(source, name);
|
|
23
|
-
/**
|
|
24
|
-
* The view range that the bubbling should start from.
|
|
25
|
-
*
|
|
26
|
-
* @readonly
|
|
27
|
-
* @member {module:engine/view/range~Range}
|
|
28
|
-
*/
|
|
29
21
|
this.startRange = startRange;
|
|
30
|
-
/**
|
|
31
|
-
* The current event phase.
|
|
32
|
-
*
|
|
33
|
-
* @protected
|
|
34
|
-
* @member {'none'|'capturing'|'atTarget'|'bubbling'}
|
|
35
|
-
*/
|
|
36
22
|
this._eventPhase = 'none';
|
|
37
|
-
/**
|
|
38
|
-
* The current bubbling target.
|
|
39
|
-
*
|
|
40
|
-
* @protected
|
|
41
|
-
* @member {module:engine/view/document~Document|module:engine/view/node~Node|null}
|
|
42
|
-
*/
|
|
43
23
|
this._currentTarget = null;
|
|
44
24
|
}
|
|
45
25
|
/**
|
|
46
26
|
* The current event phase.
|
|
47
|
-
*
|
|
48
|
-
* @readonly
|
|
49
|
-
* @member {'none'|'capturing'|'atTarget'|'bubbling'}
|
|
50
27
|
*/
|
|
51
28
|
get eventPhase() {
|
|
52
29
|
return this._eventPhase;
|
|
53
30
|
}
|
|
54
31
|
/**
|
|
55
32
|
* The current bubbling target.
|
|
56
|
-
*
|
|
57
|
-
* @readonly
|
|
58
|
-
* @member {module:engine/view/document~Document|module:engine/view/node~Node|null}
|
|
59
33
|
*/
|
|
60
34
|
get currentTarget() {
|
|
61
35
|
return this._currentTarget;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 engine/view/observer/clickobserver
|
|
7
|
+
*/
|
|
8
|
+
import DomEventObserver from './domeventobserver';
|
|
9
|
+
import type DomEventData from './domeventdata';
|
|
10
|
+
import type { BubblingEvent } from './bubblingemittermixin';
|
|
11
|
+
/**
|
|
12
|
+
* {@link module:engine/view/document~Document#event:click Click} event observer.
|
|
13
|
+
*
|
|
14
|
+
* Note that this observer is not available by default. To make it available it needs to be added to
|
|
15
|
+
* {@link module:engine/view/view~View view controller} by a {@link module:engine/view/view~View#addObserver} method.
|
|
16
|
+
*/
|
|
17
|
+
export default class ClickObserver extends DomEventObserver<'click'> {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
readonly domEventType: "click";
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
onDomEvent(domEvent: MouseEvent): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Fired when one of the editables has been clicked.
|
|
29
|
+
*
|
|
30
|
+
* Introduced by {@link module:engine/view/observer/clickobserver~ClickObserver}.
|
|
31
|
+
*
|
|
32
|
+
* Note that this event is not available by default. To make it available
|
|
33
|
+
* {@link module:engine/view/observer/clickobserver~ClickObserver} needs to be added
|
|
34
|
+
* to {@link module:engine/view/view~View} by a {@link module:engine/view/view~View#addObserver} method.
|
|
35
|
+
*
|
|
36
|
+
* @see module:engine/view/observer/clickobserver~ClickObserver
|
|
37
|
+
* @eventName click
|
|
38
|
+
* @param data Event data.
|
|
39
|
+
*/
|
|
40
|
+
export type ViewDocumentClickEvent = BubblingEvent<{
|
|
41
|
+
name: 'click';
|
|
42
|
+
args: [data: DomEventData<MouseEvent>];
|
|
43
|
+
}>;
|
|
@@ -10,30 +10,20 @@ import DomEventObserver from './domeventobserver';
|
|
|
10
10
|
* {@link module:engine/view/document~Document#event:click Click} event observer.
|
|
11
11
|
*
|
|
12
12
|
* Note that this observer is not available by default. To make it available it needs to be added to
|
|
13
|
-
* {@link module:engine/view/view~View view controller}
|
|
14
|
-
* by a {@link module:engine/view/view~View#addObserver} method.
|
|
15
|
-
*
|
|
16
|
-
* @extends module:engine/view/observer/domeventobserver~DomEventObserver
|
|
13
|
+
* {@link module:engine/view/view~View view controller} by a {@link module:engine/view/view~View#addObserver} method.
|
|
17
14
|
*/
|
|
18
15
|
export default class ClickObserver extends DomEventObserver {
|
|
19
|
-
constructor(
|
|
20
|
-
super(
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
21
|
this.domEventType = 'click';
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
23
26
|
onDomEvent(domEvent) {
|
|
24
27
|
this.fire(domEvent.type, domEvent);
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Fired when one of the editables has been clicked.
|
|
29
|
-
*
|
|
30
|
-
* Introduced by {@link module:engine/view/observer/clickobserver~ClickObserver}.
|
|
31
|
-
*
|
|
32
|
-
* Note that this event is not available by default. To make it available
|
|
33
|
-
* {@link module:engine/view/observer/clickobserver~ClickObserver} needs to be added
|
|
34
|
-
* to {@link module:engine/view/view~View} by a {@link module:engine/view/view~View#addObserver} method.
|
|
35
|
-
*
|
|
36
|
-
* @see module:engine/view/observer/clickobserver~ClickObserver
|
|
37
|
-
* @event module:engine/view/document~Document#event:click
|
|
38
|
-
* @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
|
|
39
|
-
*/
|
|
@@ -0,0 +1,82 @@
|
|
|
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 engine/view/observer/compositionobserver
|
|
7
|
+
*/
|
|
8
|
+
import DomEventObserver from './domeventobserver';
|
|
9
|
+
import type View from '../view';
|
|
10
|
+
import type DomEventData from './domeventdata';
|
|
11
|
+
/**
|
|
12
|
+
* {@link module:engine/view/document~Document#event:compositionstart Compositionstart},
|
|
13
|
+
* {@link module:engine/view/document~Document#event:compositionupdate compositionupdate} and
|
|
14
|
+
* {@link module:engine/view/document~Document#event:compositionend compositionend} events observer.
|
|
15
|
+
*
|
|
16
|
+
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
|
|
17
|
+
*/
|
|
18
|
+
export default class CompositionObserver extends DomEventObserver<'compositionstart' | 'compositionupdate' | 'compositionend'> {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
readonly domEventType: readonly ["compositionstart", "compositionupdate", "compositionend"];
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
constructor(view: View);
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
onDomEvent(domEvent: CompositionEvent): void;
|
|
31
|
+
}
|
|
32
|
+
export interface CompositionEventData extends DomEventData<CompositionEvent> {
|
|
33
|
+
data: string | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fired when composition starts inside one of the editables.
|
|
37
|
+
*
|
|
38
|
+
* Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
|
|
39
|
+
*
|
|
40
|
+
* Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
|
|
41
|
+
* {@link module:engine/view/view~View} this event is available by default.
|
|
42
|
+
*
|
|
43
|
+
* @see module:engine/view/observer/compositionobserver~CompositionObserver
|
|
44
|
+
* @eventName compositionstart
|
|
45
|
+
* @param data Event data.
|
|
46
|
+
*/
|
|
47
|
+
export type ViewDocumentCompositionStartEvent = {
|
|
48
|
+
name: 'compositionstart';
|
|
49
|
+
args: [data: CompositionEventData];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Fired when composition is updated inside one of the editables.
|
|
53
|
+
*
|
|
54
|
+
* Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
|
|
55
|
+
*
|
|
56
|
+
* Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
|
|
57
|
+
* {@link module:engine/view/view~View} this event is available by default.
|
|
58
|
+
*
|
|
59
|
+
* @see module:engine/view/observer/compositionobserver~CompositionObserver
|
|
60
|
+
* @eventName compositionupdate
|
|
61
|
+
* @param data Event data.
|
|
62
|
+
*/
|
|
63
|
+
export type ViewDocumentCompositionUpdateEvent = {
|
|
64
|
+
name: 'compositionupdate';
|
|
65
|
+
args: [data: CompositionEventData];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Fired when composition ends inside one of the editables.
|
|
69
|
+
*
|
|
70
|
+
* Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
|
|
71
|
+
*
|
|
72
|
+
* Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
|
|
73
|
+
* {@link module:engine/view/view~View} this event is available by default.
|
|
74
|
+
*
|
|
75
|
+
* @see module:engine/view/observer/compositionobserver~CompositionObserver
|
|
76
|
+
* @eventName compositionend
|
|
77
|
+
* @param data Event data.
|
|
78
|
+
*/
|
|
79
|
+
export type ViewDocumentCompositionEndEvent = {
|
|
80
|
+
name: 'compositionend';
|
|
81
|
+
args: [data: CompositionEventData];
|
|
82
|
+
};
|
|
@@ -12,16 +12,20 @@ import DomEventObserver from './domeventobserver';
|
|
|
12
12
|
* {@link module:engine/view/document~Document#event:compositionend compositionend} events observer.
|
|
13
13
|
*
|
|
14
14
|
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
|
|
15
|
-
*
|
|
16
|
-
* @extends module:engine/view/observer/domeventobserver~DomEventObserver
|
|
17
15
|
*/
|
|
18
16
|
export default class CompositionObserver extends DomEventObserver {
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
19
20
|
constructor(view) {
|
|
20
21
|
super(view);
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
21
25
|
this.domEventType = ['compositionstart', 'compositionupdate', 'compositionend'];
|
|
22
26
|
const document = this.document;
|
|
23
27
|
document.on('compositionstart', () => {
|
|
24
|
-
// @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
|
|
28
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
25
29
|
// @if CK_DEBUG_TYPING // console.log( '%c[CompositionObserver] ' +
|
|
26
30
|
// @if CK_DEBUG_TYPING // '┌───────────────────────────── isComposing = true ─────────────────────────────┐',
|
|
27
31
|
// @if CK_DEBUG_TYPING // 'font-weight: bold; color: green'
|
|
@@ -30,7 +34,7 @@ export default class CompositionObserver extends DomEventObserver {
|
|
|
30
34
|
document.isComposing = true;
|
|
31
35
|
}, { priority: 'low' });
|
|
32
36
|
document.on('compositionend', () => {
|
|
33
|
-
// @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
|
|
37
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
34
38
|
// @if CK_DEBUG_TYPING // console.log( '%c[CompositionObserver] ' +
|
|
35
39
|
// @if CK_DEBUG_TYPING // '└───────────────────────────── isComposing = false ─────────────────────────────┘',
|
|
36
40
|
// @if CK_DEBUG_TYPING // 'font-weight: bold; color: green'
|
|
@@ -39,51 +43,18 @@ export default class CompositionObserver extends DomEventObserver {
|
|
|
39
43
|
document.isComposing = false;
|
|
40
44
|
}, { priority: 'low' });
|
|
41
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @inheritDoc
|
|
48
|
+
*/
|
|
42
49
|
onDomEvent(domEvent) {
|
|
43
|
-
// @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
|
|
50
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
44
51
|
// @if CK_DEBUG_TYPING // console.group( `%c[CompositionObserver]%c ${ domEvent.type }`, 'color: green', '' );
|
|
45
52
|
// @if CK_DEBUG_TYPING // }
|
|
46
53
|
this.fire(domEvent.type, domEvent, {
|
|
47
54
|
data: domEvent.data
|
|
48
55
|
});
|
|
49
|
-
// @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
|
|
56
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
50
57
|
// @if CK_DEBUG_TYPING // console.groupEnd();
|
|
51
58
|
// @if CK_DEBUG_TYPING // }
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Fired when composition starts inside one of the editables.
|
|
56
|
-
*
|
|
57
|
-
* Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
|
|
58
|
-
*
|
|
59
|
-
* Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
|
|
60
|
-
* {@link module:engine/view/view~View} this event is available by default.
|
|
61
|
-
*
|
|
62
|
-
* @see module:engine/view/observer/compositionobserver~CompositionObserver
|
|
63
|
-
* @event module:engine/view/document~Document#event:compositionstart
|
|
64
|
-
* @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
|
|
65
|
-
*/
|
|
66
|
-
/**
|
|
67
|
-
* Fired when composition is updated inside one of the editables.
|
|
68
|
-
*
|
|
69
|
-
* Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
|
|
70
|
-
*
|
|
71
|
-
* Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
|
|
72
|
-
* {@link module:engine/view/view~View} this event is available by default.
|
|
73
|
-
*
|
|
74
|
-
* @see module:engine/view/observer/compositionobserver~CompositionObserver
|
|
75
|
-
* @event module:engine/view/document~Document#event:compositionupdate
|
|
76
|
-
* @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
|
|
77
|
-
*/
|
|
78
|
-
/**
|
|
79
|
-
* Fired when composition ends inside one of the editables.
|
|
80
|
-
*
|
|
81
|
-
* Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
|
|
82
|
-
*
|
|
83
|
-
* Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
|
|
84
|
-
* {@link module:engine/view/view~View} this event is available by default.
|
|
85
|
-
*
|
|
86
|
-
* @see module:engine/view/observer/compositionobserver~CompositionObserver
|
|
87
|
-
* @event module:engine/view/document~Document#event:compositionend
|
|
88
|
-
* @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
|
|
89
|
-
*/
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
import type Document from '../document';
|
|
6
|
+
import type Element from '../element';
|
|
7
|
+
import type View from '../view';
|
|
8
|
+
/**
|
|
9
|
+
* Information about a DOM event in context of the {@link module:engine/view/document~Document}.
|
|
10
|
+
* It wraps the native event, which usually should not be used as the wrapper contains
|
|
11
|
+
* additional data (like key code for keyboard events).
|
|
12
|
+
*
|
|
13
|
+
* @typeParam TEvent The type of DOM Event that this class represents.
|
|
14
|
+
*/
|
|
15
|
+
export default class DomEventData<TEvent extends Event = Event> {
|
|
16
|
+
/**
|
|
17
|
+
* Instance of the view controller.
|
|
18
|
+
*/
|
|
19
|
+
readonly view: View;
|
|
20
|
+
/**
|
|
21
|
+
* The instance of the document.
|
|
22
|
+
*/
|
|
23
|
+
readonly document: Document;
|
|
24
|
+
/**
|
|
25
|
+
* The DOM event.
|
|
26
|
+
*/
|
|
27
|
+
readonly domEvent: TEvent;
|
|
28
|
+
/**
|
|
29
|
+
* The DOM target.
|
|
30
|
+
*/
|
|
31
|
+
readonly domTarget: HTMLElement;
|
|
32
|
+
/**
|
|
33
|
+
* @param view The instance of the view controller.
|
|
34
|
+
* @param domEvent The DOM event.
|
|
35
|
+
* @param additionalData Additional properties that the instance should contain.
|
|
36
|
+
*/
|
|
37
|
+
constructor(view: View, domEvent: TEvent, additionalData?: object);
|
|
38
|
+
/**
|
|
39
|
+
* The tree view element representing the target.
|
|
40
|
+
*/
|
|
41
|
+
get target(): Element;
|
|
42
|
+
/**
|
|
43
|
+
* Prevents the native's event default action.
|
|
44
|
+
*/
|
|
45
|
+
preventDefault(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Stops native event propagation.
|
|
48
|
+
*/
|
|
49
|
+
stopPropagation(): void;
|
|
50
|
+
}
|
|
@@ -10,49 +10,24 @@ import { extend } from 'lodash-es';
|
|
|
10
10
|
* Information about a DOM event in context of the {@link module:engine/view/document~Document}.
|
|
11
11
|
* It wraps the native event, which usually should not be used as the wrapper contains
|
|
12
12
|
* additional data (like key code for keyboard events).
|
|
13
|
+
*
|
|
14
|
+
* @typeParam TEvent The type of DOM Event that this class represents.
|
|
13
15
|
*/
|
|
14
16
|
export default class DomEventData {
|
|
15
17
|
/**
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
18
|
+
* @param view The instance of the view controller.
|
|
19
|
+
* @param domEvent The DOM event.
|
|
20
|
+
* @param additionalData Additional properties that the instance should contain.
|
|
19
21
|
*/
|
|
20
22
|
constructor(view, domEvent, additionalData) {
|
|
21
|
-
/**
|
|
22
|
-
* Instance of the view controller.
|
|
23
|
-
*
|
|
24
|
-
* @readonly
|
|
25
|
-
* @member {module:engine/view/view~View} module:engine/view/observer/observer~Observer.DomEvent#view
|
|
26
|
-
*/
|
|
27
23
|
this.view = view;
|
|
28
|
-
/**
|
|
29
|
-
* The instance of the document.
|
|
30
|
-
*
|
|
31
|
-
* @readonly
|
|
32
|
-
* @member {module:engine/view/document~Document} module:engine/view/observer/observer~Observer.DomEvent#document
|
|
33
|
-
*/
|
|
34
24
|
this.document = view.document;
|
|
35
|
-
/**
|
|
36
|
-
* The DOM event.
|
|
37
|
-
*
|
|
38
|
-
* @readonly
|
|
39
|
-
* @member {Event} module:engine/view/observer/observer~Observer.DomEvent#domEvent
|
|
40
|
-
*/
|
|
41
25
|
this.domEvent = domEvent;
|
|
42
|
-
/**
|
|
43
|
-
* The DOM target.
|
|
44
|
-
*
|
|
45
|
-
* @readonly
|
|
46
|
-
* @member {HTMLElement} module:engine/view/observer/observer~Observer.DomEvent#target
|
|
47
|
-
*/
|
|
48
26
|
this.domTarget = domEvent.target;
|
|
49
27
|
extend(this, additionalData);
|
|
50
28
|
}
|
|
51
29
|
/**
|
|
52
30
|
* The tree view element representing the target.
|
|
53
|
-
*
|
|
54
|
-
* @readonly
|
|
55
|
-
* @type module:engine/view/element~Element
|
|
56
31
|
*/
|
|
57
32
|
get target() {
|
|
58
33
|
return this.view.domConverter.mapDomToView(this.domTarget);
|
|
@@ -0,0 +1,69 @@
|
|
|
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 engine/view/observer/domeventobserver
|
|
7
|
+
*/
|
|
8
|
+
import Observer from './observer';
|
|
9
|
+
import type { EventInfo } from '@ckeditor/ckeditor5-utils';
|
|
10
|
+
/**
|
|
11
|
+
* Base class for DOM event observers. This class handles
|
|
12
|
+
* {@link module:engine/view/observer/observer~Observer#observe adding} listeners to DOM elements,
|
|
13
|
+
* {@link module:engine/view/observer/observer~Observer#disable disabling} and
|
|
14
|
+
* {@link module:engine/view/observer/observer~Observer#enable re-enabling} events.
|
|
15
|
+
* Child class needs to define
|
|
16
|
+
* {@link module:engine/view/observer/domeventobserver~DomEventObserver#domEventType DOM event type} and
|
|
17
|
+
* {@link module:engine/view/observer/domeventobserver~DomEventObserver#onDomEvent callback}.
|
|
18
|
+
*
|
|
19
|
+
* For instance:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* class ClickObserver extends DomEventObserver<'click'> {
|
|
23
|
+
* // It can also be defined as a normal property in the constructor.
|
|
24
|
+
* get domEventType(): 'click' {
|
|
25
|
+
* return 'click';
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* onDomEvent( domEvent: MouseEvent ): void {
|
|
29
|
+
* this.fire( 'click', domEvent );
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @typeParam EventType DOM Event type name or an union of those.
|
|
35
|
+
* @typeParam AdditionalData Additional data passed along with the event.
|
|
36
|
+
*/
|
|
37
|
+
export default abstract class DomEventObserver<EventType extends keyof HTMLElementEventMap, AdditionalData extends object = object> extends Observer {
|
|
38
|
+
/**
|
|
39
|
+
* Type of the DOM event the observer should listen to. Array of types can be defined
|
|
40
|
+
* if the observer should listen to multiple DOM events.
|
|
41
|
+
*/
|
|
42
|
+
abstract get domEventType(): EventType | ReadonlyArray<EventType>;
|
|
43
|
+
/**
|
|
44
|
+
* If set to `true` DOM events will be listened on the capturing phase.
|
|
45
|
+
* Default value is `false`.
|
|
46
|
+
*/
|
|
47
|
+
useCapture: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Callback which should be called when the DOM event occurred. Note that the callback will not be called if
|
|
50
|
+
* observer {@link #isEnabled is not enabled}.
|
|
51
|
+
*
|
|
52
|
+
* @see #domEventType
|
|
53
|
+
*/
|
|
54
|
+
abstract onDomEvent(event: HTMLElementEventMap[EventType]): void;
|
|
55
|
+
/**
|
|
56
|
+
* @inheritDoc
|
|
57
|
+
*/
|
|
58
|
+
observe(domElement: HTMLElement): void;
|
|
59
|
+
/**
|
|
60
|
+
* Calls `Document#fire()` if observer {@link #isEnabled is enabled}.
|
|
61
|
+
*
|
|
62
|
+
* @see module:utils/emittermixin~Emitter#fire
|
|
63
|
+
* @param eventType The event type (name).
|
|
64
|
+
* @param domEvent The DOM event.
|
|
65
|
+
* @param additionalData The additional data which should extend the
|
|
66
|
+
* {@link module:engine/view/observer/domeventdata~DomEventData event data} object.
|
|
67
|
+
*/
|
|
68
|
+
fire(eventType: string | EventInfo, domEvent: Event, additionalData?: AdditionalData): void;
|
|
69
|
+
}
|