Showing preview only (1,347K chars total). Download the full file or copy to clipboard to get everything.
Repository: drawdb-io/drawdb
Branch: main
Commit: 75bc4f911cfc
Files: 229
Total size: 1.2 MB
Directory structure:
gitextract_axfxdxsb/
├── .dockerignore
├── .eslintrc.cjs
├── .github/
│ ├── FUNDING.yml
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ └── feature_request.md
│ └── workflows/
│ ├── build.yml
│ └── docker.yml
├── .gitignore
├── .prettierrc.json
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── README.md
├── compose.yml
├── index.html
├── package.json
├── postcss.config.js
├── public/
│ └── robots.txt
├── src/
│ ├── App.jsx
│ ├── animations/
│ │ ├── FadeIn.jsx
│ │ └── SlideIn.jsx
│ ├── api/
│ │ ├── email.js
│ │ └── gists.js
│ ├── components/
│ │ ├── CodeEditor/
│ │ │ ├── index.jsx
│ │ │ └── setUpDBML.js
│ │ ├── EditorCanvas/
│ │ │ ├── Area.jsx
│ │ │ ├── Canvas.jsx
│ │ │ ├── Note.jsx
│ │ │ ├── Relationship.jsx
│ │ │ └── Table.jsx
│ │ ├── EditorHeader/
│ │ │ ├── ControlPanel.jsx
│ │ │ ├── LayoutDropdown.jsx
│ │ │ ├── Modal/
│ │ │ │ ├── ImportDiagram.jsx
│ │ │ │ ├── ImportSource.jsx
│ │ │ │ ├── Language.jsx
│ │ │ │ ├── Modal.jsx
│ │ │ │ ├── New.jsx
│ │ │ │ ├── Open.jsx
│ │ │ │ ├── Rename.jsx
│ │ │ │ ├── SetTableWidth.jsx
│ │ │ │ └── Share.jsx
│ │ │ └── SideSheet/
│ │ │ ├── Migration.jsx
│ │ │ ├── Sidesheet.jsx
│ │ │ ├── Timeline.jsx
│ │ │ └── Versions.jsx
│ │ ├── EditorSidePanel/
│ │ │ ├── AreasTab/
│ │ │ │ ├── AreaDetails.jsx
│ │ │ │ ├── AreasTab.jsx
│ │ │ │ └── SearchBar.jsx
│ │ │ ├── ColorPicker.jsx
│ │ │ ├── DBMLEditor.jsx
│ │ │ ├── Empty.jsx
│ │ │ ├── EnumsTab/
│ │ │ │ ├── EnumDetails.jsx
│ │ │ │ ├── EnumsTab.jsx
│ │ │ │ └── SearchBar.jsx
│ │ │ ├── Issues.jsx
│ │ │ ├── NotesTab/
│ │ │ │ ├── NoteInfo.jsx
│ │ │ │ ├── NotesTab.jsx
│ │ │ │ └── SearchBar.jsx
│ │ │ ├── RelationshipsTab/
│ │ │ │ ├── RelationshipInfo.jsx
│ │ │ │ ├── RelationshipsTab.jsx
│ │ │ │ └── SearchBar.jsx
│ │ │ ├── SidePanel.jsx
│ │ │ ├── TablesTab/
│ │ │ │ ├── FieldDetails.jsx
│ │ │ │ ├── IndexDetails.jsx
│ │ │ │ ├── SearchBar.jsx
│ │ │ │ ├── TableField.jsx
│ │ │ │ ├── TableInfo.jsx
│ │ │ │ └── TablesTab.jsx
│ │ │ └── TypesTab/
│ │ │ ├── SearchBar.jsx
│ │ │ ├── TypeField.jsx
│ │ │ ├── TypeInfo.jsx
│ │ │ └── TypesTab.jsx
│ │ ├── FloatingControls.jsx
│ │ ├── LexicalEditor/
│ │ │ ├── AutoLinkPlugin.jsx
│ │ │ ├── CodeHighlightPlugin.jsx
│ │ │ ├── ListMaxIndentLevelPlugin.jsx
│ │ │ ├── RichEditor.jsx
│ │ │ ├── ToolbarPlugin.jsx
│ │ │ └── styles/
│ │ │ └── index.css
│ │ ├── Navbar.jsx
│ │ ├── SimpleCanvas.jsx
│ │ ├── SortableList/
│ │ │ ├── DragHandle.jsx
│ │ │ ├── SortableItem.jsx
│ │ │ └── SortableList.jsx
│ │ ├── Thumbnail.jsx
│ │ └── Workspace.jsx
│ ├── context/
│ │ ├── AreasContext.jsx
│ │ ├── CanvasContext.jsx
│ │ ├── DiagramContext.jsx
│ │ ├── EnumsContext.jsx
│ │ ├── LayoutContext.jsx
│ │ ├── NotesContext.jsx
│ │ ├── SaveStateContext.jsx
│ │ ├── SelectContext.jsx
│ │ ├── SettingsContext.jsx
│ │ ├── TransformContext.jsx
│ │ ├── TypesContext.jsx
│ │ └── UndoRedoContext.jsx
│ ├── data/
│ │ ├── constants.js
│ │ ├── databases.js
│ │ ├── datatypes.js
│ │ ├── db.js
│ │ ├── editorConfig.js
│ │ ├── heroDiagram.js
│ │ ├── schemas.js
│ │ ├── seeds.js
│ │ ├── socials.js
│ │ └── surveyQuestions.js
│ ├── hooks/
│ │ ├── index.js
│ │ ├── useAreas.js
│ │ ├── useCanvas.js
│ │ ├── useDiagram.js
│ │ ├── useEnums.js
│ │ ├── useFullscreen.js
│ │ ├── useLayout.js
│ │ ├── useNotes.js
│ │ ├── useSaveState.js
│ │ ├── useSelect.js
│ │ ├── useSettings.js
│ │ ├── useThemedPage.js
│ │ ├── useTransform.js
│ │ ├── useTypes.js
│ │ └── useUndoRedo.js
│ ├── i18n/
│ │ ├── i18n.js
│ │ ├── locales/
│ │ │ ├── ar.js
│ │ │ ├── as.js
│ │ │ ├── bg.js
│ │ │ ├── bn.js
│ │ │ ├── cz.js
│ │ │ ├── da.js
│ │ │ ├── de.js
│ │ │ ├── el.js
│ │ │ ├── en.js
│ │ │ ├── es.js
│ │ │ ├── fa.js
│ │ │ ├── fi.js
│ │ │ ├── fr.js
│ │ │ ├── gu.js
│ │ │ ├── he.js
│ │ │ ├── hi.js
│ │ │ ├── hu.js
│ │ │ ├── hy.js
│ │ │ ├── id.js
│ │ │ ├── it.js
│ │ │ ├── jp.js
│ │ │ ├── ka.js
│ │ │ ├── ko.js
│ │ │ ├── ml.js
│ │ │ ├── mn.js
│ │ │ ├── mr.js
│ │ │ ├── ms.js
│ │ │ ├── ne.js
│ │ │ ├── nl.js
│ │ │ ├── no.js
│ │ │ ├── od.js
│ │ │ ├── pa-pk.js
│ │ │ ├── pa.js
│ │ │ ├── pl.js
│ │ │ ├── pt-br.js
│ │ │ ├── ro.js
│ │ │ ├── ru.js
│ │ │ ├── sd.js
│ │ │ ├── sv-se.js
│ │ │ ├── sw.js
│ │ │ ├── te.js
│ │ │ ├── th.js
│ │ │ ├── tl.js
│ │ │ ├── tm.js
│ │ │ ├── tr.js
│ │ │ ├── ug.js
│ │ │ ├── uk.js
│ │ │ ├── ur.js
│ │ │ ├── vi.js
│ │ │ ├── zh-tw.js
│ │ │ └── zh.js
│ │ └── utils/
│ │ └── rtl.js
│ ├── icons/
│ │ ├── IconAddArea.jsx
│ │ ├── IconAddNote.jsx
│ │ ├── IconAddTable.jsx
│ │ └── index.js
│ ├── index.css
│ ├── main.jsx
│ ├── pages/
│ │ ├── BugReport.jsx
│ │ ├── Editor.jsx
│ │ ├── LandingPage.jsx
│ │ ├── NotFound.jsx
│ │ └── Templates.jsx
│ ├── templates/
│ │ ├── template1.js
│ │ ├── template2.js
│ │ ├── template3.js
│ │ ├── template4.js
│ │ ├── template5.js
│ │ └── template6.js
│ └── utils/
│ ├── arrangeTables.js
│ ├── cache.js
│ ├── calcPath.js
│ ├── diff.js
│ ├── exportAs/
│ │ ├── dbml.js
│ │ ├── documentation.js
│ │ └── mermaid.js
│ ├── exportSQL/
│ │ ├── generic.js
│ │ ├── index.js
│ │ ├── mariadb.js
│ │ ├── mssql.js
│ │ ├── mysql.js
│ │ ├── oraclesql.js
│ │ ├── postgres.js
│ │ ├── shared.js
│ │ └── sqlite.js
│ ├── exportSavedData.js
│ ├── fullscreen.js
│ ├── importFrom/
│ │ └── dbml.js
│ ├── importSQL/
│ │ ├── index.js
│ │ ├── mariadb.js
│ │ ├── mssql.js
│ │ ├── mysql.js
│ │ ├── oraclesql.js
│ │ ├── postgres.js
│ │ ├── shared.js
│ │ └── sqlite.js
│ ├── issues.js
│ ├── migrations/
│ │ └── diffToSQL.js
│ ├── modalData.js
│ ├── rect.js
│ ├── utils.js
│ └── validateSchema.js
├── tailwind.config.js
├── vercel.json
└── vite.config.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .dockerignore
================================================
# Ignore node_modules
node_modules
# Ignore logs
*.log
logs
*.log.*
# Ignore environment variables
.env
# Ignore build directories and files
dist
build
# Ignore temporary files and directories
tmp
temp
*.tmp
*.swp
*.swo
*.bak
# Ignore Docker-related files
Dockerfile*
docker-compose.yml
# Ignore IDE/editor specific files
.vscode
.idea
*.iml
*.sublime-project
*.sublime-workspace
# Ignore OS-specific files
.DS_Store
================================================
FILE: .eslintrc.cjs
================================================
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"prettier",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
settings: { react: { version: "18.2" } },
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"react/prop-types": 0,
"react-refresh/only-export-components": "off",
},
};
================================================
FILE: .github/FUNDING.yml
================================================
github: 1ilit
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
**Additional context**
Add any other context about the problem here. If the bug involves the import feature, please, attach the imported file.
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: Feature request
about: Suggest an idea for this project
title: "[FEATURE]"
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Additional context**
Add any other context or screenshots about the feature request here.
================================================
FILE: .github/workflows/build.yml
================================================
name: Build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [ opened, synchronize, reopened ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- name: Run eslint
run: npm run lint
- name: Run vite build
run: npm run build
================================================
FILE: .github/workflows/docker.yml
================================================
name: Docker Build and Push
on:
push:
tags:
- "*"
concurrency:
group: "docker-image"
cancel-in-progress: false
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ github.ref_name }}
platforms: linux/amd64,linux/arm64
================================================
FILE: .gitignore
================================================
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.env
================================================
FILE: .prettierrc.json
================================================
{
"singleQuote": false,
"arrowParens": "always",
"trailingComma": "all",
"tabWidth": 2,
"semi": true
}
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing to drawDB
Thanks for taking the time to contribute!
The following is a set of guidelines for contributing to our project. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
## Table of Contents
1. [How Can I Contribute?](#how-can-i-contribute)
- [Reporting Bugs](#reporting-bugs)
- [Suggesting Enhancements](#suggesting-enhancements)
- [Submitting Pull Requests](#submitting-pull-requests)
2. [Style Guides](#style-guides)
- [Git Commit Messages](#git-commit-messages)
- [Style Guide](#style-guide)
3. [Additional Notes](#additional-notes)
- [Issue and Pull Request Labels](#issue-and-pull-request-labels)
- [Getting Help](#getting-help)
## How Can I Contribute?
### Reporting Bugs
This section guides you through submitting a bug report for our project. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.
- Use a clear and descriptive title for the issue to identify the problem.
- Describe the exact steps which reproduce the problem in as many details as possible.
- Provide specific examples to demonstrate the steps (e.g. if you're having trouble importing a file please attach it or provide a link to it).
- Include screenshots if applicable.
- Explain which behavior you expected to see instead and why.
### Suggesting Enhancements
This section guides you through submitting an enhancement suggestion for our project, including completely new features and minor improvements to existing functionality.
- Use a clear and descriptive title for the issue to identify the suggestion.
- Explain why this enhancement would be useful to most users.
### Submitting Pull Requests
If you would like to implement a big feature that has not been discussed before please reach out to the maintainer on Discord at @dottle_ or send an email to drawdb@outlook.com.
Please follow these steps to have your contribution considered by the maintainers:
1. Make sure the pull request you work on is atomic. That is, it implements a single feature or fixes a single bug.
2. Fork the repository and create your branch from `main`.
3. Write clear, descriptive commit messages.
4. Ensure your code adheres to the project's style guides.
5. Create a pull request.
6. Make sure to explain what your pull request solves unless it fixes something already explained in an issue that it's linked to.
7. Explain the solution. If you implement a more involved feature explain the design decisions.
## Style Guides
### Git Commit Messages
- Use the present tense (e.g. "Add Spanish locale" not "Added Spanish locale").
- Use the imperative mood (e.g. "Move cursor to..." not "Moves cursor to...").
- Reference issues and pull requests liberally after the first line.
### Style Guide
- Format your code with Prettier.
- Ensure your code passes ESLint.
- Make sure the code base is in English, this includes comments and variable names.
## Additional Notes
### Issue and Pull Request Labels
This section lists the labels we use to help organize and identify issues and pull requests.
- `bug`: Something isn't working.
- `enhancement`: New feature or request.
- `question`: Further information is requested.
- `documentation`: Improvements or additions to documentation.
- `good first issue`: Good for newcomers.
- `help wanted`: Extra attention is needed.
### Getting Help
If you have any questions, please feel free to reach out to us through the following channels:
- [Discord](https://discord.gg/BrjZgNrmR6)
- [Email](drawdb@outlook.com)
---
Thank you for your contributions! ❤️
================================================
FILE: Dockerfile
================================================
# Stage 1: Build the app
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
ENV NODE_OPTIONS="--max-old-space-size=4096"
RUN npm run build
# Stage 2: Setup the Nginx Server to serve the app
FROM docker.io/library/nginx:stable-alpine3.17 AS production
COPY --from=build /app/dist /usr/share/nginx/html
RUN echo 'server { listen 80; server_name _; root /usr/share/nginx/html; location / { try_files $uri /index.html; } }' > /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
================================================
FILE: LICENSE
================================================
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
================================================
FILE: README.md
================================================
<div align="center">
<sup>Special thanks to:</sup>
<br>
<a href="https://www.warp.dev/drawdb/" target="_blank">
<img alt="Warp sponsorship" width="280" src="https://github.com/user-attachments/assets/c7f141e7-9751-407d-bb0e-d6f2c487b34f">
<br>
<b>Next-gen AI-powered intelligent terminal for all platforms</b>
</a>
</div>
<br/>
<br/>
<div align="center">
<img width="64" alt="drawdb logo" src="./src/assets/icon-dark.png">
<h1>drawDB</h1>
</div>
<h3 align="center">Free, simple, and intuitive database schema editor and SQL generator.</h3>
<div align="center" style="margin-bottom:12px;">
<a href="https://drawdb.app/" style="display: flex; align-items: center;">
<img src="https://img.shields.io/badge/Start%20building-grey" alt="drawDB"/>
</a>
<a href="https://discord.gg/BrjZgNrmR6" style="display: flex; align-items: center;">
<img src="https://img.shields.io/discord/1196658537208758412.svg?label=Join%20the%20Discord&logo=discord" alt="Discord"/>
</a>
<a href="https://x.com/drawDB_" style="display: flex; align-items: center;">
<img src="https://img.shields.io/badge/Follow%20us%20on%20X-blue?logo=X" alt="Follow us on X"/>
</a>
<a href="https://getmanta.ai/drawdb">
<img src="https://getmanta.ai/api/badges?text=Manta%20Graph&link=drawdb" alt="DrawDB graph on Manta">
</a>
</div>
<h3 align="center"><img width="700" style="border-radius:5px;" alt="demo" src="drawdb.png"></h3>
DrawDB is a robust and user-friendly database entity relationship (DBER) editor right in your browser. Build diagrams with a few clicks, export sql scripts, customize your editor, and more without creating an account. See the full set of features [here](https://drawdb.app/).
## Getting Started
### Local Development
```bash
git clone https://github.com/drawdb-io/drawdb
cd drawdb
npm install
npm run dev
```
### Build
```bash
git clone https://github.com/drawdb-io/drawdb
cd drawdb
npm install
npm run build
```
### Docker Build
```bash
docker build -t drawdb .
docker run -p 3000:80 drawdb
```
If you want to enable sharing, set up the [server](https://github.com/drawdb-io/drawdb-server) and environment variables according to `.env.sample`. This is optional unless you need to share files..
================================================
FILE: compose.yml
================================================
services:
drawdb:
image: node:20-alpine
container_name: drawdb
ports:
- 5173:5173
working_dir: /var/www/html
volumes:
- ./:/var/www/html
command: sh -c "npm install && npm run dev -- --host"
networks:
- default
networks:
default:
driver: bridge
================================================
FILE: index.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Online database entity-realtionship diagram editor, data modeler, and SQL generator. Design, visualize, and export scripts without an account and completely free of charge."
/>
<meta name="robots" content="index,follow,max-image-preview:large" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://drawdb.app/" />
<meta
property="og:title"
content="drawDB | Online database diagram editor and SQL generator"
/>
<meta
property="og:description"
content="Online database entity-realtionship diagram editor, data modeler, and SQL generator. Design, visualize, and export scripts without an account and completely free of charge."
/>
<meta property="og:image" content="https://drawdb.app/hero_ss.png" />
<meta
name="twitter:image:src"
content="https://drawdb.app/hero_ss.png"
/>
<meta
name="twitter:tile:image"
content="https://drawdb.app/hero_ss.png"
/>
<meta name="twitter:card" content="summary_large_image" />
<link rel="apple-touch-icon" href="/favicon.ico" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<title>drawDB | Online database diagram editor and SQL generator</title>
</head>
<body theme-mode="light">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
================================================
FILE: package.json
================================================
{
"name": "drawdb",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@dbml/core": "^3.13.9",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@douyinfe/semi-ui": "^2.77.1",
"@lexical/react": "^0.12.5",
"@monaco-editor/react": "^4.7.0",
"@vercel/analytics": "^1.2.2",
"axios": "^1.13.5",
"dexie": "^3.2.4",
"dexie-react-hooks": "^1.1.7",
"file-saver": "^2.0.5",
"framer-motion": "^10.18.0",
"html-to-image": "1.11.11",
"i18next": "^23.11.4",
"i18next-browser-languagedetector": "^8.0.0",
"jsonschema": "^1.4.1",
"jspdf": "^4.2.1",
"jszip": "^3.10.1",
"lexical": "^0.12.5",
"lodash": "^4.17.23",
"luxon": "^3.7.1",
"nanoid": "^5.1.5",
"node-sql-parser": "^5.4.0",
"oracle-sql-parser": "^0.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hotkeys-hook": "^4.4.1",
"react-i18next": "^14.1.1",
"react-router-dom": "^6.30.3",
"react-tweet": "^3.2.1",
"usehooks-ts": "^3.1.0"
},
"devDependencies": {
"@tailwindcss/postcss": "^4.0.14",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"postcss": "^8.4.32",
"prettier": "3.2.5",
"tailwindcss": "^4.0.14",
"vite": "^6.4.1"
}
}
================================================
FILE: postcss.config.js
================================================
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
================================================
FILE: public/robots.txt
================================================
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Allow: /
Allow: /editor
Allow: /templates
Disallow: /bug-report
================================================
FILE: src/App.jsx
================================================
import { BrowserRouter, Routes, Route, useLocation } from "react-router-dom";
import { useLayoutEffect } from "react";
import Editor from "./pages/Editor";
import BugReport from "./pages/BugReport";
import Templates from "./pages/Templates";
import LandingPage from "./pages/LandingPage";
import SettingsContextProvider from "./context/SettingsContext";
import NotFound from "./pages/NotFound";
export default function App() {
return (
<SettingsContextProvider>
<BrowserRouter>
<RestoreScroll />
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/editor" element={<Editor />} />
<Route path="/editor/diagrams/:id" element={<Editor />} />
<Route path="/editor/templates/:id" element={<Editor />} />
<Route path="/bug-report" element={<BugReport />} />
<Route path="/templates" element={<Templates />} />
<Route path="*" element={<NotFound />} />
</Routes>
</BrowserRouter>
</SettingsContextProvider>
);
}
function RestoreScroll() {
const location = useLocation();
useLayoutEffect(() => {
window.scroll(0, 0);
}, [location.pathname]);
return null;
}
================================================
FILE: src/animations/FadeIn.jsx
================================================
import { useRef, useEffect } from "react";
import { motion, useInView, useAnimation } from "framer-motion";
export default function FadeIn({ children, duration }) {
const ref = useRef(null);
const isInView = useInView(ref, { once: true });
const mainControls = useAnimation();
useEffect(() => {
if (isInView) {
mainControls.start("visible");
}
}, [isInView, mainControls]);
return (
<div ref={ref}>
<motion.div
variants={{
hidden: { opacity: 0 },
visible: { opacity: 1 },
}}
initial="hidden"
animate={mainControls}
transition={{ duration }}
>
{children}
</motion.div>
</div>
);
}
================================================
FILE: src/animations/SlideIn.jsx
================================================
import { useRef, useEffect } from "react";
import { motion, useInView, useAnimation } from "framer-motion";
export default function SlideIn({ children, duration, delay, className }) {
const ref = useRef(null);
const isInView = useInView(ref, { once: true });
const mainControls = useAnimation();
useEffect(() => {
if (isInView) {
mainControls.start("visible");
}
}, [isInView, mainControls]);
return (
<div ref={ref} className={className}>
<motion.div
variants={{
hidden: { opacity: 0, x: -60 },
visible: { opacity: 1, x: 0 },
}}
initial="hidden"
animate={mainControls}
transition={{ duration, delay }}
className="h-full"
>
{children}
</motion.div>
</div>
);
}
================================================
FILE: src/api/email.js
================================================
import axios from "axios";
export async function send(subject, message, attachments) {
return await axios.post(`${import.meta.env.VITE_BACKEND_URL}/email/send`, {
subject,
message,
attachments,
});
}
================================================
FILE: src/api/gists.js
================================================
import axios from "axios";
export const SHARE_FILENAME = "share.json";
export const VERSION_FILENAME = "versionned.json";
const description = "drawDB diagram";
const baseUrl = import.meta.env.VITE_BACKEND_URL;
export async function create(filename, content) {
const res = await axios.post(`${baseUrl}/gists`, {
public: false,
filename,
description,
content,
});
return res.data.data.id;
}
export async function patch(gistId, filename, content) {
const { data } = await axios.patch(`${baseUrl}/gists/${gistId}`, {
filename,
content,
});
return data.deleted;
}
export async function del(gistId) {
await axios.delete(`${baseUrl}/gists/${gistId}`);
}
export async function get(gistId) {
const res = await axios.get(`${baseUrl}/gists/${gistId}`);
return res.data;
}
export async function getCommits(gistId, perPage = 20, page = 1) {
const res = await axios.get(`${baseUrl}/gists/${gistId}/commits`, {
params: {
per_page: perPage,
page,
},
});
return res.data;
}
export async function getVersion(gistId, sha) {
const res = await axios.get(`${baseUrl}/gists/${gistId}/${sha}`);
return res.data;
}
export async function getCommitsWithFile(
gistId,
file,
limit = 10,
cursor = null,
) {
const res = await axios.get(
`${baseUrl}/gists/${gistId}/file-versions/${file}`,
{
params: {
limit,
cursor,
},
},
);
return res.data;
}
export async function compare(gistId, file, versionA, versionB) {
const res = await axios.get(
`${baseUrl}/gists/${gistId}/file/${file}/compare/${versionA}/${versionB}`,
);
return res.data;
}
================================================
FILE: src/components/CodeEditor/index.jsx
================================================
import { useState } from "react";
import { Editor } from "@monaco-editor/react";
import { useDiagram, useSettings } from "../../hooks";
import { Button } from "@douyinfe/semi-ui";
import { useTranslation } from "react-i18next";
import { IconCopy, IconTick } from "@douyinfe/semi-icons";
import { setUpDBML } from "./setUpDBML";
export default function CodeEditor({
showCopyButton,
extraControls,
filename,
className = "",
...props
}) {
const { settings } = useSettings();
const { database } = useDiagram();
const { t } = useTranslation();
const [copied, setCopied] = useState(false);
const copyCode = () => {
navigator.clipboard
.writeText(props.value)
.then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 3000);
})
.catch((e) => console.error(e));
};
const handleEditorMount = (editor, monaco) => {
setUpDBML(monaco, database);
setTimeout(() => {
editor.getAction("editor.action.formatDocument").run();
}, 300);
};
return (
<div className={`relative h-full ${className}`}>
{filename && (
<div
className={`px-4 py-2 rounded-t-md text-xs flex justify-between items-center ${
settings.mode === "dark"
? "bg-neutral-800 text-gray-50"
: "bg-gray-100 text-gray-800"
}`}
>
<div>{filename}</div>
<button
onClick={copyCode}
className="flex items-center gap-1 hover:opacity-80"
>
<i className={`bi ${copied ? "bi-check2" : "bi-copy"} me-1`} />
{t("copy")}
</button>
</div>
)}
<Editor
{...props}
theme={settings.mode === "light" ? "vs" : "vs-dark"}
onMount={handleEditorMount}
/>
{showCopyButton && (
<div className="absolute flex flex-col right-6 bottom-2 z-10 space-y-2">
{extraControls}
<Button
icon={copied ? <IconTick /> : <IconCopy />}
onClick={copyCode}
className="inline-block"
/>
</div>
)}
</div>
);
}
================================================
FILE: src/components/CodeEditor/setUpDBML.js
================================================
import { dbToTypes } from "../../data/datatypes";
export function setUpDBML(monaco, database) {
monaco.languages.register({ id: "dbml" });
monaco.languages.setMonarchTokensProvider("dbml", {
defaultToken: "",
tokenPostfix: ".dbml",
ignoreCase: true,
keywords: [
"table",
"tablegroup",
"project",
"enum",
"ref",
"as",
"indexes",
"index",
"note",
"delete",
"update",
"pk",
"increment",
"not",
"null",
"unique",
"default",
],
typeKeywords: Object.keys(dbToTypes[database]),
operators: [
"=",
">",
"<",
"!",
"~",
"?",
":",
"==",
"<=",
">=",
"!=",
"&&",
"||",
"++",
"--",
"+",
"-",
"*",
"/",
"&",
"|",
"^",
],
symbols: /[=><!~?:&|+\-*/^%]+/,
escapes:
/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
tokenizer: {
root: [
[
/[a-zA-Z_$][\w$]*/,
{
cases: {
"@keywords": "keyword",
"@typeKeywords": "type",
"@default": "identifier",
},
},
],
{ include: "@whitespace" },
[/[{}()[\]]/, "@brackets"],
[/[<>](?!@symbols)/, "@brackets"],
[
/@symbols/,
{
cases: {
"@operators": "operator",
"@default": "",
},
},
],
[/\d*\.\d+([eE][-+]?\d+)?/, "number.float"],
[/0[xX][0-9a-fA-F]+/, "number.hex"],
[/\d+/, "number"],
[/[;,.]/, "delimiter"],
[/"([^"\\]|\\.)*$/, "string.invalid"],
[/'([^'\\]|\\.)*$/, "string.invalid"],
[/"/, { token: "string.quote", bracket: "@open", next: "@dqstring" }],
[/'/, { token: "string.quote", bracket: "@open", next: "@sqstring" }],
],
dqstring: [
[/[^\\"]+/, "string"],
[/@escapes/, "string.escape"],
[/\\./, "string.escape.invalid"],
[/"/, { token: "string.quote", bracket: "@close", next: "@pop" }],
],
sqstring: [
[/[^\\']+/, "string"],
[/@escapes/, "string.escape"],
[/\\./, "string.escape.invalid"],
[/'/, { token: "string.quote", bracket: "@close", next: "@pop" }],
],
comment: [
[/[^\\/*]+/, "comment"],
[/\/\*/, "comment", "@push"],
["\\*/", "comment", "@pop"],
[/[\\/*]/, "comment"],
],
whitespace: [
[/[ \t\r\n]+/, "white"],
[/\/\*/, "comment", "@comment"],
[/\/\/.*$/, "comment"],
],
},
});
monaco.languages.setLanguageConfiguration("dbml", {
comments: {
lineComment: "//",
blockComment: ["/*", "*/"],
},
brackets: [
["{", "}"],
["[", "]"],
["(", ")"],
],
autoClosingPairs: [
{ open: "{", close: "}" },
{ open: "[", close: "]" },
{ open: "(", close: ")" },
{ open: '"', close: '"' },
{ open: "'", close: "'" },
],
surroundingPairs: [
{ open: "{", close: "}" },
{ open: "[", close: "]" },
{ open: "(", close: ")" },
{ open: '"', close: '"' },
{ open: "'", close: "'" },
],
});
}
================================================
FILE: src/components/EditorCanvas/Area.jsx
================================================
import { useMemo, useRef, useState } from "react";
import { Button, Popover, Input } from "@douyinfe/semi-ui";
import ColorPicker from "../EditorSidePanel/ColorPicker";
import {
IconEdit,
IconDeleteStroked,
IconLock,
IconUnlock,
} from "@douyinfe/semi-icons";
import { Tab, Action, ObjectType, State } from "../../data/constants";
import {
useLayout,
useSettings,
useUndoRedo,
useSelect,
useAreas,
useSaveState,
} from "../../hooks";
import { useTranslation } from "react-i18next";
import { useHover } from "usehooks-ts";
export default function Area({
data,
onPointerDown,
setResize,
setInitDimensions,
}) {
const ref = useRef(null);
const isHovered = useHover(ref);
const { layout } = useLayout();
const { settings } = useSettings();
const { setSaveState } = useSaveState();
const { updateArea } = useAreas();
const {
selectedElement,
setSelectedElement,
bulkSelectedElements,
setBulkSelectedElements,
} = useSelect();
const handleResize = (e, dir) => {
setResize({ id: data.id, dir: dir });
setInitDimensions({
x: data.x,
y: data.y,
width: data.width,
height: data.height,
});
};
const lockUnlockArea = (e) => {
const locking = !data.locked;
updateArea(data.id, { locked: locking });
const lockArea = () => {
setSelectedElement({
...selectedElement,
element: ObjectType.NONE,
id: -1,
open: false,
});
setBulkSelectedElements((prev) =>
prev.filter((el) => el.id !== data.id || el.type !== ObjectType.AREA),
);
};
const unlockArea = () => {
const elementInBulk = {
id: data.id,
type: ObjectType.AREA,
initialCoords: { x: data.x, y: data.y },
currentCoords: { x: data.x, y: data.y },
};
if (e.ctrlKey || e.metaKey) {
setBulkSelectedElements((prev) => [...prev, elementInBulk]);
} else {
setBulkSelectedElements([elementInBulk]);
}
setSelectedElement((prev) => ({
...prev,
element: ObjectType.AREA,
id: data.id,
open: false,
}));
};
if (locking) {
lockArea();
} else {
unlockArea();
}
};
const edit = () => {
if (layout.sidebar) {
setSelectedElement((prev) => ({
...prev,
element: ObjectType.AREA,
id: data.id,
currentTab: Tab.AREAS,
open: true,
}));
if (selectedElement.currentTab !== Tab.AREAS) return;
document
.getElementById(`scroll_area_${data.id}`)
.scrollIntoView({ behavior: "smooth" });
} else {
setSelectedElement((prev) => ({
...prev,
element: ObjectType.AREA,
id: data.id,
open: true,
}));
}
};
const onClickOutSide = () => {
if (selectedElement.editFromToolbar) {
setSelectedElement((prev) => ({
...prev,
editFromToolbar: false,
}));
return;
}
setSelectedElement((prev) => ({
...prev,
open: false,
}));
setSaveState(State.SAVING);
};
const areaIsOpen = () =>
selectedElement.element === ObjectType.AREA &&
selectedElement.id === data.id &&
selectedElement.open;
const isSelected = useMemo(() => {
return (
(selectedElement.id === data.id &&
selectedElement.element === ObjectType.AREA) ||
bulkSelectedElements.some(
(e) => e.type === ObjectType.AREA && e.id === data.id,
)
);
}, [selectedElement, data, bulkSelectedElements]);
return (
<g ref={ref}>
<foreignObject
key={data.id}
x={data.x}
y={data.y}
width={data.width > 0 ? data.width : 0}
height={data.height > 0 ? data.height : 0}
onPointerDown={onPointerDown}
>
<div
className={`w-full h-full p-2 rounded cursor-move border-2 ${
isHovered
? "border-dashed border-blue-500"
: isSelected
? "border-blue-500 opacity-100"
: "border-slate-400 opacity-100"
}`}
style={{ backgroundColor: `${data.color}66` }}
onDoubleClick={edit}
>
<div className="flex justify-between gap-1 w-full">
<div className="text-color select-none overflow-hidden text-ellipsis">
{data.name}
</div>
{(isHovered || (areaIsOpen() && !layout.sidebar)) && (
<div className="flex items-center gap-1.5">
<Button
icon={data.locked ? <IconLock /> : <IconUnlock />}
size="small"
theme="solid"
style={{
backgroundColor: "#2F68ADB3",
}}
onClick={lockUnlockArea}
disabled={layout.readOnly}
/>
<Popover
visible={areaIsOpen() && !layout.sidebar}
onClickOutSide={onClickOutSide}
stopPropagation
content={<EditPopoverContent data={data} />}
trigger="custom"
position="rightTop"
showArrow
>
<Button
icon={<IconEdit />}
size="small"
theme="solid"
style={{
backgroundColor: "#2F68ADB3",
}}
onClick={edit}
/>
</Popover>
</div>
)}
</div>
</div>
</foreignObject>
{isHovered && (
<>
<circle
cx={data.x}
cy={data.y}
r={6}
fill={settings.mode === "light" ? "white" : "rgb(28, 31, 35)"}
stroke="#5891db"
strokeWidth={2}
cursor="nwse-resize"
onPointerDown={(e) => e.isPrimary && handleResize(e, "tl")}
/>
<circle
cx={data.x + data.width}
cy={data.y}
r={6}
fill={settings.mode === "light" ? "white" : "rgb(28, 31, 35)"}
stroke="#5891db"
strokeWidth={2}
cursor="nesw-resize"
onPointerDown={(e) => e.isPrimary && handleResize(e, "tr")}
/>
<circle
cx={data.x}
cy={data.y + data.height}
r={6}
fill={settings.mode === "light" ? "white" : "rgb(28, 31, 35)"}
stroke="#5891db"
strokeWidth={2}
cursor="nesw-resize"
onPointerDown={(e) => e.isPrimary && handleResize(e, "bl")}
/>
<circle
cx={data.x + data.width}
cy={data.y + data.height}
r={6}
fill={settings.mode === "light" ? "white" : "rgb(28, 31, 35)"}
stroke="#5891db"
strokeWidth={2}
cursor="nwse-resize"
onPointerDown={(e) => e.isPrimary && handleResize(e, "br")}
/>
</>
)}
</g>
);
}
function EditPopoverContent({ data }) {
const [editField, setEditField] = useState({});
const { updateArea, deleteArea } = useAreas();
const { setUndoStack, setRedoStack } = useUndoRedo();
const { t } = useTranslation();
const { layout } = useLayout();
const initialColorRef = useRef(data.color);
const handleColorPick = (color) => {
setUndoStack((prev) => {
let undoColor = initialColorRef.current;
const lastColorChange = prev.findLast(
(e) =>
e.element === ObjectType.AREA &&
e.aid === data.id &&
e.action === Action.EDIT &&
e.redo?.color,
);
if (lastColorChange) {
undoColor = lastColorChange.redo.color;
}
if (color === undoColor) return prev;
const newStack = [
...prev,
{
action: Action.EDIT,
element: ObjectType.AREA,
aid: data.id,
undo: { color: undoColor },
redo: { color: color },
message: t("edit_area", {
areaName: data.name,
extra: "[color]",
}),
},
];
return newStack;
});
setRedoStack([]);
};
return (
<div className="popover-theme">
<div className="font-semibold mb-2 ms-1">{t("edit")}</div>
<div className="w-[280px] flex items-center mb-2">
<Input
value={data.name}
placeholder={t("name")}
className="me-2"
readonly={layout.readOnly}
onChange={(value) => updateArea(data.id, { name: value })}
onFocus={(e) => setEditField({ name: e.target.value })}
onBlur={(e) => {
if (e.target.value === editField.name) return;
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.AREA,
aid: data.id,
undo: editField,
redo: { name: e.target.value },
message: t("edit_area", {
areaName: e.target.value,
extra: "[name]",
}),
},
]);
setRedoStack([]);
}}
/>
<ColorPicker
usePopover={true}
readOnly={layout.readOnly}
value={data.color}
onChange={(color) => updateArea(data.id, { color })}
onColorPick={(color) => handleColorPick(color)}
/>
</div>
<div className="flex">
<Button
icon={<IconDeleteStroked />}
type="danger"
block
onClick={() => deleteArea(data.id, true)}
disabled={layout.readOnly}
>
{t("delete")}
</Button>
</div>
</div>
);
}
================================================
FILE: src/components/EditorCanvas/Canvas.jsx
================================================
import { useRef, useState } from "react";
import {
Action,
Cardinality,
Constraint,
darkBgTheme,
ObjectType,
gridSize,
gridCircleRadius,
minAreaSize,
} from "../../data/constants";
import { Toast } from "@douyinfe/semi-ui";
import Table from "./Table";
import Area from "./Area";
import Relationship from "./Relationship";
import Note from "./Note";
import {
useCanvas,
useSettings,
useTransform,
useDiagram,
useUndoRedo,
useSelect,
useAreas,
useNotes,
useLayout,
useSaveState,
} from "../../hooks";
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 { nanoid } from "nanoid";
export default function Canvas() {
const { t } = useTranslation();
const canvasRef = useRef(null);
const canvasContextValue = useCanvas();
const {
canvas: { viewBox },
pointer,
} = canvasContextValue;
const { tables, updateTable, relationships, addRelationship, database } =
useDiagram();
const { setSaveState } = useSaveState();
const { areas, updateArea } = useAreas();
const { notes, updateNote } = useNotes();
const { layout } = useLayout();
const { settings } = useSettings();
const { setUndoStack, setRedoStack } = useUndoRedo();
const { transform, setTransform } = useTransform();
const {
selectedElement,
setSelectedElement,
bulkSelectedElements,
setBulkSelectedElements,
} = useSelect();
const notDragging = {
id: -1,
type: ObjectType.NONE,
grabOffset: { x: 0, y: 0 },
};
const [dragging, setDragging] = useState(notDragging);
const [linking, setLinking] = useState(false);
const [linkingLine, setLinkingLine] = useState({
startTableId: -1,
startFieldId: -1,
endTableId: -1,
endFieldId: -1,
startX: 0,
startY: 0,
endX: 0,
endY: 0,
});
const [hoveredTable, setHoveredTable] = useState({
tableId: null,
fieldId: null,
});
const [panning, setPanning] = useState({
isPanning: false,
panStart: { x: 0, y: 0 },
cursorStart: { x: 0, y: 0 },
});
const [areaResize, setAreaResize] = useState({ id: -1, dir: "none" });
const [areaInitDimensions, setAreaInitDimensions] = useState({
x: 0,
y: 0,
width: 0,
height: 0,
});
const [bulkSelectRect, setBulkSelectRect] = useState({
x1: 0,
y1: 0,
x2: 0,
y2: 0,
show: false,
ctrlKey: false,
metaKey: false,
});
// this is used to store the element that is clicked on
// at the moment, and shouldn't be a part of the state
let elementPointerDown = null;
const isSameElement = (el1, el2) => {
return el1.id === el2.id && el1.type === el2.type;
};
const collectSelectedElements = () => {
const rect = getRectFromEndpoints(bulkSelectRect);
const elements = [];
const shouldAddElement = (elementRect, element) => {
// if ctrl key is pressed, only add the elements that are not already selected
// can theoretically be optimized later if the selected elements is
// a map from id to element (after the ids are made unique)
return (
isInsideRect(elementRect, rect) &&
((!bulkSelectRect.ctrlKey && !bulkSelectRect.metaKey) ||
!bulkSelectedElements.some((el) => isSameElement(el, element)))
);
};
tables.forEach((table) => {
if (table.locked) return;
const element = {
id: table.id,
type: ObjectType.TABLE,
currentCoords: { x: table.x, y: table.y },
initialCoords: { x: table.x, y: table.y },
};
const tableRect = {
x: table.x,
y: table.y,
width: settings.tableWidth,
height: getTableHeight(
table,
settings.tableWidth,
settings.showComments,
),
};
if (shouldAddElement(tableRect, element)) {
elements.push(element);
}
});
areas.forEach((area) => {
if (area.locked) return;
const element = {
id: area.id,
type: ObjectType.AREA,
currentCoords: { x: area.x, y: area.y },
initialCoords: { x: area.x, y: area.y },
};
const areaRect = {
x: area.x,
y: area.y,
width: area.width,
height: area.height,
};
if (shouldAddElement(areaRect, element)) {
elements.push(element);
}
});
notes.forEach((note) => {
if (note.locked) return;
const element = {
id: note.id,
type: ObjectType.NOTE,
currentCoords: { x: note.x, y: note.y },
initialCoords: { x: note.x, y: note.y },
};
const noteRect = {
x: note.x,
y: note.y,
width: note.width ?? noteWidth,
height: note.height,
};
if (shouldAddElement(noteRect, element)) {
elements.push(element);
}
});
if (bulkSelectRect.ctrlKey || bulkSelectRect.metaKey) {
setBulkSelectedElements([...bulkSelectedElements, ...elements]);
} else {
setBulkSelectedElements(elements);
}
};
const handlePointerDownOnElement = (e, { element, type }) => {
if (selectedElement.open && !layout.sidebar) return;
if (!e.isPrimary) return;
if (!element.locked || !(e.ctrlKey || e.metaKey)) {
setSelectedElement((prev) => ({
...prev,
element: type,
id: element.id,
open: false,
}));
}
if (element.locked) {
if (!(e.ctrlKey || e.metaKey)) {
setBulkSelectedElements([]);
}
return;
}
setBulkSelectRect((prev) => ({
...prev,
show: false,
}));
// this is the object that will be added to the bulk selected elements
// if necessary
const elementInBulk = {
id: element.id,
type,
currentCoords: { x: element.x, y: element.y },
initialCoords: { x: element.x, y: element.y },
};
const isSelected = bulkSelectedElements.some((el) =>
isSameElement(el, elementInBulk),
);
if (e.ctrlKey || e.metaKey) {
if (isSelected) {
if (bulkSelectedElements.length > 1) {
setBulkSelectedElements(
bulkSelectedElements.filter(
(el) => !isSameElement(el, elementInBulk),
),
);
setSelectedElement({
...selectedElement,
element: ObjectType.NONE,
id: -1,
open: false,
});
}
} else {
setBulkSelectedElements([...bulkSelectedElements, elementInBulk]);
}
setDragging(notDragging);
return;
}
if (!isSelected) {
setBulkSelectedElements([elementInBulk]);
}
setDragging({
id: element.id,
type,
grabOffset: {
x: pointer.spaces.diagram.x - element.x,
y: pointer.spaces.diagram.y - element.y,
},
});
};
const coordinatesAfterSnappingToGrid = ({ x, y }) => {
if (settings.snapToGrid) {
return {
x: Math.round(x / gridSize) * gridSize,
y: Math.round(y / gridSize) * gridSize,
};
}
return { x, y };
};
/**
* @param {PointerEvent} e
*/
const handlePointerMove = (e) => {
if (selectedElement.open && !layout.sidebar) return;
if (!e.isPrimary) return;
if (panning.isPanning) {
setTransform((prev) => ({
...prev,
pan: {
x:
panning.panStart.x +
(panning.cursorStart.x - pointer.spaces.screen.x) / transform.zoom,
y:
panning.panStart.y +
(panning.cursorStart.y - pointer.spaces.screen.y) / transform.zoom,
},
}));
return;
}
if (layout.readOnly) return;
if (linking) {
setLinkingLine({
...linkingLine,
endX: pointer.spaces.diagram.x,
endY: pointer.spaces.diagram.y,
});
return;
}
if (isDragging()) {
const { x: mainElementFinalX, y: mainElementFinalY } =
coordinatesAfterSnappingToGrid({
x: pointer.spaces.diagram.x - dragging.grabOffset.x,
y: pointer.spaces.diagram.y - dragging.grabOffset.y,
});
const { currentCoords } = bulkSelectedElements.find((el) =>
isSameElement(el, dragging),
);
const deltaX = mainElementFinalX - currentCoords.x;
const deltaY = mainElementFinalY - currentCoords.y;
const newBulkSelectedElements = [];
bulkSelectedElements.forEach((el) => {
const elementFinalCoords = {
x: el.currentCoords.x + deltaX,
y: el.currentCoords.y + deltaY,
};
if (el.type === ObjectType.TABLE) {
updateTable(el.id, { ...elementFinalCoords });
}
if (el.type === ObjectType.AREA) {
updateArea(el.id, { ...elementFinalCoords });
}
if (el.type === ObjectType.NOTE) {
updateNote(el.id, { ...elementFinalCoords });
}
newBulkSelectedElements.push({
...el,
currentCoords: elementFinalCoords,
});
});
setBulkSelectedElements(newBulkSelectedElements);
return;
}
if (areaResize.id !== -1) {
if (areaResize.dir === "none") return;
let newDims = { ...areaInitDimensions };
setPanning((old) => ({ ...old, isPanning: false }));
const { x, y } = coordinatesAfterSnappingToGrid(pointer.spaces.diagram);
switch (areaResize.dir) {
case "br":
newDims.width = x - areaInitDimensions.x;
newDims.height = y - areaInitDimensions.y;
break;
case "tl":
newDims.x = x;
newDims.y = y;
newDims.width = areaInitDimensions.width - (x - areaInitDimensions.x);
newDims.height =
areaInitDimensions.height - (y - areaInitDimensions.y);
break;
case "tr":
newDims.y = y;
newDims.width = x - areaInitDimensions.x;
newDims.height =
areaInitDimensions.height - (y - areaInitDimensions.y);
break;
case "bl":
newDims.x = x;
newDims.width = areaInitDimensions.width - (x - areaInitDimensions.x);
newDims.height = y - areaInitDimensions.y;
break;
}
if (newDims.width <= minAreaSize) {
newDims.width = minAreaSize;
if (areaResize.dir === "tl" || areaResize.dir === "bl") {
newDims.x =
areaInitDimensions.x + areaInitDimensions.width - minAreaSize;
}
}
if (newDims.height <= minAreaSize) {
newDims.height = minAreaSize;
if (areaResize.dir === "tl" || areaResize.dir === "tr") {
newDims.y =
areaInitDimensions.y + areaInitDimensions.height - minAreaSize;
}
}
updateArea(areaResize.id, { ...newDims });
return;
}
if (bulkSelectRect.show) {
setBulkSelectRect((prev) => ({
...prev,
x2: pointer.spaces.diagram.x,
y2: pointer.spaces.diagram.y,
}));
}
};
/**
* @param {PointerEvent} e
*/
const handlePointerDown = (e) => {
if (!e.isPrimary) return;
// don't pan if the sidesheet for editing a table is open
if (
selectedElement.element === ObjectType.TABLE &&
selectedElement.open &&
!layout.sidebar
)
return;
const isMouseLeftButton = e.button === 0;
const isMouseMiddleButton = e.button === 1;
if (isMouseLeftButton) {
setBulkSelectRect({
x1: pointer.spaces.diagram.x,
y1: pointer.spaces.diagram.y,
x2: pointer.spaces.diagram.x,
y2: pointer.spaces.diagram.y,
show: elementPointerDown === null || !elementPointerDown.element.locked,
ctrlKey: e.ctrlKey,
metaKey: e.metaKey,
});
if (elementPointerDown !== null) {
handlePointerDownOnElement(e, elementPointerDown);
}
pointer.setStyle("crosshair");
} else if (isMouseMiddleButton) {
setPanning({
isPanning: true,
panStart: transform.pan,
// Diagram space depends on the current panning.
// Use screen space to avoid circular dependencies and undefined behavior.
cursorStart: pointer.spaces.screen,
});
pointer.setStyle("grabbing");
}
};
const isDragging = () => {
return dragging.type !== ObjectType.NONE && dragging.id !== -1;
};
const didDrag = () => {
if (!isDragging()) return false;
// checking any element is sufficient
const { currentCoords, initialCoords } = bulkSelectedElements[0];
return (
currentCoords.x !== initialCoords.x || currentCoords.y !== initialCoords.y
);
};
const didResize = (id) => {
return !(
areas[id].x === areaInitDimensions.x &&
areas[id].y === areaInitDimensions.y &&
areas[id].width === areaInitDimensions.width &&
areas[id].height === areaInitDimensions.height
);
};
const didPan = () =>
!(
transform.pan.x === panning.panStart.x &&
transform.pan.y === panning.panStart.y
);
/**
* @param {PointerEvent} e
*/
const handlePointerUp = (e) => {
if (selectedElement.open && !layout.sidebar) return;
if (!e.isPrimary) return;
if (didDrag()) {
setUndoStack((prev) => [
...prev,
{
action: Action.MOVE,
bulk: true,
message: t("bulk_update"),
elements: bulkSelectedElements.map((el) => ({
id: el.id,
type: el.type,
undo: el.initialCoords,
redo: el.currentCoords,
})),
},
]);
setRedoStack([]);
setBulkSelectedElements((prev) =>
prev.map((el) => ({
...el,
initialCoords: { ...el.currentCoords },
})),
);
}
if (bulkSelectRect.show) {
setBulkSelectRect((prev) => ({
...prev,
x2: pointer.spaces.diagram.x,
y2: pointer.spaces.diagram.y,
show: false,
}));
if (!isDragging()) {
collectSelectedElements();
}
}
setDragging(notDragging);
if (panning.isPanning && didPan()) {
setSaveState(State.SAVING);
}
setPanning((old) => ({ ...old, isPanning: false }));
pointer.setStyle("default");
if (linking) handleLinking();
setLinking(false);
if (areaResize.id !== -1 && didResize(areaResize.id)) {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.AREA,
aid: areaResize.id,
undo: {
...areas[areaResize.id],
x: areaInitDimensions.x,
y: areaInitDimensions.y,
width: areaInitDimensions.width,
height: areaInitDimensions.height,
},
redo: areas[areaResize.id],
message: t("edit_area", {
areaName: areas[areaResize.id].name,
extra: "[resize]",
}),
},
]);
setRedoStack([]);
}
setAreaResize({ id: -1, dir: "none" });
setAreaInitDimensions({
x: 0,
y: 0,
width: 0,
height: 0,
});
};
const handleGripField = () => {
setPanning((old) => ({ ...old, isPanning: false }));
setDragging(notDragging);
setLinking(true);
};
const getCardinality = (startField, endField) => {
const startIsUnique = startField.unique || startField.primary;
const endIsUnique = endField.unique || endField.primary;
if (startIsUnique && endIsUnique) {
return Cardinality.ONE_TO_ONE;
}
if (startIsUnique && !endIsUnique) {
return Cardinality.ONE_TO_MANY;
}
if (!startIsUnique && endIsUnique) {
return Cardinality.MANY_TO_ONE;
}
return Cardinality.ONE_TO_ONE;
};
const handleLinking = () => {
if (hoveredTable.tableId === null) return;
if (hoveredTable.fieldId === null) return;
const { fields: startTableFields, name: startTableName } = tables.find(
(t) => t.id === linkingLine.startTableId,
);
const startField = startTableFields.find(
(f) => f.id === linkingLine.startFieldId,
);
const { fields: endTableFields, name: endTableName } = tables.find(
(t) => t.id === hoveredTable.tableId,
);
const endField = endTableFields.find((f) => f.id === hoveredTable.fieldId);
if (!areFieldsCompatible(database, startField.type, endField.type)) {
Toast.info(t("cannot_connect"));
return;
}
if (
linkingLine.startTableId === hoveredTable.tableId &&
linkingLine.startFieldId === hoveredTable.fieldId
)
return;
const cardinality = getCardinality(startField, endField);
const newRelationship = {
...linkingLine,
cardinality,
endTableId: hoveredTable.tableId,
endFieldId: hoveredTable.fieldId,
updateConstraint: Constraint.NONE,
deleteConstraint: Constraint.NONE,
name: `fk_${startTableName}_${startField.name}_${endTableName}`,
id: nanoid(),
};
delete newRelationship.startX;
delete newRelationship.startY;
delete newRelationship.endX;
delete newRelationship.endY;
addRelationship(newRelationship);
};
useEventListener(
"wheel",
(e) => {
e.preventDefault();
if (e.ctrlKey || e.metaKey) {
// How "eager" the viewport is to
// center the cursor's coordinates
const eagernessFactor = 0.05;
setTransform((prev) => ({
pan: {
x:
prev.pan.x -
(pointer.spaces.diagram.x - prev.pan.x) *
eagernessFactor *
Math.sign(e.deltaY),
y:
prev.pan.y -
(pointer.spaces.diagram.y - prev.pan.y) *
eagernessFactor *
Math.sign(e.deltaY),
},
zoom: e.deltaY <= 0 ? prev.zoom * 1.05 : prev.zoom / 1.05,
}));
} else if (e.shiftKey) {
setTransform((prev) => ({
...prev,
pan: {
...prev.pan,
x: prev.pan.x + e.deltaY / prev.zoom,
},
}));
} else {
setTransform((prev) => ({
...prev,
pan: {
x: prev.pan.x + e.deltaX / prev.zoom,
y: prev.pan.y + e.deltaY / prev.zoom,
},
}));
}
},
canvasRef,
{ passive: false },
);
return (
<div className="grow h-full touch-none" id="canvas">
<div
className="w-full h-full"
style={{
cursor: pointer.style,
backgroundColor: settings.mode === "dark" ? darkBgTheme : "white",
}}
>
<svg
id="diagram"
ref={canvasRef}
onPointerMove={handlePointerMove}
onPointerDown={handlePointerDown}
onPointerUp={handlePointerUp}
className="absolute w-full h-full touch-none"
viewBox={`${viewBox.left} ${viewBox.top} ${viewBox.width} ${viewBox.height}`}
>
{settings.showGrid && (
<>
<defs>
<pattern
id="pattern-grid"
x={-gridCircleRadius}
y={-gridCircleRadius}
width={gridSize}
height={gridSize}
patternUnits="userSpaceOnUse"
patternContentUnits="userSpaceOnUse"
>
<circle
cx={gridCircleRadius}
cy={gridCircleRadius}
r={gridCircleRadius}
fill="rgb(99, 152, 191)"
opacity="1"
/>
</pattern>
</defs>
<rect
x={viewBox.left}
y={viewBox.top}
width={viewBox.width}
height={viewBox.height}
fill="url(#pattern-grid)"
/>
</>
)}
{areas.map((a) => (
<Area
key={a.id}
data={a}
setResize={setAreaResize}
setInitDimensions={setAreaInitDimensions}
onPointerDown={() => {
elementPointerDown = {
element: a,
type: ObjectType.AREA,
};
}}
/>
))}
{relationships.map((e) => (
<Relationship key={e.id} data={e} />
))}
{tables.map((table) => (
<Table
key={table.id}
tableData={table}
setHoveredTable={setHoveredTable}
handleGripField={handleGripField}
setLinkingLine={setLinkingLine}
onPointerDown={() => {
elementPointerDown = {
element: table,
type: ObjectType.TABLE,
};
}}
/>
))}
{linking && (
<path
d={`M ${linkingLine.startX} ${linkingLine.startY} L ${linkingLine.endX} ${linkingLine.endY}`}
stroke="red"
strokeDasharray="8,8"
className="pointer-events-none touch-none"
/>
)}
{notes.map((n) => (
<Note
key={n.id}
data={n}
onPointerDown={() => {
elementPointerDown = {
element: n,
type: ObjectType.NOTE,
};
}}
/>
))}
{bulkSelectRect.show && (
<rect
{...getRectFromEndpoints(bulkSelectRect)}
stroke="grey"
fill="grey"
fillOpacity={0.15}
strokeDasharray={10}
/>
)}
</svg>
</div>
{settings.showDebugCoordinates && (
<div className="fixed flex flex-col flex-wrap gap-6 bg-[rgba(var(--semi-grey-1),var(--tw-bg-opacity))]/40 border border-color bottom-4 right-4 p-4 rounded-xl backdrop-blur-xs pointer-events-none select-none">
<table className="table-auto grow">
<thead>
<tr>
<th className="text-left" colSpan={3}>
{t("transform")}
</th>
</tr>
<tr className="italic [&_th]:font-normal [&_th]:text-right">
<th>pan x</th>
<th>pan y</th>
<th>scale</th>
</tr>
</thead>
<tbody className="[&_td]:text-right [&_td]:min-w-[8ch]">
<tr>
<td>{transform.pan.x.toFixed(2)}</td>
<td>{transform.pan.y.toFixed(2)}</td>
<td>{transform.zoom.toFixed(4)}</td>
</tr>
</tbody>
</table>
<table className="table-auto grow [&_th]:text-left [&_th:not(:first-of-type)]:text-right [&_td:not(:first-of-type)]:text-right [&_td]:min-w-[8ch]">
<thead>
<tr>
<th colSpan={4}>{t("viewbox")}</th>
</tr>
<tr className="italic [&_th]:font-normal">
<th>left</th>
<th>top</th>
<th>width</th>
<th>height</th>
</tr>
</thead>
<tbody>
<tr>
<td>{viewBox.left.toFixed(2)}</td>
<td>{viewBox.top.toFixed(2)}</td>
<td>{viewBox.width.toFixed(2)}</td>
<td>{viewBox.height.toFixed(2)}</td>
</tr>
</tbody>
</table>
<table className="table-auto grow [&_th]:text-left [&_th:not(:first-of-type)]:text-right [&_td:not(:first-of-type)]:text-right [&_td]:min-w-[8ch]">
<thead>
<tr>
<th colSpan={3}>{t("cursor_coordinates")}</th>
</tr>
<tr className="italic [&_th]:font-normal">
<th>{t("coordinate_space")}</th>
<th>x</th>
<th>y</th>
</tr>
</thead>
<tbody>
<tr>
<td>{t("coordinate_space_screen")}</td>
<td>{pointer.spaces.screen.x.toFixed(2)}</td>
<td>{pointer.spaces.screen.y.toFixed(2)}</td>
</tr>
<tr>
<td>{t("coordinate_space_diagram")}</td>
<td>{pointer.spaces.diagram.x.toFixed(2)}</td>
<td>{pointer.spaces.diagram.y.toFixed(2)}</td>
</tr>
</tbody>
</table>
</div>
)}
</div>
);
}
================================================
FILE: src/components/EditorCanvas/Note.jsx
================================================
import { useMemo, useState, useRef, useEffect } from "react";
import { Action, ObjectType, Tab, State } from "../../data/constants";
import { Input, Button, Popover } from "@douyinfe/semi-ui";
import ColorPicker from "../EditorSidePanel/ColorPicker";
import {
IconEdit,
IconDeleteStroked,
IconLock,
IconUnlock,
} from "@douyinfe/semi-icons";
import {
useLayout,
useUndoRedo,
useSelect,
useNotes,
useSaveState,
useTransform,
useSettings,
} from "../../hooks";
import { useTranslation } from "react-i18next";
import { noteWidth, noteRadius, noteFold } from "../../data/constants";
export default function Note({ data, onPointerDown }) {
const [editField, setEditField] = useState({});
const [hovered, setHovered] = useState(false);
const [resizing, setResizing] = useState(false);
const initialWidthRef = useRef(data.width ?? noteWidth);
const initialXRef = useRef(data.x);
const { layout } = useLayout();
const { t } = useTranslation();
const { setSaveState } = useSaveState();
const { updateNote, deleteNote } = useNotes();
const { setUndoStack, setRedoStack } = useUndoRedo();
const { transform } = useTransform();
const { settings } = useSettings();
const {
selectedElement,
setSelectedElement,
bulkSelectedElements,
setBulkSelectedElements,
} = useSelect();
const initialColorRef = useRef(data.color);
const handleColorPick = (color) => {
setUndoStack((prev) => {
let undoColor = initialColorRef.current;
const lastColorChange = prev.findLast(
(e) =>
e.element === ObjectType.NOTE &&
e.nid === data.id &&
e.action === Action.EDIT &&
e.redo?.color,
);
if (lastColorChange) {
undoColor = lastColorChange.redo.color;
}
if (color === undoColor) return prev;
const newStack = [
...prev,
{
action: Action.EDIT,
element: ObjectType.NOTE,
nid: data.id,
undo: { color: undoColor },
redo: { color: color },
message: t("edit_note", {
noteTitle: data.title,
extra: "[color]",
}),
},
];
return newStack;
});
setRedoStack([]);
};
const handleChange = (e) => {
const textarea = document.getElementById(`note_${data.id}`);
if (!textarea) return;
textarea.style.height = "0";
textarea.style.height = textarea.scrollHeight + "px";
const newHeight = textarea.scrollHeight + 42;
const updates = { content: e.target.value };
if (newHeight !== data.height) {
updates.height = newHeight;
}
updateNote(data.id, updates);
};
const handleBlur = (e) => {
if (e.target.value === editField.content) return;
const textarea = document.getElementById(`note_${data.id}`);
textarea.style.height = "0";
textarea.style.height = textarea.scrollHeight + "px";
const newHeight = textarea.scrollHeight + 16 + 20 + 4;
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.NOTE,
nid: data.id,
undo: editField,
redo: { content: e.target.value, height: newHeight },
message: t("edit_note", {
noteTitle: e.target.value,
extra: "[content]",
}),
},
]);
setRedoStack([]);
};
const lockUnlockNote = (e) => {
const locking = !data.locked;
updateNote(data.id, { locked: locking });
const lockNote = () => {
setSelectedElement({
...selectedElement,
element: ObjectType.NONE,
id: -1,
open: false,
});
setBulkSelectedElements((prev) =>
prev.filter((el) => el.id !== data.id || el.type !== ObjectType.NOTE),
);
};
const unlockNote = () => {
const elementInBulk = {
id: data.id,
type: ObjectType.NOTE,
initialCoords: { x: data.x, y: data.y },
currentCoords: { x: data.x, y: data.y },
};
if (e.ctrlKey || e.metaKey) {
setBulkSelectedElements((prev) => [...prev, elementInBulk]);
} else {
setBulkSelectedElements([elementInBulk]);
}
setSelectedElement((prev) => ({
...prev,
element: ObjectType.NOTE,
id: data.id,
open: false,
}));
};
if (locking) {
lockNote();
} else {
unlockNote();
}
};
const edit = () => {
setSelectedElement((prev) => ({
...prev,
...(layout.sidebar && { currentTab: Tab.NOTES }),
...(!layout.sidebar && { element: ObjectType.NOTE }),
id: data.id,
open: true,
}));
if (layout.sidebar && selectedElement.currentTab === Tab.NOTES) {
document
.getElementById(`scroll_note_${data.id}`)
.scrollIntoView({ behavior: "smooth" });
}
};
const isSelected = useMemo(() => {
return (
(selectedElement.id === data.id &&
selectedElement.element === ObjectType.NOTE) ||
bulkSelectedElements.some(
(e) => e.type === ObjectType.NOTE && e.id === data.id,
)
);
}, [selectedElement, data, bulkSelectedElements]);
const width = data.width ?? noteWidth;
const MIN_NOTE_WIDTH = 120;
useEffect(() => {
const textarea = document.getElementById(`note_${data.id}`);
if (!textarea) return;
textarea.style.height = "0";
const scrollHeight = textarea.scrollHeight;
textarea.style.height = scrollHeight + "px";
const newHeight = scrollHeight + 42;
if (newHeight === data.height) return;
updateNote(data.id, { height: newHeight });
}, [data.id, data.height, updateNote]);
return (
<g
onPointerEnter={(e) => e.isPrimary && setHovered(true)}
onPointerLeave={(e) => e.isPrimary && setHovered(false)}
onPointerDown={(e) => {
// Required for onPointerLeave to trigger when a touch pointer leaves
// https://stackoverflow.com/a/70976017/1137077
e.target.releasePointerCapture(e.pointerId);
}}
onDoubleClick={edit}
>
<path
d={`M${data.x + noteFold} ${data.y} L${data.x + width - noteRadius} ${
data.y
} A${noteRadius} ${noteRadius} 0 0 1 ${data.x + width} ${data.y + noteRadius} L${data.x + width} ${
data.y + data.height - noteRadius
} A${noteRadius} ${noteRadius} 0 0 1 ${data.x + width - noteRadius} ${data.y + data.height} L${
data.x + noteRadius
} ${data.y + data.height} A${noteRadius} ${noteRadius} 0 0 1 ${data.x} ${
data.y + data.height - noteRadius
} L${data.x} ${data.y + noteFold}`}
fill={data.color}
stroke={
hovered
? "rgb(59 130 246)"
: isSelected
? "rgb(59 130 246)"
: "rgb(168 162 158)"
}
strokeDasharray={hovered ? 5 : 0}
strokeLinejoin="round"
strokeWidth="2"
/>
<path
d={`M${data.x} ${data.y + noteFold} L${data.x + noteFold - noteRadius} ${
data.y + noteFold
} A${noteRadius} ${noteRadius} 0 0 0 ${data.x + noteFold} ${data.y + noteFold - noteRadius} L${
data.x + noteFold
} ${data.y} L${data.x} ${data.y + noteFold} Z`}
fill={data.color}
stroke={
hovered
? "rgb(59 130 246)"
: isSelected
? "rgb(59 130 246)"
: "rgb(168 162 158)"
}
strokeDasharray={hovered ? 5 : 0}
strokeLinejoin="round"
strokeWidth="2"
/>
{!layout.readOnly && !data.locked && hovered && (
<g style={{ pointerEvents: "none" }}>
<circle
cx={data.x}
cy={data.y + data.height / 2}
r={6}
fill={settings.mode === "light" ? "white" : "rgb(28, 31, 35)"}
stroke="#5891db"
strokeWidth={2}
opacity={1}
/>
<circle
cx={data.x + width}
cy={data.y + data.height / 2}
r={6}
fill={settings.mode === "light" ? "white" : "rgb(28, 31, 35)"}
stroke="#5891db"
strokeWidth={2}
opacity={1}
/>
</g>
)}
{!layout.readOnly && !data.locked && (
<rect
x={data.x - 4}
y={data.y + 8}
width={8}
height={Math.max(0, data.height - 16)}
fill="transparent"
stroke="transparent"
style={{ cursor: "ew-resize" }}
onPointerDown={(e) => {
e.stopPropagation();
initialWidthRef.current = data.width ?? noteWidth;
initialXRef.current = data.x;
setResizing(true);
e.currentTarget.setPointerCapture?.(e.pointerId);
}}
onPointerMove={(e) => {
if (!resizing) return;
const delta = e.movementX / (transform?.zoom || 1);
const currentWidth = data.width ?? noteWidth;
let proposedWidth = currentWidth - delta;
let proposedX = data.x + delta;
if (proposedWidth < MIN_NOTE_WIDTH) {
const clampDelta = currentWidth - MIN_NOTE_WIDTH;
proposedWidth = MIN_NOTE_WIDTH;
proposedX = data.x + clampDelta;
}
if (proposedWidth !== data.width || proposedX !== data.x) {
updateNote(data.id, { width: proposedWidth, x: proposedX });
}
}}
onPointerUp={(e) => {
if (!resizing) return;
setResizing(false);
e.stopPropagation();
const finalWidth = data.width ?? noteWidth;
const finalX = data.x;
const startWidth = initialWidthRef.current;
const startX = initialXRef.current;
if (finalWidth !== startWidth || finalX !== startX) {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.NOTE,
nid: data.id,
undo: { width: startWidth, x: startX },
redo: { width: finalWidth, x: finalX },
message: t("edit_note", {
noteTitle: data.title,
extra: "[width/x]",
}),
},
]);
setRedoStack([]);
}
}}
/>
)}
{!layout.readOnly && !data.locked && (
<rect
x={data.x + width - 4}
y={data.y + 8}
width={8}
height={Math.max(0, data.height - 16)}
fill="transparent"
stroke="transparent"
style={{ cursor: "ew-resize" }}
onPointerDown={(e) => {
e.stopPropagation();
initialWidthRef.current = data.width ?? noteWidth;
setResizing(true);
e.currentTarget.setPointerCapture?.(e.pointerId);
}}
onPointerMove={(e) => {
if (!resizing) return;
const delta = e.movementX / (transform?.zoom || 1);
const next = Math.max(
MIN_NOTE_WIDTH,
(data.width ?? noteWidth) + delta,
);
if (next !== data.width) {
updateNote(data.id, { width: next });
}
}}
onPointerUp={(e) => {
if (!resizing) return;
setResizing(false);
e.stopPropagation();
const finalWidth = data.width ?? noteWidth;
const startWidth = initialWidthRef.current;
if (finalWidth !== startWidth) {
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.NOTE,
nid: data.id,
undo: { width: startWidth },
redo: { width: finalWidth },
message: t("edit_note", {
noteTitle: data.title,
extra: "[width]",
}),
},
]);
setRedoStack([]);
}
}}
/>
)}
<foreignObject
x={data.x}
y={data.y}
width={width}
height={data.height}
onPointerDown={onPointerDown}
>
<div className="text-gray-900 select-none w-full h-full cursor-move px-3 py-2">
<div className="flex justify-between gap-1 w-full">
<label
htmlFor={`note_${data.id}`}
className="ms-5 overflow-hidden text-ellipsis"
>
{data.title}
</label>
{(hovered ||
(selectedElement.element === ObjectType.NOTE &&
selectedElement.id === data.id &&
selectedElement.open &&
!layout.sidebar)) && (
<div className="flex items-center gap-1.5">
<Button
icon={data.locked ? <IconLock /> : <IconUnlock />}
size="small"
theme="solid"
style={{
backgroundColor: "#2F68ADB3",
}}
onClick={lockUnlockNote}
disabled={layout.readOnly}
/>
<Popover
visible={
selectedElement.element === ObjectType.NOTE &&
selectedElement.id === data.id &&
selectedElement.open &&
!layout.sidebar
}
onClickOutSide={() => {
if (selectedElement.editFromToolbar) {
setSelectedElement((prev) => ({
...prev,
editFromToolbar: false,
}));
return;
}
setSelectedElement((prev) => ({
...prev,
open: false,
}));
setSaveState(State.SAVING);
}}
stopPropagation
content={
<div className="popover-theme">
<div className="font-semibold mb-2 ms-1">{t("edit")}</div>
<div className="w-[280px] flex items-center mb-2">
<Input
value={data.title}
placeholder={t("title")}
className="me-2"
readonly={layout.readOnly}
onChange={(value) =>
updateNote(data.id, { title: value })
}
onFocus={(e) =>
setEditField({ title: e.target.value })
}
onBlur={(e) => {
if (e.target.value === editField.title) return;
setUndoStack((prev) => [
...prev,
{
action: Action.EDIT,
element: ObjectType.NOTE,
nid: data.id,
undo: editField,
redo: { title: e.target.value },
message: t("edit_note", {
noteTitle: e.target.value,
extra: "[title]",
}),
},
]);
setRedoStack([]);
}}
/>
<ColorPicker
usePopover={true}
readOnly={layout.readOnly}
value={data.color}
onChange={(color) => updateNote(data.id, { color })}
onColorPick={(color) => handleColorPick(color)}
/>
</div>
<div className="flex">
<Button
block
type="danger"
disabled={layout.readOnly}
icon={<IconDeleteStroked />}
onClick={() => deleteNote(data.id, true)}
>
{t("delete")}
</Button>
</div>
</div>
}
trigger="custom"
position="rightTop"
showArrow
>
<Button
icon={<IconEdit />}
size="small"
theme="solid"
style={{
backgroundColor: "#2F68ADB3",
}}
onClick={edit}
/>
</Popover>
</div>
)}
</div>
<textarea
id={`note_${data.id}`}
readOnly={layout.readOnly}
value={data.content}
onChange={handleChange}
onFocus={(e) =>
setEditField({
content: e.target.value,
height: data.height,
})
}
onBlur={handleBlur}
className="w-full resize-none outline-hidden overflow-y-hidden border-none select-none"
style={{ backgroundColor: data.color }}
/>
</div>
</foreignObject>
</g>
);
}
================================================
FILE: src/components/EditorCanvas/Relationship.jsx
================================================
import { useMemo, useRef, useState, useEffect } from "react";
import { Cardinality, ObjectType, Tab } from "../../data/constants";
import { calcPath } from "../../utils/calcPath";
import { useDiagram, useSettings, useLayout, useSelect } from "../../hooks";
import { useTranslation } from "react-i18next";
import { SideSheet } from "@douyinfe/semi-ui";
import RelationshipInfo from "../EditorSidePanel/RelationshipsTab/RelationshipInfo";
const labelFontSize = 16;
export default function Relationship({ data }) {
const { settings } = useSettings();
const { tables } = useDiagram();
const { layout } = useLayout();
const { selectedElement, setSelectedElement } = useSelect();
const { t } = useTranslation();
const pathValues = useMemo(() => {
const startTable = tables.find((t) => t.id === data.startTableId);
const endTable = tables.find((t) => t.id === data.endTableId);
if (!startTable || !endTable || startTable.hidden || endTable.hidden)
return null;
return {
startFieldIndex: startTable.fields.findIndex(
(f) => f.id === data.startFieldId,
),
endFieldIndex: endTable.fields.findIndex((f) => f.id === data.endFieldId),
startTable: {
x: startTable.x,
y: startTable.y,
comment: startTable.comment,
},
endTable: { x: endTable.x, y: endTable.y, comment: endTable.comment },
};
}, [tables, data]);
const pathRef = useRef();
const labelRef = useRef();
let cardinalityStart = "1";
let cardinalityEnd = "1";
switch (data.cardinality) {
// the translated values are to ensure backwards compatibility
case t(Cardinality.MANY_TO_ONE):
case Cardinality.MANY_TO_ONE:
cardinalityStart = data.manyLabel || "n";
cardinalityEnd = "1";
break;
case t(Cardinality.ONE_TO_MANY):
case Cardinality.ONE_TO_MANY:
cardinalityStart = "1";
cardinalityEnd = data.manyLabel || "n";
break;
case t(Cardinality.ONE_TO_ONE):
case Cardinality.ONE_TO_ONE:
cardinalityStart = "1";
cardinalityEnd = "1";
break;
default:
break;
}
let cardinalityStartX = 0;
let cardinalityEndX = 0;
let cardinalityStartY = 0;
let cardinalityEndY = 0;
let labelX = 0;
let labelY = 0;
let labelWidth = labelRef.current?.getBBox().width ?? 0;
let labelHeight = labelRef.current?.getBBox().height ?? 0;
const cardinalityOffset = 28;
if (pathRef.current) {
const pathLength = pathRef.current.getTotalLength();
const labelPoint = pathRef.current.getPointAtLength(pathLength / 2);
labelX = labelPoint.x - (labelWidth ?? 0) / 2;
labelY = labelPoint.y + (labelHeight ?? 0) / 2;
const point1 = pathRef.current.getPointAtLength(cardinalityOffset);
cardinalityStartX = point1.x;
cardinalityStartY = point1.y;
const point2 = pathRef.current.getPointAtLength(
pathLength - cardinalityOffset,
);
cardinalityEndX = point2.x;
cardinalityEndY = point2.y;
}
const edit = () => {
if (!layout.sidebar) {
setSelectedElement((prev) => ({
...prev,
element: ObjectType.RELATIONSHIP,
id: data.id,
open: true,
}));
} else {
setSelectedElement((prev) => ({
...prev,
currentTab: Tab.RELATIONSHIPS,
element: ObjectType.RELATIONSHIP,
id: data.id,
open: true,
}));
if (selectedElement.currentTab !== Tab.RELATIONSHIPS) return;
document
.getElementById(`scroll_ref_${data.id}`)
.scrollIntoView({ behavior: "smooth" });
}
};
if (!pathValues) return null;
return (
<>
<g className="select-none group" onDoubleClick={edit}>
{/* invisible wider path for better hover ux */}
<path
d={calcPath(pathValues, settings.tableWidth, 1, settings.showComments)}
fill="none"
stroke="transparent"
strokeWidth={12}
cursor="pointer"
/>
<path
ref={pathRef}
d={calcPath(pathValues, settings.tableWidth, 1, settings.showComments)}
className="relationship-path"
fill="none"
cursor="pointer"
/>
{settings.showRelationshipLabels && (
<text
x={labelX}
y={labelY}
fill={settings.mode === "dark" ? "lightgrey" : "#333"}
fontSize={labelFontSize}
fontWeight={500}
ref={labelRef}
className="group-hover:fill-sky-600"
>
{data.name}
</text>
)}
{pathRef.current && settings.showCardinality && (
<>
<CardinalityLabel
x={cardinalityStartX}
y={cardinalityStartY}
text={cardinalityStart}
/>
<CardinalityLabel
x={cardinalityEndX}
y={cardinalityEndY}
text={cardinalityEnd}
/>
</>
)}
</g>
<SideSheet
title={t("edit")}
size="small"
visible={
selectedElement.element === ObjectType.RELATIONSHIP &&
selectedElement.id === data.id &&
selectedElement.open &&
!layout.sidebar
}
onCancel={() => {
setSelectedElement((prev) => ({
...prev,
open: false,
}));
}}
style={{ paddingBottom: "16px" }}
>
<div className="sidesheet-theme">
<RelationshipInfo data={data} />
</div>
</SideSheet>
</>
);
}
function CardinalityLabel({ x, y, text, r = 12, padding = 14 }) {
const [textWidth, setTextWidth] = useState(0);
const textRef = useRef(null);
useEffect(() => {
if (textRef.current) {
const bbox = textRef.current.getBBox();
setTextWidth(bbox.width);
}
}, [text]);
return (
<g>
<rect
x={x - textWidth / 2 - padding / 2}
y={y - r}
rx={r}
ry={r}
width={textWidth + padding}
height={r * 2}
fill="grey"
className="group-hover:fill-sky-600"
/>
<text
ref={textRef}
x={x}
y={y}
fill="white"
strokeWidth="0.5"
textAnchor="middle"
alignmentBaseline="middle"
>
{text}
</text>
</g>
);
}
================================================
FILE: src/components/EditorCanvas/Table.jsx
================================================
import { useMemo, useState } from "react";
import {
Tab,
ObjectType,
tableFieldHeight,
tableHeaderHeight,
tableColorStripHeight,
} from "../../data/constants";
import {
IconEdit,
IconMore,
IconMinus,
IconDeleteStroked,
IconKeyStroked,
IconLock,
IconUnlock,
} from "@douyinfe/semi-icons";
import { Popover, Tag, Button, SideSheet } from "@douyinfe/semi-ui";
import { useLayout, useSettings, useDiagram, useSelect } from "../../hooks";
import TableInfo from "../EditorSidePanel/TablesTab/TableInfo";
import { useTranslation } from "react-i18next";
import { dbToTypes } from "../../data/datatypes";
import { isRtl } from "../../i18n/utils/rtl";
import i18n from "../../i18n/i18n";
import { getCommentHeight, getTableHeight } from "../../utils/utils";
export default function Table({
tableData,
onPointerDown,
setHoveredTable,
handleGripField,
setLinkingLine,
}) {
const [hoveredField, setHoveredField] = useState(null);
const { database } = useDiagram();
const { layout } = useLayout();
const { deleteTable, deleteField, updateTable } = useDiagram();
const { settings } = useSettings();
const { t } = useTranslation();
const {
selectedElement,
setSelectedElement,
bulkSelectedElements,
setBulkSelectedElements,
} = useSelect();
const borderColor = useMemo(
() => (settings.mode === "light" ? "border-zinc-300" : "border-zinc-600"),
[settings.mode],
);
const height = getTableHeight(
tableData,
settings.tableWidth,
settings.showComments,
);
const isSelected = useMemo(() => {
return (
(selectedElement.id == tableData.id &&
selectedElement.element === ObjectType.TABLE) ||
bulkSelectedElements.some(
(e) => e.type === ObjectType.TABLE && e.id === tableData.id,
)
);
}, [selectedElement, tableData, bulkSelectedElements]);
const lockUnlockTable = (e) => {
const locking = !tableData.locked;
updateTable(tableData.id, { locked: locking });
const lockTable = () => {
setSelectedElement({
...selectedElement,
element: ObjectType.NONE,
id: -1,
open: false,
});
setBulkSelectedElements((prev) =>
prev.filter(
(el) => el.id !== tableData.id || el.type !== ObjectType.TABLE,
),
);
};
const unlockTable = () => {
const elementInBulk = {
id: tableData.id,
type: ObjectType.TABLE,
initialCoords: { x: tableData.x, y: tableData.y },
currentCoords: { x: tableData.x, y: tableData.y },
};
if (e.ctrlKey || e.metaKey) {
setBulkSelectedElements((prev) => [...prev, elementInBulk]);
} else {
setBulkSelectedElements([elementInBulk]);
}
setSelectedElement((prev) => ({
...prev,
element: ObjectType.TABLE,
id: tableData.id,
open: false,
}));
};
if (locking) {
lockTable();
} else {
unlockTable();
}
};
const openEditor = () => {
if (!layout.sidebar) {
setSelectedElement((prev) => ({
...prev,
element: ObjectType.TABLE,
id: tableData.id,
open: true,
}));
} else {
setSelectedElement((prev) => ({
...prev,
currentTab: Tab.TABLES,
element: ObjectType.TABLE,
id: tableData.id,
open: true,
}));
if (selectedElement.currentTab !== Tab.TABLES) return;
document
.getElementById(`scroll_table_${tableData.id}`)
.scrollIntoView({ behavior: "smooth" });
}
};
if (tableData.hidden) return null;
return (
<>
<foreignObject
key={tableData.id}
x={tableData.x}
y={tableData.y}
width={settings.tableWidth}
height={height}
className="group drop-shadow-lg rounded-md cursor-move"
onPointerDown={onPointerDown}
>
<div
onDoubleClick={openEditor}
className={`border-2 hover:border-dashed hover:border-blue-500
select-none rounded-lg w-full ${
settings.mode === "light"
? "bg-zinc-100 text-zinc-800"
: "bg-zinc-800 text-zinc-200"
} ${isSelected ? "border-solid border-blue-500" : borderColor}`}
style={{ direction: "ltr" }}
>
<div
className="h-[10px] w-full rounded-t-md"
style={{ backgroundColor: tableData.color }}
/>
<div
className={`border-b border-gray-400 ${
settings.mode === "light" ? "bg-zinc-200" : "bg-zinc-900"
} ${tableData.comment && settings.showComments ? "pb-3" : ""}`}
>
<div
className={`overflow-hidden font-bold h-[40px] flex justify-between items-center`}
>
<div className="px-3 overflow-hidden text-ellipsis whitespace-nowrap">
{tableData.name}
</div>
<div className="hidden group-hover:block">
<div className="flex justify-end items-center mx-2 space-x-1.5">
<Button
icon={tableData.locked ? <IconLock /> : <IconUnlock />}
size="small"
theme="solid"
style={{
backgroundColor: "#2f68adb3",
}}
disabled={layout.readOnly}
onClick={lockUnlockTable}
/>
<Button
icon={<IconEdit />}
size="small"
theme="solid"
style={{
backgroundColor: "#2f68adb3",
}}
onClick={openEditor}
/>
<Popover
key={tableData.id}
content={
<div className="popover-theme">
<div className="mb-2">
<strong>{t("comment")}:</strong>{" "}
{tableData.comment === "" ? (
t("not_set")
) : (
<div>{tableData.comment}</div>
)}
</div>
<div>
<strong
className={`${
tableData.indices.length === 0 ? "" : "block"
}`}
>
{t("indices")}:
</strong>{" "}
{tableData.indices.length === 0 ? (
t("not_set")
) : (
<div>
{tableData.indices.map((index, k) => (
<div
key={k}
className={`flex items-center my-1 px-2 py-1 rounded ${
settings.mode === "light"
? "bg-gray-100"
: "bg-zinc-800"
}`}
>
<i className="fa-solid fa-thumbtack me-2 mt-1 text-slate-500"></i>
<div>
{index.fields.map((f) => (
<Tag
color="blue"
key={f}
className="me-1"
>
{f}
</Tag>
))}
</div>
</div>
))}
</div>
)}
</div>
<Button
icon={<IconDeleteStroked />}
type="danger"
block
style={{ marginTop: "8px" }}
onClick={() => deleteTable(tableData.id)}
disabled={layout.readOnly}
>
{t("delete")}
</Button>
</div>
}
position="rightTop"
showArrow
trigger="click"
style={{ width: "200px", wordBreak: "break-word" }}
>
<Button
icon={<IconMore />}
type="tertiary"
size="small"
style={{
backgroundColor: "#808080b3",
color: "white",
}}
/>
</Popover>
</div>
</div>
</div>
{tableData.comment && settings.showComments && (
<div className="text-xs px-3 line-clamp-5">
{tableData.comment}
</div>
)}
</div>
{tableData.fields.map((e, i) => {
return settings.showFieldSummary ? (
<Popover
key={i}
content={
<div className="popover-theme">
<div
className="flex justify-between items-center pb-2"
style={{ direction: "ltr" }}
>
<p className="me-4 font-bold">{e.name}</p>
<p
className={
"ms-4 font-mono " + dbToTypes[database][e.type].color
}
>
{e.type +
((dbToTypes[database][e.type].isSized ||
dbToTypes[database][e.type].hasPrecision) &&
e.size &&
e.size !== ""
? "(" + e.size + ")"
: "")}
</p>
</div>
<hr />
{e.primary && (
<Tag color="blue" className="me-2 my-2">
{t("primary")}
</Tag>
)}
{e.unique && (
<Tag color="amber" className="me-2 my-2">
{t("unique")}
</Tag>
)}
{e.notNull && (
<Tag color="purple" className="me-2 my-2">
{t("not_null")}
</Tag>
)}
{e.increment && (
<Tag color="green" className="me-2 my-2">
{t("autoincrement")}
</Tag>
)}
<p>
<strong>{t("default_value")}: </strong>
{e.default === "" ? t("not_set") : e.default}
</p>
<p>
<strong>{t("comment")}: </strong>
{e.comment === "" ? t("not_set") : e.comment}
</p>
</div>
}
position="right"
showArrow
style={
isRtl(i18n.language)
? { direction: "rtl" }
: { direction: "ltr" }
}
>
{field(e, i)}
</Popover>
) : (
field(e, i)
);
})}
</div>
</foreignObject>
<SideSheet
title={t("edit")}
size="small"
visible={
selectedElement.element === ObjectType.TABLE &&
selectedElement.id === tableData.id &&
selectedElement.open &&
!layout.sidebar
}
onCancel={() =>
setSelectedElement((prev) => ({
...prev,
open: !prev.open,
}))
}
style={{ paddingBottom: "16px" }}
>
<div className="sidesheet-theme">
<TableInfo data={tableData} />
</div>
</SideSheet>
</>
);
function field(fieldData, index) {
return (
<div
className={`${
index === tableData.fields.length - 1
? ""
: "border-b border-gray-400"
} group h-[36px] px-2 py-1 flex justify-between items-center gap-1 w-full overflow-hidden`}
onPointerEnter={(e) => {
if (!e.isPrimary) return;
setHoveredField(index);
setHoveredTable({
tableId: tableData.id,
fieldId: fieldData.id,
});
}}
onPointerLeave={(e) => {
if (!e.isPrimary) return;
setHoveredField(null);
setHoveredTable({
tableId: null,
fieldId: null,
});
}}
onPointerDown={(e) => {
// Required for onPointerLeave to trigger when a touch pointer leaves
// https://stackoverflow.com/a/70976017/1137077
e.target.releasePointerCapture(e.pointerId);
}}
>
<div
className={`${
hoveredField === index ? "text-zinc-400" : ""
} flex items-center gap-2 overflow-hidden`}
>
<button
className="shrink-0 w-[10px] h-[10px] bg-[#2f68adcc] rounded-full"
onPointerDown={(e) => {
if (!e.isPrimary) return;
handleGripField();
setLinkingLine((prev) => ({
...prev,
startFieldId: fieldData.id,
startTableId: tableData.id,
startX: tableData.x + 15,
startY:
tableData.y +
index * tableFieldHeight +
tableHeaderHeight +
tableColorStripHeight +
getCommentHeight(
tableData.comment,
settings.tableWidth,
settings.showComments,
) +
14,
endX: tableData.x + 15,
endY:
tableData.y +
index * tableFieldHeight +
tableHeaderHeight +
tableColorStripHeight +
getCommentHeight(
tableData.comment,
settings.tableWidth,
settings.showComments,
) +
14,
}));
}}
/>
<span className="overflow-hidden text-ellipsis whitespace-nowrap">
{fieldData.name}
</span>
</div>
<div className="text-zinc-400">
{hoveredField === index ? (
<Button
theme="solid"
size="small"
style={{
backgroundColor: "#d42020b3",
}}
icon={<IconMinus />}
disabled={layout.readOnly}
onClick={() => {
if (layout.readOnly) return;
deleteField(fieldData, tableData.id);
}}
/>
) : settings.showDataTypes ? (
<div className="flex gap-1 items-center">
{fieldData.primary && <IconKeyStroked />}
{!fieldData.notNull && <span className="font-mono">?</span>}
<span
className={
"font-mono " + dbToTypes[database][fieldData.type].color
}
>
{fieldData.type +
((dbToTypes[database][fieldData.type].isSized ||
dbToTypes[database][fieldData.type].hasPrecision) &&
fieldData.size &&
fieldData.size !== ""
? `(${fieldData.size})`
: "")}
</span>
</div>
) : null}
</div>
</div>
);
}
}
================================================
FILE: src/components/EditorHeader/ControlPanel.jsx
================================================
import { useContext, useState } from "react";
import {
IconCaretdown,
IconChevronRight,
IconChevronLeft,
IconChevronUp,
IconChevronDown,
IconSaveStroked,
IconUndo,
IconRedo,
IconEdit,
IconShareStroked,
} from "@douyinfe/semi-icons";
import { Link, useMatch, useNavigate, useParams } from "react-router-dom";
import icon from "../../assets/icon_dark_64.png";
import {
Button,
Divider,
Dropdown,
InputNumber,
Tooltip,
Spin,
Tag,
Toast,
Popconfirm,
} from "@douyinfe/semi-ui";
import { toPng, toJpeg, toSvg } from "html-to-image";
import {
jsonToMySQL,
jsonToPostgreSQL,
jsonToSQLite,
jsonToMariaDB,
jsonToSQLServer,
jsonToOracleSQL,
} from "../../utils/exportSQL/generic";
import {
ObjectType,
Action,
Tab,
State,
MODAL,
SIDESHEET,
DB,
IMPORT_FROM,
noteWidth,
pngExportPixelRatio,
} from "../../data/constants";
import jsPDF from "jspdf";
import { useHotkeys } from "react-hotkeys-hook";
import { Validator } from "jsonschema";
import { areaSchema, noteSchema, tableSchema } from "../../data/schemas";
import { db } from "../../data/db";
import {
useLayout,
useSettings,
useTransform,
useDiagram,
useUndoRedo,
useSelect,
useSaveState,
useTypes,
useNotes,
useAreas,
useEnums,
useFullscreen,
} from "../../hooks";
import { enterFullscreen, exitFullscreen } from "../../utils/fullscreen";
import { dataURItoBlob } from "../../utils/utils";
import { IconAddArea, IconAddNote, IconAddTable } from "../../icons";
import LayoutDropdown from "./LayoutDropdown";
import Sidesheet from "./SideSheet/Sidesheet";
import Modal from "./Modal/Modal";
import { useTranslation } from "react-i18next";
import { exportSQL } from "../../utils/exportSQL";
import { databases } from "../../data/databases";
import { jsonToMermaid } from "../../utils/exportAs/mermaid";
import { isRtl } from "../../i18n/utils/rtl";
import { jsonToDocumentation } from "../../utils/exportAs/documentation";
import { IdContext } from "../Workspace";
import { socials } from "../../data/socials";
import { toDBML } from "../../utils/exportAs/dbml";
import { exportSavedData } from "../../utils/exportSavedData";
import { nanoid } from "nanoid";
import { getTableHeight } from "../../utils/utils";
import { deleteFromCache, STORAGE_KEY } from "../../utils/cache";
import { useLiveQuery } from "dexie-react-hooks";
import { DateTime } from "luxon";
export default function ControlPanel({ title, setTitle, lastSaved }) {
const { id: diagramId } = useParams();
const [modal, setModal] = useState(MODAL.NONE);
const [sidesheet, setSidesheet] = useState(SIDESHEET.NONE);
const [showEditName, setShowEditName] = useState(false);
const [importDb, setImportDb] = useState("");
const [exportData, setExportData] = useState({
data: null,
filename: `${title}_${new Date().toISOString()}`,
extension: "",
});
const [importFrom, setImportFrom] = useState(IMPORT_FROM.JSON);
const { saveState, setSaveState } = useSaveState();
const { layout, setLayout } = useLayout();
const { settings, setSettings } = useSettings();
const {
relationships,
tables,
setTables,
addTable,
updateTable,
deleteField,
deleteTable,
updateField,
setRelationships,
addRelationship,
deleteRelationship,
updateRelationship,
database,
} = useDiagram();
const { enums, setEnums, deleteEnum, addEnum, updateEnum } = useEnums();
const { types, addType, deleteType, updateType, setTypes } = useTypes();
const { notes, setNotes, updateNote, addNote, deleteNote } = useNotes();
const { areas, setAreas, updateArea, addArea, deleteArea } = useAreas();
const { undoStack, redoStack, setUndoStack, setRedoStack } = useUndoRedo();
const { selectedElement, setSelectedElement } = useSelect();
const { transform, setTransform } = useTransform();
const { t, i18n } = useTranslation();
const { version, gistId, setGistId } = useContext(IdContext);
const isTemplate = useMatch("/editor/templates/:id");
const navigate = useNavigate();
const invertLayout = (component) =>
setLayout((prev) => ({ ...prev, [component]: !prev[component] }));
const undo = () => {
if (undoStack.length === 0) return;
const a = undoStack[undoStack.length - 1];
setUndoStack((prev) => prev.filter((_, i) => i !== prev.length - 1));
if (a.bulk) {
for (const element of a.elements) {
if (element.type === ObjectType.TABLE) {
updateTable(element.id, element.undo);
} else if (element.type === ObjectType.AREA) {
updateArea(element.id, element.undo);
} else if (element.type === ObjectType.NOTE) {
updateNote(element.id, element.undo);
}
}
setRedoStack((prev) => [...prev, a]);
return;
}
if (a.action === Action.ADD) {
if (a.element === ObjectType.TABLE) {
deleteTable(a.data.table.id, false);
} else if (a.element === ObjectType.AREA) {
deleteArea(areas[areas.length - 1].id, false);
} else if (a.element === ObjectType.NOTE) {
deleteNote(notes[notes.length - 1].id, false);
} else if (a.element === ObjectType.RELATIONSHIP) {
deleteRelationship(a.data.relationship.id, false);
} else if (a.element === ObjectType.TYPE) {
deleteType(a.data.type.id, false);
} else if (a.element === ObjectType.ENUM) {
deleteEnum(a.data.enum.id, false);
}
setRedoStack((prev) => [...prev, a]);
} else if (a.action === Action.MOVE) {
if (a.element === ObjectType.TABLE) {
const { x, y } = tables.find((t) => t.id === a.id);
setRedoStack((prev) => [...prev, { ...a, x, y }]);
updateTable(a.id, { x: a.x, y: a.y });
} else if (a.element === ObjectType.AREA) {
setRedoStack((prev) => [
...prev,
{ ...a, x: areas[a.id].x, y: areas[a.id].y },
]);
updateArea(a.id, { x: a.x, y: a.y });
} else if (a.element === ObjectType.NOTE) {
setRedoStack((prev) => [
...prev,
{ ...a, x: notes[a.id].x, y: notes[a.id].y },
]);
updateNote(a.id, { x: a.x, y: a.y });
}
} else if (a.action === Action.DELETE) {
if (a.element === ObjectType.TABLE) {
a.data.relationship.forEach((x) => addRelationship(x, false));
addTable(a.data, false);
} else if (a.element === ObjectType.RELATIONSHIP) {
addRelationship(a.data, false);
} else if (a.element === ObjectType.NOTE) {
addNote(a.data, false);
} else if (a.element === ObjectType.AREA) {
addArea(a.data, false);
} else if (a.element === ObjectType.TYPE) {
addType(a.data, false);
} else if (a.element === ObjectType.ENUM) {
addEnum(a.data, false);
}
setRedoStack((prev) => [...prev, a]);
} else if (a.action === Action.EDIT) {
if (a.element === ObjectType.AREA) {
updateArea(a.aid, a.undo);
} else if (a.element === ObjectType.NOTE) {
updateNote(a.nid, a.undo);
} else if (a.element === ObjectType.TABLE) {
const table = tables.find((t) => t.id === a.tid);
if (a.component === "field") {
updateField(a.tid, a.fid, a.undo);
} else if (a.component === "field_delete") {
setRelationships((prev) => {
let temp = [...prev];
a.data.relationship.forEach((r) => {
temp.splice(r.id, 0, r);
});
return temp;
});
const updatedFields = table.fields.slice();
updatedFields.splice(a.data.index, 0, a.data.field);
updateTable(a.tid, { fields: updatedFields });
} else if (a.component === "field_add") {
updateTable(a.tid, {
fields: table.fields.filter((e) => e.id !== a.fid),
});
} else if (a.component === "index_add") {
updateTable(a.tid, {
indices: table.indices
.filter((e) => e.id !== table.indices.length - 1)
.map((t, i) => ({ ...t, id: i })),
});
} else if (a.component === "index") {
updateTable(a.tid, {
indices: table.indices.map((index) =>
index.id === a.iid
? {
...index,
...a.undo,
}
: index,
),
});
} else if (a.component === "index_delete") {
const updatedIndices = table.indices.slice();
updatedIndices.splice(a.data.id, 0, a.data);
updateTable(a.tid, {
indices: updatedIndices.map((t, i) => ({ ...t, id: i })),
});
} else if (a.component === "self") {
updateTable(a.tid, a.undo);
}
} else if (a.element === ObjectType.RELATIONSHIP) {
updateRelationship(a.rid, a.undo);
} else if (a.element === ObjectType.TYPE) {
if (a.component === "field_add") {
const type = types.find((t, i) =>
typeof a.tid === "number" ? i === a.tid : t.id === a.tid,
);
updateType(a.tid, {
fields: type.fields.filter((f, i) =>
f.id ? f.id !== a.data.field.id : i !== type.fields.length - 1,
),
});
}
if (a.component === "field") {
updateType(a.tid, {
fields: types[a.tid].fields.map((e, i) =>
i === a.fid ? { ...e, ...a.undo } : e,
),
});
} else if (a.component === "field_delete") {
setTypes((prev) =>
prev.map((t, i) => {
if (i === a.tid) {
const temp = t.fields.slice();
temp.splice(a.fid, 0, a.data);
return { ...t, fields: temp };
}
return t;
}),
);
} else if (a.component === "self") {
updateType(a.tid, a.undo);
if (a.updatedFields) {
if (a.undo.name) {
a.updatedFields.forEach((x) =>
updateField(x.tid, x.fid, { type: a.undo.name.toUpperCase() }),
);
}
}
}
} else if (a.element === ObjectType.ENUM) {
updateEnum(a.id, a.undo);
if (a.updatedFields) {
if (a.undo.name) {
a.updatedFields.forEach((x) =>
updateField(x.tid, x.fid, { type: a.undo.name.toUpperCase() }),
);
}
}
}
setRedoStack((prev) => [...prev, a]);
}
};
const redo = () => {
if (redoStack.length === 0) return;
const a = redoStack[redoStack.length - 1];
setRedoStack((prev) => prev.filter((e, i) => i !== prev.length - 1));
if (a.bulk) {
for (const element of a.elements) {
if (element.type === ObjectType.TABLE) {
updateTable(element.id, element.redo);
} else if (element.type === ObjectType.AREA) {
updateArea(element.id, element.redo);
} else if (element.type === ObjectType.NOTE) {
updateNote(element.id, element.redo);
}
}
setUndoStack((prev) => [...prev, a]);
return;
}
if (a.action === Action.ADD) {
if (a.element === ObjectType.TABLE) {
addTable(a.data, false);
} else if (a.element === ObjectType.AREA) {
addArea(null, false);
} else if (a.element === ObjectType.NOTE) {
addNote(null, false);
} else if (a.element === ObjectType.RELATIONSHIP) {
addRelationship(a.data, false);
} else if (a.element === ObjectType.TYPE) {
addType(a.data, false);
} else if (a.element === ObjectType.ENUM) {
addEnum(a.data, false);
}
setUndoStack((prev) => [...prev, a]);
} else if (a.action === Action.MOVE) {
if (a.element === ObjectType.TABLE) {
const { x, y } = tables.find((t) => t.id == a.id);
setUndoStack((prev) => [...prev, { ...a, x, y }]);
updateTable(a.id, { x: a.x, y: a.y });
} else if (a.element === ObjectType.AREA) {
setUndoStack((prev) => [
...prev,
{ ...a, x: areas[a.id].x, y: areas[a.id].y },
]);
updateArea(a.id, { x: a.x, y: a.y });
} else if (a.element === ObjectType.NOTE) {
setUndoStack((prev) => [
...prev,
{ ...a, x: notes[a.id].x, y: notes[a.id].y },
]);
updateNote(a.id, { x: a.x, y: a.y });
}
} else if (a.action === Action.DELETE) {
if (a.element === ObjectType.TABLE) {
deleteTable(a.data.table.id, false);
} else if (a.element === ObjectType.RELATIONSHIP) {
deleteRelationship(a.data.relationship.id, false);
} else if (a.element === ObjectType.NOTE) {
deleteNote(a.data.id, false);
} else if (a.element === ObjectType.AREA) {
deleteArea(a.data.id, false);
} else if (a.element === ObjectType.TYPE) {
deleteType(a.data.type.id, false);
} else if (a.element === ObjectType.ENUM) {
deleteEnum(a.data.enum.id, false);
}
setUndoStack((prev) => [...prev, a]);
} else if (a.action === Action.EDIT) {
if (a.element === ObjectType.AREA) {
updateArea(a.aid, a.redo);
} else if (a.element === ObjectType.NOTE) {
updateNote(a.nid, a.redo);
} else if (a.element === ObjectType.TABLE) {
const table = tables.find((t) => t.id === a.tid);
if (a.component === "field") {
updateField(a.tid, a.fid, a.redo);
} else if (a.component === "field_delete") {
deleteField(a.data.field, a.tid, false);
} else if (a.component === "field_add") {
updateTable(a.tid, {
fields: [
...table.fields,
{
name: "",
type: "",
default: "",
check: "",
primary: false,
unique: false,
notNull: false,
increment: false,
comment: "",
id: nanoid(),
},
],
});
} else if (a.component === "index_add") {
updateTable(a.tid, {
indices: [
...table.indices,
{
id: table.indices.length,
name: `index_${table.indices.length}`,
fields: [],
},
],
});
} else if (a.component === "index") {
updateTable(a.tid, {
indices: table.indices.map((index) =>
index.id === a.iid
? {
...index,
...a.redo,
}
: index,
),
});
} else if (a.component === "index_delete") {
updateTable(a.tid, {
indices: table.indices
.filter((e) => e.id !== a.data.id)
.map((t, i) => ({ ...t, id: i })),
});
} else if (a.component === "self") {
updateTable(a.tid, a.redo, false);
}
} else if (a.element === ObjectType.RELATIONSHIP) {
updateRelationship(a.rid, a.redo);
} else if (a.element === ObjectType.TYPE) {
if (a.component === "field_add") {
const type = types.find((t, i) =>
typeof a.tid === "number" ? i === a.tid : t.id === a.tid,
);
updateType(a.tid, {
fields: [...type.fields, a.data.field],
});
} else if (a.component === "field") {
updateType(a.tid, {
fields: types[a.tid].fields.map((e, i) =>
i === a.fid ? { ...e, ...a.redo } : e,
),
});
} else if (a.component === "field_delete") {
updateType(a.tid, {
fields: types[a.tid].fields.filter((field, i) => i !== a.fid),
});
} else if (a.component === "self") {
updateType(a.tid, a.redo);
if (a.updatedFields) {
if (a.redo.name) {
a.updatedFields.forEach((x) =>
updateField(x.tid, x.fid, { type: a.redo.name.toUpperCase() }),
);
}
}
}
} else if (a.element === ObjectType.ENUM) {
updateEnum(a.id, a.redo);
if (a.updatedFields) {
if (a.redo.name) {
a.updatedFields.forEach((x) =>
updateField(x.tid, x.fid, { type: a.redo.name.toUpperCase() }),
);
}
}
}
setUndoStack((prev) => [...prev, a]);
}
};
const fileImport = () => setModal(MODAL.IMPORT);
const viewGrid = () =>
setSettings((prev) => ({ ...prev, showGrid: !prev.showGrid }));
const snapToGrid = () =>
setSettings((prev) => ({ ...prev, snapToGrid: !prev.snapToGrid }));
const zoomIn = () =>
setTransform((prev) => ({ ...prev, zoom: prev.zoom * 1.2 }));
const zoomOut = () =>
setTransform((prev) => ({ ...prev, zoom: prev.zoom / 1.2 }));
const viewStrictMode = () => {
setSettings((prev) => ({ ...prev, strictMode: !prev.strictMode }));
};
const viewFieldSummary = () => {
setSettings((prev) => ({
...prev,
showFieldSummary: !prev.showFieldSummary,
}));
};
const copyAsImage = () => {
toPng(document.getElementById("canvas"), {
pixelRatio: pngExportPixelRatio,
}).then(function (dataUrl) {
const blob = dataURItoBlob(dataUrl);
navigator.clipboard
.write([new ClipboardItem({ "image/png": blob })])
.then(() => {
Toast.success(t("copied_to_clipboard"));
})
.catch(() => {
Toast.error(t("oops_smth_went_wrong"));
});
});
};
const resetView = () =>
setTransform((prev) => ({ ...prev, zoom: 1, pan: { x: 0, y: 0 } }));
const fitWindow = () => {
const canvas = document.getElementById("canvas").getBoundingClientRect();
const minMaxXY = {
minX: Infinity,
minY: Infinity,
maxX: -Infinity,
maxY: -Infinity,
};
tables.forEach((table) => {
minMaxXY.minX = Math.min(minMaxXY.minX, table.x);
minMaxXY.minY = Math.min(minMaxXY.minY, table.y);
minMaxXY.maxX = Math.max(minMaxXY.maxX, table.x + settings.tableWidth);
minMaxXY.maxY = Math.max(
minMaxXY.maxY,
table.y +
getTableHeight(table, settings.tableWidth, settings.showComments),
);
});
areas.forEach((area) => {
minMaxXY.minX = Math.min(minMaxXY.minX, area.x);
minMaxXY.minY = Math.min(minMaxXY.minY, area.y);
minMaxXY.maxX = Math.max(minMaxXY.maxX, area.x + area.width);
minMaxXY.maxY = Math.max(minMaxXY.maxY, area.y + area.height);
});
notes.forEach((note) => {
minMaxXY.minX = Math.min(minMaxXY.minX, note.x);
minMaxXY.minY = Math.min(minMaxXY.minY, note.y);
minMaxXY.maxX = Math.max(
minMaxXY.maxX,
note.x + (note.width ?? noteWidth),
);
minMaxXY.maxY = Math.max(minMaxXY.maxY, note.y + note.height);
});
const padding = 10;
const width = minMaxXY.maxX - minMaxXY.minX + padding;
const height = minMaxXY.maxY - minMaxXY.minY + padding;
const scaleX = canvas.width / width;
const scaleY = canvas.height / height;
// Making sure the scale is a multiple of 0.05
const scale = Math.floor(Math.min(scaleX, scaleY) * 20) / 20;
const centerX = (minMaxXY.minX + minMaxXY.maxX) / 2;
const centerY = (minMaxXY.minY + minMaxXY.maxY) / 2;
setTransform((prev) => ({
...prev,
zoom: scale,
pan: { x: centerX, y: centerY },
}));
};
const edit = () => {
if (selectedElement.element === ObjectType.TABLE) {
if (!layout.sidebar) {
setSelectedElement((prev) => ({
...prev,
open: true,
}));
} else {
setSelectedElement((prev) => ({
...prev,
open: true,
currentTab: Tab.TABLES,
}));
if (selectedElement.currentTab !== Tab.TABLES) return;
document
.getElementById(`scroll_table_${selectedElement.id}`)
.scrollIntoView({ behavior: "smooth" });
}
} else if (selectedElement.element === ObjectType.AREA) {
if (layout.sidebar) {
setSelectedElement((prev) => ({
...prev,
currentTab: Tab.AREAS,
}));
if (selectedElement.currentTab !== Tab.AREAS) return;
document
.getElementById(`scroll_area_${selectedElement.id}`)
.scrollIntoView({ behavior: "smooth" });
} else {
setSelectedElement((prev) => ({
...prev,
open: true,
editFromToolbar: true,
}));
}
} else if (selectedElement.element === ObjectType.NOTE) {
if (layout.sidebar) {
setSelectedElement((prev) => ({
...prev,
currentTab: Tab.NOTES,
open: false,
}));
if (selectedElement.currentTab !== Tab.NOTES) return;
document
.getElementById(`scroll_note_${selectedElement.id}`)
.scrollIntoView({ behavior: "smooth" });
} else {
setSelectedElement((prev) => ({
...prev,
open: true,
editFromToolbar: true,
}));
}
}
};
const del = () => {
if (layout.readOnly) {
return;
}
switch (selectedElement.element) {
case ObjectType.TABLE:
deleteTable(selectedElement.id);
break;
case ObjectType.NOTE:
deleteNote(selectedElement.id);
break;
case ObjectType.AREA:
deleteArea(selectedElement.id);
break;
default:
break;
}
};
const duplicate = () => {
if (layout.readOnly) {
return;
}
switch (selectedElement.element) {
case ObjectType.TABLE: {
const copiedTable = tables.find((t) => t.id === selectedElement.id);
addTable({
table: {
...copiedTable,
x: copiedTable.x + 20,
y: copiedTable.y + 20,
id: nanoid(),
},
});
break;
}
case ObjectType.NOTE:
addNote({
...notes[selectedElement.id],
x: notes[selectedElement.id].x + 20,
y: notes[selectedElement.id].y + 20,
id: notes.length,
});
break;
case ObjectType.AREA:
addArea({
...areas[selectedElement.id],
x: areas[selectedElement.id].x + 20,
y: areas[selectedElement.id].y + 20,
id: areas.length,
});
break;
default:
break;
}
};
const copy = () => {
switch (selectedElement.element) {
case ObjectType.TABLE:
navigator.clipboard
.writeText(
JSON.stringify(tables.find((t) => t.id === selectedElement.id)),
)
.catch(() => Toast.error(t("oops_smth_went_wrong")));
break;
case ObjectType.NOTE:
navigator.clipboard
.writeText(JSON.stringify({ ...notes[selectedElement.id] }))
.catch(() => Toast.error(t("oops_smth_went_wrong")));
break;
case ObjectType.AREA:
navigator.clipboard
.writeText(JSON.stringify({ ...areas[selectedElement.id] }))
.catch(() => Toast.error(t("oops_smth_went_wrong")));
break;
default:
break;
}
};
const paste = () => {
if (layout.readOnly) {
return;
}
navigator.clipboard.readText().then((text) => {
let obj = null;
try {
obj = JSON.parse(text);
} catch (error) {
return;
}
const v = new Validator();
if (v.validate(obj, tableSchema).valid) {
addTable({
table: {
...obj,
x: obj.x + 20,
y: obj.y + 20,
id: nanoid(),
},
});
} else if (v.validate(obj, areaSchema).valid) {
addArea({
...obj,
x: obj.x + 20,
y: obj.y + 20,
id: areas.length,
});
} else if (v.validate(obj, noteSchema)) {
addNote({
...obj,
x: obj.x + 20,
y: obj.y + 20,
id: notes.length,
});
}
});
};
const cut = () => {
if (layout.readOnly) {
return;
}
copy();
del();
};
const toggleDBMLEditor = () => {
setLayout((prev) => ({ ...prev, dbmlEditor: !prev.dbmlEditor }));
};
const save = () => setSaveState(State.SAVING);
const recentlyOpenedDiagrams = useLiveQuery(() =>
db.diagrams.orderBy("lastModified").reverse().limit(10).toArray(),
);
const open = () => setModal(MODAL.OPEN);
const saveDiagramAs = () => setModal(MODAL.SAVEAS);
const fullscreen = useFullscreen();
const menu = {
file: {
new: {
function: () => setModal(MODAL.NEW),
},
new_window: {
function: () => window.open("/editor", "_blank"),
},
open: {
function: open,
shortcut: "Ctrl+O",
},
open_recent: {
children: [
...(recentlyOpenedDiagrams && recentlyOpenedDiagrams.length > 0
? [
...recentlyOpenedDiagrams.map((diagram) => ({
name: diagram.name,
label: DateTime.fromJSDate(new Date(diagram.lastModified))
.setLocale(i18n.language)
.toRelative(),
function: () => {
navigate(`/editor/diagrams/${diagram.diagramId}`);
},
})),
{ divider: true },
{
name: t("see_all"),
function: () => open(),
},
]
: [
{
name: t("no_saved_diagrams"),
disabled: true,
},
]),
],
function: () => {},
},
save: {
function: save,
shortcut: "Ctrl+S",
disabled: layout.readOnly,
},
save_as: {
function: saveDiagramAs,
shortcut: "Ctrl+Shift+S",
disabled: layout.readOnly,
},
save_as_template: {
function: async () => {
await db.templates
.add({
title: title,
tables: tables,
database: database,
relationships: relationships,
notes: notes,
subjectAreas: areas,
custom: 1,
templateId: crypto.randomUUID(),
...(databases[database].hasEnums && { enums: enums }),
...(databases[database].hasTypes && { types: types }),
})
.then(() => {
Toast.success(t("template_saved"));
});
},
},
rename: {
function: () => {
setModal(MODAL.RENAME);
},
disabled: layout.readOnly,
},
delete_diagram: {
warning: {
title: t("delete_diagram"),
message: t("are_you_sure_delete_diagram"),
},
function: async () => {
await db.diagrams
.where("diagramId")
.equals(diagramId)
.delete()
.then(() => {
setTitle("Untitled diagram");
setTables([]);
setRelationships([]);
setAreas([]);
setNotes([]);
setTypes([]);
setEnums([]);
setUndoStack([]);
setRedoStack([]);
setGistId("");
navigate("/editor/templates/blank", { replace: true });
})
.catch(() => Toast.error(t("oops_smth_went_wrong")));
},
},
import_from: {
children: [
{
function: () => {
setModal(MODAL.IMPORT);
setImportFrom(IMPORT_FROM.JSON);
},
name: "JSON",
disabled: layout.readOnly,
},
{
function: () => {
setModal(MODAL.IMPORT);
setImportFrom(IMPORT_FROM.DBML);
},
name: "DBML",
disabled: layout.readOnly,
},
],
},
import_from_source: {
...(database === DB.GENERIC && {
children: [
{
function: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.MYSQL);
},
name: "MySQL",
disabled: layout.readOnly,
},
{
function: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.POSTGRES);
},
name: "PostgreSQL",
disabled: layout.readOnly,
},
{
function: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.SQLITE);
},
name: "SQLite",
disabled: layout.readOnly,
},
{
function: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.MARIADB);
},
name: "MariaDB",
disabled: layout.readOnly,
},
{
function: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.MSSQL);
},
name: "MSSQL",
disabled: layout.readOnly,
},
{
function: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.ORACLESQL);
},
name: "Oracle",
label: "Beta",
disabled: layout.readOnly,
},
],
}),
function: () => {
if (database === DB.GENERIC) return;
setModal(MODAL.IMPORT_SRC);
},
disabled: layout.readOnly,
},
export_source: {
...(database === DB.GENERIC && {
children: [
{
name: "MySQL",
function: () => {
setModal(MODAL.CODE);
const src = jsonToMySQL({
tables: tables,
references: relationships,
types: types,
database: database,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
},
},
{
name: "PostgreSQL",
function: () => {
setModal(MODAL.CODE);
const src = jsonToPostgreSQL({
tables: tables,
references: relationships,
types: types,
database: database,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
},
},
{
name: "SQLite",
function: () => {
setModal(MODAL.CODE);
const src = jsonToSQLite({
tables: tables,
references: relationships,
types: types,
database: database,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
},
},
{
name: "MariaDB",
function: () => {
setModal(MODAL.CODE);
const src = jsonToMariaDB({
tables: tables,
references: relationships,
types: types,
database: database,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
},
},
{
name: "MSSQL",
function: () => {
setModal(MODAL.CODE);
const src = jsonToSQLServer({
tables: tables,
references: relationships,
types: types,
database: database,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
},
},
{
label: "Beta",
name: "Oracle",
function: () => {
setModal(MODAL.CODE);
const src = jsonToOracleSQL({
tables: tables,
references: relationships,
types: types,
database: database,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
},
},
],
}),
function: () => {
if (database === DB.GENERIC) return;
setModal(MODAL.CODE);
const src = exportSQL({
tables: tables,
references: relationships,
types: types,
database: database,
enums: enums,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
},
},
export_as: {
children: [
{
name: "PNG",
function: () => {
toPng(document.getElementById("canvas"), {
pixelRatio: pngExportPixelRatio,
}).then(function (dataUrl) {
setExportData((prev) => ({
...prev,
data: dataUrl,
extension: "png",
}));
});
setModal(MODAL.IMG);
},
},
{
name: "JPEG",
function: () => {
toJpeg(document.getElementById("canvas"), { quality: 0.95 }).then(
function (dataUrl) {
setExportData((prev) => ({
...prev,
data: dataUrl,
extension: "jpeg",
}));
},
);
setModal(MODAL.IMG);
},
},
{
name: "SVG",
function: () => {
const filter = (node) => node.tagName !== "i";
toSvg(document.getElementById("canvas"), { filter: filter }).then(
function (dataUrl) {
setExportData((prev) => ({
...prev,
data: dataUrl,
extension: "svg",
}));
},
);
setModal(MODAL.IMG);
},
},
{
name: "JSON",
function: () => {
setModal(MODAL.CODE);
const result = JSON.stringify(
{
tables: tables,
relationships: relationships,
notes: notes,
subjectAreas: areas,
database: database,
...(databases[database].hasTypes && { types: types }),
...(databases[database].hasEnums && { enums: enums }),
title: title,
},
null,
2,
);
setExportData((prev) => ({
...prev,
data: result,
extension: "json",
}));
},
},
{
name: "DBML",
function: () => {
setModal(MODAL.CODE);
const result = toDBML({
tables,
relationships,
enums,
database,
});
setExportData((prev) => ({
...prev,
data: result,
extension: "dbml",
}));
},
},
{
name: "PDF",
function: () => {
const canvas = document.getElementById("canvas");
toJpeg(canvas).then(function (dataUrl) {
const doc = new jsPDF("l", "px", [
canvas.offsetWidth,
canvas.offsetHeight,
]);
doc.addImage(
dataUrl,
"jpeg",
0,
0,
canvas.offsetWidth,
canvas.offsetHeight,
);
doc.save(`${exportData.filename}.pdf`);
});
},
},
{
name: "Mermaid",
function: () => {
setModal(MODAL.CODE);
const result = jsonToMermaid({
tables: tables,
relationships: relationships,
notes: notes,
subjectAreas: areas,
database: database,
title: title,
});
setExportData((prev) => ({
...prev,
data: result,
extension: "md",
}));
},
},
{
name: "Markdown",
function: () => {
setModal(MODAL.CODE);
const result = jsonToDocumentation({
tables: tables,
relationships: relationships,
notes: notes,
subjectAreas: areas,
database: database,
title: title,
...(databases[database].hasTypes && { types: types }),
...(databases[database].hasEnums && { enums: enums }),
});
setExportData((prev) => ({
...prev,
data: result,
extension: "md",
}));
},
},
],
function: () => {},
},
exit: {
function: () => {
save();
if (saveState === State.SAVED) navigate("/");
},
},
},
edit: {
undo: {
function: undo,
shortcut: "Ctrl+Z",
disabled: layout.readOnly || undoStack.length === 0,
},
redo: {
function: redo,
shortcut: "Ctrl+Y",
disabled: layout.readOnly || redoStack.length === 0,
},
clear: {
warning: {
title: t("clear"),
message: t("are_you_sure_clear"),
},
function: async () => {
setTables([]);
setRelationships([]);
setAreas([]);
setNotes([]);
setEnums([]);
setTypes([]);
setUndoStack([]);
setRedoStack([]);
},
disabled: layout.readOnly,
},
edit: {
function: edit,
shortcut: "Ctrl+E",
disabled: layout.readOnly,
},
cut: {
function: cut,
shortcut: "Ctrl+X",
disabled: layout.readOnly,
},
copy: {
function: copy,
shortcut: "Ctrl+C",
},
paste: {
function: paste,
shortcut: "Ctrl+V",
disabled: layout.readOnly,
},
duplicate: {
function: duplicate,
shortcut: "Ctrl+D",
disabled: layout.readOnly,
},
delete: {
function: del,
shortcut: "Del",
disabled: layout.readOnly,
},
copy_as_image: {
function: copyAsImage,
shortcut: "Ctrl+Alt+C",
},
},
view: {
header: {
state: layout.header ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setLayout((prev) => ({ ...prev, header: !prev.header })),
},
sidebar: {
state: layout.sidebar ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setLayout((prev) => ({ ...prev, sidebar: !prev.sidebar })),
},
issues: {
state: layout.issues ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setLayout((prev) => ({ ...prev, issues: !prev.issues })),
},
dbml_view: {
state: layout.dbmlEditor ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: toggleDBMLEditor,
shortcut: "Alt+E",
},
strict_mode: {
state: settings.strictMode ? (
<i className="bi bi-toggle-off" />
) : (
<i className="bi bi-toggle-on" />
),
function: viewStrictMode,
shortcut: "Ctrl+Shift+M",
},
presentation_mode: {
function: () => {
setLayout((prev) => ({
...prev,
header: false,
sidebar: false,
toolbar: false,
}));
enterFullscreen();
},
},
field_details: {
state: settings.showFieldSummary ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: viewFieldSummary,
shortcut: "Ctrl+Shift+F",
},
reset_view: {
function: resetView,
shortcut: "Enter/Return",
},
show_comments: {
state: settings.showComments ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({
...prev,
showComments: !prev.showComments,
})),
},
show_datatype: {
state: settings.showDataTypes ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({
...prev,
showDataTypes: !prev.showDataTypes,
})),
},
show_grid: {
state: settings.showGrid ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: viewGrid,
shortcut: "Ctrl+Shift+G",
},
snap_to_grid: {
state: settings.snapToGrid ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: snapToGrid,
},
show_cardinality: {
state: settings.showCardinality ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({
...prev,
showCardinality: !prev.showCardinality,
})),
},
show_relationship_labels: {
state: settings.showRelationshipLabels ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({
...prev,
showRelationshipLabels: !prev.showRelationshipLabels,
})),
},
show_debug_coordinates: {
state: settings.showDebugCoordinates ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({
...prev,
showDebugCoordinates: !prev.showDebugCoordinates,
})),
},
theme: {
children: [
{
name: t("light"),
function: () => setSettings((prev) => ({ ...prev, mode: "light" })),
},
{
name: t("dark"),
function: () => setSettings((prev) => ({ ...prev, mode: "dark" })),
},
],
function: () => {},
},
zoom_in: {
function: zoomIn,
shortcut: "Ctrl+(Up/Wheel)",
},
zoom_out: {
function: zoomOut,
shortcut: "Ctrl+(Down/Wheel)",
},
fullscreen: {
state: fullscreen ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: fullscreen ? exitFullscreen : enterFullscreen,
},
},
settings: {
show_timeline: {
function: () => setSidesheet(SIDESHEET.TIMELINE),
},
autosave: {
state: settings.autosave ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({ ...prev, autosave: !prev.autosave })),
},
table_width: {
function: () => setModal(MODAL.TABLE_WIDTH),
disabled: layout.readOnly,
},
language: {
function: () => setModal(MODAL.LANGUAGE),
},
export_saved_data: {
function: exportSavedData,
},
clear_cache: {
function: () => {
deleteFromCache(gistId);
Toast.success(t("cache_cleared"));
},
},
flush_storage: {
warning: {
title: t("flush_storage"),
message: t("are_you_sure_flush_storage"),
},
function: async () => {
localStorage.removeItem(STORAGE_KEY);
db.delete()
.then(() => {
Toast.success(t("storage_flushed"));
navigate("/editor", { replace: true });
window.location.reload();
})
.catch(() => {
Toast.error(t("oops_smth_went_wrong"));
});
},
},
},
help: {
docs: {
function: () => window.open(`${socials.docs}`, "_blank"),
shortcut: "Ctrl+H",
},
shortcuts: {
function: () => window.open(`${socials.docs}/shortcuts`, "_blank"),
},
ask_on_discord: {
function: () => window.open(socials.discord, "_blank"),
},
report_bug: {
function: () => window.open("/bug-report", "_blank"),
},
},
};
useHotkeys("mod+i", fileImport, { preventDefault: true });
useHotkeys("mod+z", undo, { preventDefault: true });
useHotkeys("mod+y", redo, { preventDefault: true });
useHotkeys("mod+s", save, { preventDefault: true });
useHotkeys("mod+o", open, { preventDefault: true });
useHotkeys("mod+e", edit, { preventDefault: true });
useHotkeys("mod+d", duplicate, { preventDefault: true });
useHotkeys("mod+c", copy, { preventDefault: true });
useHotkeys("mod+v", paste, { preventDefault: true });
useHotkeys("mod+x", cut, { preventDefault: true });
useHotkeys("delete", del, { preventDefault: true });
useHotkeys("mod+shift+g", viewGrid, { preventDefault: true });
useHotkeys("mod+up", zoomIn, { preventDefault: true });
useHotkeys("mod+down", zoomOut, { preventDefault: true });
useHotkeys("mod+shift+m", viewStrictMode, {
preventDefault: true,
});
useHotkeys("mod+shift+f", viewFieldSummary, {
preventDefault: true,
});
useHotkeys("mod+shift+s", saveDiagramAs, {
preventDefault: true,
});
useHotkeys("mod+alt+c", copyAsImage, { preventDefault: true });
useHotkeys("enter", resetView, { preventDefault: true });
useHotkeys("mod+h", () => window.open(socials.docs, "_blank"), {
preventDefault: true,
});
useHotkeys("mod+alt+w", fitWindow, { preventDefault: true });
useHotkeys("alt+e", toggleDBMLEditor, { preventDefault: true });
return (
<>
<div>
{layout.header && (
<div
className="flex justify-between items-center me-7"
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
{header()}
{!isTemplate && (
<Button
type="primary"
className="!text-base me-2 !pe-6 !ps-5 !py-[18px] !rounded-md"
size="default"
icon={<IconShareStroked />}
onClick={() => setModal(MODAL.SHARE)}
>
{t("share")}
</Button>
)}
</div>
)}
{layout.toolbar && toolbar()}
</div>
<Modal
modal={modal}
exportData={exportData}
setExportData={setExportData}
title={title}
setTitle={setTitle}
setModal={setModal}
importFrom={importFrom}
importDb={importDb}
/>
<Sidesheet
type={sidesheet}
title={title}
setTitle={setTitle}
onClose={() => setSidesheet(SIDESHEET.NONE)}
/>
</>
);
function toolbar() {
return (
<div
className="py-1.5 px-5 flex justify-between items-center rounded-xl my-1 sm:mx-1 xl:mx-6 select-none overflow-hidden toolbar-theme"
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
<div className="flex justify-start items-center">
<LayoutDropdown />
<Divider layout="vertical" margin="8px" />
<Tooltip content={t("zoom_out")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm text-lg"
onClick={() =>
setTransform((prev) => ({ ...prev, zoom: prev.zoom / 1.2 }))
}
>
<i className="fa-solid fa-magnifying-glass-minus" />
</button>
</Tooltip>
<Dropdown
style={{ width: "240px" }}
position={isRtl(i18n.language) ? "bottomRight" : "bottomLeft"}
render={
<Dropdown.Menu
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
<Dropdown.Item
onClick={fitWindow}
style={{ display: "flex", justifyContent: "space-between" }}
>
<div>{t("fit_window_reset")}</div>
<div className="text-gray-400">Ctrl+Alt+W</div>
</Dropdown.Item>
<Dropdown.Divider />
{[0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 3.0].map((e, i) => (
<Dropdown.Item
key={i}
onClick={() => {
setTransform((prev) => ({ ...prev, zoom: e }));
}}
>
{Math.floor(e * 100)}%
</Dropdown.Item>
))}
<Dropdown.Divider />
<Dropdown.Item>
<InputNumber
field="zoom"
label={t("zoom")}
placeholder={t("zoom")}
suffix={<div className="p-1">%</div>}
onChange={(v) =>
setTransform((prev) => ({
...prev,
zoom: parseFloat(v) * 0.01,
}))
}
/>
</Dropdown.Item>
</Dropdown.Menu>
}
trigger="click"
>
<div className="py-1 px-2 hover-2 rounded-sm flex items-center justify-center">
<div className="w-[40px]">
{Math.floor(transform.zoom * 100)}%
</div>
<div>
<IconCaretdown />
</div>
</div>
</Dropdown>
<Tooltip content={t("zoom_in")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm text-lg"
onClick={() =>
setTransform((prev) => ({ ...prev, zoom: prev.zoom * 1.2 }))
}
>
<i className="fa-solid fa-magnifying-glass-plus" />
</button>
</Tooltip>
<Divider layout="vertical" margin="8px" />
<Tooltip content={t("undo")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm flex items-center disabled:opacity-50"
disabled={undoStack.length === 0 || layout.readOnly}
onClick={undo}
>
<IconUndo size="large" />
</button>
</Tooltip>
<Tooltip content={t("redo")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm flex items-center disabled:opacity-50"
disabled={redoStack.length === 0 || layout.readOnly}
onClick={redo}
>
<IconRedo size="large" />
</button>
</Tooltip>
<Divider layout="vertical" margin="8px" />
<Tooltip content={t("add_table")} position="bottom">
<button
className="flex items-center py-1 px-2 hover-2 rounded-sm disabled:opacity-50"
onClick={() => addTable()}
disabled={layout.readOnly}
>
<IconAddTable />
</button>
</Tooltip>
<Tooltip content={t("add_area")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm flex items-center disabled:opacity-50"
onClick={() => addArea()}
disabled={layout.readOnly}
>
<IconAddArea />
</button>
</Tooltip>
<Tooltip content={t("add_note")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm flex items-center disabled:opacity-50"
onClick={() => addNote()}
disabled={layout.readOnly}
>
<IconAddNote />
</button>
</Tooltip>
<Divider layout="vertical" margin="8px" />
<Tooltip content={t("save")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm flex items-center disabled:opacity-50"
onClick={save}
disabled={layout.readOnly}
>
<IconSaveStroked size="extra-large" />
</button>
</Tooltip>
<Divider layout="vertical" margin="8px" />
<Tooltip content={t("versions")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm text-xl -mt-0.5"
onClick={() => setSidesheet(SIDESHEET.VERSIONS)}
>
<i className="fa-solid fa-code-branch" />
</button>
</Tooltip>
<Divider layout="vertical" margin="8px" />
<Tooltip content={t("theme")} position="bottom">
<button
className="py-1 px-2 hover-2 rounded-sm text-xl -mt-0.5"
onClick={() => {
const body = document.body;
if (body.hasAttribute("theme-mode")) {
if (body.getAttribute("theme-mode") === "light") {
menu["view"]["theme"].children[1].function();
} else {
menu["view"]["theme"].children[0].function();
}
}
}}
>
<i className="fa-solid fa-circle-half-stroke" />
</button>
</Tooltip>
</div>
<button
onClick={() => invertLayout("header")}
className="flex items-center"
>
{layout.header ? <IconChevronUp /> : <IconChevronDown />}
</button>
</div>
);
}
function getState() {
switch (saveState) {
case State.NONE:
return t("no_changes");
case State.LOADING:
return t("loading");
case State.SAVED:
return `${t("last_saved")} ${lastSaved}`;
case State.SAVING:
return t("saving");
case State.ERROR:
return t("failed_to_save");
case State.FAILED_TO_LOAD:
return t("failed_to_load");
default:
return "";
}
}
function header() {
return (
<nav
className="flex justify-between pt-1 items-center whitespace-nowrap"
style={isRtl(i18n.language) ? { direction: "rtl" } : {}}
>
<div className="flex justify-start items-center">
<Link to="/">
<img
width={54}
src={icon}
alt="logo"
className="ms-7 min-w-[54px]"
/>
</Link>
<div className="ms-1 mt-1">
<div className="flex items-center ms-3 gap-2">
{databases[database].image && (
<img
src={databases[database].image}
className="h-5"
style={{
filter:
"opacity(0.4) drop-shadow(0 0 0 white) drop-shadow(0 0 0 white)",
}}
alt={databases[database].name + " icon"}
title={databases[database].name + " diagram"}
/>
)}
<div
className="text-xl flex items-center gap-1 me-1"
onPointerEnter={(e) => e.isPrimary && setShowEditName(true)}
onPointerLeave={(e) => e.isPrimary && setShowEditName(false)}
onPointerDown={(e) => {
// Required for onPointerLeave to trigger when a touch pointer leaves
// https://stackoverflow.com/a/70976017/1137077
e.target.releasePointerCapture(e.pointerId);
}}
onClick={!layout.readOnly && (() => setModal(MODAL.RENAME))}
>
<span>{(isTemplate ? "Templates/" : "Diagrams/") + title}</span>
{version && (
<Tag className="mt-1" color="blue" size="small">
{version.substring(0, 7)}
</Tag>
)}
</div>
{(showEditName || modal === MODAL.RENAME) && !layout.readOnly && (
<IconEdit />
)}
</div>
<div className="flex items-center">
<div className="flex justify-start text-md select-none me-2">
{Object.keys(menu).map((category) => (
<Dropdown
key={category}
position="bottomLeft"
style={{
width: "240px",
direction: isRtl(i18n.language) ? "rtl" : "ltr",
}}
render={
<Dropdown.Menu className="menu max-h-[calc(100vh-80px)] overflow-auto">
{Object.keys(menu[category]).map((item, index) => {
if (menu[category][item].children) {
return (
<Dropdown
className="min-w-36 max-w-72"
key={item}
position="rightTop"
render={
<Dropdown.Menu>
{menu[category][item].children.map(
(e, i) => {
if (e.divider) {
return (
<Dropdown.Divider
key={`divider-${i}`}
/>
);
}
return (
<Dropdown.Item
key={i}
onClick={e.function}
className="flex w-full items-center justify-between gap-1"
disabled={e.disabled}
>
<span className="truncate flex-1 min-w-0">
{e.name}
</span>
{e.label && (
<Tag
size="small"
className="flex-shrink-0"
>
{e.label}
</Tag>
)}
</Dropdown.Item>
);
},
)}
</Dropdown.Menu>
}
>
<Dropdown.Item
style={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
gitextract_axfxdxsb/ ├── .dockerignore ├── .eslintrc.cjs ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.md │ │ └── feature_request.md │ └── workflows/ │ ├── build.yml │ └── docker.yml ├── .gitignore ├── .prettierrc.json ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── README.md ├── compose.yml ├── index.html ├── package.json ├── postcss.config.js ├── public/ │ └── robots.txt ├── src/ │ ├── App.jsx │ ├── animations/ │ │ ├── FadeIn.jsx │ │ └── SlideIn.jsx │ ├── api/ │ │ ├── email.js │ │ └── gists.js │ ├── components/ │ │ ├── CodeEditor/ │ │ │ ├── index.jsx │ │ │ └── setUpDBML.js │ │ ├── EditorCanvas/ │ │ │ ├── Area.jsx │ │ │ ├── Canvas.jsx │ │ │ ├── Note.jsx │ │ │ ├── Relationship.jsx │ │ │ └── Table.jsx │ │ ├── EditorHeader/ │ │ │ ├── ControlPanel.jsx │ │ │ ├── LayoutDropdown.jsx │ │ │ ├── Modal/ │ │ │ │ ├── ImportDiagram.jsx │ │ │ │ ├── ImportSource.jsx │ │ │ │ ├── Language.jsx │ │ │ │ ├── Modal.jsx │ │ │ │ ├── New.jsx │ │ │ │ ├── Open.jsx │ │ │ │ ├── Rename.jsx │ │ │ │ ├── SetTableWidth.jsx │ │ │ │ └── Share.jsx │ │ │ └── SideSheet/ │ │ │ ├── Migration.jsx │ │ │ ├── Sidesheet.jsx │ │ │ ├── Timeline.jsx │ │ │ └── Versions.jsx │ │ ├── EditorSidePanel/ │ │ │ ├── AreasTab/ │ │ │ │ ├── AreaDetails.jsx │ │ │ │ ├── AreasTab.jsx │ │ │ │ └── SearchBar.jsx │ │ │ ├── ColorPicker.jsx │ │ │ ├── DBMLEditor.jsx │ │ │ ├── Empty.jsx │ │ │ ├── EnumsTab/ │ │ │ │ ├── EnumDetails.jsx │ │ │ │ ├── EnumsTab.jsx │ │ │ │ └── SearchBar.jsx │ │ │ ├── Issues.jsx │ │ │ ├── NotesTab/ │ │ │ │ ├── NoteInfo.jsx │ │ │ │ ├── NotesTab.jsx │ │ │ │ └── SearchBar.jsx │ │ │ ├── RelationshipsTab/ │ │ │ │ ├── RelationshipInfo.jsx │ │ │ │ ├── RelationshipsTab.jsx │ │ │ │ └── SearchBar.jsx │ │ │ ├── SidePanel.jsx │ │ │ ├── TablesTab/ │ │ │ │ ├── FieldDetails.jsx │ │ │ │ ├── IndexDetails.jsx │ │ │ │ ├── SearchBar.jsx │ │ │ │ ├── TableField.jsx │ │ │ │ ├── TableInfo.jsx │ │ │ │ └── TablesTab.jsx │ │ │ └── TypesTab/ │ │ │ ├── SearchBar.jsx │ │ │ ├── TypeField.jsx │ │ │ ├── TypeInfo.jsx │ │ │ └── TypesTab.jsx │ │ ├── FloatingControls.jsx │ │ ├── LexicalEditor/ │ │ │ ├── AutoLinkPlugin.jsx │ │ │ ├── CodeHighlightPlugin.jsx │ │ │ ├── ListMaxIndentLevelPlugin.jsx │ │ │ ├── RichEditor.jsx │ │ │ ├── ToolbarPlugin.jsx │ │ │ └── styles/ │ │ │ └── index.css │ │ ├── Navbar.jsx │ │ ├── SimpleCanvas.jsx │ │ ├── SortableList/ │ │ │ ├── DragHandle.jsx │ │ │ ├── SortableItem.jsx │ │ │ └── SortableList.jsx │ │ ├── Thumbnail.jsx │ │ └── Workspace.jsx │ ├── context/ │ │ ├── AreasContext.jsx │ │ ├── CanvasContext.jsx │ │ ├── DiagramContext.jsx │ │ ├── EnumsContext.jsx │ │ ├── LayoutContext.jsx │ │ ├── NotesContext.jsx │ │ ├── SaveStateContext.jsx │ │ ├── SelectContext.jsx │ │ ├── SettingsContext.jsx │ │ ├── TransformContext.jsx │ │ ├── TypesContext.jsx │ │ └── UndoRedoContext.jsx │ ├── data/ │ │ ├── constants.js │ │ ├── databases.js │ │ ├── datatypes.js │ │ ├── db.js │ │ ├── editorConfig.js │ │ ├── heroDiagram.js │ │ ├── schemas.js │ │ ├── seeds.js │ │ ├── socials.js │ │ └── surveyQuestions.js │ ├── hooks/ │ │ ├── index.js │ │ ├── useAreas.js │ │ ├── useCanvas.js │ │ ├── useDiagram.js │ │ ├── useEnums.js │ │ ├── useFullscreen.js │ │ ├── useLayout.js │ │ ├── useNotes.js │ │ ├── useSaveState.js │ │ ├── useSelect.js │ │ ├── useSettings.js │ │ ├── useThemedPage.js │ │ ├── useTransform.js │ │ ├── useTypes.js │ │ └── useUndoRedo.js │ ├── i18n/ │ │ ├── i18n.js │ │ ├── locales/ │ │ │ ├── ar.js │ │ │ ├── as.js │ │ │ ├── bg.js │ │ │ ├── bn.js │ │ │ ├── cz.js │ │ │ ├── da.js │ │ │ ├── de.js │ │ │ ├── el.js │ │ │ ├── en.js │ │ │ ├── es.js │ │ │ ├── fa.js │ │ │ ├── fi.js │ │ │ ├── fr.js │ │ │ ├── gu.js │ │ │ ├── he.js │ │ │ ├── hi.js │ │ │ ├── hu.js │ │ │ ├── hy.js │ │ │ ├── id.js │ │ │ ├── it.js │ │ │ ├── jp.js │ │ │ ├── ka.js │ │ │ ├── ko.js │ │ │ ├── ml.js │ │ │ ├── mn.js │ │ │ ├── mr.js │ │ │ ├── ms.js │ │ │ ├── ne.js │ │ │ ├── nl.js │ │ │ ├── no.js │ │ │ ├── od.js │ │ │ ├── pa-pk.js │ │ │ ├── pa.js │ │ │ ├── pl.js │ │ │ ├── pt-br.js │ │ │ ├── ro.js │ │ │ ├── ru.js │ │ │ ├── sd.js │ │ │ ├── sv-se.js │ │ │ ├── sw.js │ │ │ ├── te.js │ │ │ ├── th.js │ │ │ ├── tl.js │ │ │ ├── tm.js │ │ │ ├── tr.js │ │ │ ├── ug.js │ │ │ ├── uk.js │ │ │ ├── ur.js │ │ │ ├── vi.js │ │ │ ├── zh-tw.js │ │ │ └── zh.js │ │ └── utils/ │ │ └── rtl.js │ ├── icons/ │ │ ├── IconAddArea.jsx │ │ ├── IconAddNote.jsx │ │ ├── IconAddTable.jsx │ │ └── index.js │ ├── index.css │ ├── main.jsx │ ├── pages/ │ │ ├── BugReport.jsx │ │ ├── Editor.jsx │ │ ├── LandingPage.jsx │ │ ├── NotFound.jsx │ │ └── Templates.jsx │ ├── templates/ │ │ ├── template1.js │ │ ├── template2.js │ │ ├── template3.js │ │ ├── template4.js │ │ ├── template5.js │ │ └── template6.js │ └── utils/ │ ├── arrangeTables.js │ ├── cache.js │ ├── calcPath.js │ ├── diff.js │ ├── exportAs/ │ │ ├── dbml.js │ │ ├── documentation.js │ │ └── mermaid.js │ ├── exportSQL/ │ │ ├── generic.js │ │ ├── index.js │ │ ├── mariadb.js │ │ ├── mssql.js │ │ ├── mysql.js │ │ ├── oraclesql.js │ │ ├── postgres.js │ │ ├── shared.js │ │ └── sqlite.js │ ├── exportSavedData.js │ ├── fullscreen.js │ ├── importFrom/ │ │ └── dbml.js │ ├── importSQL/ │ │ ├── index.js │ │ ├── mariadb.js │ │ ├── mssql.js │ │ ├── mysql.js │ │ ├── oraclesql.js │ │ ├── postgres.js │ │ ├── shared.js │ │ └── sqlite.js │ ├── issues.js │ ├── migrations/ │ │ └── diffToSQL.js │ ├── modalData.js │ ├── rect.js │ ├── utils.js │ └── validateSchema.js ├── tailwind.config.js ├── vercel.json └── vite.config.js
SYMBOL INDEX (219 symbols across 134 files)
FILE: src/App.jsx
function App (line 10) | function App() {
function RestoreScroll (line 29) | function RestoreScroll() {
FILE: src/animations/FadeIn.jsx
function FadeIn (line 4) | function FadeIn({ children, duration }) {
FILE: src/animations/SlideIn.jsx
function SlideIn (line 4) | function SlideIn({ children, duration, delay, className }) {
FILE: src/api/email.js
function send (line 3) | async function send(subject, message, attachments) {
FILE: src/api/gists.js
constant SHARE_FILENAME (line 3) | const SHARE_FILENAME = "share.json";
constant VERSION_FILENAME (line 4) | const VERSION_FILENAME = "versionned.json";
function create (line 9) | async function create(filename, content) {
function patch (line 20) | async function patch(gistId, filename, content) {
function del (line 29) | async function del(gistId) {
function get (line 33) | async function get(gistId) {
function getCommits (line 39) | async function getCommits(gistId, perPage = 20, page = 1) {
function getVersion (line 50) | async function getVersion(gistId, sha) {
function getCommitsWithFile (line 56) | async function getCommitsWithFile(
function compare (line 75) | async function compare(gistId, file, versionA, versionB) {
FILE: src/components/CodeEditor/index.jsx
function CodeEditor (line 9) | function CodeEditor({
FILE: src/components/CodeEditor/setUpDBML.js
function setUpDBML (line 3) | function setUpDBML(monaco, database) {
FILE: src/components/EditorCanvas/Area.jsx
function Area (line 22) | function Area({
function EditPopoverContent (line 256) | function EditPopoverContent({ data }) {
FILE: src/components/EditorCanvas/Canvas.jsx
function Canvas (line 36) | function Canvas() {
FILE: src/components/EditorCanvas/Note.jsx
function Note (line 23) | function Note({ data, onPointerDown }) {
FILE: src/components/EditorCanvas/Relationship.jsx
function Relationship (line 11) | function Relationship({ data }) {
function CardinalityLabel (line 191) | function CardinalityLabel({ x, y, text, r = 12, padding = 14 }) {
FILE: src/components/EditorCanvas/Table.jsx
function Table (line 27) | function Table({
FILE: src/components/EditorHeader/ControlPanel.jsx
function ControlPanel (line 89) | function ControlPanel({ title, setTitle, lastSaved }) {
FILE: src/components/EditorHeader/LayoutDropdown.jsx
function LayoutDropdown (line 13) | function LayoutDropdown() {
FILE: src/components/EditorHeader/Modal/ImportDiagram.jsx
function ImportDiagram (line 17) | function ImportDiagram({
FILE: src/components/EditorHeader/Modal/ImportSource.jsx
function ImportSource (line 6) | function ImportSource({
FILE: src/components/EditorHeader/Modal/Language.jsx
function Language (line 4) | function Language({ language, setLanguage }) {
FILE: src/components/EditorHeader/Modal/Modal.jsx
function Modal (line 44) | function Modal({
FILE: src/components/EditorHeader/Modal/New.jsx
function New (line 7) | function New({ selectedTemplateId, setSelectedTemplateId }) {
FILE: src/components/EditorHeader/Modal/Open.jsx
function Open (line 7) | function Open({ selectedDiagramId, setSelectedDiagramId }) {
FILE: src/components/EditorHeader/Modal/Rename.jsx
function Rename (line 5) | function Rename({ title, setTitle }) {
FILE: src/components/EditorHeader/Modal/SetTableWidth.jsx
function SetTableWidth (line 4) | function SetTableWidth({ tempWidth, setTempWidth }) {
FILE: src/components/EditorHeader/Modal/Share.jsx
function Share (line 18) | function Share({ title, setModal }) {
FILE: src/components/EditorHeader/SideSheet/Migration.jsx
function Migration (line 13) | function Migration({
FILE: src/components/EditorHeader/SideSheet/Sidesheet.jsx
function Sidesheet (line 7) | function Sidesheet({ type, title, setTitle, onClose }) {
FILE: src/components/EditorHeader/SideSheet/Timeline.jsx
function Timeline (line 5) | function Timeline() {
FILE: src/components/EditorHeader/SideSheet/Versions.jsx
constant LIMIT (line 30) | const LIMIT = 10;
function Versions (line 32) | function Versions({ open, title, setTitle }) {
FILE: src/components/EditorSidePanel/AreasTab/AreaDetails.jsx
function AreaInfo (line 9) | function AreaInfo({ data, i }) {
FILE: src/components/EditorSidePanel/AreasTab/AreasTab.jsx
function AreasTab (line 9) | function AreasTab() {
FILE: src/components/EditorSidePanel/AreasTab/SearchBar.jsx
function SearchBar (line 7) | function SearchBar() {
FILE: src/components/EditorSidePanel/ColorPicker.jsx
function ColorPicker (line 4) | function ColorPicker({
FILE: src/components/EditorSidePanel/DBMLEditor.jsx
function DBMLEditor (line 9) | function DBMLEditor() {
FILE: src/components/EditorSidePanel/Empty.jsx
function Empty (line 7) | function Empty({ title, text }) {
FILE: src/components/EditorSidePanel/EnumsTab/EnumDetails.jsx
function EnumDetails (line 8) | function EnumDetails({ data }) {
FILE: src/components/EditorSidePanel/EnumsTab/EnumsTab.jsx
function EnumsTab (line 9) | function EnumsTab() {
FILE: src/components/EditorSidePanel/EnumsTab/SearchBar.jsx
function SearchBar (line 7) | function SearchBar() {
FILE: src/components/EditorSidePanel/Issues.jsx
function Issues (line 8) | function Issues() {
FILE: src/components/EditorSidePanel/NotesTab/NoteInfo.jsx
function NoteInfo (line 9) | function NoteInfo({ data, nid }) {
FILE: src/components/EditorSidePanel/NotesTab/NotesTab.jsx
function NotesTab (line 9) | function NotesTab() {
FILE: src/components/EditorSidePanel/NotesTab/SearchBar.jsx
function SearchBar (line 7) | function SearchBar({ setActiveKey }) {
FILE: src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx
function RelationshipInfo (line 37) | function RelationshipInfo({ data }) {
FILE: src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx
function RelationshipsTab (line 11) | function RelationshipsTab() {
FILE: src/components/EditorSidePanel/RelationshipsTab/SearchBar.jsx
function SearchBar (line 8) | function SearchBar() {
FILE: src/components/EditorSidePanel/SidePanel.jsx
function SidePanel (line 27) | function SidePanel({ width, resize, setResize }) {
FILE: src/components/EditorSidePanel/TablesTab/FieldDetails.jsx
function FieldDetails (line 17) | function FieldDetails({ data, tid }) {
FILE: src/components/EditorSidePanel/TablesTab/IndexDetails.jsx
function IndexDetails (line 8) | function IndexDetails({ data, fields, iid, tid }) {
FILE: src/components/EditorSidePanel/TablesTab/SearchBar.jsx
function SearchBar (line 8) | function SearchBar({ tables }) {
FILE: src/components/EditorSidePanel/TablesTab/TableField.jsx
function TableField (line 17) | function TableField({ data, tid, index, inherited }) {
FILE: src/components/EditorSidePanel/TablesTab/TableInfo.jsx
function TableInfo (line 25) | function TableInfo({ data }) {
FILE: src/components/EditorSidePanel/TablesTab/TablesTab.jsx
function TablesTab (line 19) | function TablesTab() {
function TableListItem (line 75) | function TableListItem({ table }) {
FILE: src/components/EditorSidePanel/TypesTab/SearchBar.jsx
function Searchbar (line 8) | function Searchbar() {
FILE: src/components/EditorSidePanel/TypesTab/TypeField.jsx
function TypeField (line 24) | function TypeField({ data, tid, fid }) {
FILE: src/components/EditorSidePanel/TypesTab/TypeInfo.jsx
function TypeInfo (line 18) | function TypeInfo({ index, data }) {
FILE: src/components/EditorSidePanel/TypesTab/TypesTab.jsx
function TypesTab (line 10) | function TypesTab() {
FILE: src/components/FloatingControls.jsx
function FloatingControls (line 6) | function FloatingControls() {
FILE: src/components/LexicalEditor/AutoLinkPlugin.jsx
constant URL_MATCHER (line 7) | const URL_MATCHER =
constant EMAIL_MATCHER (line 10) | const EMAIL_MATCHER =
constant MATCHERS (line 13) | const MATCHERS = [
function PlaygroundAutoLinkPlugin (line 38) | function PlaygroundAutoLinkPlugin() {
FILE: src/components/LexicalEditor/CodeHighlightPlugin.jsx
function CodeHighlightPlugin (line 9) | function CodeHighlightPlugin() {
FILE: src/components/LexicalEditor/ListMaxIndentLevelPlugin.jsx
function getElementNodesInSelection (line 16) | function getElementNodesInSelection(selection) {
function isIndentPermitted (line 31) | function isIndentPermitted(maxDepth) {
function ListMaxIndentLevelPlugin (line 60) | function ListMaxIndentLevelPlugin({ maxDepth }) {
FILE: src/components/LexicalEditor/RichEditor.jsx
function Placeholder (line 17) | function Placeholder({ text }) {
function RichEditor (line 21) | function RichEditor({ theme, placeholder }) {
FILE: src/components/LexicalEditor/ToolbarPlugin.jsx
function Divider (line 71) | function Divider() {
function positionEditorElement (line 75) | function positionEditorElement(editor, rect) {
function FloatingLinkEditor (line 89) | function FloatingLinkEditor({ editor }) {
function Select (line 217) | function Select({ onChange, className, options, value }) {
function getSelectedNode (line 230) | function getSelectedNode(selection) {
function BlockOptionsDropdownList (line 246) | function BlockOptionsDropdownList({ editor, blockType }) {
function ToolbarPlugin (line 381) | function ToolbarPlugin() {
FILE: src/components/Navbar.jsx
function Navbar (line 8) | function Navbar() {
FILE: src/components/SimpleCanvas.jsx
function Table (line 11) | function Table({ table, grab }) {
function Relationship (line 79) | function Relationship({ relationship, tables }) {
function SimpleCanvas (line 169) | function SimpleCanvas({ diagram, zoom }) {
FILE: src/components/SortableList/DragHandle.jsx
function DragHandle (line 4) | function DragHandle({ id, readOnly }) {
FILE: src/components/SortableList/SortableItem.jsx
function SortableItem (line 4) | function SortableItem({ children, id }) {
FILE: src/components/SortableList/SortableList.jsx
function SortableList (line 15) | function SortableList({
FILE: src/components/Thumbnail.jsx
function Thumbnail (line 11) | function Thumbnail({ diagram, i, zoom, theme }) {
FILE: src/components/Workspace.jsx
constant SIDEPANEL_MIN_WIDTH (line 42) | const SIDEPANEL_MIN_WIDTH = 384;
function WorkSpace (line 44) | function WorkSpace() {
FILE: src/context/AreasContext.jsx
function AreasContextProvider (line 9) | function AreasContextProvider({ children }) {
FILE: src/context/CanvasContext.jsx
method toDiagramSpace (line 14) | toDiagramSpace(coords) {
method toScreenSpace (line 17) | toScreenSpace(coords) {
method setStyle (line 33) | setStyle() {}
function CanvasContextProvider (line 37) | function CanvasContextProvider({ children, ...attrs }) {
FILE: src/context/DiagramContext.jsx
function DiagramContextProvider (line 10) | function DiagramContextProvider({ children }) {
FILE: src/context/EnumsContext.jsx
function EnumsContextProvider (line 10) | function EnumsContextProvider({ children }) {
FILE: src/context/LayoutContext.jsx
function LayoutContextProvider (line 5) | function LayoutContextProvider({ children }) {
FILE: src/context/NotesContext.jsx
function NotesContextProvider (line 14) | function NotesContextProvider({ children }) {
FILE: src/context/SaveStateContext.jsx
function SaveStateContextProvider (line 6) | function SaveStateContextProvider({ children }) {
FILE: src/context/SelectContext.jsx
function SelectContextProvider (line 6) | function SelectContextProvider({ children }) {
FILE: src/context/SettingsContext.jsx
function SettingsContextProvider (line 21) | function SettingsContextProvider({ children }) {
FILE: src/context/TransformContext.jsx
function TransformContextProvider (line 5) | function TransformContextProvider({ children }) {
FILE: src/context/TypesContext.jsx
function TypesContextProvider (line 10) | function TypesContextProvider({ children }) {
FILE: src/context/UndoRedoContext.jsx
function UndoRedoContextProvider (line 10) | function UndoRedoContextProvider({ children }) {
FILE: src/data/constants.js
constant MODAL (line 77) | const MODAL = {
constant STATUS (line 92) | const STATUS = {
constant SIDESHEET (line 99) | const SIDESHEET = {
constant IMPORT_FROM (line 115) | const IMPORT_FROM = {
FILE: src/data/editorConfig.js
method onError (line 77) | onError(error) {
FILE: src/hooks/useAreas.js
function useAreas (line 4) | function useAreas() {
FILE: src/hooks/useCanvas.js
function useCanvas (line 4) | function useCanvas() {
FILE: src/hooks/useDiagram.js
function useDiagram (line 4) | function useDiagram() {
FILE: src/hooks/useEnums.js
function useEnums (line 4) | function useEnums() {
FILE: src/hooks/useFullscreen.js
function useFullscreen (line 4) | function useFullscreen() {
FILE: src/hooks/useLayout.js
function useLayout (line 4) | function useLayout() {
FILE: src/hooks/useNotes.js
function useNotes (line 4) | function useNotes() {
FILE: src/hooks/useSaveState.js
function useSaveState (line 4) | function useSaveState() {
FILE: src/hooks/useSelect.js
function useSelect (line 4) | function useSelect() {
FILE: src/hooks/useSettings.js
function useSettings (line 4) | function useSettings() {
FILE: src/hooks/useThemedPage.js
function useThemedPage (line 7) | function useThemedPage() {
FILE: src/hooks/useTransform.js
function useTransform (line 4) | function useTransform() {
FILE: src/hooks/useTypes.js
function useTypes (line 4) | function useTypes() {
FILE: src/hooks/useUndoRedo.js
function useUndoRedo (line 4) | function useUndoRedo() {
FILE: src/icons/IconAddArea.jsx
function IconAddArea (line 1) | function IconAddArea() {
FILE: src/icons/IconAddNote.jsx
function IconAddNote (line 1) | function IconAddNote() {
FILE: src/icons/IconAddTable.jsx
function IconAddTable (line 1) | function IconAddTable() {
FILE: src/pages/BugReport.jsx
function Form (line 17) | function Form({ theme }) {
function BugReport (line 126) | function BugReport() {
FILE: src/pages/Editor.jsx
function Editor (line 14) | function Editor() {
FILE: src/pages/LandingPage.jsx
function shortenNumber (line 22) | function shortenNumber(number) {
function LandingPage (line 29) | function LandingPage() {
FILE: src/pages/NotFound.jsx
function NotFound (line 3) | function NotFound() {
FILE: src/pages/Templates.jsx
function Templates (line 11) | function Templates() {
FILE: src/utils/arrangeTables.js
function arrangeTables (line 7) | function arrangeTables(diagram) {
FILE: src/utils/cache.js
constant STORAGE_KEY (line 1) | const STORAGE_KEY = "versions_cache";
function loadCache (line 3) | function loadCache() {
function saveCache (line 12) | function saveCache(cache) {
function deleteFromCache (line 16) | function deleteFromCache(key) {
FILE: src/utils/calcPath.js
function calcPath (line 17) | function calcPath(r, tableWidth = 200, zoom = 1, showComments = true) {
FILE: src/utils/exportAs/dbml.js
constant IDENT_SAFE_RE (line 7) | const IDENT_SAFE_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
function escapeIdentifier (line 9) | function escapeIdentifier(s) {
function quoteIdentifier (line 13) | function quoteIdentifier(name) {
function parseDefaultDbml (line 19) | function parseDefaultDbml(field, database) {
function columnDefault (line 31) | function columnDefault(field, database) {
function columnSettings (line 43) | function columnSettings(field, database) {
function cardinality (line 62) | function cardinality(rel) {
function fieldSize (line 76) | function fieldSize(field, database) {
function processComment (line 85) | function processComment(comment) {
function columnComment (line 93) | function columnComment(field) {
function processType (line 101) | function processType(type) {
function toDBML (line 110) | function toDBML(diagram) {
FILE: src/utils/exportAs/documentation.js
function jsonToDocumentation (line 5) | function jsonToDocumentation(obj) {
FILE: src/utils/exportAs/mermaid.js
function jsonToMermaid (line 5) | function jsonToMermaid(obj) {
FILE: src/utils/exportSQL/generic.js
function getJsonType (line 5) | function getJsonType(f) {
function generateSchema (line 35) | function generateSchema(type) {
function getTypeString (line 43) | function getTypeString(
function jsonToMySQL (line 186) | function jsonToMySQL(obj) {
function jsonToPostgreSQL (line 248) | function jsonToPostgreSQL(obj) {
function getSQLiteType (line 355) | function getSQLiteType(field) {
function jsonToSQLite (line 388) | function jsonToSQLite(obj) {
function jsonToMariaDB (line 429) | function jsonToMariaDB(obj) {
function jsonToSQLServer (line 493) | function jsonToSQLServer(obj) {
function jsonToOracleSQL (line 565) | function jsonToOracleSQL(obj) {
FILE: src/utils/exportSQL/index.js
function exportSQL (line 9) | function exportSQL(diagram) {
FILE: src/utils/exportSQL/mariadb.js
function parseType (line 6) | function parseType(field) {
function toMariaDB (line 20) | function toMariaDB(diagram) {
FILE: src/utils/exportSQL/mssql.js
function generateAddExtendedPropertySQL (line 6) | function generateAddExtendedPropertySQL(value, level1name, level2name = ...
function toMSSQL (line 34) | function toMSSQL(diagram) {
FILE: src/utils/exportSQL/mysql.js
function parseType (line 6) | function parseType(field) {
function toMySQL (line 23) | function toMySQL(diagram) {
FILE: src/utils/exportSQL/oraclesql.js
function toOracleSQL (line 4) | function toOracleSQL(diagram) {
FILE: src/utils/exportSQL/postgres.js
function toPostgres (line 4) | function toPostgres(diagram) {
FILE: src/utils/exportSQL/shared.js
function parseDefault (line 6) | function parseDefault(field, database = DB.GENERIC) {
function escapeQuotes (line 18) | function escapeQuotes(str) {
function exportFieldComment (line 22) | function exportFieldComment(comment) {
function getInlineFK (line 33) | function getInlineFK(table, obj) {
FILE: src/utils/exportSQL/sqlite.js
function toSqlite (line 5) | function toSqlite(diagram) {
FILE: src/utils/exportSavedData.js
function exportSavedData (line 7) | async function exportSavedData() {
FILE: src/utils/fullscreen.js
function enterFullscreen (line 1) | function enterFullscreen() {
function exitFullscreen (line 14) | function exitFullscreen() {
FILE: src/utils/importFrom/dbml.js
function fromDBML (line 8) | function fromDBML(src) {
FILE: src/utils/importSQL/index.js
function importSQL (line 10) | function importSQL(ast, toDb = DB.MYSQL, diagramDb = DB.GENERIC) {
FILE: src/utils/importSQL/mariadb.js
function fromMariaDB (line 23) | function fromMariaDB(ast, diagramDb = DB.GENERIC) {
FILE: src/utils/importSQL/mssql.js
function fromMSSQL (line 35) | function fromMSSQL(ast, diagramDb = DB.GENERIC) {
FILE: src/utils/importSQL/mysql.js
function fromMySQL (line 23) | function fromMySQL(ast, diagramDb = DB.GENERIC) {
FILE: src/utils/importSQL/oraclesql.js
function fromOracleSQL (line 24) | function fromOracleSQL(ast, diagramDb = DB.GENERIC) {
FILE: src/utils/importSQL/postgres.js
function fromPostgres (line 22) | function fromPostgres(ast, diagramDb = DB.GENERIC) {
FILE: src/utils/importSQL/shared.js
function quoteColumn (line 3) | function quoteColumn(str, db) {
function buildSQLFromAST (line 18) | function buildSQLFromAST(ast, db = DB.MYSQL) {
FILE: src/utils/importSQL/sqlite.js
function fromSQLite (line 40) | function fromSQLite(ast, diagramDb = DB.GENERIC) {
FILE: src/utils/issues.js
function checkDefault (line 5) | function checkDefault(field, database) {
function getIssues (line 19) | function getIssues(diagram) {
FILE: src/utils/migrations/diffToSQL.js
function getQuote (line 10) | function getQuote(db) {
function parseType (line 16) | function parseType(field, db) {
function columnDefinition (line 29) | function columnDefinition(field, db) {
function toTable (line 69) | function toTable(table, db) {
function resolveRel (line 185) | function resolveRel(diagram, rel) {
function normalizeFkAction (line 201) | function normalizeFkAction(s) {
function toTypeDefinition (line 205) | function toTypeDefinition(type, database, q) {
function toEnumDefinition (line 217) | function toEnumDefinition(e, database, q) {
FILE: src/utils/rect.js
function getRectFromEndpoints (line 1) | function getRectFromEndpoints({ x1, x2, y1, y2 }) {
function isInsideRect (line 11) | function isInsideRect(rect1, rect2) {
FILE: src/utils/utils.js
function dataURItoBlob (line 9) | function dataURItoBlob(dataUrl) {
function arrayIsEqual (line 22) | function arrayIsEqual(arr1, arr2) {
function strHasQuotes (line 26) | function strHasQuotes(str) {
function isKeyword (line 47) | function isKeyword(str) {
function isFunction (line 53) | function isFunction(str) {
function areFieldsCompatible (line 57) | function areFieldsCompatible(db, field1Type, field2Type) {
function getCommentHeight (line 65) | function getCommentHeight(comment, containerWidth, showComments = true) {
function getTableHeight (line 85) | function getTableHeight(table, width, showComments = true) {
FILE: src/utils/validateSchema.js
function jsonDiagramIsValid (line 4) | function jsonDiagramIsValid(obj) {
function ddbDiagramIsValid (line 8) | function ddbDiagramIsValid(obj) {
Condensed preview — 229 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,400K chars).
[
{
"path": ".dockerignore",
"chars": 423,
"preview": "# Ignore node_modules\nnode_modules\n\n# Ignore logs\n*.log\nlogs\n*.log.*\n\n# Ignore environment variables\n.env\n\n# Ignore buil"
},
{
"path": ".eslintrc.cjs",
"chars": 621,
"preview": "module.exports = {\n root: true,\n env: { browser: true, es2020: true },\n extends: [\n \"eslint:recommended\",\n \"plu"
},
{
"path": ".github/FUNDING.yml",
"chars": 14,
"preview": "github: 1ilit\n"
},
{
"path": ".github/ISSUE_TEMPLATE/bug_report.md",
"chars": 724,
"preview": "---\nname: Bug report\nabout: Create a report to help us improve\ntitle: \"[BUG]\"\nlabels: ''\nassignees: ''\n\n---\n\n**Describe "
},
{
"path": ".github/ISSUE_TEMPLATE/feature_request.md",
"chars": 467,
"preview": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: \"[FEATURE]\"\nlabels: ''\nassignees: ''\n\n---\n\n**Is"
},
{
"path": ".github/workflows/build.yml",
"chars": 578,
"preview": "name: Build\n\non:\n push:\n branches: [ \"main\" ]\n pull_request:\n branches: [ \"main\" ]\n types: [ opened, synchron"
},
{
"path": ".github/workflows/docker.yml",
"chars": 796,
"preview": "name: Docker Build and Push\n\non:\n push:\n tags:\n - \"*\"\n\nconcurrency:\n group: \"docker-image\"\n cancel-in-progres"
},
{
"path": ".gitignore",
"chars": 258,
"preview": "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\npnpm-debug.log*\nlerna-debug.log*\n\nnode_modules\ndist\ndis"
},
{
"path": ".prettierrc.json",
"chars": 113,
"preview": "{\n \"singleQuote\": false,\n \"arrowParens\": \"always\",\n \"trailingComma\": \"all\",\n \"tabWidth\": 2,\n \"semi\": true\n}\n"
},
{
"path": "CONTRIBUTING.md",
"chars": 3692,
"preview": "# Contributing to drawDB\n\nThanks for taking the time to contribute!\n\nThe following is a set of guidelines for contributi"
},
{
"path": "Dockerfile",
"chars": 533,
"preview": "# Stage 1: Build the app\nFROM node:20-alpine AS build\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nENV NODE_OP"
},
{
"path": "LICENSE",
"chars": 34523,
"preview": " GNU AFFERO GENERAL PUBLIC LICENSE\n Version 3, 19 November 2007\n\n Copyright (C)"
},
{
"path": "README.md",
"chars": 2287,
"preview": "<div align=\"center\">\n <sup>Special thanks to:</sup>\n <br>\n <a href=\"https://www.warp.dev/drawdb/\" target=\"_blank\">\n "
},
{
"path": "compose.yml",
"chars": 300,
"preview": "services:\n drawdb:\n image: node:20-alpine\n container_name: drawdb\n ports:\n - 5173:5173\n working_dir: /"
},
{
"path": "index.html",
"chars": 2155,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <link rel=\"icon\" href=\"/favicon.ico\" />\n\n "
},
{
"path": "package.json",
"chars": 1740,
"preview": "{\n \"name\": \"drawdb\",\n \"private\": true,\n \"version\": \"0.0.0\",\n \"type\": \"module\",\n \"scripts\": {\n \"dev\": \"vite\",\n "
},
{
"path": "postcss.config.js",
"chars": 69,
"preview": "export default {\n plugins: {\n '@tailwindcss/postcss': {},\n },\n}\n"
},
{
"path": "public/robots.txt",
"chars": 121,
"preview": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nAllow: /\nAllow: /editor\nAllow: /templates\nDisallow: /bug-report"
},
{
"path": "src/App.jsx",
"chars": 1197,
"preview": "import { BrowserRouter, Routes, Route, useLocation } from \"react-router-dom\";\nimport { useLayoutEffect } from \"react\";\ni"
},
{
"path": "src/animations/FadeIn.jsx",
"chars": 704,
"preview": "import { useRef, useEffect } from \"react\";\nimport { motion, useInView, useAnimation } from \"framer-motion\";\n\nexport defa"
},
{
"path": "src/animations/SlideIn.jsx",
"chars": 793,
"preview": "import { useRef, useEffect } from \"react\";\nimport { motion, useInView, useAnimation } from \"framer-motion\";\n\nexport defa"
},
{
"path": "src/api/email.js",
"chars": 217,
"preview": "import axios from \"axios\";\n\nexport async function send(subject, message, attachments) {\n return await axios.post(`${imp"
},
{
"path": "src/api/gists.js",
"chars": 1658,
"preview": "import axios from \"axios\";\n\nexport const SHARE_FILENAME = \"share.json\";\nexport const VERSION_FILENAME = \"versionned.json"
},
{
"path": "src/components/CodeEditor/index.jsx",
"chars": 2132,
"preview": "import { useState } from \"react\";\nimport { Editor } from \"@monaco-editor/react\";\nimport { useDiagram, useSettings } from"
},
{
"path": "src/components/CodeEditor/setUpDBML.js",
"chars": 3336,
"preview": "import { dbToTypes } from \"../../data/datatypes\";\n\nexport function setUpDBML(monaco, database) {\n monaco.languages.regi"
},
{
"path": "src/components/EditorCanvas/Area.jsx",
"chars": 9854,
"preview": "import { useMemo, useRef, useState } from \"react\";\nimport { Button, Popover, Input } from \"@douyinfe/semi-ui\";\nimport Co"
},
{
"path": "src/components/EditorCanvas/Canvas.jsx",
"chars": 24736,
"preview": "import { useRef, useState } from \"react\";\nimport {\n Action,\n Cardinality,\n Constraint,\n darkBgTheme,\n ObjectType,\n "
},
{
"path": "src/components/EditorCanvas/Note.jsx",
"chars": 17694,
"preview": "import { useMemo, useState, useRef, useEffect } from \"react\";\nimport { Action, ObjectType, Tab, State } from \"../../data"
},
{
"path": "src/components/EditorCanvas/Relationship.jsx",
"chars": 6335,
"preview": "import { useMemo, useRef, useState, useEffect } from \"react\";\nimport { Cardinality, ObjectType, Tab } from \"../../data/c"
},
{
"path": "src/components/EditorCanvas/Table.jsx",
"chars": 16385,
"preview": "import { useMemo, useState } from \"react\";\nimport {\n Tab,\n ObjectType,\n tableFieldHeight,\n tableHeaderHeight,\n tabl"
},
{
"path": "src/components/EditorHeader/ControlPanel.jsx",
"chars": 65310,
"preview": "import { useContext, useState } from \"react\";\nimport {\n IconCaretdown,\n IconChevronRight,\n IconChevronLeft,\n IconChe"
},
{
"path": "src/components/EditorHeader/LayoutDropdown.jsx",
"chars": 2306,
"preview": "import {\n IconCaretdown,\n IconCheckboxTick,\n IconRowsStroked,\n} from \"@douyinfe/semi-icons\";\nimport { Dropdown } from"
},
{
"path": "src/components/EditorHeader/Modal/ImportDiagram.jsx",
"chars": 5771,
"preview": "import {\n ddbDiagramIsValid,\n jsonDiagramIsValid,\n} from \"../../../utils/validateSchema\";\nimport { Upload, Banner } fr"
},
{
"path": "src/components/EditorHeader/Modal/ImportSource.jsx",
"chars": 3159,
"preview": "import { Upload, Checkbox, Banner, Tabs, TabPane } from \"@douyinfe/semi-ui\";\nimport { STATUS } from \"../../../data/const"
},
{
"path": "src/components/EditorHeader/Modal/Language.jsx",
"chars": 1001,
"preview": "import { useSettings } from \"../../../hooks\";\nimport { languages } from \"../../../i18n/i18n\";\n\nexport default function L"
},
{
"path": "src/components/EditorHeader/Modal/Modal.jsx",
"chars": 11372,
"preview": "import { Image, Input, Modal as SemiUIModal, Spin } from \"@douyinfe/semi-ui\";\nimport { saveAs } from \"file-saver\";\nimpor"
},
{
"path": "src/components/EditorHeader/Modal/New.jsx",
"chars": 1623,
"preview": "import { db } from \"../../../data/db\";\nimport { useSettings } from \"../../../hooks\";\nimport { useLiveQuery } from \"dexie"
},
{
"path": "src/components/EditorHeader/Modal/Open.jsx",
"chars": 2553,
"preview": "import { db } from \"../../../data/db\";\nimport { Banner } from \"@douyinfe/semi-ui\";\nimport { useLiveQuery } from \"dexie-r"
},
{
"path": "src/components/EditorHeader/Modal/Rename.jsx",
"chars": 421,
"preview": "import { Input } from \"@douyinfe/semi-ui\";\nimport { useTranslation } from \"react-i18next\";\nimport { useLayout } from \".."
},
{
"path": "src/components/EditorHeader/Modal/SetTableWidth.jsx",
"chars": 410,
"preview": "import { InputNumber } from \"@douyinfe/semi-ui\";\nimport { useLayout } from \"../../../hooks\";\n\nexport default function Se"
},
{
"path": "src/components/EditorHeader/Modal/Share.jsx",
"chars": 3583,
"preview": "import { Banner, Button, Input, Spin, Toast } from \"@douyinfe/semi-ui\";\nimport { useCallback, useContext, useEffect, use"
},
{
"path": "src/components/EditorHeader/SideSheet/Migration.jsx",
"chars": 4989,
"preview": "import { useCallback, useState } from \"react\";\nimport { Tabs, TabPane, Modal, Input, Tag, Spin } from \"@douyinfe/semi-ui"
},
{
"path": "src/components/EditorHeader/SideSheet/Sidesheet.jsx",
"chars": 1254,
"preview": "import { SideSheet as SemiUISideSheet } from \"@douyinfe/semi-ui\";\nimport { SIDESHEET } from \"../../../data/constants\";\ni"
},
{
"path": "src/components/EditorHeader/SideSheet/Timeline.jsx",
"chars": 821,
"preview": "import { useTranslation } from \"react-i18next\";\nimport { useUndoRedo } from \"../../../hooks\";\nimport { List } from \"@dou"
},
{
"path": "src/components/EditorHeader/SideSheet/Versions.jsx",
"chars": 10539,
"preview": "import { useCallback, useContext, useEffect, useState, useMemo } from \"react\";\nimport { IdContext } from \"../../Workspac"
},
{
"path": "src/components/EditorSidePanel/AreasTab/AreaDetails.jsx",
"chars": 2813,
"preview": "import { useState, useRef } from \"react\";\nimport { Button, Input } from \"@douyinfe/semi-ui\";\nimport ColorPicker from \".."
},
{
"path": "src/components/EditorSidePanel/AreasTab/AreasTab.jsx",
"chars": 1101,
"preview": "import { Button } from \"@douyinfe/semi-ui\";\nimport { IconPlus } from \"@douyinfe/semi-icons\";\nimport Empty from \"../Empty"
},
{
"path": "src/components/EditorSidePanel/AreasTab/SearchBar.jsx",
"chars": 1189,
"preview": "import { useState } from \"react\";\nimport { useAreas } from \"../../../hooks\";\nimport { AutoComplete } from \"@douyinfe/sem"
},
{
"path": "src/components/EditorSidePanel/ColorPicker.jsx",
"chars": 963,
"preview": "import { ColorPicker as SemiColorPicker } from \"@douyinfe/semi-ui\";\nimport { useState } from \"react\";\n\nexport default fu"
},
{
"path": "src/components/EditorSidePanel/DBMLEditor.jsx",
"chars": 1318,
"preview": "import { useEffect, useState } from \"react\";\nimport { useDiagram, useEnums, useLayout } from \"../../hooks\";\nimport { toD"
},
{
"path": "src/components/EditorSidePanel/Empty.jsx",
"chars": 543,
"preview": "import {\n IllustrationNoContent,\n IllustrationNoContentDark,\n} from \"@douyinfe/semi-illustrations\";\nimport { Empty as "
},
{
"path": "src/components/EditorSidePanel/EnumsTab/EnumDetails.jsx",
"chars": 3672,
"preview": "import { useState } from \"react\";\nimport { Button, Input, TagInput } from \"@douyinfe/semi-ui\";\nimport { IconDeleteStroke"
},
{
"path": "src/components/EditorSidePanel/EnumsTab/EnumsTab.jsx",
"chars": 1400,
"preview": "import { Button, Collapse } from \"@douyinfe/semi-ui\";\nimport { useEnums, useLayout } from \"../../../hooks\";\nimport { Ico"
},
{
"path": "src/components/EditorSidePanel/EnumsTab/SearchBar.jsx",
"chars": 1166,
"preview": "import { useState } from \"react\";\nimport { AutoComplete } from \"@douyinfe/semi-ui\";\nimport { IconSearch } from \"@douyinf"
},
{
"path": "src/components/EditorSidePanel/Issues.jsx",
"chars": 2087,
"preview": "import { useState, useEffect } from \"react\";\nimport { Collapse, Badge } from \"@douyinfe/semi-ui\";\nimport { arrayIsEqual "
},
{
"path": "src/components/EditorSidePanel/NotesTab/NoteInfo.jsx",
"chars": 4883,
"preview": "import { useState, useRef } from \"react\";\nimport { Button, Collapse, TextArea, Input } from \"@douyinfe/semi-ui\";\nimport "
},
{
"path": "src/components/EditorSidePanel/NotesTab/NotesTab.jsx",
"chars": 1648,
"preview": "import { Button, Collapse } from \"@douyinfe/semi-ui\";\nimport { IconPlus } from \"@douyinfe/semi-icons\";\nimport { useLayou"
},
{
"path": "src/components/EditorSidePanel/NotesTab/SearchBar.jsx",
"chars": 1239,
"preview": "import { useState } from \"react\";\nimport { AutoComplete } from \"@douyinfe/semi-ui\";\nimport { IconSearch } from \"@douyinf"
},
{
"path": "src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx",
"chars": 8913,
"preview": "import {\n Row,\n Col,\n Select,\n Button,\n Popover,\n Table,\n Input,\n} from \"@douyinfe/semi-ui\";\nimport {\n IconDelet"
},
{
"path": "src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx",
"chars": 2505,
"preview": "import { Collapse } from \"@douyinfe/semi-ui\";\nimport { useSelect, useDiagram, useSaveState, useLayout } from \"../../../h"
},
{
"path": "src/components/EditorSidePanel/RelationshipsTab/SearchBar.jsx",
"chars": 1491,
"preview": "import { useState } from \"react\";\nimport { useSelect, useDiagram } from \"../../../hooks\";\nimport { AutoComplete } from \""
},
{
"path": "src/components/EditorSidePanel/SidePanel.jsx",
"chars": 4532,
"preview": "import { useMemo } from \"react\";\nimport { Tabs, TabPane, Divider, Tooltip, Button } from \"@douyinfe/semi-ui\";\nimport { I"
},
{
"path": "src/components/EditorSidePanel/TablesTab/FieldDetails.jsx",
"chars": 13308,
"preview": "import { useMemo, useState } from \"react\";\nimport {\n Input,\n TextArea,\n Button,\n TagInput,\n InputNumber,\n Checkbox"
},
{
"path": "src/components/EditorSidePanel/TablesTab/IndexDetails.jsx",
"chars": 6560,
"preview": "import { Action, ObjectType } from \"../../../data/constants\";\nimport { Input, Button, Popover, Checkbox, Select } from \""
},
{
"path": "src/components/EditorSidePanel/TablesTab/SearchBar.jsx",
"chars": 1741,
"preview": "import { useMemo } from \"react\";\nimport { useSelect } from \"../../../hooks\";\nimport { TreeSelect } from \"@douyinfe/semi-"
},
{
"path": "src/components/EditorSidePanel/TablesTab/TableField.jsx",
"chars": 7274,
"preview": "import { useMemo, useState } from \"react\";\nimport { Action, ObjectType } from \"../../../data/constants\";\nimport { Input,"
},
{
"path": "src/components/EditorSidePanel/TablesTab/TableInfo.jsx",
"chars": 10405,
"preview": "import { useState, useRef } from \"react\";\nimport {\n Collapse,\n Input,\n TextArea,\n Button,\n Card,\n Select,\n} from \""
},
{
"path": "src/components/EditorSidePanel/TablesTab/TablesTab.jsx",
"chars": 3920,
"preview": "import { Collapse, Button } from \"@douyinfe/semi-ui\";\nimport { IconEyeOpened, IconEyeClosed } from \"@douyinfe/semi-icons"
},
{
"path": "src/components/EditorSidePanel/TypesTab/SearchBar.jsx",
"chars": 1426,
"preview": "import { useState } from \"react\";\nimport { AutoComplete } from \"@douyinfe/semi-ui\";\nimport { IconSearch } from \"@douyinf"
},
{
"path": "src/components/EditorSidePanel/TypesTab/TypeField.jsx",
"chars": 11411,
"preview": "import { useState } from \"react\";\nimport { Action, ObjectType } from \"../../../data/constants\";\nimport {\n Row,\n Col,\n "
},
{
"path": "src/components/EditorSidePanel/TypesTab/TypeInfo.jsx",
"chars": 6227,
"preview": "import { useState } from \"react\";\nimport { Action, ObjectType } from \"../../../data/constants\";\nimport {\n Collapse,\n R"
},
{
"path": "src/components/EditorSidePanel/TypesTab/TypesTab.jsx",
"chars": 2254,
"preview": "import { Collapse, Button, Popover } from \"@douyinfe/semi-ui\";\nimport { IconPlus, IconInfoCircle } from \"@douyinfe/semi-"
},
{
"path": "src/components/FloatingControls.jsx",
"chars": 1676,
"preview": "import { Divider, Tooltip } from \"@douyinfe/semi-ui\";\nimport { useTransform, useLayout } from \"../hooks\";\nimport { exitF"
},
{
"path": "src/components/LexicalEditor/AutoLinkPlugin.jsx",
"chars": 1066,
"preview": "/**\n * See https://codesandbox.io/p/sandbox/vigilant-kate-5tncvy?file=%2Fsrc%2Fplugins%2FAutoLinkPlugin.js\n*/\n\nimport { "
},
{
"path": "src/components/LexicalEditor/CodeHighlightPlugin.jsx",
"chars": 488,
"preview": "/**\n * See https://codesandbox.io/p/sandbox/vigilant-kate-5tncvy?file=%2Fsrc%2Fplugins%2FCodeHighlightPlugin.js\n */\n\nimp"
},
{
"path": "src/components/LexicalEditor/ListMaxIndentLevelPlugin.jsx",
"chars": 1935,
"preview": "/**\n * See https://codesandbox.io/p/sandbox/vigilant-kate-5tncvy?file=%2Fsrc%2Fplugins%2FListMaxIndentLevelPlugin.js\n */"
},
{
"path": "src/components/LexicalEditor/RichEditor.jsx",
"chars": 1778,
"preview": "import { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { ContentEditable } from \"@lexical/react/L"
},
{
"path": "src/components/LexicalEditor/ToolbarPlugin.jsx",
"chars": 18078,
"preview": "/**\n * See https://codesandbox.io/p/sandbox/vigilant-kate-5tncvy?file=%2Fsrc%2Fplugins%2FToolbarPlugin.js\n */\n\nimport { "
},
{
"path": "src/components/LexicalEditor/styles/index.css",
"chars": 6852,
"preview": "/* See https://codesandbox.io/p/sandbox/vigilant-kate-5tncvy?file=%2Fsrc%2Fstyles.css */\n\n.ltr {\n text-align: left;\n}\n\n"
},
{
"path": "src/components/Navbar.jsx",
"chars": 4103,
"preview": "import { useState } from \"react\";\nimport { Link } from \"react-router-dom\";\nimport logo from \"../assets/logo_light_160.pn"
},
{
"path": "src/components/SimpleCanvas.jsx",
"chars": 6820,
"preview": "import { useEffect, useState, useRef } from \"react\";\nimport {\n Cardinality,\n tableColorStripHeight,\n tableFieldHeight"
},
{
"path": "src/components/SortableList/DragHandle.jsx",
"chars": 384,
"preview": "import { IconHandle } from \"@douyinfe/semi-icons\";\nimport { useSortable } from \"@dnd-kit/sortable\";\n\nexport function Dra"
},
{
"path": "src/components/SortableList/SortableItem.jsx",
"chars": 422,
"preview": "import { useSortable } from \"@dnd-kit/sortable\";\nimport { CSS } from \"@dnd-kit/utilities\";\n\nexport function SortableItem"
},
{
"path": "src/components/SortableList/SortableList.jsx",
"chars": 1265,
"preview": "import {\n closestCenter,\n DndContext,\n PointerSensor,\n useSensor,\n useSensors,\n} from \"@dnd-kit/core\";\nimport {\n S"
},
{
"path": "src/components/Thumbnail.jsx",
"chars": 5391,
"preview": "import {\n tableFieldHeight,\n tableHeaderHeight,\n noteWidth,\n noteRadius,\n noteFold,\n gridSize,\n gridCircleRadius,"
},
{
"path": "src/components/Workspace.jsx",
"chars": 17202,
"preview": "import { useState, useEffect, useCallback, createContext } from \"react\";\nimport ControlPanel from \"./EditorHeader/Contro"
},
{
"path": "src/context/AreasContext.jsx",
"chars": 2637,
"preview": "import { Toast } from \"@douyinfe/semi-ui\";\nimport { createContext, useState } from \"react\";\nimport { useTranslation } fr"
},
{
"path": "src/context/CanvasContext.jsx",
"chars": 3837,
"preview": "import { useTransform } from \"../hooks\";\nimport { createContext, useCallback, useMemo, useRef, useState } from \"react\";\n"
},
{
"path": "src/context/DiagramContext.jsx",
"chars": 6963,
"preview": "import { createContext, useState } from \"react\";\nimport { Action, DB, ObjectType, defaultBlue } from \"../data/constants\""
},
{
"path": "src/context/EnumsContext.jsx",
"chars": 2227,
"preview": "import { createContext, useState } from \"react\";\nimport { Action, ObjectType } from \"../data/constants\";\nimport { Toast "
},
{
"path": "src/context/LayoutContext.jsx",
"chars": 453,
"preview": "import { createContext, useState } from \"react\";\n\nexport const LayoutContext = createContext(null);\n\nexport default func"
},
{
"path": "src/context/NotesContext.jsx",
"chars": 2696,
"preview": "import { createContext, useState, useCallback } from \"react\";\nimport {\n Action,\n ObjectType,\n defaultNoteTheme,\n not"
},
{
"path": "src/context/SaveStateContext.jsx",
"chars": 413,
"preview": "import { createContext, useState } from \"react\";\nimport { State } from \"../data/constants\";\n\nexport const SaveStateConte"
},
{
"path": "src/context/SelectContext.jsx",
"chars": 884,
"preview": "import { createContext, useState } from \"react\";\nimport { ObjectType, Tab } from \"../data/constants\";\n\nexport const Sele"
},
{
"path": "src/context/SettingsContext.jsx",
"chars": 1129,
"preview": "import { createContext, useEffect, useState } from \"react\";\nimport { tableWidth } from \"../data/constants\";\n\nconst defau"
},
{
"path": "src/context/TransformContext.jsx",
"chars": 1280,
"preview": "import { createContext, useCallback, useState } from \"react\";\n\nexport const TransformContext = createContext(null);\n\nexp"
},
{
"path": "src/context/TypesContext.jsx",
"chars": 2618,
"preview": "import { createContext, useState } from \"react\";\nimport { Action, ObjectType } from \"../data/constants\";\nimport { useUnd"
},
{
"path": "src/context/UndoRedoContext.jsx",
"chars": 523,
"preview": "import { createContext, useState } from \"react\";\n\nexport const UndoRedoContext = createContext({\n undoStack: [],\n setU"
},
{
"path": "src/data/constants.js",
"chars": 2292,
"preview": "export const defaultBlue = \"#175e7a\";\nexport const defaultNoteTheme = \"#fcf7ac\";\nexport const noteWidth = 180;\nexport co"
},
{
"path": "src/data/databases.js",
"chars": 1597,
"preview": "import mysqlImage from \"../assets/mysql-icon.png\";\nimport postgresImage from \"../assets/postgres-icon.png\";\nimport sqlit"
},
{
"path": "src/data/datatypes.js",
"chars": 51792,
"preview": "import { strHasQuotes } from \"../utils/utils\";\nimport {\n binaryColor,\n booleanColor,\n dateColor,\n decimalColor,\n do"
},
{
"path": "src/data/db.js",
"chars": 719,
"preview": "import Dexie from \"dexie\";\nimport { templateSeeds } from \"./seeds\";\n\nexport const db = new Dexie(\"drawDB\");\n\ndb.version("
},
{
"path": "src/data/editorConfig.js",
"chars": 2609,
"preview": "import { HeadingNode, QuoteNode } from \"@lexical/rich-text\";\nimport { TableCellNode, TableNode, TableRowNode } from \"@le"
},
{
"path": "src/data/heroDiagram.js",
"chars": 2724,
"preview": "import {\n tableColorStripHeight,\n tableFieldHeight,\n tableHeaderHeight,\n} from \"./constants\";\n\nconst xOffset = window"
},
{
"path": "src/data/schemas.js",
"chars": 4939,
"preview": "export const tableSchema = {\n type: \"object\",\n properties: {\n id: { type: [\"integer\", \"string\"] },\n name: { type"
},
{
"path": "src/data/seeds.js",
"chars": 445,
"preview": "import { template1 } from \"../templates/template1\";\nimport { template2 } from \"../templates/template2\";\nimport { templat"
},
{
"path": "src/data/socials.js",
"chars": 201,
"preview": "export const socials = {\n docs: \"https://drawdb-io.github.io/docs\",\n discord: \"https://discord.gg/BrjZgNrmR6\",\n twitt"
},
{
"path": "src/data/surveyQuestions.js",
"chars": 498,
"preview": "export const questions = {\n satisfaction: \"How satisfied are you with drawDB?\",\n ease: \"How easy was it to get started"
},
{
"path": "src/hooks/index.js",
"chars": 758,
"preview": "export { default as useAreas } from \"./useAreas\";\nexport { default as useCanvas } from \"./useCanvas\";\nexport { default a"
},
{
"path": "src/hooks/useAreas.js",
"chars": 167,
"preview": "import { useContext } from \"react\";\nimport { AreasContext } from \"../context/AreasContext\";\n\nexport default function use"
},
{
"path": "src/hooks/useCanvas.js",
"chars": 171,
"preview": "import { useContext } from \"react\";\nimport { CanvasContext } from \"../context/CanvasContext\";\n\nexport default function u"
},
{
"path": "src/hooks/useDiagram.js",
"chars": 175,
"preview": "import { useContext } from \"react\";\nimport { DiagramContext } from \"../context/DiagramContext\";\n\nexport default function"
},
{
"path": "src/hooks/useEnums.js",
"chars": 167,
"preview": "import { useContext } from \"react\";\nimport { EnumsContext } from \"../context/EnumsContext\";\n\nexport default function use"
},
{
"path": "src/hooks/useFullscreen.js",
"chars": 452,
"preview": "import { useState } from \"react\";\nimport { useEventListener } from \"usehooks-ts\";\n\nexport default function useFullscreen"
},
{
"path": "src/hooks/useLayout.js",
"chars": 171,
"preview": "import { useContext } from \"react\";\nimport { LayoutContext } from \"../context/LayoutContext\";\n\nexport default function u"
},
{
"path": "src/hooks/useNotes.js",
"chars": 167,
"preview": "import { useContext } from \"react\";\nimport { NotesContext } from \"../context/NotesContext\";\n\nexport default function use"
},
{
"path": "src/hooks/useSaveState.js",
"chars": 183,
"preview": "import { useContext } from \"react\";\nimport { SaveStateContext } from \"../context/SaveStateContext\";\n\nexport default func"
},
{
"path": "src/hooks/useSelect.js",
"chars": 171,
"preview": "import { useContext } from \"react\";\nimport { SelectContext } from \"../context/SelectContext\";\n\nexport default function u"
},
{
"path": "src/hooks/useSettings.js",
"chars": 179,
"preview": "import { useContext } from \"react\";\nimport { SettingsContext } from \"../context/SettingsContext\";\n\nexport default functi"
},
{
"path": "src/hooks/useThemedPage.js",
"chars": 357,
"preview": "import { useLayoutEffect } from \"react\";\nimport useSettings from \"./useSettings\";\n\n/**\n * Adds the `theme-mode` attribut"
},
{
"path": "src/hooks/useTransform.js",
"chars": 183,
"preview": "import { useContext } from \"react\";\nimport { TransformContext } from \"../context/TransformContext\";\n\nexport default func"
},
{
"path": "src/hooks/useTypes.js",
"chars": 167,
"preview": "import { useContext } from \"react\";\nimport { TypesContext } from \"../context/TypesContext\";\n\nexport default function use"
},
{
"path": "src/hooks/useUndoRedo.js",
"chars": 179,
"preview": "import { useContext } from \"react\";\nimport { UndoRedoContext } from \"../context/UndoRedoContext\";\n\nexport default functi"
},
{
"path": "src/i18n/i18n.js",
"chars": 3813,
"preview": "import i18n from \"i18next\";\nimport { initReactI18next } from \"react-i18next\";\nimport LanguageDetector from \"i18next-brow"
},
{
"path": "src/i18n/locales/ar.js",
"chars": 8927,
"preview": "const arabic = {\n name: \"Arabic\",\n native_name: \"العربية\",\n code: \"ar\",\n};\n\nconst ar = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/as.js",
"chars": 12220,
"preview": "const assamese = {\n name: \"Assamese\",\n native_name: \"অসমীয়া\",\n code: \"as\",\n };\n \n\n\nconst as = {\n translat"
},
{
"path": "src/i18n/locales/bg.js",
"chars": 12831,
"preview": "const bulgarian = {\n name: \"Bulgarian\",\n native_name: \"Български\",\n code: \"bg\",\n};\n\nconst bg = {\n translatio"
},
{
"path": "src/i18n/locales/bn.js",
"chars": 11778,
"preview": "const bengali = {\n name: \"Bengali\",\n native_name: \"বাংলা\",\n code: \"bn\",\n};\n\nconst bn = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/cz.js",
"chars": 11157,
"preview": "const czech = {\n name: \"Czech\",\n native_name: \"Česko\",\n code: \"cz\",\n};\n\nconst cz = {\n translation: {\n report_bug:"
},
{
"path": "src/i18n/locales/da.js",
"chars": 11313,
"preview": "const danish = {\n name: \"Danish\",\n native_name: \"Dansk\",\n code: \"da\",\n};\n\nconst da = {\n translation: {\n report_bu"
},
{
"path": "src/i18n/locales/de.js",
"chars": 12332,
"preview": "const german = {\n name: \"German\",\n native_name: \"Deutsch\",\n code: \"de\",\n};\n\nconst de = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/el.js",
"chars": 11994,
"preview": "const greek = {\n name: \"Greek\",\n native_name: \"Ελληνικά\",\n code: \"el\",\n};\n\n\nconst el = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/en.js",
"chars": 10945,
"preview": "const english = {\n name: \"English\",\n native_name: \"English\",\n code: \"en\",\n};\n\nconst en = {\n translation: {\n repor"
},
{
"path": "src/i18n/locales/es.js",
"chars": 11687,
"preview": "const spanish = {\n name: \"Spanish\",\n native_name: \"Español\",\n code: \"es\",\n};\n\nconst es = {\n translation: {\n repor"
},
{
"path": "src/i18n/locales/fa.js",
"chars": 8189,
"preview": "const persian = {\n name: \"Persian\",\n native_name: \"فارسی\",\n code: \"fa\",\n};\n\nconst fa = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/fi.js",
"chars": 11555,
"preview": "const finnish = {\n name: \"Finnish\",\n native_name: \"Suomi\",\n code: \"fi\",\n};\n\nconst fi = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/fr.js",
"chars": 9306,
"preview": "const french = {\r\n name: \"French\",\r\n native_name: \"Français\",\r\n code: \"fr\",\r\n};\r\n\r\nconst fr = {\r\n translation: {\r\n "
},
{
"path": "src/i18n/locales/gu.js",
"chars": 11485,
"preview": "const gujarati = {\n name: \"Gujarati\",\n native_name: \"ગુજરાતી\",\n code: \"gu\",\n};\n\nconst gu = {\n translation: {\n rep"
},
{
"path": "src/i18n/locales/he.js",
"chars": 8394,
"preview": "const hebrew = {\n name: \"Hebrew\",\n native_name: \"עברית\",\n code: \"he\",\n};\n\nconst he = {\n translation: {\n report_bu"
},
{
"path": "src/i18n/locales/hi.js",
"chars": 8934,
"preview": "const hindi = {\n name: \"Hindi\",\n native_name: \"हिंदी\",\n code: \"hi\",\n};\n\nconst hi = {\n translation: {\n report_bug:"
},
{
"path": "src/i18n/locales/hu.js",
"chars": 11956,
"preview": "const hungarian = {\n name: \"Hungarian\",\n native_name: \"Magyar\",\n code: \"hu\",\n};\n\nconst hu = {\n translation: {\n re"
},
{
"path": "src/i18n/locales/hy.js",
"chars": 9745,
"preview": "const armenian = {\n name: \"Armenian\",\n native_name: \"Հայերեն\",\n code: \"hy\",\n};\n\nconst hy = {\n translation: {\n rep"
},
{
"path": "src/i18n/locales/id.js",
"chars": 10050,
"preview": "const indonesian = {\n name: \"Indonesian\",\n native_name: \"Bahasa Indonesia\",\n code: \"id\",\n};\n\nconst id = {\n translati"
},
{
"path": "src/i18n/locales/it.js",
"chars": 10562,
"preview": "const italian = {\n name: \"Italian\",\n native_name: \"Italiano\",\n code: \"it\",\n};\n\nconst it = {\n translation: {\n repo"
},
{
"path": "src/i18n/locales/jp.js",
"chars": 8007,
"preview": "const japanese = {\n name: \"Japanese\",\n native_name: \"Japanese\",\n code: \"jp\",\n};\n\nconst jp = {\n translation: {\n re"
},
{
"path": "src/i18n/locales/ka.js",
"chars": 12153,
"preview": "const kannada = {\n name: \"Kannada\",\n native_name: \"ಕನ್ನಡ\",\n code: \"ka\",\n};\n\nconst ka = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/ko.js",
"chars": 7582,
"preview": "const korean = {\n name: \"Korean\",\n native_name: \"한국어\",\n code: \"ko\",\n};\n\nconst ko = {\n translation: {\n report_bug:"
},
{
"path": "src/i18n/locales/ml.js",
"chars": 13396,
"preview": "const malayalam = {\n name: \"Malayalam\",\n native_name: \"മലയാളം\",\n code: \"ml\",\n};\n\nconst ml = {\n translation: "
},
{
"path": "src/i18n/locales/mn.js",
"chars": 11388,
"preview": "const mongolian = {\n name: \"Mongolian\",\n native_name: \"Монгол\",\n code: \"mn\",\n};\n\nconst mn = {\n translation: {\n re"
},
{
"path": "src/i18n/locales/mr.js",
"chars": 11482,
"preview": "const marathi = {\n name: \"Marathi\",\n native_name: \"मराठी\",\n code: \"mr\",\n};\n\nconst mr = {\n translation: {\n report_"
},
{
"path": "src/i18n/locales/ms.js",
"chars": 11274,
"preview": "const malay = {\n name: \"Malay\",\n native_name: \"Bahasa Melayu\",\n code: \"ms\",\n};\n\nconst ms = {\n translation: {\n rep"
},
{
"path": "src/i18n/locales/ne.js",
"chars": 9160,
"preview": "const nepali = {\n name: \"Nepali\",\n native_name: \"नेपाली\",\n code: \"ne\",\n};\n\nconst ne = {\n translation: {\n report_b"
},
{
"path": "src/i18n/locales/nl.js",
"chars": 11748,
"preview": "const dutch = {\n name: \"Dutch\",\n native_name: \"Nederlands\",\n code: \"nl\",\n};\n\nconst nl = {\n translation: {\n report"
},
{
"path": "src/i18n/locales/no.js",
"chars": 9779,
"preview": "const norwegian = {\n name: \"Norwegian\",\n native_name: \"Norsk\",\n code: \"no\",\n};\n\nconst no = {\n translation: {\n rep"
},
{
"path": "src/i18n/locales/od.js",
"chars": 8900,
"preview": "const odia = {\n name: \"Odia\",\n native_name: \"ଓଡିଆ\",\n code: \"od\",\n};\n\nconst od = {\n translation: {\n report_bug: \"ବ"
},
{
"path": "src/i18n/locales/pa-pk.js",
"chars": 11078,
"preview": "const punjabipk = {\n name: \"Punjabi\",\n native_name: \"پنجابی\",\n code: \"pa-PK\",\n};\n\nconst pa_pk = {\n translation: {\n "
},
{
"path": "src/i18n/locales/pa.js",
"chars": 11666,
"preview": "const punjabi = {\r\n name: \"Punjabi\",\r\n native_name: \"ਪੰਜਾਬੀ\",\r\n code: \"pa\",\r\n};\r\n\r\nconst pa = {\r\n translation: {\r\n "
},
{
"path": "src/i18n/locales/pl.js",
"chars": 9963,
"preview": "const polish = {\n name: \"Polish\",\n native_name: \"Polski\",\n code: \"pl\",\n};\n\nconst pl = {\n translation: {\n report_b"
},
{
"path": "src/i18n/locales/pt-br.js",
"chars": 10531,
"preview": "const portuguese = {\n name: \"Portuguese\",\n native_name: \"Português\",\n code: \"pt-BR\",\n};\n\nconst pt = {\n translation: "
},
{
"path": "src/i18n/locales/ro.js",
"chars": 10238,
"preview": "const romanian = {\n name: \"Romanian\",\n native_name: \"Română\",\n code: \"ro\",\n};\n\nconst ro = {\n translation: {\n repo"
},
{
"path": "src/i18n/locales/ru.js",
"chars": 10026,
"preview": "const russian = {\n name: \"Russian\",\n native_name: \"Русский\",\n code: \"ru\",\n};\n\nconst ru = {\n translation: {\n repor"
},
{
"path": "src/i18n/locales/sd.js",
"chars": 5495,
"preview": "const sindhi = {\n name: \"Sindhi\",\n native_name: \"سنڌي\",\n code: \"sd\",\n};\n\nconst sd = {\n translation: {\n report_bug"
},
{
"path": "src/i18n/locales/sv-se.js",
"chars": 9857,
"preview": "const swedish = {\n name: \"Swedish\",\n native_name: \"Svenska\",\n code: \"sv\",\n};\n\nconst sv = {\n translation: {\n repor"
},
{
"path": "src/i18n/locales/sw.js",
"chars": 11619,
"preview": "const swahili = {\n name: \"Swahili\",\n native_name: \"Kiswahili\",\n code: \"sw\",\n};\n\nconst sw = {\n translation: {\n rep"
},
{
"path": "src/i18n/locales/te.js",
"chars": 8921,
"preview": "const telugu = {\n name: \"Telugu\",\n native_name: \"తెలుగు\",\n code: \"te\",\n};\n\nconst te = {\n translation: {\n report_b"
},
{
"path": "src/i18n/locales/th.js",
"chars": 8068,
"preview": "const thai = {\n name: \"Thai\",\n native_name: \"ไทย\",\n code: \"th\",\n};\n\nconst th = {\n translation: {\n report_bug: \"รา"
},
{
"path": "src/i18n/locales/tl.js",
"chars": 5344,
"preview": "const filipino = {\n name: \"Filipino\",\n native_name: \"Filipino\",\n code: \"tl\",\n};\n\nconst tl = {\n translation: {\n re"
},
{
"path": "src/i18n/locales/tm.js",
"chars": 11883,
"preview": "const tamil = {\n name: \"Tamil\",\n native_name: \"தமிழ்\",\n code: \"tm\",\n};\n\nconst tm = {\n translation: {\n report_bug:"
},
{
"path": "src/i18n/locales/tr.js",
"chars": 9490,
"preview": "const turkish = {\n name: \"Turkish\",\n native_name: \"Türkçe\",\n code: \"tr\",\n};\n\nconst tr = {\n translation: {\n report"
},
{
"path": "src/i18n/locales/ug.js",
"chars": 8558,
"preview": "const uyghur = {\n name: \"Uyghur\",\n native_name: \"ئۇيغۇرچە\",\n code: \"ug\",\n};\n\nconst ug = {\n translation: {\n report"
},
{
"path": "src/i18n/locales/uk.js",
"chars": 9212,
"preview": "const ukrainian = {\n name: \"Ukrainian\",\n native_name: \"Українська\",\n code: \"uk\",\n};\n\nconst uk = {\n translation: {\n "
},
{
"path": "src/i18n/locales/ur.js",
"chars": 11484,
"preview": "const urdu = {\n name: \"Urdu\",\n native_name: \"اردو\",\n code: \"ur\",\n};\n\nconst ur = {\n translation: {\n report_bug: \"ب"
},
{
"path": "src/i18n/locales/vi.js",
"chars": 11214,
"preview": "const vietnamese = {\n name: \"Vietnamese\",\n native_name: \"Tiếng Việt\",\n code: \"vi\",\n};\n\nconst vi = {\n translation: {\n"
},
{
"path": "src/i18n/locales/zh-tw.js",
"chars": 8025,
"preview": "const traditionalChinese = {\n name: \"Traditional Chinese\",\n native_name: \"繁體中文\",\n code: \"zh-TW\",\n};\n\nconst zh_tw = {\n"
},
{
"path": "src/i18n/locales/zh.js",
"chars": 7857,
"preview": "const chinese = {\n name: \"Simplified Chinese\",\n native_name: \"简体中文\",\n code: \"zh\",\n};\n\nconst zh = {\n translation: {\n "
},
{
"path": "src/i18n/utils/rtl.js",
"chars": 121,
"preview": "const rtlLanguages = [\"ar\", \"he\", \"fa\", \"ps\", \"ur\"];\nexport const isRtl = (language) => rtlLanguages.includes(language);"
},
{
"path": "src/icons/IconAddArea.jsx",
"chars": 320,
"preview": "export default function IconAddArea() {\n return (\n <svg height=\"26\" width=\"26\">\n <path\n fill=\"none\"\n "
},
{
"path": "src/icons/IconAddNote.jsx",
"chars": 347,
"preview": "export default function IconAddNote() {\n return (\n <svg height=\"26\" width=\"26\">\n <path\n fill=\"none\"\n "
},
{
"path": "src/icons/IconAddTable.jsx",
"chars": 332,
"preview": "export default function IconAddTable() {\n return (\n <svg height=\"26\" width=\"26\">\n <path\n fill=\"none\"\n "
},
{
"path": "src/icons/index.js",
"chars": 170,
"preview": "export { default as IconAddTable } from \"./IconAddTable\";\nexport { default as IconAddArea } from \"./IconAddArea\";\nexport"
},
{
"path": "src/index.css",
"chars": 4418,
"preview": "@import \"tailwindcss\";\n\n@config '../tailwind.config.js';\n\n/*\n The default border color has changed to `currentColor` in"
},
{
"path": "src/main.jsx",
"chars": 457,
"preview": "import ReactDOM from \"react-dom/client\";\nimport { LocaleProvider } from \"@douyinfe/semi-ui\";\nimport { Analytics } from \""
},
{
"path": "src/pages/BugReport.jsx",
"chars": 8087,
"preview": "import { useEffect, useState, useCallback, useRef } from \"react\";\nimport logo_light from \"../assets/logo_light_160.png\";"
},
{
"path": "src/pages/Editor.jsx",
"chars": 1590,
"preview": "import LayoutContextProvider from \"../context/LayoutContext\";\nimport TransformContextProvider from \"../context/Transform"
},
{
"path": "src/pages/LandingPage.jsx",
"chars": 14823,
"preview": "import { useState, useEffect } from \"react\";\nimport { Link } from \"react-router-dom\";\nimport SimpleCanvas from \"../compo"
},
{
"path": "src/pages/NotFound.jsx",
"chars": 943,
"preview": "import { socials } from \"../data/socials\";\n\nexport default function NotFound() {\n return (\n <div className=\"p-3 spac"
},
{
"path": "src/pages/Templates.jsx",
"chars": 7590,
"preview": "import { useEffect } from \"react\";\nimport { Link } from \"react-router-dom\";\nimport { Tabs, TabPane, Banner, Steps } from"
},
{
"path": "src/templates/template1.js",
"chars": 7581,
"preview": "import { Cardinality } from \"../data/constants\";\n\nexport const template1 = {\n tables: [\n {\n id: 0,\n name: "
},
{
"path": "src/templates/template2.js",
"chars": 7513,
"preview": "import { Cardinality } from \"../data/constants\";\n\nexport const template2 = {\n tables: [\n {\n id: 0,\n name: "
},
{
"path": "src/templates/template3.js",
"chars": 9120,
"preview": "import { Cardinality } from \"../data/constants\";\n\nexport const template3 = {\n tables: [\n {\n id: 0,\n name: "
},
{
"path": "src/templates/template4.js",
"chars": 7716,
"preview": "import { Cardinality } from \"../data/constants\";\n\nexport const template4 = {\n tables: [\n {\n id: 0,\n name: "
},
{
"path": "src/templates/template5.js",
"chars": 13634,
"preview": "import { Cardinality } from \"../data/constants\";\n\nexport const template5 = {\n tables: [\n {\n id: 0,\n name: "
},
{
"path": "src/templates/template6.js",
"chars": 9780,
"preview": "import { Cardinality } from \"../data/constants\";\n\nexport const template6 = {\n tables: [\n {\n id: 0,\n name: "
},
{
"path": "src/utils/arrangeTables.js",
"chars": 733,
"preview": "import {\n tableColorStripHeight,\n tableFieldHeight,\n tableHeaderHeight,\n} from \"../data/constants\";\n\nexport function "
},
{
"path": "src/utils/cache.js",
"chars": 451,
"preview": "export const STORAGE_KEY = \"versions_cache\";\n\nexport function loadCache() {\n try {\n const saved = localStorage.getIt"
},
{
"path": "src/utils/calcPath.js",
"chars": 4101,
"preview": "import { tableFieldHeight, tableHeaderHeight } from \"../data/constants\";\nimport { getCommentHeight } from \"./utils\";\n\n/*"
},
{
"path": "src/utils/diff.js",
"chars": 2481,
"preview": "const isArrayOfObjects = (arr) =>\n Array.isArray(arr) &&\n arr.every((item) => typeof item === \"object\" && item !== nul"
},
{
"path": "src/utils/exportAs/dbml.js",
"chars": 5435,
"preview": "import { Cardinality } from \"../../data/constants\";\nimport { dbToTypes } from \"../../data/datatypes\";\nimport i18n from \""
},
{
"path": "src/utils/exportAs/documentation.js",
"chars": 4202,
"preview": "import { dbToTypes } from \"../../data/datatypes\";\nimport { jsonToMermaid } from \"./mermaid\";\nimport { databases } from \""
},
{
"path": "src/utils/exportAs/mermaid.js",
"chars": 1735,
"preview": "import { Cardinality } from \"../../data/constants\";\nimport { dbToTypes } from \"../../data/datatypes\";\nimport i18n from \""
}
]
// ... and 29 more files (download for full content)
About this extraction
This page contains the full source code of the drawdb-io/drawdb GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 229 files (1.2 MB), approximately 359.7k tokens, and a symbol index with 219 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.