Skip to content

Commit

Permalink
feat: Improved Git status change #326
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Apr 13, 2024
1 parent 8d74395 commit 7169bf2
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 42 deletions.
4 changes: 4 additions & 0 deletions json-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
},
"maxWidthComment": {
"type": "integer"
},
"ignoreSaveSettings": {
"description": "bit value (scroll: 1) | (zoomLevel: 2)",
"type": "integer"
}
},
"required": [
Expand Down
27 changes: 26 additions & 1 deletion packages/erd-editor-schema/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { pick } from 'lodash-es';

import { v2ToV3, v3ToV2 } from '@/convert';
import { bHas } from '@/utils/bit';
import { type ERDEditorSchemaV2, schemaV2Parser } from '@/v2';
import { type ERDEditorSchemaV3, schemaV3Parser } from '@/v3';
import {
type ERDEditorSchemaV3,
SchemaV3Constants,
schemaV3Parser,
} from '@/v3';

export function parser(source: string): ERDEditorSchemaV3 {
const json = JSON.parse(source);
Expand All @@ -22,6 +27,26 @@ export function toJson(schemaV3: ERDEditorSchemaV3) {
'collections',
'lww',
]);

if (
bHas(
source.settings.ignoreSaveSettings,
SchemaV3Constants.SaveSettingType.scroll
)
) {
source.settings.scrollTop = 0;
source.settings.scrollLeft = 0;
}

if (
bHas(
source.settings.ignoreSaveSettings,
SchemaV3Constants.SaveSettingType.zoomLevel
)
) {
source.settings.zoomLevel = 1;
}

return JSON.stringify(source, null, 2);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/erd-editor-schema/src/v3/parser/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const createSettings = (): Settings => ({
ColumnType.columnComment,
],
maxWidthComment: -1,
ignoreSaveSettings: 0,
});

const sizeInRange = createInRange(CANVAS_SIZE_MIN, CANVAS_SIZE_MAX);
Expand Down Expand Up @@ -96,6 +97,7 @@ export function createAndMergeSettings(json?: DeepPartial<Settings>): Settings {
assignNumber('scrollTop');
assignNumber('scrollLeft');
assignNumber('show');
assignNumber('ignoreSaveSettings');
assignString('databaseName');
assignString('canvasType');
assignBoolean('relationshipDataTypeSync');
Expand Down
2 changes: 2 additions & 0 deletions packages/erd-editor-schema/src/v3/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
LanguageList,
NameCase,
NameCaseList,
SaveSettingType,
Settings,
Show,
} from '@/v3/schema/settings';
Expand Down Expand Up @@ -83,6 +84,7 @@ export const SchemaV3Constants = {
ColumnUIKey,
OrderType,
OrderTypeList,
SaveSettingType,
CANVAS_SIZE_MAX,
CANVAS_SIZE_MIN,
CANVAS_ZOOM_MAX,
Expand Down
6 changes: 6 additions & 0 deletions packages/erd-editor-schema/src/v3/schema/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Settings = {
relationshipOptimization: boolean;
columnOrder: number[];
maxWidthComment: number;
ignoreSaveSettings: number;
};

export const CanvasType = {
Expand Down Expand Up @@ -91,6 +92,11 @@ export const BracketType = {
export const BracketTypeList: ReadonlyArray<number> =
Object.values(BracketType);

export const SaveSettingType = {
scroll: /* */ 0b0000000000000000000000000000001,
zoomLevel: /* */ 0b0000000000000000000000000000010,
};

export const CANVAS_ZOOM_MIN = 0.1;
export const CANVAS_ZOOM_MAX = 1;
export const CANVAS_SIZE_MIN = 2_000;
Expand Down
3 changes: 1 addition & 2 deletions packages/erd-editor-vscode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuerd-vscode",
"version": "1.0.19",
"version": "1.0.20",
"private": true,
"description": "Entity-Relationship Diagram Editor VSCode Extension",
"icon": "./assets/erd-editor.png",
Expand Down Expand Up @@ -50,7 +50,6 @@
"@dineug/erd-editor-vscode-bridge": "workspace:*",
"@dineug/erd-editor-vscode-webview": "workspace:*",
"@types/node": "^18.15.0",
"@types/opentype.js": "^1.3.8",
"@types/vscode": "^1.85.0",
"base64-arraybuffer": "^1.0.2",
"crypto-js": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/erd-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dineug/erd-editor",
"version": "3.2.2",
"version": "3.2.3",
"description": "Entity-Relationship Diagram Editor",
"type": "module",
"main": "./dist/erd-editor.js",
Expand Down
52 changes: 51 additions & 1 deletion packages/erd-editor/src/components/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import SettingsLnb, {
} from '@/components/settings/settings-lnb/SettingsLnb';
import Shortcuts from '@/components/settings/shortcuts/Shortcuts';
import { COLUMN_MIN_WIDTH } from '@/constants/layout';
import { ColumnTypeToName } from '@/constants/schema';
import { ColumnTypeToName, SaveSettingType } from '@/constants/schema';
import {
changeColumnOrderAction,
changeIgnoreSaveSettingsAction,
changeMaxWidthCommentAction,
changeRelationshipDataTypeSyncAction,
} from '@/engine/modules/settings/atom.actions';
import { fontSize6 } from '@/styles/typography.styles';
import { bHas } from '@/utils/bit';
import { recalculateTableWidth } from '@/utils/calcTable';
import { onPrevent } from '@/utils/domEvent';
import { relationshipSort } from '@/utils/draw-relationship/sort';
Expand Down Expand Up @@ -135,6 +137,28 @@ const Settings: FC<SettingsProps> = (props, ctx) => {
store.dispatch(changeMaxWidthCommentAction({ value: maxWidthComment }));
};

const handleChangeScrollSaveSettings = (value: boolean) => {
const { store } = app.value;

store.dispatch(
changeIgnoreSaveSettingsAction({
saveSettingType: SaveSettingType.scroll,
value: !value,
})
);
};

const handleChangeZoomLevelSaveSettings = (value: boolean) => {
const { store } = app.value;

store.dispatch(
changeIgnoreSaveSettingsAction({
saveSettingType: SaveSettingType.zoomLevel,
value: !value,
})
);
};

return () => {
const { store } = app.value;
const { settings } = store.state;
Expand All @@ -160,6 +184,31 @@ const Settings: FC<SettingsProps> = (props, ctx) => {
.onChange=${handleChangeRelationshipDataTypeSync}
/>
</div>
<div class=${styles.row}>
<div>Save Scroll Information</div>
<div class=${styles.vertical(16)}></div>
<${Switch}
value=${!bHas(
settings.ignoreSaveSettings,
SaveSettingType.scroll
)}
.onChange=${handleChangeScrollSaveSettings}
/>
</div>
<div class=${styles.row}>
<div>Save Zoom Information</div>
<div class=${styles.vertical(16)}></div>
<${Switch}
value=${!bHas(
settings.ignoreSaveSettings,
SaveSettingType.zoomLevel
)}
.onChange=${handleChangeZoomLevelSaveSettings}
/>
</div>
<div class=${styles.row}>
<div>Maximum comment width</div>
<div class=${styles.vertical(16)}></div>
Expand All @@ -180,6 +229,7 @@ const Settings: FC<SettingsProps> = (props, ctx) => {
.onChange=${handleChangeMaxWidthComment}
/>
</div>
<div class=${styles.row}>
<div>Recalculation table width</div>
<div class=${styles.vertical(16)}></div>
Expand Down
1 change: 1 addition & 0 deletions packages/erd-editor/src/constants/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const ColumnOption = SchemaV3Constants.ColumnOption;
export const ColumnUIKey = SchemaV3Constants.ColumnUIKey;
export const OrderType = SchemaV3Constants.OrderType;
export const OrderTypeList = SchemaV3Constants.OrderTypeList;
export const SaveSettingType = SchemaV3Constants.SaveSettingType;
export const CANVAS_SIZE_MAX = SchemaV3Constants.CANVAS_SIZE_MAX;
export const CANVAS_SIZE_MIN = SchemaV3Constants.CANVAS_SIZE_MIN;
export const CANVAS_ZOOM_MAX = SchemaV3Constants.CANVAS_ZOOM_MAX;
Expand Down
1 change: 1 addition & 0 deletions packages/erd-editor/src/engine/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const ChangeActionTypes: ReadonlyArray<ActionType> = [
'settings.changeRelationshipOptimization',
'settings.changeColumnOrder',
'settings.changeMaxWidthComment',
'settings.changeIgnoreSaveSettings',
// editor
'editor.loadJson',
'editor.clear',
Expand Down
5 changes: 5 additions & 0 deletions packages/erd-editor/src/engine/modules/settings/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ActionType = {
changeRelationshipOptimization: 'settings.changeRelationshipOptimization',
changeColumnOrder: 'settings.changeColumnOrder',
changeMaxWidthComment: 'settings.changeMaxWidthComment',
changeIgnoreSaveSettings: 'settings.changeIgnoreSaveSettings',
} as const;
export type ActionType = ValuesType<typeof ActionType>;

Expand Down Expand Up @@ -82,6 +83,10 @@ export type ActionMap = {
[ActionType.changeMaxWidthComment]: {
value: number;
};
[ActionType.changeIgnoreSaveSettings]: {
saveSettingType: number;
value: boolean;
};
};

export type ReducerType<T extends keyof ActionMap> = Reducer<
Expand Down
14 changes: 14 additions & 0 deletions packages/erd-editor/src/engine/modules/settings/atom.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ const changeMaxWidthComment: ReducerType<
value === -1 ? value : maxWidthCommentInRange(value);
};

export const changeIgnoreSaveSettingsAction = createAction<
ActionMap[typeof ActionType.changeIgnoreSaveSettings]
>(ActionType.changeIgnoreSaveSettings);

const changeIgnoreSaveSettings: ReducerType<
typeof ActionType.changeIgnoreSaveSettings
> = ({ settings }, { payload: { saveSettingType, value } }) => {
settings.ignoreSaveSettings = value
? settings.ignoreSaveSettings | saveSettingType
: settings.ignoreSaveSettings & ~saveSettingType;
};

export const settingsReducers = {
[ActionType.changeDatabaseName]: changeDatabaseName,
[ActionType.resize]: resize,
Expand All @@ -284,6 +296,7 @@ export const settingsReducers = {
[ActionType.changeRelationshipOptimization]: changeRelationshipOptimization,
[ActionType.changeColumnOrder]: changeColumnOrder,
[ActionType.changeMaxWidthComment]: changeMaxWidthComment,
[ActionType.changeIgnoreSaveSettings]: changeIgnoreSaveSettings,
};

export const actions = {
Expand All @@ -304,4 +317,5 @@ export const actions = {
changeRelationshipOptimizationAction,
changeColumnOrderAction,
changeMaxWidthCommentAction,
changeIgnoreSaveSettingsAction,
};
35 changes: 19 additions & 16 deletions packages/erd-editor/src/engine/modules/table-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,30 @@ const validationForeignKeyHook: CO = function* (channel, state) {
.collection('tableEntities')
.selectByIds(doc.tableIds);
const foreignKeyColumnIdsSet = new Set<string>();
const columnCollection = query(collections).collection(
'tableColumnEntities'
);

for (const { end } of relationships) {
query(collections)
.collection('tableColumnEntities')
.updateMany(end.columnIds, column => {
column.ui.keys = column.ui.keys | ColumnUIKey.foreignKey;
foreignKeyColumnIdsSet.add(column.id);
});
const columns = columnCollection.selectByIds(end.columnIds);

for (const column of columns) {
column.ui.keys = column.ui.keys | ColumnUIKey.foreignKey;
foreignKeyColumnIdsSet.add(column.id);
}
}

for (const table of tables) {
query(collections)
.collection('tableColumnEntities')
.updateMany(table.columnIds, column => {
if (
bHas(column.ui.keys, ColumnUIKey.foreignKey) &&
!foreignKeyColumnIdsSet.has(column.id)
) {
column.ui.keys = column.ui.keys & ~ColumnUIKey.foreignKey;
}
});
const columns = columnCollection.selectByIds(table.columnIds);

for (const column of columns) {
if (
bHas(column.ui.keys, ColumnUIKey.foreignKey) &&
!foreignKeyColumnIdsSet.has(column.id)
) {
column.ui.keys = column.ui.keys & ~ColumnUIKey.foreignKey;
}
}
}
});
};
Expand Down
31 changes: 17 additions & 14 deletions packages/erd-editor/src/utils/calcTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,22 @@ export function recalculateTableWidth(
{ doc: { tableIds }, collections }: RootState,
{ toWidth }: EngineContext
) {
query(collections)
const tables = query(collections)
.collection('tableEntities')
.updateMany(tableIds, table => {
table.ui.widthName = textInRange(toWidth(table.name));
table.ui.widthComment = textInRange(toWidth(table.comment));

query(collections)
.collection('tableColumnEntities')
.updateMany(table.columnIds, column => {
column.ui.widthName = textInRange(toWidth(column.name));
column.ui.widthDataType = textInRange(toWidth(column.dataType));
column.ui.widthDefault = textInRange(toWidth(column.default));
column.ui.widthComment = textInRange(toWidth(column.comment));
});
});
.selectByIds(tableIds);
const columnCollection = query(collections).collection('tableColumnEntities');

for (const table of tables) {
table.ui.widthName = textInRange(toWidth(table.name));
table.ui.widthComment = textInRange(toWidth(table.comment));

const columns = columnCollection.selectByIds(table.columnIds);

for (const column of columns) {
column.ui.widthName = textInRange(toWidth(column.name));
column.ui.widthDataType = textInRange(toWidth(column.dataType));
column.ui.widthDefault = textInRange(toWidth(column.default));
column.ui.widthComment = textInRange(toWidth(column.comment));
}
}
}
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7169bf2

Please sign in to comment.