@ckeditor/ckeditor5-enter 36.0.0 → 37.0.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-enter",
3
- "version": "36.0.0",
3
+ "version": "37.0.0-alpha.0",
4
4
  "description": "Enter feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,17 +12,17 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "@ckeditor/ckeditor5-core": "^36.0.0",
16
- "@ckeditor/ckeditor5-engine": "^36.0.0"
15
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
16
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@ckeditor/ckeditor5-basic-styles": "^36.0.0",
20
- "@ckeditor/ckeditor5-editor-classic": "^36.0.0",
21
- "@ckeditor/ckeditor5-heading": "^36.0.0",
22
- "@ckeditor/ckeditor5-link": "^36.0.0",
23
- "@ckeditor/ckeditor5-paragraph": "^36.0.0",
24
- "@ckeditor/ckeditor5-typing": "^36.0.0",
25
- "@ckeditor/ckeditor5-undo": "^36.0.0",
19
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.0",
20
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
21
+ "@ckeditor/ckeditor5-heading": "^37.0.0-alpha.0",
22
+ "@ckeditor/ckeditor5-link": "^37.0.0-alpha.0",
23
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.0",
24
+ "@ckeditor/ckeditor5-typing": "^37.0.0-alpha.0",
25
+ "@ckeditor/ckeditor5-undo": "^37.0.0-alpha.0",
26
26
  "typescript": "^4.8.4",
27
27
  "webpack": "^5.58.1",
28
28
  "webpack-cli": "^4.9.0"
@@ -51,5 +51,6 @@
51
51
  "scripts": {
52
52
  "build": "tsc -p ./tsconfig.release.json",
53
53
  "postversion": "npm run build"
54
- }
54
+ },
55
+ "types": "src/index.d.ts"
55
56
  }
package/src/enter.d.ts ADDED
@@ -0,0 +1,27 @@
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 enter/enter
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ /**
10
+ * This plugin handles the <kbd>Enter</kbd> keystroke (hard line break) in the editor.
11
+ *
12
+ * See also the {@link module:enter/shiftenter~ShiftEnter} plugin.
13
+ *
14
+ * For more information about this feature see the {@glink api/enter package page}.
15
+ */
16
+ export default class Enter extends Plugin {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): 'Enter';
21
+ init(): void;
22
+ }
23
+ declare module '@ckeditor/ckeditor5-core' {
24
+ interface PluginsMap {
25
+ [Enter.pluginName]: Enter;
26
+ }
27
+ }
package/src/enter.js CHANGED
@@ -14,8 +14,6 @@ import EnterObserver from './enterobserver';
14
14
  * See also the {@link module:enter/shiftenter~ShiftEnter} plugin.
15
15
  *
16
16
  * For more information about this feature see the {@glink api/enter package page}.
17
- *
18
- * @extends module:core/plugin~Plugin
19
17
  */
20
18
  export default class Enter extends Plugin {
21
19
  /**
@@ -0,0 +1,57 @@
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 enter/entercommand
7
+ */
8
+ import { Command } from '@ckeditor/ckeditor5-core';
9
+ import type { Writer } from '@ckeditor/ckeditor5-engine';
10
+ /**
11
+ * Enter command used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> keystroke.
12
+ */
13
+ export default class EnterCommand extends Command {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ execute(): void;
18
+ /**
19
+ * Splits a block where the document selection is placed, in the way how the <kbd>Enter</kbd> key is expected to work:
20
+ *
21
+ * ```
22
+ * <p>Foo[]bar</p> -> <p>Foo</p><p>[]bar</p>
23
+ * <p>Foobar[]</p> -> <p>Foobar</p><p>[]</p>
24
+ * <p>Fo[ob]ar</p> -> <p>Fo</p><p>[]ar</p>
25
+ * ```
26
+ *
27
+ * In some cases, the split will not happen:
28
+ *
29
+ * ```
30
+ * // The selection parent is a limit element:
31
+ * <figcaption>A[bc]d</figcaption> -> <figcaption>A[]d</figcaption>
32
+ *
33
+ * // The selection spans over multiple elements:
34
+ * <h>x[x</h><p>y]y<p> -> <h>x</h><p>[]y</p>
35
+ * ```
36
+ *
37
+ * @param writer Writer to use when performing the enter action.
38
+ * @returns Boolean indicating if the block was split.
39
+ */
40
+ enterBlock(writer: Writer): boolean;
41
+ }
42
+ /**
43
+ * Fired after the the {@link module:enter/entercommand~EnterCommand} is finished executing.
44
+ *
45
+ * @eventName afterExecute
46
+ */
47
+ export type EnterCommandAfterExecuteEvent = {
48
+ name: 'afterExecute';
49
+ args: [{
50
+ writer: Writer;
51
+ }];
52
+ };
53
+ declare module '@ckeditor/ckeditor5-core' {
54
+ interface CommandsMap {
55
+ enter: EnterCommand;
56
+ }
57
+ }
@@ -8,9 +8,7 @@
8
8
  import { Command } from '@ckeditor/ckeditor5-core';
9
9
  import { getCopyOnEnterAttributes } from './utils';
10
10
  /**
11
- * Enter command. It is used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> keystroke.
12
- *
13
- * @extends module:core/command~Command
11
+ * Enter command used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> keystroke.
14
12
  */
15
13
  export default class EnterCommand extends Command {
16
14
  /**
@@ -25,20 +23,24 @@ export default class EnterCommand extends Command {
25
23
  /**
26
24
  * Splits a block where the document selection is placed, in the way how the <kbd>Enter</kbd> key is expected to work:
27
25
  *
28
- * <p>Foo[]bar</p> -> <p>Foo</p><p>[]bar</p>
29
- * <p>Foobar[]</p> -> <p>Foobar</p><p>[]</p>
30
- * <p>Fo[ob]ar</p> -> <p>Fo</p><p>[]ar</p>
26
+ * ```
27
+ * <p>Foo[]bar</p> -> <p>Foo</p><p>[]bar</p>
28
+ * <p>Foobar[]</p> -> <p>Foobar</p><p>[]</p>
29
+ * <p>Fo[ob]ar</p> -> <p>Fo</p><p>[]ar</p>
30
+ * ```
31
31
  *
32
32
  * In some cases, the split will not happen:
33
33
  *
34
- * // The selection parent is a limit element:
35
- * <figcaption>A[bc]d</figcaption> -> <figcaption>A[]d</figcaption>
34
+ * ```
35
+ * // The selection parent is a limit element:
36
+ * <figcaption>A[bc]d</figcaption> -> <figcaption>A[]d</figcaption>
36
37
  *
37
- * // The selection spans over multiple elements:
38
- * <h>x[x</h><p>y]y<p> -> <h>x</h><p>[]y</p>
38
+ * // The selection spans over multiple elements:
39
+ * <h>x[x</h><p>y]y<p> -> <h>x</h><p>[]y</p>
40
+ * ```
39
41
  *
40
42
  * @param writer Writer to use when performing the enter action.
41
- * @returns `true` if a block was split, `false` otherwise.
43
+ * @returns Boolean indicating if the block was split.
42
44
  */
43
45
  enterBlock(writer) {
44
46
  const model = this.editor.model;
@@ -0,0 +1,40 @@
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 enter/enterobserver
7
+ */
8
+ import { Observer, DomEventData, type View, type BubblingEvent } from '@ckeditor/ckeditor5-engine';
9
+ /**
10
+ * Enter observer introduces the {@link module:engine/view/document~Document#event:enter `Document#enter`} event.
11
+ */
12
+ export default class EnterObserver extends Observer {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ constructor(view: View);
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ observe(): void;
21
+ }
22
+ /**
23
+ * Fired when the user presses the <kbd>Enter</kbd> key.
24
+ *
25
+ * Note: This event is fired by the {@link module:enter/enterobserver~EnterObserver observer}
26
+ * (usually registered by the {@link module:enter/enter~Enter Enter feature} and
27
+ * {@link module:enter/shiftenter~ShiftEnter ShiftEnter feature}).
28
+ *
29
+ * @eventName enter
30
+ */
31
+ export type ViewDocumentEnterEvent = BubblingEvent<{
32
+ name: 'enter';
33
+ args: [EnterEventData];
34
+ }>;
35
+ export interface EnterEventData extends DomEventData<InputEvent> {
36
+ /**
37
+ * Whether it is a soft enter (<kbd>Shift</kbd>+<kbd>Enter</kbd>) or a hard enter (<kbd>Enter</kbd>).
38
+ */
39
+ isSoft: boolean;
40
+ }
@@ -12,8 +12,6 @@ const ENTER_EVENT_TYPES = {
12
12
  };
13
13
  /**
14
14
  * Enter observer introduces the {@link module:engine/view/document~Document#event:enter `Document#enter`} event.
15
- *
16
- * @extends module:engine/view/observer/observer~Observer
17
15
  */
18
16
  export default class EnterObserver extends Observer {
19
17
  /**
package/src/index.d.ts ADDED
@@ -0,0 +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 enter
7
+ */
8
+ export { default as Enter } from './enter';
9
+ export { default as ShiftEnter } from './shiftenter';
10
+ export type { ViewDocumentEnterEvent } from './enterobserver';
11
+ export type { default as EnterCommand } from './entercommand';
12
+ export type { default as ShiftEnterCommand } from './shiftentercommand';
@@ -0,0 +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 { Plugin } from '@ckeditor/ckeditor5-core';
6
+ /**
7
+ * This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor.
8
+ *
9
+ * See also the {@link module:enter/enter~Enter} plugin.
10
+ *
11
+ * For more information about this feature see the {@glink api/enter package page}.
12
+ */
13
+ export default class ShiftEnter extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): 'ShiftEnter';
18
+ init(): void;
19
+ }
20
+ declare module '@ckeditor/ckeditor5-core' {
21
+ interface PluginsMap {
22
+ [ShiftEnter.pluginName]: ShiftEnter;
23
+ }
24
+ }
package/src/shiftenter.js CHANGED
@@ -14,8 +14,6 @@ import { Plugin } from '@ckeditor/ckeditor5-core';
14
14
  * See also the {@link module:enter/enter~Enter} plugin.
15
15
  *
16
16
  * For more information about this feature see the {@glink api/enter package page}.
17
- *
18
- * @extends module:core/plugin~Plugin
19
17
  */
20
18
  export default class ShiftEnter extends Plugin {
21
19
  /**
@@ -0,0 +1,39 @@
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 enter/shiftentercommand
7
+ */
8
+ import { Command } from '@ckeditor/ckeditor5-core';
9
+ import type { Writer } from '@ckeditor/ckeditor5-engine';
10
+ /**
11
+ * ShiftEnter command. It is used by the {@link module:enter/shiftenter~ShiftEnter ShiftEnter feature} to handle
12
+ * the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke.
13
+ */
14
+ export default class ShiftEnterCommand extends Command {
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ execute(): void;
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ refresh(): void;
23
+ }
24
+ /**
25
+ * Fired after the the {@link module:enter/shiftentercommand~ShiftEnterCommand} is finished executing.
26
+ *
27
+ * @eventName afterExecute
28
+ */
29
+ export type ShiftEnterCommandAfterExecuteEvent = {
30
+ name: 'afterExecute';
31
+ args: [{
32
+ writer: Writer;
33
+ }];
34
+ };
35
+ declare module '@ckeditor/ckeditor5-core' {
36
+ interface CommandsMap {
37
+ shiftEnter: ShiftEnterCommand;
38
+ }
39
+ }
@@ -10,8 +10,6 @@ import { getCopyOnEnterAttributes } from './utils';
10
10
  /**
11
11
  * ShiftEnter command. It is used by the {@link module:enter/shiftenter~ShiftEnter ShiftEnter feature} to handle
12
12
  * the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke.
13
- *
14
- * @extends module:core/command~Command
15
13
  */
16
14
  export default class ShiftEnterCommand extends Command {
17
15
  /**
@@ -25,16 +23,18 @@ export default class ShiftEnterCommand extends Command {
25
23
  this.fire('afterExecute', { writer });
26
24
  });
27
25
  }
26
+ /**
27
+ * @inheritDoc
28
+ */
28
29
  refresh() {
29
30
  const model = this.editor.model;
30
31
  const doc = model.document;
31
32
  this.isEnabled = isEnabled(model.schema, doc.selection);
32
33
  }
33
34
  }
34
- // Checks whether the ShiftEnter command should be enabled in the specified selection.
35
- //
36
- // @param {module:engine/model/schema~Schema} schema
37
- // @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
35
+ /**
36
+ * Checks whether the ShiftEnter command should be enabled in the specified selection.
37
+ */
38
38
  function isEnabled(schema, selection) {
39
39
  // At this moment it is okay to support single range selections only.
40
40
  // But in the future we may need to change that.
@@ -55,12 +55,9 @@ function isEnabled(schema, selection) {
55
55
  }
56
56
  return true;
57
57
  }
58
- // Creates a break in the way that the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke is expected to work.
59
- //
60
- // @param {module:engine/model~Model} model
61
- // @param {module:engine/model/writer~Writer} writer
62
- // @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
63
- // Selection on which the action should be performed.
58
+ /**
59
+ * Creates a break in the way that the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke is expected to work.
60
+ */
64
61
  function softBreakAction(model, writer, selection) {
65
62
  const isSelectionEmpty = selection.isCollapsed;
66
63
  const range = selection.getFirstRange();
@@ -105,15 +102,13 @@ function insertBreak(model, writer, position) {
105
102
  model.insertContent(breakLineElement, position);
106
103
  writer.setSelection(breakLineElement, 'after');
107
104
  }
108
- // Checks whether the specified `element` is a child of the limit element.
109
- //
110
- // Checking whether the `<p>` element is inside a limit element:
111
- // - <$root><p>Text.</p></$root> => false
112
- // - <$root><limitElement><p>Text</p></limitElement></$root> => true
113
- //
114
- // @param {module:engine/model/element~Element} element
115
- // @param {module:engine/schema~Schema} schema
116
- // @returns {Boolean}
105
+ /**
106
+ * Checks whether the specified `element` is a child of the limit element.
107
+ *
108
+ * Checking whether the `<p>` element is inside a limit element:
109
+ * - `<$root><p>Text.</p></$root> => false`
110
+ * - `<$root><limitElement><p>Text</p></limitElement></$root> => true`
111
+ */
117
112
  function isInsideLimitElement(element, schema) {
118
113
  // `$root` is a limit element but in this case is an invalid element.
119
114
  if (element.is('rootElement')) {
package/src/utils.d.ts ADDED
@@ -0,0 +1,18 @@
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 enter/utils
7
+ */
8
+ import type { Schema } from '@ckeditor/ckeditor5-engine';
9
+ /**
10
+ * Returns attributes that should be preserved on the enter keystroke.
11
+ *
12
+ * Filtering is realized based on `copyOnEnter` attribute property. Read more about attribute properties
13
+ * {@link module:engine/model/schema~Schema#setAttributeProperties here}.
14
+ *
15
+ * @param schema Model's schema.
16
+ * @param allAttributes Attributes to filter.
17
+ */
18
+ export declare function getCopyOnEnterAttributes(schema: Schema, allAttributes: Iterable<[string, unknown]>): IterableIterator<[string, unknown]>;
package/src/utils.js CHANGED
@@ -8,9 +8,8 @@
8
8
  * Filtering is realized based on `copyOnEnter` attribute property. Read more about attribute properties
9
9
  * {@link module:engine/model/schema~Schema#setAttributeProperties here}.
10
10
  *
11
- * @param {module:engine/model/schema~Schema} schema
12
- * @param {Iterable.<*>} allAttributes attributes to filter.
13
- * @returns {Iterable.<*>}
11
+ * @param schema Model's schema.
12
+ * @param allAttributes Attributes to filter.
14
13
  */
15
14
  export function* getCopyOnEnterAttributes(schema, allAttributes) {
16
15
  for (const attribute of allAttributes) {