@ckeditor/ckeditor5-minimap 39.0.2 → 40.0.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/build/minimap.js.map +1 -0
- package/package.json +2 -2
- package/src/augmentation.d.ts +18 -18
- package/src/augmentation.js +5 -5
- package/src/index.d.ts +10 -10
- package/src/index.js +9 -9
- package/src/minimap.d.ts +54 -54
- package/src/minimap.js +154 -154
- package/src/minimapconfig.d.ts +85 -85
- package/src/minimapconfig.js +5 -5
- package/src/minimapiframeview.d.ts +54 -54
- package/src/minimapiframeview.js +80 -80
- package/src/minimappositiontrackerview.d.ts +58 -58
- package/src/minimappositiontrackerview.js +78 -78
- package/src/minimapview.d.ts +109 -109
- package/src/minimapview.js +137 -137
- package/src/utils.d.ts +61 -61
- package/src/utils.js +97 -97
package/src/minimap.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module minimap/minimap
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { findClosestScrollableAncestor, global } from 'ckeditor5/src/utils';
|
|
10
|
-
import MinimapView from './minimapview';
|
|
11
|
-
import { cloneEditingViewDomRoot, getClientHeight, getDomElementRect, getPageStyles, getScrollable } from './utils';
|
|
12
|
-
// @if CK_DEBUG_MINIMAP // const RectDrawer = require( '@ckeditor/ckeditor5-utils/tests/_utils/rectdrawer' ).default;
|
|
13
|
-
import '../theme/minimap.css';
|
|
14
|
-
/**
|
|
15
|
-
* The content minimap feature.
|
|
16
|
-
*/
|
|
17
|
-
export default class Minimap extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get pluginName() {
|
|
22
|
-
return 'Minimap';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
init() {
|
|
28
|
-
const editor = this.editor;
|
|
29
|
-
this._minimapView = null;
|
|
30
|
-
this._scrollableRootAncestor = null;
|
|
31
|
-
this.listenTo(editor.ui, 'ready', this._onUiReady.bind(this));
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @inheritDoc
|
|
35
|
-
*/
|
|
36
|
-
destroy() {
|
|
37
|
-
this._minimapView.destroy();
|
|
38
|
-
this._minimapView.element.remove();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Initializes the minimap view element and starts the layout synchronization
|
|
42
|
-
* on the editing view `render` event.
|
|
43
|
-
*/
|
|
44
|
-
_onUiReady() {
|
|
45
|
-
const editor = this.editor;
|
|
46
|
-
// TODO: This will not work with the multi-root editor.
|
|
47
|
-
const editingRootElement = this._editingRootElement = editor.ui.getEditableElement();
|
|
48
|
-
this._scrollableRootAncestor = findClosestScrollableAncestor(editingRootElement);
|
|
49
|
-
// DOM root element is not yet attached to the document.
|
|
50
|
-
if (!editingRootElement.ownerDocument.body.contains(editingRootElement)) {
|
|
51
|
-
editor.ui.once('update', this._onUiReady.bind(this));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
this._initializeMinimapView();
|
|
55
|
-
this.listenTo(editor.editing.view, 'render', () => {
|
|
56
|
-
this._syncMinimapToEditingRootScrollPosition();
|
|
57
|
-
});
|
|
58
|
-
this._syncMinimapToEditingRootScrollPosition();
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Initializes the minimap view and attaches listeners that make it responsive to the environment (document)
|
|
62
|
-
* but also allow the minimap to control the document (scroll position).
|
|
63
|
-
*/
|
|
64
|
-
_initializeMinimapView() {
|
|
65
|
-
const editor = this.editor;
|
|
66
|
-
const locale = editor.locale;
|
|
67
|
-
const useSimplePreview = editor.config.get('minimap.useSimplePreview');
|
|
68
|
-
// TODO: Throw an error if there is no `minimap` in config.
|
|
69
|
-
const minimapContainerElement = editor.config.get('minimap.container');
|
|
70
|
-
const scrollableRootAncestor = this._scrollableRootAncestor;
|
|
71
|
-
// TODO: This should be dynamic, the root width could change as the viewport scales if not fixed unit.
|
|
72
|
-
const editingRootElementWidth = getDomElementRect(this._editingRootElement).width;
|
|
73
|
-
const minimapContainerWidth = getDomElementRect(minimapContainerElement).width;
|
|
74
|
-
const minimapScaleRatio = minimapContainerWidth / editingRootElementWidth;
|
|
75
|
-
const minimapView = this._minimapView = new MinimapView({
|
|
76
|
-
locale,
|
|
77
|
-
scaleRatio: minimapScaleRatio,
|
|
78
|
-
pageStyles: getPageStyles(),
|
|
79
|
-
extraClasses: editor.config.get('minimap.extraClasses'),
|
|
80
|
-
useSimplePreview,
|
|
81
|
-
domRootClone: cloneEditingViewDomRoot(editor)
|
|
82
|
-
});
|
|
83
|
-
minimapView.render();
|
|
84
|
-
// Scrollable ancestor scroll -> minimap position update.
|
|
85
|
-
minimapView.listenTo(global.document, 'scroll', (evt, data) => {
|
|
86
|
-
if (scrollableRootAncestor === global.document.body) {
|
|
87
|
-
if (data.target !== global.document) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else if (data.target !== scrollableRootAncestor) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
this._syncMinimapToEditingRootScrollPosition();
|
|
95
|
-
}, { useCapture: true, usePassive: true });
|
|
96
|
-
// Viewport resize -> minimap position update.
|
|
97
|
-
minimapView.listenTo(global.window, 'resize', () => {
|
|
98
|
-
this._syncMinimapToEditingRootScrollPosition();
|
|
99
|
-
});
|
|
100
|
-
// Dragging the visible content area -> document (scrollable) position update.
|
|
101
|
-
minimapView.on('drag', (evt, movementY) => {
|
|
102
|
-
let movementYPercentage;
|
|
103
|
-
if (minimapView.scrollHeight === 0) {
|
|
104
|
-
movementYPercentage = 0;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
movementYPercentage = movementY / minimapView.scrollHeight;
|
|
108
|
-
}
|
|
109
|
-
const absoluteScrollProgress = movementYPercentage *
|
|
110
|
-
(scrollableRootAncestor.scrollHeight - getClientHeight(scrollableRootAncestor));
|
|
111
|
-
const scrollable = getScrollable(scrollableRootAncestor);
|
|
112
|
-
scrollable.scrollBy(0, Math.round(absoluteScrollProgress));
|
|
113
|
-
});
|
|
114
|
-
// Clicking the minimap -> center the document (scrollable) to the corresponding position.
|
|
115
|
-
minimapView.on('click', (evt, percentage) => {
|
|
116
|
-
const absoluteScrollProgress = percentage * scrollableRootAncestor.scrollHeight;
|
|
117
|
-
const scrollable = getScrollable(scrollableRootAncestor);
|
|
118
|
-
scrollable.scrollBy(0, Math.round(absoluteScrollProgress));
|
|
119
|
-
});
|
|
120
|
-
minimapContainerElement.appendChild(minimapView.element);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* @private
|
|
124
|
-
*/
|
|
125
|
-
_syncMinimapToEditingRootScrollPosition() {
|
|
126
|
-
const editingRootElement = this._editingRootElement;
|
|
127
|
-
const minimapView = this._minimapView;
|
|
128
|
-
minimapView.setContentHeight(editingRootElement.offsetHeight);
|
|
129
|
-
const editingRootRect = getDomElementRect(editingRootElement);
|
|
130
|
-
const scrollableRootAncestorRect = getDomElementRect(this._scrollableRootAncestor);
|
|
131
|
-
let scrollProgress;
|
|
132
|
-
// @if CK_DEBUG_MINIMAP // RectDrawer.clear();
|
|
133
|
-
// @if CK_DEBUG_MINIMAP // RectDrawer.draw( scrollableRootAncestorRect, { outlineColor: 'red' }, 'scrollableRootAncestor' );
|
|
134
|
-
// @if CK_DEBUG_MINIMAP // RectDrawer.draw( editingRootRect, { outlineColor: 'green' }, 'editingRoot' );
|
|
135
|
-
// The root is completely visible in the scrollable ancestor.
|
|
136
|
-
if (scrollableRootAncestorRect.contains(editingRootRect)) {
|
|
137
|
-
scrollProgress = 0;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
if (editingRootRect.top > scrollableRootAncestorRect.top) {
|
|
141
|
-
scrollProgress = 0;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
scrollProgress = (editingRootRect.top - scrollableRootAncestorRect.top) /
|
|
145
|
-
(scrollableRootAncestorRect.height - editingRootRect.height);
|
|
146
|
-
scrollProgress = Math.max(0, Math.min(scrollProgress, 1));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// The intersection helps to change the tracker height when there is a lot of padding around the root.
|
|
150
|
-
// Note: It is **essential** that the height is set first because the progress depends on the correct tracker height.
|
|
151
|
-
minimapView.setPositionTrackerHeight(scrollableRootAncestorRect.getIntersection(editingRootRect).height);
|
|
152
|
-
minimapView.setScrollProgress(scrollProgress);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module minimap/minimap
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { findClosestScrollableAncestor, global } from 'ckeditor5/src/utils';
|
|
10
|
+
import MinimapView from './minimapview';
|
|
11
|
+
import { cloneEditingViewDomRoot, getClientHeight, getDomElementRect, getPageStyles, getScrollable } from './utils';
|
|
12
|
+
// @if CK_DEBUG_MINIMAP // const RectDrawer = require( '@ckeditor/ckeditor5-utils/tests/_utils/rectdrawer' ).default;
|
|
13
|
+
import '../theme/minimap.css';
|
|
14
|
+
/**
|
|
15
|
+
* The content minimap feature.
|
|
16
|
+
*/
|
|
17
|
+
export default class Minimap extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get pluginName() {
|
|
22
|
+
return 'Minimap';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
init() {
|
|
28
|
+
const editor = this.editor;
|
|
29
|
+
this._minimapView = null;
|
|
30
|
+
this._scrollableRootAncestor = null;
|
|
31
|
+
this.listenTo(editor.ui, 'ready', this._onUiReady.bind(this));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
destroy() {
|
|
37
|
+
this._minimapView.destroy();
|
|
38
|
+
this._minimapView.element.remove();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initializes the minimap view element and starts the layout synchronization
|
|
42
|
+
* on the editing view `render` event.
|
|
43
|
+
*/
|
|
44
|
+
_onUiReady() {
|
|
45
|
+
const editor = this.editor;
|
|
46
|
+
// TODO: This will not work with the multi-root editor.
|
|
47
|
+
const editingRootElement = this._editingRootElement = editor.ui.getEditableElement();
|
|
48
|
+
this._scrollableRootAncestor = findClosestScrollableAncestor(editingRootElement);
|
|
49
|
+
// DOM root element is not yet attached to the document.
|
|
50
|
+
if (!editingRootElement.ownerDocument.body.contains(editingRootElement)) {
|
|
51
|
+
editor.ui.once('update', this._onUiReady.bind(this));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this._initializeMinimapView();
|
|
55
|
+
this.listenTo(editor.editing.view, 'render', () => {
|
|
56
|
+
this._syncMinimapToEditingRootScrollPosition();
|
|
57
|
+
});
|
|
58
|
+
this._syncMinimapToEditingRootScrollPosition();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Initializes the minimap view and attaches listeners that make it responsive to the environment (document)
|
|
62
|
+
* but also allow the minimap to control the document (scroll position).
|
|
63
|
+
*/
|
|
64
|
+
_initializeMinimapView() {
|
|
65
|
+
const editor = this.editor;
|
|
66
|
+
const locale = editor.locale;
|
|
67
|
+
const useSimplePreview = editor.config.get('minimap.useSimplePreview');
|
|
68
|
+
// TODO: Throw an error if there is no `minimap` in config.
|
|
69
|
+
const minimapContainerElement = editor.config.get('minimap.container');
|
|
70
|
+
const scrollableRootAncestor = this._scrollableRootAncestor;
|
|
71
|
+
// TODO: This should be dynamic, the root width could change as the viewport scales if not fixed unit.
|
|
72
|
+
const editingRootElementWidth = getDomElementRect(this._editingRootElement).width;
|
|
73
|
+
const minimapContainerWidth = getDomElementRect(minimapContainerElement).width;
|
|
74
|
+
const minimapScaleRatio = minimapContainerWidth / editingRootElementWidth;
|
|
75
|
+
const minimapView = this._minimapView = new MinimapView({
|
|
76
|
+
locale,
|
|
77
|
+
scaleRatio: minimapScaleRatio,
|
|
78
|
+
pageStyles: getPageStyles(),
|
|
79
|
+
extraClasses: editor.config.get('minimap.extraClasses'),
|
|
80
|
+
useSimplePreview,
|
|
81
|
+
domRootClone: cloneEditingViewDomRoot(editor)
|
|
82
|
+
});
|
|
83
|
+
minimapView.render();
|
|
84
|
+
// Scrollable ancestor scroll -> minimap position update.
|
|
85
|
+
minimapView.listenTo(global.document, 'scroll', (evt, data) => {
|
|
86
|
+
if (scrollableRootAncestor === global.document.body) {
|
|
87
|
+
if (data.target !== global.document) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (data.target !== scrollableRootAncestor) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this._syncMinimapToEditingRootScrollPosition();
|
|
95
|
+
}, { useCapture: true, usePassive: true });
|
|
96
|
+
// Viewport resize -> minimap position update.
|
|
97
|
+
minimapView.listenTo(global.window, 'resize', () => {
|
|
98
|
+
this._syncMinimapToEditingRootScrollPosition();
|
|
99
|
+
});
|
|
100
|
+
// Dragging the visible content area -> document (scrollable) position update.
|
|
101
|
+
minimapView.on('drag', (evt, movementY) => {
|
|
102
|
+
let movementYPercentage;
|
|
103
|
+
if (minimapView.scrollHeight === 0) {
|
|
104
|
+
movementYPercentage = 0;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
movementYPercentage = movementY / minimapView.scrollHeight;
|
|
108
|
+
}
|
|
109
|
+
const absoluteScrollProgress = movementYPercentage *
|
|
110
|
+
(scrollableRootAncestor.scrollHeight - getClientHeight(scrollableRootAncestor));
|
|
111
|
+
const scrollable = getScrollable(scrollableRootAncestor);
|
|
112
|
+
scrollable.scrollBy(0, Math.round(absoluteScrollProgress));
|
|
113
|
+
});
|
|
114
|
+
// Clicking the minimap -> center the document (scrollable) to the corresponding position.
|
|
115
|
+
minimapView.on('click', (evt, percentage) => {
|
|
116
|
+
const absoluteScrollProgress = percentage * scrollableRootAncestor.scrollHeight;
|
|
117
|
+
const scrollable = getScrollable(scrollableRootAncestor);
|
|
118
|
+
scrollable.scrollBy(0, Math.round(absoluteScrollProgress));
|
|
119
|
+
});
|
|
120
|
+
minimapContainerElement.appendChild(minimapView.element);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
_syncMinimapToEditingRootScrollPosition() {
|
|
126
|
+
const editingRootElement = this._editingRootElement;
|
|
127
|
+
const minimapView = this._minimapView;
|
|
128
|
+
minimapView.setContentHeight(editingRootElement.offsetHeight);
|
|
129
|
+
const editingRootRect = getDomElementRect(editingRootElement);
|
|
130
|
+
const scrollableRootAncestorRect = getDomElementRect(this._scrollableRootAncestor);
|
|
131
|
+
let scrollProgress;
|
|
132
|
+
// @if CK_DEBUG_MINIMAP // RectDrawer.clear();
|
|
133
|
+
// @if CK_DEBUG_MINIMAP // RectDrawer.draw( scrollableRootAncestorRect, { outlineColor: 'red' }, 'scrollableRootAncestor' );
|
|
134
|
+
// @if CK_DEBUG_MINIMAP // RectDrawer.draw( editingRootRect, { outlineColor: 'green' }, 'editingRoot' );
|
|
135
|
+
// The root is completely visible in the scrollable ancestor.
|
|
136
|
+
if (scrollableRootAncestorRect.contains(editingRootRect)) {
|
|
137
|
+
scrollProgress = 0;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (editingRootRect.top > scrollableRootAncestorRect.top) {
|
|
141
|
+
scrollProgress = 0;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
scrollProgress = (editingRootRect.top - scrollableRootAncestorRect.top) /
|
|
145
|
+
(scrollableRootAncestorRect.height - editingRootRect.height);
|
|
146
|
+
scrollProgress = Math.max(0, Math.min(scrollProgress, 1));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// The intersection helps to change the tracker height when there is a lot of padding around the root.
|
|
150
|
+
// Note: It is **essential** that the height is set first because the progress depends on the correct tracker height.
|
|
151
|
+
minimapView.setPositionTrackerHeight(scrollableRootAncestorRect.getIntersection(editingRootRect).height);
|
|
152
|
+
minimapView.setScrollProgress(scrollProgress);
|
|
153
|
+
}
|
|
154
|
+
}
|
package/src/minimapconfig.d.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module minimap/minimapconfig
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* The configuration of the {@link module:minimap/minimap~Minimap} feature.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* ClassicEditor
|
|
13
|
-
* .create( {
|
|
14
|
-
* minimap: ... // Minimap feature config.
|
|
15
|
-
* } )
|
|
16
|
-
* .then( ... )
|
|
17
|
-
* .catch( ... );
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
21
|
-
*/
|
|
22
|
-
export interface MinimapConfig {
|
|
23
|
-
/**
|
|
24
|
-
* The DOM element container for the minimap.
|
|
25
|
-
*
|
|
26
|
-
* **Note**: The container must have a fixed `width` and `overflow: hidden` for the minimap to work correctly.
|
|
27
|
-
*/
|
|
28
|
-
container: HTMLElement;
|
|
29
|
-
/**
|
|
30
|
-
* When set to `true`, the minimap will render content as simple boxes instead of replicating the look of the content (default).
|
|
31
|
-
*/
|
|
32
|
-
useSimplePreview?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Extra CSS class (or classes) that will be set internally on the `<body>` element of the `<iframe>` enclosing the minimap.
|
|
35
|
-
*
|
|
36
|
-
* By default, the minimap feature will attempt to clone all website styles and re-apply them in the `<iframe>` for the best accuracy.
|
|
37
|
-
* However, this may not work if the content of your editor inherits the styles from parent containers, resulting in inconsistent
|
|
38
|
-
* look and imprecise scrolling of the minimap.
|
|
39
|
-
*
|
|
40
|
-
* This optional configuration can address these issues by ensuring the same CSS rules apply to the content of the minimap
|
|
41
|
-
* and the original content of the editor.
|
|
42
|
-
*
|
|
43
|
-
* For instance, consider the following DOM structure:
|
|
44
|
-
*
|
|
45
|
-
* ```html
|
|
46
|
-
* <div class="website">
|
|
47
|
-
* <!-- ... -->
|
|
48
|
-
* <div class="styled-container">
|
|
49
|
-
* <!-- ... -->
|
|
50
|
-
* <div id="editor">
|
|
51
|
-
* <!-- content of the editor -->
|
|
52
|
-
* </div>
|
|
53
|
-
* </div>
|
|
54
|
-
* <!-- ... -->
|
|
55
|
-
* </div>
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* and the following CSS styles:
|
|
59
|
-
*
|
|
60
|
-
* ```css
|
|
61
|
-
* .website p {
|
|
62
|
-
* font-size: 13px;
|
|
63
|
-
* }
|
|
64
|
-
*
|
|
65
|
-
* .styled-container p {
|
|
66
|
-
* color: #ccc;
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* To maintain the consistency of styling (`font-size` and `color` of paragraphs), you will need to pass the CSS class names
|
|
71
|
-
* of these containers:
|
|
72
|
-
*
|
|
73
|
-
* ```ts
|
|
74
|
-
* ClassicEditor
|
|
75
|
-
* .create( document.getElementById( 'editor' ), {
|
|
76
|
-
* minimap: {
|
|
77
|
-
* extraClasses: 'website styled-container'
|
|
78
|
-
* }
|
|
79
|
-
* } )
|
|
80
|
-
* .then( ... )
|
|
81
|
-
* .catch( ... );
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
extraClasses?: string;
|
|
85
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module minimap/minimapconfig
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The configuration of the {@link module:minimap/minimap~Minimap} feature.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* ClassicEditor
|
|
13
|
+
* .create( {
|
|
14
|
+
* minimap: ... // Minimap feature config.
|
|
15
|
+
* } )
|
|
16
|
+
* .then( ... )
|
|
17
|
+
* .catch( ... );
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
21
|
+
*/
|
|
22
|
+
export interface MinimapConfig {
|
|
23
|
+
/**
|
|
24
|
+
* The DOM element container for the minimap.
|
|
25
|
+
*
|
|
26
|
+
* **Note**: The container must have a fixed `width` and `overflow: hidden` for the minimap to work correctly.
|
|
27
|
+
*/
|
|
28
|
+
container: HTMLElement;
|
|
29
|
+
/**
|
|
30
|
+
* When set to `true`, the minimap will render content as simple boxes instead of replicating the look of the content (default).
|
|
31
|
+
*/
|
|
32
|
+
useSimplePreview?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Extra CSS class (or classes) that will be set internally on the `<body>` element of the `<iframe>` enclosing the minimap.
|
|
35
|
+
*
|
|
36
|
+
* By default, the minimap feature will attempt to clone all website styles and re-apply them in the `<iframe>` for the best accuracy.
|
|
37
|
+
* However, this may not work if the content of your editor inherits the styles from parent containers, resulting in inconsistent
|
|
38
|
+
* look and imprecise scrolling of the minimap.
|
|
39
|
+
*
|
|
40
|
+
* This optional configuration can address these issues by ensuring the same CSS rules apply to the content of the minimap
|
|
41
|
+
* and the original content of the editor.
|
|
42
|
+
*
|
|
43
|
+
* For instance, consider the following DOM structure:
|
|
44
|
+
*
|
|
45
|
+
* ```html
|
|
46
|
+
* <div class="website">
|
|
47
|
+
* <!-- ... -->
|
|
48
|
+
* <div class="styled-container">
|
|
49
|
+
* <!-- ... -->
|
|
50
|
+
* <div id="editor">
|
|
51
|
+
* <!-- content of the editor -->
|
|
52
|
+
* </div>
|
|
53
|
+
* </div>
|
|
54
|
+
* <!-- ... -->
|
|
55
|
+
* </div>
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* and the following CSS styles:
|
|
59
|
+
*
|
|
60
|
+
* ```css
|
|
61
|
+
* .website p {
|
|
62
|
+
* font-size: 13px;
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* .styled-container p {
|
|
66
|
+
* color: #ccc;
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* To maintain the consistency of styling (`font-size` and `color` of paragraphs), you will need to pass the CSS class names
|
|
71
|
+
* of these containers:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* ClassicEditor
|
|
75
|
+
* .create( document.getElementById( 'editor' ), {
|
|
76
|
+
* minimap: {
|
|
77
|
+
* extraClasses: 'website styled-container'
|
|
78
|
+
* }
|
|
79
|
+
* } )
|
|
80
|
+
* .then( ... )
|
|
81
|
+
* .catch( ... );
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
extraClasses?: string;
|
|
85
|
+
}
|
package/src/minimapconfig.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
export {};
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module minimap/minimapiframeview
|
|
7
|
-
*/
|
|
8
|
-
import { IframeView } from 'ckeditor5/src/ui';
|
|
9
|
-
import { type Locale } from 'ckeditor5/src/utils';
|
|
10
|
-
import type { MinimapViewOptions } from './minimapview';
|
|
11
|
-
/**
|
|
12
|
-
* The internal `<iframe>` view that hosts the minimap content.
|
|
13
|
-
*
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export default class MinimapIframeView extends IframeView {
|
|
17
|
-
/**
|
|
18
|
-
* The CSS `top` used to scroll the minimap.
|
|
19
|
-
*
|
|
20
|
-
* @readonly
|
|
21
|
-
*/
|
|
22
|
-
top: number;
|
|
23
|
-
/**
|
|
24
|
-
* The CSS `height` of the iframe.
|
|
25
|
-
*
|
|
26
|
-
* @readonly
|
|
27
|
-
*/
|
|
28
|
-
height: number;
|
|
29
|
-
/**
|
|
30
|
-
* Cached view constructor options for re-use in other methods.
|
|
31
|
-
*/
|
|
32
|
-
private readonly _options;
|
|
33
|
-
/**
|
|
34
|
-
* Creates an instance of the internal minimap iframe.
|
|
35
|
-
*/
|
|
36
|
-
constructor(locale: Locale, options: MinimapViewOptions);
|
|
37
|
-
/**
|
|
38
|
-
* @inheritDoc
|
|
39
|
-
*/
|
|
40
|
-
render(): Promise<unknown>;
|
|
41
|
-
/**
|
|
42
|
-
* Sets the new height of the iframe.
|
|
43
|
-
*/
|
|
44
|
-
setHeight(newHeight: number): void;
|
|
45
|
-
/**
|
|
46
|
-
* Sets the top offset of the iframe to move it around vertically.
|
|
47
|
-
*/
|
|
48
|
-
setTopOffset(newOffset: number): void;
|
|
49
|
-
/**
|
|
50
|
-
* Sets the internal structure of the `<iframe>` readying it to display the
|
|
51
|
-
* minimap element.
|
|
52
|
-
*/
|
|
53
|
-
private _prepareDocument;
|
|
54
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module minimap/minimapiframeview
|
|
7
|
+
*/
|
|
8
|
+
import { IframeView } from 'ckeditor5/src/ui';
|
|
9
|
+
import { type Locale } from 'ckeditor5/src/utils';
|
|
10
|
+
import type { MinimapViewOptions } from './minimapview';
|
|
11
|
+
/**
|
|
12
|
+
* The internal `<iframe>` view that hosts the minimap content.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export default class MinimapIframeView extends IframeView {
|
|
17
|
+
/**
|
|
18
|
+
* The CSS `top` used to scroll the minimap.
|
|
19
|
+
*
|
|
20
|
+
* @readonly
|
|
21
|
+
*/
|
|
22
|
+
top: number;
|
|
23
|
+
/**
|
|
24
|
+
* The CSS `height` of the iframe.
|
|
25
|
+
*
|
|
26
|
+
* @readonly
|
|
27
|
+
*/
|
|
28
|
+
height: number;
|
|
29
|
+
/**
|
|
30
|
+
* Cached view constructor options for re-use in other methods.
|
|
31
|
+
*/
|
|
32
|
+
private readonly _options;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance of the internal minimap iframe.
|
|
35
|
+
*/
|
|
36
|
+
constructor(locale: Locale, options: MinimapViewOptions);
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
render(): Promise<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Sets the new height of the iframe.
|
|
43
|
+
*/
|
|
44
|
+
setHeight(newHeight: number): void;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the top offset of the iframe to move it around vertically.
|
|
47
|
+
*/
|
|
48
|
+
setTopOffset(newOffset: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* Sets the internal structure of the `<iframe>` readying it to display the
|
|
51
|
+
* minimap element.
|
|
52
|
+
*/
|
|
53
|
+
private _prepareDocument;
|
|
54
|
+
}
|