Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/EditorCanvas/Canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { useTranslation } from "react-i18next";
import { useEventListener } from "usehooks-ts";
import { areFieldsCompatible, getTableHeight } from "../../utils/utils";
import { getRectFromEndpoints, isInsideRect } from "../../utils/rect";
import { State, noteWidth } from "../../data/constants";
import { State } from "../../data/constants";

export default function Canvas() {
const { t } = useTranslation();
Expand Down Expand Up @@ -173,7 +173,7 @@ export default function Canvas() {
const noteRect = {
x: note.x,
y: note.y,
width: noteWidth,
width: settings.noteWidth,
height: note.height,
};
if (shouldAddElement(noteRect, element)) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/EditorCanvas/Note.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import {
useSelect,
useNotes,
useSaveState,
useSettings,
} from "../../hooks";
import { useTranslation } from "react-i18next";
import { noteWidth, noteRadius, noteFold } from "../../data/constants";
import { noteRadius, noteFold } from "../../data/constants";

export default function Note({ data, onPointerDown }) {
const [editField, setEditField] = useState({});
const [hovered, setHovered] = useState(false);
const { layout } = useLayout();
const { t } = useTranslation();
const { settings } = useSettings();
const noteWidth = settings.noteWidth;
const { setSaveState } = useSaveState();
const { updateNote, deleteNote } = useNotes();
const { setUndoStack, setRedoStack } = useUndoRedo();
Expand Down
7 changes: 6 additions & 1 deletion src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
SIDESHEET,
DB,
IMPORT_FROM,
noteWidth,
pngExportPixelRatio,
} from "../../data/constants";
import jsPDF from "jspdf";
Expand Down Expand Up @@ -133,6 +132,8 @@ export default function ControlPanel({
const { version, gistId, setGistId } = useContext(IdContext);
const navigate = useNavigate();

const noteWidth = settings.noteWidth;

const invertLayout = (component) =>
setLayout((prev) => ({ ...prev, [component]: !prev[component] }));

Expand Down Expand Up @@ -1516,6 +1517,10 @@ export default function ControlPanel({
function: () => setModal(MODAL.TABLE_WIDTH),
disabled: layout.readOnly,
},
notes_width: {
function: () => setModal(MODAL.NOTE_WIDTH),
disabled: layout.readOnly,
},
language: {
function: () => setModal(MODAL.LANGUAGE),
},
Expand Down
3 changes: 3 additions & 0 deletions src/components/EditorHeader/Modal/Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import New from "./New";
import ImportDiagram from "./ImportDiagram";
import ImportSource from "./ImportSource";
import SetTableWidth from "./SetTableWidth";
import SetNotesWidth from "./SetNotesWidth";
import Language from "./Language";
import Share from "./Share";
import CodeEditor from "../../CodeEditor";
Expand Down Expand Up @@ -346,6 +347,8 @@ export default function Modal({
}
case MODAL.TABLE_WIDTH:
return <SetTableWidth />;
case MODAL.NOTE_WIDTH:
return <SetNotesWidth />;
case MODAL.LANGUAGE:
return <Language />;
case MODAL.SHARE:
Expand Down
19 changes: 19 additions & 0 deletions src/components/EditorHeader/Modal/SetNotesWidth.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { InputNumber } from "@douyinfe/semi-ui";
import { useLayout, useSettings } from "../../../hooks";

export default function SetNotesWidth() {
const { layout } = useLayout();
const { settings, setSettings } = useSettings();

return (
<InputNumber
className="w-full"
value={settings.noteWidth}
readonly={layout.readOnly}
onChange={(c) => {
if (c < 180) return;
setSettings((prev) => ({ ...prev, noteWidth: c }));
}}
/>
);
}
2 changes: 1 addition & 1 deletion src/components/Thumbnail.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
tableFieldHeight,
tableHeaderHeight,
noteWidth,
defaultNoteWidth as noteWidth,
noteRadius,
noteFold,
gridSize,
Expand Down
3 changes: 2 additions & 1 deletion src/context/SettingsContext.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useEffect, useState } from "react";
import { tableWidth } from "../data/constants";
import { tableWidth, defaultNoteWidth } from "../data/constants";

const defaultSettings = {
strictMode: false,
Expand All @@ -13,6 +13,7 @@ const defaultSettings = {
showRelationshipLabels: true,
tableWidth: tableWidth,
showDebugCoordinates: false,
noteWidth: defaultNoteWidth,
};

export const SettingsContext = createContext(defaultSettings);
Expand Down
3 changes: 2 additions & 1 deletion src/data/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const defaultBlue = "#175e7a";
export const defaultNoteTheme = "#fcf7ac";
export const noteWidth = 180;
export const defaultNoteWidth = 180;
export const noteRadius = 3;
export const noteFold = 24;
export const darkBgTheme = "#16161A";
Expand Down Expand Up @@ -87,6 +87,7 @@ export const MODAL = {
TABLE_WIDTH: 9,
LANGUAGE: 10,
SHARE: 11,
NOTE_WIDTH: 12,
};

export const STATUS = {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const en = {
coordinate_space_screen: "Screen",
coordinate_space_diagram: "Diagram",
table_width: "Table width",
notes_width: "Notes width",
language: "Language",
flush_storage: "Flush storage",
are_you_sure_flush_storage:
Expand Down
2 changes: 2 additions & 0 deletions src/utils/modalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const getModalTitle = (modal) => {
return i18n.t("create_new_diagram");
case MODAL.TABLE_WIDTH:
return i18n.t("table_width");
case MODAL.NOTE_WIDTH:
return i18n.t("notes_width");
case MODAL.LANGUAGE:
return i18n.t("language");
case MODAL.SHARE:
Expand Down