@ckeditor/ckeditor5-style 40.0.0 → 40.2.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.
- package/LICENSE.md +2 -2
- package/package.json +2 -2
- package/src/augmentation.d.ts +24 -24
- package/src/augmentation.js +5 -5
- package/src/index.d.ts +14 -14
- package/src/index.js +12 -12
- package/src/integrations/documentlist.d.ts +42 -42
- package/src/integrations/documentlist.js +141 -141
- package/src/integrations/link.d.ts +37 -37
- package/src/integrations/link.js +156 -156
- package/src/integrations/table.d.ts +49 -49
- package/src/integrations/table.js +115 -115
- package/src/style.d.ts +26 -26
- package/src/style.js +30 -30
- package/src/stylecommand.d.ts +82 -82
- package/src/stylecommand.js +200 -200
- package/src/styleconfig.d.ts +87 -87
- package/src/styleconfig.js +5 -5
- package/src/styleediting.d.ts +33 -33
- package/src/styleediting.js +46 -46
- package/src/styleui.d.ts +30 -30
- package/src/styleui.js +94 -94
- package/src/styleutils.d.ts +138 -138
- package/src/styleutils.js +268 -268
- package/src/ui/stylegridbuttonview.d.ts +34 -34
- package/src/ui/stylegridbuttonview.js +55 -55
- package/src/ui/stylegridview.d.ts +72 -72
- package/src/ui/stylegridview.js +89 -89
- package/src/ui/stylegroupview.d.ts +35 -35
- package/src/ui/stylegroupview.js +45 -45
- package/src/ui/stylepanelview.d.ts +89 -89
- package/src/ui/stylepanelview.js +95 -95
- package/build/style.js.map +0 -1
package/src/styleediting.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
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 style/styleediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import StyleCommand from './stylecommand';
|
|
10
|
-
import StyleUtils from './styleutils';
|
|
11
|
-
import DocumentListStyleSupport from './integrations/documentlist';
|
|
12
|
-
import TableStyleSupport from './integrations/table';
|
|
13
|
-
import LinkStyleSupport from './integrations/link';
|
|
14
|
-
/**
|
|
15
|
-
* The style engine feature.
|
|
16
|
-
*
|
|
17
|
-
* It configures the {@glink features/html/general-html-support General HTML Support feature} based on
|
|
18
|
-
* {@link module:style/styleconfig~StyleConfig#definitions configured style definitions} and introduces the
|
|
19
|
-
* {@link module:style/stylecommand~StyleCommand style command} that applies styles to the content of the document.
|
|
20
|
-
*/
|
|
21
|
-
export default class StyleEditing extends Plugin {
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
static get pluginName() {
|
|
26
|
-
return 'StyleEditing';
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @inheritDoc
|
|
30
|
-
*/
|
|
31
|
-
static get requires() {
|
|
32
|
-
return ['GeneralHtmlSupport', StyleUtils, DocumentListStyleSupport, TableStyleSupport, LinkStyleSupport];
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @inheritDoc
|
|
36
|
-
*/
|
|
37
|
-
init() {
|
|
38
|
-
const editor = this.editor;
|
|
39
|
-
const dataSchema = editor.plugins.get('DataSchema');
|
|
40
|
-
const styleUtils = editor.plugins.get('StyleUtils');
|
|
41
|
-
const styleDefinitions = editor.config.get('style.definitions');
|
|
42
|
-
const normalizedStyleDefinitions = styleUtils.normalizeConfig(dataSchema, styleDefinitions);
|
|
43
|
-
editor.commands.add('style', new StyleCommand(editor, normalizedStyleDefinitions));
|
|
44
|
-
styleUtils.configureGHSDataFilter(normalizedStyleDefinitions);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
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 style/styleediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import StyleCommand from './stylecommand';
|
|
10
|
+
import StyleUtils from './styleutils';
|
|
11
|
+
import DocumentListStyleSupport from './integrations/documentlist';
|
|
12
|
+
import TableStyleSupport from './integrations/table';
|
|
13
|
+
import LinkStyleSupport from './integrations/link';
|
|
14
|
+
/**
|
|
15
|
+
* The style engine feature.
|
|
16
|
+
*
|
|
17
|
+
* It configures the {@glink features/html/general-html-support General HTML Support feature} based on
|
|
18
|
+
* {@link module:style/styleconfig~StyleConfig#definitions configured style definitions} and introduces the
|
|
19
|
+
* {@link module:style/stylecommand~StyleCommand style command} that applies styles to the content of the document.
|
|
20
|
+
*/
|
|
21
|
+
export default class StyleEditing extends Plugin {
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get pluginName() {
|
|
26
|
+
return 'StyleEditing';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get requires() {
|
|
32
|
+
return ['GeneralHtmlSupport', StyleUtils, DocumentListStyleSupport, TableStyleSupport, LinkStyleSupport];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
init() {
|
|
38
|
+
const editor = this.editor;
|
|
39
|
+
const dataSchema = editor.plugins.get('DataSchema');
|
|
40
|
+
const styleUtils = editor.plugins.get('StyleUtils');
|
|
41
|
+
const styleDefinitions = editor.config.get('style.definitions');
|
|
42
|
+
const normalizedStyleDefinitions = styleUtils.normalizeConfig(dataSchema, styleDefinitions);
|
|
43
|
+
editor.commands.add('style', new StyleCommand(editor, normalizedStyleDefinitions));
|
|
44
|
+
styleUtils.configureGHSDataFilter(normalizedStyleDefinitions);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/styleui.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
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 style/styleui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import StyleUtils from './styleutils';
|
|
10
|
-
import '../theme/style.css';
|
|
11
|
-
/**
|
|
12
|
-
* The UI plugin of the style feature .
|
|
13
|
-
*
|
|
14
|
-
* It registers the `'style'` UI dropdown in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
|
|
15
|
-
* that displays a grid of styles and allows changing styles of the content.
|
|
16
|
-
*/
|
|
17
|
-
export default class StyleUI extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get pluginName(): "StyleUI";
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
static get requires(): readonly [typeof StyleUtils];
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
init(): void;
|
|
30
|
-
}
|
|
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 style/styleui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import StyleUtils from './styleutils';
|
|
10
|
+
import '../theme/style.css';
|
|
11
|
+
/**
|
|
12
|
+
* The UI plugin of the style feature .
|
|
13
|
+
*
|
|
14
|
+
* It registers the `'style'` UI dropdown in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
|
|
15
|
+
* that displays a grid of styles and allows changing styles of the content.
|
|
16
|
+
*/
|
|
17
|
+
export default class StyleUI extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get pluginName(): "StyleUI";
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get requires(): readonly [typeof StyleUtils];
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
init(): void;
|
|
30
|
+
}
|
package/src/styleui.js
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
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 style/styleui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { createDropdown } from 'ckeditor5/src/ui';
|
|
10
|
-
import StylePanelView from './ui/stylepanelview';
|
|
11
|
-
import StyleUtils from './styleutils';
|
|
12
|
-
import '../theme/style.css';
|
|
13
|
-
/**
|
|
14
|
-
* The UI plugin of the style feature .
|
|
15
|
-
*
|
|
16
|
-
* It registers the `'style'` UI dropdown in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
|
|
17
|
-
* that displays a grid of styles and allows changing styles of the content.
|
|
18
|
-
*/
|
|
19
|
-
export default class StyleUI extends Plugin {
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
static get pluginName() {
|
|
24
|
-
return 'StyleUI';
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get requires() {
|
|
30
|
-
return [StyleUtils];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
init() {
|
|
36
|
-
const editor = this.editor;
|
|
37
|
-
const dataSchema = editor.plugins.get('DataSchema');
|
|
38
|
-
const styleUtils = editor.plugins.get('StyleUtils');
|
|
39
|
-
const styleDefinitions = editor.config.get('style.definitions');
|
|
40
|
-
const normalizedStyleDefinitions = styleUtils.normalizeConfig(dataSchema, styleDefinitions);
|
|
41
|
-
// Add the dropdown to the component factory.
|
|
42
|
-
editor.ui.componentFactory.add('style', locale => {
|
|
43
|
-
const t = locale.t;
|
|
44
|
-
const dropdown = createDropdown(locale);
|
|
45
|
-
const styleCommand = editor.commands.get('style');
|
|
46
|
-
dropdown.once('change:isOpen', () => {
|
|
47
|
-
const panelView = new StylePanelView(locale, normalizedStyleDefinitions);
|
|
48
|
-
// Put the styles panel is the dropdown.
|
|
49
|
-
dropdown.panelView.children.add(panelView);
|
|
50
|
-
// Close the dropdown when a style is selected in the styles panel.
|
|
51
|
-
panelView.delegate('execute').to(dropdown);
|
|
52
|
-
// Bind the state of the styles panel to the command.
|
|
53
|
-
panelView.bind('activeStyles').to(styleCommand, 'value');
|
|
54
|
-
panelView.bind('enabledStyles').to(styleCommand, 'enabledStyles');
|
|
55
|
-
});
|
|
56
|
-
// The entire dropdown will be disabled together with the command (e.g. when the editor goes read-only).
|
|
57
|
-
dropdown.bind('isEnabled').to(styleCommand);
|
|
58
|
-
// This dropdown has no icon. It displays text label depending on the selection.
|
|
59
|
-
dropdown.buttonView.withText = true;
|
|
60
|
-
// The label of the dropdown is dynamic and depends on how many styles are active at a time.
|
|
61
|
-
dropdown.buttonView.bind('label').to(styleCommand, 'value', value => {
|
|
62
|
-
if (value.length > 1) {
|
|
63
|
-
return t('Multiple styles');
|
|
64
|
-
}
|
|
65
|
-
else if (value.length === 1) {
|
|
66
|
-
return value[0];
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return t('Styles');
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
// The dropdown has a static CSS class for easy customization. There's another CSS class
|
|
73
|
-
// that gets displayed when multiple styles are active at a time allowing visual customization of
|
|
74
|
-
// the label.
|
|
75
|
-
dropdown.bind('class').to(styleCommand, 'value', value => {
|
|
76
|
-
const classes = [
|
|
77
|
-
'ck-style-dropdown'
|
|
78
|
-
];
|
|
79
|
-
if (value.length > 1) {
|
|
80
|
-
classes.push('ck-style-dropdown_multiple-active');
|
|
81
|
-
}
|
|
82
|
-
return classes.join(' ');
|
|
83
|
-
});
|
|
84
|
-
// Execute the command when a style is selected in the styles panel.
|
|
85
|
-
// Also focus the editable after executing the command.
|
|
86
|
-
// It overrides a default behaviour where the focus is moved to the dropdown button (#12125).
|
|
87
|
-
dropdown.on('execute', evt => {
|
|
88
|
-
editor.execute('style', { styleName: evt.source.styleDefinition.name });
|
|
89
|
-
editor.editing.view.focus();
|
|
90
|
-
});
|
|
91
|
-
return dropdown;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
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 style/styleui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { createDropdown } from 'ckeditor5/src/ui';
|
|
10
|
+
import StylePanelView from './ui/stylepanelview';
|
|
11
|
+
import StyleUtils from './styleutils';
|
|
12
|
+
import '../theme/style.css';
|
|
13
|
+
/**
|
|
14
|
+
* The UI plugin of the style feature .
|
|
15
|
+
*
|
|
16
|
+
* It registers the `'style'` UI dropdown in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
|
|
17
|
+
* that displays a grid of styles and allows changing styles of the content.
|
|
18
|
+
*/
|
|
19
|
+
export default class StyleUI extends Plugin {
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
static get pluginName() {
|
|
24
|
+
return 'StyleUI';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
static get requires() {
|
|
30
|
+
return [StyleUtils];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
init() {
|
|
36
|
+
const editor = this.editor;
|
|
37
|
+
const dataSchema = editor.plugins.get('DataSchema');
|
|
38
|
+
const styleUtils = editor.plugins.get('StyleUtils');
|
|
39
|
+
const styleDefinitions = editor.config.get('style.definitions');
|
|
40
|
+
const normalizedStyleDefinitions = styleUtils.normalizeConfig(dataSchema, styleDefinitions);
|
|
41
|
+
// Add the dropdown to the component factory.
|
|
42
|
+
editor.ui.componentFactory.add('style', locale => {
|
|
43
|
+
const t = locale.t;
|
|
44
|
+
const dropdown = createDropdown(locale);
|
|
45
|
+
const styleCommand = editor.commands.get('style');
|
|
46
|
+
dropdown.once('change:isOpen', () => {
|
|
47
|
+
const panelView = new StylePanelView(locale, normalizedStyleDefinitions);
|
|
48
|
+
// Put the styles panel is the dropdown.
|
|
49
|
+
dropdown.panelView.children.add(panelView);
|
|
50
|
+
// Close the dropdown when a style is selected in the styles panel.
|
|
51
|
+
panelView.delegate('execute').to(dropdown);
|
|
52
|
+
// Bind the state of the styles panel to the command.
|
|
53
|
+
panelView.bind('activeStyles').to(styleCommand, 'value');
|
|
54
|
+
panelView.bind('enabledStyles').to(styleCommand, 'enabledStyles');
|
|
55
|
+
});
|
|
56
|
+
// The entire dropdown will be disabled together with the command (e.g. when the editor goes read-only).
|
|
57
|
+
dropdown.bind('isEnabled').to(styleCommand);
|
|
58
|
+
// This dropdown has no icon. It displays text label depending on the selection.
|
|
59
|
+
dropdown.buttonView.withText = true;
|
|
60
|
+
// The label of the dropdown is dynamic and depends on how many styles are active at a time.
|
|
61
|
+
dropdown.buttonView.bind('label').to(styleCommand, 'value', value => {
|
|
62
|
+
if (value.length > 1) {
|
|
63
|
+
return t('Multiple styles');
|
|
64
|
+
}
|
|
65
|
+
else if (value.length === 1) {
|
|
66
|
+
return value[0];
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return t('Styles');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
// The dropdown has a static CSS class for easy customization. There's another CSS class
|
|
73
|
+
// that gets displayed when multiple styles are active at a time allowing visual customization of
|
|
74
|
+
// the label.
|
|
75
|
+
dropdown.bind('class').to(styleCommand, 'value', value => {
|
|
76
|
+
const classes = [
|
|
77
|
+
'ck-style-dropdown'
|
|
78
|
+
];
|
|
79
|
+
if (value.length > 1) {
|
|
80
|
+
classes.push('ck-style-dropdown_multiple-active');
|
|
81
|
+
}
|
|
82
|
+
return classes.join(' ');
|
|
83
|
+
});
|
|
84
|
+
// Execute the command when a style is selected in the styles panel.
|
|
85
|
+
// Also focus the editable after executing the command.
|
|
86
|
+
// It overrides a default behaviour where the focus is moved to the dropdown button (#12125).
|
|
87
|
+
dropdown.on('execute', evt => {
|
|
88
|
+
editor.execute('style', { styleName: evt.source.styleDefinition.name });
|
|
89
|
+
editor.editing.view.focus();
|
|
90
|
+
});
|
|
91
|
+
return dropdown;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
package/src/styleutils.d.ts
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
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 style/styleutils
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
-
import type { Element, DocumentSelection, Selectable } from 'ckeditor5/src/engine';
|
|
10
|
-
import type { DecoratedMethodEvent } from 'ckeditor5/src/utils';
|
|
11
|
-
import type { TemplateDefinition } from 'ckeditor5/src/ui';
|
|
12
|
-
import type { DataSchema } from '@ckeditor/ckeditor5-html-support';
|
|
13
|
-
import type { StyleDefinition } from './styleconfig';
|
|
14
|
-
export default class StyleUtils extends Plugin {
|
|
15
|
-
private _htmlSupport;
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
static get pluginName(): "StyleUtils";
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
constructor(editor: Editor);
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
init(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Normalizes {@link module:style/styleconfig~StyleConfig#definitions} in the configuration of the styles feature.
|
|
30
|
-
* The structure of normalized styles looks as follows:
|
|
31
|
-
*
|
|
32
|
-
* ```ts
|
|
33
|
-
* {
|
|
34
|
-
* block: [
|
|
35
|
-
* <module:style/style~StyleDefinition>,
|
|
36
|
-
* <module:style/style~StyleDefinition>,
|
|
37
|
-
* ...
|
|
38
|
-
* ],
|
|
39
|
-
* inline: [
|
|
40
|
-
* <module:style/style~StyleDefinition>,
|
|
41
|
-
* <module:style/style~StyleDefinition>,
|
|
42
|
-
* ...
|
|
43
|
-
* ]
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @returns An object with normalized style definitions grouped into `block` and `inline` categories (arrays).
|
|
48
|
-
*/
|
|
49
|
-
normalizeConfig(dataSchema: DataSchema, styleDefinitions?: Array<StyleDefinition>): NormalizedStyleDefinitions;
|
|
50
|
-
/**
|
|
51
|
-
* Verifies if the given style is applicable to the provided block element.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
isStyleEnabledForBlock(definition: BlockStyleDefinition, block: Element): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Returns true if the given style is applied to the specified block element.
|
|
58
|
-
*
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
isStyleActiveForBlock(definition: BlockStyleDefinition, block: Element): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Returns an array of block elements that style should be applied to.
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
getAffectedBlocks(definition: BlockStyleDefinition, block: Element): Array<Element> | null;
|
|
68
|
-
/**
|
|
69
|
-
* Verifies if the given style is applicable to the provided document selection.
|
|
70
|
-
*
|
|
71
|
-
* @internal
|
|
72
|
-
*/
|
|
73
|
-
isStyleEnabledForInlineSelection(definition: InlineStyleDefinition, selection: DocumentSelection): boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Returns true if the given style is applied to the specified document selection.
|
|
76
|
-
*
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
isStyleActiveForInlineSelection(definition: InlineStyleDefinition, selection: DocumentSelection): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Returns a selectable that given style should be applied to.
|
|
82
|
-
*
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
getAffectedInlineSelectable(definition: InlineStyleDefinition, selection: DocumentSelection): Selectable;
|
|
86
|
-
/**
|
|
87
|
-
* Returns the `TemplateDefinition` used by styles dropdown to render style preview.
|
|
88
|
-
*
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
|
-
getStylePreview(definition: StyleDefinition, children: Iterable<TemplateDefinition>): TemplateDefinition;
|
|
92
|
-
/**
|
|
93
|
-
* Verifies if all classes are present in the given GHS attribute.
|
|
94
|
-
*
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
hasAllClasses(ghsAttributeValue: unknown, classes: Array<string>): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* This is where the styles feature configures the GHS feature. This method translates normalized
|
|
100
|
-
* {@link module:style/styleconfig~StyleDefinition style definitions} to
|
|
101
|
-
* {@link module:engine/view/matcher~MatcherObjectPattern matcher patterns} and feeds them to the GHS
|
|
102
|
-
* {@link module:html-support/datafilter~DataFilter} plugin.
|
|
103
|
-
*
|
|
104
|
-
* @internal
|
|
105
|
-
*/
|
|
106
|
-
configureGHSDataFilter({ block, inline }: NormalizedStyleDefinitions): void;
|
|
107
|
-
/**
|
|
108
|
-
* Checks the attribute value of the first node in the selection that allows the attribute.
|
|
109
|
-
* For the collapsed selection, returns the selection attribute.
|
|
110
|
-
*
|
|
111
|
-
* @param selection The document selection.
|
|
112
|
-
* @param attributeName Name of the GHS attribute.
|
|
113
|
-
* @returns The attribute value.
|
|
114
|
-
*/
|
|
115
|
-
private _getValueFromFirstAllowedNode;
|
|
116
|
-
}
|
|
117
|
-
export interface NormalizedStyleDefinitions {
|
|
118
|
-
block: Array<BlockStyleDefinition>;
|
|
119
|
-
inline: Array<InlineStyleDefinition>;
|
|
120
|
-
}
|
|
121
|
-
export interface BlockStyleDefinition extends StyleDefinition {
|
|
122
|
-
isBlock: true;
|
|
123
|
-
modelElements: Array<string>;
|
|
124
|
-
previewTemplate: TemplateDefinition;
|
|
125
|
-
}
|
|
126
|
-
export interface InlineStyleDefinition extends StyleDefinition {
|
|
127
|
-
ghsAttributes: Array<string>;
|
|
128
|
-
previewTemplate: TemplateDefinition;
|
|
129
|
-
}
|
|
130
|
-
export type NormalizedStyleDefinition = BlockStyleDefinition | InlineStyleDefinition;
|
|
131
|
-
export type StyleUtilsIsEnabledForBlockEvent = DecoratedMethodEvent<StyleUtils, 'isStyleEnabledForBlock'>;
|
|
132
|
-
export type StyleUtilsIsActiveForBlockEvent = DecoratedMethodEvent<StyleUtils, 'isStyleActiveForBlock'>;
|
|
133
|
-
export type StyleUtilsGetAffectedBlocksEvent = DecoratedMethodEvent<StyleUtils, 'getAffectedBlocks'>;
|
|
134
|
-
export type StyleUtilsIsStyleEnabledForInlineSelectionEvent = DecoratedMethodEvent<StyleUtils, 'isStyleEnabledForInlineSelection'>;
|
|
135
|
-
export type StyleUtilsIsStyleActiveForInlineSelectionEvent = DecoratedMethodEvent<StyleUtils, 'isStyleActiveForInlineSelection'>;
|
|
136
|
-
export type StyleUtilsGetAffectedInlineSelectableEvent = DecoratedMethodEvent<StyleUtils, 'getAffectedInlineSelectable'>;
|
|
137
|
-
export type StyleUtilsGetStylePreviewEvent = DecoratedMethodEvent<StyleUtils, 'getStylePreview'>;
|
|
138
|
-
export type StyleUtilsConfigureGHSDataFilterEvent = DecoratedMethodEvent<StyleUtils, 'configureGHSDataFilter'>;
|
|
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 style/styleutils
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
+
import type { Element, DocumentSelection, Selectable } from 'ckeditor5/src/engine';
|
|
10
|
+
import type { DecoratedMethodEvent } from 'ckeditor5/src/utils';
|
|
11
|
+
import type { TemplateDefinition } from 'ckeditor5/src/ui';
|
|
12
|
+
import type { DataSchema } from '@ckeditor/ckeditor5-html-support';
|
|
13
|
+
import type { StyleDefinition } from './styleconfig';
|
|
14
|
+
export default class StyleUtils extends Plugin {
|
|
15
|
+
private _htmlSupport;
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get pluginName(): "StyleUtils";
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
constructor(editor: Editor);
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
init(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Normalizes {@link module:style/styleconfig~StyleConfig#definitions} in the configuration of the styles feature.
|
|
30
|
+
* The structure of normalized styles looks as follows:
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* {
|
|
34
|
+
* block: [
|
|
35
|
+
* <module:style/style~StyleDefinition>,
|
|
36
|
+
* <module:style/style~StyleDefinition>,
|
|
37
|
+
* ...
|
|
38
|
+
* ],
|
|
39
|
+
* inline: [
|
|
40
|
+
* <module:style/style~StyleDefinition>,
|
|
41
|
+
* <module:style/style~StyleDefinition>,
|
|
42
|
+
* ...
|
|
43
|
+
* ]
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @returns An object with normalized style definitions grouped into `block` and `inline` categories (arrays).
|
|
48
|
+
*/
|
|
49
|
+
normalizeConfig(dataSchema: DataSchema, styleDefinitions?: Array<StyleDefinition>): NormalizedStyleDefinitions;
|
|
50
|
+
/**
|
|
51
|
+
* Verifies if the given style is applicable to the provided block element.
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
isStyleEnabledForBlock(definition: BlockStyleDefinition, block: Element): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Returns true if the given style is applied to the specified block element.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
isStyleActiveForBlock(definition: BlockStyleDefinition, block: Element): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Returns an array of block elements that style should be applied to.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
getAffectedBlocks(definition: BlockStyleDefinition, block: Element): Array<Element> | null;
|
|
68
|
+
/**
|
|
69
|
+
* Verifies if the given style is applicable to the provided document selection.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
isStyleEnabledForInlineSelection(definition: InlineStyleDefinition, selection: DocumentSelection): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Returns true if the given style is applied to the specified document selection.
|
|
76
|
+
*
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
isStyleActiveForInlineSelection(definition: InlineStyleDefinition, selection: DocumentSelection): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Returns a selectable that given style should be applied to.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
getAffectedInlineSelectable(definition: InlineStyleDefinition, selection: DocumentSelection): Selectable;
|
|
86
|
+
/**
|
|
87
|
+
* Returns the `TemplateDefinition` used by styles dropdown to render style preview.
|
|
88
|
+
*
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
getStylePreview(definition: StyleDefinition, children: Iterable<TemplateDefinition>): TemplateDefinition;
|
|
92
|
+
/**
|
|
93
|
+
* Verifies if all classes are present in the given GHS attribute.
|
|
94
|
+
*
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
hasAllClasses(ghsAttributeValue: unknown, classes: Array<string>): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* This is where the styles feature configures the GHS feature. This method translates normalized
|
|
100
|
+
* {@link module:style/styleconfig~StyleDefinition style definitions} to
|
|
101
|
+
* {@link module:engine/view/matcher~MatcherObjectPattern matcher patterns} and feeds them to the GHS
|
|
102
|
+
* {@link module:html-support/datafilter~DataFilter} plugin.
|
|
103
|
+
*
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
configureGHSDataFilter({ block, inline }: NormalizedStyleDefinitions): void;
|
|
107
|
+
/**
|
|
108
|
+
* Checks the attribute value of the first node in the selection that allows the attribute.
|
|
109
|
+
* For the collapsed selection, returns the selection attribute.
|
|
110
|
+
*
|
|
111
|
+
* @param selection The document selection.
|
|
112
|
+
* @param attributeName Name of the GHS attribute.
|
|
113
|
+
* @returns The attribute value.
|
|
114
|
+
*/
|
|
115
|
+
private _getValueFromFirstAllowedNode;
|
|
116
|
+
}
|
|
117
|
+
export interface NormalizedStyleDefinitions {
|
|
118
|
+
block: Array<BlockStyleDefinition>;
|
|
119
|
+
inline: Array<InlineStyleDefinition>;
|
|
120
|
+
}
|
|
121
|
+
export interface BlockStyleDefinition extends StyleDefinition {
|
|
122
|
+
isBlock: true;
|
|
123
|
+
modelElements: Array<string>;
|
|
124
|
+
previewTemplate: TemplateDefinition;
|
|
125
|
+
}
|
|
126
|
+
export interface InlineStyleDefinition extends StyleDefinition {
|
|
127
|
+
ghsAttributes: Array<string>;
|
|
128
|
+
previewTemplate: TemplateDefinition;
|
|
129
|
+
}
|
|
130
|
+
export type NormalizedStyleDefinition = BlockStyleDefinition | InlineStyleDefinition;
|
|
131
|
+
export type StyleUtilsIsEnabledForBlockEvent = DecoratedMethodEvent<StyleUtils, 'isStyleEnabledForBlock'>;
|
|
132
|
+
export type StyleUtilsIsActiveForBlockEvent = DecoratedMethodEvent<StyleUtils, 'isStyleActiveForBlock'>;
|
|
133
|
+
export type StyleUtilsGetAffectedBlocksEvent = DecoratedMethodEvent<StyleUtils, 'getAffectedBlocks'>;
|
|
134
|
+
export type StyleUtilsIsStyleEnabledForInlineSelectionEvent = DecoratedMethodEvent<StyleUtils, 'isStyleEnabledForInlineSelection'>;
|
|
135
|
+
export type StyleUtilsIsStyleActiveForInlineSelectionEvent = DecoratedMethodEvent<StyleUtils, 'isStyleActiveForInlineSelection'>;
|
|
136
|
+
export type StyleUtilsGetAffectedInlineSelectableEvent = DecoratedMethodEvent<StyleUtils, 'getAffectedInlineSelectable'>;
|
|
137
|
+
export type StyleUtilsGetStylePreviewEvent = DecoratedMethodEvent<StyleUtils, 'getStylePreview'>;
|
|
138
|
+
export type StyleUtilsConfigureGHSDataFilterEvent = DecoratedMethodEvent<StyleUtils, 'configureGHSDataFilter'>;
|