Skip to content

Commit

Permalink
feat(monorepo) Move shadcn/ui to bristles/ui package (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggenzone authored Dec 13, 2023
1 parent 5eecf0c commit 4333864
Show file tree
Hide file tree
Showing 96 changed files with 2,447 additions and 3,041 deletions.
6 changes: 3 additions & 3 deletions apps/web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RouterProvider } from 'react-router-dom'
import { ThemeProvider } from './context/theme-provider'
import { Toaster } from '@/components/ui/toaster'
import { routes } from '@/features/app/routes'
import { ThemeProvider } from '@bristles/ui/context/theme-provider'
import { Toaster } from '@bristles/ui/components/ui/toaster'
import { routes } from './features/app/routes'

export default function App (): JSX.Element {
return (
Expand Down
68 changes: 0 additions & 68 deletions apps/web/src/components/draw/colors.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions apps/web/src/components/draw/hooks/use-canvas-rerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export function useCanvasRerender ({ elements, selection }: UseCanvasRerenderPro
elements.forEach(element => {
if (selection !== undefined && selection.type === 'simple' && (selection.ids ?? []).includes(element.id)) {
// @ts-expect-error find out how to call generic method based on element
ShapeHandler(element.name).draw({ canvas, context, element: { ...element, selected: true } })
ShapeHandler(element.name).draw({ ...element, selected: true }, { canvas, context })
} else {
// @ts-expect-error find out how to call generic method based on element
ShapeHandler(element.name).draw({ canvas, context, element: { ...element, selected: false } })
ShapeHandler(element.name).draw({ ...element, selected: false }, { canvas, context, })
}
})

Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/draw/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDrawing } from './hooks/use-drawing'
import { useHotkeys } from './hooks/hotkeys/use-hotkeys'
import { Menu } from './menu'
import { useEffect, useRef } from 'react'
import { isDebugEnable } from '@/config/const'
import { isDebugEnable } from '@bristles/web/config/const'


export function Draw () {
Expand All @@ -30,7 +30,6 @@ export function Draw () {

useEffect(() => {
if (action.name === 'writing' && textAreaRef.current != null) {
console.log('set focus')
textAreaRef.current.focus()
}
}, [action])
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/draw/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
MenubarSeparator,
MenubarShortcut,
MenubarTrigger
} from '@/components/ui/menubar'
import { useTheme } from '@/context/theme-provider'
} from '@bristles/ui/components/ui/menubar'
import { useTheme } from '@bristles/ui/context/theme-provider'
import { CursorArrowIcon, DoubleArrowRightIcon, DownloadIcon, DragHandleDots2Icon, FileIcon, MoonIcon, QuestionMarkCircledIcon, Share1Icon, SlashIcon, SquareIcon, SunIcon, TextIcon } from '@radix-ui/react-icons'
import { Button } from '../ui/button'
import { Button } from '@bristles/ui/components/ui/button'
import { type ControlProps } from './hooks/use-drawing'

// https://www.svgrepo.com/svg/450678/brush-mark
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/components/draw/selector.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { buttonVariants } from '@/components/ui/button'
import { buttonVariants } from '@bristles/ui/components/ui/button'
import {
Popover,
PopoverContent,
PopoverTrigger
} from '@/components/ui/popover'
} from '@bristles/ui/components/ui/popover'
import { BorderDashedIcon, BorderDottedIcon, BorderSolidIcon, BorderStyleIcon, CaretSortIcon, GroupIcon, PaddingIcon, TransparencyGridIcon } from '@radix-ui/react-icons'
import { AppRadioGroup2 } from './components/radio-group'
import { cn } from '@/lib/utils'
import { AppRadioGroup2 } from '@bristles/ui/components/radio-group'
import { cn } from '@bristles/ui/lib/utils'
import { type ControlProps } from './hooks/use-drawing'

const colorsStyleOptions = [
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/draw/shapes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type Shapes } from '../types'

type Handlers = RectangleHandler | TextHandler | LineHandler

export const ShapeHandler = (shape: Shapes): Handlers => {
export const ShapeHandler = (shape: Shapes): Handlers=> {
switch (shape) {
case 'rectangle':
return Rectangle
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/draw/shapes/line/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LineSchemaType } from '@bristles/schema'
import { type GenericHandler } from '../types/handler'
import { type LineElement } from './types'

import {
draw,
Expand All @@ -16,7 +16,7 @@ import {
positionInElement
} from './line'

export interface LineHandler extends GenericHandler<LineElement> {
export interface LineHandler extends GenericHandler<LineSchemaType> {
//clone: VoidFunction
}

Expand Down
39 changes: 20 additions & 19 deletions apps/web/src/components/draw/shapes/line/line.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type Properties, type DrawFunctionProps, type Position } from '../types/handler'
import { distance, nearPoints } from '../../lib/math/math'
import { type ElementDrawingAction, type ElementMainAction } from '../types/actions'
import { type LineElement } from './types'
import { Point } from '../../lib/math/types'
import { LineSchema, type LineSchemaType } from '@bristles/schema'

export function draw (props: DrawFunctionProps<LineElement>) {
const { context, element } = props
export function draw (element: LineSchemaType, props: DrawFunctionProps) {
const { context } = props

const fromPoint = { x: element.x, y: element.y }
const toPoint = { x: element.x + element.width, y: element.y + element.height }
Expand Down Expand Up @@ -85,9 +85,9 @@ export function draw (props: DrawFunctionProps<LineElement>) {
* @param {LineProperties} properties - The properties defining the line (e.g., width, height, etc.).
* @returns {LineElement} - A LineElement object created with the provided current point and properties.
*/
export function create (action: ElementDrawingAction): LineElement {
export function create (action: ElementDrawingAction): LineSchemaType {
const { currentPoint, properties } = action
const line: LineElement = {
const line: LineSchemaType = {
id: crypto.randomUUID(),
name: 'line',
x: currentPoint.x,
Expand All @@ -113,7 +113,7 @@ export function create (action: ElementDrawingAction): LineElement {
* @param {Point} currentPoint - The new current point representing the final position.
* @returns {LineElement} - A new Element with the updated size based on the new current point.
*/
function updateElement (oldElement: LineElement, currentPoint: Point): LineElement {
function updateElement (oldElement: LineSchemaType, currentPoint: Point): LineSchemaType {
const width = currentPoint.x - oldElement.x
const height = currentPoint.y - oldElement.y
const element = { ...oldElement, width, height }
Expand All @@ -125,7 +125,7 @@ function updateElement (oldElement: LineElement, currentPoint: Point): LineEleme
* @param {LineElement} element - The Element to be rearranged.
* @returns {LineElement} - The rearranged Element with position set in the top-left corner.
*/
function cleanup (oldElement: LineElement): LineElement {
function cleanup (oldElement: LineSchemaType): LineSchemaType {
const toX = oldElement.x + oldElement.width
const toY = oldElement.y + oldElement.height

Expand Down Expand Up @@ -153,7 +153,7 @@ function cleanup (oldElement: LineElement): LineElement {
* @param {Point} offset - The offset point representing the change in position.
* @returns {ElemenLineElementt} - A new Element moved to the new position based on the current point and offset.
*/
function moveLine (oldElement: LineElement, currentPoint: Point, offset: Point): LineElement {
function moveLine (oldElement: LineSchemaType, currentPoint: Point, offset: Point): LineSchemaType {
const x = currentPoint.x - offset.x
const y = currentPoint.y - offset.y
const width = oldElement.width
Expand All @@ -168,7 +168,7 @@ function moveLine (oldElement: LineElement, currentPoint: Point, offset: Point):
* @param {Position} position - The position ('start' or 'end') to reorder the initial point.
* @returns {LineElement} - A new LineElement with the initial point reordered based on the position.
*/
function reoderForResizeFromPosition (oldElement: LineElement, position: Position): LineElement {
function reoderForResizeFromPosition (oldElement: LineSchemaType, position: Position): LineSchemaType {
if (position.position === 'start') {
const toX = oldElement.x + oldElement.width
const toY = oldElement.y + oldElement.height
Expand All @@ -185,7 +185,7 @@ function reoderForResizeFromPosition (oldElement: LineElement, position: Positio
* @param {ElementMainAction} action - The action to perform over the element.
* @returns {LineElement} - Returns the created/update element
*/
export function startAction (element: LineElement, action: ElementMainAction) {
export function startAction (element: LineSchemaType, action: ElementMainAction) {
switch (action.name) {
case 'drawing':
return create(action)
Expand All @@ -201,7 +201,7 @@ export function startAction (element: LineElement, action: ElementMainAction) {
* @param {ElementMainAction} action - The action to perform over the element.
* @returns {LineElement} - Returns the updated element
*/
export function updateAction (element: LineElement, action: ElementMainAction) {
export function updateAction (element: LineSchemaType, action: ElementMainAction) {
switch (action.name) {
case 'drawing':
if (element !== undefined) {
Expand All @@ -222,7 +222,7 @@ export function updateAction (element: LineElement, action: ElementMainAction) {
* @param {ElementMainAction} action - The action to perform over the element.
* @returns {LineElement} - Returns the updated element
*/
export function endAction (element: LineElement, action: ElementMainAction) {
export function endAction (element: LineSchemaType, action: ElementMainAction) {
switch (action.name) {
case 'drawing': {
if (element !== undefined) {
Expand Down Expand Up @@ -250,7 +250,7 @@ export function endAction (element: LineElement, action: ElementMainAction) {
* @returns {Position} - Returns the position relative to the LineElement: 'start', 'end' if near the beginning or end,
* 'inside' if inside the element, or 'outside' if outside the element.
*/
export function positionInElement (element: LineElement, point: Point): Position {
export function positionInElement (element: LineSchemaType, point: Point): Position {
const a: Point = { x: element.x, y: element.y }
const b: Point = { x: element.x + element.width, y: element.y + element.height }

Expand All @@ -270,15 +270,16 @@ export function positionInElement (element: LineElement, point: Point): Position
return { type: 'outside', cursor: 'default', position: '' }
}

export function toString (element: LineElement): string {
export function toString (element: LineSchemaType): string {
return JSON.stringify(element, null, 2)
}

export function fromString (element: string): LineElement {
return JSON.parse(element) as LineElement
export function fromString (element: string): LineSchemaType {
const object = JSON.parse(element)
return LineSchema.parse(object)
}

export function copy (element: LineElement, point: Point): LineElement {
export function copy (element: LineSchemaType, point: Point): LineSchemaType {
return {
...element,
id: crypto.randomUUID(),
Expand All @@ -287,7 +288,7 @@ export function copy (element: LineElement, point: Point): LineElement {
}
}

export function update (element: LineElement, properties: Properties): LineElement {
export function update (element: LineSchemaType, properties: Properties): LineSchemaType {
return {
...element,
color: properties.color,
Expand All @@ -301,6 +302,6 @@ export function allowedProperties (): string[] {
return ['stroke', 'arrow']
}

export function properties (element: LineElement): Properties {
export function properties (element: LineSchemaType): Properties {
return { color: element.color, opacity: element.opacity, arrow: element.arrow, stroke: element.stroke }
}
10 changes: 0 additions & 10 deletions apps/web/src/components/draw/shapes/line/types.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/web/src/components/draw/shapes/rectangle/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type RectangleSchemaType } from '@bristles/schema'
import { type GenericHandler } from '../types/handler'
import { type RectangleElement } from './types'

import {
draw,
Expand All @@ -16,7 +16,7 @@ import {
positionInElement
} from './rectangle'

export interface RectangleHandler extends GenericHandler<RectangleElement> {
export interface RectangleHandler extends GenericHandler<RectangleSchemaType> {
//clone: VoidFunction
}

Expand Down
Loading

0 comments on commit 4333864

Please sign in to comment.