@ckeditor/ckeditor5-widget 33.0.0 → 34.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
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor 5 widget API** – https://github.com/ckeditor/ckeditor5-image <br>
5
- Copyright (c) 2003-2022, [CKSource](http://cksource.com) Holding sp. z o.o. All rights reserved.
5
+ Copyright (c) 2003-2022, [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](http://cksource.com) Holding sp. z o.o. 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/README.md CHANGED
@@ -3,7 +3,8 @@ CKEditor 5 widget API
3
3
 
4
4
  [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-widget.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-widget)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
6
- [![Build Status](https://travis-ci.com/ckeditor/ckeditor5.svg?branch=master)](https://travis-ci.com/ckeditor/ckeditor5)
6
+ [![Build Status](https://travis-ci.com/ckeditor/ckeditor5.svg?branch=master)](https://app.travis-ci.com/github/ckeditor/ckeditor5)
7
+ ![Dependency Status](https://img.shields.io/librariesio/release/npm/@ckeditor/ckeditor5-widget)
7
8
 
8
9
  This package implements the widget API for CKEditor 5.
9
10
 
@@ -14,7 +14,7 @@ msgid ""
14
14
  msgstr ""
15
15
  "Language-Team: Spanish (https://www.transifex.com/ckeditor/teams/11143/es/)\n"
16
16
  "Language: es\n"
17
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+ "Plural-Forms: nplurals=3; plural=n == 1 ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;\n"
18
18
 
19
19
  msgctxt "The label used by assistive technologies describing a toolbar attached to a widget."
20
20
  msgid "Widget toolbar"
@@ -14,7 +14,7 @@ msgid ""
14
14
  msgstr ""
15
15
  "Language-Team: French (https://www.transifex.com/ckeditor/teams/11143/fr/)\n"
16
16
  "Language: fr\n"
17
- "Plural-Forms: nplurals=2; plural=(n > 1);\n"
17
+ "Plural-Forms: nplurals=3; plural=(n == 0 || n == 1) ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;\n"
18
18
 
19
19
  msgctxt "The label used by assistive technologies describing a toolbar attached to a widget."
20
20
  msgid "Widget toolbar"
@@ -22,8 +22,8 @@ msgstr "Traka sa spravicama"
22
22
 
23
23
  msgctxt "The title displayed when a mouse is over a button that inserts a paragraph before a block."
24
24
  msgid "Insert paragraph before block"
25
- msgstr ""
25
+ msgstr "Umetni odlomak prije bloka"
26
26
 
27
27
  msgctxt "The title displayed when a mouse is over a button that inserts a paragraph after a block."
28
28
  msgid "Insert paragraph after block"
29
- msgstr ""
29
+ msgstr "Umetni odlomak poslije bloka"
@@ -22,8 +22,8 @@ msgstr "Alat widget"
22
22
 
23
23
  msgctxt "The title displayed when a mouse is over a button that inserts a paragraph before a block."
24
24
  msgid "Insert paragraph before block"
25
- msgstr ""
25
+ msgstr "Tambahkan paragraf sebelum blok"
26
26
 
27
27
  msgctxt "The title displayed when a mouse is over a button that inserts a paragraph after a block."
28
28
  msgid "Insert paragraph after block"
29
- msgstr ""
29
+ msgstr "Tambahkan paragraf setelah blok"
@@ -14,7 +14,7 @@ msgid ""
14
14
  msgstr ""
15
15
  "Language-Team: Italian (https://www.transifex.com/ckeditor/teams/11143/it/)\n"
16
16
  "Language: it\n"
17
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+ "Plural-Forms: nplurals=3; plural=n == 1 ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;\n"
18
18
 
19
19
  msgctxt "The label used by assistive technologies describing a toolbar attached to a widget."
20
20
  msgid "Widget toolbar"
@@ -22,8 +22,8 @@ msgstr "Sīkrīku rīkjosla"
22
22
 
23
23
  msgctxt "The title displayed when a mouse is over a button that inserts a paragraph before a block."
24
24
  msgid "Insert paragraph before block"
25
- msgstr ""
25
+ msgstr "Ievietot paragrāfu pirms bloka"
26
26
 
27
27
  msgctxt "The title displayed when a mouse is over a button that inserts a paragraph after a block."
28
28
  msgid "Insert paragraph after block"
29
- msgstr ""
29
+ msgstr "Ievietot paragrāfu aiz bloka"
@@ -14,7 +14,7 @@ msgid ""
14
14
  msgstr ""
15
15
  "Language-Team: Portuguese (Brazil) (https://www.transifex.com/ckeditor/teams/11143/pt_BR/)\n"
16
16
  "Language: pt_BR\n"
17
- "Plural-Forms: nplurals=2; plural=(n > 1);\n"
17
+ "Plural-Forms: nplurals=3; plural=(n == 0 || n == 1) ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;\n"
18
18
 
19
19
  msgctxt "The label used by assistive technologies describing a toolbar attached to a widget."
20
20
  msgid "Widget toolbar"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-widget",
3
- "version": "33.0.0",
3
+ "version": "34.2.0",
4
4
  "description": "Widget API for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -11,29 +11,29 @@
11
11
  ],
12
12
  "main": "src/index.js",
13
13
  "dependencies": {
14
- "@ckeditor/ckeditor5-core": "^33.0.0",
15
- "@ckeditor/ckeditor5-engine": "^33.0.0",
16
- "@ckeditor/ckeditor5-enter": "^33.0.0",
17
- "@ckeditor/ckeditor5-ui": "^33.0.0",
18
- "@ckeditor/ckeditor5-utils": "^33.0.0",
19
- "@ckeditor/ckeditor5-typing": "^33.0.0",
14
+ "@ckeditor/ckeditor5-core": "^34.2.0",
15
+ "@ckeditor/ckeditor5-engine": "^34.2.0",
16
+ "@ckeditor/ckeditor5-enter": "^34.2.0",
17
+ "@ckeditor/ckeditor5-ui": "^34.2.0",
18
+ "@ckeditor/ckeditor5-utils": "^34.2.0",
19
+ "@ckeditor/ckeditor5-typing": "^34.2.0",
20
20
  "lodash-es": "^4.17.15"
21
21
  },
22
22
  "devDependencies": {
23
- "@ckeditor/ckeditor5-basic-styles": "^33.0.0",
24
- "@ckeditor/ckeditor5-block-quote": "^33.0.0",
25
- "@ckeditor/ckeditor5-clipboard": "^33.0.0",
26
- "@ckeditor/ckeditor5-editor-balloon": "^33.0.0",
27
- "@ckeditor/ckeditor5-editor-classic": "^33.0.0",
28
- "@ckeditor/ckeditor5-essentials": "^33.0.0",
29
- "@ckeditor/ckeditor5-heading": "^33.0.0",
30
- "@ckeditor/ckeditor5-horizontal-line": "^33.0.0",
31
- "@ckeditor/ckeditor5-image": "^33.0.0",
32
- "@ckeditor/ckeditor5-link": "^33.0.0",
33
- "@ckeditor/ckeditor5-media-embed": "^33.0.0",
34
- "@ckeditor/ckeditor5-paragraph": "^33.0.0",
35
- "@ckeditor/ckeditor5-table": "^33.0.0",
36
- "@ckeditor/ckeditor5-undo": "^33.0.0"
23
+ "@ckeditor/ckeditor5-basic-styles": "^34.2.0",
24
+ "@ckeditor/ckeditor5-block-quote": "^34.2.0",
25
+ "@ckeditor/ckeditor5-clipboard": "^34.2.0",
26
+ "@ckeditor/ckeditor5-editor-balloon": "^34.2.0",
27
+ "@ckeditor/ckeditor5-editor-classic": "^34.2.0",
28
+ "@ckeditor/ckeditor5-essentials": "^34.2.0",
29
+ "@ckeditor/ckeditor5-heading": "^34.2.0",
30
+ "@ckeditor/ckeditor5-horizontal-line": "^34.2.0",
31
+ "@ckeditor/ckeditor5-image": "^34.2.0",
32
+ "@ckeditor/ckeditor5-link": "^34.2.0",
33
+ "@ckeditor/ckeditor5-media-embed": "^34.2.0",
34
+ "@ckeditor/ckeditor5-paragraph": "^34.2.0",
35
+ "@ckeditor/ckeditor5-table": "^34.2.0",
36
+ "@ckeditor/ckeditor5-undo": "^34.2.0"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=14.0.0",
package/src/utils.js CHANGED
@@ -9,6 +9,9 @@
9
9
 
10
10
  import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
11
11
  import toArray from '@ckeditor/ckeditor5-utils/src/toarray';
12
+ import {
13
+ findOptimalInsertionRange as engineFindOptimalInsertionRange
14
+ } from '@ckeditor/ckeditor5-engine/src/model/utils/findoptimalinsertionrange';
12
15
 
13
16
  import HighlightStack from './highlightstack';
14
17
  import { getTypeAroundFakeCaretPosition } from './widgettypearound/utils';
@@ -307,33 +310,9 @@ export function findOptimalInsertionRange( selection, model ) {
307
310
  if ( typeAroundFakeCaretPosition ) {
308
311
  return model.createRange( model.createPositionAt( selectedElement, typeAroundFakeCaretPosition ) );
309
312
  }
310
-
311
- if ( model.schema.isObject( selectedElement ) && !model.schema.isInline( selectedElement ) ) {
312
- return model.createRangeOn( selectedElement );
313
- }
314
- }
315
-
316
- const firstBlock = selection.getSelectedBlocks().next().value;
317
-
318
- if ( firstBlock ) {
319
- // If inserting into an empty block – return position in that block. It will get
320
- // replaced with the image by insertContent(). #42.
321
- if ( firstBlock.isEmpty ) {
322
- return model.createRange( model.createPositionAt( firstBlock, 0 ) );
323
- }
324
-
325
- const positionAfter = model.createPositionAfter( firstBlock );
326
-
327
- // If selection is at the end of the block - return position after the block.
328
- if ( selection.focus.isTouching( positionAfter ) ) {
329
- return model.createRange( positionAfter );
330
- }
331
-
332
- // Otherwise return position before the block.
333
- return model.createRange( model.createPositionBefore( firstBlock ) );
334
313
  }
335
314
 
336
- return model.createRange( selection.focus );
315
+ return engineFindOptimalInsertionRange( selection, model );
337
316
  }
338
317
 
339
318
  /**
@@ -121,6 +121,7 @@ export default class WidgetTypeAround extends Plugin {
121
121
  this._enableTypeAroundFakeCaretActivationUsingKeyboardArrows();
122
122
  this._enableDeleteIntegration();
123
123
  this._enableInsertContentIntegration();
124
+ this._enableInsertObjectIntegration();
124
125
  this._enableDeleteContentIntegration();
125
126
  }
126
127
 
@@ -145,8 +146,11 @@ export default class WidgetTypeAround extends Plugin {
145
146
  const editor = this.editor;
146
147
  const editingView = editor.editing.view;
147
148
 
149
+ const attributesToCopy = editor.model.schema.getAttributesWithProperty( widgetModelElement, 'copyOnReplace', true );
150
+
148
151
  editor.execute( 'insertParagraph', {
149
- position: editor.model.createPositionAt( widgetModelElement, position )
152
+ position: editor.model.createPositionAt( widgetModelElement, position ),
153
+ attributes: attributesToCopy
150
154
  } );
151
155
 
152
156
  editingView.focus();
@@ -779,6 +783,38 @@ export default class WidgetTypeAround extends Plugin {
779
783
  }, { priority: 'high' } );
780
784
  }
781
785
 
786
+ /**
787
+ * Attaches the {@link module:engine/model/model~Model#event:insertObject} event listener that modifies the
788
+ * `options.findOptimalPosition`parameter to position of fake caret in relation to selected element
789
+ * to reflect user's intent of desired insertion position.
790
+ *
791
+ * The object is inserted according to the `widget-type-around` selection attribute (see {@link #_handleArrowKeyPress}).
792
+ *
793
+ * @private
794
+ */
795
+ _enableInsertObjectIntegration() {
796
+ const editor = this.editor;
797
+ const model = this.editor.model;
798
+ const documentSelection = model.document.selection;
799
+
800
+ this._listenToIfEnabled( editor.model, 'insertObject', ( evt, args ) => {
801
+ const [ , selectable, , options = {} ] = args;
802
+
803
+ if ( selectable && !selectable.is( 'documentSelection' ) ) {
804
+ return;
805
+ }
806
+
807
+ const typeAroundFakeCaretPosition = getTypeAroundFakeCaretPosition( documentSelection );
808
+
809
+ if ( !typeAroundFakeCaretPosition ) {
810
+ return;
811
+ }
812
+
813
+ options.findOptimalPosition = typeAroundFakeCaretPosition;
814
+ args[ 3 ] = options;
815
+ }, { priority: 'high' } );
816
+ }
817
+
782
818
  /**
783
819
  * Attaches the {@link module:engine/model/model~Model#event:deleteContent} event listener to block the event when the fake
784
820
  * caret is active.