@ckeditor/ckeditor5-minimap 40.0.0 → 40.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,8 +1,8 @@
1
1
  Software License Agreement
2
2
  ==========================
3
3
 
4
- **CKEditor&nbsp;5 Minimap Feature** – https://github.com/ckeditor/ckeditor5-minimap <br>
5
- Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
4
+ **CKEditor&nbsp;5 minimap feature** – https://github.com/ckeditor/ckeditor5-minimap <br>
5
+ Copyright (c) 20032023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
14
14
  Trademarks
15
15
  ----------
16
16
 
17
- **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
17
+ **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-minimap",
3
- "version": "40.0.0",
3
+ "version": "40.2.0",
4
4
  "description": "Content minimap feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "40.0.0"
15
+ "ckeditor5": "40.2.0"
16
16
  },
17
17
  "author": "CKSource (http://cksource.com/)",
18
18
  "license": "GPL-2.0-or-later",
@@ -1,18 +1,18 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import type { MinimapConfig, Minimap } from './index';
6
- declare module '@ckeditor/ckeditor5-core' {
7
- interface EditorConfig {
8
- /**
9
- * The configuration of the minimap feature. Introduced by the {@link module:minimap/minimap~Minimap} feature.
10
- *
11
- * Read more in {@link module:minimap/minimapconfig~MinimapConfig}.
12
- */
13
- minimap?: MinimapConfig;
14
- }
15
- interface PluginsMap {
16
- [Minimap.pluginName]: Minimap;
17
- }
18
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import type { MinimapConfig, Minimap } from './index';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface EditorConfig {
8
+ /**
9
+ * The configuration of the minimap feature. Introduced by the {@link module:minimap/minimap~Minimap} feature.
10
+ *
11
+ * Read more in {@link module:minimap/minimapconfig~MinimapConfig}.
12
+ */
13
+ minimap?: MinimapConfig;
14
+ }
15
+ interface PluginsMap {
16
+ [Minimap.pluginName]: Minimap;
17
+ }
18
+ }
@@ -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 {};
package/src/index.d.ts CHANGED
@@ -1,10 +1,10 @@
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
7
- */
8
- export { default as Minimap } from './minimap';
9
- export type { MinimapConfig } from './minimapconfig';
10
- import './augmentation';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module minimap
7
+ */
8
+ export { default as Minimap } from './minimap';
9
+ export type { MinimapConfig } from './minimapconfig';
10
+ import './augmentation';
package/src/index.js CHANGED
@@ -1,9 +1,9 @@
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
7
- */
8
- export { default as Minimap } from './minimap';
9
- import './augmentation';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module minimap
7
+ */
8
+ export { default as Minimap } from './minimap';
9
+ import './augmentation';
package/src/minimap.d.ts CHANGED
@@ -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/minimap
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import '../theme/minimap.css';
10
- /**
11
- * The content minimap feature.
12
- */
13
- export default class Minimap extends Plugin {
14
- /**
15
- * @inheritDoc
16
- */
17
- static get pluginName(): "Minimap";
18
- /**
19
- * The reference to the view of the minimap.
20
- */
21
- private _minimapView;
22
- /**
23
- * The DOM element closest to the editable element of the editor as returned
24
- * by {@link module:ui/editorui/editorui~EditorUI#getEditableElement}.
25
- */
26
- private _scrollableRootAncestor;
27
- /**
28
- * The DOM element closest to the editable element of the editor as returned
29
- * by {@link module:ui/editorui/editorui~EditorUI#getEditableElement}.
30
- */
31
- private _editingRootElement?;
32
- /**
33
- * @inheritDoc
34
- */
35
- init(): void;
36
- /**
37
- * @inheritDoc
38
- */
39
- destroy(): void;
40
- /**
41
- * Initializes the minimap view element and starts the layout synchronization
42
- * on the editing view `render` event.
43
- */
44
- private _onUiReady;
45
- /**
46
- * Initializes the minimap view and attaches listeners that make it responsive to the environment (document)
47
- * but also allow the minimap to control the document (scroll position).
48
- */
49
- private _initializeMinimapView;
50
- /**
51
- * @private
52
- */
53
- private _syncMinimapToEditingRootScrollPosition;
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/minimap
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import '../theme/minimap.css';
10
+ /**
11
+ * The content minimap feature.
12
+ */
13
+ export default class Minimap extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): "Minimap";
18
+ /**
19
+ * The reference to the view of the minimap.
20
+ */
21
+ private _minimapView;
22
+ /**
23
+ * The DOM element closest to the editable element of the editor as returned
24
+ * by {@link module:ui/editorui/editorui~EditorUI#getEditableElement}.
25
+ */
26
+ private _scrollableRootAncestor;
27
+ /**
28
+ * The DOM element closest to the editable element of the editor as returned
29
+ * by {@link module:ui/editorui/editorui~EditorUI#getEditableElement}.
30
+ */
31
+ private _editingRootElement?;
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ init(): void;
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ destroy(): void;
40
+ /**
41
+ * Initializes the minimap view element and starts the layout synchronization
42
+ * on the editing view `render` event.
43
+ */
44
+ private _onUiReady;
45
+ /**
46
+ * Initializes the minimap view and attaches listeners that make it responsive to the environment (document)
47
+ * but also allow the minimap to control the document (scroll position).
48
+ */
49
+ private _initializeMinimapView;
50
+ /**
51
+ * @private
52
+ */
53
+ private _syncMinimapToEditingRootScrollPosition;
54
+ }
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
+ }