masonry
diceui-radix/masonryFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/masonry.jsonSource
1"use client";23import { Slot as SlotPrimitive } from "radix-ui";4import * as React from "react";5import { useComposedRefs } from "@/lib/compose-refs";6import { useIsomorphicLayoutEffect } from "@/registry/bases/radix/hooks/use-isomorphic-layout-effect";78const NODE_COLOR = {9 RED: 0,10 BLACK: 1,11 SENTINEL: 2,12} as const;1314const NODE_OPERATION = {15 REMOVE: 0,16 PRESERVE: 1,17} as const;1819type NodeColor = (typeof NODE_COLOR)[keyof typeof NODE_COLOR];20type NodeOperation = (typeof NODE_OPERATION)[keyof typeof NODE_OPERATION];2122interface ListNode {23 index: number;24 high: number;25 next: ListNode | null;26}2728interface TreeNode {29 max: number;30 low: number;31 high: number;32 color: NodeColor;33 parent: TreeNode;34 right: TreeNode;35 left: TreeNode;36 list: ListNode;37}3839interface Tree {40 root: TreeNode;41 size: number;42}4344function addInterval(treeNode: TreeNode, high: number, index: number): boolean {45 let node: ListNode | null = treeNode.list;46 let prevNode: ListNode | undefined;4748 while (node) {49 if (node.index === index) return false;50 if (high > node.high) break;51 prevNode = node;52 node = node.next;53 }5455 if (!prevNode) treeNode.list = { index, high, next: node };56 if (prevNode) prevNode.next = { index, high, next: prevNode.next };5758 return true;59}6061function removeInterval(62 treeNode: TreeNode,63 index: number,64): NodeOperation | undefined {65 let node: ListNode | null = treeNode.list;66 if (node.index === index) {67 if (node.next === null) return NODE_OPERATION.REMOVE;68 treeNode.list = node.next;69 return NODE_OPERATION.PRESERVE;70 }7172 let prevNode: ListNode | undefined = node;73 node = node.next;7475 while (node !== null) {76 if (node.index === index) {77 prevNode.next = node.next;78 return NODE_OPERATION.PRESERVE;79 }80 prevNode = node;81 node = node.next;82 }83}8485const SENTINEL_NODE: TreeNode = {86 low: 0,87 max: 0,88 high: 0,89 color: NODE_COLOR.SENTINEL,90 parent: undefined as unknown as TreeNode,91 right: undefined as unknown as TreeNode,92 left: undefined as unknown as TreeNode,93 list: undefined as unknown as ListNode,94};9596SENTINEL_NODE.parent = SENTINEL_NODE;97SENTINEL_NODE.left = SENTINEL_NODE;98SENTINEL_NODE.right = SENTINEL_NODE;99100function updateMax(node: TreeNode) {101 const max = node.high;102 if (node.left === SENTINEL_NODE && node.right === SENTINEL_NODE)103 node.max = max;104 else if (node.left === SENTINEL_NODE)105 node.max = Math.max(node.right.max, max);106 else if (node.right === SENTINEL_NODE)107// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
