Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix table resizable #2555

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/olive-tips-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@udecode/plate-resizable': patch
---

Major changes missing from 23.0.0:
- `ResizeHandleOptions`: removed `style`, `width`, `startMargin`, `endMargin`, `zIndex`.
6 changes: 6 additions & 0 deletions .changeset/seven-trees-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@udecode/plate-table': patch
---

Major changes missing from 23.0.0:
- Removed `TableCellElementResizable`. Use `useTableCellElementResizableState` and `useTableCellElementResizable` instead.
6 changes: 6 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
- Package renamed to `@udecode/plate-resizable`.
- `ResizeHandle` is now fully headless: no style is applied by default. Add your own `Resizable`, `ResizeHandle` components:
- `npx @udecode/plate-ui@latest add resizable`

## @udecode/plate-table@23.0

### Major Changes

- Removed `TableCellElementResizable`. Use `useTableCellElementResizableState` and `useTableCellElementResizable` instead.

# 22.0.0

Expand Down
63 changes: 53 additions & 10 deletions apps/www/content/docs/table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1003,17 +1003,17 @@ Enhance the editor instance with table-related functionality by applying the fol

## API Components

### TableCellElementResizable
### useTableCellElementResizableState

A component that represents the resizable handles for a table cell element.
A state for the table resize handles.

<APIProps>
<APIItem name="colIndex" type="number">
The index of the column of the cell.
</APIItem>
<APIItem name="rowIndex" type="number">
The index of the row of the cell.
</APIItem>
<APIOptions>
<APIItem name="colIndex" type="number">
The index of the column of the cell.
</APIItem>
<APIItem name="rowIndex" type="number">
The index of the row of the cell.
</APIItem>
<APIItem name="step" type="number" optional>
The step size for resizing the table cell element.
</APIItem>
Expand All @@ -1029,7 +1029,50 @@ A component that represents the resizable handles for a table cell element.
- **Default:** `step`

</APIItem>
</APIProps>
</APIOptions>

<APIReturns>
<APIItem name="disableMarginLeft" type="boolean">
Whether to disable the margin left.
</APIItem>
<APIItem name="colIndex" type="number">
The index of the column of the cell.
</APIItem>
<APIItem name="rowIndex" type="number">
The index of the row of the cell.
</APIItem>
<APIItem name="stepX" type="number">
The step size for resizing the table cell element horizontally.
</APIItem>
<APIItem name="stepY" type="number">
The step size for resizing the table cell element vertically.
</APIItem>
</APIReturns>

### useTableCellElementResizable

A behavior hook for the table resize handles.

<APIParameters>
<APIItem name="state" type="object">
The state returned by [useTableCellElementResizableState](#usetablecellelementresizablestate).
</APIItem>
</APIParameters>

<APIReturns>
<APIItem name="rightProps" type="object">
The props for the right resize handle.
</APIItem>
<APIItem name="bottomProps" type="object">
The props for the bottom resize handle.
</APIItem>
<APIItem name="leftProps" type="object">
The props for the left resize handle.
</APIItem>
<APIItem name="hiddenLeft" type="boolean">
Whether the left resize handle is hidden.
</APIItem>
</APIReturns>

### getOnSelectTableBorderFactory

Expand Down
4 changes: 3 additions & 1 deletion apps/www/public/registry/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,9 @@
"dependencies": [
"@udecode/plate-table"
],
"registryDependencies": [],
"registryDependencies": [
"resizable"
],
"files": [
"plate-ui/table-cell-element.tsx"
],
Expand Down
2 changes: 1 addition & 1 deletion apps/www/public/registry/styles/default/image-element.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"files": [
{
"name": "image-element.tsx",
"content": "import React from 'react';\nimport { PlateElement, PlateElementProps, Value } from '@udecode/plate-common';\nimport {\n ELEMENT_IMAGE,\n Image,\n TImageElement,\n useMediaState,\n} from '@udecode/plate-media';\nimport { useResizableStore } from '@udecode/plate-resizable';\n\nimport { cn } from '@/lib/utils';\n\nimport { Caption, CaptionTextarea } from './caption';\nimport { MediaPopover } from './media-popover';\nimport { Resizable, ResizeHandle } from './resizable';\n\nexport function ImageElement({\n className,\n children,\n nodeProps,\n ...props\n}: PlateElementProps<Value, TImageElement>) {\n const { readOnly, focused, selected, align } = useMediaState();\n const width = useResizableStore().get.width();\n\n return (\n <MediaPopover pluginKey={ELEMENT_IMAGE}>\n <PlateElement className={cn('py-2.5', className)} {...props}>\n <figure className=\"group relative m-0\" contentEditable={false}>\n <Resizable\n align={align}\n options={{\n align,\n readOnly,\n }}\n >\n <ResizeHandle options={{ direction: 'left' }} />\n <Image\n className={cn(\n 'block w-full max-w-full cursor-pointer object-cover px-0',\n 'rounded-sm',\n focused && selected && 'ring-2 ring-ring ring-offset-2'\n )}\n alt=\"\"\n {...nodeProps}\n />\n <ResizeHandle options={{ direction: 'right' }} />\n </Resizable>\n\n <Caption align={align} style={{ width }}>\n <CaptionTextarea\n placeholder=\"Write a caption...\"\n options={{}}\n readOnly={readOnly}\n />\n </Caption>\n </figure>\n\n {children}\n </PlateElement>\n </MediaPopover>\n );\n}\n"
"content": "import React from 'react';\nimport { PlateElement, PlateElementProps, Value } from '@udecode/plate-common';\nimport {\n ELEMENT_IMAGE,\n Image,\n TImageElement,\n useMediaState,\n} from '@udecode/plate-media';\nimport { useResizableStore } from '@udecode/plate-resizable';\n\nimport { cn } from '@/lib/utils';\n\nimport { Caption, CaptionTextarea } from './caption';\nimport { MediaPopover } from './media-popover';\nimport {\n mediaResizeHandleVariants,\n Resizable,\n ResizeHandle,\n} from './resizable';\n\nexport function ImageElement({\n className,\n children,\n nodeProps,\n ...props\n}: PlateElementProps<Value, TImageElement>) {\n const { readOnly, focused, selected, align = 'center' } = useMediaState();\n const width = useResizableStore().get.width();\n\n return (\n <MediaPopover pluginKey={ELEMENT_IMAGE}>\n <PlateElement className={cn('py-2.5', className)} {...props}>\n <figure className=\"group relative m-0\" contentEditable={false}>\n <Resizable\n align={align}\n options={{\n align,\n readOnly,\n }}\n >\n <ResizeHandle\n options={{ direction: 'left' }}\n className={mediaResizeHandleVariants({ direction: 'left' })}\n />\n <Image\n className={cn(\n 'block w-full max-w-full cursor-pointer object-cover px-0',\n 'rounded-sm',\n focused && selected && 'ring-2 ring-ring ring-offset-2'\n )}\n alt=\"\"\n {...nodeProps}\n />\n <ResizeHandle\n options={{ direction: 'right' }}\n className={mediaResizeHandleVariants({ direction: 'right' })}\n />\n </Resizable>\n\n <Caption align={align} style={{ width }}>\n <CaptionTextarea\n placeholder=\"Write a caption...\"\n options={{}}\n readOnly={readOnly}\n />\n </Caption>\n </figure>\n\n {children}\n </PlateElement>\n </MediaPopover>\n );\n}\n"
}
],
"type": "components:plate-ui"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"files": [
{
"name": "media-embed-element.tsx",
"content": "import React from 'react';\nimport { PlateElement, PlateElementProps, Value } from '@udecode/plate-common';\nimport {\n ELEMENT_MEDIA_EMBED,\n parseTwitterUrl,\n parseVideoUrl,\n TMediaEmbedElement,\n useMediaState,\n} from '@udecode/plate-media';\nimport { useResizableStore } from '@udecode/plate-resizable';\nimport LiteYouTubeEmbed from 'react-lite-youtube-embed';\nimport { Tweet } from 'react-tweet';\n\nimport { cn } from '@/lib/utils';\n\nimport { Caption, CaptionTextarea } from './caption';\nimport { MediaPopover } from './media-popover';\nimport { Resizable, ResizeHandle } from './resizable';\n\nconst MediaEmbedElement = React.forwardRef<\n React.ElementRef<typeof PlateElement>,\n PlateElementProps<Value, TMediaEmbedElement>\n>(({ className, children, ...props }, ref) => {\n const {\n align,\n focused,\n readOnly,\n selected,\n embed,\n isTweet,\n isVideo,\n isYoutube,\n } = useMediaState({\n urlParsers: [parseTwitterUrl, parseVideoUrl],\n });\n const width = useResizableStore().get.width();\n const provider = embed?.provider;\n\n return (\n <MediaPopover pluginKey={ELEMENT_MEDIA_EMBED}>\n <PlateElement\n ref={ref}\n className={cn('relative py-2.5', className)}\n {...props}\n >\n <figure className=\"group relative m-0 w-full\" contentEditable={false}>\n <Resizable\n align={align}\n options={{\n maxWidth: isTweet ? 550 : '100%',\n minWidth: isTweet ? 300 : 100,\n }}\n >\n <ResizeHandle options={{ direction: 'left' }} />\n\n {isVideo ? (\n isYoutube ? (\n <LiteYouTubeEmbed\n id={embed!.id!}\n title=\"youtube\"\n wrapperClass={cn(\n 'rounded-sm',\n focused && selected && 'ring-2 ring-ring ring-offset-2',\n 'relative block cursor-pointer bg-black bg-cover bg-center [contain:content]',\n '[&.lyt-activated]:before:absolute [&.lyt-activated]:before:top-0 [&.lyt-activated]:before:h-[60px] [&.lyt-activated]:before:w-full [&.lyt-activated]:before:bg-top [&.lyt-activated]:before:bg-repeat-x [&.lyt-activated]:before:pb-[50px] [&.lyt-activated]:before:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',\n '[&.lyt-activated]:before:bg-[url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==)]',\n 'after:block after:pb-[var(--aspect-ratio)] after:content-[\"\"]',\n '[&_>_iframe]:absolute [&_>_iframe]:left-0 [&_>_iframe]:top-0 [&_>_iframe]:h-full [&_>_iframe]:w-full',\n '[&_>_.lty-playbtn]:z-[1] [&_>_.lty-playbtn]:h-[46px] [&_>_.lty-playbtn]:w-[70px] [&_>_.lty-playbtn]:rounded-[14%] [&_>_.lty-playbtn]:bg-[#212121] [&_>_.lty-playbtn]:opacity-80 [&_>_.lty-playbtn]:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',\n '[&:hover_>_.lty-playbtn]:bg-[red] [&:hover_>_.lty-playbtn]:opacity-100',\n '[&_>_.lty-playbtn]:before:border-y-[11px] [&_>_.lty-playbtn]:before:border-l-[19px] [&_>_.lty-playbtn]:before:border-r-0 [&_>_.lty-playbtn]:before:border-[transparent_transparent_transparent_#fff] [&_>_.lty-playbtn]:before:content-[\"\"]',\n '[&_>_.lty-playbtn]:absolute [&_>_.lty-playbtn]:left-1/2 [&_>_.lty-playbtn]:top-1/2 [&_>_.lty-playbtn]:[transform:translate3d(-50%,-50%,0)]',\n '[&_>_.lty-playbtn]:before:absolute [&_>_.lty-playbtn]:before:left-1/2 [&_>_.lty-playbtn]:before:top-1/2 [&_>_.lty-playbtn]:before:[transform:translate3d(-50%,-50%,0)]',\n '[&.lyt-activated]:cursor-[unset]',\n '[&.lyt-activated]:before:pointer-events-none [&.lyt-activated]:before:opacity-0',\n '[&.lyt-activated_>_.lty-playbtn]:pointer-events-none [&.lyt-activated_>_.lty-playbtn]:!opacity-0'\n )}\n />\n ) : (\n <div\n className={cn(\n provider === 'vimeo' && 'pb-[75%]',\n provider === 'youku' && 'pb-[56.25%]',\n provider === 'dailymotion' && 'pb-[56.0417%]',\n provider === 'coub' && 'pb-[51.25%]'\n )}\n >\n <iframe\n className={cn(\n 'absolute left-0 top-0 h-full w-full rounded-sm',\n isVideo && 'border-0',\n focused && selected && 'ring-2 ring-ring ring-offset-2'\n )}\n src={embed!.url}\n title=\"embed\"\n allowFullScreen\n />\n </div>\n )\n ) : null}\n\n {isTweet && (\n <div\n className={cn(\n '[&_.react-tweet-theme]:my-0',\n !readOnly &&\n selected &&\n '[&_.react-tweet-theme]:ring-2 [&_.react-tweet-theme]:ring-ring [&_.react-tweet-theme]:ring-offset-2'\n )}\n >\n <Tweet id={embed!.id!} />\n </div>\n )}\n\n <ResizeHandle options={{ direction: 'right' }} />\n </Resizable>\n\n <Caption align={align} style={{ width }}>\n <CaptionTextarea placeholder=\"Write a caption...\" />\n </Caption>\n </figure>\n\n {children}\n </PlateElement>\n </MediaPopover>\n );\n});\nMediaEmbedElement.displayName = 'MediaEmbedElement';\n\nexport { MediaEmbedElement };\n"
"content": "import React from 'react';\nimport { PlateElement, PlateElementProps, Value } from '@udecode/plate-common';\nimport {\n ELEMENT_MEDIA_EMBED,\n parseTwitterUrl,\n parseVideoUrl,\n TMediaEmbedElement,\n useMediaState,\n} from '@udecode/plate-media';\nimport { useResizableStore } from '@udecode/plate-resizable';\nimport LiteYouTubeEmbed from 'react-lite-youtube-embed';\nimport { Tweet } from 'react-tweet';\n\nimport { cn } from '@/lib/utils';\n\nimport { Caption, CaptionTextarea } from './caption';\nimport { MediaPopover } from './media-popover';\nimport {\n mediaResizeHandleVariants,\n Resizable,\n ResizeHandle,\n} from './resizable';\n\nconst MediaEmbedElement = React.forwardRef<\n React.ElementRef<typeof PlateElement>,\n PlateElementProps<Value, TMediaEmbedElement>\n>(({ className, children, ...props }, ref) => {\n const {\n align = 'center',\n focused,\n readOnly,\n selected,\n embed,\n isTweet,\n isVideo,\n isYoutube,\n } = useMediaState({\n urlParsers: [parseTwitterUrl, parseVideoUrl],\n });\n const width = useResizableStore().get.width();\n const provider = embed?.provider;\n\n return (\n <MediaPopover pluginKey={ELEMENT_MEDIA_EMBED}>\n <PlateElement\n ref={ref}\n className={cn('relative py-2.5', className)}\n {...props}\n >\n <figure className=\"group relative m-0 w-full\" contentEditable={false}>\n <Resizable\n align={align}\n options={{\n maxWidth: isTweet ? 550 : '100%',\n minWidth: isTweet ? 300 : 100,\n }}\n >\n <ResizeHandle\n options={{ direction: 'left' }}\n className={mediaResizeHandleVariants({ direction: 'left' })}\n />\n\n {isVideo ? (\n isYoutube ? (\n <LiteYouTubeEmbed\n id={embed!.id!}\n title=\"youtube\"\n wrapperClass={cn(\n 'rounded-sm',\n focused && selected && 'ring-2 ring-ring ring-offset-2',\n 'relative block cursor-pointer bg-black bg-cover bg-center [contain:content]',\n '[&.lyt-activated]:before:absolute [&.lyt-activated]:before:top-0 [&.lyt-activated]:before:h-[60px] [&.lyt-activated]:before:w-full [&.lyt-activated]:before:bg-top [&.lyt-activated]:before:bg-repeat-x [&.lyt-activated]:before:pb-[50px] [&.lyt-activated]:before:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',\n '[&.lyt-activated]:before:bg-[url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==)]',\n 'after:block after:pb-[var(--aspect-ratio)] after:content-[\"\"]',\n '[&_>_iframe]:absolute [&_>_iframe]:left-0 [&_>_iframe]:top-0 [&_>_iframe]:h-full [&_>_iframe]:w-full',\n '[&_>_.lty-playbtn]:z-[1] [&_>_.lty-playbtn]:h-[46px] [&_>_.lty-playbtn]:w-[70px] [&_>_.lty-playbtn]:rounded-[14%] [&_>_.lty-playbtn]:bg-[#212121] [&_>_.lty-playbtn]:opacity-80 [&_>_.lty-playbtn]:[transition:all_0.2s_cubic-bezier(0,_0,_0.2,_1)]',\n '[&:hover_>_.lty-playbtn]:bg-[red] [&:hover_>_.lty-playbtn]:opacity-100',\n '[&_>_.lty-playbtn]:before:border-y-[11px] [&_>_.lty-playbtn]:before:border-l-[19px] [&_>_.lty-playbtn]:before:border-r-0 [&_>_.lty-playbtn]:before:border-[transparent_transparent_transparent_#fff] [&_>_.lty-playbtn]:before:content-[\"\"]',\n '[&_>_.lty-playbtn]:absolute [&_>_.lty-playbtn]:left-1/2 [&_>_.lty-playbtn]:top-1/2 [&_>_.lty-playbtn]:[transform:translate3d(-50%,-50%,0)]',\n '[&_>_.lty-playbtn]:before:absolute [&_>_.lty-playbtn]:before:left-1/2 [&_>_.lty-playbtn]:before:top-1/2 [&_>_.lty-playbtn]:before:[transform:translate3d(-50%,-50%,0)]',\n '[&.lyt-activated]:cursor-[unset]',\n '[&.lyt-activated]:before:pointer-events-none [&.lyt-activated]:before:opacity-0',\n '[&.lyt-activated_>_.lty-playbtn]:pointer-events-none [&.lyt-activated_>_.lty-playbtn]:!opacity-0'\n )}\n />\n ) : (\n <div\n className={cn(\n provider === 'vimeo' && 'pb-[75%]',\n provider === 'youku' && 'pb-[56.25%]',\n provider === 'dailymotion' && 'pb-[56.0417%]',\n provider === 'coub' && 'pb-[51.25%]'\n )}\n >\n <iframe\n className={cn(\n 'absolute left-0 top-0 h-full w-full rounded-sm',\n isVideo && 'border-0',\n focused && selected && 'ring-2 ring-ring ring-offset-2'\n )}\n src={embed!.url}\n title=\"embed\"\n allowFullScreen\n />\n </div>\n )\n ) : null}\n\n {isTweet && (\n <div\n className={cn(\n '[&_.react-tweet-theme]:my-0',\n !readOnly &&\n selected &&\n '[&_.react-tweet-theme]:ring-2 [&_.react-tweet-theme]:ring-ring [&_.react-tweet-theme]:ring-offset-2'\n )}\n >\n <Tweet id={embed!.id!} />\n </div>\n )}\n\n <ResizeHandle\n options={{ direction: 'right' }}\n className={mediaResizeHandleVariants({ direction: 'right' })}\n />\n </Resizable>\n\n <Caption align={align} style={{ width }}>\n <CaptionTextarea placeholder=\"Write a caption...\" />\n </Caption>\n </figure>\n\n {children}\n </PlateElement>\n </MediaPopover>\n );\n});\nMediaEmbedElement.displayName = 'MediaEmbedElement';\n\nexport { MediaEmbedElement };\n"
}
],
"type": "components:plate-ui"
Expand Down
Loading
Loading