@ckeditor/ckeditor5-editor-decoupled 39.0.2 → 40.0.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,97 +1,97 @@
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 } from 'ckeditor5/src/ui';
6
- import { enablePlaceholder } from 'ckeditor5/src/engine';
7
- /**
8
- * The decoupled editor UI class.
9
- */
10
- export default class DecoupledEditorUI extends EditorUI {
11
- /**
12
- * Creates an instance of the decoupled editor UI class.
13
- *
14
- * @param editor The editor instance.
15
- * @param view The view of the UI.
16
- */
17
- constructor(editor, view) {
18
- super(editor);
19
- this.view = view;
20
- }
21
- /**
22
- * Initializes the UI.
23
- */
24
- init() {
25
- const editor = this.editor;
26
- const view = this.view;
27
- const editingView = editor.editing.view;
28
- const editable = view.editable;
29
- const editingRoot = editingView.document.getRoot();
30
- // The editable UI and editing root should share the same name. Then name is used
31
- // to recognize the particular editable, for instance in ARIA attributes.
32
- editable.name = editingRoot.rootName;
33
- view.render();
34
- // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
35
- // But it can be available earlier if a DOM element has been passed to DecoupledEditor.create().
36
- const editableElement = editable.element;
37
- // Register the editable UI view in the editor. A single editor instance can aggregate multiple
38
- // editable areas (roots) but the decoupled editor has only one.
39
- this.setEditableElement(editable.name, editableElement);
40
- // Let the editable UI element respond to the changes in the global editor focus
41
- // tracker. It has been added to the same tracker a few lines above but, in reality, there are
42
- // many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
43
- // as they have focus, the editable should act like it is focused too (although technically
44
- // it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
45
- // Doing otherwise will result in editable focus styles disappearing, once e.g. the
46
- // toolbar gets focused.
47
- view.editable.bind('isFocused').to(this.focusTracker);
48
- // Bind the editable UI element to the editing view, making it an end– and entry–point
49
- // of the editor's engine. This is where the engine meets the UI.
50
- editingView.attachDomRoot(editableElement);
51
- this._initPlaceholder();
52
- this._initToolbar();
53
- this.fire('ready');
54
- }
55
- /**
56
- * @inheritDoc
57
- */
58
- destroy() {
59
- super.destroy();
60
- const view = this.view;
61
- const editingView = this.editor.editing.view;
62
- editingView.detachDomRoot(view.editable.name);
63
- view.destroy();
64
- }
65
- /**
66
- * Initializes the inline editor toolbar and its panel.
67
- */
68
- _initToolbar() {
69
- const editor = this.editor;
70
- const view = this.view;
71
- const toolbar = view.toolbar;
72
- toolbar.fillFromConfig(editor.config.get('toolbar'), this.componentFactory);
73
- // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
74
- this.addToolbar(view.toolbar);
75
- }
76
- /**
77
- * Enable the placeholder text on the editing root.
78
- */
79
- _initPlaceholder() {
80
- const editor = this.editor;
81
- const editingView = editor.editing.view;
82
- const editingRoot = editingView.document.getRoot();
83
- const placeholder = editor.config.get('placeholder');
84
- if (placeholder) {
85
- const placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[editingRoot.rootName];
86
- if (placeholderText) {
87
- editingRoot.placeholder = placeholderText;
88
- }
89
- }
90
- enablePlaceholder({
91
- view: editingView,
92
- element: editingRoot,
93
- isDirectHost: false,
94
- keepOnFocus: true
95
- });
96
- }
97
- }
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 } from 'ckeditor5/src/ui';
6
+ import { enablePlaceholder } from 'ckeditor5/src/engine';
7
+ /**
8
+ * The decoupled editor UI class.
9
+ */
10
+ export default class DecoupledEditorUI extends EditorUI {
11
+ /**
12
+ * Creates an instance of the decoupled editor UI class.
13
+ *
14
+ * @param editor The editor instance.
15
+ * @param view The view of the UI.
16
+ */
17
+ constructor(editor, view) {
18
+ super(editor);
19
+ this.view = view;
20
+ }
21
+ /**
22
+ * Initializes the UI.
23
+ */
24
+ init() {
25
+ const editor = this.editor;
26
+ const view = this.view;
27
+ const editingView = editor.editing.view;
28
+ const editable = view.editable;
29
+ const editingRoot = editingView.document.getRoot();
30
+ // The editable UI and editing root should share the same name. Then name is used
31
+ // to recognize the particular editable, for instance in ARIA attributes.
32
+ editable.name = editingRoot.rootName;
33
+ view.render();
34
+ // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
35
+ // But it can be available earlier if a DOM element has been passed to DecoupledEditor.create().
36
+ const editableElement = editable.element;
37
+ // Register the editable UI view in the editor. A single editor instance can aggregate multiple
38
+ // editable areas (roots) but the decoupled editor has only one.
39
+ this.setEditableElement(editable.name, editableElement);
40
+ // Let the editable UI element respond to the changes in the global editor focus
41
+ // tracker. It has been added to the same tracker a few lines above but, in reality, there are
42
+ // many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
43
+ // as they have focus, the editable should act like it is focused too (although technically
44
+ // it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
45
+ // Doing otherwise will result in editable focus styles disappearing, once e.g. the
46
+ // toolbar gets focused.
47
+ view.editable.bind('isFocused').to(this.focusTracker);
48
+ // Bind the editable UI element to the editing view, making it an end– and entry–point
49
+ // of the editor's engine. This is where the engine meets the UI.
50
+ editingView.attachDomRoot(editableElement);
51
+ this._initPlaceholder();
52
+ this._initToolbar();
53
+ this.fire('ready');
54
+ }
55
+ /**
56
+ * @inheritDoc
57
+ */
58
+ destroy() {
59
+ super.destroy();
60
+ const view = this.view;
61
+ const editingView = this.editor.editing.view;
62
+ editingView.detachDomRoot(view.editable.name);
63
+ view.destroy();
64
+ }
65
+ /**
66
+ * Initializes the inline editor toolbar and its panel.
67
+ */
68
+ _initToolbar() {
69
+ const editor = this.editor;
70
+ const view = this.view;
71
+ const toolbar = view.toolbar;
72
+ toolbar.fillFromConfig(editor.config.get('toolbar'), this.componentFactory);
73
+ // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
74
+ this.addToolbar(view.toolbar);
75
+ }
76
+ /**
77
+ * Enable the placeholder text on the editing root.
78
+ */
79
+ _initPlaceholder() {
80
+ const editor = this.editor;
81
+ const editingView = editor.editing.view;
82
+ const editingRoot = editingView.document.getRoot();
83
+ const placeholder = editor.config.get('placeholder');
84
+ if (placeholder) {
85
+ const placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[editingRoot.rootName];
86
+ if (placeholderText) {
87
+ editingRoot.placeholder = placeholderText;
88
+ }
89
+ }
90
+ enablePlaceholder({
91
+ view: editingView,
92
+ element: editingRoot,
93
+ isDirectHost: false,
94
+ keepOnFocus: true
95
+ });
96
+ }
97
+ }
@@ -1,49 +1,49 @@
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-decoupled/decouplededitoruiview
7
- */
8
- import { EditorUIView, InlineEditableUIView, ToolbarView } from 'ckeditor5/src/ui';
9
- import type { Locale } from 'ckeditor5/src/utils';
10
- import type { View } from 'ckeditor5/src/engine';
11
- /**
12
- * The decoupled editor UI view. It is a virtual view providing an inline
13
- * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#editable} and a
14
- * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar}, but without any
15
- * specific arrangement of the components in the DOM.
16
- *
17
- * See {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
18
- * to learn more about this view.
19
- */
20
- export default class DecoupledEditorUIView extends EditorUIView {
21
- /**
22
- * The main toolbar of the decoupled editor UI.
23
- */
24
- readonly toolbar: ToolbarView;
25
- /**
26
- * The editable of the decoupled editor UI.
27
- */
28
- readonly editable: InlineEditableUIView;
29
- /**
30
- * Creates an instance of the decoupled editor UI view.
31
- *
32
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
33
- * @param editingView The editing view instance this view is related to.
34
- * @param options Configuration options for the view instance.
35
- * @param options.editableElement The editable element. If not specified, it will be automatically created by
36
- * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
37
- * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
38
- * in the main {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar toolbar}.
39
- * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
40
- */
41
- constructor(locale: Locale, editingView: View, options?: {
42
- editableElement?: HTMLElement;
43
- shouldToolbarGroupWhenFull?: boolean;
44
- });
45
- /**
46
- * @inheritDoc
47
- */
48
- render(): void;
49
- }
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-decoupled/decouplededitoruiview
7
+ */
8
+ import { EditorUIView, InlineEditableUIView, ToolbarView } from 'ckeditor5/src/ui';
9
+ import type { Locale } from 'ckeditor5/src/utils';
10
+ import type { View } from 'ckeditor5/src/engine';
11
+ /**
12
+ * The decoupled editor UI view. It is a virtual view providing an inline
13
+ * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#editable} and a
14
+ * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar}, but without any
15
+ * specific arrangement of the components in the DOM.
16
+ *
17
+ * See {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
18
+ * to learn more about this view.
19
+ */
20
+ export default class DecoupledEditorUIView extends EditorUIView {
21
+ /**
22
+ * The main toolbar of the decoupled editor UI.
23
+ */
24
+ readonly toolbar: ToolbarView;
25
+ /**
26
+ * The editable of the decoupled editor UI.
27
+ */
28
+ readonly editable: InlineEditableUIView;
29
+ /**
30
+ * Creates an instance of the decoupled editor UI view.
31
+ *
32
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
33
+ * @param editingView The editing view instance this view is related to.
34
+ * @param options Configuration options for the view instance.
35
+ * @param options.editableElement The editable element. If not specified, it will be automatically created by
36
+ * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
37
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
38
+ * in the main {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar toolbar}.
39
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
40
+ */
41
+ constructor(locale: Locale, editingView: View, options?: {
42
+ editableElement?: HTMLElement;
43
+ shouldToolbarGroupWhenFull?: boolean;
44
+ });
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ render(): void;
49
+ }
@@ -1,63 +1,63 @@
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-decoupled/decouplededitoruiview
7
- */
8
- import { EditorUIView, InlineEditableUIView, ToolbarView } from 'ckeditor5/src/ui';
9
- /**
10
- * The decoupled editor UI view. It is a virtual view providing an inline
11
- * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#editable} and a
12
- * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar}, but without any
13
- * specific arrangement of the components in the DOM.
14
- *
15
- * See {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
16
- * to learn more about this view.
17
- */
18
- export default class DecoupledEditorUIView extends EditorUIView {
19
- /**
20
- * Creates an instance of the decoupled editor UI view.
21
- *
22
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
23
- * @param editingView The editing view instance this view is related to.
24
- * @param options Configuration options for the view instance.
25
- * @param options.editableElement The editable element. If not specified, it will be automatically created by
26
- * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
27
- * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
28
- * in the main {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar toolbar}.
29
- * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
30
- */
31
- constructor(locale, editingView, options = {}) {
32
- super(locale);
33
- const t = locale.t;
34
- this.toolbar = new ToolbarView(locale, {
35
- shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
36
- });
37
- this.editable = new InlineEditableUIView(locale, editingView, options.editableElement, {
38
- label: editableView => {
39
- return t('Rich Text Editor. Editing area: %0', editableView.name);
40
- }
41
- });
42
- // This toolbar may be placed anywhere in the page so things like font size need to be reset in it.
43
- // Because of the above, make sure the toolbar supports rounded corners.
44
- // Also, make sure the toolbar has the proper dir attribute because its ancestor may not have one
45
- // and some toolbar item styles depend on this attribute.
46
- this.toolbar.extendTemplate({
47
- attributes: {
48
- class: [
49
- 'ck-reset_all',
50
- 'ck-rounded-corners'
51
- ],
52
- dir: locale.uiLanguageDirection
53
- }
54
- });
55
- }
56
- /**
57
- * @inheritDoc
58
- */
59
- render() {
60
- super.render();
61
- this.registerChild([this.toolbar, this.editable]);
62
- }
63
- }
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-decoupled/decouplededitoruiview
7
+ */
8
+ import { EditorUIView, InlineEditableUIView, ToolbarView } from 'ckeditor5/src/ui';
9
+ /**
10
+ * The decoupled editor UI view. It is a virtual view providing an inline
11
+ * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#editable} and a
12
+ * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar}, but without any
13
+ * specific arrangement of the components in the DOM.
14
+ *
15
+ * See {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
16
+ * to learn more about this view.
17
+ */
18
+ export default class DecoupledEditorUIView extends EditorUIView {
19
+ /**
20
+ * Creates an instance of the decoupled editor UI view.
21
+ *
22
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
23
+ * @param editingView The editing view instance this view is related to.
24
+ * @param options Configuration options for the view instance.
25
+ * @param options.editableElement The editable element. If not specified, it will be automatically created by
26
+ * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
27
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
28
+ * in the main {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar toolbar}.
29
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
30
+ */
31
+ constructor(locale, editingView, options = {}) {
32
+ super(locale);
33
+ const t = locale.t;
34
+ this.toolbar = new ToolbarView(locale, {
35
+ shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
36
+ });
37
+ this.editable = new InlineEditableUIView(locale, editingView, options.editableElement, {
38
+ label: editableView => {
39
+ return t('Rich Text Editor. Editing area: %0', editableView.name);
40
+ }
41
+ });
42
+ // This toolbar may be placed anywhere in the page so things like font size need to be reset in it.
43
+ // Because of the above, make sure the toolbar supports rounded corners.
44
+ // Also, make sure the toolbar has the proper dir attribute because its ancestor may not have one
45
+ // and some toolbar item styles depend on this attribute.
46
+ this.toolbar.extendTemplate({
47
+ attributes: {
48
+ class: [
49
+ 'ck-reset_all',
50
+ 'ck-rounded-corners'
51
+ ],
52
+ dir: locale.uiLanguageDirection
53
+ }
54
+ });
55
+ }
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ render() {
60
+ super.render();
61
+ this.registerChild([this.toolbar, this.editable]);
62
+ }
63
+ }
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-decoupled
7
- */
8
- export { default as DecoupledEditor } from './decouplededitor';
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-decoupled
7
+ */
8
+ export { default as DecoupledEditor } from './decouplededitor';
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-decoupled
7
- */
8
- export { default as DecoupledEditor } from './decouplededitor';
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-decoupled
7
+ */
8
+ export { default as DecoupledEditor } from './decouplededitor';