-
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
28 changed files
with
2,381 additions
and
16 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
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
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
30 changes: 30 additions & 0 deletions
30
packages/erd-editor/src/components/primitives/code-block/CodeBlock.stories.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,30 @@ | ||
import { html, render } from '@dineug/r-html'; | ||
import type { Meta, StoryObj } from '@storybook/html'; | ||
|
||
import CodeBlock, { CodeBlockProps } from './CodeBlock'; | ||
|
||
const meta = { | ||
title: 'Primitives/CodeBlock', | ||
render: args => { | ||
const fragment = document.createDocumentFragment(); | ||
render(fragment, html`<${CodeBlock} ...${args} />`); | ||
return fragment; | ||
}, | ||
argTypes: { | ||
value: { | ||
control: 'text', | ||
}, | ||
onCopy: { | ||
action: 'onCopy', | ||
}, | ||
}, | ||
} satisfies Meta<CodeBlockProps>; | ||
|
||
export default meta; | ||
type Story = StoryObj<CodeBlockProps>; | ||
|
||
export const Normal: Story = { | ||
args: { | ||
value: 'SELECT * FROM users;', | ||
}, | ||
}; |
45 changes: 45 additions & 0 deletions
45
packages/erd-editor/src/components/primitives/code-block/CodeBlock.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,45 @@ | ||
import { css } from '@dineug/r-html'; | ||
|
||
export const clipboard = css` | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
padding: 8px; | ||
margin: 8px; | ||
cursor: pointer; | ||
fill: var(--foreground); | ||
color: var(--foreground); | ||
opacity: 0; | ||
transition: opacity 0.15s; | ||
&:hover { | ||
fill: var(--active); | ||
color: var(--active); | ||
} | ||
`; | ||
|
||
export const root = css` | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
min-height: 40px; | ||
outline: none; | ||
&:hover { | ||
${clipboard} { | ||
opacity: 1; | ||
} | ||
} | ||
`; | ||
|
||
export const code = css` | ||
width: 100%; | ||
height: 100%; | ||
white-space: pre; | ||
overflow: auto; | ||
outline: none; | ||
font-family: var(--code-font-family) !important; | ||
color: var(--active); | ||
padding: 16px; | ||
`; |
27 changes: 27 additions & 0 deletions
27
packages/erd-editor/src/components/primitives/code-block/CodeBlock.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,27 @@ | ||
import { FC, html, innerHTML } from '@dineug/r-html'; | ||
|
||
import Icon from '@/components/primitives/icon/Icon'; | ||
|
||
import * as styles from './CodeBlock.styles'; | ||
|
||
export type CodeBlockProps = { | ||
value: string; | ||
onCopy?: (value: string) => void; | ||
}; | ||
|
||
const CodeBlock: FC<CodeBlockProps> = (props, ctx) => { | ||
const handleCopy = () => { | ||
props.onCopy?.(props.value); | ||
}; | ||
|
||
return () => html` | ||
<div class=${styles.root}> | ||
<pre class=${['scrollbar', styles.code]}>${innerHTML(props.value)}</pre> | ||
<div class=${styles.clipboard} title="Copy" @click=${handleCopy}> | ||
<${Icon} prefix="far" name="copy" useTransition=${true} /> | ||
</div> | ||
</div> | ||
`; | ||
}; | ||
|
||
export default CodeBlock; |
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
8 changes: 8 additions & 0 deletions
8
packages/erd-editor/src/components/schema-sql/SchemaSQL.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,8 @@ | ||
import { css } from '@dineug/r-html'; | ||
|
||
export const root = css` | ||
position: relative; | ||
height: 100%; | ||
overflow: auto; | ||
background-color: var(--canvas-background); | ||
`; |
78 changes: 78 additions & 0 deletions
78
packages/erd-editor/src/components/schema-sql/SchemaSQL.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,78 @@ | ||
import { delay } from '@dineug/go'; | ||
import { FC, html, observable, onBeforeMount, watch } from '@dineug/r-html'; | ||
|
||
import { useAppContext } from '@/components/appContext'; | ||
import CodeBlock from '@/components/primitives/code-block/CodeBlock'; | ||
import { useContextMenuRootProvider } from '@/components/primitives/context-menu/context-menu-root/contextMenuRootContext'; | ||
import Toast from '@/components/primitives/toast/Toast'; | ||
import SchemaSQLContextMenu from '@/components/schema-sql/schema-sql-context-menu/SchemaSQLContextMenu'; | ||
import { useUnmounted } from '@/hooks/useUnmounted'; | ||
import { copyToClipboard } from '@/utils/clipboard'; | ||
import { openToastAction } from '@/utils/emitter'; | ||
import { createSchemaSQL } from '@/utils/schemaSQL'; | ||
|
||
import * as styles from './SchemaSQL.styles'; | ||
|
||
export type SchemaSQLProps = {}; | ||
|
||
const SchemaSQL: FC<SchemaSQLProps> = (props, ctx) => { | ||
const app = useAppContext(ctx); | ||
const { addUnsubscribe } = useUnmounted(); | ||
const contextMenu = useContextMenuRootProvider(ctx); | ||
|
||
const state = observable({ | ||
sql: '', | ||
}); | ||
|
||
const setSQL = () => { | ||
const { store } = app.value; | ||
state.sql = createSchemaSQL(store.state); | ||
}; | ||
|
||
const handleCopy = () => { | ||
const { emitter } = app.value; | ||
|
||
copyToClipboard(state.sql).then(() => { | ||
emitter.emit( | ||
openToastAction({ | ||
close: delay(2000), | ||
message: html`<${Toast} description="Copied!" />`, | ||
}) | ||
); | ||
}); | ||
}; | ||
|
||
const handleContextmenuClose = () => { | ||
contextMenu.state.show = false; | ||
}; | ||
|
||
onBeforeMount(() => { | ||
const { store } = app.value; | ||
const { settings } = store.state; | ||
|
||
setSQL(); | ||
|
||
addUnsubscribe( | ||
watch(settings).subscribe(propName => { | ||
if (propName !== 'database' && propName !== 'bracketType') { | ||
return; | ||
} | ||
|
||
setSQL(); | ||
}) | ||
); | ||
}); | ||
|
||
return () => html` | ||
<div | ||
class=${styles.root} | ||
@contextmenu=${contextMenu.onContextmenu} | ||
@mousedown=${contextMenu.onMousedown} | ||
> | ||
<${CodeBlock} value=${state.sql} .onCopy=${handleCopy} /> | ||
<${SchemaSQLContextMenu} .onClose=${handleContextmenuClose} /> | ||
</div> | ||
`; | ||
}; | ||
|
||
export default SchemaSQL; |
78 changes: 78 additions & 0 deletions
78
...ages/erd-editor/src/components/schema-sql/schema-sql-context-menu/SchemaSQLContextMenu.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,78 @@ | ||
import { FC, html } from '@dineug/r-html'; | ||
|
||
import { useAppContext } from '@/components/appContext'; | ||
import { createDatabaseMenus } from '@/components/erd/erd-context-menu/menus/databaseMenus'; | ||
import ContextMenu from '@/components/primitives/context-menu/ContextMenu'; | ||
import Icon from '@/components/primitives/icon/Icon'; | ||
|
||
import { createBracketMenus } from './menus/bracketMenus'; | ||
|
||
export type SchemaSQLContextMenuProps = { | ||
onClose: () => void; | ||
}; | ||
|
||
const SchemaSQLContextMenu: FC<SchemaSQLContextMenuProps> = (props, ctx) => { | ||
const app = useAppContext(ctx); | ||
|
||
const chevronRightIcon = html`<${Icon} name="chevron-right" size=${14} />`; | ||
|
||
return () => | ||
html`<${ContextMenu.Root} | ||
children=${html` | ||
<${ContextMenu.Item} | ||
children=${html` | ||
<${ContextMenu.Menu} | ||
icon=${html` | ||
<${Icon} prefix="mdi" name="database" size=${14} /> | ||
`} | ||
name="Database" | ||
right=${chevronRightIcon} | ||
/> | ||
`} | ||
subChildren=${html`${createDatabaseMenus(app.value).map( | ||
menu => html` | ||
<${ContextMenu.Item} | ||
.onClick=${menu.onClick} | ||
children=${html` | ||
<${ContextMenu.Menu} | ||
icon=${menu.checked | ||
? html`<${Icon} name="check" size=${14} />` | ||
: null} | ||
name=${menu.name} | ||
/> | ||
`} | ||
/> | ||
` | ||
)}`} | ||
/> | ||
<${ContextMenu.Item} | ||
children=${html` | ||
<${ContextMenu.Menu} | ||
icon=${html` | ||
<${Icon} prefix="mdi" name="code-brackets" size=${14} /> | ||
`} | ||
name="Bracket" | ||
right=${chevronRightIcon} | ||
/> | ||
`} | ||
subChildren=${html`${createBracketMenus(app.value).map( | ||
menu => html` | ||
<${ContextMenu.Item} | ||
.onClick=${menu.onClick} | ||
children=${html` | ||
<${ContextMenu.Menu} | ||
icon=${menu.checked | ||
? html`<${Icon} name="check" size=${14} />` | ||
: null} | ||
name=${menu.name} | ||
/> | ||
`} | ||
/> | ||
` | ||
)}`} | ||
/> | ||
`} | ||
/>`; | ||
}; | ||
|
||
export default SchemaSQLContextMenu; |
Oops, something went wrong.