@ckeditor/ckeditor5-editor-inline 40.0.0 → 40.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,121 +1,121 @@
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
- /**
8
- * The inline editor UI class.
9
- *
10
- * @extends module:ui/editorui/editorui~EditorUI
11
- */
12
- export default class InlineEditorUI extends EditorUI {
13
- /**
14
- * Creates an instance of the inline editor UI class.
15
- *
16
- * @param editor The editor instance.
17
- * @param view The view of the UI.
18
- */
19
- constructor(editor, view) {
20
- super(editor);
21
- this.view = view;
22
- this._toolbarConfig = normalizeToolbarConfig(editor.config.get('toolbar'));
23
- }
24
- /**
25
- * @inheritDoc
26
- */
27
- get element() {
28
- return this.view.editable.element;
29
- }
30
- /**
31
- * Initializes the UI.
32
- */
33
- init() {
34
- const editor = this.editor;
35
- const view = this.view;
36
- const editingView = editor.editing.view;
37
- const editable = view.editable;
38
- const editingRoot = editingView.document.getRoot();
39
- // The editable UI and editing root should share the same name. Then name is used
40
- // to recognize the particular editable, for instance in ARIA attributes.
41
- editable.name = editingRoot.rootName;
42
- view.render();
43
- // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
44
- // But it can be available earlier if a DOM element has been passed to InlineEditor.create().
45
- const editableElement = editable.element;
46
- // Register the editable UI view in the editor. A single editor instance can aggregate multiple
47
- // editable areas (roots) but the inline editor has only one.
48
- this.setEditableElement(editable.name, editableElement);
49
- // Let the editable UI element respond to the changes in the global editor focus
50
- // tracker. It has been added to the same tracker a few lines above but, in reality, there are
51
- // many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
52
- // as they have focus, the editable should act like it is focused too (although technically
53
- // it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
54
- // Doing otherwise will result in editable focus styles disappearing, once e.g. the
55
- // toolbar gets focused.
56
- editable.bind('isFocused').to(this.focusTracker);
57
- // Bind the editable UI element to the editing view, making it an end– and entry–point
58
- // of the editor's engine. This is where the engine meets the UI.
59
- editingView.attachDomRoot(editableElement);
60
- this._initPlaceholder();
61
- this._initToolbar();
62
- this.fire('ready');
63
- }
64
- /**
65
- * @inheritDoc
66
- */
67
- destroy() {
68
- super.destroy();
69
- const view = this.view;
70
- const editingView = this.editor.editing.view;
71
- editingView.detachDomRoot(view.editable.name);
72
- view.destroy();
73
- }
74
- /**
75
- * Initializes the inline editor toolbar and its panel.
76
- */
77
- _initToolbar() {
78
- const editor = this.editor;
79
- const view = this.view;
80
- const editableElement = view.editable.element;
81
- const toolbar = view.toolbar;
82
- // Set–up the view#panel.
83
- view.panel.bind('isVisible').to(this.focusTracker, 'isFocused');
84
- view.bind('viewportTopOffset').to(this, 'viewportOffset', ({ top }) => top || 0);
85
- // https://github.com/ckeditor/ckeditor5-editor-inline/issues/4
86
- view.listenTo(editor.ui, 'update', () => {
87
- // Don't pin if the panel is not already visible. It prevents the panel
88
- // showing up when there's no focus in the UI.
89
- if (view.panel.isVisible) {
90
- view.panel.pin({
91
- target: editableElement,
92
- positions: view.panelPositions
93
- });
94
- }
95
- });
96
- toolbar.fillFromConfig(this._toolbarConfig, this.componentFactory);
97
- // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
98
- this.addToolbar(toolbar);
99
- }
100
- /**
101
- * Enable the placeholder text on the editing root.
102
- */
103
- _initPlaceholder() {
104
- const editor = this.editor;
105
- const editingView = editor.editing.view;
106
- const editingRoot = editingView.document.getRoot();
107
- const placeholder = editor.config.get('placeholder');
108
- if (placeholder) {
109
- const placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[editingRoot.rootName];
110
- if (placeholderText) {
111
- editingRoot.placeholder = placeholderText;
112
- }
113
- }
114
- enablePlaceholder({
115
- view: editingView,
116
- element: editingRoot,
117
- isDirectHost: false,
118
- keepOnFocus: true
119
- });
120
- }
121
- }
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
+ /**
8
+ * The inline editor UI class.
9
+ *
10
+ * @extends module:ui/editorui/editorui~EditorUI
11
+ */
12
+ export default class InlineEditorUI extends EditorUI {
13
+ /**
14
+ * Creates an instance of the inline editor UI class.
15
+ *
16
+ * @param editor The editor instance.
17
+ * @param view The view of the UI.
18
+ */
19
+ constructor(editor, view) {
20
+ super(editor);
21
+ this.view = view;
22
+ this._toolbarConfig = normalizeToolbarConfig(editor.config.get('toolbar'));
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ get element() {
28
+ return this.view.editable.element;
29
+ }
30
+ /**
31
+ * Initializes the UI.
32
+ */
33
+ init() {
34
+ const editor = this.editor;
35
+ const view = this.view;
36
+ const editingView = editor.editing.view;
37
+ const editable = view.editable;
38
+ const editingRoot = editingView.document.getRoot();
39
+ // The editable UI and editing root should share the same name. Then name is used
40
+ // to recognize the particular editable, for instance in ARIA attributes.
41
+ editable.name = editingRoot.rootName;
42
+ view.render();
43
+ // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
44
+ // But it can be available earlier if a DOM element has been passed to InlineEditor.create().
45
+ const editableElement = editable.element;
46
+ // Register the editable UI view in the editor. A single editor instance can aggregate multiple
47
+ // editable areas (roots) but the inline editor has only one.
48
+ this.setEditableElement(editable.name, editableElement);
49
+ // Let the editable UI element respond to the changes in the global editor focus
50
+ // tracker. It has been added to the same tracker a few lines above but, in reality, there are
51
+ // many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
52
+ // as they have focus, the editable should act like it is focused too (although technically
53
+ // it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
54
+ // Doing otherwise will result in editable focus styles disappearing, once e.g. the
55
+ // toolbar gets focused.
56
+ editable.bind('isFocused').to(this.focusTracker);
57
+ // Bind the editable UI element to the editing view, making it an end– and entry–point
58
+ // of the editor's engine. This is where the engine meets the UI.
59
+ editingView.attachDomRoot(editableElement);
60
+ this._initPlaceholder();
61
+ this._initToolbar();
62
+ this.fire('ready');
63
+ }
64
+ /**
65
+ * @inheritDoc
66
+ */
67
+ destroy() {
68
+ super.destroy();
69
+ const view = this.view;
70
+ const editingView = this.editor.editing.view;
71
+ editingView.detachDomRoot(view.editable.name);
72
+ view.destroy();
73
+ }
74
+ /**
75
+ * Initializes the inline editor toolbar and its panel.
76
+ */
77
+ _initToolbar() {
78
+ const editor = this.editor;
79
+ const view = this.view;
80
+ const editableElement = view.editable.element;
81
+ const toolbar = view.toolbar;
82
+ // Set–up the view#panel.
83
+ view.panel.bind('isVisible').to(this.focusTracker, 'isFocused');
84
+ view.bind('viewportTopOffset').to(this, 'viewportOffset', ({ top }) => top || 0);
85
+ // https://github.com/ckeditor/ckeditor5-editor-inline/issues/4
86
+ view.listenTo(editor.ui, 'update', () => {
87
+ // Don't pin if the panel is not already visible. It prevents the panel
88
+ // showing up when there's no focus in the UI.
89
+ if (view.panel.isVisible) {
90
+ view.panel.pin({
91
+ target: editableElement,
92
+ positions: view.panelPositions
93
+ });
94
+ }
95
+ });
96
+ toolbar.fillFromConfig(this._toolbarConfig, this.componentFactory);
97
+ // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
98
+ this.addToolbar(toolbar);
99
+ }
100
+ /**
101
+ * Enable the placeholder text on the editing root.
102
+ */
103
+ _initPlaceholder() {
104
+ const editor = this.editor;
105
+ const editingView = editor.editing.view;
106
+ const editingRoot = editingView.document.getRoot();
107
+ const placeholder = editor.config.get('placeholder');
108
+ if (placeholder) {
109
+ const placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[editingRoot.rootName];
110
+ if (placeholderText) {
111
+ editingRoot.placeholder = placeholderText;
112
+ }
113
+ }
114
+ enablePlaceholder({
115
+ view: editingView,
116
+ element: editingRoot,
117
+ isDirectHost: false,
118
+ keepOnFocus: true
119
+ });
120
+ }
121
+ }
@@ -1,137 +1,137 @@
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-inline/inlineeditoruiview
7
- */
8
- import { BalloonPanelView, EditorUIView, InlineEditableUIView, ToolbarView } from 'ckeditor5/src/ui';
9
- import { type PositioningFunction, type Locale } from 'ckeditor5/src/utils';
10
- import type { View } from 'ckeditor5/src/engine';
11
- /**
12
- * Inline editor UI view. Uses an nline editable and a floating toolbar.
13
- */
14
- export default class InlineEditorUIView extends EditorUIView {
15
- /**
16
- * A floating toolbar view instance.
17
- */
18
- readonly toolbar: ToolbarView;
19
- /**
20
- * The offset from the top edge of the web browser's viewport which makes the
21
- * UI become sticky. The default value is `0`, which means that the UI becomes
22
- * sticky when its upper edge touches the top of the page viewport.
23
- *
24
- * This attribute is useful when the web page has UI elements positioned to the top
25
- * either using `position: fixed` or `position: sticky`, which would cover the
26
- * UI or vice–versa (depending on the `z-index` hierarchy).
27
- *
28
- * Bound to {@link module:ui/editorui/editorui~EditorUI#viewportOffset `EditorUI#viewportOffset`}.
29
- *
30
- * If {@link module:core/editor/editorconfig~EditorConfig#ui `EditorConfig#ui.viewportOffset.top`} is defined, then
31
- * it will override the default value.
32
- *
33
- * @observable
34
- * @default 0
35
- */
36
- viewportTopOffset: number;
37
- /**
38
- * A balloon panel view instance.
39
- */
40
- readonly panel: BalloonPanelView;
41
- /**
42
- * A set of positioning functions used by the {@link #panel} to float around
43
- * {@link #element editableElement}.
44
- *
45
- * The positioning functions are as follows:
46
- *
47
- * * West:
48
- *
49
- * ```
50
- * [ Panel ]
51
- * +------------------+
52
- * | #editableElement |
53
- * +------------------+
54
- *
55
- * +------------------+
56
- * | #editableElement |
57
- * |[ Panel ] |
58
- * | |
59
- * +------------------+
60
- *
61
- * +------------------+
62
- * | #editableElement |
63
- * +------------------+
64
- * [ Panel ]
65
- * ```
66
- *
67
- * * East:
68
- *
69
- * ```
70
- * [ Panel ]
71
- * +------------------+
72
- * | #editableElement |
73
- * +------------------+
74
- *
75
- * +------------------+
76
- * | #editableElement |
77
- * | [ Panel ]|
78
- * | |
79
- * +------------------+
80
- *
81
- * +------------------+
82
- * | #editableElement |
83
- * +------------------+
84
- * [ Panel ]
85
- * ```
86
- *
87
- * See: {@link module:utils/dom/position~Options#positions}.
88
- */
89
- readonly panelPositions: Array<PositioningFunction>;
90
- /**
91
- * Editable UI view.
92
- */
93
- readonly editable: InlineEditableUIView;
94
- /**
95
- * An instance of the resize observer that helps dynamically determine the geometry of the toolbar
96
- * and manage items that do not fit into a single row.
97
- *
98
- * **Note:** Created in {@link #render}.
99
- */
100
- private _resizeObserver;
101
- /**
102
- * Creates an instance of the inline editor UI view.
103
- *
104
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
105
- * @param editingView The editing view instance this view is related to.
106
- * @param editableElement The editable element. If not specified, it will be automatically created by
107
- * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
108
- * @param options Configuration options for the view instance.
109
- * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
110
- * in the main {@link module:editor-inline/inlineeditoruiview~InlineEditorUIView#toolbar toolbar}.
111
- * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
112
- */
113
- constructor(locale: Locale, editingView: View, editableElement?: HTMLElement, options?: {
114
- shouldToolbarGroupWhenFull?: boolean;
115
- });
116
- /**
117
- * @inheritDoc
118
- */
119
- render(): void;
120
- /**
121
- * @inheritDoc
122
- */
123
- destroy(): void;
124
- /**
125
- * Determines the panel top position of the {@link #panel} in {@link #panelPositions}.
126
- *
127
- * @param editableRect Rect of the {@link #element}.
128
- * @param panelRect Rect of the {@link #panel}.
129
- */
130
- private _getPanelPositionTop;
131
- /**
132
- * Returns the positions for {@link #panelPositions}.
133
- *
134
- * See: {@link module:utils/dom/position~Options#positions}.
135
- */
136
- private _getPanelPositions;
137
- }
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-inline/inlineeditoruiview
7
+ */
8
+ import { BalloonPanelView, EditorUIView, InlineEditableUIView, ToolbarView } from 'ckeditor5/src/ui';
9
+ import { type PositioningFunction, type Locale } from 'ckeditor5/src/utils';
10
+ import type { View } from 'ckeditor5/src/engine';
11
+ /**
12
+ * Inline editor UI view. Uses an nline editable and a floating toolbar.
13
+ */
14
+ export default class InlineEditorUIView extends EditorUIView {
15
+ /**
16
+ * A floating toolbar view instance.
17
+ */
18
+ readonly toolbar: ToolbarView;
19
+ /**
20
+ * The offset from the top edge of the web browser's viewport which makes the
21
+ * UI become sticky. The default value is `0`, which means that the UI becomes
22
+ * sticky when its upper edge touches the top of the page viewport.
23
+ *
24
+ * This attribute is useful when the web page has UI elements positioned to the top
25
+ * either using `position: fixed` or `position: sticky`, which would cover the
26
+ * UI or vice–versa (depending on the `z-index` hierarchy).
27
+ *
28
+ * Bound to {@link module:ui/editorui/editorui~EditorUI#viewportOffset `EditorUI#viewportOffset`}.
29
+ *
30
+ * If {@link module:core/editor/editorconfig~EditorConfig#ui `EditorConfig#ui.viewportOffset.top`} is defined, then
31
+ * it will override the default value.
32
+ *
33
+ * @observable
34
+ * @default 0
35
+ */
36
+ viewportTopOffset: number;
37
+ /**
38
+ * A balloon panel view instance.
39
+ */
40
+ readonly panel: BalloonPanelView;
41
+ /**
42
+ * A set of positioning functions used by the {@link #panel} to float around
43
+ * {@link #element editableElement}.
44
+ *
45
+ * The positioning functions are as follows:
46
+ *
47
+ * * West:
48
+ *
49
+ * ```
50
+ * [ Panel ]
51
+ * +------------------+
52
+ * | #editableElement |
53
+ * +------------------+
54
+ *
55
+ * +------------------+
56
+ * | #editableElement |
57
+ * |[ Panel ] |
58
+ * | |
59
+ * +------------------+
60
+ *
61
+ * +------------------+
62
+ * | #editableElement |
63
+ * +------------------+
64
+ * [ Panel ]
65
+ * ```
66
+ *
67
+ * * East:
68
+ *
69
+ * ```
70
+ * [ Panel ]
71
+ * +------------------+
72
+ * | #editableElement |
73
+ * +------------------+
74
+ *
75
+ * +------------------+
76
+ * | #editableElement |
77
+ * | [ Panel ]|
78
+ * | |
79
+ * +------------------+
80
+ *
81
+ * +------------------+
82
+ * | #editableElement |
83
+ * +------------------+
84
+ * [ Panel ]
85
+ * ```
86
+ *
87
+ * See: {@link module:utils/dom/position~Options#positions}.
88
+ */
89
+ readonly panelPositions: Array<PositioningFunction>;
90
+ /**
91
+ * Editable UI view.
92
+ */
93
+ readonly editable: InlineEditableUIView;
94
+ /**
95
+ * An instance of the resize observer that helps dynamically determine the geometry of the toolbar
96
+ * and manage items that do not fit into a single row.
97
+ *
98
+ * **Note:** Created in {@link #render}.
99
+ */
100
+ private _resizeObserver;
101
+ /**
102
+ * Creates an instance of the inline editor UI view.
103
+ *
104
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
105
+ * @param editingView The editing view instance this view is related to.
106
+ * @param editableElement The editable element. If not specified, it will be automatically created by
107
+ * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
108
+ * @param options Configuration options for the view instance.
109
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
110
+ * in the main {@link module:editor-inline/inlineeditoruiview~InlineEditorUIView#toolbar toolbar}.
111
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
112
+ */
113
+ constructor(locale: Locale, editingView: View, editableElement?: HTMLElement, options?: {
114
+ shouldToolbarGroupWhenFull?: boolean;
115
+ });
116
+ /**
117
+ * @inheritDoc
118
+ */
119
+ render(): void;
120
+ /**
121
+ * @inheritDoc
122
+ */
123
+ destroy(): void;
124
+ /**
125
+ * Determines the panel top position of the {@link #panel} in {@link #panelPositions}.
126
+ *
127
+ * @param editableRect Rect of the {@link #element}.
128
+ * @param panelRect Rect of the {@link #panel}.
129
+ */
130
+ private _getPanelPositionTop;
131
+ /**
132
+ * Returns the positions for {@link #panelPositions}.
133
+ *
134
+ * See: {@link module:utils/dom/position~Options#positions}.
135
+ */
136
+ private _getPanelPositions;
137
+ }