-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BlockquoteExtension and withEvents plugins to Plate
- Loading branch information
Showing
27 changed files
with
210 additions
and
199 deletions.
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
packages/slate-editor/src/extensions/blockquote/BlockquoteExtension.tsx
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
packages/slate-editor/src/extensions/blockquote/components/BlockQuoteElement.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
packages/slate-editor/src/extensions/blockquote/lib/parseBlockquoteElement.ts
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import { isElement, type SlateEditor, type TElement } from '@udecode/plate-common'; | ||
import type { PlateRenderElementProps } from '@udecode/plate-common/react'; | ||
|
||
export function extendElementAttributes( | ||
editor: SlateEditor, | ||
element: TElement, | ||
attributes: PlateRenderElementProps['attributes'], | ||
) { | ||
return { | ||
'data-slate-block': detectBlockType(editor, element), | ||
'data-slate-type': element.type, | ||
'data-slate-value': JSON.stringify(element), | ||
...attributes, | ||
}; | ||
} | ||
|
||
function detectBlockType(editor: SlateEditor, element: TElement): string | undefined { | ||
if (!isElement(element) || editor.isInline(element)) { | ||
return undefined; | ||
} | ||
return editor.isRichBlock(element) ? 'rich' : 'regular'; | ||
} |
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
21 changes: 21 additions & 0 deletions
21
packages/slate-editor/src/modules/editor/getEnabledPlugins.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,21 @@ | ||
import type { Events } from '@prezly/events'; | ||
import type { PlatePlugin } from '@udecode/plate-common/react'; | ||
|
||
import { EventsPlugin, type EditorEventMap } from '#modules/events'; | ||
import { BlockquotePlugin } from '#plugins/blockquote'; | ||
|
||
import type { EditorProps } from './types'; | ||
|
||
type Parameters = { | ||
events: Events<EditorEventMap>; | ||
} & Pick<Required<EditorProps>, 'withBlockquotes'>; | ||
|
||
export function* getEnabledPlugins(parameters: Parameters): Generator<PlatePlugin> { | ||
const { events, withBlockquotes } = parameters; | ||
|
||
yield EventsPlugin(events); | ||
|
||
if (withBlockquotes) { | ||
yield BlockquotePlugin; | ||
} | ||
} |
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
Oops, something went wrong.