@ckeditor/ckeditor5-minimap 36.0.1 → 37.0.0-alpha.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-minimap",
3
- "version": "36.0.1",
3
+ "version": "37.0.0-alpha.1",
4
4
  "description": "Content minimap feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,23 +12,23 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^36.0.1"
15
+ "ckeditor5": "^37.0.0-alpha.1"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-alignment": "^36.0.1",
19
- "@ckeditor/ckeditor5-basic-styles": "^36.0.1",
20
- "@ckeditor/ckeditor5-cloud-services": "^36.0.1",
21
- "@ckeditor/ckeditor5-code-block": "^36.0.1",
22
- "@ckeditor/ckeditor5-core": "^36.0.1",
23
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
24
- "@ckeditor/ckeditor5-easy-image": "^36.0.1",
25
- "@ckeditor/ckeditor5-editor-decoupled": "^36.0.1",
26
- "@ckeditor/ckeditor5-font": "^36.0.1",
27
- "@ckeditor/ckeditor5-image": "^36.0.1",
28
- "@ckeditor/ckeditor5-indent": "^36.0.1",
29
- "@ckeditor/ckeditor5-page-break": "^36.0.1",
30
- "@ckeditor/ckeditor5-table": "^36.0.1",
31
- "@ckeditor/ckeditor5-theme-lark": "^36.0.1",
18
+ "@ckeditor/ckeditor5-alignment": "^37.0.0-alpha.1",
19
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.1",
20
+ "@ckeditor/ckeditor5-cloud-services": "^37.0.0-alpha.1",
21
+ "@ckeditor/ckeditor5-code-block": "^37.0.0-alpha.1",
22
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.1",
23
+ "@ckeditor/ckeditor5-dev-utils": "^35.0.0",
24
+ "@ckeditor/ckeditor5-easy-image": "^37.0.0-alpha.1",
25
+ "@ckeditor/ckeditor5-editor-decoupled": "^37.0.0-alpha.1",
26
+ "@ckeditor/ckeditor5-font": "^37.0.0-alpha.1",
27
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.1",
28
+ "@ckeditor/ckeditor5-indent": "^37.0.0-alpha.1",
29
+ "@ckeditor/ckeditor5-page-break": "^37.0.0-alpha.1",
30
+ "@ckeditor/ckeditor5-table": "^37.0.0-alpha.1",
31
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.1",
32
32
  "typescript": "^4.8.4",
33
33
  "webpack": "^5.58.1",
34
34
  "webpack-cli": "^4.9.0"
@@ -57,7 +57,8 @@
57
57
  ],
58
58
  "scripts": {
59
59
  "dll:build": "webpack",
60
- "build": "tsc -p ./tsconfig.release.json",
60
+ "build": "tsc -p ./tsconfig.json",
61
61
  "postversion": "npm run build"
62
- }
62
+ },
63
+ "types": "src/index.d.ts"
63
64
  }
@@ -0,0 +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
+ }
@@ -0,0 +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 {};
package/src/index.d.ts ADDED
@@ -0,0 +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';
package/src/index.js CHANGED
@@ -6,3 +6,4 @@
6
6
  * @module minimap
7
7
  */
8
8
  export { default as Minimap } from './minimap';
9
+ import './augmentation';
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +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 {};
@@ -0,0 +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
+ }
@@ -0,0 +1,58 @@
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/minimappositiontrackerview
7
+ */
8
+ import { View } from 'ckeditor5/src/ui';
9
+ import { type Locale } from 'ckeditor5/src/utils';
10
+ /**
11
+ * The position tracker visualizing the visible subset of the content. Displayed over the minimap.
12
+ *
13
+ * @internal
14
+ */
15
+ export default class MinimapPositionTrackerView extends View {
16
+ /**
17
+ * The CSS `height` of the tracker visualizing the subset of the content visible to the user.
18
+ *
19
+ * @readonly
20
+ */
21
+ height: number;
22
+ /**
23
+ * The CSS `top` of the tracker, used to move it vertically over the minimap.
24
+ *
25
+ * @readonly
26
+ */
27
+ top: number;
28
+ /**
29
+ * The scroll progress (in %) displayed over the tracker when being dragged by the user.
30
+ *
31
+ * @readonly
32
+ */
33
+ scrollProgress: number;
34
+ /**
35
+ * Indicates whether the tracker is being dragged by the user (e.g. using the mouse).
36
+ *
37
+ * @internal
38
+ * @readonly
39
+ */
40
+ _isDragging: boolean;
41
+ constructor(locale: Locale);
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ render(): void;
46
+ /**
47
+ * Sets the new height of the tracker to visualize the subset of the content visible to the user.
48
+ */
49
+ setHeight(newHeight: number): void;
50
+ /**
51
+ * Sets the top offset of the tracker to move it around vertically.
52
+ */
53
+ setTopOffset(newOffset: number): void;
54
+ /**
55
+ * Sets the scroll progress (in %) to inform the user using a label when the tracker is being dragged.
56
+ */
57
+ setScrollProgress(newProgress: number): void;
58
+ }
@@ -0,0 +1,109 @@
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/minimapview
7
+ */
8
+ import { View } from 'ckeditor5/src/ui';
9
+ import { type Locale } from 'ckeditor5/src/utils';
10
+ export type MinimapViewOptions = {
11
+ domRootClone: HTMLElement;
12
+ pageStyles: Array<string | {
13
+ href: string;
14
+ }>;
15
+ scaleRatio: number;
16
+ useSimplePreview?: boolean;
17
+ extraClasses?: string;
18
+ };
19
+ /**
20
+ * The main view of the minimap. It renders the original content but scaled down with a tracker element
21
+ * visualizing the subset of the content visible to the user and allowing interactions (scrolling, dragging).
22
+ *
23
+ * @internal
24
+ */
25
+ export default class MinimapView extends View {
26
+ /**
27
+ * An instance of the tracker view displayed over the minimap.
28
+ */
29
+ private readonly _positionTrackerView;
30
+ /**
31
+ * The scale ratio of the minimap relative to the original editing DOM root with the content.
32
+ */
33
+ private readonly _scaleRatio;
34
+ /**
35
+ * An instance of the iframe view that hosts the minimap.
36
+ */
37
+ private readonly _minimapIframeView;
38
+ /**
39
+ * Creates an instance of the minimap view.
40
+ */
41
+ constructor({ locale, scaleRatio, pageStyles, extraClasses, useSimplePreview, domRootClone }: {
42
+ locale: Locale;
43
+ } & MinimapViewOptions);
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ destroy(): void;
48
+ /**
49
+ * Returns the DOM {@link module:utils/dom/rect~Rect} height of the minimap.
50
+ */
51
+ get height(): number;
52
+ /**
53
+ * Returns the number of available space (pixels) the position tracker (visible subset of the content) can use to scroll vertically.
54
+ */
55
+ get scrollHeight(): number;
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ render(): void;
60
+ /**
61
+ * Sets the new height of the minimap (in px) to respond to the changes in the original editing DOM root.
62
+ *
63
+ * **Note**:The provided value should be the `offsetHeight` of the original editing DOM root.
64
+ */
65
+ setContentHeight(newHeight: number): void;
66
+ /**
67
+ * Sets the minimap scroll progress.
68
+ *
69
+ * The minimap scroll progress is linked to the original editing DOM root and its scrollable container (ancestor).
70
+ * Changing the progress will alter the vertical position of the minimap (and its position tracker) and give the user an accurate
71
+ * overview of the visible document.
72
+ *
73
+ * **Note**: The value should be between 0 and 1. 0 when the DOM root has not been scrolled, 1 when the
74
+ * scrolling has reached the end.
75
+ */
76
+ setScrollProgress(newScrollProgress: number): void;
77
+ /**
78
+ * Sets the new height of the tracker (in px) to visualize the subset of the content visible to the user.
79
+ */
80
+ setPositionTrackerHeight(trackerHeight: number): void;
81
+ /**
82
+ * @param data DOM event data
83
+ */
84
+ private _handleMinimapClick;
85
+ /**
86
+ * @param data DOM event data
87
+ */
88
+ private _handleMinimapMouseWheel;
89
+ }
90
+ /**
91
+ * Fired when the minimap view is clicked.
92
+ *
93
+ * @eventName ~MinimapView#click
94
+ * @param percentage The number between 0 and 1 representing a place in the minimap (its height) that was clicked.
95
+ */
96
+ export type MinimapClickEvent = {
97
+ name: 'click';
98
+ args: [percentage: number];
99
+ };
100
+ /**
101
+ * Fired when the position tracker is dragged or the minimap is scrolled via mouse wheel.
102
+ *
103
+ * @eventName ~MinimapView#drag
104
+ * @param movementY The vertical movement of the minimap as a result of dragging or scrolling.
105
+ */
106
+ export type MinimapDragEvent = {
107
+ name: 'drag';
108
+ args: [movementY: number];
109
+ };
package/src/utils.d.ts ADDED
@@ -0,0 +1,61 @@
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/utils
7
+ */
8
+ import { Rect } from 'ckeditor5/src/utils';
9
+ import type { Editor } from 'ckeditor5/src/core';
10
+ /**
11
+ * Clones the editing view DOM root by using a dedicated pair of {@link module:engine/view/renderer~Renderer} and
12
+ * {@link module:engine/view/domconverter~DomConverter}. The DOM root clone updates incrementally to stay in sync with the
13
+ * source root.
14
+ *
15
+ * @internal
16
+ * @param editor The editor instance the original editing root belongs to.
17
+ * @param rootName The name of the root to clone.
18
+ * @returns The editing root DOM clone element.
19
+ */
20
+ export declare function cloneEditingViewDomRoot(editor: Editor, rootName?: string): HTMLElement;
21
+ /**
22
+ * Harvests all web page styles, for instance, to allow re-using them in an `<iframe>` preserving the look of the content.
23
+ *
24
+ * The returned data format is as follows:
25
+ *
26
+ * ```ts
27
+ * [
28
+ * 'p { color: red; ... } h2 { font-size: 2em; ... } ...',
29
+ * '.spacing { padding: 1em; ... }; ...',
30
+ * '...',
31
+ * { href: 'http://link.to.external.stylesheet' },
32
+ * { href: '...' }
33
+ * ]
34
+ * ```
35
+ *
36
+ * **Note**: For stylesheets with `href` different than window origin, an object is returned because
37
+ * accessing rules of these styles may cause CORS errors (depending on the configuration of the web page).
38
+ *
39
+ * @internal
40
+ */
41
+ export declare function getPageStyles(): Array<string | {
42
+ href: string;
43
+ }>;
44
+ /**
45
+ * Gets dimensions rectangle according to passed DOM element. Returns whole window's size for `body` element.
46
+ *
47
+ * @internal
48
+ */
49
+ export declare function getDomElementRect(domElement: HTMLElement): Rect;
50
+ /**
51
+ * Gets client height according to passed DOM element. Returns window's height for `body` element.
52
+ *
53
+ * @internal
54
+ */
55
+ export declare function getClientHeight(domElement: HTMLElement): number;
56
+ /**
57
+ * Returns the DOM element itself if it's not a `body` element, whole window otherwise.
58
+ *
59
+ * @internal
60
+ */
61
+ export declare function getScrollable(domElement: HTMLElement): Window | HTMLElement;