@ckeditor/ckeditor5-minimap 35.3.2 → 36.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.
@@ -1,115 +1,68 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module minimap/minimapiframeview
8
7
  */
9
-
10
8
  import { IframeView } from 'ckeditor5/src/ui';
11
9
  import { toUnit } from 'ckeditor5/src/utils';
12
-
13
- const toPx = toUnit( 'px' );
14
-
10
+ const toPx = toUnit('px');
15
11
  /**
16
12
  * The internal `<iframe>` view that hosts the minimap content.
17
13
  *
18
- * @private
19
- * @extends module:ui/iframe/iframeview~IframeView
14
+ * @internal
20
15
  */
21
16
  export default class MinimapIframeView extends IframeView {
22
- /**
23
- * Creates an instance of the internal minimap iframe.
24
- *
25
- * @param {module:utils/locale~Locale} locale
26
- * @param {Object} options
27
- * @param {HTMLElement} options.domRootClone
28
- * @param {Array} options.pageStyles
29
- * @param {Number} options.scaleRatio
30
- * @param {Boolean} [options.useSimplePreview]
31
- * @param {String} [options.extraClasses]
32
- */
33
- constructor( locale, options ) {
34
- super( locale );
35
-
36
- const bind = this.bindTemplate;
37
-
38
- /**
39
- * The CSS `top` used to scroll the minimap.
40
- *
41
- * @readonly
42
- * @member {Number} #top
43
- */
44
- this.set( 'top', 0 );
45
-
46
- /**
47
- * The CSS `height` of the iframe.
48
- *
49
- * @readonly
50
- * @member {Number} #height
51
- */
52
- this.set( 'height', 0 );
53
-
54
- /**
55
- * Cached view constructor options for re-use in other methods.
56
- *
57
- * @readonly
58
- * @member {Object} #options
59
- */
60
- this._options = options;
61
-
62
- this.extendTemplate( {
63
- attributes: {
64
- class: [
65
- 'ck-minimap__iframe'
66
- ],
67
- style: {
68
- top: bind.to( 'top', top => toPx( top ) ),
69
- height: bind.to( 'height', height => toPx( height ) )
70
- }
71
- }
72
- } );
73
- }
74
-
75
- /**
76
- * @inheritDoc
77
- */
78
- render() {
79
- return super.render().then( () => {
80
- this._prepareDocument();
81
- } );
82
- }
83
-
84
- /**
85
- * Sets the new height of the iframe.
86
- *
87
- * @param {Number} newHeight
88
- */
89
- setHeight( newHeight ) {
90
- this.height = newHeight;
91
- }
92
-
93
- /**
94
- * Sets the top offset of the iframe to move it around vertically.
95
- *
96
- * @param {Number} newOffset
97
- */
98
- setTopOffset( newOffset ) {
99
- this.top = newOffset;
100
- }
101
-
102
- /**
103
- * Sets the internal structure of the `<iframe>` readying it to display the
104
- * minimap element.
105
- *
106
- * @private
107
- */
108
- _prepareDocument() {
109
- const iframeDocument = this.element.contentWindow.document;
110
- const domRootClone = iframeDocument.adoptNode( this._options.domRootClone );
111
-
112
- const boxStyles = this._options.useSimplePreview ? `
17
+ /**
18
+ * Creates an instance of the internal minimap iframe.
19
+ */
20
+ constructor(locale, options) {
21
+ super(locale);
22
+ const bind = this.bindTemplate;
23
+ this.set('top', 0);
24
+ this.set('height', 0);
25
+ this._options = options;
26
+ this.extendTemplate({
27
+ attributes: {
28
+ class: [
29
+ 'ck-minimap__iframe'
30
+ ],
31
+ style: {
32
+ top: bind.to('top', top => toPx(top)),
33
+ height: bind.to('height', height => toPx(height))
34
+ }
35
+ }
36
+ });
37
+ }
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ render() {
42
+ return super.render().then(() => {
43
+ this._prepareDocument();
44
+ });
45
+ }
46
+ /**
47
+ * Sets the new height of the iframe.
48
+ */
49
+ setHeight(newHeight) {
50
+ this.height = newHeight;
51
+ }
52
+ /**
53
+ * Sets the top offset of the iframe to move it around vertically.
54
+ */
55
+ setTopOffset(newOffset) {
56
+ this.top = newOffset;
57
+ }
58
+ /**
59
+ * Sets the internal structure of the `<iframe>` readying it to display the
60
+ * minimap element.
61
+ */
62
+ _prepareDocument() {
63
+ const iframeDocument = this.element.contentWindow.document;
64
+ const domRootClone = iframeDocument.adoptNode(this._options.domRootClone);
65
+ const boxStyles = this._options.useSimplePreview ? `
113
66
  .ck.ck-editor__editable_inline img {
114
67
  filter: contrast( 0 );
115
68
  }
@@ -124,20 +77,19 @@ export default class MinimapIframeView extends IframeView {
124
77
  color: hsl(0, 0%, 60%) !important;
125
78
  }
126
79
  ` : '';
127
-
128
- const pageStyles = this._options.pageStyles.map( definition => {
129
- if ( typeof definition === 'string' ) {
130
- return `<style>${ definition }</style>`;
131
- } else {
132
- return `<link rel="stylesheet" type="text/css" href="${ definition.href }">`;
133
- }
134
- } ).join( '\n' );
135
-
136
- const html = `<!DOCTYPE html><html lang="en">
80
+ const pageStyles = this._options.pageStyles.map(definition => {
81
+ if (typeof definition === 'string') {
82
+ return `<style>${definition}</style>`;
83
+ }
84
+ else {
85
+ return `<link rel="stylesheet" type="text/css" href="${definition.href}">`;
86
+ }
87
+ }).join('\n');
88
+ const html = `<!DOCTYPE html><html lang="en">
137
89
  <head>
138
90
  <meta charset="utf-8">
139
91
  <meta name="viewport" content="width=device-width, initial-scale=1">
140
- ${ pageStyles }
92
+ ${pageStyles}
141
93
  <style>
142
94
  html, body {
143
95
  margin: 0 !important;
@@ -149,7 +101,7 @@ export default class MinimapIframeView extends IframeView {
149
101
  }
150
102
 
151
103
  body {
152
- transform: scale( ${ this._options.scaleRatio } );
104
+ transform: scale( ${this._options.scaleRatio} );
153
105
  transform-origin: 0 0;
154
106
  overflow: visible;
155
107
  }
@@ -165,15 +117,14 @@ export default class MinimapIframeView extends IframeView {
165
117
  background: white;
166
118
  }
167
119
 
168
- ${ boxStyles }
120
+ ${boxStyles}
169
121
  </style>
170
122
  </head>
171
- <body class="${ this._options.extraClasses || '' }"></body>
123
+ <body class="${this._options.extraClasses || ''}"></body>
172
124
  </html>`;
173
-
174
- iframeDocument.open();
175
- iframeDocument.write( html );
176
- iframeDocument.close();
177
- iframeDocument.body.appendChild( domRootClone );
178
- }
125
+ iframeDocument.open();
126
+ iframeDocument.write(html);
127
+ iframeDocument.close();
128
+ iframeDocument.body.appendChild(domRootClone);
129
+ }
179
130
  }
@@ -1,134 +1,78 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module minimap/minimappositiontrackerview
8
7
  */
9
-
10
8
  import { View } from 'ckeditor5/src/ui';
11
9
  import { toUnit, global } from 'ckeditor5/src/utils';
12
-
13
- const toPx = toUnit( 'px' );
14
-
10
+ const toPx = toUnit('px');
15
11
  /**
16
12
  * The position tracker visualizing the visible subset of the content. Displayed over the minimap.
17
13
  *
18
- * @private
19
- * @extends module:ui/view~View
14
+ * @internal
20
15
  */
21
16
  export default class MinimapPositionTrackerView extends View {
22
- constructor( locale ) {
23
- super( locale );
24
-
25
- const bind = this.bindTemplate;
26
-
27
- /**
28
- * The CSS `height` of the tracker visualizing the subset of the content visible to the user.
29
- *
30
- * @readonly
31
- * @member {Number} #height
32
- */
33
- this.set( 'height', 0 );
34
-
35
- /**
36
- * The CSS `top` of the tracker, used to move it vertically over the minimap.
37
- *
38
- * @readonly
39
- * @member {Number} #top
40
- */
41
- this.set( 'top', 0 );
42
-
43
- /**
44
- * The scroll progress (in %) displayed over the tracker when being dragged by the user.
45
- *
46
- * @readonly
47
- * @member {Number} #scrollProgress
48
- */
49
- this.set( 'scrollProgress', 0 );
50
-
51
- /**
52
- * Indicates whether the tracker is being dragged by the user (e.g. using the mouse).
53
- *
54
- * @private
55
- * @readonly
56
- * @member {Boolean} #_isDragging
57
- */
58
- this.set( '_isDragging', false );
59
-
60
- this.setTemplate( {
61
- tag: 'div',
62
- attributes: {
63
- class: [
64
- 'ck',
65
- 'ck-minimap__position-tracker',
66
- bind.if( '_isDragging', 'ck-minimap__position-tracker_dragging' )
67
- ],
68
- style: {
69
- top: bind.to( 'top', top => toPx( top ) ),
70
- height: bind.to( 'height', height => toPx( height ) )
71
- },
72
- 'data-progress': bind.to( 'scrollProgress' )
73
- },
74
- on: {
75
- mousedown: bind.to( () => {
76
- this._isDragging = true;
77
- } )
78
- }
79
- } );
80
-
81
- /**
82
- * Fired when the position tracker is dragged.
83
- *
84
- * @event drag
85
- * @param {Number} movementY The vertical movement of the tracker as a result of dragging.
86
- */
87
- }
88
-
89
- /**
90
- * @inheritDoc
91
- */
92
- render() {
93
- super.render();
94
-
95
- this.listenTo( global.document, 'mousemove', ( evt, data ) => {
96
- if ( !this._isDragging ) {
97
- return;
98
- }
99
-
100
- this.fire( 'drag', data.movementY );
101
- }, { useCapture: true } );
102
-
103
- this.listenTo( global.document, 'mouseup', () => {
104
- this._isDragging = false;
105
- }, { useCapture: true } );
106
- }
107
-
108
- /**
109
- * Sets the new height of the tracker to visualize the subset of the content visible to the user.
110
- *
111
- * @param {Number} newHeight
112
- */
113
- setHeight( newHeight ) {
114
- this.height = newHeight;
115
- }
116
-
117
- /**
118
- * Sets the top offset of the tracker to move it around vertically.
119
- *
120
- * @param {Number} newOffset
121
- */
122
- setTopOffset( newOffset ) {
123
- this.top = newOffset;
124
- }
125
-
126
- /**
127
- * Sets the scroll progress (in %) to inform the user using a label when the tracker is being dragged.
128
- *
129
- * @param {Number} newProgress
130
- */
131
- setScrollProgress( newProgress ) {
132
- this.scrollProgress = newProgress;
133
- }
17
+ constructor(locale) {
18
+ super(locale);
19
+ const bind = this.bindTemplate;
20
+ this.set('height', 0);
21
+ this.set('top', 0);
22
+ this.set('scrollProgress', 0);
23
+ this.set('_isDragging', false);
24
+ this.setTemplate({
25
+ tag: 'div',
26
+ attributes: {
27
+ class: [
28
+ 'ck',
29
+ 'ck-minimap__position-tracker',
30
+ bind.if('_isDragging', 'ck-minimap__position-tracker_dragging')
31
+ ],
32
+ style: {
33
+ top: bind.to('top', top => toPx(top)),
34
+ height: bind.to('height', height => toPx(height))
35
+ },
36
+ 'data-progress': bind.to('scrollProgress')
37
+ },
38
+ on: {
39
+ mousedown: bind.to(() => {
40
+ this._isDragging = true;
41
+ })
42
+ }
43
+ });
44
+ }
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ render() {
49
+ super.render();
50
+ this.listenTo(global.document, 'mousemove', (evt, data) => {
51
+ if (!this._isDragging) {
52
+ return;
53
+ }
54
+ this.fire('drag', data.movementY);
55
+ }, { useCapture: true });
56
+ this.listenTo(global.document, 'mouseup', () => {
57
+ this._isDragging = false;
58
+ }, { useCapture: true });
59
+ }
60
+ /**
61
+ * Sets the new height of the tracker to visualize the subset of the content visible to the user.
62
+ */
63
+ setHeight(newHeight) {
64
+ this.height = newHeight;
65
+ }
66
+ /**
67
+ * Sets the top offset of the tracker to move it around vertically.
68
+ */
69
+ setTopOffset(newOffset) {
70
+ this.top = newOffset;
71
+ }
72
+ /**
73
+ * Sets the scroll progress (in %) to inform the user using a label when the tracker is being dragged.
74
+ */
75
+ setScrollProgress(newProgress) {
76
+ this.scrollProgress = newProgress;
77
+ }
134
78
  }