-
Notifications
You must be signed in to change notification settings - Fork 100
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 #514 from ckeditor/ck/513
Feature: Add an onChangeInitializedEditors callback to CKEditorContext to allow tracking of newly initialized editors within the JSX React tree. Closes #513
- Loading branch information
Showing
11 changed files
with
417 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import type { Config, EditorConfig } from 'ckeditor5'; | ||
|
||
/** | ||
* The symbol cannot be used as a key because config getters require strings as keys. | ||
*/ | ||
const ReactContextMetadataKey = '$__CKEditorReactContextMetadata'; | ||
|
||
/** | ||
* Sets the metadata in the object. | ||
* | ||
* @param metadata The metadata to set. | ||
* @param object The object to set the metadata in. | ||
* @returns The object with the metadata set. | ||
*/ | ||
export function withCKEditorReactContextMetadata( | ||
metadata: CKEditorConfigContextMetadata, | ||
config: EditorConfig | ||
): EditorConfig & { [ ReactContextMetadataKey ]: CKEditorConfigContextMetadata } { | ||
return { | ||
...config, | ||
[ ReactContextMetadataKey ]: metadata | ||
}; | ||
} | ||
|
||
/** | ||
* Tries to extract the metadata from the object. | ||
* | ||
* @param object The object to extract the metadata from. | ||
*/ | ||
export function tryExtractCKEditorReactContextMetadata( object: Config<any> ): CKEditorConfigContextMetadata | null { | ||
return object.get( ReactContextMetadataKey ); | ||
} | ||
|
||
/** | ||
* The metadata that is stored in the React context. | ||
*/ | ||
export type CKEditorConfigContextMetadata = { | ||
|
||
/** | ||
* The name of the editor in the React context. It'll be later used in the `useInitializedCKEditorsMap` hook | ||
* to track the editor initialization and destruction events. | ||
*/ | ||
name?: string; | ||
|
||
/** | ||
* Any additional metadata that can be stored in the context. | ||
*/ | ||
[x: string | number | symbol]: unknown; | ||
}; |
Oops, something went wrong.