Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 committed Dec 5, 2024
1 parent 2a06713 commit 4f31bcb
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 79 deletions.
2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/heading-element.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"files": [
{
"content": "'use client';\n\nimport React from 'react';\n\nimport { withRef, withVariants } from '@udecode/cn';\nimport { cva } from 'class-variance-authority';\n\nimport { PlateElement } from './plate-element';\n\nexport const headingVariants = cva('relative mb-1', {\n variants: {\n variant: {\n h1: 'mt-[1.6em] pb-1 font-heading text-4xl font-bold',\n h2: 'mt-[1.4em] pb-px font-heading text-2xl font-semibold tracking-tight',\n h3: 'mt-[1em] pb-px font-heading text-xl font-semibold tracking-tight',\n h4: 'mt-[0.75em] font-heading text-lg font-semibold tracking-tight',\n h5: 'mt-[0.75em] text-lg font-semibold tracking-tight',\n h6: 'mt-[0.75em] text-base font-semibold tracking-tight',\n },\n },\n});\n\nconst HeadingElementVariants = withVariants(PlateElement, headingVariants, [\n 'variant',\n]);\n\nexport const HeadingElement = withRef<typeof HeadingElementVariants>(\n ({ children, variant = 'h1', ...props }, ref) => {\n return (\n <HeadingElementVariants\n ref={ref}\n as={variant!}\n variant={variant}\n {...props}\n >\n {children}\n </HeadingElementVariants>\n );\n }\n);\n",
"content": "'use client';\n\nimport React from 'react';\n\nimport { withRef, withVariants } from '@udecode/cn';\n\nimport { headingVariants } from '../plate-static-ui/heading-element';\nimport { PlateElement } from './plate-element';\n\nconst HeadingElementVariants = withVariants(PlateElement, headingVariants, [\n 'variant',\n]);\n\nexport const HeadingElement = withRef<typeof HeadingElementVariants>(\n ({ children, variant = 'h1', ...props }, ref) => {\n return (\n <HeadingElementVariants\n ref={ref}\n as={variant!}\n variant={variant}\n {...props}\n >\n {children}\n </HeadingElementVariants>\n );\n }\n);\n",
"path": "plate-ui/heading-element.tsx",
"target": "components/plate-ui/heading-element.tsx",
"type": "registry:ui"
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/lib/static/components/DefaultStaticElement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

import type { RenderElementProps } from 'slate-react/dist/components/editable';

export function DefaultStaticElement({
attributes,
children,
}: RenderElementProps) {
return <div {...attributes}>{children}</div>;
}
7 changes: 7 additions & 0 deletions packages/core/src/lib/static/components/DefaultStaticLeaf.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

import type { RenderLeafProps } from 'slate-react/dist/components/editable';

export function DefaultStaticLeaf({ attributes, children }: RenderLeafProps) {
return <span {...attributes}>{children}</span>;
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import React from 'react';

import type {
EditableProps,
RenderElementProps,
RenderLeafProps,
} from 'slate-react/dist/components/editable';

import {
type TDescendant,
type TElement,
type TText,
isElement,
} from '@udecode/slate';

import type { SlateEditor } from '..';
import type { SlateEditor } from '../../editor';
import type { RenderStaticElement, RenderStaticLeaf } from '../type';

import { pipeRenderStaticElement } from './pipeRenderStaticElement';
import { pipeRenderStaticLeaf } from './pipeRenderStaticLeaf';
import { pipeRenderStaticElement } from '../pipeRenderStaticElement';
import { pipeRenderStaticLeaf } from '../pipeRenderStaticLeaf';
import { createStaticString } from '../utils/createStaticString';

export type ChildrenProps = {
children: TDescendant[];
Expand All @@ -35,8 +31,8 @@ export type LeafProps = {

export type PlateViewProps = {
editor: SlateEditor;
renderElement?: EditableProps['renderElement'];
renderLeaf?: EditableProps['renderLeaf'];
renderElement?: RenderStaticElement;
renderLeaf?: RenderStaticLeaf;
};

function Element({
Expand All @@ -48,7 +44,7 @@ function Element({
return (
<React.Fragment>
{renderElement?.({
attributes: { 'data-slate-node': 'element' } as any,
attributes: { 'data-slate-node': 'element', ref: null },
children: (
<PlateViewContent editor={editor}>
{element.children}
Expand All @@ -64,7 +60,7 @@ function Leaf({ editor, leaf = { text: '' } }: LeafProps) {
const renderLeaf = pipeRenderStaticLeaf(editor);

return renderLeaf!({
attributes: { 'data-slate-leaf': true } as any,
attributes: { 'data-slate-leaf': true },
children: createStaticString({ text: leaf.text }),
leaf,
text: leaf,
Expand All @@ -90,22 +86,3 @@ export function PlateStatic(props: PlateViewProps) {

return <PlateViewContent editor={editor}>{editor.children}</PlateViewContent>;
}

export function DefaultStaticElement({
attributes,
children,
}: RenderElementProps) {
return <div {...attributes}>{children}</div>;
}

export function DefaultStaticLeaf({ attributes, children }: RenderLeafProps) {
return <span {...attributes}>{children}</span>;
}

export function createStaticString({ text }: { text: string }) {
return React.createElement(
'span',
{ 'data-slate-string': true },
text === '' ? '\uFEFF' : text
);
}
7 changes: 7 additions & 0 deletions packages/core/src/lib/static/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @file Automatically generated by barrelsby.
*/

export * from './DefaultStaticElement';
export * from './DefaultStaticLeaf';
export * from './PlateStatic';
4 changes: 3 additions & 1 deletion packages/core/src/lib/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @file Automatically generated by barrelsby.
*/

export * from './PlateStatic';
export * from './pipeRenderStaticElement';
export * from './pipeRenderStaticLeaf';
export * from './type';
export * from './components/index';
export * from './utils/index';
26 changes: 7 additions & 19 deletions packages/core/src/lib/static/pipeRenderStaticElement.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
import React from 'react';

import type { TElement } from '@udecode/slate';
import type { TEditableProps, TRenderElementProps } from '@udecode/slate-react';

import type { SlateEditor } from '../editor';
import type { SlatePlugin } from '../plugin';
import type { RenderStaticElement } from './type';

import { DefaultStaticElement } from './PlateStatic';

export type RenderElement = (
props: TRenderElementProps
) => React.ReactElement | undefined;

export interface StaticElementProps<T extends TElement = TElement> {
attributes?: Record<string, any>;
children?: React.ReactNode;
element?: T;
}
import { DefaultStaticElement } from './components/DefaultStaticElement';

const pluginRenderStaticElement = (
editor: SlateEditor,
_: SlateEditor,
plugin: SlatePlugin
): RenderElement =>
): RenderStaticElement =>
function render(nodeProps) {
if (nodeProps.element.type === plugin.node.type) {
const { children, element } = nodeProps;
Expand All @@ -46,9 +34,9 @@ const pluginRenderStaticElement = (
/** @see {@link RenderElement} */
export const pipeRenderStaticElement = (
editor: SlateEditor,
renderElementProp?: TEditableProps['renderElement']
): TEditableProps['renderElement'] => {
const renderElements: RenderElement[] = [];
renderElementProp?: RenderStaticElement
): RenderStaticElement => {
const renderElements: RenderStaticElement[] = [];

editor.pluginList.forEach((plugin) => {
if (plugin.node.isElement) {
Expand Down
27 changes: 7 additions & 20 deletions packages/core/src/lib/static/pipeRenderStaticLeaf.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import React from 'react';

import type { TText } from '@udecode/slate';
import type { TEditableProps, TRenderLeafProps } from '@udecode/slate-react';

import type { SlateEditor } from '../editor';
import type { SlatePlugin } from '../plugin';
import type { RenderStaticLeaf } from './type';

import { DefaultStaticLeaf } from './PlateStatic';

export type RenderLeaf = (
props: TRenderLeafProps
) => React.ReactElement | undefined;

export interface StaticLeafProps<T extends TText = TText> {
as?: React.ElementType;
attributes?: Record<string, any>;
children?: React.ReactNode;
leaf?: T;
}
import { DefaultStaticLeaf } from './components/DefaultStaticLeaf';

export const pluginRenderStaticLeaf = (
editor: SlateEditor,
_: SlateEditor,
plugin: SlatePlugin
): RenderLeaf =>
): RenderStaticLeaf =>
function render(nodeProps) {
const {
node: { staticComponent },
Expand All @@ -45,9 +32,9 @@ export const pluginRenderStaticLeaf = (
/** @see {@link RenderLeaf} */
export const pipeRenderStaticLeaf = (
editor: SlateEditor,
renderLeafProp?: TEditableProps['renderLeaf']
): TEditableProps['renderLeaf'] => {
const renderLeafs: RenderLeaf[] = [];
renderLeafProp?: RenderStaticLeaf
): RenderStaticLeaf => {
const renderLeafs: RenderStaticLeaf[] = [];

editor.pluginList.forEach((plugin) => {
if (plugin.node.isLeaf && plugin.key) {
Expand Down
43 changes: 43 additions & 0 deletions packages/core/src/lib/static/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { TElement, TText } from '@udecode/slate';

export interface TRenderStaticElementProps<T extends TElement = TElement> {
attributes: {
'data-slate-node': 'element';
ref: any;
'data-slate-inline'?: true;
'data-slate-void'?: true;
dir?: 'rtl';
};
children: any;
element: T;
}

export type RenderStaticElement<T extends TElement = TElement> = (
props: TRenderStaticElementProps<T>
) => React.ReactElement | undefined;

export interface StaticElementProps<T extends TElement = TElement> {
attributes?: Record<string, any>;
children?: React.ReactNode;
element?: T;
}

export interface TRenderStaticLeafProps<N extends TText = TText> {
attributes: {
'data-slate-leaf': true;
};
children: any;
leaf: N;
text: N;
}

export type RenderStaticLeaf<N extends TText = TText> = (
props: TRenderStaticLeafProps<N>
) => React.ReactElement | undefined;

export interface StaticLeafProps<N extends TText = TText> {
as?: React.ElementType;
attributes?: Record<string, any>;
children?: React.ReactNode;
leaf?: N;
}
9 changes: 9 additions & 0 deletions packages/core/src/lib/static/utils/createStaticString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

export function createStaticString({ text }: { text: string }) {
return React.createElement(
'span',
{ 'data-slate-string': true },
text === '' ? '\uFEFF' : text
);
}
5 changes: 5 additions & 0 deletions packages/core/src/lib/static/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* @file Automatically generated by barrelsby.
*/

export * from './createStaticString';
4 changes: 1 addition & 3 deletions packages/html/src/lib/staticElementToHtml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { TRenderElementProps } from '@udecode/plate-common/react';

import {
type SlateEditor,
type SlatePlugin,
Expand All @@ -15,7 +13,7 @@ export const staticElementToHtml = (
props,
}: {
ReactDOMServer: any;
props: TRenderElementProps;
props: any;
preserveClassNames?: string[];
}
): string => {
Expand Down
4 changes: 1 addition & 3 deletions packages/html/src/lib/staticLeafToHtml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { TRenderLeafProps } from '@udecode/plate-common/react';

import {
type SlateEditor,
type SlatePlugin,
Expand All @@ -11,7 +9,7 @@ import { renderComponentToHtml } from './utils/renderComponentToHtml';

export const staticLeafToHtml = (
editor: SlateEditor,
{ ReactDOMServer, props }: { ReactDOMServer: any; props: TRenderLeafProps }
{ ReactDOMServer, props }: { ReactDOMServer: any; props: any }
): string => {
let html;

Expand Down

0 comments on commit 4f31bcb

Please sign in to comment.