@ckeditor/ckeditor5-remove-format 39.0.1 → 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.
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/build/remove-format.js.map +1 -0
- package/lang/translations/af.po +1 -0
- package/lang/translations/ar.po +1 -0
- package/lang/translations/az.po +1 -0
- package/lang/translations/bg.po +1 -0
- package/lang/translations/bn.po +1 -0
- package/lang/translations/ca.po +1 -0
- package/lang/translations/cs.po +1 -0
- package/lang/translations/da.po +1 -0
- package/lang/translations/de-ch.po +1 -0
- package/lang/translations/de.po +1 -0
- package/lang/translations/el.po +1 -0
- package/lang/translations/en-au.po +1 -0
- package/lang/translations/en-gb.po +1 -0
- package/lang/translations/en.po +1 -0
- package/lang/translations/es.po +1 -0
- package/lang/translations/et.po +1 -0
- package/lang/translations/fa.po +1 -0
- package/lang/translations/fi.po +1 -0
- package/lang/translations/fr.po +1 -0
- package/lang/translations/gl.po +1 -0
- package/lang/translations/he.po +1 -0
- package/lang/translations/hi.po +1 -0
- package/lang/translations/hr.po +1 -0
- package/lang/translations/hu.po +1 -0
- package/lang/translations/id.po +1 -0
- package/lang/translations/it.po +1 -0
- package/lang/translations/ja.po +1 -0
- package/lang/translations/ko.po +1 -0
- package/lang/translations/ku.po +1 -0
- package/lang/translations/lt.po +1 -0
- package/lang/translations/lv.po +1 -0
- package/lang/translations/ms.po +1 -0
- package/lang/translations/ne.po +1 -0
- package/lang/translations/nl.po +1 -0
- package/lang/translations/no.po +1 -0
- package/lang/translations/pl.po +1 -0
- package/lang/translations/pt-br.po +1 -0
- package/lang/translations/pt.po +1 -0
- package/lang/translations/ro.po +1 -0
- package/lang/translations/ru.po +1 -0
- package/lang/translations/sk.po +1 -0
- package/lang/translations/sq.po +1 -0
- package/lang/translations/sr-latn.po +1 -0
- package/lang/translations/sr.po +1 -0
- package/lang/translations/sv.po +1 -0
- package/lang/translations/th.po +1 -0
- package/lang/translations/tk.po +1 -0
- package/lang/translations/tr.po +1 -0
- package/lang/translations/ug.po +1 -0
- package/lang/translations/uk.po +1 -0
- package/lang/translations/ur.po +1 -0
- package/lang/translations/uz.po +1 -0
- package/lang/translations/vi.po +1 -0
- package/lang/translations/zh-cn.po +1 -0
- package/lang/translations/zh.po +1 -0
- package/package.json +2 -6
- package/src/augmentation.d.ts +15 -15
- package/src/augmentation.js +5 -5
- package/src/index.d.ts +12 -12
- package/src/index.js +11 -11
- package/src/removeformat.d.ts +28 -28
- package/src/removeformat.js +32 -32
- package/src/removeformatcommand.d.ts +42 -42
- package/src/removeformatcommand.js +94 -94
- package/src/removeformatediting.d.ts +23 -23
- package/src/removeformatediting.js +29 -29
- package/src/removeformatui.d.ts +22 -22
- package/src/removeformatui.js +46 -46
package/src/augmentation.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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 type { RemoveFormat, RemoveFormatEditing, RemoveFormatUI, RemoveFormatCommand } from './index';
|
|
6
|
-
declare module '@ckeditor/ckeditor5-core' {
|
|
7
|
-
interface PluginsMap {
|
|
8
|
-
[RemoveFormat.pluginName]: RemoveFormat;
|
|
9
|
-
[RemoveFormatUI.pluginName]: RemoveFormatUI;
|
|
10
|
-
[RemoveFormatEditing.pluginName]: RemoveFormatEditing;
|
|
11
|
-
}
|
|
12
|
-
interface CommandsMap {
|
|
13
|
-
removeFormat: RemoveFormatCommand;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
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 type { RemoveFormat, RemoveFormatEditing, RemoveFormatUI, RemoveFormatCommand } from './index';
|
|
6
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
7
|
+
interface PluginsMap {
|
|
8
|
+
[RemoveFormat.pluginName]: RemoveFormat;
|
|
9
|
+
[RemoveFormatUI.pluginName]: RemoveFormatUI;
|
|
10
|
+
[RemoveFormatEditing.pluginName]: RemoveFormatEditing;
|
|
11
|
+
}
|
|
12
|
+
interface CommandsMap {
|
|
13
|
+
removeFormat: RemoveFormatCommand;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/augmentation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
|
-
export {};
|
|
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
|
+
export {};
|
package/src/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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 remove-format
|
|
7
|
-
*/
|
|
8
|
-
export { default as RemoveFormat } from './removeformat';
|
|
9
|
-
export { default as RemoveFormatEditing } from './removeformatediting';
|
|
10
|
-
export { default as RemoveFormatUI } from './removeformatui';
|
|
11
|
-
export type { default as RemoveFormatCommand } from './removeformatcommand';
|
|
12
|
-
import './augmentation';
|
|
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 remove-format
|
|
7
|
+
*/
|
|
8
|
+
export { default as RemoveFormat } from './removeformat';
|
|
9
|
+
export { default as RemoveFormatEditing } from './removeformatediting';
|
|
10
|
+
export { default as RemoveFormatUI } from './removeformatui';
|
|
11
|
+
export type { default as RemoveFormatCommand } from './removeformatcommand';
|
|
12
|
+
import './augmentation';
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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 remove-format
|
|
7
|
-
*/
|
|
8
|
-
export { default as RemoveFormat } from './removeformat';
|
|
9
|
-
export { default as RemoveFormatEditing } from './removeformatediting';
|
|
10
|
-
export { default as RemoveFormatUI } from './removeformatui';
|
|
11
|
-
import './augmentation';
|
|
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 remove-format
|
|
7
|
+
*/
|
|
8
|
+
export { default as RemoveFormat } from './removeformat';
|
|
9
|
+
export { default as RemoveFormatEditing } from './removeformatediting';
|
|
10
|
+
export { default as RemoveFormatUI } from './removeformatui';
|
|
11
|
+
import './augmentation';
|
package/src/removeformat.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
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 remove-format/removeformat
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import RemoveFormatUI from './removeformatui';
|
|
10
|
-
import RemoveFormatEditing from './removeformatediting';
|
|
11
|
-
/**
|
|
12
|
-
* The remove format plugin.
|
|
13
|
-
*
|
|
14
|
-
* This is a "glue" plugin which loads the {@link module:remove-format/removeformatediting~RemoveFormatEditing}
|
|
15
|
-
* and {@link module:remove-format/removeformatui~RemoveFormatUI} plugins.
|
|
16
|
-
*
|
|
17
|
-
* For a detailed overview, check out the {@glink features/remove-format remove format} feature documentation.
|
|
18
|
-
*/
|
|
19
|
-
export default class RemoveFormat extends Plugin {
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
static get requires(): readonly [typeof RemoveFormatEditing, typeof RemoveFormatUI];
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
static get pluginName(): "RemoveFormat";
|
|
28
|
-
}
|
|
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 remove-format/removeformat
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import RemoveFormatUI from './removeformatui';
|
|
10
|
+
import RemoveFormatEditing from './removeformatediting';
|
|
11
|
+
/**
|
|
12
|
+
* The remove format plugin.
|
|
13
|
+
*
|
|
14
|
+
* This is a "glue" plugin which loads the {@link module:remove-format/removeformatediting~RemoveFormatEditing}
|
|
15
|
+
* and {@link module:remove-format/removeformatui~RemoveFormatUI} plugins.
|
|
16
|
+
*
|
|
17
|
+
* For a detailed overview, check out the {@glink features/remove-format remove format} feature documentation.
|
|
18
|
+
*/
|
|
19
|
+
export default class RemoveFormat extends Plugin {
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
static get requires(): readonly [typeof RemoveFormatEditing, typeof RemoveFormatUI];
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get pluginName(): "RemoveFormat";
|
|
28
|
+
}
|
package/src/removeformat.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
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 remove-format/removeformat
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import RemoveFormatUI from './removeformatui';
|
|
10
|
-
import RemoveFormatEditing from './removeformatediting';
|
|
11
|
-
/**
|
|
12
|
-
* The remove format plugin.
|
|
13
|
-
*
|
|
14
|
-
* This is a "glue" plugin which loads the {@link module:remove-format/removeformatediting~RemoveFormatEditing}
|
|
15
|
-
* and {@link module:remove-format/removeformatui~RemoveFormatUI} plugins.
|
|
16
|
-
*
|
|
17
|
-
* For a detailed overview, check out the {@glink features/remove-format remove format} feature documentation.
|
|
18
|
-
*/
|
|
19
|
-
export default class RemoveFormat extends Plugin {
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
static get requires() {
|
|
24
|
-
return [RemoveFormatEditing, RemoveFormatUI];
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get pluginName() {
|
|
30
|
-
return 'RemoveFormat';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
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 remove-format/removeformat
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import RemoveFormatUI from './removeformatui';
|
|
10
|
+
import RemoveFormatEditing from './removeformatediting';
|
|
11
|
+
/**
|
|
12
|
+
* The remove format plugin.
|
|
13
|
+
*
|
|
14
|
+
* This is a "glue" plugin which loads the {@link module:remove-format/removeformatediting~RemoveFormatEditing}
|
|
15
|
+
* and {@link module:remove-format/removeformatui~RemoveFormatUI} plugins.
|
|
16
|
+
*
|
|
17
|
+
* For a detailed overview, check out the {@glink features/remove-format remove format} feature documentation.
|
|
18
|
+
*/
|
|
19
|
+
export default class RemoveFormat extends Plugin {
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
static get requires() {
|
|
24
|
+
return [RemoveFormatEditing, RemoveFormatUI];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
static get pluginName() {
|
|
30
|
+
return 'RemoveFormat';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
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 { Command } from 'ckeditor5/src/core';
|
|
6
|
-
/**
|
|
7
|
-
* The remove format command.
|
|
8
|
-
*
|
|
9
|
-
* It is used by the {@link module:remove-format/removeformat~RemoveFormat remove format feature}
|
|
10
|
-
* to clear the formatting in the selection.
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* editor.execute( 'removeFormat' );
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export default class RemoveFormatCommand extends Command {
|
|
17
|
-
value: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
refresh(): void;
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
execute(): void;
|
|
26
|
-
/**
|
|
27
|
-
* Returns an iterable of items in a selection (including the selection itself) that have formatting model
|
|
28
|
-
* attributes to be removed by the feature.
|
|
29
|
-
*
|
|
30
|
-
* @param schema The schema describing the item.
|
|
31
|
-
*/
|
|
32
|
-
private _getFormattingItems;
|
|
33
|
-
/**
|
|
34
|
-
* Returns an iterable of formatting attributes of a given model item.
|
|
35
|
-
*
|
|
36
|
-
* **Note:** Formatting items have the `isFormatting` property set to `true`.
|
|
37
|
-
*
|
|
38
|
-
* @param schema The schema describing the item.
|
|
39
|
-
* @returns The names of formatting attributes found in a given item.
|
|
40
|
-
*/
|
|
41
|
-
private _getFormattingAttributes;
|
|
42
|
-
}
|
|
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 { Command } from 'ckeditor5/src/core';
|
|
6
|
+
/**
|
|
7
|
+
* The remove format command.
|
|
8
|
+
*
|
|
9
|
+
* It is used by the {@link module:remove-format/removeformat~RemoveFormat remove format feature}
|
|
10
|
+
* to clear the formatting in the selection.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* editor.execute( 'removeFormat' );
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export default class RemoveFormatCommand extends Command {
|
|
17
|
+
value: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
refresh(): void;
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
execute(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Returns an iterable of items in a selection (including the selection itself) that have formatting model
|
|
28
|
+
* attributes to be removed by the feature.
|
|
29
|
+
*
|
|
30
|
+
* @param schema The schema describing the item.
|
|
31
|
+
*/
|
|
32
|
+
private _getFormattingItems;
|
|
33
|
+
/**
|
|
34
|
+
* Returns an iterable of formatting attributes of a given model item.
|
|
35
|
+
*
|
|
36
|
+
* **Note:** Formatting items have the `isFormatting` property set to `true`.
|
|
37
|
+
*
|
|
38
|
+
* @param schema The schema describing the item.
|
|
39
|
+
* @returns The names of formatting attributes found in a given item.
|
|
40
|
+
*/
|
|
41
|
+
private _getFormattingAttributes;
|
|
42
|
+
}
|
|
@@ -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
|
-
import { Command } from 'ckeditor5/src/core';
|
|
6
|
-
import { first } from 'ckeditor5/src/utils';
|
|
7
|
-
/**
|
|
8
|
-
* The remove format command.
|
|
9
|
-
*
|
|
10
|
-
* It is used by the {@link module:remove-format/removeformat~RemoveFormat remove format feature}
|
|
11
|
-
* to clear the formatting in the selection.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* editor.execute( 'removeFormat' );
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export default class RemoveFormatCommand extends Command {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
refresh() {
|
|
22
|
-
const model = this.editor.model;
|
|
23
|
-
this.isEnabled = !!first(this._getFormattingItems(model.document.selection, model.schema));
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @inheritDoc
|
|
27
|
-
*/
|
|
28
|
-
execute() {
|
|
29
|
-
const model = this.editor.model;
|
|
30
|
-
const schema = model.schema;
|
|
31
|
-
model.change(writer => {
|
|
32
|
-
for (const item of this._getFormattingItems(model.document.selection, schema)) {
|
|
33
|
-
if (item.is('selection')) {
|
|
34
|
-
for (const attributeName of this._getFormattingAttributes(item, schema)) {
|
|
35
|
-
writer.removeSelectionAttribute(attributeName);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// Workaround for items with multiple removable attributes. See
|
|
40
|
-
// https://github.com/ckeditor/ckeditor5-remove-format/pull/1#pullrequestreview-220515609
|
|
41
|
-
const itemRange = writer.createRangeOn(item);
|
|
42
|
-
for (const attributeName of this._getFormattingAttributes(item, schema)) {
|
|
43
|
-
writer.removeAttribute(attributeName, itemRange);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Returns an iterable of items in a selection (including the selection itself) that have formatting model
|
|
51
|
-
* attributes to be removed by the feature.
|
|
52
|
-
*
|
|
53
|
-
* @param schema The schema describing the item.
|
|
54
|
-
*/
|
|
55
|
-
*_getFormattingItems(selection, schema) {
|
|
56
|
-
const itemHasRemovableFormatting = (item) => {
|
|
57
|
-
return !!first(this._getFormattingAttributes(item, schema));
|
|
58
|
-
};
|
|
59
|
-
// Check formatting on selected items that are not blocks.
|
|
60
|
-
for (const curRange of selection.getRanges()) {
|
|
61
|
-
for (const item of curRange.getItems()) {
|
|
62
|
-
if (!schema.isBlock(item) && itemHasRemovableFormatting(item)) {
|
|
63
|
-
yield item;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// Check formatting from selected blocks.
|
|
68
|
-
for (const block of selection.getSelectedBlocks()) {
|
|
69
|
-
if (itemHasRemovableFormatting(block)) {
|
|
70
|
-
yield block;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Finally the selection might be formatted as well, so make sure to check it.
|
|
74
|
-
if (itemHasRemovableFormatting(selection)) {
|
|
75
|
-
yield selection;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Returns an iterable of formatting attributes of a given model item.
|
|
80
|
-
*
|
|
81
|
-
* **Note:** Formatting items have the `isFormatting` property set to `true`.
|
|
82
|
-
*
|
|
83
|
-
* @param schema The schema describing the item.
|
|
84
|
-
* @returns The names of formatting attributes found in a given item.
|
|
85
|
-
*/
|
|
86
|
-
*_getFormattingAttributes(item, schema) {
|
|
87
|
-
for (const [attributeName] of item.getAttributes()) {
|
|
88
|
-
const attributeProperties = schema.getAttributeProperties(attributeName);
|
|
89
|
-
if (attributeProperties && attributeProperties.isFormatting) {
|
|
90
|
-
yield attributeName;
|
|
91
|
-
}
|
|
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
|
+
import { Command } from 'ckeditor5/src/core';
|
|
6
|
+
import { first } from 'ckeditor5/src/utils';
|
|
7
|
+
/**
|
|
8
|
+
* The remove format command.
|
|
9
|
+
*
|
|
10
|
+
* It is used by the {@link module:remove-format/removeformat~RemoveFormat remove format feature}
|
|
11
|
+
* to clear the formatting in the selection.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* editor.execute( 'removeFormat' );
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export default class RemoveFormatCommand extends Command {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
refresh() {
|
|
22
|
+
const model = this.editor.model;
|
|
23
|
+
this.isEnabled = !!first(this._getFormattingItems(model.document.selection, model.schema));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
execute() {
|
|
29
|
+
const model = this.editor.model;
|
|
30
|
+
const schema = model.schema;
|
|
31
|
+
model.change(writer => {
|
|
32
|
+
for (const item of this._getFormattingItems(model.document.selection, schema)) {
|
|
33
|
+
if (item.is('selection')) {
|
|
34
|
+
for (const attributeName of this._getFormattingAttributes(item, schema)) {
|
|
35
|
+
writer.removeSelectionAttribute(attributeName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Workaround for items with multiple removable attributes. See
|
|
40
|
+
// https://github.com/ckeditor/ckeditor5-remove-format/pull/1#pullrequestreview-220515609
|
|
41
|
+
const itemRange = writer.createRangeOn(item);
|
|
42
|
+
for (const attributeName of this._getFormattingAttributes(item, schema)) {
|
|
43
|
+
writer.removeAttribute(attributeName, itemRange);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns an iterable of items in a selection (including the selection itself) that have formatting model
|
|
51
|
+
* attributes to be removed by the feature.
|
|
52
|
+
*
|
|
53
|
+
* @param schema The schema describing the item.
|
|
54
|
+
*/
|
|
55
|
+
*_getFormattingItems(selection, schema) {
|
|
56
|
+
const itemHasRemovableFormatting = (item) => {
|
|
57
|
+
return !!first(this._getFormattingAttributes(item, schema));
|
|
58
|
+
};
|
|
59
|
+
// Check formatting on selected items that are not blocks.
|
|
60
|
+
for (const curRange of selection.getRanges()) {
|
|
61
|
+
for (const item of curRange.getItems()) {
|
|
62
|
+
if (!schema.isBlock(item) && itemHasRemovableFormatting(item)) {
|
|
63
|
+
yield item;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Check formatting from selected blocks.
|
|
68
|
+
for (const block of selection.getSelectedBlocks()) {
|
|
69
|
+
if (itemHasRemovableFormatting(block)) {
|
|
70
|
+
yield block;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Finally the selection might be formatted as well, so make sure to check it.
|
|
74
|
+
if (itemHasRemovableFormatting(selection)) {
|
|
75
|
+
yield selection;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns an iterable of formatting attributes of a given model item.
|
|
80
|
+
*
|
|
81
|
+
* **Note:** Formatting items have the `isFormatting` property set to `true`.
|
|
82
|
+
*
|
|
83
|
+
* @param schema The schema describing the item.
|
|
84
|
+
* @returns The names of formatting attributes found in a given item.
|
|
85
|
+
*/
|
|
86
|
+
*_getFormattingAttributes(item, schema) {
|
|
87
|
+
for (const [attributeName] of item.getAttributes()) {
|
|
88
|
+
const attributeProperties = schema.getAttributeProperties(attributeName);
|
|
89
|
+
if (attributeProperties && attributeProperties.isFormatting) {
|
|
90
|
+
yield attributeName;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
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 remove-format/removeformatediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
/**
|
|
10
|
-
* The remove format editing plugin.
|
|
11
|
-
*
|
|
12
|
-
* It registers the {@link module:remove-format/removeformatcommand~RemoveFormatCommand removeFormat} command.
|
|
13
|
-
*/
|
|
14
|
-
export default class RemoveFormatEditing extends Plugin {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
static get pluginName(): "RemoveFormatEditing";
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
init(): void;
|
|
23
|
-
}
|
|
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 remove-format/removeformatediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The remove format editing plugin.
|
|
11
|
+
*
|
|
12
|
+
* It registers the {@link module:remove-format/removeformatcommand~RemoveFormatCommand removeFormat} command.
|
|
13
|
+
*/
|
|
14
|
+
export default class RemoveFormatEditing extends Plugin {
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
static get pluginName(): "RemoveFormatEditing";
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
init(): void;
|
|
23
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
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 remove-format/removeformatediting
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import RemoveFormatCommand from './removeformatcommand';
|
|
10
|
-
/**
|
|
11
|
-
* The remove format editing plugin.
|
|
12
|
-
*
|
|
13
|
-
* It registers the {@link module:remove-format/removeformatcommand~RemoveFormatCommand removeFormat} command.
|
|
14
|
-
*/
|
|
15
|
-
export default class RemoveFormatEditing extends Plugin {
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
static get pluginName() {
|
|
20
|
-
return 'RemoveFormatEditing';
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
init() {
|
|
26
|
-
const editor = this.editor;
|
|
27
|
-
editor.commands.add('removeFormat', new RemoveFormatCommand(editor));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
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 remove-format/removeformatediting
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import RemoveFormatCommand from './removeformatcommand';
|
|
10
|
+
/**
|
|
11
|
+
* The remove format editing plugin.
|
|
12
|
+
*
|
|
13
|
+
* It registers the {@link module:remove-format/removeformatcommand~RemoveFormatCommand removeFormat} command.
|
|
14
|
+
*/
|
|
15
|
+
export default class RemoveFormatEditing extends Plugin {
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get pluginName() {
|
|
20
|
+
return 'RemoveFormatEditing';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
init() {
|
|
26
|
+
const editor = this.editor;
|
|
27
|
+
editor.commands.add('removeFormat', new RemoveFormatCommand(editor));
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/removeformatui.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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 remove-format/removeformatui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
/**
|
|
10
|
-
* The remove format UI plugin. It registers the `'removeFormat'` button which can be
|
|
11
|
-
* used in the toolbar.
|
|
12
|
-
*/
|
|
13
|
-
export default class RemoveFormatUI extends Plugin {
|
|
14
|
-
/**
|
|
15
|
-
* @inheritDoc
|
|
16
|
-
*/
|
|
17
|
-
static get pluginName(): "RemoveFormatUI";
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
init(): void;
|
|
22
|
-
}
|
|
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 remove-format/removeformatui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The remove format UI plugin. It registers the `'removeFormat'` button which can be
|
|
11
|
+
* used in the toolbar.
|
|
12
|
+
*/
|
|
13
|
+
export default class RemoveFormatUI extends Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
static get pluginName(): "RemoveFormatUI";
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
init(): void;
|
|
22
|
+
}
|