@ckeditor/ckeditor5-html-embed 40.0.0 → 40.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor&nbsp;5 HTML embed feature** – https://github.com/ckeditor/ckeditor5-html-embed <br>
5
- Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
5
+ Copyright (c) 20032023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
14
14
  Trademarks
15
15
  ----------
16
16
 
17
- **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
17
+ **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-html-embed",
3
- "version": "40.0.0",
3
+ "version": "40.1.0",
4
4
  "description": "HTML embed feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "40.0.0"
15
+ "ckeditor5": "40.1.0"
16
16
  },
17
17
  "author": "CKSource (http://cksource.com/)",
18
18
  "license": "GPL-2.0-or-later",
@@ -1,24 +1,24 @@
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 { HtmlEmbed, HtmlEmbedCommand, HtmlEmbedConfig, HtmlEmbedEditing, HtmlEmbedUI } from './index';
6
- declare module '@ckeditor/ckeditor5-core' {
7
- interface EditorConfig {
8
- /**
9
- * The configuration of the HTML embed feature. Introduced by the {@link module:html-embed/htmlembedediting~HtmlEmbedEditing}
10
- * feature.
11
- *
12
- * Read more in {@link module:core/editor/editorconfig~EditorConfig all editor options}.
13
- */
14
- htmlEmbed?: HtmlEmbedConfig;
15
- }
16
- interface PluginsMap {
17
- [HtmlEmbed.pluginName]: HtmlEmbed;
18
- [HtmlEmbedEditing.pluginName]: HtmlEmbedEditing;
19
- [HtmlEmbedUI.pluginName]: HtmlEmbedUI;
20
- }
21
- interface CommandsMap {
22
- htmlEmbed: HtmlEmbedCommand;
23
- }
24
- }
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 { HtmlEmbed, HtmlEmbedCommand, HtmlEmbedConfig, HtmlEmbedEditing, HtmlEmbedUI } from './index';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface EditorConfig {
8
+ /**
9
+ * The configuration of the HTML embed feature. Introduced by the {@link module:html-embed/htmlembedediting~HtmlEmbedEditing}
10
+ * feature.
11
+ *
12
+ * Read more in {@link module:core/editor/editorconfig~EditorConfig all editor options}.
13
+ */
14
+ htmlEmbed?: HtmlEmbedConfig;
15
+ }
16
+ interface PluginsMap {
17
+ [HtmlEmbed.pluginName]: HtmlEmbed;
18
+ [HtmlEmbedEditing.pluginName]: HtmlEmbedEditing;
19
+ [HtmlEmbedUI.pluginName]: HtmlEmbedUI;
20
+ }
21
+ interface CommandsMap {
22
+ htmlEmbed: HtmlEmbedCommand;
23
+ }
24
+ }
@@ -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 {};
@@ -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 html-embed/htmlembed
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { Widget } from 'ckeditor5/src/widget';
10
- import HtmlEmbedEditing from './htmlembedediting';
11
- import HtmlEmbedUI from './htmlembedui';
12
- /**
13
- * The HTML embed feature.
14
- *
15
- * It allows inserting HTML snippets directly into the editor.
16
- *
17
- * For a detailed overview, check the {@glink features/html/html-embed HTML embed feature} documentation.
18
- */
19
- export default class HtmlEmbed extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get requires(): readonly [typeof HtmlEmbedEditing, typeof HtmlEmbedUI, typeof Widget];
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName(): "HtmlEmbed";
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 html-embed/htmlembed
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { Widget } from 'ckeditor5/src/widget';
10
+ import HtmlEmbedEditing from './htmlembedediting';
11
+ import HtmlEmbedUI from './htmlembedui';
12
+ /**
13
+ * The HTML embed feature.
14
+ *
15
+ * It allows inserting HTML snippets directly into the editor.
16
+ *
17
+ * For a detailed overview, check the {@glink features/html/html-embed HTML embed feature} documentation.
18
+ */
19
+ export default class HtmlEmbed extends Plugin {
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get requires(): readonly [typeof HtmlEmbedEditing, typeof HtmlEmbedUI, typeof Widget];
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName(): "HtmlEmbed";
28
+ }
package/src/htmlembed.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 html-embed/htmlembed
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { Widget } from 'ckeditor5/src/widget';
10
- import HtmlEmbedEditing from './htmlembedediting';
11
- import HtmlEmbedUI from './htmlembedui';
12
- /**
13
- * The HTML embed feature.
14
- *
15
- * It allows inserting HTML snippets directly into the editor.
16
- *
17
- * For a detailed overview, check the {@glink features/html/html-embed HTML embed feature} documentation.
18
- */
19
- export default class HtmlEmbed extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get requires() {
24
- return [HtmlEmbedEditing, HtmlEmbedUI, Widget];
25
- }
26
- /**
27
- * @inheritDoc
28
- */
29
- static get pluginName() {
30
- return 'HtmlEmbed';
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 html-embed/htmlembed
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { Widget } from 'ckeditor5/src/widget';
10
+ import HtmlEmbedEditing from './htmlembedediting';
11
+ import HtmlEmbedUI from './htmlembedui';
12
+ /**
13
+ * The HTML embed feature.
14
+ *
15
+ * It allows inserting HTML snippets directly into the editor.
16
+ *
17
+ * For a detailed overview, check the {@glink features/html/html-embed HTML embed feature} documentation.
18
+ */
19
+ export default class HtmlEmbed extends Plugin {
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get requires() {
24
+ return [HtmlEmbedEditing, HtmlEmbedUI, Widget];
25
+ }
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get pluginName() {
30
+ return 'HtmlEmbed';
31
+ }
32
+ }
@@ -1,44 +1,44 @@
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 insert HTML embed element command.
8
- *
9
- * The command is registered by {@link module:html-embed/htmlembedediting~HtmlEmbedEditing} as `'htmlEmbed'`.
10
- *
11
- * To insert an empty HTML embed element at the current selection, execute the command:
12
- *
13
- * ```ts
14
- * editor.execute( 'htmlEmbed' );
15
- * ```
16
- *
17
- * You can specify the initial content of a new HTML embed in the argument:
18
- *
19
- * ```ts
20
- * editor.execute( 'htmlEmbed', '<b>Initial content.</b>' );
21
- * ```
22
- *
23
- * To update the content of the HTML embed, select it in the model and pass the content in the argument:
24
- *
25
- * ```ts
26
- * editor.execute( 'htmlEmbed', '<b>New content of an existing embed.</b>' );
27
- * ```
28
- */
29
- export default class HtmlEmbedCommand extends Command {
30
- /**
31
- * @inheritDoc
32
- */
33
- refresh(): void;
34
- /**
35
- * Executes the command, which either:
36
- *
37
- * * creates and inserts a new HTML embed element if none was selected,
38
- * * updates the content of the HTML embed if one was selected.
39
- *
40
- * @fires execute
41
- * @param value When passed, the value (content) will be set on a new embed or a selected one.
42
- */
43
- execute(value?: string): void;
44
- }
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 insert HTML embed element command.
8
+ *
9
+ * The command is registered by {@link module:html-embed/htmlembedediting~HtmlEmbedEditing} as `'htmlEmbed'`.
10
+ *
11
+ * To insert an empty HTML embed element at the current selection, execute the command:
12
+ *
13
+ * ```ts
14
+ * editor.execute( 'htmlEmbed' );
15
+ * ```
16
+ *
17
+ * You can specify the initial content of a new HTML embed in the argument:
18
+ *
19
+ * ```ts
20
+ * editor.execute( 'htmlEmbed', '<b>Initial content.</b>' );
21
+ * ```
22
+ *
23
+ * To update the content of the HTML embed, select it in the model and pass the content in the argument:
24
+ *
25
+ * ```ts
26
+ * editor.execute( 'htmlEmbed', '<b>New content of an existing embed.</b>' );
27
+ * ```
28
+ */
29
+ export default class HtmlEmbedCommand extends Command {
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ refresh(): void;
34
+ /**
35
+ * Executes the command, which either:
36
+ *
37
+ * * creates and inserts a new HTML embed element if none was selected,
38
+ * * updates the content of the HTML embed if one was selected.
39
+ *
40
+ * @fires execute
41
+ * @param value When passed, the value (content) will be set on a new embed or a selected one.
42
+ */
43
+ execute(value?: string): void;
44
+ }
@@ -1,95 +1,95 @@
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 { findOptimalInsertionRange } from 'ckeditor5/src/widget';
7
- /**
8
- * The insert HTML embed element command.
9
- *
10
- * The command is registered by {@link module:html-embed/htmlembedediting~HtmlEmbedEditing} as `'htmlEmbed'`.
11
- *
12
- * To insert an empty HTML embed element at the current selection, execute the command:
13
- *
14
- * ```ts
15
- * editor.execute( 'htmlEmbed' );
16
- * ```
17
- *
18
- * You can specify the initial content of a new HTML embed in the argument:
19
- *
20
- * ```ts
21
- * editor.execute( 'htmlEmbed', '<b>Initial content.</b>' );
22
- * ```
23
- *
24
- * To update the content of the HTML embed, select it in the model and pass the content in the argument:
25
- *
26
- * ```ts
27
- * editor.execute( 'htmlEmbed', '<b>New content of an existing embed.</b>' );
28
- * ```
29
- */
30
- export default class HtmlEmbedCommand extends Command {
31
- /**
32
- * @inheritDoc
33
- */
34
- refresh() {
35
- const model = this.editor.model;
36
- const schema = model.schema;
37
- const selection = model.document.selection;
38
- const selectedRawHtmlElement = getSelectedRawHtmlModelWidget(selection);
39
- this.isEnabled = isHtmlEmbedAllowedInParent(selection, schema, model);
40
- this.value = selectedRawHtmlElement ? selectedRawHtmlElement.getAttribute('value') || '' : null;
41
- }
42
- /**
43
- * Executes the command, which either:
44
- *
45
- * * creates and inserts a new HTML embed element if none was selected,
46
- * * updates the content of the HTML embed if one was selected.
47
- *
48
- * @fires execute
49
- * @param value When passed, the value (content) will be set on a new embed or a selected one.
50
- */
51
- execute(value) {
52
- const model = this.editor.model;
53
- const selection = model.document.selection;
54
- model.change(writer => {
55
- let htmlEmbedElement;
56
- // If the command has a non-null value, there must be some HTML embed selected in the model.
57
- if (this.value !== null) {
58
- htmlEmbedElement = getSelectedRawHtmlModelWidget(selection);
59
- }
60
- else {
61
- htmlEmbedElement = writer.createElement('rawHtml');
62
- model.insertObject(htmlEmbedElement, null, null, { setSelection: 'on' });
63
- }
64
- writer.setAttribute('value', value, htmlEmbedElement);
65
- });
66
- }
67
- }
68
- /**
69
- * Checks if an HTML embed is allowed by the schema in the optimal insertion parent.
70
- */
71
- function isHtmlEmbedAllowedInParent(selection, schema, model) {
72
- const parent = getInsertHtmlEmbedParent(selection, model);
73
- return schema.checkChild(parent, 'rawHtml');
74
- }
75
- /**
76
- * Returns a node that will be used to insert a html embed with `model.insertContent` to check if a html embed element can be placed there.
77
- */
78
- function getInsertHtmlEmbedParent(selection, model) {
79
- const insertionRange = findOptimalInsertionRange(selection, model);
80
- const parent = insertionRange.start.parent;
81
- if (parent.isEmpty && !parent.is('rootElement')) {
82
- return parent.parent;
83
- }
84
- return parent;
85
- }
86
- /**
87
- * Returns the selected HTML embed element in the model, if any.
88
- */
89
- function getSelectedRawHtmlModelWidget(selection) {
90
- const selectedElement = selection.getSelectedElement();
91
- if (selectedElement && selectedElement.is('element', 'rawHtml')) {
92
- return selectedElement;
93
- }
94
- return null;
95
- }
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 { findOptimalInsertionRange } from 'ckeditor5/src/widget';
7
+ /**
8
+ * The insert HTML embed element command.
9
+ *
10
+ * The command is registered by {@link module:html-embed/htmlembedediting~HtmlEmbedEditing} as `'htmlEmbed'`.
11
+ *
12
+ * To insert an empty HTML embed element at the current selection, execute the command:
13
+ *
14
+ * ```ts
15
+ * editor.execute( 'htmlEmbed' );
16
+ * ```
17
+ *
18
+ * You can specify the initial content of a new HTML embed in the argument:
19
+ *
20
+ * ```ts
21
+ * editor.execute( 'htmlEmbed', '<b>Initial content.</b>' );
22
+ * ```
23
+ *
24
+ * To update the content of the HTML embed, select it in the model and pass the content in the argument:
25
+ *
26
+ * ```ts
27
+ * editor.execute( 'htmlEmbed', '<b>New content of an existing embed.</b>' );
28
+ * ```
29
+ */
30
+ export default class HtmlEmbedCommand extends Command {
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ refresh() {
35
+ const model = this.editor.model;
36
+ const schema = model.schema;
37
+ const selection = model.document.selection;
38
+ const selectedRawHtmlElement = getSelectedRawHtmlModelWidget(selection);
39
+ this.isEnabled = isHtmlEmbedAllowedInParent(selection, schema, model);
40
+ this.value = selectedRawHtmlElement ? selectedRawHtmlElement.getAttribute('value') || '' : null;
41
+ }
42
+ /**
43
+ * Executes the command, which either:
44
+ *
45
+ * * creates and inserts a new HTML embed element if none was selected,
46
+ * * updates the content of the HTML embed if one was selected.
47
+ *
48
+ * @fires execute
49
+ * @param value When passed, the value (content) will be set on a new embed or a selected one.
50
+ */
51
+ execute(value) {
52
+ const model = this.editor.model;
53
+ const selection = model.document.selection;
54
+ model.change(writer => {
55
+ let htmlEmbedElement;
56
+ // If the command has a non-null value, there must be some HTML embed selected in the model.
57
+ if (this.value !== null) {
58
+ htmlEmbedElement = getSelectedRawHtmlModelWidget(selection);
59
+ }
60
+ else {
61
+ htmlEmbedElement = writer.createElement('rawHtml');
62
+ model.insertObject(htmlEmbedElement, null, null, { setSelection: 'on' });
63
+ }
64
+ writer.setAttribute('value', value, htmlEmbedElement);
65
+ });
66
+ }
67
+ }
68
+ /**
69
+ * Checks if an HTML embed is allowed by the schema in the optimal insertion parent.
70
+ */
71
+ function isHtmlEmbedAllowedInParent(selection, schema, model) {
72
+ const parent = getInsertHtmlEmbedParent(selection, model);
73
+ return schema.checkChild(parent, 'rawHtml');
74
+ }
75
+ /**
76
+ * Returns a node that will be used to insert a html embed with `model.insertContent` to check if a html embed element can be placed there.
77
+ */
78
+ function getInsertHtmlEmbedParent(selection, model) {
79
+ const insertionRange = findOptimalInsertionRange(selection, model);
80
+ const parent = insertionRange.start.parent;
81
+ if (parent.isEmpty && !parent.is('rootElement')) {
82
+ return parent.parent;
83
+ }
84
+ return parent;
85
+ }
86
+ /**
87
+ * Returns the selected HTML embed element in the model, if any.
88
+ */
89
+ function getSelectedRawHtmlModelWidget(selection) {
90
+ const selectedElement = selection.getSelectedElement();
91
+ if (selectedElement && selectedElement.is('element', 'rawHtml')) {
92
+ return selectedElement;
93
+ }
94
+ return null;
95
+ }