@ckeditor/ckeditor5-engine 47.6.1 → 48.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/LICENSE.md +1 -1
- package/{src → dist}/engineconfig.d.ts +6 -15
- package/dist/index-editor.css +38 -15
- package/dist/index.css +37 -37
- package/dist/index.css.map +1 -1
- package/{src → dist}/index.d.ts +0 -1
- package/dist/index.js +588 -94
- package/dist/index.js.map +1 -1
- package/{src → dist}/model/model.d.ts +10 -4
- package/{src → dist}/model/selection.d.ts +1 -1
- package/{src → dist}/view/downcastwriter.d.ts +3 -2
- package/{src → dist}/view/element.d.ts +2 -2
- package/{src → dist}/view/matcher.d.ts +4 -2
- package/dist/view/styles/background.d.ts +18 -0
- package/{src → dist}/view/styles/border.d.ts +0 -12
- package/{src → dist}/view/styles/margin.d.ts +0 -13
- package/{src → dist}/view/styles/padding.d.ts +0 -13
- package/{src → dist}/view/styles/utils.d.ts +12 -0
- package/package.json +20 -39
- package/src/controller/datacontroller.js +0 -522
- package/src/controller/editingcontroller.js +0 -181
- package/src/conversion/conversion.js +0 -606
- package/src/conversion/conversionhelpers.js +0 -33
- package/src/conversion/downcastdispatcher.js +0 -563
- package/src/conversion/downcasthelpers.js +0 -2160
- package/src/conversion/mapper.js +0 -1050
- package/src/conversion/modelconsumable.js +0 -331
- package/src/conversion/upcastdispatcher.js +0 -470
- package/src/conversion/upcasthelpers.js +0 -952
- package/src/conversion/viewconsumable.js +0 -541
- package/src/dataprocessor/basichtmlwriter.js +0 -22
- package/src/dataprocessor/dataprocessor.js +0 -5
- package/src/dataprocessor/htmldataprocessor.js +0 -107
- package/src/dataprocessor/htmlwriter.js +0 -5
- package/src/dataprocessor/xmldataprocessor.js +0 -127
- package/src/dev-utils/model.js +0 -396
- package/src/dev-utils/operationreplayer.js +0 -116
- package/src/dev-utils/utils.js +0 -122
- package/src/dev-utils/view.js +0 -990
- package/src/engineconfig.js +0 -5
- package/src/index.js +0 -134
- package/src/legacyerrors.js +0 -17
- package/src/model/batch.js +0 -98
- package/src/model/differ.js +0 -1288
- package/src/model/document.js +0 -398
- package/src/model/documentfragment.js +0 -332
- package/src/model/documentselection.js +0 -1026
- package/src/model/element.js +0 -323
- package/src/model/history.js +0 -206
- package/src/model/item.js +0 -5
- package/src/model/liveposition.js +0 -93
- package/src/model/liverange.js +0 -121
- package/src/model/markercollection.js +0 -436
- package/src/model/model.js +0 -866
- package/src/model/node.js +0 -371
- package/src/model/nodelist.js +0 -244
- package/src/model/operation/attributeoperation.js +0 -172
- package/src/model/operation/detachoperation.js +0 -87
- package/src/model/operation/insertoperation.js +0 -153
- package/src/model/operation/markeroperation.js +0 -136
- package/src/model/operation/mergeoperation.js +0 -184
- package/src/model/operation/moveoperation.js +0 -179
- package/src/model/operation/nooperation.js +0 -48
- package/src/model/operation/operation.js +0 -78
- package/src/model/operation/operationfactory.js +0 -44
- package/src/model/operation/renameoperation.js +0 -128
- package/src/model/operation/rootattributeoperation.js +0 -173
- package/src/model/operation/rootoperation.js +0 -106
- package/src/model/operation/splitoperation.js +0 -214
- package/src/model/operation/transform.js +0 -2211
- package/src/model/operation/utils.js +0 -217
- package/src/model/position.js +0 -1041
- package/src/model/range.js +0 -880
- package/src/model/rootelement.js +0 -82
- package/src/model/schema.js +0 -1542
- package/src/model/selection.js +0 -814
- package/src/model/text.js +0 -92
- package/src/model/textproxy.js +0 -202
- package/src/model/treewalker.js +0 -313
- package/src/model/typecheckable.js +0 -16
- package/src/model/utils/autoparagraphing.js +0 -63
- package/src/model/utils/deletecontent.js +0 -509
- package/src/model/utils/getselectedcontent.js +0 -126
- package/src/model/utils/insertcontent.js +0 -750
- package/src/model/utils/insertobject.js +0 -135
- package/src/model/utils/modifyselection.js +0 -187
- package/src/model/utils/selection-post-fixer.js +0 -264
- package/src/model/writer.js +0 -1318
- package/src/view/attributeelement.js +0 -220
- package/src/view/containerelement.js +0 -91
- package/src/view/datatransfer.js +0 -106
- package/src/view/document.js +0 -139
- package/src/view/documentfragment.js +0 -251
- package/src/view/documentselection.js +0 -270
- package/src/view/domconverter.js +0 -1661
- package/src/view/downcastwriter.js +0 -1589
- package/src/view/editableelement.js +0 -74
- package/src/view/element.js +0 -1053
- package/src/view/elementdefinition.js +0 -5
- package/src/view/emptyelement.js +0 -83
- package/src/view/filler.js +0 -161
- package/src/view/item.js +0 -5
- package/src/view/matcher.js +0 -437
- package/src/view/node.js +0 -238
- package/src/view/observer/arrowkeysobserver.js +0 -40
- package/src/view/observer/bubblingemittermixin.js +0 -215
- package/src/view/observer/bubblingeventinfo.js +0 -49
- package/src/view/observer/clickobserver.js +0 -26
- package/src/view/observer/compositionobserver.js +0 -64
- package/src/view/observer/domeventdata.js +0 -63
- package/src/view/observer/domeventobserver.js +0 -81
- package/src/view/observer/fakeselectionobserver.js +0 -95
- package/src/view/observer/focusobserver.js +0 -166
- package/src/view/observer/inputobserver.js +0 -236
- package/src/view/observer/keyobserver.js +0 -36
- package/src/view/observer/mouseobserver.js +0 -26
- package/src/view/observer/mutationobserver.js +0 -219
- package/src/view/observer/observer.js +0 -92
- package/src/view/observer/pointerobserver.js +0 -26
- package/src/view/observer/selectionobserver.js +0 -318
- package/src/view/observer/tabobserver.js +0 -42
- package/src/view/observer/touchobserver.js +0 -26
- package/src/view/placeholder.js +0 -285
- package/src/view/position.js +0 -341
- package/src/view/range.js +0 -451
- package/src/view/rawelement.js +0 -115
- package/src/view/renderer.js +0 -1148
- package/src/view/rooteditableelement.js +0 -78
- package/src/view/selection.js +0 -594
- package/src/view/styles/background.d.ts +0 -33
- package/src/view/styles/background.js +0 -74
- package/src/view/styles/border.js +0 -316
- package/src/view/styles/margin.js +0 -34
- package/src/view/styles/padding.js +0 -34
- package/src/view/styles/utils.js +0 -219
- package/src/view/stylesmap.js +0 -941
- package/src/view/text.js +0 -110
- package/src/view/textproxy.js +0 -136
- package/src/view/tokenlist.js +0 -194
- package/src/view/treewalker.js +0 -389
- package/src/view/typecheckable.js +0 -19
- package/src/view/uielement.js +0 -194
- package/src/view/upcastwriter.js +0 -363
- package/src/view/view.js +0 -579
- package/theme/placeholder.css +0 -36
- package/theme/renderer.css +0 -9
- /package/{src → dist}/controller/datacontroller.d.ts +0 -0
- /package/{src → dist}/controller/editingcontroller.d.ts +0 -0
- /package/{src → dist}/conversion/conversion.d.ts +0 -0
- /package/{src → dist}/conversion/conversionhelpers.d.ts +0 -0
- /package/{src → dist}/conversion/downcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/downcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/mapper.d.ts +0 -0
- /package/{src → dist}/conversion/modelconsumable.d.ts +0 -0
- /package/{src → dist}/conversion/upcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/upcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/viewconsumable.d.ts +0 -0
- /package/{src → dist}/dataprocessor/basichtmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/dataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/xmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dev-utils/model.d.ts +0 -0
- /package/{src → dist}/dev-utils/operationreplayer.d.ts +0 -0
- /package/{src → dist}/dev-utils/utils.d.ts +0 -0
- /package/{src → dist}/dev-utils/view.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/model/batch.d.ts +0 -0
- /package/{src → dist}/model/differ.d.ts +0 -0
- /package/{src → dist}/model/document.d.ts +0 -0
- /package/{src → dist}/model/documentfragment.d.ts +0 -0
- /package/{src → dist}/model/documentselection.d.ts +0 -0
- /package/{src → dist}/model/element.d.ts +0 -0
- /package/{src → dist}/model/history.d.ts +0 -0
- /package/{src → dist}/model/item.d.ts +0 -0
- /package/{src → dist}/model/liveposition.d.ts +0 -0
- /package/{src → dist}/model/liverange.d.ts +0 -0
- /package/{src → dist}/model/markercollection.d.ts +0 -0
- /package/{src → dist}/model/node.d.ts +0 -0
- /package/{src → dist}/model/nodelist.d.ts +0 -0
- /package/{src → dist}/model/operation/attributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/detachoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/insertoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/markeroperation.d.ts +0 -0
- /package/{src → dist}/model/operation/mergeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/moveoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/nooperation.d.ts +0 -0
- /package/{src → dist}/model/operation/operation.d.ts +0 -0
- /package/{src → dist}/model/operation/operationfactory.d.ts +0 -0
- /package/{src → dist}/model/operation/renameoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootattributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/splitoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/transform.d.ts +0 -0
- /package/{src → dist}/model/operation/utils.d.ts +0 -0
- /package/{src → dist}/model/position.d.ts +0 -0
- /package/{src → dist}/model/range.d.ts +0 -0
- /package/{src → dist}/model/rootelement.d.ts +0 -0
- /package/{src → dist}/model/schema.d.ts +0 -0
- /package/{src → dist}/model/text.d.ts +0 -0
- /package/{src → dist}/model/textproxy.d.ts +0 -0
- /package/{src → dist}/model/treewalker.d.ts +0 -0
- /package/{src → dist}/model/typecheckable.d.ts +0 -0
- /package/{src → dist}/model/utils/autoparagraphing.d.ts +0 -0
- /package/{src → dist}/model/utils/deletecontent.d.ts +0 -0
- /package/{src → dist}/model/utils/getselectedcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertobject.d.ts +0 -0
- /package/{src → dist}/model/utils/modifyselection.d.ts +0 -0
- /package/{src → dist}/model/utils/selection-post-fixer.d.ts +0 -0
- /package/{src → dist}/model/writer.d.ts +0 -0
- /package/{src → dist}/view/attributeelement.d.ts +0 -0
- /package/{src → dist}/view/containerelement.d.ts +0 -0
- /package/{src → dist}/view/datatransfer.d.ts +0 -0
- /package/{src → dist}/view/document.d.ts +0 -0
- /package/{src → dist}/view/documentfragment.d.ts +0 -0
- /package/{src → dist}/view/documentselection.d.ts +0 -0
- /package/{src → dist}/view/domconverter.d.ts +0 -0
- /package/{src → dist}/view/editableelement.d.ts +0 -0
- /package/{src → dist}/view/elementdefinition.d.ts +0 -0
- /package/{src → dist}/view/emptyelement.d.ts +0 -0
- /package/{src → dist}/view/filler.d.ts +0 -0
- /package/{src → dist}/view/item.d.ts +0 -0
- /package/{src → dist}/view/node.d.ts +0 -0
- /package/{src → dist}/view/observer/arrowkeysobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingemittermixin.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingeventinfo.d.ts +0 -0
- /package/{src → dist}/view/observer/clickobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/compositionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventdata.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/fakeselectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/focusobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/inputobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/keyobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mouseobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mutationobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/observer.d.ts +0 -0
- /package/{src → dist}/view/observer/pointerobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/selectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/tabobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/touchobserver.d.ts +0 -0
- /package/{src → dist}/view/placeholder.d.ts +0 -0
- /package/{src → dist}/view/position.d.ts +0 -0
- /package/{src → dist}/view/range.d.ts +0 -0
- /package/{src → dist}/view/rawelement.d.ts +0 -0
- /package/{src → dist}/view/renderer.d.ts +0 -0
- /package/{src → dist}/view/rooteditableelement.d.ts +0 -0
- /package/{src → dist}/view/selection.d.ts +0 -0
- /package/{src → dist}/view/stylesmap.d.ts +0 -0
- /package/{src → dist}/view/text.d.ts +0 -0
- /package/{src → dist}/view/textproxy.d.ts +0 -0
- /package/{src → dist}/view/tokenlist.d.ts +0 -0
- /package/{src → dist}/view/treewalker.d.ts +0 -0
- /package/{src → dist}/view/typecheckable.d.ts +0 -0
- /package/{src → dist}/view/uielement.d.ts +0 -0
- /package/{src → dist}/view/upcastwriter.d.ts +0 -0
- /package/{src → dist}/view/view.d.ts +0 -0
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
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 { env } from '@ckeditor/ckeditor5-utils';
|
|
12
|
-
import { debounce } from 'es-toolkit/compat';
|
|
13
|
-
/**
|
|
14
|
-
* Selection observer class observes selection changes in the document. If a selection changes on the document this
|
|
15
|
-
* observer checks if the DOM selection is different from the {@link module:engine/view/document~ViewDocument#selection view selection}.
|
|
16
|
-
* The selection observer fires {@link module:engine/view/document~ViewDocument#event:selectionChange} event only if
|
|
17
|
-
* a selection change was the only change in the document and the DOM selection is different from the view selection.
|
|
18
|
-
*
|
|
19
|
-
* This observer also manages the {@link module:engine/view/document~ViewDocument#isSelecting} property of the view document.
|
|
20
|
-
*
|
|
21
|
-
* Note that this observer is attached by the {@link module:engine/view/view~EditingView} and is available by default.
|
|
22
|
-
*/
|
|
23
|
-
export class SelectionObserver extends Observer {
|
|
24
|
-
/**
|
|
25
|
-
* Instance of the mutation observer. Selection observer calls
|
|
26
|
-
* {@link module:engine/view/observer/mutationobserver~MutationObserver#flush} to ensure that the mutations will be handled
|
|
27
|
-
* before the {@link module:engine/view/document~ViewDocument#event:selectionChange} event is fired.
|
|
28
|
-
*/
|
|
29
|
-
mutationObserver;
|
|
30
|
-
/**
|
|
31
|
-
* Instance of the focus observer. Focus observer calls
|
|
32
|
-
* {@link module:engine/view/observer/focusobserver~FocusObserver#flush} to mark the latest focus change as complete.
|
|
33
|
-
*/
|
|
34
|
-
focusObserver;
|
|
35
|
-
/**
|
|
36
|
-
* Reference to the view {@link module:engine/view/documentselection~ViewDocumentSelection} object used to compare
|
|
37
|
-
* new selection with it.
|
|
38
|
-
*/
|
|
39
|
-
selection;
|
|
40
|
-
/**
|
|
41
|
-
* Reference to the {@link module:engine/view/view~EditingView#domConverter}.
|
|
42
|
-
*/
|
|
43
|
-
domConverter;
|
|
44
|
-
/**
|
|
45
|
-
* A set of documents which have added `selectionchange` listener to avoid adding a listener twice to the same
|
|
46
|
-
* document.
|
|
47
|
-
*/
|
|
48
|
-
_documents = new WeakSet();
|
|
49
|
-
/**
|
|
50
|
-
* Fires debounced event `selectionChangeDone`. It uses `es-toolkit#debounce` method to delay function call.
|
|
51
|
-
*/
|
|
52
|
-
_fireSelectionChangeDoneDebounced;
|
|
53
|
-
/**
|
|
54
|
-
* When called, starts clearing the {@link #_loopbackCounter} counter in time intervals. When the number of selection
|
|
55
|
-
* changes exceeds a certain limit within the interval of time, the observer will not fire `selectionChange` but warn about
|
|
56
|
-
* possible infinite selection loop.
|
|
57
|
-
*/
|
|
58
|
-
_clearInfiniteLoopInterval;
|
|
59
|
-
/**
|
|
60
|
-
* Unlocks the `isSelecting` state of the view document in case the selection observer did not record this fact
|
|
61
|
-
* correctly (for whatever reason). It is a safeguard (paranoid check), that returns document to the normal state
|
|
62
|
-
* after a certain period of time (debounced, postponed by each selectionchange event).
|
|
63
|
-
*/
|
|
64
|
-
_documentIsSelectingInactivityTimeoutDebounced;
|
|
65
|
-
/**
|
|
66
|
-
* Private property to check if the code does not enter infinite loop.
|
|
67
|
-
*/
|
|
68
|
-
_loopbackCounter = 0;
|
|
69
|
-
/**
|
|
70
|
-
* A set of DOM documents that have a pending selection change.
|
|
71
|
-
* Pending selection change is recorded while selection change event is detected on non focused editable.
|
|
72
|
-
*/
|
|
73
|
-
_pendingSelectionChange = new Set();
|
|
74
|
-
constructor(view) {
|
|
75
|
-
super(view);
|
|
76
|
-
this.mutationObserver = view.getObserver(MutationObserver);
|
|
77
|
-
this.focusObserver = view.getObserver(FocusObserver);
|
|
78
|
-
this.selection = this.document.selection;
|
|
79
|
-
this.domConverter = view.domConverter;
|
|
80
|
-
this._fireSelectionChangeDoneDebounced = debounce(data => {
|
|
81
|
-
this.document.fire('selectionChangeDone', data);
|
|
82
|
-
}, 200);
|
|
83
|
-
this._clearInfiniteLoopInterval = setInterval(() => this._clearInfiniteLoop(), 1000);
|
|
84
|
-
this._documentIsSelectingInactivityTimeoutDebounced = debounce(() => (this.document.isSelecting = false), 5000);
|
|
85
|
-
this.view.document.on('change:isFocused', (evt, name, isFocused) => {
|
|
86
|
-
if (isFocused && this._pendingSelectionChange.size) {
|
|
87
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
88
|
-
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'SelectionObserver',
|
|
89
|
-
// @if CK_DEBUG_TYPING // 'Flush pending selection change'
|
|
90
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
91
|
-
// @if CK_DEBUG_TYPING // }
|
|
92
|
-
// Iterate over a copy of set because it is modified in selection change handler.
|
|
93
|
-
for (const domDocument of Array.from(this._pendingSelectionChange)) {
|
|
94
|
-
this._handleSelectionChange(domDocument);
|
|
95
|
-
}
|
|
96
|
-
this._pendingSelectionChange.clear();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @inheritDoc
|
|
102
|
-
*/
|
|
103
|
-
observe(domElement) {
|
|
104
|
-
const domDocument = domElement.ownerDocument;
|
|
105
|
-
const startDocumentIsSelecting = () => {
|
|
106
|
-
this.document.isSelecting = true;
|
|
107
|
-
// Let's activate the safety timeout each time the document enters the "is selecting" state.
|
|
108
|
-
this._documentIsSelectingInactivityTimeoutDebounced();
|
|
109
|
-
};
|
|
110
|
-
const endDocumentIsSelecting = () => {
|
|
111
|
-
if (!this.document.isSelecting) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// Make sure that model selection is up-to-date at the end of selecting process.
|
|
115
|
-
// Sometimes `selectionchange` events could arrive after the `mouseup` event and that selection could be already outdated.
|
|
116
|
-
this._handleSelectionChange(domDocument);
|
|
117
|
-
this.document.isSelecting = false;
|
|
118
|
-
// The safety timeout can be canceled when the document leaves the "is selecting" state.
|
|
119
|
-
this._documentIsSelectingInactivityTimeoutDebounced.cancel();
|
|
120
|
-
};
|
|
121
|
-
// The document has the "is selecting" state while the user keeps making (extending) the selection
|
|
122
|
-
// (e.g. by holding the mouse button and moving the cursor). The state resets when they either released
|
|
123
|
-
// the mouse button or interrupted the process by pressing or releasing any key.
|
|
124
|
-
this.listenTo(domElement, 'selectstart', startDocumentIsSelecting, { priority: 'highest' });
|
|
125
|
-
this.listenTo(domElement, 'keydown', endDocumentIsSelecting, { priority: 'highest', useCapture: true });
|
|
126
|
-
this.listenTo(domElement, 'keyup', endDocumentIsSelecting, { priority: 'highest', useCapture: true });
|
|
127
|
-
// Add document-wide listeners only once. This method could be called for multiple editing roots.
|
|
128
|
-
if (this._documents.has(domDocument)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
// This listener is using capture mode to make sure that selection is upcasted before any other
|
|
132
|
-
// handler would like to check it and update (for example table multi cell selection).
|
|
133
|
-
this.listenTo(domDocument, 'mouseup', endDocumentIsSelecting, { priority: 'highest', useCapture: true });
|
|
134
|
-
this.listenTo(domDocument, 'selectionchange', () => {
|
|
135
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
136
|
-
// @if CK_DEBUG_TYPING // _debouncedLine();
|
|
137
|
-
// @if CK_DEBUG_TYPING // const domSelection = domDocument.defaultView!.getSelection();
|
|
138
|
-
// @if CK_DEBUG_TYPING // console.group( ..._buildLogMessage( this, 'SelectionObserver',
|
|
139
|
-
// @if CK_DEBUG_TYPING // 'selectionchange'
|
|
140
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
141
|
-
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'SelectionObserver',
|
|
142
|
-
// @if CK_DEBUG_TYPING // 'DOM Selection:',
|
|
143
|
-
// @if CK_DEBUG_TYPING // { node: domSelection!.anchorNode, offset: domSelection!.anchorOffset },
|
|
144
|
-
// @if CK_DEBUG_TYPING // { node: domSelection!.focusNode, offset: domSelection!.focusOffset }
|
|
145
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
146
|
-
// @if CK_DEBUG_TYPING // }
|
|
147
|
-
// The Renderer is disabled while composing on non-android browsers, so we can't update the view selection
|
|
148
|
-
// because the DOM and view tree drifted apart. Position mapping could fail because of it.
|
|
149
|
-
if (this.document.isComposing && !env.isAndroid) {
|
|
150
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
151
|
-
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'SelectionObserver',
|
|
152
|
-
// @if CK_DEBUG_TYPING // 'Selection change ignored (isComposing)'
|
|
153
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
154
|
-
// @if CK_DEBUG_TYPING // console.groupEnd();
|
|
155
|
-
// @if CK_DEBUG_TYPING // }
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
this._handleSelectionChange(domDocument);
|
|
159
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
160
|
-
// @if CK_DEBUG_TYPING // console.groupEnd();
|
|
161
|
-
// @if CK_DEBUG_TYPING // }
|
|
162
|
-
// Defer the safety timeout when the selection changes (e.g. the user keeps extending the selection
|
|
163
|
-
// using their mouse).
|
|
164
|
-
this._documentIsSelectingInactivityTimeoutDebounced();
|
|
165
|
-
});
|
|
166
|
-
// Update the model ViewDocumentSelection just after the Renderer and the SelectionObserver are locked.
|
|
167
|
-
// We do this synchronously (without waiting for the `selectionchange` DOM event) as browser updates
|
|
168
|
-
// the DOM selection (but not visually) to span the text that is under composition and could be replaced.
|
|
169
|
-
this.listenTo(this.view.document, 'compositionstart', () => {
|
|
170
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
171
|
-
// @if CK_DEBUG_TYPING // const domSelection = domDocument.defaultView!.getSelection();
|
|
172
|
-
// @if CK_DEBUG_TYPING // console.group( ..._buildLogMessage( this, 'SelectionObserver',
|
|
173
|
-
// @if CK_DEBUG_TYPING // 'update selection on compositionstart'
|
|
174
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
175
|
-
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'SelectionObserver',
|
|
176
|
-
// @if CK_DEBUG_TYPING // 'DOM Selection:',
|
|
177
|
-
// @if CK_DEBUG_TYPING // { node: domSelection!.anchorNode, offset: domSelection!.anchorOffset },
|
|
178
|
-
// @if CK_DEBUG_TYPING // { node: domSelection!.focusNode, offset: domSelection!.focusOffset }
|
|
179
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
180
|
-
// @if CK_DEBUG_TYPING // }
|
|
181
|
-
this._handleSelectionChange(domDocument);
|
|
182
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
183
|
-
// @if CK_DEBUG_TYPING // console.groupEnd();
|
|
184
|
-
// @if CK_DEBUG_TYPING // }
|
|
185
|
-
}, { priority: 'lowest' });
|
|
186
|
-
this._documents.add(domDocument);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* @inheritDoc
|
|
190
|
-
*/
|
|
191
|
-
stopObserving(domElement) {
|
|
192
|
-
this.stopListening(domElement);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* @inheritDoc
|
|
196
|
-
*/
|
|
197
|
-
destroy() {
|
|
198
|
-
super.destroy();
|
|
199
|
-
clearInterval(this._clearInfiniteLoopInterval);
|
|
200
|
-
this._fireSelectionChangeDoneDebounced.cancel();
|
|
201
|
-
this._documentIsSelectingInactivityTimeoutDebounced.cancel();
|
|
202
|
-
}
|
|
203
|
-
/* istanbul ignore next -- @preserve */
|
|
204
|
-
_reportInfiniteLoop() {
|
|
205
|
-
// @if CK_DEBUG // throw new Error(
|
|
206
|
-
// @if CK_DEBUG // 'Selection change observer detected an infinite rendering loop.\n\n' +
|
|
207
|
-
// @if CK_DEBUG // '⚠️⚠️ Report this error on https://github.com/ckeditor/ckeditor5/issues/11658.'
|
|
208
|
-
// @if CK_DEBUG // );
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Selection change listener. {@link module:engine/view/observer/mutationobserver~MutationObserver#flush Flush} mutations, check if
|
|
212
|
-
* a selection changes and fires {@link module:engine/view/document~ViewDocument#event:selectionChange} event on every change
|
|
213
|
-
* and {@link module:engine/view/document~ViewDocument#event:selectionChangeDone} when a selection stop changing.
|
|
214
|
-
*
|
|
215
|
-
* @param domDocument DOM document.
|
|
216
|
-
*/
|
|
217
|
-
_handleSelectionChange(domDocument) {
|
|
218
|
-
if (!this.isEnabled) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const domSelection = domDocument.defaultView.getSelection();
|
|
222
|
-
if (this.checkShouldIgnoreEventFromTarget(domSelection.anchorNode)) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
// Ensure the mutation event will be before selection event on all browsers.
|
|
226
|
-
this.mutationObserver.flush();
|
|
227
|
-
const newViewSelection = this.domConverter.domSelectionToView(domSelection);
|
|
228
|
-
// Do not convert selection change if the new view selection has no ranges in it.
|
|
229
|
-
//
|
|
230
|
-
// It means that the DOM selection is in some way incorrect. Ranges that were in the DOM selection could not be
|
|
231
|
-
// converted to the view. This happens when the DOM selection was moved outside of the editable element.
|
|
232
|
-
if (newViewSelection.rangeCount == 0) {
|
|
233
|
-
this.view.hasDomSelection = false;
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
this.view.hasDomSelection = true;
|
|
237
|
-
// Mark the latest focus change as complete (we got new selection after the focus so the selection is in the focused element).
|
|
238
|
-
this.focusObserver.flush();
|
|
239
|
-
// Ignore selection change as the editable is not focused. Note that in read-only mode, we have to update
|
|
240
|
-
// the model selection as there won't be any focus change to flush the pending selection changes.
|
|
241
|
-
if (!this.view.document.isFocused && !this.view.document.isReadOnly) {
|
|
242
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
243
|
-
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'SelectionObserver',
|
|
244
|
-
// @if CK_DEBUG_TYPING // 'Ignore selection change while editable is not focused'
|
|
245
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
246
|
-
// @if CK_DEBUG_TYPING // }
|
|
247
|
-
this._pendingSelectionChange.add(domDocument);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
this._pendingSelectionChange.delete(domDocument);
|
|
251
|
-
if (this.selection.isEqual(newViewSelection) && this.domConverter.isDomSelectionCorrect(domSelection)) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
// Ensure we are not in the infinite loop (#400).
|
|
255
|
-
// This counter is reset each second. 60 selection changes in 1 second is enough high number
|
|
256
|
-
// to be very difficult (impossible) to achieve using just keyboard keys (during normal editor use).
|
|
257
|
-
if (++this._loopbackCounter > 60) {
|
|
258
|
-
// Selection change observer detected an infinite rendering loop.
|
|
259
|
-
// Most probably you try to put the selection in the position which is not allowed
|
|
260
|
-
// by the browser and browser fixes it automatically what causes `selectionchange` event on
|
|
261
|
-
// which a loopback through a model tries to re-render the wrong selection and again.
|
|
262
|
-
this._reportInfiniteLoop();
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
if (!isSelectionWithinRootElements(newViewSelection)) {
|
|
266
|
-
// Occasionally, such as when removing markers during a focus change, the selection may end up inside a view element
|
|
267
|
-
// whose parent has already been detached from the DOM. In most cases this is harmless, but if the selectionchange
|
|
268
|
-
// event fires before the view is fully synchronized with the DOM converter, some elements in the selection may become orphans.
|
|
269
|
-
// This can result in the view being out of sync with the actual DOM structure.
|
|
270
|
-
// See: https://github.com/ckeditor/ckeditor5/issues/18744
|
|
271
|
-
this.view.forceRender();
|
|
272
|
-
}
|
|
273
|
-
else if (this.selection.isSimilar(newViewSelection)) {
|
|
274
|
-
// If selection was equal and we are at this point of algorithm, it means that it was incorrect.
|
|
275
|
-
// Just re-render it, no need to fire any events, etc.
|
|
276
|
-
this.view.forceRender();
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
const data = {
|
|
280
|
-
oldSelection: this.selection,
|
|
281
|
-
newSelection: newViewSelection,
|
|
282
|
-
domSelection
|
|
283
|
-
};
|
|
284
|
-
// @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
|
|
285
|
-
// @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'SelectionObserver',
|
|
286
|
-
// @if CK_DEBUG_TYPING // 'Fire selection change:',
|
|
287
|
-
// @if CK_DEBUG_TYPING // newViewSelection.getFirstRange()
|
|
288
|
-
// @if CK_DEBUG_TYPING // ) );
|
|
289
|
-
// @if CK_DEBUG_TYPING // }
|
|
290
|
-
// Prepare data for new selection and fire appropriate events.
|
|
291
|
-
this.document.fire('selectionChange', data);
|
|
292
|
-
// Call `#_fireSelectionChangeDoneDebounced` every time when `selectionChange` event is fired.
|
|
293
|
-
// This function is debounced what means that `selectionChangeDone` event will be fired only when
|
|
294
|
-
// defined int the function time will elapse since the last time the function was called.
|
|
295
|
-
// So `selectionChangeDone` will be fired when selection will stop changing.
|
|
296
|
-
this._fireSelectionChangeDoneDebounced(data);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Clears `SelectionObserver` internal properties connected with preventing infinite loop.
|
|
301
|
-
*/
|
|
302
|
-
_clearInfiniteLoop() {
|
|
303
|
-
this._loopbackCounter = 0;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Checks if all roots of the selection's range boundaries are root elements.
|
|
308
|
-
* Returns true if the selection is fully contained within root elements (not orphaned).
|
|
309
|
-
*
|
|
310
|
-
* @param selection The view selection to check.
|
|
311
|
-
* @returns True if all range boundaries are within root elements, false otherwise.
|
|
312
|
-
*/
|
|
313
|
-
function isSelectionWithinRootElements(selection) {
|
|
314
|
-
return Array
|
|
315
|
-
.from(selection.getRanges())
|
|
316
|
-
.flatMap(range => [range.start.root, range.end.root])
|
|
317
|
-
.every(root => root && root.is('rootElement'));
|
|
318
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { Observer } from './observer.js';
|
|
6
|
-
import { BubblingEventInfo } from './bubblingeventinfo.js';
|
|
7
|
-
import { keyCodes } from '@ckeditor/ckeditor5-utils';
|
|
8
|
-
/**
|
|
9
|
-
* Tab observer introduces the {@link module:engine/view/document~ViewDocument#event:tab `Document#tab`} event.
|
|
10
|
-
*
|
|
11
|
-
* Note that because {@link module:engine/view/observer/tabobserver~TabObserver} is attached by the
|
|
12
|
-
* {@link module:engine/view/view~EditingView}, this event is available by default.
|
|
13
|
-
*/
|
|
14
|
-
export class TabObserver extends Observer {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
constructor(view) {
|
|
19
|
-
super(view);
|
|
20
|
-
const doc = this.document;
|
|
21
|
-
doc.on('keydown', (evt, data) => {
|
|
22
|
-
if (!this.isEnabled ||
|
|
23
|
-
data.keyCode != keyCodes.tab ||
|
|
24
|
-
data.ctrlKey) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const event = new BubblingEventInfo(doc, 'tab', doc.selection.getFirstRange());
|
|
28
|
-
doc.fire(event, data);
|
|
29
|
-
if (event.stop.called) {
|
|
30
|
-
evt.stop();
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @inheritDoc
|
|
36
|
-
*/
|
|
37
|
-
observe() { }
|
|
38
|
-
/**
|
|
39
|
-
* @inheritDoc
|
|
40
|
-
*/
|
|
41
|
-
stopObserving() { }
|
|
42
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/view/observer/touchobserver
|
|
7
|
-
*/
|
|
8
|
-
import { DomEventObserver } from './domeventobserver.js';
|
|
9
|
-
/**
|
|
10
|
-
* Touch 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~EditingView} by {@link module:engine/view/view~EditingView#addObserver} method.
|
|
14
|
-
*/
|
|
15
|
-
export class TouchObserver extends DomEventObserver {
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
domEventType = ['touchstart', 'touchend', 'touchmove'];
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
onDomEvent(domEvent) {
|
|
24
|
-
this.fire(domEvent.type, domEvent);
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/view/placeholder.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/view/placeholder
|
|
7
|
-
*/
|
|
8
|
-
import '../../theme/placeholder.css';
|
|
9
|
-
import { logWarning } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
// Each document stores information about its placeholder elements and check functions.
|
|
11
|
-
const documentPlaceholders = new WeakMap();
|
|
12
|
-
let hasDisplayedPlaceholderDeprecationWarning = false;
|
|
13
|
-
/**
|
|
14
|
-
* A helper that enables a placeholder on the provided view element (also updates its visibility).
|
|
15
|
-
* The placeholder is a CSS pseudo–element (with a text content) attached to the element.
|
|
16
|
-
*
|
|
17
|
-
* To change the placeholder text, change value of the `placeholder` property in the provided `element`.
|
|
18
|
-
*
|
|
19
|
-
* To disable the placeholder, use {@link module:engine/view/placeholder~disableViewPlaceholder `disableViewPlaceholder()`} helper.
|
|
20
|
-
*
|
|
21
|
-
* @param options Configuration options of the placeholder.
|
|
22
|
-
* @param options.view Editing view instance.
|
|
23
|
-
* @param options.element Element that will gain a placeholder. See `options.isDirectHost` to learn more.
|
|
24
|
-
* @param options.isDirectHost If set `false`, the placeholder will not be enabled directly
|
|
25
|
-
* in the passed `element` but in one of its children (selected automatically, i.e. a first empty child element).
|
|
26
|
-
* Useful when attaching placeholders to elements that can host other elements (not just text), for instance,
|
|
27
|
-
* editable root elements.
|
|
28
|
-
* @param options.text Placeholder text. It's **deprecated** and will be removed soon. Use
|
|
29
|
-
* {@link module:engine/view/placeholder~PlaceholderableViewElement#placeholder `options.element.placeholder`} instead.
|
|
30
|
-
* @param options.keepOnFocus If set `true`, the placeholder stay visible when the host element is focused.
|
|
31
|
-
*/
|
|
32
|
-
export function enableViewPlaceholder({ view, element, text, isDirectHost = true, keepOnFocus = false }) {
|
|
33
|
-
const doc = view.document;
|
|
34
|
-
// Use a single post fixer per—document to update all placeholders.
|
|
35
|
-
if (!documentPlaceholders.has(doc)) {
|
|
36
|
-
documentPlaceholders.set(doc, new Map());
|
|
37
|
-
// If a post-fixer callback makes a change, it should return `true` so other post–fixers
|
|
38
|
-
// can re–evaluate the document again.
|
|
39
|
-
doc.registerPostFixer(writer => updateDocumentPlaceholders(documentPlaceholders.get(doc), writer));
|
|
40
|
-
// Update placeholders on isComposing state change since rendering is disabled while in composition mode.
|
|
41
|
-
doc.on('change:isComposing', () => {
|
|
42
|
-
view.change(writer => updateDocumentPlaceholders(documentPlaceholders.get(doc), writer));
|
|
43
|
-
}, { priority: 'high' });
|
|
44
|
-
}
|
|
45
|
-
if (element.is('editableElement')) {
|
|
46
|
-
element.on('change:placeholder', (evtInfo, evt, text) => setPlaceholder(text));
|
|
47
|
-
}
|
|
48
|
-
if (element.placeholder) {
|
|
49
|
-
setPlaceholder(element.placeholder);
|
|
50
|
-
}
|
|
51
|
-
else if (text) {
|
|
52
|
-
setPlaceholder(text);
|
|
53
|
-
}
|
|
54
|
-
if (text) {
|
|
55
|
-
showViewPlaceholderTextDeprecationWarning();
|
|
56
|
-
}
|
|
57
|
-
function setPlaceholder(text) {
|
|
58
|
-
const config = {
|
|
59
|
-
text,
|
|
60
|
-
isDirectHost,
|
|
61
|
-
keepOnFocus,
|
|
62
|
-
hostElement: isDirectHost ? element : null
|
|
63
|
-
};
|
|
64
|
-
// Store information about the element placeholder under its document.
|
|
65
|
-
documentPlaceholders.get(doc).set(element, config);
|
|
66
|
-
// Update the placeholders right away.
|
|
67
|
-
view.change(writer => updateDocumentPlaceholders([[element, config]], writer));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Disables the placeholder functionality from a given element.
|
|
72
|
-
*
|
|
73
|
-
* See {@link module:engine/view/placeholder~enableViewPlaceholder `enableViewPlaceholder()`} to learn more.
|
|
74
|
-
*/
|
|
75
|
-
export function disableViewPlaceholder(view, element) {
|
|
76
|
-
const doc = element.document;
|
|
77
|
-
if (!documentPlaceholders.has(doc)) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
view.change(writer => {
|
|
81
|
-
const placeholders = documentPlaceholders.get(doc);
|
|
82
|
-
const config = placeholders.get(element);
|
|
83
|
-
writer.removeAttribute('data-placeholder', config.hostElement);
|
|
84
|
-
hideViewPlaceholder(writer, config.hostElement);
|
|
85
|
-
placeholders.delete(element);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Shows a placeholder in the provided element by changing related attributes and CSS classes.
|
|
90
|
-
*
|
|
91
|
-
* **Note**: This helper will not update the placeholder visibility nor manage the
|
|
92
|
-
* it in any way in the future. What it does is a one–time state change of an element. Use
|
|
93
|
-
* {@link module:engine/view/placeholder~enableViewPlaceholder `enableViewPlaceholder()`} and
|
|
94
|
-
* {@link module:engine/view/placeholder~disableViewPlaceholder `disableViewPlaceholder()`} for full
|
|
95
|
-
* placeholder functionality.
|
|
96
|
-
*
|
|
97
|
-
* **Note**: This helper will blindly show the placeholder directly in the root editable element if
|
|
98
|
-
* one is passed, which could result in a visual clash if the editable element has some children
|
|
99
|
-
* (for instance, an empty paragraph). Use {@link module:engine/view/placeholder~enableViewPlaceholder `enableViewPlaceholder()`}
|
|
100
|
-
* in that case or make sure the correct element is passed to the helper.
|
|
101
|
-
*
|
|
102
|
-
* @returns `true`, if any changes were made to the `element`.
|
|
103
|
-
*/
|
|
104
|
-
export function showViewPlaceholder(writer, element) {
|
|
105
|
-
if (!element.hasClass('ck-placeholder')) {
|
|
106
|
-
writer.addClass('ck-placeholder', element);
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Hides a placeholder in the element by changing related attributes and CSS classes.
|
|
113
|
-
*
|
|
114
|
-
* **Note**: This helper will not update the placeholder visibility nor manage the
|
|
115
|
-
* it in any way in the future. What it does is a one–time state change of an element. Use
|
|
116
|
-
* {@link module:engine/view/placeholder~enableViewPlaceholder `enableViewPlaceholder()`} and
|
|
117
|
-
* {@link module:engine/view/placeholder~disableViewPlaceholder `disableViewPlaceholder()`} for full
|
|
118
|
-
* placeholder functionality.
|
|
119
|
-
*
|
|
120
|
-
* @returns `true`, if any changes were made to the `element`.
|
|
121
|
-
*/
|
|
122
|
-
export function hideViewPlaceholder(writer, element) {
|
|
123
|
-
if (element.hasClass('ck-placeholder')) {
|
|
124
|
-
writer.removeClass('ck-placeholder', element);
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Checks if a placeholder should be displayed in the element.
|
|
131
|
-
*
|
|
132
|
-
* **Note**: This helper will blindly check the possibility of showing a placeholder directly in the
|
|
133
|
-
* root editable element if one is passed, which may not be the expected result. If an element can
|
|
134
|
-
* host other elements (not just text), most likely one of its children should be checked instead
|
|
135
|
-
* because it will be the final host for the placeholder. Use
|
|
136
|
-
* {@link module:engine/view/placeholder~enableViewPlaceholder `enableViewPlaceholder()`} in that case or make
|
|
137
|
-
* sure the correct element is passed to the helper.
|
|
138
|
-
*
|
|
139
|
-
* @param element Element that holds the placeholder.
|
|
140
|
-
* @param keepOnFocus Focusing the element will keep the placeholder visible.
|
|
141
|
-
*/
|
|
142
|
-
export function needsViewPlaceholder(element, keepOnFocus) {
|
|
143
|
-
if (!element.isAttached()) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
if (hasContent(element)) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
const doc = element.document;
|
|
150
|
-
const viewSelection = doc.selection;
|
|
151
|
-
const selectionAnchor = viewSelection.anchor;
|
|
152
|
-
if (doc.isComposing && selectionAnchor && selectionAnchor.parent === element) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
// Skip the focus check and make the placeholder visible already regardless of document focus state.
|
|
156
|
-
if (keepOnFocus) {
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
// If the document is blurred.
|
|
160
|
-
if (!doc.isFocused) {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
// If document is focused and the element is empty but the selection is not anchored inside it.
|
|
164
|
-
return !!selectionAnchor && selectionAnchor.parent !== element;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Anything but uiElement(s) counts as content.
|
|
168
|
-
*/
|
|
169
|
-
function hasContent(element) {
|
|
170
|
-
for (const child of element.getChildren()) {
|
|
171
|
-
if (!child.is('uiElement')) {
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Updates all placeholders associated with a document in a post–fixer callback.
|
|
179
|
-
*
|
|
180
|
-
* @returns True if any changes were made to the view document.
|
|
181
|
-
*/
|
|
182
|
-
function updateDocumentPlaceholders(placeholders, writer) {
|
|
183
|
-
const directHostElements = [];
|
|
184
|
-
let wasViewModified = false;
|
|
185
|
-
// First set placeholders on the direct hosts.
|
|
186
|
-
for (const [element, config] of placeholders) {
|
|
187
|
-
if (config.isDirectHost) {
|
|
188
|
-
directHostElements.push(element);
|
|
189
|
-
if (updatePlaceholder(writer, element, config)) {
|
|
190
|
-
wasViewModified = true;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
// Then set placeholders on the indirect hosts but only on those that does not already have an direct host placeholder.
|
|
195
|
-
for (const [element, config] of placeholders) {
|
|
196
|
-
if (config.isDirectHost) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
const hostElement = getChildPlaceholderHostSubstitute(element);
|
|
200
|
-
// If host element changed, remove the placeholder from the previous one.
|
|
201
|
-
// This can happen when user replaces the first child element of the parent element
|
|
202
|
-
// with new one, but the previous one is still in the view tree.
|
|
203
|
-
// See:
|
|
204
|
-
// https://github.com/ckeditor/ckeditor5/issues/14354
|
|
205
|
-
// https://github.com/ckeditor/ckeditor5/issues/18149
|
|
206
|
-
if (hostElement !== config.hostElement && config.hostElement) {
|
|
207
|
-
writer.removeAttribute('data-placeholder', config.hostElement);
|
|
208
|
-
hideViewPlaceholder(writer, config.hostElement);
|
|
209
|
-
config.hostElement = null;
|
|
210
|
-
wasViewModified = true;
|
|
211
|
-
}
|
|
212
|
-
// When not a direct host, it could happen that there is no child element
|
|
213
|
-
// capable of displaying a placeholder.
|
|
214
|
-
if (!hostElement) {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
// Don't override placeholder if the host element already has some direct placeholder.
|
|
218
|
-
if (directHostElements.includes(hostElement)) {
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
// Update the host element (used for setting and removing the placeholder).
|
|
222
|
-
config.hostElement = hostElement;
|
|
223
|
-
if (updatePlaceholder(writer, element, config)) {
|
|
224
|
-
wasViewModified = true;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return wasViewModified;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Updates a single placeholder in a post–fixer callback.
|
|
231
|
-
*
|
|
232
|
-
* @returns True if any changes were made to the view document.
|
|
233
|
-
*/
|
|
234
|
-
function updatePlaceholder(writer, element, config) {
|
|
235
|
-
const { text, isDirectHost, hostElement } = config;
|
|
236
|
-
let wasViewModified = false;
|
|
237
|
-
// This may be necessary when updating the placeholder text to something else.
|
|
238
|
-
if (hostElement.getAttribute('data-placeholder') !== text) {
|
|
239
|
-
writer.setAttribute('data-placeholder', text, hostElement);
|
|
240
|
-
wasViewModified = true;
|
|
241
|
-
}
|
|
242
|
-
// If the host element is not a direct host then placeholder is needed only when there is only one element.
|
|
243
|
-
const isOnlyChild = isDirectHost || element.childCount == 1;
|
|
244
|
-
if (isOnlyChild && needsViewPlaceholder(hostElement, config.keepOnFocus)) {
|
|
245
|
-
if (showViewPlaceholder(writer, hostElement)) {
|
|
246
|
-
wasViewModified = true;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
else if (hideViewPlaceholder(writer, hostElement)) {
|
|
250
|
-
wasViewModified = true;
|
|
251
|
-
}
|
|
252
|
-
return wasViewModified;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Gets a child element capable of displaying a placeholder if a parent element can host more
|
|
256
|
-
* than just text (for instance, when it is a root editable element). The child element
|
|
257
|
-
* can then be used in other placeholder helpers as a substitute of its parent.
|
|
258
|
-
*/
|
|
259
|
-
function getChildPlaceholderHostSubstitute(parent) {
|
|
260
|
-
if (parent.childCount) {
|
|
261
|
-
const firstChild = parent.getChild(0);
|
|
262
|
-
if (firstChild.is('element') && !firstChild.is('uiElement') && !firstChild.is('attributeElement')) {
|
|
263
|
-
return firstChild;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Displays a deprecation warning message in the console, but only once per page load.
|
|
270
|
-
*/
|
|
271
|
-
function showViewPlaceholderTextDeprecationWarning() {
|
|
272
|
-
if (!hasDisplayedPlaceholderDeprecationWarning) {
|
|
273
|
-
/**
|
|
274
|
-
* The "text" option in the {@link module:engine/view/placeholder~enableViewPlaceholder `enableViewPlaceholder()`}
|
|
275
|
-
* function is deprecated and will be removed soon.
|
|
276
|
-
*
|
|
277
|
-
* See the {@glink updating/guides/update-to-39#view-element-placeholder Migration to v39} guide for
|
|
278
|
-
* more information on how to apply this change.
|
|
279
|
-
*
|
|
280
|
-
* @error enableViewPlaceholder-deprecated-text-option
|
|
281
|
-
*/
|
|
282
|
-
logWarning('enableViewPlaceholder-deprecated-text-option');
|
|
283
|
-
}
|
|
284
|
-
hasDisplayedPlaceholderDeprecationWarning = true;
|
|
285
|
-
}
|