@ckeditor/ckeditor5-link 38.1.1 → 38.2.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.
@@ -1,101 +1,101 @@
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 link/ui/linkactionsview
7
- */
8
- import { ButtonView, View } from 'ckeditor5/src/ui';
9
- import { FocusTracker, KeystrokeHandler, type LocaleTranslate, type Locale } from 'ckeditor5/src/utils';
10
- import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
11
- import '../../theme/linkactions.css';
12
- /**
13
- * The link actions view class. This view displays the link preview, allows
14
- * unlinking or editing the link.
15
- */
16
- export default class LinkActionsView extends View {
17
- /**
18
- * Tracks information about DOM focus in the actions.
19
- */
20
- readonly focusTracker: FocusTracker;
21
- /**
22
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
23
- */
24
- readonly keystrokes: KeystrokeHandler;
25
- /**
26
- * The href preview view.
27
- */
28
- previewButtonView: View;
29
- /**
30
- * The unlink button view.
31
- */
32
- unlinkButtonView: ButtonView;
33
- /**
34
- * The edit link button view.
35
- */
36
- editButtonView: ButtonView;
37
- /**
38
- * The value of the "href" attribute of the link to use in the {@link #previewButtonView}.
39
- *
40
- * @observable
41
- */
42
- href: string | undefined;
43
- /**
44
- * A collection of views that can be focused in the view.
45
- */
46
- private readonly _focusables;
47
- /**
48
- * Helps cycling over {@link #_focusables} in the view.
49
- */
50
- private readonly _focusCycler;
51
- t: LocaleTranslate;
52
- /**
53
- * @inheritDoc
54
- */
55
- constructor(locale: Locale);
56
- /**
57
- * @inheritDoc
58
- */
59
- render(): void;
60
- /**
61
- * @inheritDoc
62
- */
63
- destroy(): void;
64
- /**
65
- * Focuses the fist {@link #_focusables} in the actions.
66
- */
67
- focus(): void;
68
- /**
69
- * Creates a button view.
70
- *
71
- * @param label The button label.
72
- * @param icon The button icon.
73
- * @param eventName An event name that the `ButtonView#execute` event will be delegated to.
74
- * @returns The button view instance.
75
- */
76
- private _createButton;
77
- /**
78
- * Creates a link href preview button.
79
- *
80
- * @returns The button view instance.
81
- */
82
- private _createPreviewButton;
83
- }
84
- /**
85
- * Fired when the {@link ~LinkActionsView#editButtonView} is clicked.
86
- *
87
- * @eventName ~LinkActionsView#edit
88
- */
89
- export type EditEvent = {
90
- name: 'edit';
91
- args: [];
92
- };
93
- /**
94
- * Fired when the {@link ~LinkActionsView#unlinkButtonView} is clicked.
95
- *
96
- * @eventName ~LinkActionsView#unlink
97
- */
98
- export type UnlinkEvent = {
99
- name: 'unlink';
100
- args: [];
101
- };
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 link/ui/linkactionsview
7
+ */
8
+ import { ButtonView, View } from 'ckeditor5/src/ui.js';
9
+ import { FocusTracker, KeystrokeHandler, type LocaleTranslate, type Locale } from 'ckeditor5/src/utils.js';
10
+ import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
11
+ import '../../theme/linkactions.css';
12
+ /**
13
+ * The link actions view class. This view displays the link preview, allows
14
+ * unlinking or editing the link.
15
+ */
16
+ export default class LinkActionsView extends View {
17
+ /**
18
+ * Tracks information about DOM focus in the actions.
19
+ */
20
+ readonly focusTracker: FocusTracker;
21
+ /**
22
+ * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
23
+ */
24
+ readonly keystrokes: KeystrokeHandler;
25
+ /**
26
+ * The href preview view.
27
+ */
28
+ previewButtonView: View;
29
+ /**
30
+ * The unlink button view.
31
+ */
32
+ unlinkButtonView: ButtonView;
33
+ /**
34
+ * The edit link button view.
35
+ */
36
+ editButtonView: ButtonView;
37
+ /**
38
+ * The value of the "href" attribute of the link to use in the {@link #previewButtonView}.
39
+ *
40
+ * @observable
41
+ */
42
+ href: string | undefined;
43
+ /**
44
+ * A collection of views that can be focused in the view.
45
+ */
46
+ private readonly _focusables;
47
+ /**
48
+ * Helps cycling over {@link #_focusables} in the view.
49
+ */
50
+ private readonly _focusCycler;
51
+ t: LocaleTranslate;
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ constructor(locale: Locale);
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ render(): void;
60
+ /**
61
+ * @inheritDoc
62
+ */
63
+ destroy(): void;
64
+ /**
65
+ * Focuses the fist {@link #_focusables} in the actions.
66
+ */
67
+ focus(): void;
68
+ /**
69
+ * Creates a button view.
70
+ *
71
+ * @param label The button label.
72
+ * @param icon The button icon.
73
+ * @param eventName An event name that the `ButtonView#execute` event will be delegated to.
74
+ * @returns The button view instance.
75
+ */
76
+ private _createButton;
77
+ /**
78
+ * Creates a link href preview button.
79
+ *
80
+ * @returns The button view instance.
81
+ */
82
+ private _createPreviewButton;
83
+ }
84
+ /**
85
+ * Fired when the {@link ~LinkActionsView#editButtonView} is clicked.
86
+ *
87
+ * @eventName ~LinkActionsView#edit
88
+ */
89
+ export type EditEvent = {
90
+ name: 'edit';
91
+ args: [];
92
+ };
93
+ /**
94
+ * Fired when the {@link ~LinkActionsView#unlinkButtonView} is clicked.
95
+ *
96
+ * @eventName ~LinkActionsView#unlink
97
+ */
98
+ export type UnlinkEvent = {
99
+ name: 'unlink';
100
+ args: [];
101
+ };
@@ -1,156 +1,156 @@
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 link/ui/linkactionsview
7
- */
8
- import { ButtonView, View, ViewCollection, FocusCycler } from 'ckeditor5/src/ui';
9
- import { FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils';
10
- import { icons } from 'ckeditor5/src/core';
11
- import { ensureSafeUrl } from '../utils';
12
- // See: #8833.
13
- // eslint-disable-next-line ckeditor5-rules/ckeditor-imports
14
- import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
15
- import '../../theme/linkactions.css';
16
- import unlinkIcon from '../../theme/icons/unlink.svg';
17
- /**
18
- * The link actions view class. This view displays the link preview, allows
19
- * unlinking or editing the link.
20
- */
21
- export default class LinkActionsView extends View {
22
- /**
23
- * @inheritDoc
24
- */
25
- constructor(locale) {
26
- super(locale);
27
- /**
28
- * Tracks information about DOM focus in the actions.
29
- */
30
- this.focusTracker = new FocusTracker();
31
- /**
32
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
33
- */
34
- this.keystrokes = new KeystrokeHandler();
35
- /**
36
- * A collection of views that can be focused in the view.
37
- */
38
- this._focusables = new ViewCollection();
39
- const t = locale.t;
40
- this.previewButtonView = this._createPreviewButton();
41
- this.unlinkButtonView = this._createButton(t('Unlink'), unlinkIcon, 'unlink');
42
- this.editButtonView = this._createButton(t('Edit link'), icons.pencil, 'edit');
43
- this.set('href', undefined);
44
- this._focusCycler = new FocusCycler({
45
- focusables: this._focusables,
46
- focusTracker: this.focusTracker,
47
- keystrokeHandler: this.keystrokes,
48
- actions: {
49
- // Navigate fields backwards using the Shift + Tab keystroke.
50
- focusPrevious: 'shift + tab',
51
- // Navigate fields forwards using the Tab key.
52
- focusNext: 'tab'
53
- }
54
- });
55
- this.setTemplate({
56
- tag: 'div',
57
- attributes: {
58
- class: [
59
- 'ck',
60
- 'ck-link-actions',
61
- 'ck-responsive-form'
62
- ],
63
- // https://github.com/ckeditor/ckeditor5-link/issues/90
64
- tabindex: '-1'
65
- },
66
- children: [
67
- this.previewButtonView,
68
- this.editButtonView,
69
- this.unlinkButtonView
70
- ]
71
- });
72
- }
73
- /**
74
- * @inheritDoc
75
- */
76
- render() {
77
- super.render();
78
- const childViews = [
79
- this.previewButtonView,
80
- this.editButtonView,
81
- this.unlinkButtonView
82
- ];
83
- childViews.forEach(v => {
84
- // Register the view as focusable.
85
- this._focusables.add(v);
86
- // Register the view in the focus tracker.
87
- this.focusTracker.add(v.element);
88
- });
89
- // Start listening for the keystrokes coming from #element.
90
- this.keystrokes.listenTo(this.element);
91
- }
92
- /**
93
- * @inheritDoc
94
- */
95
- destroy() {
96
- super.destroy();
97
- this.focusTracker.destroy();
98
- this.keystrokes.destroy();
99
- }
100
- /**
101
- * Focuses the fist {@link #_focusables} in the actions.
102
- */
103
- focus() {
104
- this._focusCycler.focusFirst();
105
- }
106
- /**
107
- * Creates a button view.
108
- *
109
- * @param label The button label.
110
- * @param icon The button icon.
111
- * @param eventName An event name that the `ButtonView#execute` event will be delegated to.
112
- * @returns The button view instance.
113
- */
114
- _createButton(label, icon, eventName) {
115
- const button = new ButtonView(this.locale);
116
- button.set({
117
- label,
118
- icon,
119
- tooltip: true
120
- });
121
- button.delegate('execute').to(this, eventName);
122
- return button;
123
- }
124
- /**
125
- * Creates a link href preview button.
126
- *
127
- * @returns The button view instance.
128
- */
129
- _createPreviewButton() {
130
- const button = new ButtonView(this.locale);
131
- const bind = this.bindTemplate;
132
- const t = this.t;
133
- button.set({
134
- withText: true,
135
- tooltip: t('Open link in new tab')
136
- });
137
- button.extendTemplate({
138
- attributes: {
139
- class: [
140
- 'ck',
141
- 'ck-link-actions__preview'
142
- ],
143
- href: bind.to('href', href => href && ensureSafeUrl(href)),
144
- target: '_blank',
145
- rel: 'noopener noreferrer'
146
- }
147
- });
148
- button.bind('label').to(this, 'href', href => {
149
- return href || t('This link has no URL');
150
- });
151
- button.bind('isEnabled').to(this, 'href', href => !!href);
152
- button.template.tag = 'a';
153
- button.template.eventListeners = {};
154
- return button;
155
- }
156
- }
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 link/ui/linkactionsview
7
+ */
8
+ import { ButtonView, View, ViewCollection, FocusCycler } from 'ckeditor5/src/ui.js';
9
+ import { FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils.js';
10
+ import { icons } from 'ckeditor5/src/core.js';
11
+ import { ensureSafeUrl } from '../utils.js';
12
+ // See: #8833.
13
+ // eslint-disable-next-line ckeditor5-rules/ckeditor-imports
14
+ import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
15
+ import '../../theme/linkactions.css';
16
+ import unlinkIcon from '../../theme/icons/unlink.svg';
17
+ /**
18
+ * The link actions view class. This view displays the link preview, allows
19
+ * unlinking or editing the link.
20
+ */
21
+ export default class LinkActionsView extends View {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ constructor(locale) {
26
+ super(locale);
27
+ /**
28
+ * Tracks information about DOM focus in the actions.
29
+ */
30
+ this.focusTracker = new FocusTracker();
31
+ /**
32
+ * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
33
+ */
34
+ this.keystrokes = new KeystrokeHandler();
35
+ /**
36
+ * A collection of views that can be focused in the view.
37
+ */
38
+ this._focusables = new ViewCollection();
39
+ const t = locale.t;
40
+ this.previewButtonView = this._createPreviewButton();
41
+ this.unlinkButtonView = this._createButton(t('Unlink'), unlinkIcon, 'unlink');
42
+ this.editButtonView = this._createButton(t('Edit link'), icons.pencil, 'edit');
43
+ this.set('href', undefined);
44
+ this._focusCycler = new FocusCycler({
45
+ focusables: this._focusables,
46
+ focusTracker: this.focusTracker,
47
+ keystrokeHandler: this.keystrokes,
48
+ actions: {
49
+ // Navigate fields backwards using the Shift + Tab keystroke.
50
+ focusPrevious: 'shift + tab',
51
+ // Navigate fields forwards using the Tab key.
52
+ focusNext: 'tab'
53
+ }
54
+ });
55
+ this.setTemplate({
56
+ tag: 'div',
57
+ attributes: {
58
+ class: [
59
+ 'ck',
60
+ 'ck-link-actions',
61
+ 'ck-responsive-form'
62
+ ],
63
+ // https://github.com/ckeditor/ckeditor5-link/issues/90
64
+ tabindex: '-1'
65
+ },
66
+ children: [
67
+ this.previewButtonView,
68
+ this.editButtonView,
69
+ this.unlinkButtonView
70
+ ]
71
+ });
72
+ }
73
+ /**
74
+ * @inheritDoc
75
+ */
76
+ render() {
77
+ super.render();
78
+ const childViews = [
79
+ this.previewButtonView,
80
+ this.editButtonView,
81
+ this.unlinkButtonView
82
+ ];
83
+ childViews.forEach(v => {
84
+ // Register the view as focusable.
85
+ this._focusables.add(v);
86
+ // Register the view in the focus tracker.
87
+ this.focusTracker.add(v.element);
88
+ });
89
+ // Start listening for the keystrokes coming from #element.
90
+ this.keystrokes.listenTo(this.element);
91
+ }
92
+ /**
93
+ * @inheritDoc
94
+ */
95
+ destroy() {
96
+ super.destroy();
97
+ this.focusTracker.destroy();
98
+ this.keystrokes.destroy();
99
+ }
100
+ /**
101
+ * Focuses the fist {@link #_focusables} in the actions.
102
+ */
103
+ focus() {
104
+ this._focusCycler.focusFirst();
105
+ }
106
+ /**
107
+ * Creates a button view.
108
+ *
109
+ * @param label The button label.
110
+ * @param icon The button icon.
111
+ * @param eventName An event name that the `ButtonView#execute` event will be delegated to.
112
+ * @returns The button view instance.
113
+ */
114
+ _createButton(label, icon, eventName) {
115
+ const button = new ButtonView(this.locale);
116
+ button.set({
117
+ label,
118
+ icon,
119
+ tooltip: true
120
+ });
121
+ button.delegate('execute').to(this, eventName);
122
+ return button;
123
+ }
124
+ /**
125
+ * Creates a link href preview button.
126
+ *
127
+ * @returns The button view instance.
128
+ */
129
+ _createPreviewButton() {
130
+ const button = new ButtonView(this.locale);
131
+ const bind = this.bindTemplate;
132
+ const t = this.t;
133
+ button.set({
134
+ withText: true,
135
+ tooltip: t('Open link in new tab')
136
+ });
137
+ button.extendTemplate({
138
+ attributes: {
139
+ class: [
140
+ 'ck',
141
+ 'ck-link-actions__preview'
142
+ ],
143
+ href: bind.to('href', href => href && ensureSafeUrl(href)),
144
+ target: '_blank',
145
+ rel: 'noopener noreferrer'
146
+ }
147
+ });
148
+ button.bind('label').to(this, 'href', href => {
149
+ return href || t('This link has no URL');
150
+ });
151
+ button.bind('isEnabled').to(this, 'href', href => !!href);
152
+ button.template.tag = 'a';
153
+ button.template.eventListeners = {};
154
+ return button;
155
+ }
156
+ }