-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13409 from ckeditor/ck/13029-move-restricted-edit…
…ing-plugin-to-typescript Other (restricted-editing): Rewrite 'ckeditor5-restricted-editing' to TypeScript. Closes #13029.
- Loading branch information
Showing
36 changed files
with
1,524 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module restricted-editing | ||
*/ | ||
|
||
export { default as RestrictedEditingMode } from './restrictededitingmode'; | ||
export { default as RestrictedEditingModeEditing } from './restrictededitingmodeediting'; | ||
export { default as RestrictedEditingModeUI } from './restrictededitingmodeui'; | ||
export { default as StandardEditingMode } from './standardeditingmode'; | ||
export { default as StandardEditingModeEditing } from './standardeditingmodeediting'; | ||
export { default as StandardEditingModeUI } from './standardeditingmodeui'; |
77 changes: 77 additions & 0 deletions
77
packages/ckeditor5-restricted-editing/src/restrictededitingconfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module restricted-editing/restrictededitingconfig | ||
*/ | ||
|
||
/** | ||
* The configuration of the restricted editing mode feature. | ||
* The option is used by the {@link module:restricted-editing/restrictededitingmode~RestrictedEditingMode} feature. | ||
* | ||
* ```ts | ||
* ClassicEditor | ||
* .create( { | ||
* restrictedEditing: { | ||
* allowedCommands: [ 'bold', 'link', 'unlink' ], | ||
* allowedAttributes: [ 'bold', 'linkHref' ] | ||
* } | ||
* } ) | ||
* .then( ... ) | ||
* .catch( ... ); | ||
* ``` | ||
* | ||
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}. | ||
*/ | ||
export interface RestrictedEditingConfig { | ||
|
||
/** | ||
* The command names allowed in non-restricted areas of the content. | ||
* | ||
* Defines which feature commands should be enabled in the restricted editing mode. The commands used for typing and deleting text | ||
* (`'input'`, `'delete'` and `'deleteForward'`) are allowed by the feature inside non-restricted regions and do not need to be defined. | ||
* | ||
* **Note**: The restricted editing mode always allows to use the restricted mode navigation commands as well as `'undo'` and `'redo'` | ||
* commands. | ||
* | ||
* The default value is: | ||
* | ||
* ```ts | ||
* const restrictedEditingConfig = { | ||
* allowedCommands: [ 'bold', 'italic', 'link', 'unlink' ] | ||
* }; | ||
* ``` | ||
* | ||
* To make a command always enabled (also outside non-restricted areas) use | ||
* {@link module:restricted-editing/restrictededitingconfig~RestrictedEditingModeEditing#enableCommand} method. | ||
*/ | ||
allowedCommands: Array<string>; | ||
|
||
/** | ||
* The text attribute names allowed when pasting content ot non-restricted areas. | ||
* | ||
* The default value is: | ||
* | ||
* ```ts | ||
* const restrictedEditingConfig = { | ||
* allowedAttributes: [ 'bold', 'italic', 'linkHref' ] | ||
* }; | ||
* ``` | ||
*/ | ||
allowedAttributes: Array<string>; | ||
} | ||
|
||
declare module '@ckeditor/ckeditor5-core' { | ||
|
||
/** | ||
* The configuration of the restricted editing mode feature. Introduced by the | ||
* {@link module:restricted-editing/restrictededitingmode~RestrictedEditingMode} feature. | ||
* | ||
* Read more in {@link module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig}. | ||
*/ | ||
interface EditorConfig { | ||
restrictedEditing?: RestrictedEditingConfig; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
packages/ckeditor5-restricted-editing/src/restrictededitingexceptioncommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module restricted-editing/restrictededitingexceptioncommand | ||
*/ | ||
|
||
import { Command } from 'ckeditor5/src/core'; | ||
import type { TreeWalkerValue } from 'ckeditor5/src/engine'; | ||
|
||
/** | ||
* The command that toggles exceptions from the restricted editing on text. | ||
*/ | ||
export default class RestrictedEditingExceptionCommand extends Command { | ||
/** | ||
* A flag indicating whether the command is active | ||
* | ||
* @readonly | ||
*/ | ||
declare public value: boolean; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public override refresh(): void { | ||
const model = this.editor.model; | ||
const doc = model.document; | ||
|
||
this.value = !!doc.selection.getAttribute( 'restrictedEditingException' ); | ||
|
||
this.isEnabled = model.schema.checkAttributeInSelection( doc.selection, 'restrictedEditingException' ); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public override execute( options: RestrictedEditingExceptionCommandParams = {} ): void { | ||
const model = this.editor.model; | ||
const document = model.document; | ||
const selection = document.selection; | ||
const valueToSet = ( options.forceValue === undefined ) ? !this.value : options.forceValue; | ||
|
||
model.change( writer => { | ||
const ranges = model.schema.getValidRanges( selection.getRanges(), 'restrictedEditingException' ); | ||
|
||
if ( selection.isCollapsed ) { | ||
if ( valueToSet ) { | ||
writer.setSelectionAttribute( 'restrictedEditingException', valueToSet ); | ||
} else { | ||
const isSameException = ( value: TreeWalkerValue ) => { | ||
return value.item.getAttribute( 'restrictedEditingException' ) === this.value; | ||
}; | ||
|
||
const focus = selection.focus!; | ||
const exceptionStart = focus.getLastMatchingPosition( isSameException, { direction: 'backward' } ); | ||
const exceptionEnd = focus.getLastMatchingPosition( isSameException ); | ||
|
||
writer.removeSelectionAttribute( 'restrictedEditingException' ); | ||
|
||
if ( !( focus.isEqual( exceptionStart ) || focus.isEqual( exceptionEnd ) ) ) { | ||
writer.removeAttribute( 'restrictedEditingException', writer.createRange( exceptionStart, exceptionEnd ) ); | ||
} | ||
} | ||
} else { | ||
for ( const range of ranges ) { | ||
if ( valueToSet ) { | ||
writer.setAttribute( 'restrictedEditingException', valueToSet, range ); | ||
} else { | ||
writer.removeAttribute( 'restrictedEditingException', range ); | ||
} | ||
} | ||
} | ||
} ); | ||
} | ||
} | ||
|
||
export interface RestrictedEditingExceptionCommandParams { | ||
forceValue?: unknown; | ||
} | ||
|
||
declare module '@ckeditor/ckeditor5-core' { | ||
interface CommandsMap { | ||
restrictedEditingException: RestrictedEditingExceptionCommand; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/ckeditor5-restricted-editing/src/restrictededitingmode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module restricted-editing/restrictededitingmode | ||
*/ | ||
|
||
import { Plugin, type PluginDependencies } from 'ckeditor5/src/core'; | ||
|
||
import RestrictedEditingModeEditing from './restrictededitingmodeediting'; | ||
import RestrictedEditingModeUI from './restrictededitingmodeui'; | ||
|
||
import '../theme/restrictedediting.css'; | ||
|
||
/** | ||
* The restricted editing mode plugin. | ||
* | ||
* This is a "glue" plugin which loads the following plugins: | ||
* | ||
* * The {@link module:restricted-editing/restrictededitingmodeediting~RestrictedEditingModeEditing restricted mode editing feature}. | ||
* * The {@link module:restricted-editing/restrictededitingmodeui~RestrictedEditingModeUI restricted mode UI feature}. | ||
*/ | ||
export default class RestrictedEditingMode extends Plugin { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public static get pluginName(): 'RestrictedEditingMode' { | ||
return 'RestrictedEditingMode'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static get requires(): PluginDependencies { | ||
return [ RestrictedEditingModeEditing, RestrictedEditingModeUI ]; | ||
} | ||
} | ||
|
||
declare module '@ckeditor/ckeditor5-core' { | ||
interface PluginsMap { | ||
[ RestrictedEditingMode.pluginName ]: RestrictedEditingMode; | ||
} | ||
} |
Oops, something went wrong.