Skip to content

Commit

Permalink
feat: color picker dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Nov 25, 2023
1 parent 8d81b2c commit c65cee2
Show file tree
Hide file tree
Showing 24 changed files with 981 additions and 388 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
18 changes: 10 additions & 8 deletions packages/erd-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@
"@mdi/js": "7.2.96",
"@radix-ui/colors": "2.1.0",
"@rollup/plugin-typescript": "^11.1.2",
"@storybook/addon-essentials": "^7.4.0",
"@storybook/addon-interactions": "^7.4.0",
"@storybook/addon-links": "^7.4.0",
"@storybook/blocks": "^7.4.0",
"@storybook/html-vite": "^7.4.0",
"@storybook/html": "^7.4.0",
"@storybook/testing-library": "^0.2.0",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
"@storybook/addon-links": "^7.5.3",
"@storybook/blocks": "^7.5.3",
"@storybook/html-vite": "^7.5.3",
"@storybook/html": "^7.5.3",
"@storybook/testing-library": "^0.2.2",
"@types/color": "^3.0.3",
"@types/d3": "7.4.3",
"@types/highlight-words-core": "^1.2.3",
"@types/lodash-es": "^4.17.8",
"@types/luxon": "^3.3.1",
"@types/ua-parser-js": "^0.7.37",
"color": "^4.2.3",
"d3": "7.8.5",
"deepmerge": "^4.3.1",
"highlight-words-core": "^1.2.2",
"html-to-image": "^1.11.11",
Expand All @@ -78,7 +80,7 @@
"rollup-plugin-visualizer": "^5.9.2",
"rxjs": "^7.8.1",
"stats.js": "^0.17.0",
"storybook": "^7.4.0",
"storybook": "^7.5.3",
"ts-patch": "^3.0.2",
"tslib": "^2.6.1",
"typescript-transform-paths": "^3.4.6",
Expand Down
43 changes: 28 additions & 15 deletions packages/erd-editor/src/components/erd-editor/ErdEditor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
cache,
createRef,
defineCustomElement,
FC,
Expand All @@ -14,7 +15,9 @@ import Erd from '@/components/erd/Erd';
import GlobalStyles from '@/components/global-styles/GlobalStyles';
import Theme from '@/components/theme/Theme';
import Toolbar from '@/components/toolbar/Toolbar';
import Visualization from '@/components/visualization/Visualization';
import { TOOLBAR_HEIGHT } from '@/constants/layout';
import { CanvasType } from '@/constants/schema';
import { DatabaseVendor } from '@/constants/sql/database';
import { changeViewportAction } from '@/engine/modules/editor/atom.actions';
import { useKeyBindingMap } from '@/hooks/useKeyBindingMap';
Expand Down Expand Up @@ -121,22 +124,32 @@ const ErdEditor: FC<ErdEditorProps, ErdEditorElement> = (props, ctx) => {
});
});

return () => html`
<${GlobalStyles} />
<${Theme} .theme=${theme} />
<div
${ref(root)}
class=${['root', styles.root, { dark: isDarkMode() }]}
tabindex="-1"
@keydown=${handleKeydown}
>
<${Toolbar} />
<div class=${styles.main}>
<${Erd} />
return () => {
const { store } = appContextValue;
const { settings } = store.state;

return html`
<${GlobalStyles} />
<${Theme} .theme=${theme} />
<div
${ref(root)}
class=${['root', styles.root, { dark: isDarkMode() }]}
tabindex="-1"
@keydown=${handleKeydown}
>
<${Toolbar} />
<div class=${styles.main}>
${cache(
settings.canvasType === CanvasType.ERD ? html`<${Erd} />` : null
)}
${settings.canvasType === CanvasType.visualization
? html`<${Visualization} />`
: null}
</div>
${text.span}
</div>
${text.span}
</div>
`;
`;
};
};

defineCustomElement('erd-editor', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { FC, repeat, svg } from '@dineug/r-html';

import { useAppContext } from '@/components/appContext';
import Relationship from '@/components/erd/canvas/canvas-svg/relationship/Relationship';
import { hoverColumnMapAction } from '@/engine/modules/editor/atom.actions';
import { Relationship as RelationshipType } from '@/internal-types';
import { query } from '@/utils/collection/query';

import * as styles from './CanvasSvg.styles';
Expand All @@ -14,6 +16,23 @@ export type CanvasSvgProps = {
const CanvasSvg: FC<CanvasSvgProps> = (props, ctx) => {
const app = useAppContext(ctx);

const handleMouseenter = (relationship: RelationshipType) => {
const { store } = app.value;
store.dispatch(
hoverColumnMapAction({
columnIds: [
...relationship.start.columnIds,
...relationship.end.columnIds,
],
})
);
};

const handleMouseleave = () => {
const { store } = app.value;
store.dispatch(hoverColumnMapAction({ columnIds: [] }));
};

return () => {
const { store } = app.value;
const {
Expand Down Expand Up @@ -46,6 +65,8 @@ const CanvasSvg: FC<CanvasSvgProps> = (props, ctx) => {
{ identification: relationship.identification },
]}
data-id=${relationship.id}
@mouseenter=${() => handleMouseenter(relationship)}
@mouseleave=${handleMouseleave}
>
<${Relationship}
relationship=${relationship}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ const HighLevelTable: FC<HighLevelTableProps> = (props, ctx) => {

return () => {
const { store } = app.value;
const { editor } = store.state;
const { table } = props;
const selected = Boolean(store.state.editor.selectedMap[table.id]);
const selected = Boolean(editor.selectedMap[table.id]);
const tableWidths = calcTableWidths(table, store.state);
const height = calcTableHeight(table);

Expand Down
3 changes: 2 additions & 1 deletion packages/erd-editor/src/components/erd/canvas/memo/Memo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ const Memo: FC<MemoProps> = (props, ctx) => {

return () => {
const { store, keyBindingMap } = app.value;
const { editor } = store.state;
const { memo } = props;
const selected = Boolean(store.state.editor.selectedMap[memo.id]);
const selected = Boolean(editor.selectedMap[memo.id]);
const width = calcMemoWidth(memo);
const height = calcMemoHeight(memo);

Expand Down
4 changes: 2 additions & 2 deletions packages/erd-editor/src/components/erd/canvas/table/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ const Table: FC<TableProps> = (props, ctx) => {

return () => {
const { store, keyBindingMap } = app.value;
const { settings, collections } = store.state;
const { editor, settings, collections } = store.state;
const { table } = props;
const selected = Boolean(store.state.editor.selectedMap[table.id]);
const selected = Boolean(editor.selectedMap[table.id]);
const tableWidths = calcTableWidths(table, store.state);
const height = calcTableHeight(table);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const root = css`
background-color: var(--column-hover);
}
&.hover {
background-color: var(--column-hover);
}
&.selected {
background-color: var(--column-select);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,14 @@ const Column: FC<ColumnProps> = (props, ctx) => {
};

return () => {
const { keyBindingMap } = app.value;
const { store, keyBindingMap } = app.value;
const { editor } = store.state;
const { column, selected } = props;
const hover = Boolean(editor.hoverColumnMap[column.id]);

return html`
<div
class=${['column-row', styles.root, { selected }]}
class=${['column-row', styles.root, { selected, hover }]}
data-id=${column.id}
>
<${ColumnKey} keys=${column.ui.keys} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const meta = {
onChange: {
action: 'onChange',
},
onLastUpdate: {
action: 'onLastUpdate',
},
},
} satisfies Meta<ColorPickerProps>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export type ColorPickerProps = {
x: number;
y: number;
color: string;
onChange: (color: string) => void;
onChange?: (color: string) => void;
onLastUpdate?: (color: string) => void;
};

const ColorPicker: FC<ColorPickerProps> = (props, ctx) => {
Expand All @@ -25,7 +26,10 @@ const ColorPicker: FC<ColorPickerProps> = (props, ctx) => {
position: 'inline',
color: props.color || '',
onChange: (color: string) => {
props.onChange(color);
props.onChange?.(color);
},
onLastUpdate: (color: string) => {
props.onLastUpdate?.(color);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@dineug/r-html';

import { useUnmounted } from '@/hooks/useUnmounted';
import { restAttrs } from '@/utils/attribute';
import { lastCursorFocus } from '@/utils/focus';
import { focusEvent } from '@/utils/internalEvents';

Expand Down Expand Up @@ -85,10 +86,12 @@ const EditInput: FC<EditInputProps> = (props, ctx) => {
width: `${props.width}px`,
'min-width': `${props.width}px`,
}}
placeholder=${props.placeholder ?? ''}
...${restAttrs({
title: props.title,
placeholder: props.placeholder,
})}
type="text"
spellcheck="false"
title=${props.title}
.value=${props.value ?? ''}
@input=${props.onInput}
@blur=${handleBlur}
Expand All @@ -109,7 +112,7 @@ const EditInput: FC<EditInputProps> = (props, ctx) => {
width: `${props.width}px`,
'min-width': `${props.width}px`,
}}
title=${props.title}
...${restAttrs({ title: props.title })}
>
${props.value.trim() ? props.value : props.placeholder}
</div>
Expand Down
4 changes: 3 additions & 1 deletion packages/erd-editor/src/components/primitives/icon/Icon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FC, html, svg } from '@dineug/r-html';

import { restAttrs } from '@/utils/attribute';

import * as styles from './Icon.styles';
import { getIcon } from './icons';

Expand Down Expand Up @@ -31,7 +33,7 @@ const Icon: FC<IconProps> = (props, ctx) => () => {
return html`
<div
class=${['icon', styles.wrap, props.class]}
title=${props.title}
...${restAttrs({ title: props.title })}
@click=${props.onClick}
>
${prefix === 'base64'
Expand Down
3 changes: 2 additions & 1 deletion packages/erd-editor/src/components/primitives/icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '@fortawesome/free-solid-svg-icons';
import {
mdiAtom,
mdiChartScatterPlot,
mdiCodeBrackets,
mdiCodeJson,
mdiDatabase,
Expand Down Expand Up @@ -111,9 +112,9 @@ const icons = [
createMDI('format-letter-case', mdiFormatLetterCase),
createMDI('table-cog', mdiTableCog),
createMDI('code-brackets', mdiCodeBrackets),
createMDI('xml', mdiXml),
createMDI('vector-line', mdiVectorLine),
createMDI('atom', mdiAtom),
createMDI('chart-scatter-plot', mdiChartScatterPlot),
...Object.entries(BASE_64_ICON).map(([name, base64]) =>
createBase64(name, base64)
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, html } from '@dineug/r-html';

import { restAttrs } from '@/utils/attribute';
import { onNumberOnly } from '@/utils/domEvent';

export type TextInputProps = {
Expand All @@ -19,8 +20,10 @@ const TextInput: FC<TextInputProps> = (props, ctx) => {
return () => html`
<input
style=${{ width: props.width ? `${props.width}px` : '' }}
placeholder=${props.placeholder ?? ''}
title=${props.title ?? ''}
...${restAttrs({
title: props.title,
placeholder: props.placeholder,
})}
type="text"
spellcheck="false"
?readonly=${props.readonly}
Expand Down
27 changes: 27 additions & 0 deletions packages/erd-editor/src/components/toolbar/Toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Icon from '@/components/primitives/icon/Icon';
import TextInput from '@/components/primitives/text-input/TextInput';
import { CanvasType } from '@/constants/schema';
import {
changeCanvasTypeAction,
changeDatabaseNameAction,
changeZoomLevelAction,
resizeAction,
Expand Down Expand Up @@ -51,6 +52,11 @@ const Toolbar: FC<ToolbarProps> = (props, ctx) => {
store.dispatch(changeZoomLevelAction({ value: zoomLevel }));
};

const handleChangeCanvasType = (value: string) => {
const { store } = app.value;
store.dispatch(changeCanvasTypeAction({ value }));
};

const handleUndo = () => {
const { store } = app.value;
store.undo();
Expand Down Expand Up @@ -91,6 +97,27 @@ const Toolbar: FC<ToolbarProps> = (props, ctx) => {
.onChange=${handleZoomLevel}
/>
<div class=${styles.vertical}></div>
<div
class=${[
styles.menu,
{ active: settings.canvasType === CanvasType.ERD },
]}
title="Entity Relationship Diagram"
@click=${() => handleChangeCanvasType(CanvasType.ERD)}
>
<${Icon} name="diagram-project" size=${16} />
</div>
<div
class=${[
styles.menu,
{ active: settings.canvasType === CanvasType.visualization },
]}
title="Visualization"
@click=${() => handleChangeCanvasType(CanvasType.visualization)}
>
<${Icon} prefix="mdi" name="chart-scatter-plot" size=${16} />
</div>
<div class=${styles.vertical}></div>
${settings.canvasType === CanvasType.ERD
? html`
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { css } from '@dineug/r-html';
Loading

0 comments on commit c65cee2

Please sign in to comment.