Skip to content

Commit 0787688

Browse files
committed
wip: refactor builder click overlay
1 parent 670b3d3 commit 0787688

File tree

7 files changed

+46
-67
lines changed

7 files changed

+46
-67
lines changed

libs/frontend/application/builder/src/use-cases/base-builder/BuilderClickOverlay.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ export const BuilderClickOverlay = observer<{
4646
}
4747

4848
const element = selectedNode.element.current
49-
50-
console.log(selectedNode.element.current.slug)
51-
52-
const domElement = queryRenderedElementById(element.id)
49+
const domElement = queryRenderedElementById(selectedNode.compositeKey)
5350

5451
if (!domElement || !renderContainerRef.current) {
5552
return null
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Nullable } from '@codelab/shared/abstract/types'
22

3-
import { DATA_ELEMENT_ID } from '@codelab/frontend/abstract/domain'
3+
import { DATA_RUNTIME_ELEMENT_ID } from '@codelab/frontend/abstract/domain'
44

55
export const queryRenderedElementById = (
66
nodeId: string,
@@ -9,7 +9,7 @@ export const queryRenderedElementById = (
99
return null
1010
}
1111

12-
const nodeQuerySelector = `[${DATA_ELEMENT_ID}="${nodeId}"]`
12+
const nodeQuerySelector = `[${DATA_RUNTIME_ELEMENT_ID}="${nodeId}"]`
1313

1414
return document.querySelector(nodeQuerySelector)
1515
}

libs/frontend/application/renderer/src/components/DroppableStyledComponent.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ interface DroppableStyledComponentProps extends StyledComponentProps {
1313
}
1414

1515
const DroppableFragment = styled.div`
16-
display: contents;
16+
width: 100%
17+
heigh: 100%
18+
position: absolute;
1719
`
1820

1921
const FragmentComponent = ({
@@ -25,7 +27,7 @@ const FragmentComponent = ({
2527
}: PropsWithChildren<
2628
Omit<DroppableStyledComponentProps, 'ReactComponent'>
2729
>) => {
28-
return isDroppable ? (
30+
const drag = (
2931
<MakeComponentDroppable
3032
ReactComponent={DroppableFragment}
3133
componentProps={componentProps}
@@ -35,9 +37,9 @@ const FragmentComponent = ({
3537
>
3638
{children}
3739
</MakeComponentDroppable>
38-
) : (
39-
children
4040
)
41+
42+
return children
4143
}
4244

4345
export const DroppableStyledComponent = ({
Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,37 @@
11
import type { IComponentType } from '@codelab/frontend/abstract/domain'
22
import type { IPropData } from '@codelab/shared/abstract/core'
3-
import type { Nullable } from '@codelab/shared/abstract/types'
43
import type { PropsWithChildren } from 'react'
54

6-
import { camelCaseToKebabCaseOnlyKeys } from '@codelab/shared/utils'
7-
import { forwardRef, useCallback } from 'react'
5+
import { toKebabCase } from 'remeda'
86
import styled from 'styled-components'
97

10-
const ReusableStyledComponent = styled('placeholder')`
11-
${(props: IPropData) => camelCaseToKebabCaseOnlyKeys(props['css'])}
8+
const Placeholder = styled('placeholder')`
9+
${(props: IPropData) => toKebabCase(props['css'])}
1210
`
1311

14-
export interface StyledComponentProps {
12+
export interface StyledComponentProps extends PropsWithChildren {
1513
ReactComponent: IComponentType
1614
componentProps: IPropData
1715
}
1816

19-
export const StyledComponent = forwardRef(
20-
(
21-
{
22-
children,
23-
componentProps,
24-
ReactComponent,
25-
}: PropsWithChildren<StyledComponentProps>,
26-
ref,
27-
) => {
28-
const onRefChange = useCallback((node: Nullable<HTMLElement>) => {
29-
componentProps['ref']?.(node)
30-
31-
if (ref && node instanceof HTMLElement) {
32-
if (typeof ref === 'function') {
33-
ref(node)
34-
} else {
35-
ref.current = node
36-
}
37-
}
38-
}, [])
39-
40-
const { key, ...restComponentProps } = componentProps
41-
42-
return (
43-
<ReusableStyledComponent
44-
id="reuseable-styled-component"
45-
key={key}
46-
// eslint-disable-next-line react/jsx-props-no-spreading
47-
{...restComponentProps}
48-
as={ReactComponent}
49-
ref={onRefChange}
50-
>
51-
{children}
52-
</ReusableStyledComponent>
53-
)
54-
},
55-
)
17+
export const StyledComponent = ({
18+
children,
19+
componentProps,
20+
ReactComponent,
21+
}: StyledComponentProps) => {
22+
const { key, ...restComponentProps } = componentProps
23+
24+
return (
25+
<Placeholder
26+
id="reuseable-styled-component"
27+
key={key}
28+
// eslint-disable-next-line react/jsx-props-no-spreading
29+
{...restComponentProps}
30+
as={ReactComponent}
31+
>
32+
{children}
33+
</Placeholder>
34+
)
35+
}
5636

5737
StyledComponent.displayName = 'StyledComponent'

libs/shared/utils/src/transform/strings.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export const getNameFromSlug = (str?: string) => {
3131
*
3232
* Example: "fontFamily: 'Gloria Hallelujah'" => "font-family: 'Gloria Hallelujah'"
3333
*/
34-
export const camelCaseToKebabCaseOnlyKeys = (input?: string) =>
35-
input?.replace(/(\w+)(\s*)(?=:)/g, (match) =>
36-
match.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`),
37-
)
34+
// export const camelCaseToKebabCaseOnlyKeys = (input?: string) =>
35+
// input?.replace(/(\w+)(\s*)(?=:)/g, (match) =>
36+
// match.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`),
37+
// )
3838

3939
/**
4040
* Transform both `camelCase`, `PascalCase` to title case

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
"react-use": "^17.5.1",
229229
"recoil": "0.7.7",
230230
"reflect-metadata": "0.1.13",
231-
"remeda": "2.12.0",
231+
"remeda": "2.17.4",
232232
"rooks": "7.6.1",
233233
"rxjs": "7.8.0",
234234
"server-only": "^0.0.1",

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)