Skip to content

Commit

Permalink
Merge pull request #350 from haydenbleasel/main
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdoro committed Mar 18, 2024
2 parents 9008395 + d04495a commit 9140b03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion apps/docs/guides/tailwind/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description: "Follow this guide to set up Novel with Tailwindcss"
href="https://ui.shadcn.com/docs/installation"
>
You can find more info about installing shadcn-ui here. You will need to add
the following components: <b>Button, Separator, Popover, Command, Dialog,</b>
the following components: <b>Button, Separator, Popover, Command, Dialog</b>
</Card>

This example will use the same stucture from here: [Anatomy](/quickstart#anatomy)\
Expand Down Expand Up @@ -339,3 +339,7 @@ import { defaultEditorProps, EditorContent } from "novel";
</AccordionGroup>

<Note>You need `require("@tailwindcss/typography")` for the prose styling</Note>

## Usage within Dialogs

Novel has been designed to work automatically within Radix Dialogs, namely by looking for the closest parent attribute `[role="dialog"]`. If you're using a different implementation for popups and dialogs, ensure you add this attribute above the editor so the drag handle calculates the correct position.
13 changes: 12 additions & 1 deletion packages/headless/src/extensions/drag-and-drop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export interface DragHandleOptions {
}
function absoluteRect(node: Element) {
const data = node.getBoundingClientRect();
const modal = node.closest('[role="dialog"]');

if (modal && window.getComputedStyle(modal).transform !== "none") {
const modalRect = modal.getBoundingClientRect();

return {
top: data.top - modalRect.top,
left: data.left - modalRect.left,
width: data.width,
};
}

return {
top: data.top,
Expand Down Expand Up @@ -154,7 +165,7 @@ function DragHandle(options: DragHandleOptions) {
y: event.clientY,
});

if (!(node instanceof Element)) {
if (!(node instanceof Element) || node.matches("ul, ol")) {
hideDragHandle();
return;
}
Expand Down

0 comments on commit 9140b03

Please sign in to comment.