@ckeditor/ckeditor5-engine 0.0.0-internal-20241017.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 +4 -0
- package/LICENSE.md +21 -0
- package/README.md +36 -0
- package/dist/controller/datacontroller.d.ts +339 -0
- package/dist/controller/editingcontroller.d.ts +102 -0
- package/dist/conversion/conversion.d.ts +482 -0
- package/dist/conversion/conversionhelpers.d.ts +30 -0
- package/dist/conversion/downcastdispatcher.d.ts +566 -0
- package/dist/conversion/downcasthelpers.d.ts +1194 -0
- package/dist/conversion/mapper.d.ts +507 -0
- package/dist/conversion/modelconsumable.d.ts +205 -0
- package/dist/conversion/upcastdispatcher.d.ts +496 -0
- package/dist/conversion/upcasthelpers.d.ts +503 -0
- package/dist/conversion/viewconsumable.d.ts +373 -0
- package/dist/dataprocessor/basichtmlwriter.d.ts +22 -0
- package/dist/dataprocessor/dataprocessor.d.ts +65 -0
- package/dist/dataprocessor/htmldataprocessor.d.ts +80 -0
- package/dist/dataprocessor/htmlwriter.d.ts +20 -0
- package/dist/dataprocessor/xmldataprocessor.d.ts +94 -0
- package/dist/dev-utils/model.d.ts +130 -0
- package/dist/dev-utils/operationreplayer.d.ts +55 -0
- package/dist/dev-utils/utils.d.ts +41 -0
- package/dist/dev-utils/view.d.ts +324 -0
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +24 -0
- package/dist/index.css +49 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.js +37775 -0
- package/dist/index.js.map +1 -0
- package/dist/model/batch.d.ts +110 -0
- package/dist/model/differ.d.ts +511 -0
- package/dist/model/document.d.ts +278 -0
- package/dist/model/documentfragment.d.ts +204 -0
- package/dist/model/documentselection.d.ts +424 -0
- package/dist/model/element.d.ts +169 -0
- package/dist/model/history.d.ts +118 -0
- package/dist/model/item.d.ts +18 -0
- package/dist/model/liveposition.d.ts +81 -0
- package/dist/model/liverange.d.ts +106 -0
- package/dist/model/markercollection.d.ts +339 -0
- package/dist/model/model.d.ts +923 -0
- package/dist/model/node.d.ts +259 -0
- package/dist/model/nodelist.d.ts +95 -0
- package/dist/model/operation/attributeoperation.d.ts +107 -0
- package/dist/model/operation/detachoperation.d.ts +64 -0
- package/dist/model/operation/insertoperation.d.ts +94 -0
- package/dist/model/operation/markeroperation.d.ts +95 -0
- package/dist/model/operation/mergeoperation.d.ts +104 -0
- package/dist/model/operation/moveoperation.d.ts +100 -0
- package/dist/model/operation/nooperation.d.ts +42 -0
- package/dist/model/operation/operation.d.ts +100 -0
- package/dist/model/operation/operationfactory.d.ts +22 -0
- package/dist/model/operation/renameoperation.d.ts +87 -0
- package/dist/model/operation/rootattributeoperation.d.ts +102 -0
- package/dist/model/operation/rootoperation.d.ts +80 -0
- package/dist/model/operation/splitoperation.d.ts +113 -0
- package/dist/model/operation/transform.d.ts +104 -0
- package/dist/model/operation/utils.d.ts +75 -0
- package/dist/model/position.d.ts +542 -0
- package/dist/model/range.d.ts +462 -0
- package/dist/model/rootelement.d.ts +64 -0
- package/dist/model/schema.d.ts +1334 -0
- package/dist/model/selection.d.ts +486 -0
- package/dist/model/text.d.ts +70 -0
- package/dist/model/textproxy.d.ts +148 -0
- package/dist/model/treewalker.d.ts +190 -0
- package/dist/model/typecheckable.d.ts +289 -0
- package/dist/model/utils/autoparagraphing.d.ts +41 -0
- package/dist/model/utils/deletecontent.d.ts +62 -0
- package/dist/model/utils/getselectedcontent.d.ts +34 -0
- package/dist/model/utils/insertcontent.d.ts +50 -0
- package/dist/model/utils/insertobject.d.ts +51 -0
- package/dist/model/utils/modifyselection.d.ts +52 -0
- package/dist/model/utils/selection-post-fixer.d.ts +78 -0
- package/dist/model/writer.d.ts +855 -0
- package/dist/view/attributeelement.d.ts +112 -0
- package/dist/view/containerelement.d.ts +53 -0
- package/dist/view/datatransfer.d.ts +83 -0
- package/dist/view/document.d.ts +188 -0
- package/dist/view/documentfragment.d.ts +157 -0
- package/dist/view/documentselection.d.ts +310 -0
- package/dist/view/domconverter.d.ts +665 -0
- package/dist/view/downcastwriter.d.ts +1000 -0
- package/dist/view/editableelement.d.ts +66 -0
- package/dist/view/element.d.ts +472 -0
- package/dist/view/elementdefinition.d.ts +91 -0
- package/dist/view/emptyelement.d.ts +45 -0
- package/dist/view/filler.d.ts +115 -0
- package/dist/view/item.d.ts +18 -0
- package/dist/view/matcher.d.ts +490 -0
- package/dist/view/node.d.ts +166 -0
- package/dist/view/observer/arrowkeysobserver.d.ts +49 -0
- package/dist/view/observer/bubblingemittermixin.d.ts +170 -0
- package/dist/view/observer/bubblingeventinfo.d.ts +51 -0
- package/dist/view/observer/clickobserver.d.ts +47 -0
- package/dist/view/observer/compositionobserver.d.ts +86 -0
- package/dist/view/observer/domeventdata.d.ts +54 -0
- package/dist/view/observer/domeventobserver.d.ts +82 -0
- package/dist/view/observer/fakeselectionobserver.d.ts +51 -0
- package/dist/view/observer/focusobserver.d.ts +98 -0
- package/dist/view/observer/inputobserver.d.ts +90 -0
- package/dist/view/observer/keyobserver.d.ts +70 -0
- package/dist/view/observer/mouseobserver.d.ts +93 -0
- package/dist/view/observer/mutationobserver.d.ts +119 -0
- package/dist/view/observer/observer.d.ts +93 -0
- package/dist/view/observer/selectionobserver.d.ts +151 -0
- package/dist/view/observer/tabobserver.d.ts +50 -0
- package/dist/view/placeholder.d.ts +100 -0
- package/dist/view/position.d.ts +192 -0
- package/dist/view/range.d.ts +283 -0
- package/dist/view/rawelement.d.ts +77 -0
- package/dist/view/renderer.d.ts +281 -0
- package/dist/view/rooteditableelement.d.ts +45 -0
- package/dist/view/selection.d.ts +379 -0
- package/dist/view/styles/background.d.ts +37 -0
- package/dist/view/styles/border.d.ts +47 -0
- package/dist/view/styles/margin.d.ts +33 -0
- package/dist/view/styles/padding.d.ts +33 -0
- package/dist/view/styles/utils.d.ts +97 -0
- package/dist/view/stylesmap.d.ts +677 -0
- package/dist/view/text.d.ts +78 -0
- package/dist/view/textproxy.d.ts +101 -0
- package/dist/view/treewalker.d.ts +199 -0
- package/dist/view/typecheckable.d.ts +452 -0
- package/dist/view/uielement.d.ts +100 -0
- package/dist/view/upcastwriter.d.ts +421 -0
- package/dist/view/view.d.ts +488 -0
- package/package.json +49 -0
- package/src/controller/datacontroller.d.ts +335 -0
- package/src/controller/datacontroller.js +481 -0
- package/src/controller/editingcontroller.d.ts +98 -0
- package/src/controller/editingcontroller.js +191 -0
- package/src/conversion/conversion.d.ts +478 -0
- package/src/conversion/conversion.js +601 -0
- package/src/conversion/conversionhelpers.d.ts +26 -0
- package/src/conversion/conversionhelpers.js +32 -0
- package/src/conversion/downcastdispatcher.d.ts +562 -0
- package/src/conversion/downcastdispatcher.js +548 -0
- package/src/conversion/downcasthelpers.d.ts +1190 -0
- package/src/conversion/downcasthelpers.js +2161 -0
- package/src/conversion/mapper.d.ts +503 -0
- package/src/conversion/mapper.js +536 -0
- package/src/conversion/modelconsumable.d.ts +201 -0
- package/src/conversion/modelconsumable.js +333 -0
- package/src/conversion/upcastdispatcher.d.ts +492 -0
- package/src/conversion/upcastdispatcher.js +460 -0
- package/src/conversion/upcasthelpers.d.ts +499 -0
- package/src/conversion/upcasthelpers.js +943 -0
- package/src/conversion/viewconsumable.d.ts +369 -0
- package/src/conversion/viewconsumable.js +535 -0
- package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/src/dataprocessor/basichtmlwriter.js +20 -0
- package/src/dataprocessor/dataprocessor.d.ts +61 -0
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/src/dataprocessor/htmldataprocessor.js +96 -0
- package/src/dataprocessor/htmlwriter.d.ts +16 -0
- package/src/dataprocessor/htmlwriter.js +5 -0
- package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/src/dataprocessor/xmldataprocessor.js +108 -0
- package/src/dev-utils/model.d.ts +126 -0
- package/src/dev-utils/model.js +397 -0
- package/src/dev-utils/operationreplayer.d.ts +51 -0
- package/src/dev-utils/operationreplayer.js +112 -0
- package/src/dev-utils/utils.d.ts +37 -0
- package/src/dev-utils/utils.js +80 -0
- package/src/dev-utils/view.d.ts +320 -0
- package/src/dev-utils/view.js +970 -0
- package/src/index.d.ts +118 -0
- package/src/index.js +83 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/batch.js +96 -0
- package/src/model/differ.d.ts +507 -0
- package/src/model/differ.js +1285 -0
- package/src/model/document.d.ts +274 -0
- package/src/model/document.js +360 -0
- package/src/model/documentfragment.d.ts +200 -0
- package/src/model/documentfragment.js +306 -0
- package/src/model/documentselection.d.ts +420 -0
- package/src/model/documentselection.js +993 -0
- package/src/model/element.d.ts +165 -0
- package/src/model/element.js +281 -0
- package/src/model/history.d.ts +114 -0
- package/src/model/history.js +207 -0
- package/src/model/item.d.ts +14 -0
- package/src/model/item.js +5 -0
- package/src/model/liveposition.d.ts +77 -0
- package/src/model/liveposition.js +93 -0
- package/src/model/liverange.d.ts +102 -0
- package/src/model/liverange.js +120 -0
- package/src/model/markercollection.d.ts +335 -0
- package/src/model/markercollection.js +403 -0
- package/src/model/model.d.ts +919 -0
- package/src/model/model.js +838 -0
- package/src/model/node.d.ts +255 -0
- package/src/model/node.js +373 -0
- package/src/model/nodelist.d.ts +91 -0
- package/src/model/nodelist.js +170 -0
- package/src/model/operation/attributeoperation.d.ts +103 -0
- package/src/model/operation/attributeoperation.js +148 -0
- package/src/model/operation/detachoperation.d.ts +60 -0
- package/src/model/operation/detachoperation.js +77 -0
- package/src/model/operation/insertoperation.d.ts +90 -0
- package/src/model/operation/insertoperation.js +135 -0
- package/src/model/operation/markeroperation.d.ts +91 -0
- package/src/model/operation/markeroperation.js +107 -0
- package/src/model/operation/mergeoperation.d.ts +100 -0
- package/src/model/operation/mergeoperation.js +167 -0
- package/src/model/operation/moveoperation.d.ts +96 -0
- package/src/model/operation/moveoperation.js +164 -0
- package/src/model/operation/nooperation.d.ts +38 -0
- package/src/model/operation/nooperation.js +48 -0
- package/src/model/operation/operation.d.ts +96 -0
- package/src/model/operation/operation.js +59 -0
- package/src/model/operation/operationfactory.d.ts +18 -0
- package/src/model/operation/operationfactory.js +44 -0
- package/src/model/operation/renameoperation.d.ts +83 -0
- package/src/model/operation/renameoperation.js +115 -0
- package/src/model/operation/rootattributeoperation.d.ts +98 -0
- package/src/model/operation/rootattributeoperation.js +155 -0
- package/src/model/operation/rootoperation.d.ts +76 -0
- package/src/model/operation/rootoperation.js +90 -0
- package/src/model/operation/splitoperation.d.ts +109 -0
- package/src/model/operation/splitoperation.js +194 -0
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/transform.js +2119 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/operation/utils.js +217 -0
- package/src/model/position.d.ts +538 -0
- package/src/model/position.js +977 -0
- package/src/model/range.d.ts +458 -0
- package/src/model/range.js +872 -0
- package/src/model/rootelement.d.ts +60 -0
- package/src/model/rootelement.js +74 -0
- package/src/model/schema.d.ts +1330 -0
- package/src/model/schema.js +1524 -0
- package/src/model/selection.d.ts +482 -0
- package/src/model/selection.js +789 -0
- package/src/model/text.d.ts +66 -0
- package/src/model/text.js +85 -0
- package/src/model/textproxy.d.ts +144 -0
- package/src/model/textproxy.js +189 -0
- package/src/model/treewalker.d.ts +186 -0
- package/src/model/treewalker.js +244 -0
- package/src/model/typecheckable.d.ts +285 -0
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.d.ts +37 -0
- package/src/model/utils/autoparagraphing.js +63 -0
- package/src/model/utils/deletecontent.d.ts +58 -0
- package/src/model/utils/deletecontent.js +488 -0
- package/src/model/utils/getselectedcontent.d.ts +30 -0
- package/src/model/utils/getselectedcontent.js +125 -0
- package/src/model/utils/insertcontent.d.ts +46 -0
- package/src/model/utils/insertcontent.js +661 -0
- package/src/model/utils/insertobject.d.ts +47 -0
- package/src/model/utils/insertobject.js +135 -0
- package/src/model/utils/modifyselection.d.ts +48 -0
- package/src/model/utils/modifyselection.js +186 -0
- package/src/model/utils/selection-post-fixer.d.ts +74 -0
- package/src/model/utils/selection-post-fixer.js +260 -0
- package/src/model/writer.d.ts +851 -0
- package/src/model/writer.js +1306 -0
- package/src/view/attributeelement.d.ts +108 -0
- package/src/view/attributeelement.js +185 -0
- package/src/view/containerelement.d.ts +49 -0
- package/src/view/containerelement.js +80 -0
- package/src/view/datatransfer.d.ts +79 -0
- package/src/view/datatransfer.js +98 -0
- package/src/view/document.d.ts +184 -0
- package/src/view/document.js +122 -0
- package/src/view/documentfragment.d.ts +153 -0
- package/src/view/documentfragment.js +234 -0
- package/src/view/documentselection.d.ts +306 -0
- package/src/view/documentselection.js +256 -0
- package/src/view/domconverter.d.ts +661 -0
- package/src/view/domconverter.js +1523 -0
- package/src/view/downcastwriter.d.ts +996 -0
- package/src/view/downcastwriter.js +1696 -0
- package/src/view/editableelement.d.ts +62 -0
- package/src/view/editableelement.js +62 -0
- package/src/view/element.d.ts +468 -0
- package/src/view/element.js +724 -0
- package/src/view/elementdefinition.d.ts +87 -0
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.d.ts +41 -0
- package/src/view/emptyelement.js +73 -0
- package/src/view/filler.d.ts +111 -0
- package/src/view/filler.js +150 -0
- package/src/view/item.d.ts +14 -0
- package/src/view/item.js +5 -0
- package/src/view/matcher.d.ts +486 -0
- package/src/view/matcher.js +507 -0
- package/src/view/node.d.ts +162 -0
- package/src/view/node.js +226 -0
- package/src/view/observer/arrowkeysobserver.d.ts +45 -0
- package/src/view/observer/arrowkeysobserver.js +40 -0
- package/src/view/observer/bubblingemittermixin.d.ts +166 -0
- package/src/view/observer/bubblingemittermixin.js +172 -0
- package/src/view/observer/bubblingeventinfo.d.ts +47 -0
- package/src/view/observer/bubblingeventinfo.js +37 -0
- package/src/view/observer/clickobserver.d.ts +43 -0
- package/src/view/observer/clickobserver.js +29 -0
- package/src/view/observer/compositionobserver.d.ts +82 -0
- package/src/view/observer/compositionobserver.js +62 -0
- package/src/view/observer/domeventdata.d.ts +50 -0
- package/src/view/observer/domeventdata.js +47 -0
- package/src/view/observer/domeventobserver.d.ts +78 -0
- package/src/view/observer/domeventobserver.js +84 -0
- package/src/view/observer/fakeselectionobserver.d.ts +47 -0
- package/src/view/observer/fakeselectionobserver.js +91 -0
- package/src/view/observer/focusobserver.d.ts +94 -0
- package/src/view/observer/focusobserver.js +116 -0
- package/src/view/observer/inputobserver.d.ts +86 -0
- package/src/view/observer/inputobserver.js +166 -0
- package/src/view/observer/keyobserver.d.ts +66 -0
- package/src/view/observer/keyobserver.js +39 -0
- package/src/view/observer/mouseobserver.d.ts +89 -0
- package/src/view/observer/mouseobserver.js +29 -0
- package/src/view/observer/mutationobserver.d.ts +115 -0
- package/src/view/observer/mutationobserver.js +203 -0
- package/src/view/observer/observer.d.ts +89 -0
- package/src/view/observer/observer.js +84 -0
- package/src/view/observer/selectionobserver.d.ts +147 -0
- package/src/view/observer/selectionobserver.js +220 -0
- package/src/view/observer/tabobserver.d.ts +46 -0
- package/src/view/observer/tabobserver.js +42 -0
- package/src/view/placeholder.d.ts +96 -0
- package/src/view/placeholder.js +267 -0
- package/src/view/position.d.ts +188 -0
- package/src/view/position.js +322 -0
- package/src/view/range.d.ts +279 -0
- package/src/view/range.js +430 -0
- package/src/view/rawelement.d.ts +73 -0
- package/src/view/rawelement.js +105 -0
- package/src/view/renderer.d.ts +277 -0
- package/src/view/renderer.js +1056 -0
- package/src/view/rooteditableelement.d.ts +41 -0
- package/src/view/rooteditableelement.js +69 -0
- package/src/view/selection.d.ts +375 -0
- package/src/view/selection.js +559 -0
- package/src/view/styles/background.d.ts +33 -0
- package/src/view/styles/background.js +74 -0
- package/src/view/styles/border.d.ts +43 -0
- package/src/view/styles/border.js +316 -0
- package/src/view/styles/margin.d.ts +29 -0
- package/src/view/styles/margin.js +34 -0
- package/src/view/styles/padding.d.ts +29 -0
- package/src/view/styles/padding.js +34 -0
- package/src/view/styles/utils.d.ts +93 -0
- package/src/view/styles/utils.js +219 -0
- package/src/view/stylesmap.d.ts +673 -0
- package/src/view/stylesmap.js +762 -0
- package/src/view/text.d.ts +74 -0
- package/src/view/text.js +93 -0
- package/src/view/textproxy.d.ts +97 -0
- package/src/view/textproxy.js +124 -0
- package/src/view/treewalker.d.ts +195 -0
- package/src/view/treewalker.js +327 -0
- package/src/view/typecheckable.d.ts +448 -0
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +183 -0
- package/src/view/upcastwriter.d.ts +417 -0
- package/src/view/upcastwriter.js +359 -0
- package/src/view/view.d.ts +484 -0
- package/src/view/view.js +560 -0
- package/theme/placeholder.css +36 -0
- package/theme/renderer.css +9 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/mouseobserver
|
|
7
|
+
*/
|
|
8
|
+
import DomEventObserver from './domeventobserver.js';
|
|
9
|
+
/**
|
|
10
|
+
* Mouse events observer.
|
|
11
|
+
*
|
|
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} by {@link module:engine/view/view~View#addObserver} method.
|
|
14
|
+
*/
|
|
15
|
+
export default class MouseObserver extends DomEventObserver {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
this.domEventType = ['mousedown', 'mouseup', 'mouseover', 'mouseout'];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
onDomEvent(domEvent) {
|
|
27
|
+
this.fire(domEvent.type, domEvent);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/mutationobserver
|
|
7
|
+
*/
|
|
8
|
+
import Observer from './observer.js';
|
|
9
|
+
import type DomConverter from '../domconverter.js';
|
|
10
|
+
import type View from '../view.js';
|
|
11
|
+
import type ViewNode from '../node.js';
|
|
12
|
+
import type { ChangeType } from '../document.js';
|
|
13
|
+
/**
|
|
14
|
+
* Mutation observer's role is to watch for any DOM changes inside the editor that weren't
|
|
15
|
+
* done by the editor's {@link module:engine/view/renderer~Renderer} itself and reverting these changes.
|
|
16
|
+
*
|
|
17
|
+
* It does this by observing all mutations in the DOM, marking related view elements as changed and calling
|
|
18
|
+
* {@link module:engine/view/renderer~Renderer#render}. Because all mutated nodes are marked as
|
|
19
|
+
* "to be rendered" and the {@link module:engine/view/renderer~Renderer#render `render()`} method is called,
|
|
20
|
+
* all changes are reverted in the DOM (the DOM is synced with the editor's view structure).
|
|
21
|
+
*
|
|
22
|
+
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
|
|
23
|
+
*/
|
|
24
|
+
export default class MutationObserver extends Observer {
|
|
25
|
+
/**
|
|
26
|
+
* Reference to the {@link module:engine/view/view~View#domConverter}.
|
|
27
|
+
*/
|
|
28
|
+
readonly domConverter: DomConverter;
|
|
29
|
+
/**
|
|
30
|
+
* Native mutation observer config.
|
|
31
|
+
*/
|
|
32
|
+
private readonly _config;
|
|
33
|
+
/**
|
|
34
|
+
* Observed DOM elements.
|
|
35
|
+
*/
|
|
36
|
+
private readonly _domElements;
|
|
37
|
+
/**
|
|
38
|
+
* Native mutation observer.
|
|
39
|
+
*/
|
|
40
|
+
private _mutationObserver;
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
constructor(view: View);
|
|
45
|
+
/**
|
|
46
|
+
* Synchronously handles mutations and empties the queue.
|
|
47
|
+
*/
|
|
48
|
+
flush(): void;
|
|
49
|
+
/**
|
|
50
|
+
* @inheritDoc
|
|
51
|
+
*/
|
|
52
|
+
observe(domElement: HTMLElement): void;
|
|
53
|
+
/**
|
|
54
|
+
* @inheritDoc
|
|
55
|
+
*/
|
|
56
|
+
stopObserving(domElement: HTMLElement): void;
|
|
57
|
+
/**
|
|
58
|
+
* @inheritDoc
|
|
59
|
+
*/
|
|
60
|
+
enable(): void;
|
|
61
|
+
/**
|
|
62
|
+
* @inheritDoc
|
|
63
|
+
*/
|
|
64
|
+
disable(): void;
|
|
65
|
+
/**
|
|
66
|
+
* @inheritDoc
|
|
67
|
+
*/
|
|
68
|
+
destroy(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Handles mutations. Mark view elements to sync and call render.
|
|
71
|
+
*
|
|
72
|
+
* @param domMutations Array of native mutations.
|
|
73
|
+
*/
|
|
74
|
+
private _onMutations;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if mutation was generated by the browser inserting bogus br on the end of the block element.
|
|
77
|
+
* Such mutations are generated while pressing space or performing native spellchecker correction
|
|
78
|
+
* on the end of the block element in Firefox browser.
|
|
79
|
+
*
|
|
80
|
+
* @param mutation Native mutation object.
|
|
81
|
+
*/
|
|
82
|
+
private _isBogusBrMutation;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Event fired on DOM mutations detected.
|
|
86
|
+
*
|
|
87
|
+
* This event is introduced by {@link module:engine/view/observer/mutationobserver~MutationObserver} and available
|
|
88
|
+
* by default in all editor instances (attached by {@link module:engine/view/view~View}).
|
|
89
|
+
*
|
|
90
|
+
* @eventName module:engine/view/document~Document#mutations
|
|
91
|
+
* @param data Event data containing detailed information about the event.
|
|
92
|
+
*/
|
|
93
|
+
export type ViewDocumentMutationsEvent = {
|
|
94
|
+
name: 'mutations';
|
|
95
|
+
args: [data: MutationsEventData];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The value of {@link ~ViewDocumentMutationsEvent}.
|
|
99
|
+
*/
|
|
100
|
+
export type MutationsEventData = {
|
|
101
|
+
mutations: Array<MutationData>;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* A single entry in {@link ~MutationsEventData} mutations array.
|
|
105
|
+
*/
|
|
106
|
+
export type MutationData = {
|
|
107
|
+
/**
|
|
108
|
+
* Type of mutation detected.
|
|
109
|
+
*/
|
|
110
|
+
type: ChangeType;
|
|
111
|
+
/**
|
|
112
|
+
* The view node related to the detected mutation.
|
|
113
|
+
*/
|
|
114
|
+
node: ViewNode;
|
|
115
|
+
};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/mutationobserver
|
|
7
|
+
*/
|
|
8
|
+
/* globals window */
|
|
9
|
+
import Observer from './observer.js';
|
|
10
|
+
import { startsWithFiller } from '../filler.js';
|
|
11
|
+
import { isEqualWith } from 'lodash-es';
|
|
12
|
+
// @if CK_DEBUG_TYPING // const { _debouncedLine } = require( '../../dev-utils/utils.js' );
|
|
13
|
+
/**
|
|
14
|
+
* Mutation observer's role is to watch for any DOM changes inside the editor that weren't
|
|
15
|
+
* done by the editor's {@link module:engine/view/renderer~Renderer} itself and reverting these changes.
|
|
16
|
+
*
|
|
17
|
+
* It does this by observing all mutations in the DOM, marking related view elements as changed and calling
|
|
18
|
+
* {@link module:engine/view/renderer~Renderer#render}. Because all mutated nodes are marked as
|
|
19
|
+
* "to be rendered" and the {@link module:engine/view/renderer~Renderer#render `render()`} method is called,
|
|
20
|
+
* all changes are reverted in the DOM (the DOM is synced with the editor's view structure).
|
|
21
|
+
*
|
|
22
|
+
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
|
|
23
|
+
*/
|
|
24
|
+
export default class MutationObserver extends Observer {
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
constructor(view) {
|
|
29
|
+
super(view);
|
|
30
|
+
this._config = {
|
|
31
|
+
childList: true,
|
|
32
|
+
characterData: true,
|
|
33
|
+
subtree: true
|
|
34
|
+
};
|
|
35
|
+
this.domConverter = view.domConverter;
|
|
36
|
+
this._domElements = new Set();
|
|
37
|
+
this._mutationObserver = new window.MutationObserver(this._onMutations.bind(this));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Synchronously handles mutations and empties the queue.
|
|
41
|
+
*/
|
|
42
|
+
flush() {
|
|
43
|
+
this._onMutations(this._mutationObserver.takeRecords());
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @inheritDoc
|
|
47
|
+
*/
|
|
48
|
+
observe(domElement) {
|
|
49
|
+
this._domElements.add(domElement);
|
|
50
|
+
if (this.isEnabled) {
|
|
51
|
+
this._mutationObserver.observe(domElement, this._config);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @inheritDoc
|
|
56
|
+
*/
|
|
57
|
+
stopObserving(domElement) {
|
|
58
|
+
this._domElements.delete(domElement);
|
|
59
|
+
if (this.isEnabled) {
|
|
60
|
+
// Unfortunately, it is not possible to stop observing particular DOM element.
|
|
61
|
+
// In order to stop observing one of multiple DOM elements, we need to re-connect the mutation observer.
|
|
62
|
+
this._mutationObserver.disconnect();
|
|
63
|
+
for (const domElement of this._domElements) {
|
|
64
|
+
this._mutationObserver.observe(domElement, this._config);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @inheritDoc
|
|
70
|
+
*/
|
|
71
|
+
enable() {
|
|
72
|
+
super.enable();
|
|
73
|
+
for (const domElement of this._domElements) {
|
|
74
|
+
this._mutationObserver.observe(domElement, this._config);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @inheritDoc
|
|
79
|
+
*/
|
|
80
|
+
disable() {
|
|
81
|
+
super.disable();
|
|
82
|
+
this._mutationObserver.disconnect();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @inheritDoc
|
|
86
|
+
*/
|
|
87
|
+
destroy() {
|
|
88
|
+
super.destroy();
|
|
89
|
+
this._mutationObserver.disconnect();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Handles mutations. Mark view elements to sync and call render.
|
|
93
|
+
*
|
|
94
|
+
* @param domMutations Array of native mutations.
|
|
95
|
+
*/
|
|
96
|
+
_onMutations(domMutations) {
|
|
97
|
+
// As a result of this.flush() we can have an empty collection.
|
|
98
|
+
if (domMutations.length === 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const domConverter = this.domConverter;
|
|
102
|
+
// Use map and set for deduplication.
|
|
103
|
+
const mutatedTextNodes = new Set();
|
|
104
|
+
const elementsWithMutatedChildren = new Set();
|
|
105
|
+
// Handle `childList` mutations first, so we will be able to check if the `characterData` mutation is in the
|
|
106
|
+
// element with changed structure anyway.
|
|
107
|
+
for (const mutation of domMutations) {
|
|
108
|
+
const element = domConverter.mapDomToView(mutation.target);
|
|
109
|
+
if (!element) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
// Do not collect mutations from UIElements and RawElements.
|
|
113
|
+
if (element.is('uiElement') || element.is('rawElement')) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (mutation.type === 'childList' && !this._isBogusBrMutation(mutation)) {
|
|
117
|
+
elementsWithMutatedChildren.add(element);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Handle `characterData` mutations later, when we have the full list of nodes which changed structure.
|
|
121
|
+
for (const mutation of domMutations) {
|
|
122
|
+
const element = domConverter.mapDomToView(mutation.target);
|
|
123
|
+
// Do not collect mutations from UIElements and RawElements.
|
|
124
|
+
if (element && (element.is('uiElement') || element.is('rawElement'))) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (mutation.type === 'characterData') {
|
|
128
|
+
const text = domConverter.findCorrespondingViewText(mutation.target);
|
|
129
|
+
if (text && !elementsWithMutatedChildren.has(text.parent)) {
|
|
130
|
+
mutatedTextNodes.add(text);
|
|
131
|
+
}
|
|
132
|
+
// When we added first letter to the text node which had only inline filler, for the DOM it is mutation
|
|
133
|
+
// on text, but for the view, where filler text node did not exist, new text node was created, so we
|
|
134
|
+
// need to handle it as a 'children' mutation instead of 'text'.
|
|
135
|
+
else if (!text && startsWithFiller(mutation.target)) {
|
|
136
|
+
elementsWithMutatedChildren.add(domConverter.mapDomToView(mutation.target.parentNode));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Now we build the list of mutations to mark elements. We did not do it earlier to avoid marking the
|
|
141
|
+
// same node multiple times in case of duplication.
|
|
142
|
+
const mutations = [];
|
|
143
|
+
for (const textNode of mutatedTextNodes) {
|
|
144
|
+
mutations.push({ type: 'text', node: textNode });
|
|
145
|
+
}
|
|
146
|
+
for (const viewElement of elementsWithMutatedChildren) {
|
|
147
|
+
const domElement = domConverter.mapViewToDom(viewElement);
|
|
148
|
+
const viewChildren = Array.from(viewElement.getChildren());
|
|
149
|
+
const newViewChildren = Array.from(domConverter.domChildrenToView(domElement, { withChildren: false }));
|
|
150
|
+
// It may happen that as a result of many changes (sth was inserted and then removed),
|
|
151
|
+
// both elements haven't really changed. #1031
|
|
152
|
+
if (!isEqualWith(viewChildren, newViewChildren, sameNodes)) {
|
|
153
|
+
mutations.push({ type: 'children', node: viewElement });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// In case only non-relevant mutations were recorded it skips the event and force render (#5600).
|
|
157
|
+
if (mutations.length) {
|
|
158
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
159
|
+
// @if CK_DEBUG_TYPING // _debouncedLine();
|
|
160
|
+
// @if CK_DEBUG_TYPING // console.group( '%c[MutationObserver]%c Mutations detected',
|
|
161
|
+
// @if CK_DEBUG_TYPING // 'font-weight: bold; color: green', 'font-weight: bold'
|
|
162
|
+
// @if CK_DEBUG_TYPING // );
|
|
163
|
+
// @if CK_DEBUG_TYPING // }
|
|
164
|
+
this.document.fire('mutations', { mutations });
|
|
165
|
+
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
166
|
+
// @if CK_DEBUG_TYPING // console.groupEnd();
|
|
167
|
+
// @if CK_DEBUG_TYPING // }
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Checks if mutation was generated by the browser inserting bogus br on the end of the block element.
|
|
172
|
+
* Such mutations are generated while pressing space or performing native spellchecker correction
|
|
173
|
+
* on the end of the block element in Firefox browser.
|
|
174
|
+
*
|
|
175
|
+
* @param mutation Native mutation object.
|
|
176
|
+
*/
|
|
177
|
+
_isBogusBrMutation(mutation) {
|
|
178
|
+
let addedNode = null;
|
|
179
|
+
// Check if mutation added only one node on the end of its parent.
|
|
180
|
+
if (mutation.nextSibling === null && mutation.removedNodes.length === 0 && mutation.addedNodes.length == 1) {
|
|
181
|
+
addedNode = this.domConverter.domToView(mutation.addedNodes[0], {
|
|
182
|
+
withChildren: false
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return addedNode && addedNode.is('element', 'br');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function sameNodes(child1, child2) {
|
|
189
|
+
// First level of comparison (array of children vs array of children) – use the Lodash's default behavior.
|
|
190
|
+
if (Array.isArray(child1)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// Elements.
|
|
194
|
+
if (child1 === child2) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
// Texts.
|
|
198
|
+
else if (child1.is('$text') && child2.is('$text')) {
|
|
199
|
+
return child1.data === child2.data;
|
|
200
|
+
}
|
|
201
|
+
// Not matching types.
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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.js';
|
|
6
|
+
import type View from '../view.js';
|
|
7
|
+
declare const Observer_base: {
|
|
8
|
+
new (): import("@ckeditor/ckeditor5-utils").DomEmitter;
|
|
9
|
+
prototype: import("@ckeditor/ckeditor5-utils").DomEmitter;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Abstract base observer class. Observers are classes which listen to DOM events, do the preliminary
|
|
13
|
+
* processing and fire events on the {@link module:engine/view/document~Document} objects.
|
|
14
|
+
* Observers can also add features to the view, for instance by updating its status or marking elements
|
|
15
|
+
* which need a refresh on DOM events.
|
|
16
|
+
*/
|
|
17
|
+
export default abstract class Observer extends /* #__PURE__ */ Observer_base {
|
|
18
|
+
/**
|
|
19
|
+
* An instance of the view controller.
|
|
20
|
+
*/
|
|
21
|
+
readonly view: View;
|
|
22
|
+
/**
|
|
23
|
+
* A reference to the {@link module:engine/view/document~Document} object.
|
|
24
|
+
*/
|
|
25
|
+
readonly document: Document;
|
|
26
|
+
/**
|
|
27
|
+
* The state of the observer. If it is disabled, no events will be fired.
|
|
28
|
+
*/
|
|
29
|
+
private _isEnabled;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of the observer.
|
|
32
|
+
*/
|
|
33
|
+
constructor(view: View);
|
|
34
|
+
/**
|
|
35
|
+
* The state of the observer. If it is disabled, no events will be fired.
|
|
36
|
+
*/
|
|
37
|
+
get isEnabled(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Enables the observer. This method is called when the observer is registered to the
|
|
40
|
+
* {@link module:engine/view/view~View} and after {@link module:engine/view/view~View#forceRender rendering}
|
|
41
|
+
* (all observers are {@link #disable disabled} before rendering).
|
|
42
|
+
*
|
|
43
|
+
* A typical use case for disabling observers is that mutation observers need to be disabled for the rendering.
|
|
44
|
+
* However, a child class may not need to be disabled, so it can implement an empty method.
|
|
45
|
+
*
|
|
46
|
+
* @see module:engine/view/observer/observer~Observer#disable
|
|
47
|
+
*/
|
|
48
|
+
enable(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Disables the observer. This method is called before
|
|
51
|
+
* {@link module:engine/view/view~View#forceRender rendering} to prevent firing events during rendering.
|
|
52
|
+
*
|
|
53
|
+
* @see module:engine/view/observer/observer~Observer#enable
|
|
54
|
+
*/
|
|
55
|
+
disable(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Disables and destroys the observer, among others removes event listeners created by the observer.
|
|
58
|
+
*/
|
|
59
|
+
destroy(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Checks whether a given DOM event should be ignored (should not be turned into a synthetic view document event).
|
|
62
|
+
*
|
|
63
|
+
* Currently, an event will be ignored only if its target or any of its ancestors has the `data-cke-ignore-events` attribute.
|
|
64
|
+
* This attribute can be used inside the structures generated by
|
|
65
|
+
* {@link module:engine/view/downcastwriter~DowncastWriter#createUIElement `DowncastWriter#createUIElement()`} to ignore events
|
|
66
|
+
* fired within a UI that should be excluded from CKEditor 5's realms.
|
|
67
|
+
*
|
|
68
|
+
* @param domTarget The DOM event target to check (usually an element, sometimes a text node and
|
|
69
|
+
* potentially sometimes a document, too).
|
|
70
|
+
* @returns Whether this event should be ignored by the observer.
|
|
71
|
+
*/
|
|
72
|
+
checkShouldIgnoreEventFromTarget(domTarget: Node | null): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Starts observing given DOM element.
|
|
75
|
+
*
|
|
76
|
+
* @param domElement DOM element to observe.
|
|
77
|
+
* @param name The name of the related root element.
|
|
78
|
+
*/
|
|
79
|
+
abstract observe(domElement: HTMLElement, name: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Stops observing given DOM element.
|
|
82
|
+
*/
|
|
83
|
+
abstract stopObserving(domElement: HTMLElement): void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The constructor of {@link ~Observer} subclass.
|
|
87
|
+
*/
|
|
88
|
+
export type ObserverConstructor = new (view: View) => Observer;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/observer
|
|
7
|
+
*/
|
|
8
|
+
import { DomEmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base observer class. Observers are classes which listen to DOM events, do the preliminary
|
|
11
|
+
* processing and fire events on the {@link module:engine/view/document~Document} objects.
|
|
12
|
+
* Observers can also add features to the view, for instance by updating its status or marking elements
|
|
13
|
+
* which need a refresh on DOM events.
|
|
14
|
+
*/
|
|
15
|
+
export default class Observer extends /* #__PURE__ */ DomEmitterMixin() {
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of the observer.
|
|
18
|
+
*/
|
|
19
|
+
constructor(view) {
|
|
20
|
+
super();
|
|
21
|
+
/**
|
|
22
|
+
* The state of the observer. If it is disabled, no events will be fired.
|
|
23
|
+
*/
|
|
24
|
+
this._isEnabled = false;
|
|
25
|
+
this.view = view;
|
|
26
|
+
this.document = view.document;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The state of the observer. If it is disabled, no events will be fired.
|
|
30
|
+
*/
|
|
31
|
+
get isEnabled() {
|
|
32
|
+
return this._isEnabled;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Enables the observer. This method is called when the observer is registered to the
|
|
36
|
+
* {@link module:engine/view/view~View} and after {@link module:engine/view/view~View#forceRender rendering}
|
|
37
|
+
* (all observers are {@link #disable disabled} before rendering).
|
|
38
|
+
*
|
|
39
|
+
* A typical use case for disabling observers is that mutation observers need to be disabled for the rendering.
|
|
40
|
+
* However, a child class may not need to be disabled, so it can implement an empty method.
|
|
41
|
+
*
|
|
42
|
+
* @see module:engine/view/observer/observer~Observer#disable
|
|
43
|
+
*/
|
|
44
|
+
enable() {
|
|
45
|
+
this._isEnabled = true;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Disables the observer. This method is called before
|
|
49
|
+
* {@link module:engine/view/view~View#forceRender rendering} to prevent firing events during rendering.
|
|
50
|
+
*
|
|
51
|
+
* @see module:engine/view/observer/observer~Observer#enable
|
|
52
|
+
*/
|
|
53
|
+
disable() {
|
|
54
|
+
this._isEnabled = false;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Disables and destroys the observer, among others removes event listeners created by the observer.
|
|
58
|
+
*/
|
|
59
|
+
destroy() {
|
|
60
|
+
this.disable();
|
|
61
|
+
this.stopListening();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Checks whether a given DOM event should be ignored (should not be turned into a synthetic view document event).
|
|
65
|
+
*
|
|
66
|
+
* Currently, an event will be ignored only if its target or any of its ancestors has the `data-cke-ignore-events` attribute.
|
|
67
|
+
* This attribute can be used inside the structures generated by
|
|
68
|
+
* {@link module:engine/view/downcastwriter~DowncastWriter#createUIElement `DowncastWriter#createUIElement()`} to ignore events
|
|
69
|
+
* fired within a UI that should be excluded from CKEditor 5's realms.
|
|
70
|
+
*
|
|
71
|
+
* @param domTarget The DOM event target to check (usually an element, sometimes a text node and
|
|
72
|
+
* potentially sometimes a document, too).
|
|
73
|
+
* @returns Whether this event should be ignored by the observer.
|
|
74
|
+
*/
|
|
75
|
+
checkShouldIgnoreEventFromTarget(domTarget) {
|
|
76
|
+
if (domTarget && domTarget.nodeType === 3) {
|
|
77
|
+
domTarget = domTarget.parentNode;
|
|
78
|
+
}
|
|
79
|
+
if (!domTarget || domTarget.nodeType !== 1) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return domTarget.matches('[data-cke-ignore-events], [data-cke-ignore-events] *');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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/selectionobserver
|
|
7
|
+
*/
|
|
8
|
+
import Observer from './observer.js';
|
|
9
|
+
import MutationObserver from './mutationobserver.js';
|
|
10
|
+
import FocusObserver from './focusobserver.js';
|
|
11
|
+
import type View from '../view.js';
|
|
12
|
+
import type DocumentSelection from '../documentselection.js';
|
|
13
|
+
import type DomConverter from '../domconverter.js';
|
|
14
|
+
import type Selection from '../selection.js';
|
|
15
|
+
type DomSelection = globalThis.Selection;
|
|
16
|
+
/**
|
|
17
|
+
* Selection observer class observes selection changes in the document. If a selection changes on the document this
|
|
18
|
+
* observer checks if the DOM selection is different from the {@link module:engine/view/document~Document#selection view selection}.
|
|
19
|
+
* The selection observer fires {@link module:engine/view/document~Document#event:selectionChange} event only if
|
|
20
|
+
* a selection change was the only change in the document and the DOM selection is different from the view selection.
|
|
21
|
+
*
|
|
22
|
+
* This observer also manages the {@link module:engine/view/document~Document#isSelecting} property of the view document.
|
|
23
|
+
*
|
|
24
|
+
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
|
|
25
|
+
*/
|
|
26
|
+
export default class SelectionObserver extends Observer {
|
|
27
|
+
/**
|
|
28
|
+
* Instance of the mutation observer. Selection observer calls
|
|
29
|
+
* {@link module:engine/view/observer/mutationobserver~MutationObserver#flush} to ensure that the mutations will be handled
|
|
30
|
+
* before the {@link module:engine/view/document~Document#event:selectionChange} event is fired.
|
|
31
|
+
*/
|
|
32
|
+
readonly mutationObserver: MutationObserver;
|
|
33
|
+
/**
|
|
34
|
+
* Instance of the focus observer. Focus observer calls
|
|
35
|
+
* {@link module:engine/view/observer/focusobserver~FocusObserver#flush} to mark the latest focus change as complete.
|
|
36
|
+
*/
|
|
37
|
+
readonly focusObserver: FocusObserver;
|
|
38
|
+
/**
|
|
39
|
+
* Reference to the view {@link module:engine/view/documentselection~DocumentSelection} object used to compare
|
|
40
|
+
* new selection with it.
|
|
41
|
+
*/
|
|
42
|
+
readonly selection: DocumentSelection;
|
|
43
|
+
/**
|
|
44
|
+
* Reference to the {@link module:engine/view/view~View#domConverter}.
|
|
45
|
+
*/
|
|
46
|
+
readonly domConverter: DomConverter;
|
|
47
|
+
/**
|
|
48
|
+
* A set of documents which have added `selectionchange` listener to avoid adding a listener twice to the same
|
|
49
|
+
* document.
|
|
50
|
+
*/
|
|
51
|
+
private readonly _documents;
|
|
52
|
+
/**
|
|
53
|
+
* Fires debounced event `selectionChangeDone`. It uses `lodash#debounce` method to delay function call.
|
|
54
|
+
*/
|
|
55
|
+
private readonly _fireSelectionChangeDoneDebounced;
|
|
56
|
+
/**
|
|
57
|
+
* When called, starts clearing the {@link #_loopbackCounter} counter in time intervals. When the number of selection
|
|
58
|
+
* changes exceeds a certain limit within the interval of time, the observer will not fire `selectionChange` but warn about
|
|
59
|
+
* possible infinite selection loop.
|
|
60
|
+
*/
|
|
61
|
+
private readonly _clearInfiniteLoopInterval;
|
|
62
|
+
/**
|
|
63
|
+
* Unlocks the `isSelecting` state of the view document in case the selection observer did not record this fact
|
|
64
|
+
* correctly (for whatever reason). It is a safeguard (paranoid check), that returns document to the normal state
|
|
65
|
+
* after a certain period of time (debounced, postponed by each selectionchange event).
|
|
66
|
+
*/
|
|
67
|
+
private readonly _documentIsSelectingInactivityTimeoutDebounced;
|
|
68
|
+
/**
|
|
69
|
+
* Private property to check if the code does not enter infinite loop.
|
|
70
|
+
*/
|
|
71
|
+
private _loopbackCounter;
|
|
72
|
+
constructor(view: View);
|
|
73
|
+
/**
|
|
74
|
+
* @inheritDoc
|
|
75
|
+
*/
|
|
76
|
+
observe(domElement: HTMLElement): void;
|
|
77
|
+
/**
|
|
78
|
+
* @inheritDoc
|
|
79
|
+
*/
|
|
80
|
+
stopObserving(domElement: HTMLElement): void;
|
|
81
|
+
/**
|
|
82
|
+
* @inheritDoc
|
|
83
|
+
*/
|
|
84
|
+
destroy(): void;
|
|
85
|
+
private _reportInfiniteLoop;
|
|
86
|
+
/**
|
|
87
|
+
* Selection change listener. {@link module:engine/view/observer/mutationobserver~MutationObserver#flush Flush} mutations, check if
|
|
88
|
+
* a selection changes and fires {@link module:engine/view/document~Document#event:selectionChange} event on every change
|
|
89
|
+
* and {@link module:engine/view/document~Document#event:selectionChangeDone} when a selection stop changing.
|
|
90
|
+
*
|
|
91
|
+
* @param domDocument DOM document.
|
|
92
|
+
*/
|
|
93
|
+
private _handleSelectionChange;
|
|
94
|
+
/**
|
|
95
|
+
* Clears `SelectionObserver` internal properties connected with preventing infinite loop.
|
|
96
|
+
*/
|
|
97
|
+
private _clearInfiniteLoop;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The value of {@link ~ViewDocumentSelectionChangeEvent} and {@link ~ViewDocumentSelectionChangeDoneEvent} events.
|
|
101
|
+
*/
|
|
102
|
+
export type ViewDocumentSelectionEventData = {
|
|
103
|
+
/**
|
|
104
|
+
* Old View selection which is {@link module:engine/view/document~Document#selection}.
|
|
105
|
+
*/
|
|
106
|
+
oldSelection: DocumentSelection;
|
|
107
|
+
/**
|
|
108
|
+
* New View selection which is converted DOM selection.
|
|
109
|
+
*/
|
|
110
|
+
newSelection: Selection;
|
|
111
|
+
/**
|
|
112
|
+
* Native DOM selection.
|
|
113
|
+
*/
|
|
114
|
+
domSelection: DomSelection | null;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Fired when a selection has changed. This event is fired only when the selection change was the only change that happened
|
|
118
|
+
* in the document, and the old selection is different then the new selection.
|
|
119
|
+
*
|
|
120
|
+
* Introduced by {@link module:engine/view/observer/selectionobserver~SelectionObserver}.
|
|
121
|
+
*
|
|
122
|
+
* Note that because {@link module:engine/view/observer/selectionobserver~SelectionObserver} is attached by the
|
|
123
|
+
* {@link module:engine/view/view~View} this event is available by default.
|
|
124
|
+
*
|
|
125
|
+
* @see module:engine/view/observer/selectionobserver~SelectionObserver
|
|
126
|
+
* @eventName module:engine/view/document~Document#selectionChange
|
|
127
|
+
*/
|
|
128
|
+
export type ViewDocumentSelectionChangeEvent = {
|
|
129
|
+
name: 'selectionChange';
|
|
130
|
+
args: [ViewDocumentSelectionEventData];
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Fired when selection stops changing.
|
|
134
|
+
*
|
|
135
|
+
* Introduced by {@link module:engine/view/observer/selectionobserver~SelectionObserver}.
|
|
136
|
+
*
|
|
137
|
+
* Note that because {@link module:engine/view/observer/selectionobserver~SelectionObserver} is attached by the
|
|
138
|
+
* {@link module:engine/view/view~View} this event is available by default.
|
|
139
|
+
*
|
|
140
|
+
* @see module:engine/view/observer/selectionobserver~SelectionObserver
|
|
141
|
+
* @eventName module:engine/view/document~Document#selectionChangeDone
|
|
142
|
+
*/
|
|
143
|
+
export type ViewDocumentSelectionChangeDoneEvent = {
|
|
144
|
+
name: 'selectionChangeDone';
|
|
145
|
+
args: [ViewDocumentSelectionEventData];
|
|
146
|
+
};
|
|
147
|
+
export {};
|