react-code-dataset / react-page /docs /examples /slate-plugin-src /pluginFactories /createSimpleHtmlBlockPlugin.tsx
Download react-page/docs/examples/slate-plugin-src/pluginFactories/createSimpleHtmlBlockPlugin.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-page/docs/examples/slate-plugin-src/pluginFactories/createSimpleHtmlBlockPlugin.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-page/docs/examples/slate-plugin-src/pluginFactories/createSimpleHtmlBlockPlugin.tsx
-
curl -L -o createSimpleHtmlBlockPlugin.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-page/docs/examples/slate-plugin-src/pluginFactories/createSimpleHtmlBlockPlugin.tsx
1.7 kB
| /* eslint-disable @typescript-eslint/ban-types */ | |
| import { getAlignmentFromElement } from '../plugins/paragraphs'; | |
| import type { SlateComponentPluginDefinition } from '../types/slatePluginDefinitions'; | |
| import createComponentPlugin from './createComponentPlugin'; | |
| type Def<T extends Record<string, unknown>> = Pick< | |
| SlateComponentPluginDefinition<HtmlBlockData<T>>, | |
| | 'type' | |
| | 'icon' | |
| | 'label' | |
| | 'customAdd' | |
| | 'customRemove' | |
| | 'isDisabled' | |
| | 'hotKey' | |
| | 'onKeyDown' | |
| | 'getInitialData' | |
| | 'controls' | |
| | 'getStyle' | |
| > & { | |
| replaceWithDefaultOnRemove?: boolean; | |
| tagName: keyof JSX.IntrinsicElements; | |
| getData?: (el: HTMLElement) => T | void; | |
| noButton?: boolean; | |
| }; | |
| export type DefaultBlockDataType = { | |
| align: 'left' | 'right' | 'center' | 'justify'; | |
| }; | |
| export type HtmlBlockData<T> = T & DefaultBlockDataType; | |
| function createSimpleHtmlBlockPlugin<T = {}>(def: Def<HtmlBlockData<T>>) { | |
| return createComponentPlugin<HtmlBlockData<T>>({ | |
| type: def.type, | |
| object: 'block', | |
| hotKey: def.hotKey, | |
| replaceWithDefaultOnRemove: def.replaceWithDefaultOnRemove, | |
| icon: def.icon, | |
| label: def.label, | |
| onKeyDown: def.onKeyDown, | |
| addToolbarButton: !def.noButton, | |
| customAdd: def.customAdd, | |
| customRemove: def.customRemove, | |
| controls: def.controls, | |
| addHoverButton: false, | |
| deserialize: { | |
| tagName: def.tagName, | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| getData: def.getData || (getAlignmentFromElement as any), | |
| }, | |
| getStyle: (data) => ({ | |
| textAlign: data.align, | |
| ...(def.getStyle?.(data) ?? {}), | |
| }), | |
| Component: def.tagName, | |
| }); | |
| } | |
| export default createSimpleHtmlBlockPlugin; | |