@ckeditor/ckeditor5-editor-classic 40.0.0 → 40.1.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,151 +1,151 @@
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
- import { EditorUI, normalizeToolbarConfig } from 'ckeditor5/src/ui';
6
- import { enablePlaceholder } from 'ckeditor5/src/engine';
7
- import { ElementReplacer, Rect } from 'ckeditor5/src/utils';
8
- /**
9
- * The classic editor UI class.
10
- */
11
- export default class ClassicEditorUI extends EditorUI {
12
- /**
13
- * Creates an instance of the classic editor UI class.
14
- *
15
- * @param editor The editor instance.
16
- * @param view The view of the UI.
17
- */
18
- constructor(editor, view) {
19
- super(editor);
20
- this.view = view;
21
- this._toolbarConfig = normalizeToolbarConfig(editor.config.get('toolbar'));
22
- this._elementReplacer = new ElementReplacer();
23
- this.listenTo(editor.editing.view, 'scrollToTheSelection', this._handleScrollToTheSelectionWithStickyPanel.bind(this));
24
- }
25
- /**
26
- * @inheritDoc
27
- */
28
- get element() {
29
- return this.view.element;
30
- }
31
- /**
32
- * Initializes the UI.
33
- *
34
- * @param replacementElement The DOM element that will be the source for the created editor.
35
- */
36
- init(replacementElement) {
37
- const editor = this.editor;
38
- const view = this.view;
39
- const editingView = editor.editing.view;
40
- const editable = view.editable;
41
- const editingRoot = editingView.document.getRoot();
42
- // The editable UI and editing root should share the same name. Then name is used
43
- // to recognize the particular editable, for instance in ARIA attributes.
44
- editable.name = editingRoot.rootName;
45
- view.render();
46
- // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
47
- // But it can be available earlier if a DOM element has been passed to BalloonEditor.create().
48
- const editableElement = editable.element;
49
- // Register the editable UI view in the editor. A single editor instance can aggregate multiple
50
- // editable areas (roots) but the classic editor has only one.
51
- this.setEditableElement(editable.name, editableElement);
52
- // Let the editable UI element respond to the changes in the global editor focus
53
- // tracker. It has been added to the same tracker a few lines above but, in reality, there are
54
- // many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
55
- // as they have focus, the editable should act like it is focused too (although technically
56
- // it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
57
- // Doing otherwise will result in editable focus styles disappearing, once e.g. the
58
- // toolbar gets focused.
59
- view.editable.bind('isFocused').to(this.focusTracker);
60
- // Bind the editable UI element to the editing view, making it an end– and entry–point
61
- // of the editor's engine. This is where the engine meets the UI.
62
- editingView.attachDomRoot(editableElement);
63
- // If an element containing the initial data of the editor was provided, replace it with
64
- // an editor instance's UI in DOM until the editor is destroyed. For instance, a <textarea>
65
- // can be such element.
66
- if (replacementElement) {
67
- this._elementReplacer.replace(replacementElement, this.element);
68
- }
69
- this._initPlaceholder();
70
- this._initToolbar();
71
- this.fire('ready');
72
- }
73
- /**
74
- * @inheritDoc
75
- */
76
- destroy() {
77
- super.destroy();
78
- const view = this.view;
79
- const editingView = this.editor.editing.view;
80
- this._elementReplacer.restore();
81
- editingView.detachDomRoot(view.editable.name);
82
- view.destroy();
83
- }
84
- /**
85
- * Initializes the editor toolbar.
86
- */
87
- _initToolbar() {
88
- const view = this.view;
89
- // Set–up the sticky panel with toolbar.
90
- view.stickyPanel.bind('isActive').to(this.focusTracker, 'isFocused');
91
- view.stickyPanel.limiterElement = view.element;
92
- view.stickyPanel.bind('viewportTopOffset').to(this, 'viewportOffset', ({ top }) => top || 0);
93
- view.toolbar.fillFromConfig(this._toolbarConfig, this.componentFactory);
94
- // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
95
- this.addToolbar(view.toolbar);
96
- }
97
- /**
98
- * Enable the placeholder text on the editing root.
99
- */
100
- _initPlaceholder() {
101
- const editor = this.editor;
102
- const editingView = editor.editing.view;
103
- const editingRoot = editingView.document.getRoot();
104
- const sourceElement = editor.sourceElement;
105
- let placeholderText;
106
- const placeholder = editor.config.get('placeholder');
107
- if (placeholder) {
108
- placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[this.view.editable.name];
109
- }
110
- if (!placeholderText && sourceElement && sourceElement.tagName.toLowerCase() === 'textarea') {
111
- placeholderText = sourceElement.getAttribute('placeholder');
112
- }
113
- if (placeholderText) {
114
- editingRoot.placeholder = placeholderText;
115
- }
116
- enablePlaceholder({
117
- view: editingView,
118
- element: editingRoot,
119
- isDirectHost: false,
120
- keepOnFocus: true
121
- });
122
- }
123
- /**
124
- * Provides an integration between the sticky toolbar and {@link module:utils/dom/scroll~scrollViewportToShowTarget}.
125
- * It allows the UI-agnostic engine method to consider the geometry of the
126
- * {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#stickyPanel} that pins to the
127
- * edge of the viewport and can obscure the user caret after scrolling the window.
128
- *
129
- * @param evt The `scrollToTheSelection` event info.
130
- * @param data The payload carried by the `scrollToTheSelection` event.
131
- * @param originalArgs The original arguments passed to `scrollViewportToShowTarget()` method (see implementation to learn more).
132
- */
133
- _handleScrollToTheSelectionWithStickyPanel(evt, data, originalArgs) {
134
- const stickyPanel = this.view.stickyPanel;
135
- if (stickyPanel.isSticky) {
136
- const stickyPanelHeight = new Rect(stickyPanel.element).height;
137
- data.viewportOffset.top += stickyPanelHeight;
138
- }
139
- else {
140
- const scrollViewportOnPanelGettingSticky = () => {
141
- this.editor.editing.view.scrollToTheSelection(originalArgs);
142
- };
143
- this.listenTo(stickyPanel, 'change:isSticky', scrollViewportOnPanelGettingSticky);
144
- // This works as a post-scroll-fixer because it's impossible predict whether the panel will be sticky after scrolling or not.
145
- // Listen for a short period of time only and if the toolbar does not become sticky very soon, cancel the listener.
146
- setTimeout(() => {
147
- this.stopListening(stickyPanel, 'change:isSticky', scrollViewportOnPanelGettingSticky);
148
- }, 20);
149
- }
150
- }
151
- }
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
+ import { EditorUI, normalizeToolbarConfig } from 'ckeditor5/src/ui';
6
+ import { enablePlaceholder } from 'ckeditor5/src/engine';
7
+ import { ElementReplacer, Rect } from 'ckeditor5/src/utils';
8
+ /**
9
+ * The classic editor UI class.
10
+ */
11
+ export default class ClassicEditorUI extends EditorUI {
12
+ /**
13
+ * Creates an instance of the classic editor UI class.
14
+ *
15
+ * @param editor The editor instance.
16
+ * @param view The view of the UI.
17
+ */
18
+ constructor(editor, view) {
19
+ super(editor);
20
+ this.view = view;
21
+ this._toolbarConfig = normalizeToolbarConfig(editor.config.get('toolbar'));
22
+ this._elementReplacer = new ElementReplacer();
23
+ this.listenTo(editor.editing.view, 'scrollToTheSelection', this._handleScrollToTheSelectionWithStickyPanel.bind(this));
24
+ }
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ get element() {
29
+ return this.view.element;
30
+ }
31
+ /**
32
+ * Initializes the UI.
33
+ *
34
+ * @param replacementElement The DOM element that will be the source for the created editor.
35
+ */
36
+ init(replacementElement) {
37
+ const editor = this.editor;
38
+ const view = this.view;
39
+ const editingView = editor.editing.view;
40
+ const editable = view.editable;
41
+ const editingRoot = editingView.document.getRoot();
42
+ // The editable UI and editing root should share the same name. Then name is used
43
+ // to recognize the particular editable, for instance in ARIA attributes.
44
+ editable.name = editingRoot.rootName;
45
+ view.render();
46
+ // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
47
+ // But it can be available earlier if a DOM element has been passed to BalloonEditor.create().
48
+ const editableElement = editable.element;
49
+ // Register the editable UI view in the editor. A single editor instance can aggregate multiple
50
+ // editable areas (roots) but the classic editor has only one.
51
+ this.setEditableElement(editable.name, editableElement);
52
+ // Let the editable UI element respond to the changes in the global editor focus
53
+ // tracker. It has been added to the same tracker a few lines above but, in reality, there are
54
+ // many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
55
+ // as they have focus, the editable should act like it is focused too (although technically
56
+ // it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
57
+ // Doing otherwise will result in editable focus styles disappearing, once e.g. the
58
+ // toolbar gets focused.
59
+ view.editable.bind('isFocused').to(this.focusTracker);
60
+ // Bind the editable UI element to the editing view, making it an end– and entry–point
61
+ // of the editor's engine. This is where the engine meets the UI.
62
+ editingView.attachDomRoot(editableElement);
63
+ // If an element containing the initial data of the editor was provided, replace it with
64
+ // an editor instance's UI in DOM until the editor is destroyed. For instance, a <textarea>
65
+ // can be such element.
66
+ if (replacementElement) {
67
+ this._elementReplacer.replace(replacementElement, this.element);
68
+ }
69
+ this._initPlaceholder();
70
+ this._initToolbar();
71
+ this.fire('ready');
72
+ }
73
+ /**
74
+ * @inheritDoc
75
+ */
76
+ destroy() {
77
+ super.destroy();
78
+ const view = this.view;
79
+ const editingView = this.editor.editing.view;
80
+ this._elementReplacer.restore();
81
+ editingView.detachDomRoot(view.editable.name);
82
+ view.destroy();
83
+ }
84
+ /**
85
+ * Initializes the editor toolbar.
86
+ */
87
+ _initToolbar() {
88
+ const view = this.view;
89
+ // Set–up the sticky panel with toolbar.
90
+ view.stickyPanel.bind('isActive').to(this.focusTracker, 'isFocused');
91
+ view.stickyPanel.limiterElement = view.element;
92
+ view.stickyPanel.bind('viewportTopOffset').to(this, 'viewportOffset', ({ top }) => top || 0);
93
+ view.toolbar.fillFromConfig(this._toolbarConfig, this.componentFactory);
94
+ // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
95
+ this.addToolbar(view.toolbar);
96
+ }
97
+ /**
98
+ * Enable the placeholder text on the editing root.
99
+ */
100
+ _initPlaceholder() {
101
+ const editor = this.editor;
102
+ const editingView = editor.editing.view;
103
+ const editingRoot = editingView.document.getRoot();
104
+ const sourceElement = editor.sourceElement;
105
+ let placeholderText;
106
+ const placeholder = editor.config.get('placeholder');
107
+ if (placeholder) {
108
+ placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[this.view.editable.name];
109
+ }
110
+ if (!placeholderText && sourceElement && sourceElement.tagName.toLowerCase() === 'textarea') {
111
+ placeholderText = sourceElement.getAttribute('placeholder');
112
+ }
113
+ if (placeholderText) {
114
+ editingRoot.placeholder = placeholderText;
115
+ }
116
+ enablePlaceholder({
117
+ view: editingView,
118
+ element: editingRoot,
119
+ isDirectHost: false,
120
+ keepOnFocus: true
121
+ });
122
+ }
123
+ /**
124
+ * Provides an integration between the sticky toolbar and {@link module:utils/dom/scroll~scrollViewportToShowTarget}.
125
+ * It allows the UI-agnostic engine method to consider the geometry of the
126
+ * {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#stickyPanel} that pins to the
127
+ * edge of the viewport and can obscure the user caret after scrolling the window.
128
+ *
129
+ * @param evt The `scrollToTheSelection` event info.
130
+ * @param data The payload carried by the `scrollToTheSelection` event.
131
+ * @param originalArgs The original arguments passed to `scrollViewportToShowTarget()` method (see implementation to learn more).
132
+ */
133
+ _handleScrollToTheSelectionWithStickyPanel(evt, data, originalArgs) {
134
+ const stickyPanel = this.view.stickyPanel;
135
+ if (stickyPanel.isSticky) {
136
+ const stickyPanelHeight = new Rect(stickyPanel.element).height;
137
+ data.viewportOffset.top += stickyPanelHeight;
138
+ }
139
+ else {
140
+ const scrollViewportOnPanelGettingSticky = () => {
141
+ this.editor.editing.view.scrollToTheSelection(originalArgs);
142
+ };
143
+ this.listenTo(stickyPanel, 'change:isSticky', scrollViewportOnPanelGettingSticky);
144
+ // This works as a post-scroll-fixer because it's impossible predict whether the panel will be sticky after scrolling or not.
145
+ // Listen for a short period of time only and if the toolbar does not become sticky very soon, cancel the listener.
146
+ setTimeout(() => {
147
+ this.stopListening(stickyPanel, 'change:isSticky', scrollViewportOnPanelGettingSticky);
148
+ }, 20);
149
+ }
150
+ }
151
+ }
@@ -1,47 +1,47 @@
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 editor-classic/classiceditoruiview
7
- */
8
- import { BoxedEditorUIView, InlineEditableUIView, StickyPanelView, ToolbarView } from 'ckeditor5/src/ui';
9
- import type { Locale } from 'ckeditor5/src/utils';
10
- import type { View } from 'ckeditor5/src/engine';
11
- import '../theme/classiceditor.css';
12
- /**
13
- * Classic editor UI view. Uses an inline editable and a sticky toolbar, all
14
- * enclosed in a boxed UI view.
15
- */
16
- export default class ClassicEditorUIView extends BoxedEditorUIView {
17
- /**
18
- * Sticky panel view instance. This is a parent view of a {@link #toolbar}
19
- * that makes toolbar sticky.
20
- */
21
- readonly stickyPanel: StickyPanelView;
22
- /**
23
- * Toolbar view instance.
24
- */
25
- readonly toolbar: ToolbarView;
26
- /**
27
- * Editable UI view.
28
- */
29
- readonly editable: InlineEditableUIView;
30
- /**
31
- * Creates an instance of the classic editor UI view.
32
- *
33
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
34
- * @param editingView The editing view instance this view is related to.
35
- * @param options Configuration options for the view instance.
36
- * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
37
- * in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
38
- * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
39
- */
40
- constructor(locale: Locale, editingView: View, options?: {
41
- shouldToolbarGroupWhenFull?: boolean;
42
- });
43
- /**
44
- * @inheritDoc
45
- */
46
- render(): void;
47
- }
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 editor-classic/classiceditoruiview
7
+ */
8
+ import { BoxedEditorUIView, InlineEditableUIView, StickyPanelView, ToolbarView } from 'ckeditor5/src/ui';
9
+ import type { Locale } from 'ckeditor5/src/utils';
10
+ import type { View } from 'ckeditor5/src/engine';
11
+ import '../theme/classiceditor.css';
12
+ /**
13
+ * Classic editor UI view. Uses an inline editable and a sticky toolbar, all
14
+ * enclosed in a boxed UI view.
15
+ */
16
+ export default class ClassicEditorUIView extends BoxedEditorUIView {
17
+ /**
18
+ * Sticky panel view instance. This is a parent view of a {@link #toolbar}
19
+ * that makes toolbar sticky.
20
+ */
21
+ readonly stickyPanel: StickyPanelView;
22
+ /**
23
+ * Toolbar view instance.
24
+ */
25
+ readonly toolbar: ToolbarView;
26
+ /**
27
+ * Editable UI view.
28
+ */
29
+ readonly editable: InlineEditableUIView;
30
+ /**
31
+ * Creates an instance of the classic editor UI view.
32
+ *
33
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
34
+ * @param editingView The editing view instance this view is related to.
35
+ * @param options Configuration options for the view instance.
36
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
37
+ * in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
38
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
39
+ */
40
+ constructor(locale: Locale, editingView: View, options?: {
41
+ shouldToolbarGroupWhenFull?: boolean;
42
+ });
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ render(): void;
47
+ }
@@ -1,43 +1,43 @@
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 editor-classic/classiceditoruiview
7
- */
8
- import { BoxedEditorUIView, InlineEditableUIView, StickyPanelView, ToolbarView } from 'ckeditor5/src/ui';
9
- import '../theme/classiceditor.css';
10
- /**
11
- * Classic editor UI view. Uses an inline editable and a sticky toolbar, all
12
- * enclosed in a boxed UI view.
13
- */
14
- export default class ClassicEditorUIView extends BoxedEditorUIView {
15
- /**
16
- * Creates an instance of the classic editor UI view.
17
- *
18
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
19
- * @param editingView The editing view instance this view is related to.
20
- * @param options Configuration options for the view instance.
21
- * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
22
- * in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
23
- * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
24
- */
25
- constructor(locale, editingView, options = {}) {
26
- super(locale);
27
- this.stickyPanel = new StickyPanelView(locale);
28
- this.toolbar = new ToolbarView(locale, {
29
- shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
30
- });
31
- this.editable = new InlineEditableUIView(locale, editingView);
32
- }
33
- /**
34
- * @inheritDoc
35
- */
36
- render() {
37
- super.render();
38
- // Set toolbar as a child of a stickyPanel and makes toolbar sticky.
39
- this.stickyPanel.content.add(this.toolbar);
40
- this.top.add(this.stickyPanel);
41
- this.main.add(this.editable);
42
- }
43
- }
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 editor-classic/classiceditoruiview
7
+ */
8
+ import { BoxedEditorUIView, InlineEditableUIView, StickyPanelView, ToolbarView } from 'ckeditor5/src/ui';
9
+ import '../theme/classiceditor.css';
10
+ /**
11
+ * Classic editor UI view. Uses an inline editable and a sticky toolbar, all
12
+ * enclosed in a boxed UI view.
13
+ */
14
+ export default class ClassicEditorUIView extends BoxedEditorUIView {
15
+ /**
16
+ * Creates an instance of the classic editor UI view.
17
+ *
18
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
19
+ * @param editingView The editing view instance this view is related to.
20
+ * @param options Configuration options for the view instance.
21
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
22
+ * in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
23
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
24
+ */
25
+ constructor(locale, editingView, options = {}) {
26
+ super(locale);
27
+ this.stickyPanel = new StickyPanelView(locale);
28
+ this.toolbar = new ToolbarView(locale, {
29
+ shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
30
+ });
31
+ this.editable = new InlineEditableUIView(locale, editingView);
32
+ }
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ render() {
37
+ super.render();
38
+ // Set toolbar as a child of a stickyPanel and makes toolbar sticky.
39
+ this.stickyPanel.content.add(this.toolbar);
40
+ this.top.add(this.stickyPanel);
41
+ this.main.add(this.editable);
42
+ }
43
+ }
package/src/index.d.ts CHANGED
@@ -1,8 +1,8 @@
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 editor-classic
7
- */
8
- export { default as ClassicEditor } from './classiceditor';
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 editor-classic
7
+ */
8
+ export { default as ClassicEditor } from './classiceditor';
package/src/index.js CHANGED
@@ -1,8 +1,8 @@
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 editor-classic
7
- */
8
- export { default as ClassicEditor } from './classiceditor';
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 editor-classic
7
+ */
8
+ export { default as ClassicEditor } from './classiceditor';