qms-angular 1.0.72 → 1.0.73
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/bundles/qms-angular.umd.js +509 -116
- package/bundles/qms-angular.umd.js.map +1 -1
- package/esm2015/lib/components/qms-navigation-drawer/qms-navigation-drawer.component.js +2 -2
- package/esm2015/lib/components/qms-navigation-drawer/qms-navigation-drawer.module.js +1 -3
- package/esm2015/lib/components/select-include-children/select-include-children.component.js +112 -45
- package/esm2015/lib/components/tree/tree.component.js +10 -14
- package/esm2015/lib/model/en.js +19 -2
- package/esm2015/lib/model/no.js +19 -2
- package/esm2015/lib/qms-ckeditor-components/common/classes/qmsUploadAdapter.js +89 -0
- package/esm2015/lib/qms-ckeditor-components/common/constants/ckeditorEvent.constant.js +3 -1
- package/esm2015/lib/qms-ckeditor-components/common/models/qms-ckeditor-data.model.js +1 -1
- package/esm2015/lib/qms-ckeditor-components/common/models/qms-ckeditor-video-tree.model.js +4 -0
- package/esm2015/lib/qms-ckeditor-components/common/models/wproofreader-config.model.js +6 -0
- package/esm2015/lib/qms-ckeditor-components/components/qms-ckeditor-about/qms-ckeditor-about.component.js +38 -0
- package/esm2015/lib/qms-ckeditor-components/components/qms-ckeditor-bpmn/qms-ckeditor-bpmn.component.js +22 -3
- package/esm2015/lib/qms-ckeditor-components/components/qms-ckeditor-imagemap/qms-ckeditor-imagemap.component.js +9 -8
- package/esm2015/lib/qms-ckeditor-components/components/qms-ckeditor-link/qms-ckeditor-link.component.js +4 -1
- package/esm2015/lib/qms-ckeditor-components/components/qms-ckeditor-tooltip/qms-ckeditor-tooltip.component.js +3 -4
- package/esm2015/lib/qms-ckeditor-components/qms-ckeditor.component.js +160 -10
- package/esm2015/lib/qms-ckeditor-components/qms-ckeditor.module.js +7 -3
- package/esm2015/lib/qms-ckeditor-components/services/qms-ckeditor-tree.service.js +4 -1
- package/esm2015/lib/qms-ckeditor-components/services/qms-ckeditor-upload.service.js +20 -0
- package/esm2015/qms-angular.js +6 -4
- package/fesm2015/qms-angular.js +475 -95
- package/fesm2015/qms-angular.js.map +1 -1
- package/lib/components/select-include-children/select-include-children.component.d.ts +2 -1
- package/lib/model/en.d.ts +17 -0
- package/lib/model/no.d.ts +17 -0
- package/lib/qms-ckeditor-components/common/classes/qmsUploadAdapter.d.ts +18 -0
- package/lib/qms-ckeditor-components/common/constants/ckeditorEvent.constant.d.ts +2 -0
- package/lib/qms-ckeditor-components/common/models/qms-ckeditor-data.model.d.ts +4 -0
- package/lib/qms-ckeditor-components/common/models/qms-ckeditor-video-tree.model.d.ts +5 -0
- package/lib/qms-ckeditor-components/common/models/wproofreader-config.model.d.ts +25 -0
- package/lib/qms-ckeditor-components/components/qms-ckeditor-about/qms-ckeditor-about.component.d.ts +15 -0
- package/lib/qms-ckeditor-components/components/qms-ckeditor-bpmn/qms-ckeditor-bpmn.component.d.ts +4 -1
- package/lib/qms-ckeditor-components/components/qms-ckeditor-imagemap/qms-ckeditor-imagemap.component.d.ts +2 -1
- package/lib/qms-ckeditor-components/qms-ckeditor.component.d.ts +15 -1
- package/lib/qms-ckeditor-components/services/qms-ckeditor-tree.service.d.ts +2 -0
- package/lib/qms-ckeditor-components/services/qms-ckeditor-upload.service.d.ts +5 -0
- package/lib.theme.scss +1 -0
- package/package.json +1 -1
- package/qms-angular.d.ts +5 -3
- package/qms-angular.metadata.json +1 -1
- package/src/assets/images/ckeditor5.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/build/ckeditor.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/ckeditor.js.map +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/az.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/cs.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/da.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/de-ch.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/de.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/en-au.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/es.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/et.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/fa.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/fr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/gl.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/he.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/hi.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/hr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/hu.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/id.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/it.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ja.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ko.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ku.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/lv.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/nl.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/no.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/pl.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/pt-br.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/ru.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sk.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sl.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sr-latn.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/sr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/th.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/tk.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/tr.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/uk.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/vi.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/zh-cn.js +1 -1
- package/src/assets/qms-ckeditor-plugin/build/translations/zh.js +1 -1
- package/src/assets/qms-ckeditor-plugin/package-lock.json +23 -0
- package/src/assets/qms-ckeditor-plugin/package.json +2 -0
- package/src/assets/qms-ckeditor-plugin/src/ckeditor.js +16 -4
- package/src/assets/qms-ckeditor-plugin/src/plugins/aboutckeditor/aboutckeditor.js +28 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/bpmn/bpmndialogcommand.js +74 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/bpmn/qmsCKEditorBpmnPlugin.js +5 -68
- package/src/assets/qms-ckeditor-plugin/src/plugins/common/qmsCKEditorConstant.js +4 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/common/qmsCKEditorService.js +21 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/imagemap/imagemapcommand.js +1 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/imagemap/utils.js +1 -1
- package/src/assets/qms-ckeditor-plugin/src/plugins/link/linkcommand.js +131 -176
- package/src/assets/qms-ckeditor-plugin/src/plugins/link/linkdialogcommand.js +88 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/link/linkediting.js +2 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/link/linkui.js +41 -32
- package/src/assets/qms-ckeditor-plugin/src/plugins/tableofcontents/tableofcontents.js +14 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/tableofcontents/tableofcontentscommand.js +87 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/tableofcontents/tableofcontentsediting.js +59 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/tableofcontents/tableofcontentsui.js +35 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/tableofcontents/utils.js +62 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/template/loadtemplatedialogcommand.js +14 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/template/qmsCKEditorLoadTemplatePlugin.js +10 -12
- package/src/assets/qms-ckeditor-plugin/src/plugins/template/qmsCKEdtiorTemplatePlugin.js +10 -7
- package/src/assets/qms-ckeditor-plugin/src/plugins/template/templatedialogcommand.js +9 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/timestamp/timestamp.js +15 -18
- package/src/assets/qms-ckeditor-plugin/src/plugins/timestamp/timestampcommand.js +17 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/removetooltipcommand.js +42 -26
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/tooltip.js +3 -3
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/tooltipcommand.js +75 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/tooltipdialogcommand.js +68 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/tooltipediting.js +206 -131
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/tooltipui.js +424 -136
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/ui/actionsview.js +67 -12
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/utils.js +17 -55
- package/src/assets/qms-ckeditor-plugin/src/plugins/video/autovideo.js +1 -5
- package/src/assets/qms-ckeditor-plugin/src/plugins/video/video/videoediting.js +5 -2
- package/src/assets/qms-ckeditor-plugin/src/plugins/video/videoupload/browsevideodialogcommand.js +25 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/video/videoupload/uploadvideocommand.js +3 -16
- package/src/assets/qms-ckeditor-plugin/src/plugins/video/videoupload/videouploadediting.js +4 -0
- package/src/assets/qms-ckeditor-plugin/src/plugins/video/videoupload/videouploadui.js +12 -23
- package/src/assets/qms-ckeditor-plugin/src/themes/icons/information.svg +1 -50
- package/src/assets/qms-ckeditor-plugin/src/themes/icons/table-excel.svg +44 -0
- package/src/assets/qms-ckeditor-plugin/src/themes/icons/timestamp.svg +1 -1
- package/src/assets/qms-ckeditor-plugin/src/themes/icons/tooltip.svg +1 -0
- package/src/assets/qms-ckeditor-plugin/src/themes/styles/heading.css +54 -0
- package/src/assets/qms-ckeditor-plugin/src/themes/styles/tooltip.css +11 -53
- package/src/lib/qms-ckeditor-components/components/qms-ckeditor-about/qms-ckeditor-about.component.scss +16 -0
- package/src/lib/qms-ckeditor-components/components/qms-ckeditor-imagemap/qms-ckeditor-imagemap.component.scss +26 -23
- package/src/themes/core/_range-slider.scss +10 -12
- package/esm2015/lib/qms-ckeditor-components/common/classes/uploadAdapter.js +0 -26
- package/lib/qms-ckeditor-components/common/classes/uploadAdapter.d.ts +0 -5
- package/src/assets/qms-ckeditor-plugin/src/plugins/tooltip/inserttooltipcommand.js +0 -88
@@ -0,0 +1,75 @@
|
|
1
|
+
import { Command } from '@ckeditor/ckeditor5-core';
|
2
|
+
import { findAttributeRange } from '@ckeditor/ckeditor5-typing';
|
3
|
+
import { toMap, first } from '@ckeditor/ckeditor5-utils';
|
4
|
+
import { isImageAllowed, TOOLTIP_ATTRIBUTE } from './utils';
|
5
|
+
|
6
|
+
export default class TooltipCommand extends Command {
|
7
|
+
|
8
|
+
refresh() {
|
9
|
+
const model = this.editor.model;
|
10
|
+
const doc = model.document;
|
11
|
+
const selectedElement = first(doc.selection.getSelectedBlocks());
|
12
|
+
|
13
|
+
// A check for the `LinkImage` plugin. If the selection contains an element, get values from the element.
|
14
|
+
// Currently the selection reads attributes from text nodes only. See #7429 and #7465.
|
15
|
+
if (isImageAllowed(selectedElement, model.schema)) {
|
16
|
+
this.isEnabled = model.schema.checkAttribute(selectedElement, TOOLTIP_ATTRIBUTE);
|
17
|
+
} else {
|
18
|
+
this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, TOOLTIP_ATTRIBUTE);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
execute(options) {
|
23
|
+
const model = this.editor.model;
|
24
|
+
const selection = model.document.selection;
|
25
|
+
model.change(writer => {
|
26
|
+
// If selection is collapsed then update selected link or insert new one at the place of caret.
|
27
|
+
if (selection.isCollapsed) {
|
28
|
+
const position = selection.getFirstPosition();
|
29
|
+
|
30
|
+
// When selection is inside text with `qmsTooltip` attribute.
|
31
|
+
if (selection.hasAttribute(TOOLTIP_ATTRIBUTE)) {
|
32
|
+
// Then update `qmsTooltip` value.
|
33
|
+
const linkRange = findAttributeRange(position, TOOLTIP_ATTRIBUTE, selection.getAttribute(TOOLTIP_ATTRIBUTE), model);
|
34
|
+
|
35
|
+
const attributes = toMap(selection.getAttributes());
|
36
|
+
|
37
|
+
attributes.set(TOOLTIP_ATTRIBUTE, options.content);
|
38
|
+
|
39
|
+
const { end: positionAfter } = model.insertContent(writer.createText(options.text, attributes), linkRange);
|
40
|
+
|
41
|
+
// Put the selection at the end of the inserted link.
|
42
|
+
// Using end of range returned from insertContent in case nodes with the same attributes got merged.
|
43
|
+
writer.setSelection(positionAfter);
|
44
|
+
}
|
45
|
+
else if (options.text !== '') {
|
46
|
+
const attributes = toMap(selection.getAttributes());
|
47
|
+
|
48
|
+
attributes.set(TOOLTIP_ATTRIBUTE, options.content);
|
49
|
+
|
50
|
+
const { end: positionAfter } = model.insertContent(writer.createText(options.text, attributes), position);
|
51
|
+
|
52
|
+
// Put the selection at the end of the inserted link.
|
53
|
+
// Using end of range returned from insertContent in case nodes with the same attributes got merged.
|
54
|
+
writer.setSelection(positionAfter);
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
const attributes = toMap(selection.getAttributes());
|
58
|
+
|
59
|
+
attributes.set(TOOLTIP_ATTRIBUTE, options.content);
|
60
|
+
|
61
|
+
const { end: positionAfter } = model.insertContent(writer.createText(options.text, attributes), selection);
|
62
|
+
|
63
|
+
writer.setSelection(positionAfter);
|
64
|
+
}
|
65
|
+
// Remove the `qmsTooltip` attribute and all link decorators from the selection.
|
66
|
+
// It stops adding a new content into the link element.
|
67
|
+
[TOOLTIP_ATTRIBUTE].forEach(item => {
|
68
|
+
writer.removeSelectionAttribute(item);
|
69
|
+
});
|
70
|
+
console.log('this.editor.getData()' + new Date().toISOString());
|
71
|
+
console.log(this.editor.getData());
|
72
|
+
});
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import { Command } from '@ckeditor/ckeditor5-core';
|
2
|
+
import { findAttributeRange } from '@ckeditor/ckeditor5-typing';
|
3
|
+
import { first } from '@ckeditor/ckeditor5-utils';
|
4
|
+
import * as QMSCKEditorConstant from '../common/qmsCKEditorConstant';
|
5
|
+
import * as QMSCKEditorService from '../common/qmsCKEditorService';
|
6
|
+
import { isImageAllowed, TOOLTIP_COMMANDS, TOOLTIP_ATTRIBUTE } from './utils';
|
7
|
+
|
8
|
+
export default class TooltipDialogCommand extends Command {
|
9
|
+
|
10
|
+
refresh() {
|
11
|
+
const model = this.editor.model;
|
12
|
+
const doc = model.document;
|
13
|
+
const selectedElement = first(doc.selection.getSelectedBlocks());
|
14
|
+
// A check for the `LinkImage` plugin. If the selection contains an element, get values from the element.
|
15
|
+
// Currently the selection reads attributes from text nodes only. See #7429 and #7465.
|
16
|
+
if (isImageAllowed(selectedElement, model.schema)) {
|
17
|
+
this.value = selectedElement.getAttribute(TOOLTIP_ATTRIBUTE);
|
18
|
+
this.isEnabled = model.schema.checkAttribute(selectedElement, TOOLTIP_ATTRIBUTE);
|
19
|
+
} else {
|
20
|
+
this.value = doc.selection.getAttribute(TOOLTIP_ATTRIBUTE);
|
21
|
+
this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, TOOLTIP_ATTRIBUTE);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
execute() {
|
26
|
+
const editor = this.editor;
|
27
|
+
const model = editor.model;
|
28
|
+
const selection = model.document.selection;
|
29
|
+
const tooltip = { text: '', content: '' };
|
30
|
+
if(selection.isCollapsed){
|
31
|
+
if(selection.hasAttribute(TOOLTIP_ATTRIBUTE)){
|
32
|
+
const linkRange = findAttributeRange(selection.getFirstPosition(), TOOLTIP_ATTRIBUTE, selection.getAttribute(TOOLTIP_ATTRIBUTE), model);
|
33
|
+
for (const node of linkRange.getItems()) {
|
34
|
+
if ((node.is('text') || node.is('textProxy')) && node.hasAttribute(TOOLTIP_ATTRIBUTE)) {
|
35
|
+
tooltip.text = node.data;
|
36
|
+
tooltip.content = node.getAttribute(TOOLTIP_ATTRIBUTE);
|
37
|
+
break;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
else
|
43
|
+
{
|
44
|
+
const ranges = selection.getFirstRange();
|
45
|
+
if(ranges)
|
46
|
+
{
|
47
|
+
for (const item of ranges.getItems()) {
|
48
|
+
if (item.data) {
|
49
|
+
tooltip.text = tooltip.text + item.data;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
QMSCKEditorService.tooltipNotify(tooltip);
|
56
|
+
window[QMSCKEditorConstant.QMSCK_TOOLTIP_IS_PROCESSING] = false;
|
57
|
+
|
58
|
+
window.addEventListener(QMSCKEditorConstant.QMSCK_TOOLTIP_PLUGIN_RESP, function (evt) {
|
59
|
+
if (window[QMSCKEditorConstant.QMSCK_TOOLTIP_IS_PROCESSING]) {
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
const options = evt.detail;
|
63
|
+
editor.commands.get(TOOLTIP_COMMANDS.TOOLTIP).execute(options);
|
64
|
+
window[QMSCKEditorConstant.QMSCK_TOOLTIP_IS_PROCESSING] = true;
|
65
|
+
}, { once: true });
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
@@ -1,76 +1,80 @@
|
|
1
|
-
|
2
|
-
import '
|
3
|
-
import {
|
4
|
-
TOOLTIP_CUSTOM_PROPERTY, TOOLTIP_ATTRIBUTE, HTML_ATTRIBUTE,
|
5
|
-
INSERT_TOOLTIP_COMMAND, REMOVE_TOOLTIP_COMMAND, HTML_CLASS, isTyping, shouldCopyAttributes
|
6
|
-
} from './utils';
|
7
|
-
import InsertTooltipCommand from './inserttooltipcommand';
|
8
|
-
import RemoveTooltipCommand from './removetooltipcommand';
|
9
|
-
import {MouseObserver} from '@ckeditor/ckeditor5-engine';
|
1
|
+
|
2
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
3
|
+
import { MouseObserver } from '@ckeditor/ckeditor5-engine';
|
10
4
|
import { keyCodes } from '@ckeditor/ckeditor5-utils';
|
11
5
|
import { Input, TwoStepCaretMovement, findAttributeRange } from '@ckeditor/ckeditor5-typing';
|
12
6
|
import { ClipboardPipeline } from '@ckeditor/ckeditor5-clipboard';
|
13
|
-
|
7
|
+
import TooltipCommand from './tooltipcommand';
|
8
|
+
import RemoveTooltipCommand from './removetooltipcommand';
|
9
|
+
import TooltipDialogCommand from './tooltipdialogcommand';
|
10
|
+
import { TOOLTIP_COMMANDS, HTML_ATTRIBUTE, HTML_CLASS, HTML_ELEMENT, TOOLTIP_ATTRIBUTE, TOOLTIP_CUSTOM_PROPERTY } from './utils';
|
11
|
+
import '../../themes/styles/tooltip.css';
|
12
|
+
|
14
13
|
export default class TooltipEditing extends Plugin {
|
15
14
|
|
16
15
|
static get pluginName() {
|
17
16
|
return 'TooltipEditing';
|
18
|
-
}
|
19
|
-
|
17
|
+
}
|
18
|
+
|
20
19
|
static get requires() {
|
21
|
-
// Clipboard is required for handling cut and paste events while typing over the
|
20
|
+
// Clipboard is required for handling cut and paste events while typing over the link.
|
22
21
|
return [ TwoStepCaretMovement, Input, ClipboardPipeline ];
|
23
22
|
}
|
23
|
+
|
24
|
+
init() {
|
25
|
+
const editor = this.editor;
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
// Allow link attribute on all inline nodes.
|
28
|
+
editor.model.schema.extend('$text', { allowAttributes: TOOLTIP_ATTRIBUTE });
|
29
|
+
|
30
|
+
editor.conversion.for('downcast')
|
31
|
+
.attributeToElement({
|
32
|
+
model: TOOLTIP_ATTRIBUTE,
|
33
|
+
view: (modelAttributeValue, { writer }) =>{
|
34
|
+
const attributes = { class: HTML_CLASS };
|
35
|
+
attributes[HTML_ATTRIBUTE] = modelAttributeValue;
|
36
|
+
const tooltipElement = writer.createAttributeElement(HTML_ELEMENT, attributes, { priority: 5 });
|
37
|
+
writer.setCustomProperty(TOOLTIP_CUSTOM_PROPERTY, true, tooltipElement);
|
38
|
+
return tooltipElement;
|
39
|
+
}
|
40
|
+
});
|
27
41
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
editor.conversion.for('upcast')
|
43
|
+
.elementToAttribute({
|
44
|
+
view: {
|
45
|
+
name: HTML_ELEMENT,
|
46
|
+
attributes: {
|
47
|
+
[HTML_ATTRIBUTE]: true
|
48
|
+
}
|
49
|
+
},
|
50
|
+
model: {
|
51
|
+
key: TOOLTIP_ATTRIBUTE,
|
52
|
+
value: viewElement => viewElement.getAttribute(HTML_ATTRIBUTE)
|
53
|
+
}
|
54
|
+
});
|
55
|
+
|
56
|
+
// Create linking commands.
|
57
|
+
editor.commands.add(TOOLTIP_COMMANDS.TOOLTIP, new TooltipCommand(editor));
|
58
|
+
editor.commands.add(TOOLTIP_COMMANDS.REMOVE_TOOLTIP, new RemoveTooltipCommand(editor));
|
59
|
+
editor.commands.add(TOOLTIP_COMMANDS.TOOLTIP_DIALOG, new TooltipDialogCommand(editor));
|
41
60
|
|
42
|
-
|
43
|
-
model: TOOLTIP_ATTRIBUTE,
|
44
|
-
view: (modelAttributeValue, { writer: viewWriter }) =>{
|
45
|
-
const attributes = { class: HTML_CLASS};
|
46
|
-
attributes[HTML_ATTRIBUTE] = modelAttributeValue;
|
47
|
-
|
48
|
-
const tooltipElement = viewWriter.createAttributeElement('span', attributes, { priority: 5 });
|
49
|
-
viewWriter.setCustomProperty(TOOLTIP_CUSTOM_PROPERTY, true, tooltipElement);
|
50
|
-
return tooltipElement;
|
51
|
-
}
|
52
|
-
});
|
53
|
-
|
54
|
-
editor.commands.add(INSERT_TOOLTIP_COMMAND, new InsertTooltipCommand(editor));
|
55
|
-
editor.commands.add(REMOVE_TOOLTIP_COMMAND, new RemoveTooltipCommand(editor));
|
56
|
-
|
57
|
-
// Enable two-step caret movement for `data-tooltip` attribute.
|
61
|
+
// Enable two-step caret movement for `TOOLTIP_ATTRIBUTE` attribute.
|
58
62
|
const twoStepCaretMovementPlugin = editor.plugins.get(TwoStepCaretMovement);
|
59
63
|
twoStepCaretMovementPlugin.registerAttribute(TOOLTIP_ATTRIBUTE);
|
60
|
-
|
64
|
+
|
61
65
|
// Change the attributes of the selection in certain situations after the link was inserted into the document.
|
62
66
|
this._enableInsertContentSelectionAttributesFixer();
|
63
67
|
|
64
|
-
|
65
|
-
this.
|
66
|
-
|
67
|
-
// Handle typing over the tooltip element.
|
68
|
-
this._enableTypingOverTooltip();
|
68
|
+
// Handle a click at the beginning/end of a link element.
|
69
|
+
this._enableClickingAfterLink();
|
69
70
|
|
70
|
-
// Handle
|
71
|
-
this.
|
72
|
-
}
|
71
|
+
// Handle typing over the link.
|
72
|
+
this._enableTypingOverLink();
|
73
73
|
|
74
|
+
// Handle removing the content after the link element.
|
75
|
+
this._handleDeleteContentAfterLink();
|
76
|
+
}
|
77
|
+
|
74
78
|
_enableInsertContentSelectionAttributesFixer() {
|
75
79
|
const editor = this.editor;
|
76
80
|
const model = editor.model;
|
@@ -95,33 +99,88 @@ export default class TooltipEditing extends Plugin {
|
|
95
99
|
if (nodeAfter && nodeAfter.hasAttribute(TOOLTIP_ATTRIBUTE)) {
|
96
100
|
return;
|
97
101
|
}
|
98
|
-
|
102
|
+
|
99
103
|
model.change(writer => {
|
100
|
-
writer
|
104
|
+
removeLinkAttributesFromSelection(writer);
|
101
105
|
});
|
102
106
|
}, { priority: 'low' });
|
103
107
|
}
|
108
|
+
|
109
|
+
_enableClickingAfterLink() {
|
110
|
+
const editor = this.editor;
|
111
|
+
|
112
|
+
editor.editing.view.addObserver(MouseObserver);
|
113
|
+
|
114
|
+
let clicked = false;
|
115
|
+
|
116
|
+
// Detect the click.
|
117
|
+
this.listenTo(editor.editing.view.document, 'mousedown', () => {
|
118
|
+
clicked = true;
|
119
|
+
});
|
120
|
+
|
121
|
+
// When the selection has changed...
|
122
|
+
this.listenTo(editor.editing.view.document, 'selectionChange', () => {
|
123
|
+
if (!clicked) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
|
127
|
+
// ...and it was caused by the click...
|
128
|
+
clicked = false;
|
129
|
+
|
130
|
+
const selection = editor.model.document.selection;
|
131
|
+
|
132
|
+
// ...and no text is selected...
|
133
|
+
if (!selection.isCollapsed) {
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
|
137
|
+
// ...and clicked text is the link...
|
138
|
+
if (!selection.hasAttribute(TOOLTIP_ATTRIBUTE)) {
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
|
142
|
+
const position = selection.getFirstPosition();
|
143
|
+
const tooltipRange = findAttributeRange(position, TOOLTIP_ATTRIBUTE, selection.getAttribute(TOOLTIP_ATTRIBUTE), editor.model);
|
144
|
+
|
145
|
+
// ...check whether clicked start/end boundary of the link.
|
146
|
+
// If so, remove the `TOOLTIP_ATTRIBUTE` attribute.
|
147
|
+
if (position.isTouching(tooltipRange.start) || position.isTouching(tooltipRange.end)) {
|
148
|
+
editor.model.change(writer => {
|
149
|
+
removeLinkAttributesFromSelection(writer);
|
150
|
+
});
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}
|
104
154
|
|
105
|
-
|
155
|
+
/**
|
156
|
+
* Starts listening to {@link module:engine/model/model~Model#deleteContent} and {@link module:engine/model/model~Model#insertContent}
|
157
|
+
* and checks whether typing over the link. If so, attributes of removed text are preserved and applied to the inserted text.
|
158
|
+
*
|
159
|
+
* The purpose of this action is to allow modifying a text without loosing the `TOOLTIP_ATTRIBUTE` attribute (and other).
|
160
|
+
*
|
161
|
+
* See https://github.com/ckeditor/ckeditor5/issues/4762.
|
162
|
+
*
|
163
|
+
* @private
|
164
|
+
*/
|
165
|
+
_enableTypingOverLink() {
|
106
166
|
const editor = this.editor;
|
107
167
|
const view = editor.editing.view;
|
108
168
|
|
109
|
-
// Selection attributes when started typing over the
|
169
|
+
// Selection attributes when started typing over the link.
|
110
170
|
let selectionAttributes;
|
111
171
|
|
112
172
|
// Whether pressed `Backspace` or `Delete`. If so, attributes should not be preserved.
|
113
173
|
let deletedContent;
|
114
174
|
|
115
175
|
// Detect pressing `Backspace` / `Delete`.
|
116
|
-
|
117
176
|
this.listenTo(view.document, 'delete', () => {
|
118
177
|
deletedContent = true;
|
119
178
|
}, { priority: 'high' });
|
120
179
|
|
121
|
-
// Listening to `model#deleteContent` allows detecting whether selected content was
|
180
|
+
// Listening to `model#deleteContent` allows detecting whether selected content was a link.
|
122
181
|
// If so, before removing the element, we will copy its attributes.
|
123
182
|
this.listenTo(editor.model, 'deleteContent', () => {
|
124
|
-
const selection = editor.model.document.selection;
|
183
|
+
const selection = editor.model.document.selection;
|
125
184
|
|
126
185
|
// Copy attributes only if anything is selected.
|
127
186
|
if (selection.isCollapsed) {
|
@@ -145,10 +204,10 @@ export default class TooltipEditing extends Plugin {
|
|
145
204
|
}, { priority: 'high' });
|
146
205
|
|
147
206
|
// Listening to `model#insertContent` allows detecting the content insertion.
|
148
|
-
// We want to apply attributes that were removed while typing over the
|
207
|
+
// We want to apply attributes that were removed while typing over the link.
|
149
208
|
this.listenTo(editor.model, 'insertContent', (evt, [ element ]) => {
|
150
209
|
deletedContent = false;
|
151
|
-
|
210
|
+
|
152
211
|
// Enabled only when typing.
|
153
212
|
if (!isTyping(editor)) {
|
154
213
|
return;
|
@@ -157,7 +216,7 @@ export default class TooltipEditing extends Plugin {
|
|
157
216
|
if (!selectionAttributes) {
|
158
217
|
return;
|
159
218
|
}
|
160
|
-
|
219
|
+
|
161
220
|
editor.model.change(writer => {
|
162
221
|
for (const [ attribute, value ] of selectionAttributes) {
|
163
222
|
writer.setAttribute(attribute, value, element);
|
@@ -168,60 +227,27 @@ export default class TooltipEditing extends Plugin {
|
|
168
227
|
}, { priority: 'high' });
|
169
228
|
}
|
170
229
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
return;
|
187
|
-
}
|
188
|
-
|
189
|
-
// ...and it was caused by the click...
|
190
|
-
clicked = false;
|
191
|
-
|
192
|
-
// ...and no text is selected...
|
193
|
-
if (!selection.isCollapsed) {
|
194
|
-
return;
|
195
|
-
}
|
196
|
-
|
197
|
-
//console.log('_enableClickingAtBeginingOrEndTooltip==>selectionChange==>selection.hasAttribute(TOOLTIP_ATTRIBUTE): ' + selection.hasAttribute(TOOLTIP_ATTRIBUTE));
|
198
|
-
// ...and clicked text is the tooltip...
|
199
|
-
if (!selection.hasAttribute(TOOLTIP_ATTRIBUTE)) {
|
200
|
-
return;
|
201
|
-
}
|
202
|
-
|
203
|
-
const position = selection.getFirstPosition();
|
204
|
-
const selectedRange = findAttributeRange(position, TOOLTIP_ATTRIBUTE, selection.getAttribute(TOOLTIP_ATTRIBUTE), editor.model);
|
205
|
-
|
206
|
-
// ...check whether clicked start/end boundary of the tooltip.
|
207
|
-
// If so, remove the `tooltip` attribute.
|
208
|
-
const isTouching = position.isTouching(selectedRange.start) || position.isTouching(selectedRange.end);
|
209
|
-
//console.log('_enableClickingAtBeginingOrEndTooltip==>selectionChange==>isTouching: ' + isTouching);
|
210
|
-
if (isTouching) {
|
211
|
-
editor.model.change(writer => {
|
212
|
-
writer.removeSelectionAttribute(TOOLTIP_ATTRIBUTE);
|
213
|
-
});
|
214
|
-
}
|
215
|
-
});
|
216
|
-
}
|
217
|
-
|
218
|
-
_handleDeleteContent() {
|
230
|
+
/**
|
231
|
+
* Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether
|
232
|
+
* removing a content right after the "qmsTooltip" attribute.
|
233
|
+
*
|
234
|
+
* If so, the selection should not preserve the `TOOLTIP_ATTRIBUTE` attribute. However, if
|
235
|
+
* the {@link module:typing/twostepcaretmovement~TwoStepCaretMovement} plugin is active and
|
236
|
+
* the selection has the "qmsTooltip" attribute due to overriden gravity (at the end), the `TOOLTIP_ATTRIBUTE` attribute should stay untouched.
|
237
|
+
*
|
238
|
+
* The purpose of this action is to allow removing the link text and keep the selection outside the link.
|
239
|
+
*
|
240
|
+
* See https://github.com/ckeditor/ckeditor5/issues/7521.
|
241
|
+
*
|
242
|
+
* @private
|
243
|
+
*/
|
244
|
+
_handleDeleteContentAfterLink() {
|
219
245
|
const editor = this.editor;
|
220
246
|
const model = editor.model;
|
221
247
|
const selection = model.document.selection;
|
222
248
|
const view = editor.editing.view;
|
223
|
-
|
224
|
-
// A flag whether attributes `
|
249
|
+
|
250
|
+
// A flag whether attributes `TOOLTIP_ATTRIBUTE` attribute should be preserved.
|
225
251
|
let shouldPreserveAttributes = false;
|
226
252
|
|
227
253
|
// A flag whether the `Backspace` key was pressed.
|
@@ -232,48 +258,97 @@ export default class TooltipEditing extends Plugin {
|
|
232
258
|
hasBackspacePressed = data.domEvent.keyCode === keyCodes.backspace;
|
233
259
|
}, { priority: 'high' });
|
234
260
|
|
235
|
-
// Before removing the content, check whether the selection is inside a
|
236
|
-
// If so, we want to preserve
|
261
|
+
// Before removing the content, check whether the selection is inside a link or at the end of link but with 2-SCM enabled.
|
262
|
+
// If so, we want to preserve link attributes.
|
237
263
|
this.listenTo(model, 'deleteContent', () => {
|
238
264
|
// Reset the state.
|
239
265
|
shouldPreserveAttributes = false;
|
240
266
|
|
241
267
|
const position = selection.getFirstPosition();
|
242
|
-
const
|
268
|
+
const qmsTooltip = selection.getAttribute(TOOLTIP_ATTRIBUTE);
|
243
269
|
|
244
|
-
if (!
|
270
|
+
if (!qmsTooltip) {
|
245
271
|
return;
|
246
272
|
}
|
247
273
|
|
248
|
-
const
|
274
|
+
const tooltipRange = findAttributeRange(position, TOOLTIP_ATTRIBUTE, qmsTooltip, model);
|
249
275
|
|
250
|
-
// Preserve `
|
251
|
-
// the selection is at the end of the
|
252
|
-
shouldPreserveAttributes =
|
276
|
+
// Preserve `TOOLTIP_ATTRIBUTE` attribute if the selection is in the middle of the link or
|
277
|
+
// the selection is at the end of the link and 2-SCM is activated.
|
278
|
+
shouldPreserveAttributes = tooltipRange.containsPosition(position) || tooltipRange.end.isEqual(position);
|
253
279
|
}, { priority: 'high' });
|
254
280
|
|
255
|
-
// After removing the content, check whether the current selection should preserve the `
|
281
|
+
// After removing the content, check whether the current selection should preserve the `TOOLTIP_ATTRIBUTE` attribute.
|
256
282
|
this.listenTo(model, 'deleteContent', () => {
|
257
283
|
// If didn't press `Backspace`.
|
258
284
|
if (!hasBackspacePressed) {
|
259
285
|
return;
|
260
286
|
}
|
261
|
-
|
262
|
-
//console.log('_handleDeleteContent==>deleteContent==>shouldPreserveAttributes: ' + shouldPreserveAttributes);
|
263
287
|
|
264
288
|
hasBackspacePressed = false;
|
265
289
|
|
266
|
-
// Disable the mechanism if inside a
|
290
|
+
// Disable the mechanism if inside a link (`<$text url="foo">F[]oo</$text>` or <$text url="foo">Foo[]</$text>`).
|
267
291
|
if (shouldPreserveAttributes) {
|
268
292
|
return;
|
269
293
|
}
|
270
|
-
|
271
|
-
// Use `model.enqueueChange()` in order to execute the callback at the end of the changes process.
|
272
|
-
editor.model.enqueueChange(writer => {
|
273
|
-
writer.removeSelectionAttribute(TOOLTIP_ATTRIBUTE);
|
274
|
-
});
|
294
|
+
|
275
295
|
}, { priority: 'low' });
|
276
296
|
}
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
function removeLinkAttributesFromSelection(writer) {
|
301
|
+
writer.removeSelectionAttribute(TOOLTIP_ATTRIBUTE);
|
302
|
+
}
|
303
|
+
|
304
|
+
// Checks whether selection's attributes should be copied to the new inserted text.
|
305
|
+
//
|
306
|
+
// @param {module:engine/model/model~Model} model
|
307
|
+
// @returns {Boolean}
|
308
|
+
function shouldCopyAttributes(model) {
|
309
|
+
const selection = model.document.selection;
|
310
|
+
const firstPosition = selection.getFirstPosition();
|
311
|
+
const lastPosition = selection.getLastPosition();
|
312
|
+
const nodeAtFirstPosition = firstPosition.nodeAfter;
|
313
|
+
|
314
|
+
// The text link node does not exist...
|
315
|
+
if (!nodeAtFirstPosition) {
|
316
|
+
return false;
|
317
|
+
}
|
318
|
+
|
319
|
+
// ...or it isn't the text node...
|
320
|
+
if (!nodeAtFirstPosition.is('$text')) {
|
321
|
+
return false;
|
322
|
+
}
|
323
|
+
|
324
|
+
// ...or isn't the link.
|
325
|
+
if (!nodeAtFirstPosition.hasAttribute(TOOLTIP_ATTRIBUTE)) {
|
326
|
+
return false;
|
327
|
+
}
|
328
|
+
|
329
|
+
// `textNode` = the position is inside the link element.
|
330
|
+
// `nodeBefore` = the position is at the end of the link element.
|
331
|
+
const nodeAtLastPosition = lastPosition.textNode || lastPosition.nodeBefore;
|
332
|
+
|
333
|
+
// If both references the same node selection contains a single text node.
|
334
|
+
if (nodeAtFirstPosition === nodeAtLastPosition) {
|
335
|
+
return true;
|
336
|
+
}
|
337
|
+
|
338
|
+
// If nodes are not equal, maybe the link nodes has defined additional attributes inside.
|
339
|
+
// First, we need to find the entire link range.
|
340
|
+
const tooltipRange = findAttributeRange(firstPosition, TOOLTIP_ATTRIBUTE, nodeAtFirstPosition.getAttribute(TOOLTIP_ATTRIBUTE), model);
|
341
|
+
|
342
|
+
// Then we can check whether selected range is inside the found link range. If so, attributes should be preserved.
|
343
|
+
return tooltipRange.containsRange(model.createRange(firstPosition, lastPosition), true);
|
344
|
+
}
|
345
|
+
|
346
|
+
// Checks whether provided changes were caused by typing.
|
347
|
+
//
|
348
|
+
// @params {module:core/editor/editor~Editor} editor
|
349
|
+
// @returns {Boolean}
|
350
|
+
function isTyping(editor) {
|
351
|
+
const input = editor.plugins.get('Input');
|
277
352
|
|
353
|
+
return input.isInput(editor.model.change(writer => writer.batch));
|
278
354
|
}
|
279
|
-
|