Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed May 11, 2022
1 parent 7b2e7a7 commit 0844c6e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/docs/getting-started/basic-editor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Let's set the initial value of the editor to one block of text.
// Stored in VALUES.plainText
const initialValue = [
{
type: 'p',
children: [
{
text:
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/getting-started/basic-plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following undeclared variables and types are imported from `@udecode/plate`.
This guide will use existing plugins.

If you don't provide any plugins to `Plate` as done in the previous section,
`createReactPlugin()`, `createHistoryPlugin()` and other core plugins will be used as default.
`createTReactPlugin()`, `createTHistoryPlugin()` and other core plugins will be used as default.

### Plugins

Expand Down
22 changes: 11 additions & 11 deletions docs/docs/guides/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const createSubscriptPlugin = createPluginFactory<ToggleMarkPlugin>({
```ts
// Example
const createReactPlugin = {
withOverrides: withReact
withOverrides: withTReact
};
```

Expand Down Expand Up @@ -255,7 +255,7 @@ type PlatePluginInsertDataOptions = {
dataTransfer: DataTransfer;
};

type PlatePluginInsertData = {
type PlatePluginInsertData<V extends Value> = {
/**
* Format to get data. Example data types are text/plain and text/uri-list.
*/
Expand All @@ -271,7 +271,7 @@ type PlatePluginInsertData = {
*/
getFragment?: (
options: PlatePluginInsertDataOptions
) => TDescendant[] | undefined;
) => EDescendant<V>[] | undefined;

// injected

Expand All @@ -282,7 +282,7 @@ type PlatePluginInsertData = {
* @return if true, the next handlers will be skipped.
*/
preInsert?: (
fragment: TDescendant[],
fragment: EDescendant<V>[],
options: PlatePluginInsertDataOptions
) => HandlerReturnType;

Expand All @@ -298,9 +298,9 @@ type PlatePluginInsertData = {
* Transform the fragment to insert.
*/
transformFragment?: (
fragment: TDescendant[],
fragment: EDescendant<V>[],
options: PlatePluginInsertDataOptions
) => TDescendant[];
) => EDescendant<V>[];
}
```
Expand Down Expand Up @@ -402,19 +402,19 @@ type Handler<P = {}, V extends Value, E extends PlateEditor<V> = PlateEditor<V>>
* Transform the className.
* @default clsx(className, classNames[value])
*/
transformClassName?: (options: TransformOptions) => any;
transformClassName?: (options: TransformOptions<V>) => any;

/**
* Transform the node value for the style or className.
* @default nodeValue
*/
transformNodeValue?: (options: TransformOptions) => any;
transformNodeValue?: (options: TransformOptions<V>) => any;

/**
* Transform the style.
* @default { ...style, [styleKey]: value }
*/
transformStyle?: (options: TransformOptions) => CSSProperties;
transformStyle?: (options: TransformOptions<V>) => CSSProperties;

/**
* List of supported node values.
Expand Down Expand Up @@ -509,9 +509,9 @@ createIndentPlugin({
- Type is:
```tsx
(
editor: PlateEditor<V>,
editor: E,
plugin: WithPlatePlugin<P, V, E>
) => Partial<PlatePlugin<P, V, E>>
) => Partial<PlatePlugin<P, V, E>> | void;
```

### `type`
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/plugins/PlatePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type PlatePlugin<
* Properties used by the `insertData` core plugin to deserialize inserted data to a slate fragment.
* The fragment will be inserted to the editor if not empty.
*/
insertData?: PlatePluginInsertData;
insertData?: PlatePluginInsertData<V>;
}>;

/**
Expand Down
13 changes: 7 additions & 6 deletions packages/core/src/types/plugins/PlatePluginInsertData.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { TDescendant } from '../../slate/node/TDescendant';
import { Value } from '../../slate/editor/TEditor';
import { EDescendant } from '../../slate/node/TDescendant';
import { HandlerReturnType } from './DOMHandlers';

export type PlatePluginInsertDataOptions = {
data: string;
dataTransfer: DataTransfer;
};

export type PlatePluginInsertData = {
export type PlatePluginInsertData<V extends Value> = {
/**
* Format to get data. Example data types are text/plain and text/uri-list.
*/
Expand All @@ -22,7 +23,7 @@ export type PlatePluginInsertData = {
*/
getFragment?: (
options: PlatePluginInsertDataOptions
) => TDescendant[] | undefined;
) => EDescendant<V>[] | undefined;

// injected

Expand All @@ -33,7 +34,7 @@ export type PlatePluginInsertData = {
* @return if true, the next handlers will be skipped.
*/
preInsert?: (
fragment: TDescendant[],
fragment: EDescendant<V>[],
options: PlatePluginInsertDataOptions
) => HandlerReturnType;

Expand All @@ -49,7 +50,7 @@ export type PlatePluginInsertData = {
* Transform the fragment to insert.
*/
transformFragment?: (
fragment: TDescendant[],
fragment: EDescendant<V>[],
options: PlatePluginInsertDataOptions
) => TDescendant[];
) => EDescendant<V>[];
};
4 changes: 2 additions & 2 deletions packages/core/src/utils/pipeTransformFragment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Value } from '../slate/editor/TEditor';
import { TDescendant } from '../slate/node/TDescendant';
import { EDescendant } from '../slate/node/TDescendant';
import { PlateEditor } from '../types/PlateEditor';
import { PlatePluginInsertDataOptions } from '../types/plugins/PlatePluginInsertData';
import { InjectedPlugin } from './getInjectedPlugins';
Expand All @@ -15,7 +15,7 @@ export const pipeTransformFragment = <
{
fragment,
...options
}: PlatePluginInsertDataOptions & { fragment: TDescendant[] }
}: PlatePluginInsertDataOptions & { fragment: EDescendant<V>[] }
) => {
plugins.forEach((p) => {
const transformFragment = p.editor?.insertData?.transformFragment;
Expand Down

0 comments on commit 0844c6e

Please sign in to comment.