-
Notifications
You must be signed in to change notification settings - Fork 105
Add support for paragraph like editor. #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mati365
wants to merge
21
commits into
master
Choose a base branch
from
ck/9933
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d015796
Add support for paragraph like editor.
Mati365 18f7019
Fix failing tests.
Mati365 3e95729
Add support for passing `tagName` into `CKEditor` component.
Mati365 5a116cc
Add changelog and tests for `tagName` property.
Mati365 6f1faca
Add `addRoot` / `removeRoot` methods for `useMultiRootEditor`
Mati365 b4b76aa
Adjust creator.
Mati365 b6ddb11
Adjust handler.
Mati365 8601a13
Add testing.
Mati365 1d0761d
Add `EditorElement` component.
Mati365 ec4224f
Make it work.
Mati365 5452422
Add changelogs.
Mati365 f90e6e6
Re-export type
Mati365 fa99632
Rename type.
Mati365 090a64b
Fix edge case for classic editor.
Mati365 173064c
Fix `waitFor` behavior for editors rerenders
Mati365 83cb33b
Adjust handler.
Mati365 44483a6
Move element definition normalize to separate file.
Mati365 03e020e
Fix imports
Mati365 d40ebf9
Better syntax.
Mati365 cd4c032
CR fixes
Mati365 1298079
Add commnet.
Mati365 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
| --- | ||
| type: Feature | ||
| --- | ||
|
|
||
| The `useMultiRootEditor` hook now returns `addRoot` and `removeRoot` helpers directly. Previously, adding or removing a root required manually manipulating the `data` and `attributes` state outside the hook. You can now call them directly: | ||
|
|
||
| ```js | ||
| const { addRoot, removeRoot } = useMultiRootEditor( props ); | ||
|
|
||
| await addRoot({ | ||
| name: 'my-root', | ||
| data: '<p>Hello</p>', | ||
| attributes: { order: 10 }, | ||
| editableOptions: { | ||
| element: 'section', | ||
| placeholder: 'Start typing...', | ||
| label: 'My section' | ||
| } | ||
| }); | ||
|
|
||
| await removeRoot( 'my-root' ); | ||
| ``` |
This file contains hidden or 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,5 @@ | ||
| --- | ||
| type: Feature | ||
| --- | ||
|
|
||
| The `<CKEditor>` component now supports paragraph-like editor configurations. When `config.root.element` (or `config.roots.main.element`) is provided, you can customize the tag name, CSS classes and inline styles of the editable element instead of relying on the default plain `<div>`. |
This file contains hidden or 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,5 @@ | ||
| --- | ||
| type: Feature | ||
| --- | ||
|
|
||
| Each editable root in the multi-root editor can now be configured independently with its own HTML element type, placeholder text and accessible label. Pass an `editableOptions` object to `addRoot` to control the `element` (e.g. `'section'`, `'article'`), `placeholder` and assistive-technology `label` for that specific root. |
This file contains hidden or 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 hidden or 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-2026, CKSource Holding sp. z o.o. All rights reserved. | ||
| * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options | ||
| */ | ||
|
|
||
| import React, { forwardRef, memo } from 'react'; | ||
| import { normalizeClassList } from './utils/normalizeClassList.js'; | ||
| import { | ||
| type EditorElementDefinition, | ||
| normalizeEditorElementDefinition | ||
| } from './utils/normalizeEditorElementDefinition.js'; | ||
|
|
||
| /** | ||
| * Creates and renders a dynamic React element based on the element definition owned and provided by the editor. | ||
| * | ||
| * @param props The component properties. | ||
| */ | ||
| export const EditorElement = memo( forwardRef<HTMLElement, Props>( ( { definition }, ref ) => { | ||
| const { id, name: Tag, classes, styles, attributes } = normalizeEditorElementDefinition( definition ?? { | ||
| name: 'div' | ||
| } ); | ||
|
|
||
| return ( | ||
| <Tag | ||
| ref={ref} | ||
| {...attributes} | ||
| id={id} | ||
| className={normalizeClassList( classes )} | ||
| style={styles} | ||
| /> | ||
| ); | ||
| } ) ); | ||
|
|
||
| EditorElement.displayName = 'EditorElement'; | ||
|
|
||
| /** | ||
| * Properties for the {@link EditorElement} component. | ||
| */ | ||
| type Props = { | ||
|
|
||
| /** | ||
| * The definition of the element to be rendered. Defaults to a `div` element if not provided or null. | ||
| */ | ||
| definition?: EditorElementDefinition | null; | ||
| }; | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -36,9 +36,13 @@ import { | |
| assignElementToEditorConfig, | ||
| compareInstalledCKBaseVersion, | ||
| getInstalledCKBaseFeatures, | ||
| type EditorRelaxedConstructor | ||
| type EditorRelaxedConstructor, | ||
| type EditorRelaxedConfig | ||
| } from '@ckeditor/ckeditor5-integrations-common'; | ||
|
|
||
| import { EditorElement } from './EditorElement.js'; | ||
| import type { EditorElementDefinition } from './utils/normalizeEditorElementDefinition.js'; | ||
|
|
||
| const REACT_INTEGRATION_READ_ONLY_LOCK_ID = 'Lock from React integration (@ckeditor/ckeditor5-react)'; | ||
|
|
||
| export default class CKEditor<TEditor extends Editor> extends React.Component<Props<TEditor>> { | ||
|
|
@@ -209,8 +213,14 @@ export default class CKEditor<TEditor extends Editor> extends React.Component<Pr | |
| * Render a <div> element which will be replaced by CKEditor. | ||
| */ | ||
| public override render(): React.ReactNode { | ||
| const { editor: Editor, config = {} } = this.props; | ||
| const definition = getEditorElementDefinition( Editor, config ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit worried about type safety here. In case of typo or passing a number, there won't be a proper error. We could narrow the type or reject more invalid shapes during normalization.
Mati365 marked this conversation as resolved.
|
||
|
|
||
| return ( | ||
| <div ref={ this.domContainer }></div> | ||
| <EditorElement | ||
| ref={ this.domContainer } | ||
| definition={definition} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -412,6 +422,17 @@ export default class CKEditor<TEditor extends Editor> extends React.Component<Pr | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get definition of the element used to create editor. | ||
| */ | ||
| function getEditorElementDefinition( editor: EditorRelaxedConstructor, config: EditorRelaxedConfig ): EditorElementDefinition { | ||
| if ( !editor.editorName || editor.editorName === 'ClassicEditor' ) { | ||
| return 'div'; | ||
| } | ||
|
|
||
| return config.roots?.main?.element ?? config.root?.element ?? 'div'; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true when the editor should be updated. | ||
| * | ||
|
|
@@ -466,7 +487,7 @@ export interface Props<TEditor extends Editor> { | |
| disableWatchdog?: boolean; | ||
| onReady?: ( editor: TEditor ) => void; | ||
| onAfterDestroy?: ( editor: TEditor ) => void; | ||
| onError?: ( error: Error, details: ErrorDetails ) => void; | ||
| onError?: ( error: Error, details: EditorErrorDetails ) => void; | ||
| onChange?: ( event: EventInfo, editor: TEditor ) => void; | ||
| onFocus?: ( event: EventInfo, editor: TEditor ) => void; | ||
| onBlur?: ( event: EventInfo, editor: TEditor ) => void; | ||
|
|
@@ -475,7 +496,10 @@ export interface Props<TEditor extends Editor> { | |
| id?: any; | ||
| } | ||
|
|
||
| interface ErrorDetails { | ||
| /** | ||
| * Error thrown by editor watchdog. | ||
| */ | ||
| export type EditorErrorDetails = { | ||
| phase: 'initialization' | 'runtime'; | ||
| willEditorRestart?: boolean; | ||
| } | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.