-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
168 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/erd-editor/src/components/erd/canvas/high-level-table/HighLevelTable.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { css } from '@dineug/r-html'; | ||
|
||
export const name = css` | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
overflow: auto; | ||
word-break: break-all; | ||
color: var(--active); | ||
font-weight: var(--font-weight-bold); | ||
`; |
85 changes: 85 additions & 0 deletions
85
packages/erd-editor/src/components/erd/canvas/high-level-table/HighLevelTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { FC, html } from '@dineug/r-html'; | ||
|
||
import { useAppContext } from '@/components/context'; | ||
import * as styles from '@/components/erd/canvas/table/Table.styles'; | ||
import { useMoveTable } from '@/components/erd/canvas/table/useMoveTable'; | ||
import { Table } from '@/internal-types'; | ||
import { | ||
fontSize5, | ||
fontSize6, | ||
fontSize7, | ||
fontSize8, | ||
fontSize9, | ||
} from '@/styles/typography.styles'; | ||
import { calcTableHeight, calcTableWidths } from '@/utils/calcTable'; | ||
|
||
import * as highLevelTableStyle from './HighLevelTable.styles'; | ||
|
||
export type HighLevelTableProps = { | ||
table: Table; | ||
}; | ||
|
||
const HighLevelTable: FC<HighLevelTableProps> = (props, ctx) => { | ||
const app = useAppContext(ctx); | ||
const { onMoveStart } = useMoveTable(ctx, props); | ||
|
||
const fontSize = () => { | ||
const { store } = app.value; | ||
const { | ||
settings: { zoomLevel }, | ||
} = store.state; | ||
let fontSize = fontSize5.toString(); | ||
|
||
if (zoomLevel > 0.6) { | ||
fontSize = fontSize5.toString(); | ||
} else if (zoomLevel > 0.5) { | ||
fontSize = fontSize6.toString(); | ||
} else if (zoomLevel > 0.4) { | ||
fontSize = fontSize7.toString(); | ||
} else if (zoomLevel > 0.3) { | ||
fontSize = fontSize8.toString(); | ||
} else { | ||
fontSize = fontSize9.toString(); | ||
} | ||
|
||
return fontSize; | ||
}; | ||
|
||
return () => { | ||
const { store } = app.value; | ||
const { table } = props; | ||
const selected = Boolean(store.state.editor.selectedMap[table.id]); | ||
const tableWidths = calcTableWidths(table, store.state); | ||
const height = calcTableHeight(table); | ||
|
||
return html` | ||
<div | ||
class=${['table', styles.root]} | ||
style=${{ | ||
top: `${table.ui.y}px`, | ||
left: `${table.ui.x}px`, | ||
'z-index': `${table.ui.zIndex}`, | ||
width: `${tableWidths.width}px`, | ||
height: `${height}px`, | ||
}} | ||
?data-selected=${selected} | ||
@mousedown=${onMoveStart} | ||
@touchstart=${onMoveStart} | ||
> | ||
<div class=${styles.header}> | ||
<div | ||
class=${['table-header-color', styles.headerColor]} | ||
style=${{ | ||
'background-color': table.ui.color, | ||
}} | ||
></div> | ||
</div> | ||
<div class=${['scrollbar', highLevelTableStyle.name, fontSize()]}> | ||
${table.name} | ||
</div> | ||
</div> | ||
`; | ||
}; | ||
}; | ||
|
||
export default HighLevelTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/erd-editor/src/components/erd/canvas/table/useMoveTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useAppContext } from '@/components/context'; | ||
import { moveAllAction$ } from '@/engine/modules/editor/generator.actions'; | ||
import { selectTableAction$ } from '@/engine/modules/table/generator.actions'; | ||
import { Ctx, Table } from '@/internal-types'; | ||
import { drag$, DragMove } from '@/utils/globalEventObservable'; | ||
import { isMod } from '@/utils/keyboard-shortcut'; | ||
|
||
export function useMoveTable(ctx: Ctx, props: { table: Table }) { | ||
const app = useAppContext(ctx); | ||
|
||
const handleMove = ({ event, movementX, movementY }: DragMove) => { | ||
event.type === 'mousemove' && event.preventDefault(); | ||
const { store } = app.value; | ||
store.dispatch(moveAllAction$(movementX, movementY)); | ||
}; | ||
|
||
const onMoveStart = (event: MouseEvent | TouchEvent) => { | ||
const el = event.target as HTMLElement | null; | ||
if (!el) return; | ||
|
||
const { store } = app.value; | ||
store.dispatch(selectTableAction$(props.table.id, isMod(event))); | ||
|
||
if ( | ||
!el.closest('.table-header-color') && | ||
!el.closest('.column-row') && | ||
!el.closest('.icon') && | ||
!el.closest('.input-padding') | ||
) { | ||
drag$.subscribe(handleMove); | ||
} | ||
}; | ||
|
||
return { | ||
onMoveStart, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters