qms-angular 1.1.35 → 1.1.36

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.
@@ -149,6 +149,10 @@ export default class LinkCommand extends Command {
149
149
  * @param {Object} [manualDecoratorIds={}] The information about manual decorator attributes to be applied or removed upon execution.
150
150
  */
151
151
  execute(options) {
152
+ if(!options) {
153
+ return;
154
+ }
155
+
152
156
  const model = this.editor.model;
153
157
  const selection = model.document.selection;
154
158
  const manualDecoratorIds = {};
@@ -4,9 +4,10 @@ import { Collection, first } from '@ckeditor/ckeditor5-utils';
4
4
  import * as QMSCKEditorConstant from '../common/qmsCKEditorConstant';
5
5
  import * as QMSCKEditorEnum from '../common/qmsCKEditorEnum';
6
6
  import * as QMSCKEditorService from '../common/qmsCKEditorService';
7
- import { isImageAllowed } from './utils';
7
+ import { isImageAllowed, isLinkElement} from './utils';
8
8
  import AutomaticDecorators from './utils/automaticdecorators';
9
-
9
+ import * as QMSCKEditorUtil from '../common/qmsCKEditorUtil';
10
+
10
11
  export default class LinkDialogCommand extends Command {
11
12
  constructor( editor ) {
12
13
  super( editor );
@@ -48,18 +49,38 @@ import AutomaticDecorators from './utils/automaticdecorators';
48
49
  const ranges = selection.getFirstRange();
49
50
 
50
51
  let link = QMSCKEditorEnum.hyperLink;
51
- link.typeId = 0;
52
- link.targetId = 0;
53
- link.protocolId = 0;
54
- link.url = '';
55
- link.title = '';
56
- link.editorContent = '';
57
- link.ckeditorId = editor.id;
58
- for (const item of ranges.getItems()) {
59
- if (item.data) {
60
- link.title = item.data;
61
- }
62
- }
52
+
53
+ let parentLink = this._getSelectedLinkElement();
54
+
55
+ if(parentLink) {
56
+ let linkOption = parentLink.getAttribute('url') || parentLink.getAttribute('option');
57
+ link.typeId = QMSCKEditorUtil.getLinkType(linkOption);
58
+ link.targetId = parentLink.getAttribute('target') ? QMSCKEditorEnum.targetEnum[parentLink.getAttribute('target')] : 0;
59
+ if (parentLink._children.length > 0) {
60
+ link.title = parentLink._children[0]._textData ? parentLink._children[0]._textData.trim() : '';
61
+ }
62
+ else {
63
+ link.title = '';
64
+ }
65
+ link.protocolId = QMSCKEditorUtil.getProtocolId(linkOption);
66
+ link.url = parentLink.getAttribute('href') || '';
67
+ link.edit = true;
68
+ link.ckeditorId = editor.id;
69
+ } else {
70
+ link.typeId = 0;
71
+ link.targetId = 0;
72
+ link.protocolId = 0;
73
+ link.url = '';
74
+ link.title = '';
75
+ link.editorContent = '';
76
+ link.ckeditorId = editor.id;
77
+ for (const item of ranges.getItems()) {
78
+ if (item.data) {
79
+ link.title = item.data;
80
+ }
81
+ }
82
+ }
83
+
63
84
  QMSCKEditorService.linkNotify(link);
64
85
  window[QMSCKEditorConstant.QMSCK_LINKED] = false;
65
86
  window.addEventListener(QMSCKEditorConstant.QMSCK_LINK_PLUGIN_RESP, function(evt) {
@@ -88,4 +109,35 @@ import AutomaticDecorators from './utils/automaticdecorators';
88
109
 
89
110
  return doc.selection.getAttribute( decoratorName );
90
111
  }
112
+
113
+ _getSelectedLinkElement() {
114
+ const view = this.editor.editing.view;
115
+ const selection = view.document.selection;
116
+
117
+ if ( selection.isCollapsed ) {
118
+ return findLinkElementAncestor( selection.getFirstPosition() );
119
+ } else {
120
+ // The range for fully selected link is usually anchored in adjacent text nodes.
121
+ // Trim it to get closer to the actual link element.
122
+ const range = selection.getFirstRange().getTrimmed();
123
+ const startLink = findLinkElementAncestor( range.start );
124
+ const endLink = findLinkElementAncestor( range.end );
125
+
126
+ if ( !startLink || startLink != endLink ) {
127
+ return null;
128
+ }
129
+
130
+ // Check if the link element is fully selected.
131
+ if ( view.createRangeIn( startLink ).getTrimmed().isEqual( range ) ) {
132
+ return startLink;
133
+ } else {
134
+ return null;
135
+ }
136
+ }
137
+ }
138
+
91
139
  }
140
+
141
+ function findLinkElementAncestor( position ) {
142
+ return position.getAncestors().find( ancestor => isLinkElement( ancestor ) );
143
+ }