├── test.json ├── CHANGELOG.md ├── .erb ├── mocks │ └── fileMock.js ├── img │ ├── erb-logo.png │ └── erb-banner.svg ├── configs │ ├── .eslintrc │ ├── webpack.config.eslint.ts │ ├── postcss.config.js │ ├── webpack.paths.ts │ ├── webpack.config.base.ts │ ├── webpack.config.renderer.dev.dll.ts │ ├── webpack.config.preload.dev.ts │ ├── webpack.config.main.prod.ts │ ├── webpack.config.renderer.prod.ts │ └── webpack.config.renderer.dev.ts └── scripts │ ├── .eslintrc │ ├── delete-source-maps.js │ ├── link-modules.ts │ ├── check-node-env.js │ ├── clean.js │ ├── check-port-in-use.js │ ├── electron-rebuild.js │ ├── check-build-exists.ts │ ├── notarize.js │ └── check-native-dep.js ├── src ├── renderer │ ├── constants │ │ ├── index.ts │ │ └── constants.ts │ ├── state │ │ ├── index.ts │ │ ├── substates │ │ │ ├── working-directory-state.ts │ │ │ ├── show-hidden-state.ts │ │ │ ├── level-filter-state.ts │ │ │ ├── working-directory-state.test.ts │ │ │ ├── status-state.ts │ │ │ ├── workbench-view-state.ts │ │ │ ├── error-state.ts │ │ │ ├── cdk-app-state.ts │ │ │ ├── widget-view-state.ts │ │ │ ├── error-state.test.ts │ │ │ ├── status-state.test.ts │ │ │ └── test_states │ │ │ │ ├── tree.json │ │ │ │ └── workbench.json │ │ ├── states.ts │ │ └── zustand-state.ts │ ├── components │ │ ├── styles │ │ │ ├── footer.module.css │ │ │ └── commands.module.css │ │ ├── assets │ │ │ ├── hide.png │ │ │ ├── show-svgrepo-com.svg │ │ │ ├── hide-svgrepo-com.svg │ │ │ └── search.svg │ │ ├── background.png │ │ ├── Contexts.ts │ │ ├── index.ts │ │ ├── WorkbenchBackground.tsx │ │ ├── OpenPrompt.tsx │ │ ├── WidgetBackground.tsx │ │ ├── utils.ts │ │ ├── LevelFilter.tsx │ │ ├── Footer.tsx │ │ ├── WorkbenchSurface.tsx │ │ └── ConstructWidget.tsx │ ├── index.ejs │ ├── preload.d.ts │ ├── index.tsx │ ├── App.css │ ├── colors.ts │ └── App.tsx └── main │ ├── listeners │ ├── fs-utils.ts │ ├── workbench-state-update-listener.ts │ ├── save-export-listener.ts │ ├── load-recent-listener.ts │ └── open-workbench-listener.ts │ ├── menus │ ├── undo-redo.ts │ └── file.ts │ ├── util.ts │ ├── preload.ts │ ├── providers │ └── open-workbench.ts │ ├── main.ts │ └── menu.ts ├── screenshot.png ├── assets ├── icon.icns ├── icon.ico ├── icon.png ├── icons │ ├── 128x128.png │ ├── 16x16.png │ ├── 24x24.png │ ├── 256x256.png │ ├── 32x32.png │ ├── 48x48.png │ ├── 512x512.png │ ├── 64x64.png │ ├── 96x96.png │ └── 1024x1024.png ├── entitlements.mac.plist ├── assets.d.ts └── icon.svg ├── .github ├── FUNDING.yml ├── config.yml ├── ISSUE_TEMPLATE │ ├── 3-Feature_request.md │ ├── 2-Question.md │ └── 1-Bug_report.md ├── stale.yml └── workflows │ ├── test.yml │ └── publish.yml ├── wip-pics └── 2022-05-02_20-11.png ├── .vscode ├── extensions.json ├── settings.json ├── tasks.json └── launch.json ├── release └── app │ ├── yarn.lock │ ├── package-lock.json │ └── package.json ├── .editorconfig ├── .gitattributes ├── tailwind.config.js ├── .gitignore ├── .eslintignore ├── tsconfig.json ├── LICENSE ├── .eslintrc.js ├── CONTRIBUTING.md ├── README.md ├── CODE_OF_CONDUCT.md └── package.json /test.json: -------------------------------------------------------------------------------- 1 | [{}] -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.0.1 2 | 3 | Initial release 4 | -------------------------------------------------------------------------------- /.erb/mocks/fileMock.js: -------------------------------------------------------------------------------- 1 | export default 'test-file-stub'; 2 | -------------------------------------------------------------------------------- /src/renderer/constants/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constants'; 2 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/screenshot.png -------------------------------------------------------------------------------- /assets/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icon.icns -------------------------------------------------------------------------------- /assets/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icon.ico -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icon.png -------------------------------------------------------------------------------- /src/renderer/constants/constants.ts: -------------------------------------------------------------------------------- 1 | export const DRAG_DATA_KEY = '__drag_data_payload__'; 2 | -------------------------------------------------------------------------------- /.erb/img/erb-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/.erb/img/erb-logo.png -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [the-ocf] 4 | -------------------------------------------------------------------------------- /src/renderer/state/index.ts: -------------------------------------------------------------------------------- 1 | export * from './states'; 2 | export * from './zustand-state'; 3 | -------------------------------------------------------------------------------- /assets/icons/128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/128x128.png -------------------------------------------------------------------------------- /assets/icons/16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/16x16.png -------------------------------------------------------------------------------- /assets/icons/24x24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/24x24.png -------------------------------------------------------------------------------- /assets/icons/256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/256x256.png -------------------------------------------------------------------------------- /assets/icons/32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/32x32.png -------------------------------------------------------------------------------- /assets/icons/48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/48x48.png -------------------------------------------------------------------------------- /assets/icons/512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/512x512.png -------------------------------------------------------------------------------- /assets/icons/64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/64x64.png -------------------------------------------------------------------------------- /assets/icons/96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/96x96.png -------------------------------------------------------------------------------- /assets/icons/1024x1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/assets/icons/1024x1024.png -------------------------------------------------------------------------------- /wip-pics/2022-05-02_20-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/wip-pics/2022-05-02_20-11.png -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["dbaeumer.vscode-eslint", "EditorConfig.EditorConfig"] 3 | } 4 | -------------------------------------------------------------------------------- /src/renderer/components/styles/footer.module.css: -------------------------------------------------------------------------------- 1 | .container{ 2 | min-height: 48px; 3 | overflow: hidden; 4 | } 5 | -------------------------------------------------------------------------------- /release/app/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/renderer/components/assets/hide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/src/renderer/components/assets/hide.png -------------------------------------------------------------------------------- /src/renderer/components/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-ocf/cdklightbox/HEAD/src/renderer/components/background.png -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | requiredHeaders: 2 | - Prerequisites 3 | - Expected Behavior 4 | - Current Behavior 5 | - Possible Solution 6 | - Your Environment 7 | -------------------------------------------------------------------------------- /.erb/configs/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-console": "off", 4 | "global-require": "off", 5 | "import/no-dynamic-require": "off" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.eslint.ts: -------------------------------------------------------------------------------- 1 | /* eslint import/no-unresolved: off, import/no-self-import: off */ 2 | 3 | module.exports = require('./webpack.config.renderer.dev').default; 4 | -------------------------------------------------------------------------------- /.erb/configs/postcss.config.js: -------------------------------------------------------------------------------- 1 | const tailwindcss = require('tailwindcss'); 2 | const autoprefixer = require('autoprefixer'); 3 | 4 | module.exports = { 5 | plugins: [tailwindcss, autoprefixer], 6 | }; 7 | -------------------------------------------------------------------------------- /.erb/scripts/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-console": "off", 4 | "global-require": "off", 5 | "import/no-dynamic-require": "off", 6 | "import/no-extraneous-dependencies": "off" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/renderer/components/styles/commands.module.css: -------------------------------------------------------------------------------- 1 | .commands { 2 | color: #ddd7c2; 3 | cursor: pointer; 4 | transition: all ease-in 0.1s; 5 | } 6 | .commands:hover{ 7 | transform: scale(1.05); 8 | opacity: 1; 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | *.exe binary 3 | *.png binary 4 | *.jpg binary 5 | *.jpeg binary 6 | *.ico binary 7 | *.icns binary 8 | *.eot binary 9 | *.otf binary 10 | *.ttf binary 11 | *.woff binary 12 | *.woff2 binary 13 | -------------------------------------------------------------------------------- /src/renderer/components/Contexts.ts: -------------------------------------------------------------------------------- 1 | import { createContext } from 'react'; 2 | 3 | export const StageRefContext = createContext({} as any); 4 | export const ScaleContext = createContext({} as any); 5 | export const LevelFilterContext = createContext({} as any); 6 | -------------------------------------------------------------------------------- /src/main/listeners/fs-utils.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | 3 | export function checkIfEmpty(filePath: string) { 4 | if (!filePath) { 5 | throw new Error('Must provide a filePath, none was provided'); 6 | } 7 | const results = fs.readdirSync(filePath); 8 | return results.length === 0; 9 | } 10 | -------------------------------------------------------------------------------- /.erb/scripts/delete-source-maps.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import rimraf from 'rimraf'; 3 | import webpackPaths from '../configs/webpack.paths'; 4 | 5 | export default function deleteSourceMaps() { 6 | rimraf.sync(path.join(webpackPaths.distMainPath, '*.js.map')); 7 | rimraf.sync(path.join(webpackPaths.distRendererPath, '*.js.map')); 8 | } 9 | -------------------------------------------------------------------------------- /src/renderer/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | The CDK Lightbox 10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /src/renderer/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './utils'; 2 | export * from './Footer'; 3 | export * from './Contexts'; 4 | export * from './OpenPrompt'; 5 | export * from './LevelFilter'; 6 | export * from './ConstructWidget'; 7 | export * from './WidgetBackground'; 8 | export * from './WorkbenchSurface'; 9 | export * from './WorkbenchBackground'; 10 | -------------------------------------------------------------------------------- /release/app/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "electron-react-boilerplate", 3 | "version": "4.5.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "electron-react-boilerplate", 9 | "version": "4.5.0", 10 | "hasInstallScript": true, 11 | "license": "MIT" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.erb/scripts/link-modules.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import webpackPaths from '../configs/webpack.paths'; 3 | 4 | const { srcNodeModulesPath } = webpackPaths; 5 | const { appNodeModulesPath } = webpackPaths; 6 | 7 | if (!fs.existsSync(srcNodeModulesPath) && fs.existsSync(appNodeModulesPath)) { 8 | fs.symlinkSync(appNodeModulesPath, srcNodeModulesPath, 'junction'); 9 | } 10 | -------------------------------------------------------------------------------- /assets/entitlements.mac.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.allow-unsigned-executable-memory 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/renderer/preload.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | interface Window { 3 | electron: { 4 | ipcRenderer: { 5 | myPing(): void; 6 | on( 7 | channel: string, 8 | func: (...args: unknown[]) => void 9 | ): (() => void) | undefined; 10 | once(channel: string, func: (...args: unknown[]) => void): void; 11 | }; 12 | }; 13 | } 14 | } 15 | 16 | export {}; 17 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | import colors from 'tailwindcss/colors'; 2 | 3 | module.exports = { 4 | content: ['./src/renderer/**/*.{js,jsx,ts,tsx,ejs}'], 5 | darkMode: false, // or 'media' or 'class' 6 | theme: { 7 | extend: { 8 | colors: { 9 | sky: colors.sky, 10 | cyan: colors.cyan, 11 | }, 12 | }, 13 | }, 14 | variants: { 15 | extend: {}, 16 | }, 17 | plugins: [], 18 | }; 19 | -------------------------------------------------------------------------------- /.erb/scripts/check-node-env.js: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | 3 | export default function checkNodeEnv(expectedEnv) { 4 | if (!expectedEnv) { 5 | throw new Error('"expectedEnv" not set'); 6 | } 7 | 8 | if (process.env.NODE_ENV !== expectedEnv) { 9 | console.log( 10 | chalk.whiteBright.bgRed.bold( 11 | `"process.env.NODE_ENV" must be "${expectedEnv}" to use this webpack config` 12 | ) 13 | ); 14 | process.exit(2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/3-Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: You want something added to the boilerplate. 🎉 4 | labels: 'enhancement' 5 | --- 6 | 7 | 16 | -------------------------------------------------------------------------------- /src/renderer/index.tsx: -------------------------------------------------------------------------------- 1 | import { createRoot } from 'react-dom/client'; 2 | import App from './App'; 3 | 4 | const container = document.getElementById('root')!; 5 | const root = createRoot(container); 6 | root.render(); 7 | 8 | // // calling IPC exposed from preload script 9 | // window.electron.ipcRenderer.once('ipc-example', (arg) => { 10 | // // eslint-disable-next-line no-console 11 | // console.log(arg); 12 | // }); 13 | // window.electron.ipcRenderer.myPing(); 14 | -------------------------------------------------------------------------------- /.erb/scripts/clean.js: -------------------------------------------------------------------------------- 1 | import rimraf from 'rimraf'; 2 | import process from 'process'; 3 | import webpackPaths from '../configs/webpack.paths'; 4 | 5 | const args = process.argv.slice(2); 6 | const commandMap = { 7 | dist: webpackPaths.distPath, 8 | release: webpackPaths.releasePath, 9 | dll: webpackPaths.dllPath, 10 | }; 11 | 12 | args.forEach((x) => { 13 | const pathToRemove = commandMap[x]; 14 | if (pathToRemove !== undefined) { 15 | rimraf.sync(pathToRemove); 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/2-Question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question.❓ 4 | labels: 'question' 5 | --- 6 | 7 | ## Summary 8 | 9 | 10 | 11 | 20 | -------------------------------------------------------------------------------- /src/renderer/state/substates/working-directory-state.ts: -------------------------------------------------------------------------------- 1 | import { Set } from '../states'; 2 | 3 | export interface WorkingDirectoryState { 4 | setWorkingDirectory(workingDirectory: string): void; 5 | workingDirectory: string; 6 | } 7 | export const workingDirectoryState = (set: Set) => ({ 8 | workingDirectory: '', 9 | setWorkingDirectory(workingDirectory: string) { 10 | set(() => ({ 11 | workingDirectory, 12 | })); 13 | }, 14 | }); 15 | 16 | export default workingDirectoryState; 17 | -------------------------------------------------------------------------------- /.erb/scripts/check-port-in-use.js: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | import detectPort from 'detect-port'; 3 | 4 | const port = process.env.PORT || '1212'; 5 | 6 | detectPort(port, (err, availablePort) => { 7 | if (port !== String(availablePort)) { 8 | throw new Error( 9 | chalk.whiteBright.bgRed.bold( 10 | `Port "${port}" on "localhost" is already in use. Please use another port. ex: PORT=4343 npm start` 11 | ) 12 | ); 13 | } else { 14 | process.exit(0); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Coverage directory used by tools like istanbul 11 | coverage 12 | .eslintcache 13 | 14 | # Dependency directory 15 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 16 | node_modules 17 | 18 | # OSX 19 | .DS_Store 20 | 21 | release/app/dist 22 | release/build 23 | .erb/dll 24 | 25 | .idea 26 | npm-debug.log.* 27 | *.css.d.ts 28 | *.sass.d.ts 29 | *.scss.d.ts 30 | -------------------------------------------------------------------------------- /src/renderer/components/WorkbenchBackground.tsx: -------------------------------------------------------------------------------- 1 | import { useImage } from 'react-konva-utils'; 2 | import { Rect } from 'react-konva'; 3 | import backgroundImage from './background.png'; 4 | 5 | export const WorkbenchBackground = () => { 6 | const [image] = useImage(backgroundImage); 7 | 8 | return ( 9 | 17 | ); 18 | }; 19 | 20 | export default WorkbenchBackground; 21 | -------------------------------------------------------------------------------- /src/renderer/components/assets/show-svgrepo-com.svg: -------------------------------------------------------------------------------- 1 | show 2 | -------------------------------------------------------------------------------- /src/renderer/state/substates/show-hidden-state.ts: -------------------------------------------------------------------------------- 1 | import produce from 'immer'; 2 | import { Set, WorkbenchState } from '../states'; 3 | 4 | export interface ShowHiddenState { 5 | showHidden: boolean; 6 | setShowHidden: (value: boolean) => void; 7 | } 8 | 9 | export const showHiddenState = (set: Set): ShowHiddenState => { 10 | return { 11 | setShowHidden(value: boolean): void { 12 | set( 13 | produce((state: WorkbenchState) => { 14 | state.showHidden = value; 15 | }) 16 | ); 17 | }, 18 | showHidden: false, 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /src/renderer/state/substates/level-filter-state.ts: -------------------------------------------------------------------------------- 1 | import produce from 'immer'; 2 | import { Set, WorkbenchState } from '../states'; 3 | 4 | export interface LevelFilterState { 5 | levelFilter: number; 6 | 7 | setLevelFilter(level: number): void; 8 | } 9 | 10 | export const levelFilterState = (set: Set): LevelFilterState => { 11 | return { 12 | levelFilter: 3, 13 | setLevelFilter(level: number): void { 14 | set( 15 | produce(function (state: WorkbenchState) { 16 | state.levelFilter = level; 17 | }) 18 | ); 19 | }, 20 | }; 21 | }; 22 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Coverage directory used by tools like istanbul 11 | coverage 12 | .eslintcache 13 | 14 | # Dependency directory 15 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 16 | node_modules 17 | 18 | # OSX 19 | .DS_Store 20 | 21 | release/app/dist 22 | release/build 23 | .erb/dll 24 | 25 | .idea 26 | npm-debug.log.* 27 | *.css.d.ts 28 | *.sass.d.ts 29 | *.scss.d.ts 30 | 31 | # eslint ignores hidden directories by default: 32 | # https://github.com/eslint/eslint/issues/8429 33 | !.erb 34 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | ".eslintrc": "jsonc", 4 | ".prettierrc": "jsonc", 5 | ".eslintignore": "ignore" 6 | }, 7 | 8 | "javascript.validate.enable": false, 9 | "javascript.format.enable": false, 10 | "typescript.format.enable": false, 11 | 12 | "search.exclude": { 13 | ".git": true, 14 | ".eslintcache": true, 15 | ".erb/dll": true, 16 | "release/{build,app/dist}": true, 17 | "node_modules": true, 18 | "npm-debug.log.*": true, 19 | "test/**/__snapshots__": true, 20 | "package-lock.json": true, 21 | "*.{css,sass,scss}.d.ts": true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/menus/undo-redo.ts: -------------------------------------------------------------------------------- 1 | import { BrowserWindow } from 'electron'; 2 | 3 | export const buildUndoRedoMenu = () => ({ 4 | label: 'Edit', 5 | submenu: [ 6 | { 7 | label: 'Undo', 8 | accelerator: 'CommandOrControl+Z', 9 | selector: 'undo:', 10 | click() { 11 | BrowserWindow.getFocusedWindow()!.webContents.send('undo'); 12 | }, 13 | }, 14 | { 15 | label: 'Redo', 16 | accelerator: 'Shift+CommandOrControl+Z', 17 | selector: 'redo:', 18 | click() { 19 | BrowserWindow.getFocusedWindow()!.webContents.send('redo'); 20 | }, 21 | }, 22 | ], 23 | }); 24 | -------------------------------------------------------------------------------- /src/renderer/components/OpenPrompt.tsx: -------------------------------------------------------------------------------- 1 | import { ipcRenderer } from 'electron'; 2 | import styles from './styles/commands.module.css'; 3 | 4 | export function OpenPrompt() { 5 | const openWorkbenchClickHandler = async () => { 6 | ipcRenderer.send('open-workbench'); 7 | }; 8 | return ( 9 |
10 | 17 |
18 | ); 19 | } 20 | 21 | export default OpenPrompt; 22 | -------------------------------------------------------------------------------- /src/renderer/components/WidgetBackground.tsx: -------------------------------------------------------------------------------- 1 | import { Rect } from 'react-konva'; 2 | 3 | import { WIDGET_BACKGROUND_COLOR } from '../colors'; 4 | 5 | export interface WidgetBackgroundProps { 6 | width: number; 7 | height: number; 8 | widgetColor: string; 9 | } 10 | 11 | export function WidgetBackground({ 12 | width, 13 | height, 14 | widgetColor, 15 | }: WidgetBackgroundProps) { 16 | return ( 17 | 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /assets/assets.d.ts: -------------------------------------------------------------------------------- 1 | type Styles = Record; 2 | 3 | declare module '*.svg' { 4 | const content: string; 5 | export default content; 6 | } 7 | 8 | declare module '*.png' { 9 | const content: string; 10 | export default content; 11 | } 12 | 13 | declare module '*.jpg' { 14 | const content: string; 15 | export default content; 16 | } 17 | 18 | declare module '*.scss' { 19 | const content: Styles; 20 | export default content; 21 | } 22 | 23 | declare module '*.sass' { 24 | const content: Styles; 25 | export default content; 26 | } 27 | 28 | declare module '*.css' { 29 | const content: Styles; 30 | export default content; 31 | } 32 | -------------------------------------------------------------------------------- /src/renderer/App.css: -------------------------------------------------------------------------------- 1 | /* 2 | * @NOTE: Prepend a `~` to css file paths that are in your node_modules 3 | * See https://github.com/webpack-contrib/sass-loader#imports 4 | */ 5 | body { 6 | position: relative; 7 | height: 100vh; 8 | background: linear-gradient( 9 | 150deg, 10 | #2e4e55 -29.09%, 11 | #0c154b 51.77%, 12 | #291133 129.35% 13 | ); 14 | font-family: sans-serif; 15 | overflow-y: hidden; 16 | display: flex; 17 | justify-content: center; 18 | align-items: center; 19 | margin: 0; 20 | } 21 | 22 | input { 23 | color: #0e0e0e; 24 | border-color: #0e0e0e; 25 | border-width: 1px; 26 | border-radius: 5px; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/util.ts: -------------------------------------------------------------------------------- 1 | /* eslint import/prefer-default-export: off, import/no-mutable-exports: off */ 2 | import { URL } from 'url'; 3 | import path from 'path'; 4 | 5 | export let resolveHtmlPath: (htmlFileName: string) => string; 6 | 7 | if (process.env.NODE_ENV === 'development') { 8 | const port = process.env.PORT || 1212; 9 | resolveHtmlPath = (htmlFileName: string) => { 10 | const url = new URL(`http://localhost:${port}`); 11 | url.pathname = htmlFileName; 12 | return url.href; 13 | }; 14 | } else { 15 | resolveHtmlPath = (htmlFileName: string) => { 16 | return `file://${path.resolve(__dirname, '../renderer/', htmlFileName)}`; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/renderer/state/substates/working-directory-state.test.ts: -------------------------------------------------------------------------------- 1 | import { useWorkbenchStore } from '../zustand-state'; 2 | 3 | describe('setWorkingDirectory', () => { 4 | it('Sets properly', () => { 5 | useWorkbenchStore.setState(() => ({ 6 | workingDirectory: undefined, 7 | widgets: {}, 8 | pickers: {}, 9 | docs: {}, 10 | })); 11 | 12 | // when 13 | 14 | const workingDirectory = 'asdfasfd'; 15 | useWorkbenchStore.getState().setWorkingDirectory(workingDirectory); 16 | 17 | const updatedState = useWorkbenchStore.getState(); 18 | 19 | expect(updatedState.workingDirectory).toEqual(workingDirectory); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /src/renderer/state/substates/status-state.ts: -------------------------------------------------------------------------------- 1 | import { nanoid } from 'nanoid'; 2 | import produce from 'immer'; 3 | import { Set, WorkbenchState } from '../states'; 4 | 5 | export interface StatusMessage { 6 | message: string; 7 | } 8 | 9 | export interface StatusState { 10 | statuses: Record; 11 | 12 | addStatus(newMessage: StatusMessage): void; 13 | } 14 | 15 | export const statusState = (set: Set): StatusState => ({ 16 | statuses: {}, 17 | addStatus(newMessage: StatusMessage) { 18 | set( 19 | produce((state: WorkbenchState) => { 20 | state.statuses[nanoid()] = newMessage; 21 | }) 22 | ); 23 | }, 24 | }); 25 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "label": "Start Webpack Dev", 7 | "script": "start:renderer", 8 | "options": { 9 | "cwd": "${workspaceFolder}" 10 | }, 11 | "isBackground": true, 12 | "problemMatcher": { 13 | "owner": "custom", 14 | "pattern": { 15 | "regexp": "____________" 16 | }, 17 | "background": { 18 | "activeOnStart": true, 19 | "beginsPattern": "Compiling\\.\\.\\.$", 20 | "endsPattern": "(Compiled successfully|Failed to compile)\\.$" 21 | } 22 | } 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /release/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "the-cdk-lightbox", 3 | "version": "0.1.2", 4 | "description": "A viewer for your CDK Apps", 5 | "main": "./dist/main/main.js", 6 | "author": { 7 | "name": "The CDK Lightbox", 8 | "email": "matthew.bonig@gmail.com", 9 | "url": "https://github.com/the-ocf/cdklightbox" 10 | }, 11 | "scripts": { 12 | "electron-rebuild": "node -r ts-node/register ../../.erb/scripts/electron-rebuild.js", 13 | "link-modules": "node -r ts-node/register ../../.erb/scripts/link-modules.ts", 14 | "postinstall": "npm run electron-rebuild && npm run link-modules" 15 | }, 16 | "dependencies": {}, 17 | "license": "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /.erb/scripts/electron-rebuild.js: -------------------------------------------------------------------------------- 1 | import { execSync } from 'child_process'; 2 | import fs from 'fs'; 3 | import { dependencies } from '../../release/app/package.json'; 4 | import webpackPaths from '../configs/webpack.paths'; 5 | 6 | if ( 7 | Object.keys(dependencies || {}).length > 0 && 8 | fs.existsSync(webpackPaths.appNodeModulesPath) 9 | ) { 10 | const electronRebuildCmd = 11 | '../../node_modules/.bin/electron-rebuild --force --types prod,dev,optional --module-dir .'; 12 | const cmd = 13 | process.platform === 'win32' 14 | ? electronRebuildCmd.replace(/\//g, '\\') 15 | : electronRebuildCmd; 16 | execSync(cmd, { 17 | cwd: webpackPaths.appPath, 18 | stdio: 'inherit', 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /src/renderer/state/substates/workbench-view-state.ts: -------------------------------------------------------------------------------- 1 | import { Set } from '../states'; 2 | 3 | export interface WorkbenchViewState { 4 | workbenchPosition: { 5 | x: number; 6 | y: number; 7 | }; 8 | 9 | scale: number; 10 | setWorkbenchPosition(position: { x: number; y: number }): void; 11 | setScale(scale: number): void; 12 | } 13 | 14 | export const workbenchViewState = (set: Set): WorkbenchViewState => ({ 15 | workbenchPosition: { x: 0, y: 0 }, 16 | setWorkbenchPosition(position: { x: number; y: number }): void { 17 | set(() => ({ 18 | workbenchPosition: position, 19 | })); 20 | }, 21 | scale: 1, 22 | setScale(scale: number): void { 23 | set(() => ({ 24 | scale, 25 | })); 26 | }, 27 | }); 28 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - discussion 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: wontfix 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false 18 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Electron: Main", 6 | "type": "node", 7 | "request": "launch", 8 | "protocol": "inspector", 9 | "runtimeExecutable": "npm", 10 | "runtimeArgs": [ 11 | "run start:main --inspect=5858 --remote-debugging-port=9223" 12 | ], 13 | "preLaunchTask": "Start Webpack Dev" 14 | }, 15 | { 16 | "name": "Electron: Renderer", 17 | "type": "chrome", 18 | "request": "attach", 19 | "port": 9223, 20 | "webRoot": "${workspaceFolder}", 21 | "timeout": 15000 22 | } 23 | ], 24 | "compounds": [ 25 | { 26 | "name": "Electron: All", 27 | "configurations": ["Electron: Main", "Electron: Renderer"] 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | release: 7 | runs-on: ${{ matrix.os }} 8 | 9 | strategy: 10 | matrix: 11 | os: [ macos-latest, windows-latest, ubuntu-latest ] 12 | 13 | steps: 14 | - name: Check out Git repository 15 | uses: actions/checkout@v1 16 | 17 | - name: Install Node.js and yarn 18 | uses: actions/setup-node@v2 19 | with: 20 | node-version: 16 21 | cache: yarn 22 | 23 | - name: yarn install 24 | run: | 25 | yarn install 26 | 27 | - name: yarn test 28 | env: 29 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | run: | 31 | yarn package 32 | yarn lint 33 | yarn tsc 34 | yarn test 35 | -------------------------------------------------------------------------------- /.erb/scripts/check-build-exists.ts: -------------------------------------------------------------------------------- 1 | // Check if the renderer and main bundles are built 2 | import path from 'path'; 3 | import chalk from 'chalk'; 4 | import fs from 'fs'; 5 | import webpackPaths from '../configs/webpack.paths'; 6 | 7 | const mainPath = path.join(webpackPaths.distMainPath, 'main.js'); 8 | const rendererPath = path.join(webpackPaths.distRendererPath, 'renderer.js'); 9 | 10 | if (!fs.existsSync(mainPath)) { 11 | throw new Error( 12 | chalk.whiteBright.bgRed.bold( 13 | 'The main process is not built yet. Build it by running "npm run build:main"' 14 | ) 15 | ); 16 | } 17 | 18 | if (!fs.existsSync(rendererPath)) { 19 | throw new Error( 20 | chalk.whiteBright.bgRed.bold( 21 | 'The renderer process is not built yet. Build it by running "npm run build:renderer"' 22 | ) 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /src/renderer/state/substates/error-state.ts: -------------------------------------------------------------------------------- 1 | import { nanoid } from 'nanoid'; 2 | import produce from 'immer'; 3 | import { WorkbenchState, Set } from '../states'; 4 | 5 | export interface ErrorMessage { 6 | message: string; 7 | } 8 | 9 | export interface ErrorsState { 10 | errors: Record; 11 | 12 | clearError(errorKey: string): void; 13 | 14 | addErrors(errorMessage: ErrorMessage): void; 15 | } 16 | 17 | export const errorState = (set: Set) => ({ 18 | errors: {}, 19 | addErrors(errorMessage: ErrorMessage) { 20 | set((state: WorkbenchState) => ({ 21 | errors: { [nanoid()]: errorMessage, ...state.errors }, 22 | })); 23 | }, 24 | clearError(errorKey: string) { 25 | set( 26 | produce((state) => { 27 | delete state.errors[errorKey]; 28 | }) 29 | ); 30 | }, 31 | }); 32 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2021", 4 | "module": "commonjs", 5 | "lib": [ 6 | "dom", 7 | "es2021" 8 | ], 9 | "declaration": true, 10 | "declarationMap": true, 11 | "jsx": "react-jsx", 12 | "strict": true, 13 | "pretty": true, 14 | "sourceMap": true, 15 | "baseUrl": "./src", 16 | "noUnusedLocals": true, 17 | "noUnusedParameters": true, 18 | "noImplicitReturns": true, 19 | "noFallthroughCasesInSwitch": true, 20 | "moduleResolution": "node", 21 | "esModuleInterop": true, 22 | "allowSyntheticDefaultImports": true, 23 | "resolveJsonModule": true, 24 | "allowJs": true, 25 | "outDir": "release/app/dist", 26 | "skipLibCheck": true 27 | }, 28 | "exclude": [ 29 | "test", 30 | "release/build", 31 | "release/app/dist", 32 | ".erb/dll" 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /src/renderer/state/substates/cdk-app-state.ts: -------------------------------------------------------------------------------- 1 | import { Set, WorkbenchState } from '../states'; 2 | 3 | export interface Child { 4 | id: string; 5 | path: string; 6 | children?: Record; 7 | constructInfo: ConstructInfo; 8 | } 9 | 10 | type ConstructInfo = any; 11 | 12 | export interface CdkAppState { 13 | cdkApp?: CdkApp; 14 | 15 | setCdkApp(state: WorkbenchState): void; 16 | } 17 | 18 | export interface CdkApp { 19 | version: string; 20 | tree: Tree; 21 | } 22 | 23 | export type Children = Record; 24 | 25 | export interface Tree { 26 | id: string; 27 | path: string; 28 | children: Children; 29 | constructInfo: ConstructInfo; 30 | } 31 | 32 | export const cdkAppState = (set: Set): CdkAppState => ({ 33 | cdkApp: undefined, 34 | setCdkApp(state: WorkbenchState) { 35 | set(() => { 36 | return { ...state }; 37 | }); 38 | }, 39 | }); 40 | -------------------------------------------------------------------------------- /src/main/listeners/workbench-state-update-listener.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs/promises'; 2 | import path from 'path'; 3 | import { WorkbenchState } from '../../renderer/state'; 4 | import IpcMainEvent = Electron.IpcMainEvent; 5 | 6 | export const LIGHTBOX_STATE_DIRECTORY = '.lightbox'; 7 | export const LIGHTBOX_STATE_FILE = 'state.json'; 8 | 9 | export const workbenchStateUpdateListener = async ( 10 | _event: IpcMainEvent, 11 | state: WorkbenchState 12 | ) => { 13 | console.log('WorkbenchState Updated, ', Date.now()); 14 | 15 | const { workingDirectory } = state; 16 | const lightboxStateDirectory = path.join( 17 | workingDirectory, 18 | LIGHTBOX_STATE_DIRECTORY 19 | ); 20 | await fs.mkdir(lightboxStateDirectory, { recursive: true }); 21 | await fs.writeFile( 22 | path.join(lightboxStateDirectory, LIGHTBOX_STATE_FILE), 23 | JSON.stringify(state, null, 2), 24 | { encoding: 'utf-8' } 25 | ); 26 | }; 27 | 28 | export default workbenchStateUpdateListener; 29 | -------------------------------------------------------------------------------- /.erb/scripts/notarize.js: -------------------------------------------------------------------------------- 1 | const { notarize } = require('electron-notarize'); 2 | const { build } = require('../../package.json'); 3 | 4 | exports.default = async function notarizeMacos(context) { 5 | const { electronPlatformName, appOutDir } = context; 6 | if (electronPlatformName !== 'darwin') { 7 | return; 8 | } 9 | 10 | if (process.env.CI !== 'true') { 11 | console.warn('Skipping notarizing step. Packaging is not running in CI'); 12 | return; 13 | } 14 | 15 | if (!('APPLE_ID' in process.env && 'APPLE_ID_PASS' in process.env)) { 16 | console.warn( 17 | 'Skipping notarizing step. APPLE_ID and APPLE_ID_PASS env variables must be set' 18 | ); 19 | return; 20 | } 21 | 22 | const appName = context.packager.appInfo.productFilename; 23 | 24 | await notarize({ 25 | appBundleId: build.appId, 26 | appPath: `${appOutDir}/${appName}.app`, 27 | appleId: process.env.APPLE_ID, 28 | appleIdPassword: process.env.APPLE_ID_PASS, 29 | }); 30 | }; 31 | -------------------------------------------------------------------------------- /src/main/listeners/save-export-listener.ts: -------------------------------------------------------------------------------- 1 | import { dialog } from 'electron'; 2 | import { writeFileSync } from 'fs'; 3 | import path from 'path'; 4 | import IpcMainEvent = Electron.IpcMainEvent; 5 | 6 | async function writeFile(filePath: string, dataUrl: any) { 7 | const [, encodedString] = dataUrl.split(','); 8 | writeFileSync(filePath, Buffer.from(encodedString, 'base64')); 9 | } 10 | 11 | export const saveExportListener = async ( 12 | _event: IpcMainEvent, 13 | args: { dataUrl: any; workingDirectory: string } 14 | ) => { 15 | console.log('save export listener args: ', args); 16 | const dialogResults = await dialog.showSaveDialog({ 17 | properties: [], 18 | defaultPath: path.join(args.workingDirectory, 'diagram.png'), 19 | message: 'Save Diagram', 20 | filters: [{ name: 'PNG Image', extensions: ['*.png'] }], 21 | }); 22 | if (dialogResults.canceled) { 23 | return; 24 | } 25 | const filePath = dialogResults.filePath!; 26 | await writeFile(filePath, args.dataUrl); 27 | }; 28 | -------------------------------------------------------------------------------- /src/renderer/colors.ts: -------------------------------------------------------------------------------- 1 | export const UNKNOWN = '#1e4b2c'; 2 | export const CONSTRUCT_COLOR = 'rgba(161,255,147,0.36)'; 3 | export const STATIC_FUNCTION_COLOR = '#af694b'; 4 | export const WIDGET_BACKGROUND_COLOR = '#474947'; 5 | export const TEXT_COLOR = '#cbcbcb'; 6 | export const LOOSE_OBJECT_COLOR = '#b7a5d5'; 7 | export const ENUM_COLOR = '#5a87cc'; 8 | export const REQUIRED_COLOR = '#be7c7c'; 9 | export const OBJECT_PICKER_BUTTON_COLOR = '#709eb3'; 10 | export const HIDE_BUTTON = '#747474'; 11 | export const HIDE_BUTTON_TEXT = '#cccccc'; 12 | export const WIDGET_COLORS = [ 13 | '#a94600', 14 | '#a99200', 15 | '#447200', 16 | '#00724e', 17 | '#005f72', 18 | '#003372', 19 | '#330072', 20 | '#6c0072', 21 | ]; 22 | export const LINE_COLOR = 'white'; 23 | export const HIDE_BUTTON_STROKE_COLOR = '#333333'; 24 | export const HIDE_BUTTON_IS_VISIBLE_STROKE_COLOR = '#652727'; 25 | export const SHOW_BUTTON_IS_VISIBLE_STROKE_COLOR = '#2e6527'; 26 | 27 | export const DOUBLE_CORNER_RADIUS = [5, 0, 5, 0]; 28 | export const SINGLE_CORNER_RADIUS = [5, 0, 0, 0]; 29 | -------------------------------------------------------------------------------- /src/main/listeners/load-recent-listener.ts: -------------------------------------------------------------------------------- 1 | import { app, BrowserWindow } from 'electron'; 2 | import { checkIfEmpty } from './fs-utils'; 3 | import { openWorkbench } from '../providers/open-workbench'; 4 | import IpcMainEvent = Electron.IpcMainEvent; 5 | import { createWindow } from '../main'; 6 | 7 | export const loadRecentListener = async ( 8 | _event: IpcMainEvent, 9 | filePath: string 10 | ) => { 11 | const isEmpty = checkIfEmpty(filePath); 12 | const focusedWindow = BrowserWindow.getFocusedWindow(); 13 | if (!focusedWindow) { 14 | await createWindow(); 15 | } 16 | const { webContents } = focusedWindow!; 17 | if (isEmpty) { 18 | webContents.send('error', { 19 | message: 'Directory is empty, cannot open an empty directory.', 20 | }); 21 | return; 22 | } 23 | webContents.send('status', { 24 | message: `Opening app at ${filePath}`, 25 | }); 26 | const state = await openWorkbench(filePath); 27 | app.addRecentDocument(filePath); 28 | webContents.send('load-workbench-state', { 29 | workingDirectory: filePath, 30 | ...state, 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /src/main/preload.ts: -------------------------------------------------------------------------------- 1 | import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron'; 2 | 3 | contextBridge.exposeInMainWorld('electron', { 4 | ipcRenderer: { 5 | myPing() { 6 | ipcRenderer.send('ipc-example', 'ping'); 7 | }, 8 | on(channel: string, func: (...args: unknown[]) => void) { 9 | const validChannels = ['ipc-example']; 10 | if (validChannels.includes(channel)) { 11 | const subscription = (_event: IpcRendererEvent, ...args: unknown[]) => 12 | func(...args); 13 | // Deliberately strip event as it includes `sender` 14 | ipcRenderer.on(channel, subscription); 15 | 16 | return () => ipcRenderer.removeListener(channel, subscription); 17 | } 18 | 19 | return undefined; 20 | }, 21 | once(channel: string, func: (...args: unknown[]) => void) { 22 | const validChannels = ['ipc-example']; 23 | if (validChannels.includes(channel)) { 24 | // Deliberately strip event as it includes `sender` 25 | ipcRenderer.once(channel, (_event, ...args) => func(...args)); 26 | } 27 | }, 28 | }, 29 | }); 30 | -------------------------------------------------------------------------------- /src/main/providers/open-workbench.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs/promises'; 2 | import { existsSync } from 'fs'; 3 | import * as path from 'path'; 4 | import { 5 | LIGHTBOX_STATE_DIRECTORY, 6 | LIGHTBOX_STATE_FILE, 7 | } from '../listeners/workbench-state-update-listener'; 8 | 9 | export const openWorkbench = async (filePath: string) => { 10 | const pathToTree = path.join(filePath, 'cdk.out', 'tree.json'); 11 | if (!existsSync(pathToTree)) { 12 | throw new Error( 13 | "The CDK App doesn't exist yet. Please synthesize your app first." 14 | ); 15 | } 16 | const contents = await fs.readFile(pathToTree, { encoding: 'utf-8' }); 17 | const pathToSavedState = path.join( 18 | filePath, 19 | LIGHTBOX_STATE_DIRECTORY, 20 | LIGHTBOX_STATE_FILE 21 | ); 22 | let parsedState: any = {}; 23 | 24 | if (existsSync(pathToSavedState)) { 25 | const stateContents = await fs.readFile(pathToSavedState, { 26 | encoding: 'utf-8', 27 | }); 28 | parsedState = JSON.parse(stateContents); 29 | } 30 | const parsedTree = JSON.parse(contents); 31 | return { cdkApp: parsedTree, ...parsedState }; 32 | }; 33 | 34 | export default openWorkbench; 35 | -------------------------------------------------------------------------------- /src/renderer/state/substates/widget-view-state.ts: -------------------------------------------------------------------------------- 1 | import produce from 'immer'; 2 | import { Set, WorkbenchState } from '../states'; 3 | 4 | export interface WidgetViewState { 5 | position: { x: number; y: number }; 6 | isVisible: boolean; 7 | } 8 | 9 | export interface WidgetsViewState { 10 | widgets: Record; 11 | 12 | loadPosition(path: string): WidgetViewState; 13 | 14 | setWidgetViewState( 15 | id: string, 16 | widgetViewState: Partial 17 | ): void; 18 | } 19 | 20 | export const widgetsViewState = ( 21 | set: Set, 22 | get: () => WorkbenchState 23 | ): WidgetsViewState => { 24 | return { 25 | widgets: {}, 26 | loadPosition(path: string): WidgetViewState { 27 | return get().widgets[path || 'root']; 28 | }, 29 | setWidgetViewState(id: string, widgetViewState: WidgetViewState): void { 30 | set( 31 | produce(function (state: WorkbenchState) { 32 | state.widgets[id || 'root'] = { 33 | ...(get().widgets[id || 'root'] || { isVisible: true }), 34 | ...widgetViewState, 35 | }; 36 | }) 37 | ); 38 | }, 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present Electron React Boilerplate 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.erb/configs/webpack.paths.ts: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | const rootPath = path.join(__dirname, '../..'); 4 | 5 | const dllPath = path.join(__dirname, '../dll'); 6 | 7 | const srcPath = path.join(rootPath, 'src'); 8 | const srcMainPath = path.join(srcPath, 'main'); 9 | const srcRendererPath = path.join(srcPath, 'renderer'); 10 | 11 | const releasePath = path.join(rootPath, 'release'); 12 | const appPath = path.join(releasePath, 'app'); 13 | const appPackagePath = path.join(appPath, 'package.json'); 14 | const appNodeModulesPath = path.join(appPath, 'node_modules'); 15 | const srcNodeModulesPath = path.join(srcPath, 'node_modules'); 16 | 17 | const distPath = path.join(appPath, 'dist'); 18 | const distMainPath = path.join(distPath, 'main'); 19 | const distRendererPath = path.join(distPath, 'renderer'); 20 | 21 | const buildPath = path.join(releasePath, 'build'); 22 | 23 | export default { 24 | rootPath, 25 | dllPath, 26 | srcPath, 27 | srcMainPath, 28 | srcRendererPath, 29 | releasePath, 30 | appPath, 31 | appPackagePath, 32 | appNodeModulesPath, 33 | srcNodeModulesPath, 34 | distPath, 35 | distMainPath, 36 | distRendererPath, 37 | buildPath, 38 | }; 39 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | 8 | jobs: 9 | publish: 10 | permissions: write-all 11 | 12 | runs-on: ${{ matrix.os }} 13 | 14 | strategy: 15 | matrix: 16 | os: [macos-latest] 17 | 18 | steps: 19 | - name: Checkout git repo 20 | uses: actions/checkout@v3 21 | 22 | - name: Install Node and NPM 23 | uses: actions/setup-node@v3 24 | with: 25 | node-version: 16 26 | 27 | 28 | - name: Install dependencies 29 | run: | 30 | yarn install 31 | 32 | - name: Publish releases 33 | env: 34 | # These values are used for auto updates signing 35 | APPLE_ID: ${{ secrets.APPLE_ID }} 36 | APPLE_ID_PASS: ${{ secrets.APPLE_ID_PASS }} 37 | CSC_LINK: ${{ secrets.CSC_LINK }} 38 | CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} 39 | # This is used for uploading release assets to github 40 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | run: | 42 | yarn postinstall 43 | yarn build 44 | npx electron-builder --publish always --win --mac --linux 45 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: 'erb', 3 | rules: { 4 | // A temporary hack related to IDE not resolving correct package.json 5 | 'import/no-extraneous-dependencies': 'off', 6 | '@typescript-eslint/ban-ts-comment': 'off', 7 | 'react/jsx-props-no-spreading': 'off', 8 | 'import/no-unresolved': 'error', 9 | 'import/prefer-default-export': 'off', 10 | '@typescript-eslint/no-explicit-any': 'off', 11 | 'import/no-cycle': 'off', // Since React 17 and typescript 4.1 you can safely disable the rule 12 | 'react/react-in-jsx-scope': 'off', 13 | }, 14 | parserOptions: { 15 | ecmaVersion: 2020, 16 | sourceType: 'module', 17 | project: './tsconfig.json', 18 | tsconfigRootDir: __dirname, 19 | createDefaultProgram: true, 20 | }, 21 | settings: { 22 | 'import/resolver': { 23 | // See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below 24 | node: {}, 25 | webpack: { 26 | config: require.resolve('./.erb/configs/webpack.config.eslint.ts'), 27 | }, 28 | typescript: {}, 29 | }, 30 | 'import/parsers': { 31 | '@typescript-eslint/parser': ['.ts', '.tsx'], 32 | }, 33 | }, 34 | }; 35 | -------------------------------------------------------------------------------- /src/renderer/state/states.ts: -------------------------------------------------------------------------------- 1 | import { UndoState } from 'zundo'; 2 | import { ErrorsState } from './substates/error-state'; 3 | import { WorkingDirectoryState } from './substates/working-directory-state'; 4 | import { StatusState } from './substates/status-state'; 5 | import { CdkAppState } from './substates/cdk-app-state'; 6 | import { LevelFilterState } from './substates/level-filter-state'; 7 | import { WidgetsViewState } from './substates/widget-view-state'; 8 | import { WorkbenchViewState } from './substates/workbench-view-state'; 9 | import { ShowHiddenState } from './substates/show-hidden-state'; 10 | 11 | export interface WidgetState { 12 | id: string; 13 | x: number; 14 | y: number; 15 | } 16 | 17 | export type Set = ( 18 | partial: 19 | | Partial 20 | | ((state: WorkbenchState) => Partial | WorkbenchState) 21 | | WorkbenchState, 22 | replace?: boolean | undefined 23 | ) => void; 24 | 25 | export interface WorkbenchState 26 | extends ErrorsState, 27 | WorkingDirectoryState, 28 | CdkAppState, 29 | LevelFilterState, 30 | WidgetsViewState, 31 | WorkbenchViewState, 32 | StatusState, 33 | ShowHiddenState, 34 | UndoState { 35 | resetState(): void; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/listeners/open-workbench-listener.ts: -------------------------------------------------------------------------------- 1 | import { app, dialog } from 'electron'; 2 | import { checkIfEmpty } from './fs-utils'; 3 | import { openWorkbench } from '../providers/open-workbench'; 4 | import IpcMainEvent = Electron.IpcMainEvent; 5 | 6 | export async function openWorkbenchHandler( 7 | send: (bus: string, args: any) => void 8 | ) { 9 | console.log('opening dialog...'); 10 | // @ts-ignore 11 | const dialogResults = await dialog.showOpenDialog({ 12 | properties: ['openDirectory'], 13 | }); 14 | if (dialogResults.canceled) { 15 | return; 16 | } 17 | const filePath = dialogResults.filePaths[0]; 18 | const isEmpty = checkIfEmpty(filePath); 19 | if (isEmpty) { 20 | send('error', { 21 | message: 'Directory is empty, cannot open an empty directory.', 22 | }); 23 | return; 24 | } 25 | send('status', { 26 | message: `Opening app at ${filePath}`, 27 | }); 28 | const state = await openWorkbench(filePath); 29 | app.addRecentDocument(filePath); 30 | send('load-workbench-state', { 31 | workingDirectory: filePath, 32 | ...state, 33 | }); 34 | } 35 | 36 | export const openWorkbenchListener = async (event: IpcMainEvent) => { 37 | const send = event.reply; 38 | // @ts-ignore 39 | await openWorkbenchHandler(send); 40 | }; 41 | -------------------------------------------------------------------------------- /src/renderer/state/substates/error-state.test.ts: -------------------------------------------------------------------------------- 1 | import { useWorkbenchStore } from '../zustand-state'; 2 | 3 | describe('errors', () => { 4 | it('adds it', () => { 5 | useWorkbenchStore.setState(() => ({ 6 | widgets: {}, 7 | pickers: {}, 8 | docs: {}, 9 | errors: {}, 10 | })); 11 | 12 | // when 13 | useWorkbenchStore.getState().addErrors({ message: 'some error' }); 14 | 15 | const updatedState = useWorkbenchStore.getState(); 16 | const entries = Object.entries(updatedState.errors); 17 | expect(entries).toHaveLength(1); 18 | const doc = entries[0][1]; 19 | expect(doc.message).toEqual('some error'); 20 | }); 21 | 22 | it('removes it', () => { 23 | // given 24 | useWorkbenchStore.setState(() => ({ 25 | widgets: {}, 26 | pickers: {}, 27 | errors: { 28 | error_1: { message: 'some error 1' }, 29 | error_2: { message: 'some error 2' }, 30 | }, 31 | })); 32 | 33 | // when 34 | useWorkbenchStore.getState().clearError('error_1'); 35 | 36 | // then 37 | const updatedState = useWorkbenchStore.getState(); 38 | const entries = Object.entries(updatedState.errors); 39 | expect(entries).toHaveLength(1); 40 | expect(entries[0][1].message).toEqual('some error 2'); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /src/renderer/components/utils.ts: -------------------------------------------------------------------------------- 1 | export const handlePointerHover = (e: any) => { 2 | // style stage container: 3 | const container = e.target.getStage().container(); 4 | container.style.cursor = 'pointer'; 5 | }; 6 | export const handlePointerLeave = (e: any) => { 7 | const container = e.target.getStage().container(); 8 | container.style.cursor = 'default'; 9 | }; 10 | 11 | const shortenRegex = /([\w-]*)\.(\w*$)/; 12 | 13 | export function shorten(fqn: string) { 14 | const results = shortenRegex.exec(fqn); 15 | if (!results || !results.length) { 16 | return fqn; 17 | } 18 | if (results[1] === 'aws-cdk-lib') { 19 | return results[2]; 20 | } 21 | return `${results[1]}.${results[2]}`; 22 | } 23 | 24 | export function getGradient(width: number, height: number, color: string) { 25 | let marks; 26 | if (height > 300) { 27 | marks = 0.02; 28 | } else if (height >= 100) { 29 | marks = 0.05; 30 | } else { 31 | marks = 0.15; 32 | } 33 | return { 34 | fillLinearGradientStartPoint: { x: width / 2, y: 0 }, 35 | fillLinearGradientEndPoint: { x: width / 2, y: height }, 36 | fillLinearGradientColorStops: [ 37 | 0, 38 | color, 39 | marks, 40 | 'white', 41 | 1 - marks, 42 | 'white', 43 | 1, 44 | color, 45 | ], 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | The CDK Workbench is an open source tool built for and by the CDK community. 4 | 5 | Originally built with the Electron React Boilerplate, anyone looking to develop should have knowledge of the following tools and frameworks: 6 | 7 | * [ElectronJS](https://www.electronjs.org/) 8 | * [ReactJS](https://reactjs.org/) 9 | * [Typescript](https://www.typescriptlang.org/) 10 | * [Konva](https://konvajs.org/docs/react/index.html) 11 | * [React Konva](https://github.com/konvajs/react-konva) 12 | 13 | 14 | ## Install 15 | 16 | Clone the repo and install dependencies. We recommend you fork the repository first and work off of your fork: 17 | 18 | ```bash 19 | git clone --depth 1 --branch main https://github.com/yourforkof/cdklightbox.git cdklightbox 20 | cd cdklightbox 21 | yarn install 22 | ``` 23 | 24 | **Having issues installing? See the [debugging guide](https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/400)** 25 | 26 | ## Starting Development 27 | 28 | Local development is done with a simple: 29 | 30 | ```bash 31 | yarn start 32 | ``` 33 | 34 | ## Community 35 | 36 | Join the [cdk.dev Slack server](https://cdk.dev) and subscribe to the #cdklightbox channel to discuss development and ask questions. 37 | 38 | ## Maintainers 39 | 40 | - [Matthew Bonig](https://github.com/mbonig) 41 | -------------------------------------------------------------------------------- /src/renderer/state/substates/status-state.test.ts: -------------------------------------------------------------------------------- 1 | import { useWorkbenchStore } from '../zustand-state'; 2 | 3 | describe('status', () => { 4 | it('adds it', () => { 5 | useWorkbenchStore.setState(() => ({ 6 | widgets: {}, 7 | pickers: {}, 8 | docs: {}, 9 | statuses: { 10 | existing: { message: 'for reasons' }, 11 | }, 12 | })); 13 | 14 | // when 15 | useWorkbenchStore.getState().addStatus({ message: 'some status' }); 16 | 17 | const updatedState = useWorkbenchStore.getState(); 18 | const entries = Object.entries(updatedState.statuses); 19 | expect(entries).toHaveLength(2); 20 | const doc = entries[1][1]; 21 | expect(doc.message).toEqual('some status'); 22 | }); 23 | 24 | /* it('removes it', () => { 25 | // given 26 | useWorkbenchStore.setState(() => ({ 27 | widgets: {}, 28 | pickers: {}, 29 | errors: { 30 | error_1: { message: 'some error 1' }, 31 | error_2: { message: 'some error 2' }, 32 | }, 33 | })); 34 | 35 | // when 36 | useWorkbenchStore.getState().clearError('error_1'); 37 | 38 | // then 39 | const updatedState = useWorkbenchStore.getState(); 40 | const entries = Object.entries(updatedState.errors); 41 | expect(entries).toHaveLength(1); 42 | expect(entries[0][1].message).toEqual('some error 2'); 43 | }); */ 44 | }); 45 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.base.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Base webpack config used across other specific configs 3 | */ 4 | 5 | import webpack from 'webpack'; 6 | import webpackPaths from './webpack.paths'; 7 | import { dependencies as externals } from '../../release/app/package.json'; 8 | 9 | const configuration: webpack.Configuration = { 10 | externals: [...Object.keys(externals || {})], 11 | 12 | stats: 'errors-only', 13 | 14 | module: { 15 | rules: [ 16 | { 17 | test: /\.[jt]sx?$/, 18 | exclude: /node_modules/, 19 | use: { 20 | loader: 'ts-loader', 21 | options: { 22 | // Remove this line to enable type checking in webpack builds 23 | transpileOnly: true, 24 | }, 25 | }, 26 | }, 27 | ], 28 | }, 29 | 30 | output: { 31 | path: webpackPaths.srcPath, 32 | // https://github.com/webpack/webpack/issues/1114 33 | library: { 34 | type: 'commonjs2', 35 | }, 36 | }, 37 | 38 | /** 39 | * Determine the array of extensions that should be used to resolve modules. 40 | */ 41 | resolve: { 42 | extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'], 43 | modules: [webpackPaths.srcPath, 'node_modules'], 44 | }, 45 | 46 | plugins: [ 47 | new webpack.EnvironmentPlugin({ 48 | NODE_ENV: 'production', 49 | }), 50 | ], 51 | }; 52 | 53 | export default configuration; 54 | -------------------------------------------------------------------------------- /src/renderer/components/LevelFilter.tsx: -------------------------------------------------------------------------------- 1 | import { AiOutlineArrowDown, AiOutlineArrowUp } from 'react-icons/ai'; 2 | import { useWorkbenchStore } from '../state'; 3 | 4 | export function LevelFilter() { 5 | const levelFilter = useWorkbenchStore((x) => x.levelFilter); 6 | const setLevelFilter = useWorkbenchStore((x) => x.setLevelFilter); 7 | const showHidden = useWorkbenchStore((x) => x.showHidden); 8 | const setShowHidden = useWorkbenchStore((x) => x.setShowHidden); 9 | return ( 10 |
14 | Show Hidden: 15 | { 19 | setShowHidden(event.target.checked); 20 | }} 21 | checked={showHidden} 22 | /> 23 |
24 | Level Filter: 25 | {levelFilter} 26 | 33 | 40 |
41 |
42 | ); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/menus/file.ts: -------------------------------------------------------------------------------- 1 | import { BrowserWindow } from 'electron'; 2 | import { openWorkbenchHandler } from '../listeners/open-workbench-listener'; 3 | import MenuItemConstructorOptions = Electron.MenuItemConstructorOptions; 4 | import { createWindow } from '../main'; 5 | 6 | export function buildFileMenu(): MenuItemConstructorOptions { 7 | return { 8 | label: '&File', 9 | submenu: [ 10 | { 11 | label: '📂 &Open...', 12 | accelerator: 'CommandOrControl+O', 13 | click: async () => { 14 | const focusedWindow = BrowserWindow.getFocusedWindow(); 15 | if (!focusedWindow) { 16 | await createWindow(); 17 | } 18 | const { webContents } = BrowserWindow.getFocusedWindow()!; 19 | 20 | await openWorkbenchHandler((bus, args) => 21 | webContents.send(bus, args) 22 | ); 23 | }, 24 | }, 25 | { 26 | label: 'Open Recent', 27 | role: 'recentDocuments', 28 | submenu: [ 29 | { 30 | label: 'Clear Recent', 31 | role: 'clearRecentDocuments', 32 | }, 33 | ], 34 | }, 35 | { 36 | label: 'Export...', 37 | click: () => { 38 | BrowserWindow.getFocusedWindow()!.webContents.send('get-export'); 39 | }, 40 | }, 41 | { 42 | label: '&Close', 43 | accelerator: 'CommandOrControl+W', 44 | click: () => { 45 | BrowserWindow.getFocusedWindow()!.webContents.send('reset-state', {}); 46 | }, 47 | }, 48 | ], 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The CDK Lightbox 2 | 3 | The CDK Lightbox is a tool for visualizing your CDK applications. 4 | 5 | ![Screenshot](./screenshot.png) 6 | 7 | ## Installing 8 | 9 | Head over to [Releases](https://github.com/the-ocf/cdklightbox/releases/latest) and download the package for your operating system. 10 | 11 | Mac M1 - Use the `arm64.dmg` release. Download and run to install. 12 | 13 | Mac Intel - Use the `.dmg` release. Download and run to install. 14 | 15 | Windows - Use the `.exe` release. Download and run to install. 16 | 17 | Linux - Use the `.AppImage` release. Download, `chmod +x` to execute. For example: 18 | 19 | ```shell 20 | curl -O https://github.com/the-ocf/cdklightbox/releases/download/v0.1.2/The-CDK-Lightbox-0.1.2.AppImage 21 | chmod +x The-CDK-Lightbox-0.1.2.AppImage 22 | ./The-CDK-Lightbox-0.1.2.AppImage 23 | ``` 24 | 25 | 26 | ## Using 27 | 28 | Please watch [this video](https://www.youtube.com/watch?v=OK9c-PuoYSM&ab_channel=MatthewBonig) to get an introduction to the CDK Workbench. 29 | 30 | If you have further questions, ask them at the cdk.dev's [Slack server](https://cdk.dev) in the #cdklightbox channel. 31 | 32 | ## Donations 33 | 34 | **Donations will ensure the following:** 35 | 36 | - 🔨 Long term maintenance of the project, including covering build costs and paying for MacOS Developer Licenses. 37 | 38 | 39 | ## Contributing 40 | 41 | This project is built with ElectronJS and the Electron React Boilerplate and is completely open source, built by the CDK community, for the CDK community. 42 | Please refer to [the Contributing doc](./CONTRIBUTING.md) for how to develop and [submit Pull Request](https://github.com/the-ocf/cdklightbox/issues). 43 | -------------------------------------------------------------------------------- /src/renderer/components/assets/hide-svgrepo-com.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/renderer/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | import { ipcRenderer } from 'electron'; 2 | import { useEffect } from 'react'; 3 | import { useWorkbenchStore } from '../state'; 4 | import footer from './styles/footer.module.css'; 5 | import { StatusMessage } from '../state/substates/status-state'; 6 | import { ErrorMessage } from '../state/substates/error-state'; 7 | import IpcRendererEvent = Electron.IpcRendererEvent; 8 | 9 | export function Errors() { 10 | const addErrors = useWorkbenchStore((state) => state.addErrors); 11 | const addStatus = useWorkbenchStore((state) => state.addStatus); 12 | const clearError = useWorkbenchStore((state) => state.clearError); 13 | const errors = useWorkbenchStore((state) => Object.entries(state.errors)); 14 | 15 | // @ts-ignore 16 | useEffect(() => { 17 | const errorListener = ( 18 | _event: IpcRendererEvent, 19 | newError: ErrorMessage 20 | ) => { 21 | addErrors(newError); 22 | }; 23 | 24 | const errorHandler = ipcRenderer.on('error', errorListener); 25 | return () => errorHandler.removeListener('error', errorListener); 26 | }, [addErrors]); 27 | 28 | // @ts-ignore 29 | useEffect(() => { 30 | const statusListener = ( 31 | _event: IpcRendererEvent, 32 | newStatus: StatusMessage 33 | ) => { 34 | addStatus(newStatus); 35 | }; 36 | 37 | const errorHandler = ipcRenderer.on('status', statusListener); 38 | return () => errorHandler.removeListener('status', statusListener); 39 | }, [addStatus]); 40 | 41 | return ( 42 |
43 | {errors.map(([key, error]) => ( 44 | 47 | ))} 48 |
49 | ); 50 | } 51 | 52 | export function Footer() { 53 | return ; 54 | } 55 | -------------------------------------------------------------------------------- /src/renderer/state/zustand-state.ts: -------------------------------------------------------------------------------- 1 | import create from 'zustand'; 2 | import { persist, subscribeWithSelector } from 'zustand/middleware'; 3 | import { undoMiddleware } from 'zundo'; 4 | import { Set, WorkbenchState } from './states'; 5 | import { errorState } from './substates/error-state'; 6 | import { workingDirectoryState } from './substates/working-directory-state'; 7 | 8 | import { statusState } from './substates/status-state'; 9 | import { cdkAppState } from './substates/cdk-app-state'; 10 | import { levelFilterState } from './substates/level-filter-state'; 11 | import { widgetsViewState } from './substates/widget-view-state'; 12 | import { workbenchViewState } from './substates/workbench-view-state'; 13 | import { showHiddenState } from './substates/show-hidden-state'; 14 | 15 | // eslint-disable-next-line import/prefer-default-export 16 | export const useWorkbenchStore = create( 17 | // @ts-ignore 18 | subscribeWithSelector( 19 | persist( 20 | undoMiddleware( 21 | // @ts-ignore 22 | (set: Set, get: () => WorkbenchState) => ({ 23 | ...errorState(set), 24 | ...statusState(set), 25 | ...workingDirectoryState(set), 26 | ...cdkAppState(set), 27 | ...levelFilterState(set), 28 | ...widgetsViewState(set, get), 29 | ...workbenchViewState(set), 30 | ...showHiddenState(set), 31 | resetState() { 32 | // @ts-ignore 33 | set(() => ({ 34 | workingDirectory: '', 35 | widgets: {}, 36 | cdkApp: {}, 37 | scale: 1, 38 | levelFilter: 3, 39 | showHidden: false, 40 | workbenchPosition: { x: 0, y: 0 }, 41 | })); 42 | }, 43 | }), 44 | { exclude: ['workbenchPosition', 'scale'], coolOffDurationMs: 1000 } 45 | ), 46 | { 47 | name: 'workbenchState', 48 | getStorage: () => localStorage, 49 | } 50 | ) 51 | ) 52 | ); 53 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.renderer.dev.dll.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Builds the DLL for development electron renderer process 3 | */ 4 | 5 | import webpack from 'webpack'; 6 | import path from 'path'; 7 | import { merge } from 'webpack-merge'; 8 | import baseConfig from './webpack.config.base'; 9 | import webpackPaths from './webpack.paths'; 10 | import { dependencies } from '../../package.json'; 11 | import checkNodeEnv from '../scripts/check-node-env'; 12 | 13 | checkNodeEnv('development'); 14 | 15 | const dist = webpackPaths.dllPath; 16 | 17 | const configuration: webpack.Configuration = { 18 | context: webpackPaths.rootPath, 19 | 20 | devtool: 'eval', 21 | 22 | mode: 'development', 23 | 24 | target: 'electron-renderer', 25 | 26 | externals: ['fsevents', 'crypto-browserify'], 27 | 28 | /** 29 | * Use `module` from `webpack.config.renderer.dev.js` 30 | */ 31 | module: require('./webpack.config.renderer.dev').default.module, 32 | 33 | entry: { 34 | renderer: Object.keys(dependencies || {}), 35 | }, 36 | 37 | output: { 38 | path: dist, 39 | filename: '[name].dev.dll.js', 40 | library: { 41 | name: 'renderer', 42 | type: 'var', 43 | }, 44 | }, 45 | 46 | plugins: [ 47 | new webpack.DllPlugin({ 48 | path: path.join(dist, '[name].json'), 49 | name: '[name]', 50 | }), 51 | 52 | /** 53 | * Create global constants which can be configured at compile time. 54 | * 55 | * Useful for allowing different behaviour between development builds and 56 | * release builds 57 | * 58 | * NODE_ENV should be production so that modules do not perform certain 59 | * development checks 60 | */ 61 | new webpack.EnvironmentPlugin({ 62 | NODE_ENV: 'development', 63 | }), 64 | 65 | new webpack.LoaderOptionsPlugin({ 66 | debug: true, 67 | options: { 68 | context: webpackPaths.srcPath, 69 | output: { 70 | path: webpackPaths.dllPath, 71 | }, 72 | }, 73 | }), 74 | ], 75 | }; 76 | 77 | export default merge(baseConfig, configuration); 78 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/1-Bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: You're having technical issues. 🐞 4 | labels: 'bug' 5 | --- 6 | 7 | 8 | 9 | ## Prerequisites 10 | 11 | 12 | 13 | - [ ] Using npm 14 | - [ ] Using an up-to-date [`main` branch](https://github.com/electron-react-boilerplate/electron-react-boilerplate/tree/main) 15 | - [ ] Using latest version of devtools. [Check the docs for how to update](https://electron-react-boilerplate.js.org/docs/dev-tools/) 16 | - [ ] Tried solutions mentioned in [#400](https://github.com/electron-react-boilerplate/electron-react-boilerplate/issues/400) 17 | - [ ] For issue in production release, add devtools output of `DEBUG_PROD=true npm run build && npm start` 18 | 19 | ## Expected Behavior 20 | 21 | 22 | 23 | ## Current Behavior 24 | 25 | 26 | 27 | ## Steps to Reproduce 28 | 29 | 30 | 31 | 32 | 1. 33 | 34 | 2. 35 | 36 | 3. 37 | 38 | 4. 39 | 40 | ## Possible Solution (Not obligatory) 41 | 42 | 43 | 44 | ## Context 45 | 46 | 47 | 48 | 49 | 50 | ## Your Environment 51 | 52 | 53 | 54 | - Node version : 55 | - electron-react-boilerplate version or branch : 56 | - Operating System and version : 57 | - Link to your project : 58 | 59 | 68 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.preload.dev.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import webpack from 'webpack'; 3 | import { merge } from 'webpack-merge'; 4 | import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; 5 | import baseConfig from './webpack.config.base'; 6 | import webpackPaths from './webpack.paths'; 7 | import checkNodeEnv from '../scripts/check-node-env'; 8 | 9 | // When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's 10 | // at the dev webpack config is not accidentally run in a production environment 11 | if (process.env.NODE_ENV === 'production') { 12 | checkNodeEnv('development'); 13 | } 14 | 15 | const configuration: webpack.Configuration = { 16 | devtool: 'inline-source-map', 17 | 18 | mode: 'development', 19 | 20 | target: 'electron-preload', 21 | 22 | entry: path.join(webpackPaths.srcMainPath, 'preload.ts'), 23 | 24 | output: { 25 | path: webpackPaths.dllPath, 26 | filename: 'preload.js', 27 | }, 28 | 29 | plugins: [ 30 | new BundleAnalyzerPlugin({ 31 | analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled', 32 | }), 33 | 34 | /** 35 | * Create global constants which can be configured at compile time. 36 | * 37 | * Useful for allowing different behaviour between development builds and 38 | * release builds 39 | * 40 | * NODE_ENV should be production so that modules do not perform certain 41 | * development checks 42 | * 43 | * By default, use 'development' as NODE_ENV. This can be overriden with 44 | * 'staging', for example, by changing the ENV variables in the npm scripts 45 | */ 46 | new webpack.EnvironmentPlugin({ 47 | NODE_ENV: 'development', 48 | }), 49 | 50 | new webpack.LoaderOptionsPlugin({ 51 | debug: true, 52 | }), 53 | ], 54 | 55 | /** 56 | * Disables webpack processing of __dirname and __filename. 57 | * If you run the bundle in node.js it falls back to these values of node.js. 58 | * https://github.com/webpack/webpack/issues/2010 59 | */ 60 | node: { 61 | __dirname: false, 62 | __filename: false, 63 | }, 64 | 65 | watch: true, 66 | }; 67 | 68 | export default merge(baseConfig, configuration); 69 | -------------------------------------------------------------------------------- /.erb/scripts/check-native-dep.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import chalk from 'chalk'; 3 | import { execSync } from 'child_process'; 4 | import { dependencies } from '../../package.json'; 5 | 6 | if (dependencies) { 7 | const dependenciesKeys = Object.keys(dependencies); 8 | const nativeDeps = fs 9 | .readdirSync('node_modules') 10 | .filter((folder) => fs.existsSync(`node_modules/${folder}/binding.gyp`)); 11 | if (nativeDeps.length === 0) { 12 | process.exit(0); 13 | } 14 | try { 15 | // Find the reason for why the dependency is installed. If it is installed 16 | // because of a devDependency then that is okay. Warn when it is installed 17 | // because of a dependency 18 | const { dependencies: dependenciesObject } = JSON.parse( 19 | execSync(`npm ls ${nativeDeps.join(' ')} --json`).toString() 20 | ); 21 | const rootDependencies = Object.keys(dependenciesObject); 22 | const filteredRootDependencies = rootDependencies.filter((rootDependency) => 23 | dependenciesKeys.includes(rootDependency) 24 | ); 25 | if (filteredRootDependencies.length > 0) { 26 | const plural = filteredRootDependencies.length > 1; 27 | console.log(` 28 | ${chalk.whiteBright.bgYellow.bold( 29 | 'Webpack does not work with native dependencies.' 30 | )} 31 | ${chalk.bold(filteredRootDependencies.join(', '))} ${ 32 | plural ? 'are native dependencies' : 'is a native dependency' 33 | } and should be installed inside of the "./release/app" folder. 34 | First, uninstall the packages from "./package.json": 35 | ${chalk.whiteBright.bgGreen.bold('npm uninstall your-package')} 36 | ${chalk.bold( 37 | 'Then, instead of installing the package to the root "./package.json":' 38 | )} 39 | ${chalk.whiteBright.bgRed.bold('npm install your-package')} 40 | ${chalk.bold('Install the package to "./release/app/package.json"')} 41 | ${chalk.whiteBright.bgGreen.bold( 42 | 'cd ./release/app && npm install your-package' 43 | )} 44 | Read more about native dependencies at: 45 | ${chalk.bold( 46 | 'https://electron-react-boilerplate.js.org/docs/adding-dependencies/#module-structure' 47 | )} 48 | `); 49 | process.exit(1); 50 | } 51 | } catch (e) { 52 | console.log('Native dependencies could not be checked'); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.main.prod.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Webpack config for production electron main process 3 | */ 4 | 5 | import path from 'path'; 6 | import webpack from 'webpack'; 7 | import { merge } from 'webpack-merge'; 8 | import TerserPlugin from 'terser-webpack-plugin'; 9 | import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; 10 | import baseConfig from './webpack.config.base'; 11 | import webpackPaths from './webpack.paths'; 12 | import checkNodeEnv from '../scripts/check-node-env'; 13 | import deleteSourceMaps from '../scripts/delete-source-maps'; 14 | 15 | checkNodeEnv('production'); 16 | deleteSourceMaps(); 17 | 18 | const devtoolsConfig = 19 | process.env.DEBUG_PROD === 'true' 20 | ? { 21 | devtool: 'source-map', 22 | } 23 | : {}; 24 | 25 | const configuration: webpack.Configuration = { 26 | ...devtoolsConfig, 27 | 28 | mode: 'production', 29 | 30 | target: 'electron-main', 31 | 32 | entry: { 33 | main: path.join(webpackPaths.srcMainPath, 'main.ts'), 34 | // preload: path.join(webpackPaths.srcMainPath, 'preload.ts'), 35 | }, 36 | 37 | output: { 38 | path: webpackPaths.distMainPath, 39 | filename: '[name].js', 40 | }, 41 | 42 | optimization: { 43 | minimizer: [ 44 | new TerserPlugin({ 45 | parallel: true, 46 | }), 47 | ], 48 | }, 49 | 50 | plugins: [ 51 | new BundleAnalyzerPlugin({ 52 | analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled', 53 | }), 54 | 55 | /** 56 | * Create global constants which can be configured at compile time. 57 | * 58 | * Useful for allowing different behaviour between development builds and 59 | * release builds 60 | * 61 | * NODE_ENV should be production so that modules do not perform certain 62 | * development checks 63 | */ 64 | new webpack.EnvironmentPlugin({ 65 | NODE_ENV: 'production', 66 | DEBUG_PROD: false, 67 | START_MINIMIZED: false, 68 | }), 69 | ], 70 | 71 | /** 72 | * Disables webpack processing of __dirname and __filename. 73 | * If you run the bundle in node.js it falls back to these values of node.js. 74 | * https://github.com/webpack/webpack/issues/2010 75 | */ 76 | node: { 77 | __dirname: false, 78 | __filename: false, 79 | }, 80 | }; 81 | 82 | export default merge(baseConfig, configuration); 83 | -------------------------------------------------------------------------------- /src/renderer/components/assets/search.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 38 | 40 | 41 | 43 | image/svg+xml 44 | 46 | 47 | 48 | 49 | 50 | 54 | 57 | 64 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /assets/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/renderer/App.tsx: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import 'tailwindcss/tailwind.css'; 3 | import { ipcRenderer } from 'electron'; 4 | import { useEffect } from 'react'; 5 | import { WorkbenchSurface } from './components/WorkbenchSurface'; 6 | import { useWorkbenchStore, WorkbenchState } from './state'; 7 | import { OpenPrompt } from './components/OpenPrompt'; 8 | import { Footer } from './components/Footer'; 9 | import IpcRendererEvent = Electron.IpcRendererEvent; 10 | 11 | function App() { 12 | const workingDirectory = useWorkbenchStore((state) => state.workingDirectory); 13 | const resetState = useWorkbenchStore((state) => state.resetState); 14 | const setWorkingDirectory = useWorkbenchStore( 15 | (state) => state.setWorkingDirectory 16 | ); 17 | const workbenchState = useWorkbenchStore((state) => state); 18 | const loadState = useWorkbenchStore((state) => state.setCdkApp); 19 | const undo = useWorkbenchStore((state) => state.undo); 20 | const redo = useWorkbenchStore((state) => state.redo); 21 | 22 | useEffect(() => { 23 | return useWorkbenchStore.subscribe( 24 | (state) => state, 25 | // @ts-ignore 26 | (state) => { 27 | const { 28 | levelFilter, 29 | scale, 30 | showHidden, 31 | widgets, 32 | workbenchPosition, 33 | // eslint-disable-next-line @typescript-eslint/no-shadow 34 | workingDirectory, 35 | } = state; 36 | 37 | if (!workingDirectory) { 38 | // don't do anything if we don't have a workingDirectory 39 | return; 40 | } 41 | 42 | ipcRenderer.send('workbench-state-update', { 43 | levelFilter, 44 | scale, 45 | showHidden, 46 | widgets, 47 | workbenchPosition, 48 | workingDirectory, 49 | }); 50 | } 51 | ); 52 | }); 53 | // @ts-ignore 54 | useEffect(() => { 55 | const listener = () => { 56 | if (redo) redo(); 57 | }; 58 | 59 | const handler = ipcRenderer.on('redo', listener); 60 | return () => handler.removeListener('redo', listener); 61 | }, [redo, workbenchState]); 62 | 63 | // @ts-ignore 64 | useEffect(() => { 65 | const listener = () => { 66 | console.debug('Closing project'); 67 | resetState(); 68 | }; 69 | 70 | const handler = ipcRenderer.on('reset-state', listener); 71 | return () => handler.removeListener('reset-state', listener); 72 | }, [resetState]); 73 | 74 | // @ts-ignore 75 | useEffect(() => { 76 | const listener = () => { 77 | if (undo) undo(); 78 | }; 79 | 80 | const handler = ipcRenderer.on('undo', listener); 81 | return () => handler.removeListener('undo', listener); 82 | }, [undo, workbenchState]); 83 | 84 | // @ts-ignore 85 | useEffect(() => { 86 | const listener = ( 87 | _event: IpcRendererEvent, 88 | loadedState: WorkbenchState 89 | ) => { 90 | console.log('loaded state: ', loadedState); 91 | loadState(loadedState); 92 | setWorkingDirectory(loadedState.workingDirectory); 93 | }; 94 | const handler = ipcRenderer.on('load-workbench-state', listener); 95 | return () => handler.removeListener('load-workbench-state', listener); 96 | }); 97 | 98 | return ( 99 |
100 | {workingDirectory ? : null} 101 | {!workingDirectory ? : null} 102 |
103 |
104 | ); 105 | } 106 | 107 | export default App; 108 | -------------------------------------------------------------------------------- /src/renderer/components/WorkbenchSurface.tsx: -------------------------------------------------------------------------------- 1 | import { Layer, Stage } from 'react-konva'; 2 | import { ipcRenderer } from 'electron'; 3 | import { useEffect, useRef, useState } from 'react'; 4 | import Konva from 'konva'; 5 | import { useWorkbenchStore } from '../state'; 6 | 7 | import { WorkbenchBackground } from './WorkbenchBackground'; 8 | import { ConstructWidget } from './ConstructWidget'; 9 | import { LevelFilter } from './LevelFilter'; 10 | import { ScaleContext, StageRefContext } from './Contexts'; 11 | import KonvaEventObject = Konva.KonvaEventObject; 12 | import IpcRendererEvent = Electron.IpcRendererEvent; 13 | 14 | export function WorkbenchSurface() { 15 | const [size, setSize] = useState({ 16 | width: window.innerWidth, 17 | height: window.innerHeight, 18 | }); 19 | 20 | const setPosition = useWorkbenchStore((state) => state.setWorkbenchPosition); 21 | const setScale = useWorkbenchStore((state) => state.setScale); 22 | const position = useWorkbenchStore((state) => state.workbenchPosition); 23 | const scale = useWorkbenchStore((state) => state.scale); 24 | const tree = useWorkbenchStore((state) => state.cdkApp?.tree); 25 | const workingDirectory = useWorkbenchStore((state) => state.workingDirectory); 26 | const stageRef: any = useRef(); 27 | // @ts-ignore 28 | useEffect(() => { 29 | const handler = (event: IpcRendererEvent) => { 30 | const dataUrl = stageRef.current.toDataURL({ pixelRatio: 4 }); 31 | event.sender.send('save-export', { dataUrl, workingDirectory }); 32 | }; 33 | ipcRenderer.on('get-export', handler); 34 | return () => ipcRenderer.removeListener('get-export', handler); 35 | }); 36 | const handleWheel = (e: any) => { 37 | e.evt.preventDefault(); 38 | const scaleBy = 1.02; 39 | const stage = e.target.getStage(); 40 | const oldScale = stage.scaleX(); 41 | const mousePointTo = { 42 | x: stage.getPointerPosition().x / oldScale - stage.x() / oldScale, 43 | y: stage.getPointerPosition().y / oldScale - stage.y() / oldScale, 44 | }; 45 | 46 | let direction = e.evt.deltaY < 0 ? 1 : -1; 47 | 48 | // when we zoom on trackpad, e.evt.ctrlKey is true 49 | // in that case lets revert direction 50 | if (e.evt.ctrlKey) { 51 | direction = -direction; 52 | } 53 | 54 | let newScale = direction > 0 ? oldScale * scaleBy : oldScale / scaleBy; 55 | if (newScale > 1) { 56 | newScale = 1; 57 | } 58 | if (newScale < 0.25) { 59 | newScale = 0.25; 60 | } 61 | setScale(newScale); 62 | setPosition({ 63 | x: -(mousePointTo.x - stage.getPointerPosition().x / newScale) * newScale, 64 | y: -(mousePointTo.y - stage.getPointerPosition().y / newScale) * newScale, 65 | }); 66 | }; 67 | useEffect(() => { 68 | const checkSize = () => { 69 | setSize({ width: window.innerWidth, height: window.innerHeight }); 70 | }; 71 | window.addEventListener('resize', checkSize); 72 | return () => window.removeEventListener('resize', checkSize); 73 | }, []); 74 | 75 | const handleOnDragEnd = (event: KonvaEventObject) => { 76 | event.cancelBubble = true; 77 | setPosition({ x: event.target.x(), y: event.target.y() }); 78 | }; 79 | 80 | return ( 81 |
82 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
108 | ); 109 | } 110 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.renderer.prod.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Build config for electron renderer process 3 | */ 4 | 5 | import path from 'path'; 6 | import webpack from 'webpack'; 7 | import HtmlWebpackPlugin from 'html-webpack-plugin'; 8 | import MiniCssExtractPlugin from 'mini-css-extract-plugin'; 9 | import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; 10 | import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'; 11 | import { merge } from 'webpack-merge'; 12 | import TerserPlugin from 'terser-webpack-plugin'; 13 | import baseConfig from './webpack.config.base'; 14 | import webpackPaths from './webpack.paths'; 15 | import checkNodeEnv from '../scripts/check-node-env'; 16 | import deleteSourceMaps from '../scripts/delete-source-maps'; 17 | 18 | checkNodeEnv('production'); 19 | deleteSourceMaps(); 20 | 21 | const devtoolsConfig = 22 | process.env.DEBUG_PROD === 'true' 23 | ? { 24 | devtool: 'source-map', 25 | } 26 | : {}; 27 | 28 | const configuration: webpack.Configuration = { 29 | ...devtoolsConfig, 30 | 31 | mode: 'production', 32 | 33 | target: 'electron-renderer', 34 | 35 | entry: [path.join(webpackPaths.srcRendererPath, 'index.tsx')], 36 | 37 | output: { 38 | path: webpackPaths.distRendererPath, 39 | publicPath: './', 40 | filename: 'renderer.js', 41 | }, 42 | 43 | module: { 44 | rules: [ 45 | { 46 | test: /\.s?(a|c)ss$/, 47 | use: [ 48 | MiniCssExtractPlugin.loader, 49 | { 50 | loader: 'css-loader', 51 | options: { 52 | modules: true, 53 | sourceMap: true, 54 | importLoaders: 1, 55 | }, 56 | }, 57 | 'sass-loader', 58 | { 59 | loader: 'postcss-loader', 60 | options: { 61 | postcssOptions: { 62 | plugins: [require('tailwindcss'), require('autoprefixer')], 63 | }, 64 | }, 65 | }, 66 | ], 67 | include: /\.module\.s?(c|a)ss$/, 68 | }, 69 | { 70 | test: /\.s?(a|c)ss$/, 71 | use: [ 72 | MiniCssExtractPlugin.loader, 73 | 'css-loader', 74 | 'sass-loader', 75 | { 76 | loader: 'postcss-loader', 77 | options: { 78 | postcssOptions: { 79 | plugins: [require('tailwindcss'), require('autoprefixer')], 80 | }, 81 | }, 82 | }, 83 | ], 84 | exclude: /\.module\.s?(c|a)ss$/, 85 | }, 86 | // Fonts 87 | { 88 | test: /\.(woff|woff2|eot|ttf|otf)$/i, 89 | type: 'asset/resource', 90 | }, 91 | // Images 92 | { 93 | test: /\.(png|svg|jpg|jpeg|gif)$/i, 94 | type: 'asset/resource', 95 | }, 96 | ], 97 | }, 98 | 99 | optimization: { 100 | minimize: true, 101 | minimizer: [ 102 | new TerserPlugin({ 103 | parallel: true, 104 | }), 105 | new CssMinimizerPlugin(), 106 | ], 107 | }, 108 | 109 | plugins: [ 110 | /** 111 | * Create global constants which can be configured at compile time. 112 | * 113 | * Useful for allowing different behaviour between development builds and 114 | * release builds 115 | * 116 | * NODE_ENV should be production so that modules do not perform certain 117 | * development checks 118 | */ 119 | new webpack.EnvironmentPlugin({ 120 | NODE_ENV: 'production', 121 | DEBUG_PROD: false, 122 | }), 123 | 124 | new MiniCssExtractPlugin({ 125 | filename: 'style.css', 126 | }), 127 | 128 | new BundleAnalyzerPlugin({ 129 | analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled', 130 | }), 131 | 132 | new HtmlWebpackPlugin({ 133 | filename: 'index.html', 134 | template: path.join(webpackPaths.srcRendererPath, 'index.ejs'), 135 | minify: { 136 | collapseWhitespace: true, 137 | removeAttributeQuotes: true, 138 | removeComments: true, 139 | }, 140 | isBrowser: false, 141 | isDevelopment: process.env.NODE_ENV !== 'production', 142 | }), 143 | ], 144 | }; 145 | 146 | export default merge(baseConfig, configuration); 147 | -------------------------------------------------------------------------------- /src/main/main.ts: -------------------------------------------------------------------------------- 1 | /* eslint global-require: off, no-console: off, promise/always-return: off */ 2 | 3 | /** 4 | * This module executes inside of electron's main process. You can start 5 | * electron renderer process from here and communicate with the other processes 6 | * through IPC. 7 | * 8 | * When running `npm run build` or `npm run build:main`, this file is compiled to 9 | * `./src/main.js` using webpack. This gives us some performance wins. 10 | */ 11 | import path from 'path'; 12 | import { app, BrowserWindow, ipcMain, shell } from 'electron'; 13 | import { autoUpdater } from 'electron-updater'; 14 | import log from 'electron-log'; 15 | import MenuBuilder from './menu'; 16 | import { resolveHtmlPath } from './util'; 17 | 18 | import { workbenchStateUpdateListener } from './listeners/workbench-state-update-listener'; 19 | import { openWorkbenchListener } from './listeners/open-workbench-listener'; 20 | import { loadRecentListener } from './listeners/load-recent-listener'; 21 | import { saveExportListener } from './listeners/save-export-listener'; 22 | import { WorkbenchState } from '../renderer/state'; 23 | import IpcMainEvent = Electron.IpcMainEvent; 24 | 25 | export default class AppUpdater { 26 | constructor() { 27 | log.transports.file.level = 'info'; 28 | autoUpdater.logger = log; 29 | autoUpdater.checkForUpdatesAndNotify(); 30 | } 31 | } 32 | 33 | function debounce(func: (..._args: any) => any, timeout = 500) { 34 | let timer: any; 35 | return (...args: []) => { 36 | clearTimeout(timer); 37 | timer = setTimeout(() => { 38 | // @ts-ignore - I don't know how to annotate this type properly, so just ignoring 39 | func.apply(this, args); 40 | }, timeout); 41 | }; 42 | } 43 | 44 | let mainWindow: BrowserWindow | null = null; 45 | 46 | ipcMain.on('ipc-example', async (event, arg) => { 47 | const msgTemplate = (pingPong: string) => `IPC test: ${pingPong}`; 48 | console.log(msgTemplate(arg)); 49 | event.reply('ipc-example', msgTemplate('pong')); 50 | }); 51 | 52 | // @ts-ignore 53 | app.on('open-file', loadRecentListener); 54 | ipcMain.on('open-workbench', openWorkbenchListener); 55 | ipcMain.on( 56 | 'workbench-state-update', 57 | debounce((event: IpcMainEvent, state: WorkbenchState) => 58 | workbenchStateUpdateListener(event, state) 59 | ) 60 | ); 61 | ipcMain.on('save-export', saveExportListener); 62 | 63 | if (process.env.NODE_ENV === 'production') { 64 | const sourceMapSupport = require('source-map-support'); 65 | sourceMapSupport.install(); 66 | } 67 | 68 | const isDevelopment = 69 | process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'; 70 | 71 | if (isDevelopment) { 72 | require('electron-debug')(); 73 | } 74 | 75 | const installExtensions = async () => { 76 | const installer = require('electron-devtools-installer'); 77 | const forceDownload = !!process.env.UPGRADE_EXTENSIONS; 78 | const extensions = ['REACT_DEVELOPER_TOOLS']; 79 | 80 | return installer 81 | .default( 82 | extensions.map((name) => installer[name]), 83 | forceDownload 84 | ) 85 | .catch(console.log); 86 | }; 87 | 88 | export const createWindow = async () => { 89 | if (isDevelopment) { 90 | await installExtensions(); 91 | } 92 | 93 | const RESOURCES_PATH = app.isPackaged 94 | ? path.join(process.resourcesPath, 'assets') 95 | : path.join(__dirname, '../../assets'); 96 | 97 | const getAssetPath = (...paths: string[]): string => { 98 | return path.join(RESOURCES_PATH, ...paths); 99 | }; 100 | 101 | mainWindow = new BrowserWindow({ 102 | show: false, 103 | width: 1024, 104 | height: 728, 105 | icon: getAssetPath('icon.png'), 106 | webPreferences: { 107 | nodeIntegration: true, 108 | nodeIntegrationInWorker: true, 109 | contextIsolation: false, 110 | // preload: app.isPackaged 111 | // ? path.join(__dirname, 'preload.js') 112 | // : path.join(__dirname, '../../.erb/dll/preload.js'), 113 | }, 114 | }); 115 | 116 | mainWindow.loadURL(resolveHtmlPath('index.html')); 117 | 118 | mainWindow.on('ready-to-show', () => { 119 | if (!mainWindow) { 120 | throw new Error('"mainWindow" is not defined'); 121 | } 122 | if (process.env.START_MINIMIZED) { 123 | mainWindow.minimize(); 124 | } else { 125 | mainWindow.showInactive(); 126 | } 127 | }); 128 | 129 | mainWindow.on('closed', () => { 130 | mainWindow = null; 131 | }); 132 | 133 | const menuBuilder = new MenuBuilder(mainWindow); 134 | menuBuilder.buildMenu(); 135 | 136 | // Open urls in the user's browser 137 | mainWindow.webContents.setWindowOpenHandler((edata) => { 138 | shell.openExternal(edata.url); 139 | return { action: 'deny' }; 140 | }); 141 | 142 | // Remove this if your app does not use auto updates 143 | // eslint-disable-next-line 144 | new AppUpdater(); 145 | }; 146 | 147 | /** 148 | * Add event listeners... 149 | */ 150 | 151 | app.on('window-all-closed', () => { 152 | // Respect the OSX convention of having the application in memory even 153 | // after all windows have been closed 154 | if (process.platform !== 'darwin') { 155 | app.quit(); 156 | } 157 | }); 158 | 159 | app 160 | .whenReady() 161 | .then(() => { 162 | createWindow(); 163 | app.on('activate', () => { 164 | // On macOS it's common to re-create a window in the app when the 165 | // dock icon is clicked and there are no other windows open. 166 | if (mainWindow === null) createWindow(); 167 | }); 168 | }) 169 | .catch(console.log); 170 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, religion, or sexual identity 11 | and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the 27 | overall community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or 32 | advances of any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email 36 | address, without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | hello@cdk.dev. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series 87 | of actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or 94 | permanent ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within 114 | the community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.0, available at 120 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 121 | 122 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 123 | enforcement ladder](https://github.com/mozilla/diversity). 124 | 125 | [homepage]: https://www.contributor-covenant.org 126 | 127 | For answers to common questions about this code of conduct, see the FAQ at 128 | https://www.contributor-covenant.org/faq. Translations are available at 129 | https://www.contributor-covenant.org/translations. 130 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.renderer.dev.ts: -------------------------------------------------------------------------------- 1 | import 'webpack-dev-server'; 2 | import path from 'path'; 3 | import fs from 'fs'; 4 | import webpack from 'webpack'; 5 | import HtmlWebpackPlugin from 'html-webpack-plugin'; 6 | import chalk from 'chalk'; 7 | import { merge } from 'webpack-merge'; 8 | import { execSync, spawn } from 'child_process'; 9 | import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'; 10 | import baseConfig from './webpack.config.base'; 11 | import webpackPaths from './webpack.paths'; 12 | import checkNodeEnv from '../scripts/check-node-env'; 13 | 14 | // When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's 15 | // at the dev webpack config is not accidentally run in a production environment 16 | if (process.env.NODE_ENV === 'production') { 17 | checkNodeEnv('development'); 18 | } 19 | 20 | const port = process.env.PORT || 1212; 21 | const manifest = path.resolve(webpackPaths.dllPath, 'renderer.json'); 22 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion 23 | const requiredByDLLConfig = module.parent!.filename.includes( 24 | 'webpack.config.renderer.dev.dll' 25 | ); 26 | 27 | /** 28 | * Warn if the DLL is not built 29 | */ 30 | if ( 31 | !requiredByDLLConfig && 32 | !(fs.existsSync(webpackPaths.dllPath) && fs.existsSync(manifest)) 33 | ) { 34 | console.log( 35 | chalk.black.bgYellow.bold( 36 | 'The DLL files are missing. Sit back while we build them for you with "npm run build-dll"' 37 | ) 38 | ); 39 | execSync('npm run postinstall'); 40 | } 41 | 42 | const configuration: webpack.Configuration = { 43 | devtool: 'inline-source-map', 44 | 45 | mode: 'development', 46 | 47 | target: 'electron-renderer', 48 | 49 | entry: [ 50 | `webpack-dev-server/client?http://localhost:${port}/dist`, 51 | 'webpack/hot/only-dev-server', 52 | path.join(webpackPaths.srcRendererPath, 'index.tsx'), 53 | ], 54 | 55 | output: { 56 | path: webpackPaths.distRendererPath, 57 | publicPath: '/', 58 | filename: 'renderer.dev.js', 59 | }, 60 | 61 | module: { 62 | rules: [ 63 | { 64 | test: /\.s?css$/, 65 | use: [ 66 | 'style-loader', 67 | { 68 | loader: 'css-loader', 69 | options: { 70 | modules: true, 71 | sourceMap: true, 72 | importLoaders: 1, 73 | }, 74 | }, 75 | 'sass-loader', 76 | { 77 | loader: 'postcss-loader', 78 | options: { 79 | postcssOptions: { 80 | plugins: [require('tailwindcss'), require('autoprefixer')], 81 | }, 82 | }, 83 | }, 84 | ], 85 | include: /\.module\.s?(c|a)ss$/, 86 | }, 87 | { 88 | test: /\.s?css$/, 89 | use: [ 90 | 'style-loader', 91 | 'css-loader', 92 | 'sass-loader', 93 | { 94 | loader: 'postcss-loader', 95 | options: { 96 | postcssOptions: { 97 | plugins: [require('tailwindcss'), require('autoprefixer')], 98 | }, 99 | }, 100 | }, 101 | ], 102 | exclude: /\.module\.s?(c|a)ss$/, 103 | }, 104 | // Fonts 105 | { 106 | test: /\.(woff|woff2|eot|ttf|otf)$/i, 107 | type: 'asset/resource', 108 | }, 109 | // Images 110 | { 111 | test: /\.(png|svg|jpg|jpeg|gif)$/i, 112 | type: 'asset/resource', 113 | }, 114 | ], 115 | }, 116 | plugins: [ 117 | ...(requiredByDLLConfig 118 | ? [] 119 | : [ 120 | new webpack.DllReferencePlugin({ 121 | context: webpackPaths.dllPath, 122 | manifest: require(manifest), 123 | sourceType: 'var', 124 | }), 125 | ]), 126 | 127 | new webpack.NoEmitOnErrorsPlugin(), 128 | 129 | /** 130 | * Create global constants which can be configured at compile time. 131 | * 132 | * Useful for allowing different behaviour between development builds and 133 | * release builds 134 | * 135 | * NODE_ENV should be production so that modules do not perform certain 136 | * development checks 137 | * 138 | * By default, use 'development' as NODE_ENV. This can be overriden with 139 | * 'staging', for example, by changing the ENV variables in the npm scripts 140 | */ 141 | new webpack.EnvironmentPlugin({ 142 | NODE_ENV: 'development', 143 | }), 144 | 145 | new webpack.LoaderOptionsPlugin({ 146 | debug: true, 147 | }), 148 | 149 | new ReactRefreshWebpackPlugin(), 150 | 151 | new HtmlWebpackPlugin({ 152 | filename: path.join('index.html'), 153 | template: path.join(webpackPaths.srcRendererPath, 'index.ejs'), 154 | minify: { 155 | collapseWhitespace: true, 156 | removeAttributeQuotes: true, 157 | removeComments: true, 158 | }, 159 | isBrowser: false, 160 | env: process.env.NODE_ENV, 161 | isDevelopment: process.env.NODE_ENV !== 'production', 162 | nodeModules: webpackPaths.appNodeModulesPath, 163 | }), 164 | ], 165 | 166 | node: { 167 | __dirname: false, 168 | __filename: false, 169 | }, 170 | 171 | devServer: { 172 | port, 173 | compress: true, 174 | hot: true, 175 | headers: { 'Access-Control-Allow-Origin': '*' }, 176 | static: { 177 | publicPath: '/', 178 | }, 179 | historyApiFallback: { 180 | verbose: true, 181 | }, 182 | setupMiddlewares(middlewares) { 183 | console.log('Starting preload.js builder...'); 184 | const preloadProcess = spawn('npm', ['run', 'start:preload'], { 185 | shell: true, 186 | stdio: 'inherit', 187 | }) 188 | .on('close', (code: number) => process.exit(code!)) 189 | .on('error', (spawnError) => console.error(spawnError)); 190 | 191 | console.log('Starting Main Process...'); 192 | spawn('npm', ['run', 'start:main'], { 193 | shell: true, 194 | stdio: 'inherit', 195 | }) 196 | .on('close', (code: number) => { 197 | preloadProcess.kill(); 198 | process.exit(code!); 199 | }) 200 | .on('error', (spawnError) => console.error(spawnError)); 201 | return middlewares; 202 | }, 203 | }, 204 | }; 205 | 206 | export default merge(baseConfig, configuration); 207 | -------------------------------------------------------------------------------- /src/renderer/components/ConstructWidget.tsx: -------------------------------------------------------------------------------- 1 | import { Group, Image, Line, Rect, Text } from 'react-konva'; 2 | import { createContext, useContext } from 'react'; 3 | import Konva from 'konva'; 4 | import { useImage } from 'react-konva-utils'; 5 | import { 6 | CONSTRUCT_COLOR, 7 | HIDE_BUTTON_IS_VISIBLE_STROKE_COLOR, 8 | LINE_COLOR, 9 | SHOW_BUTTON_IS_VISIBLE_STROKE_COLOR, 10 | SINGLE_CORNER_RADIUS, 11 | WIDGET_BACKGROUND_COLOR, 12 | WIDGET_COLORS, 13 | } from '../colors'; 14 | import { WidgetBackground } from './WidgetBackground'; 15 | import { Child } from '../state/substates/cdk-app-state'; 16 | import { useWorkbenchStore } from '../state'; 17 | import { WidgetViewState } from '../state/substates/widget-view-state'; 18 | import hideImage from './assets/hide-svgrepo-com.svg'; 19 | import showImage from './assets/show-svgrepo-com.svg'; 20 | import { shorten } from './utils'; 21 | import KonvaEventObject = Konva.KonvaEventObject; 22 | 23 | const ConstructContext = createContext({} as ConstructWidgetProps); 24 | 25 | export interface ConstructWidgetState { 26 | forType: string; 27 | id: string; 28 | 29 | [k: string]: any; 30 | } 31 | 32 | const HEADER_HEIGHT = 50; 33 | 34 | const Header = () => { 35 | const { root, level } = useContext(ConstructContext); 36 | const setWidgetViewState = useWorkbenchStore( 37 | (state) => state.setWidgetViewState 38 | ); 39 | const widgetViewState = useWorkbenchStore( 40 | (state) => state.widgets[root.path || 'root'] 41 | ) ?? { isVisible: true }; 42 | const [hideIcon] = useImage(hideImage); 43 | const [showIcon] = useImage(showImage); 44 | 45 | const groupHeight = HEADER_HEIGHT; 46 | const toggleWidget = (event: KonvaEventObject) => { 47 | console.debug('Toggling visibility'); 48 | event.cancelBubble = true; 49 | 50 | setWidgetViewState(root.path, { 51 | position: widgetViewState.position, 52 | isVisible: !widgetViewState.isVisible, 53 | }); 54 | }; 55 | const handleCursor = (e: KonvaEventObject) => { 56 | const stage = e.target.getStage(); 57 | if (stage) { 58 | if (e.type === 'mouseenter') { 59 | stage.container().style.cursor = 'pointer'; 60 | } else { 61 | stage.container().style.cursor = 'default'; 62 | } 63 | } 64 | }; 65 | 66 | return ( 67 | 68 | 81 | 89 | 108 | 109 | 110 | 111 | 118 | 125 | 126 | 127 | ); 128 | }; 129 | 130 | export interface ConstructWidgetProps { 131 | root: Child; 132 | level: number; 133 | index: number; 134 | // eslint-disable-next-line react/require-default-props 135 | scopeX?: number; 136 | // eslint-disable-next-line react/require-default-props 137 | scopeY?: number; 138 | } 139 | 140 | function getPosition(index: number): WidgetViewState { 141 | const offsetX = 0; 142 | const offsetY = 0; 143 | const angle = index * 30; 144 | const radius = 500; 145 | return { 146 | position: { 147 | x: offsetX + Math.cos(angle * (Math.PI / 180)) * radius, 148 | y: offsetY + -1 * Math.sin(angle * (Math.PI / 180)) * radius, 149 | }, 150 | isVisible: true, 151 | }; 152 | } 153 | 154 | export const ConstructWidget = (props: ConstructWidgetProps) => { 155 | const { root, index, level, scopeX, scopeY } = props; 156 | 157 | const levelFilter = useWorkbenchStore((x) => x.levelFilter); 158 | const loadPosition = useWorkbenchStore((x) => x.loadPosition); 159 | const setWidgetViewState = useWorkbenchStore((x) => x.setWidgetViewState); 160 | const showHidden = useWorkbenchStore((x) => x.showHidden); 161 | const { position, isVisible } = loadPosition(root.path) ?? getPosition(index); 162 | const { x, y } = position ?? {}; 163 | const handleOnDrag = (event: KonvaEventObject) => { 164 | event.cancelBubble = true; 165 | setWidgetViewState(root.path, { 166 | position: { x: event.target.x(), y: event.target.y() }, 167 | }); 168 | }; 169 | 170 | const calculateCenter = () => { 171 | return [100, 100 + HEADER_HEIGHT / 2]; 172 | }; 173 | 174 | const calculateLineStart = () => { 175 | // if we're to the right of the parent 176 | if (x > 100) { 177 | const startX = -x + 200; 178 | const startY = -y + 100 + HEADER_HEIGHT / 2; 179 | return [startX, startY]; 180 | } 181 | // we're to the left of the parent 182 | if (x < -200) { 183 | return [-x, -y + 100 + HEADER_HEIGHT / 2]; 184 | } 185 | // if we're below the parent 186 | if (y > 0) { 187 | return [-x + 100, -y + 200 + HEADER_HEIGHT]; 188 | } 189 | // otherwise go out the top 190 | return [-x + 100, -y]; 191 | }; 192 | return isVisible || showHidden ? ( 193 | 194 | 195 | {scopeX !== undefined && scopeY !== undefined ? ( 196 | 201 | ) : null} 202 | 207 |
208 | {root.children && level <= levelFilter 209 | ? Object.values(root.children) 210 | .filter((child) => child.id !== 'Tree') 211 | .filter((child) => child.id !== 'CDKMetadata') 212 | .map((child, i) => ( 213 | 221 | )) 222 | : null} 223 | 224 | 225 | ) : null; 226 | }; 227 | -------------------------------------------------------------------------------- /src/main/menu.ts: -------------------------------------------------------------------------------- 1 | import { 2 | app, 3 | BrowserWindow, 4 | Menu, 5 | MenuItemConstructorOptions, 6 | shell, 7 | } from 'electron'; 8 | import { buildFileMenu } from './menus/file'; 9 | import { buildUndoRedoMenu } from './menus/undo-redo'; 10 | 11 | export interface DarwinMenuItemConstructorOptions 12 | extends MenuItemConstructorOptions { 13 | selector?: string; 14 | submenu?: DarwinMenuItemConstructorOptions[] | Menu; 15 | } 16 | 17 | export default class MenuBuilder { 18 | mainWindow: BrowserWindow; 19 | 20 | constructor(mainWindow: BrowserWindow) { 21 | this.mainWindow = mainWindow; 22 | } 23 | 24 | buildMenu(): Menu { 25 | if ( 26 | process.env.NODE_ENV === 'development' || 27 | process.env.DEBUG_PROD === 'true' 28 | ) { 29 | this.setupDevelopmentEnvironment(); 30 | } 31 | 32 | const template = 33 | process.platform === 'darwin' 34 | ? this.buildDarwinTemplate() 35 | : this.buildDefaultTemplate(); 36 | 37 | const menu = Menu.buildFromTemplate(template); 38 | Menu.setApplicationMenu(menu); 39 | 40 | return menu; 41 | } 42 | 43 | setupDevelopmentEnvironment(): void { 44 | this.mainWindow.webContents.on('context-menu', (_, props) => { 45 | const { x, y } = props; 46 | 47 | Menu.buildFromTemplate([ 48 | { 49 | label: 'Inspect element', 50 | click: () => { 51 | this.mainWindow.webContents.inspectElement(x, y); 52 | }, 53 | }, 54 | ]).popup({ window: this.mainWindow }); 55 | }); 56 | } 57 | 58 | buildDarwinTemplate(): MenuItemConstructorOptions[] { 59 | const subMenuAbout: DarwinMenuItemConstructorOptions = { 60 | label: 'CDK Lightbox', 61 | submenu: [ 62 | { 63 | label: 'About', 64 | selector: 'orderFrontStandardAboutPanel:', 65 | }, 66 | { type: 'separator' }, 67 | { 68 | label: 'Hide CDK Lightbox', 69 | accelerator: 'CommandOrControl+H', 70 | selector: 'hide:', 71 | }, 72 | { 73 | label: 'Hide Others', 74 | accelerator: 'CommandOrControl+Shift+H', 75 | selector: 'hideOtherApplications:', 76 | }, 77 | { label: 'Show All', selector: 'unhideAllApplications:' }, 78 | { type: 'separator' }, 79 | { 80 | label: 'Quit', 81 | accelerator: 'CommandOrControl+Q', 82 | click: () => { 83 | app.quit(); 84 | }, 85 | }, 86 | ], 87 | }; 88 | 89 | const subMenuViewDev: MenuItemConstructorOptions = { 90 | label: 'View', 91 | submenu: [ 92 | { 93 | label: 'Reload', 94 | accelerator: 'CommandOrControl+R', 95 | click: () => { 96 | this.mainWindow.webContents.reload(); 97 | }, 98 | }, 99 | { 100 | label: 'Toggle Full Screen', 101 | accelerator: 'Ctrl+Command+F', 102 | click: () => { 103 | this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); 104 | }, 105 | }, 106 | { 107 | label: 'Toggle Developer Tools', 108 | accelerator: 'Alt+Command+I', 109 | click: () => { 110 | this.mainWindow.webContents.toggleDevTools(); 111 | }, 112 | }, 113 | ], 114 | }; 115 | const subMenuViewProd: MenuItemConstructorOptions = { 116 | label: 'View', 117 | submenu: [ 118 | { 119 | label: 'Toggle Full Screen', 120 | accelerator: 'Ctrl+Command+F', 121 | click: () => { 122 | this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); 123 | }, 124 | }, 125 | ], 126 | }; 127 | const subMenuWindow: DarwinMenuItemConstructorOptions = { 128 | label: 'Window', 129 | submenu: [ 130 | { 131 | label: 'Minimize', 132 | accelerator: 'CommandOrControl+M', 133 | selector: 'performMiniaturize:', 134 | }, 135 | { 136 | label: 'Close', 137 | accelerator: 'CommandOrControl+W', 138 | selector: 'performClose:', 139 | }, 140 | { type: 'separator' }, 141 | { label: 'Bring All to Front', selector: 'arrangeInFront:' }, 142 | ], 143 | }; 144 | const subMenuHelp: MenuItemConstructorOptions = { 145 | label: 'Help', 146 | submenu: [ 147 | { 148 | label: 'Learn More', 149 | click() { 150 | shell.openExternal('https://electronjs.org'); 151 | }, 152 | }, 153 | { 154 | label: 'Documentation', 155 | click() { 156 | shell.openExternal( 157 | 'https://github.com/electron/electron/tree/main/docs#readme' 158 | ); 159 | }, 160 | }, 161 | { 162 | label: 'Community Discussions', 163 | click() { 164 | shell.openExternal('https://www.electronjs.org/community'); 165 | }, 166 | }, 167 | { 168 | label: 'Search Issues', 169 | click() { 170 | shell.openExternal('https://github.com/electron/electron/issues'); 171 | }, 172 | }, 173 | ], 174 | }; 175 | 176 | const subMenuView = 177 | process.env.NODE_ENV === 'development' || 178 | process.env.DEBUG_PROD === 'true' 179 | ? subMenuViewDev 180 | : subMenuViewProd; 181 | 182 | return [ 183 | subMenuAbout, 184 | buildFileMenu(), 185 | buildUndoRedoMenu(), 186 | subMenuView, 187 | subMenuWindow, 188 | subMenuHelp, 189 | ]; 190 | } 191 | 192 | buildDefaultTemplate() { 193 | const templateDefault = [ 194 | buildFileMenu(), 195 | buildUndoRedoMenu(), 196 | 197 | { 198 | label: '&View', 199 | submenu: 200 | process.env.NODE_ENV === 'development' || 201 | process.env.DEBUG_PROD === 'true' 202 | ? [ 203 | { 204 | label: '&Reload', 205 | accelerator: 'Ctrl+R', 206 | click: () => { 207 | this.mainWindow.webContents.reload(); 208 | }, 209 | }, 210 | { 211 | label: 'Toggle &Full Screen', 212 | accelerator: 'F11', 213 | click: () => { 214 | this.mainWindow.setFullScreen( 215 | !this.mainWindow.isFullScreen() 216 | ); 217 | }, 218 | }, 219 | { 220 | label: 'Toggle &Developer Tools', 221 | accelerator: 'Alt+Ctrl+I', 222 | click: () => { 223 | this.mainWindow.webContents.toggleDevTools(); 224 | }, 225 | }, 226 | ] 227 | : [ 228 | { 229 | label: 'Toggle &Full Screen', 230 | accelerator: 'F11', 231 | click: () => { 232 | this.mainWindow.setFullScreen( 233 | !this.mainWindow.isFullScreen() 234 | ); 235 | }, 236 | }, 237 | ], 238 | }, 239 | { 240 | label: 'Help', 241 | submenu: [ 242 | { 243 | label: 'Learn More', 244 | click() { 245 | shell.openExternal('https://electronjs.org'); 246 | }, 247 | }, 248 | { 249 | label: 'Documentation', 250 | click() { 251 | shell.openExternal( 252 | 'https://github.com/electron/electron/tree/main/docs#readme' 253 | ); 254 | }, 255 | }, 256 | { 257 | label: 'Community Discussions', 258 | click() { 259 | shell.openExternal('https://www.electronjs.org/community'); 260 | }, 261 | }, 262 | { 263 | label: 'Search Issues', 264 | click() { 265 | shell.openExternal('https://github.com/electron/electron/issues'); 266 | }, 267 | }, 268 | ], 269 | }, 270 | ]; 271 | 272 | return templateDefault; 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cdk-lightbox", 3 | "description": "A visual lightbox for viewing CDK applications.", 4 | "scripts": { 5 | "build": "concurrently \"npm run build:main\" \"npm run build:renderer\"", 6 | "build:main": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.main.prod.ts", 7 | "build:renderer": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.prod.ts", 8 | "rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir release/app", 9 | "lint": "cross-env NODE_ENV=development eslint . --ext .js,.jsx,.ts,.tsx", 10 | "package": "ts-node ./.erb/scripts/clean.js dist && npm run build && electron-builder build --publish never", 11 | "preinstall": "npx only-allow yarn", 12 | "postinstall": "ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts && opencollective-postinstall", 13 | "start": "ts-node ./.erb/scripts/check-port-in-use.js && npm run start:renderer", 14 | "start:main": "cross-env NODE_ENV=development electronmon -r ts-node/register/transpile-only ./src/main/main.ts", 15 | "start:preload": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.preload.dev.ts", 16 | "start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts", 17 | "scrape-jsii": "ts-node ./src/util/scrape-jsii.ts", 18 | "test": "jest", 19 | "prepare": "husky install" 20 | }, 21 | "lint-staged": { 22 | "*.{js,jsx,ts,tsx}": [ 23 | "cross-env NODE_ENV=development eslint --cache" 24 | ], 25 | "*.json,.{eslintrc,prettierrc}": [ 26 | "prettier --ignore-path .eslintignore --parser json --write" 27 | ], 28 | "*.{css,scss}": [ 29 | "prettier --ignore-path .eslintignore --single-quote --write" 30 | ], 31 | "*.{html,md,yml}": [ 32 | "prettier --ignore-path .eslintignore --single-quote --write" 33 | ] 34 | }, 35 | "build": { 36 | "productName": "The CDK Lightbox", 37 | "appId": "org.openconstructfoundation.cdklightbox", 38 | "asar": true, 39 | "asarUnpack": "**\\*.{node,dll}", 40 | "files": [ 41 | "dist", 42 | "node_modules", 43 | "package.json" 44 | ], 45 | "afterSign": ".erb/scripts/notarize.js", 46 | "mac": { 47 | "target": { 48 | "target": "default", 49 | "arch": [ 50 | "arm64", 51 | "x64" 52 | ] 53 | }, 54 | "type": "distribution", 55 | "hardenedRuntime": true, 56 | "entitlements": "assets/entitlements.mac.plist", 57 | "entitlementsInherit": "assets/entitlements.mac.plist", 58 | "gatekeeperAssess": false 59 | }, 60 | "dmg": { 61 | "contents": [ 62 | { 63 | "x": 130, 64 | "y": 220 65 | }, 66 | { 67 | "x": 410, 68 | "y": 220, 69 | "type": "link", 70 | "path": "/Applications" 71 | } 72 | ] 73 | }, 74 | "win": { 75 | "target": [ 76 | "nsis" 77 | ] 78 | }, 79 | "linux": { 80 | "target": [ 81 | "AppImage" 82 | ], 83 | "category": "Development" 84 | }, 85 | "directories": { 86 | "app": "release/app", 87 | "buildResources": "assets", 88 | "output": "release/build" 89 | }, 90 | "extraResources": [ 91 | "./assets/**" 92 | ], 93 | "publish": { 94 | "provider": "github", 95 | "owner": "the-ocf", 96 | "repo": "cdklightbox", 97 | "releaseType": "release" 98 | } 99 | }, 100 | "repository": { 101 | "type": "git", 102 | "url": "git+https://github.com/the-ocf/cdklightbox.git" 103 | }, 104 | "author": { 105 | "name": "Matthew Bonig", 106 | "email": "matthew.bonig@gmail.com", 107 | "url": "https://github.com/the-ocf/cdklightbox" 108 | }, 109 | "license": "MIT", 110 | "bugs": { 111 | "url": "https://github.com/the-ocf/cdklightbox/issues" 112 | }, 113 | "keywords": [ 114 | "awscdk", 115 | "cdk", 116 | "lightbox", 117 | "openconstructfoundation" 118 | ], 119 | "homepage": "https://github.com/the-ocf/cdklightbox#readme", 120 | "jest": { 121 | "testURL": "http://localhost/", 122 | "testEnvironment": "jsdom", 123 | "transform": { 124 | "\\.(ts|tsx|js|jsx)$": "ts-jest" 125 | }, 126 | "moduleNameMapper": { 127 | "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/.erb/mocks/fileMock.js", 128 | "\\.(css|less|sass|scss)$": "identity-obj-proxy" 129 | }, 130 | "moduleFileExtensions": [ 131 | "js", 132 | "jsx", 133 | "ts", 134 | "tsx", 135 | "json" 136 | ], 137 | "moduleDirectories": [ 138 | "node_modules", 139 | "release/app/node_modules" 140 | ], 141 | "testPathIgnorePatterns": [ 142 | "release/app/dist" 143 | ], 144 | "setupFiles": [ 145 | "./.erb/scripts/check-build-exists.ts" 146 | ] 147 | }, 148 | "devDependencies": { 149 | "@pmmmwh/react-refresh-webpack-plugin": "0.5.5", 150 | "@teamsupercell/typings-for-css-modules-loader": "^2.5.1", 151 | "@testing-library/jest-dom": "^5.16.4", 152 | "@testing-library/react": "^13.0.0", 153 | "@types/jest": "^27.4.1", 154 | "@types/node": "17.0.23", 155 | "@types/react": "^17.0.43", 156 | "@types/react-dom": "^17.0.14", 157 | "@types/react-test-renderer": "^17.0.1", 158 | "@types/terser-webpack-plugin": "^5.0.4", 159 | "@types/webpack-bundle-analyzer": "^4.4.1", 160 | "@types/webpack-env": "^1.16.3", 161 | "@typescript-eslint/eslint-plugin": "^5.18.0", 162 | "@typescript-eslint/parser": "^5.18.0", 163 | "autoprefixer": "^10.4.4", 164 | "browserslist-config-erb": "^0.0.3", 165 | "chalk": "^4.1.2", 166 | "concurrently": "^7.1.0", 167 | "core-js": "^3.21.1", 168 | "cross-env": "^7.0.3", 169 | "css-loader": "^6.7.1", 170 | "css-minimizer-webpack-plugin": "^3.4.1", 171 | "detect-port": "^1.3.0", 172 | "electron": "^18.0.1", 173 | "electron-builder": "^23.0.3", 174 | "electron-devtools-installer": "^3.2.0", 175 | "electron-notarize": "^1.2.1", 176 | "electron-rebuild": "^3.2.7", 177 | "electronmon": "^2.0.2", 178 | "eslint": "^8.12.0", 179 | "eslint-config-airbnb-base": "^15.0.0", 180 | "eslint-config-erb": "^4.0.3", 181 | "eslint-import-resolver-typescript": "^2.7.1", 182 | "eslint-import-resolver-webpack": "^0.13.2", 183 | "eslint-plugin-compat": "^4.0.2", 184 | "eslint-plugin-import": "^2.25.4", 185 | "eslint-plugin-jest": "^26.1.3", 186 | "eslint-plugin-jsx-a11y": "^6.5.1", 187 | "eslint-plugin-promise": "^6.0.0", 188 | "eslint-plugin-react": "^7.29.4", 189 | "eslint-plugin-react-hooks": "^4.4.0", 190 | "file-loader": "^6.2.0", 191 | "html-webpack-plugin": "^5.5.0", 192 | "husky": "^7.0.4", 193 | "identity-obj-proxy": "^3.0.0", 194 | "jest": "^27.5.1", 195 | "lint-staged": "^12.3.7", 196 | "mini-css-extract-plugin": "^2.6.0", 197 | "opencollective-postinstall": "^2.0.3", 198 | "postcss": "^8.4.12", 199 | "postcss-loader": "^6.2.1", 200 | "prettier": "^2.6.2", 201 | "react-refresh": "^0.12.0", 202 | "react-refresh-typescript": "^2.0.4", 203 | "react-test-renderer": "^18.0.0", 204 | "rimraf": "^3.0.2", 205 | "sass": "^1.49.11", 206 | "sass-loader": "^12.6.0", 207 | "style-loader": "^3.3.1", 208 | "terser-webpack-plugin": "^5.3.1", 209 | "ts-jest": "^27.1.4", 210 | "ts-loader": "^9.2.8", 211 | "ts-node": "^10.7.0", 212 | "typescript": "^4.6.3", 213 | "url-loader": "^4.1.1", 214 | "webpack": "^5.71.0", 215 | "webpack-bundle-analyzer": "^4.5.0", 216 | "webpack-cli": "^4.9.2", 217 | "webpack-dev-server": "^4.8.0", 218 | "webpack-merge": "^5.8.0" 219 | }, 220 | "dependencies": { 221 | "electron-debug": "^3.2.0", 222 | "electron-log": "^4.4.6", 223 | "electron-updater": "^4.6.5", 224 | "glob": "^8.0.1", 225 | "glob-promise": "^4.2.2", 226 | "history": "^5.3.0", 227 | "immer": "^9.0.12", 228 | "konva": "^8.3.5", 229 | "nanoid": "^3.3.2", 230 | "projen": "^0.54.41", 231 | "react": "^18.0.0", 232 | "react-dom": "^18.0.0", 233 | "react-icons": "^4.3.1", 234 | "react-konva": "^18.0.0-0", 235 | "react-konva-utils": "^0.3.0", 236 | "react-router-dom": "^6.3.0", 237 | "tailwindcss": "^3.0.24", 238 | "zundo": "^1.5.9", 239 | "zustand": "^4.0.0-rc.0" 240 | }, 241 | "devEngines": { 242 | "node": ">=14.x", 243 | "npm": ">=7.x" 244 | }, 245 | "collective": { 246 | "url": "https://opencollective.com/electron-react-boilerplate-594" 247 | }, 248 | "browserslist": [], 249 | "prettier": { 250 | "overrides": [ 251 | { 252 | "files": [ 253 | ".prettierrc", 254 | ".eslintrc" 255 | ], 256 | "options": { 257 | "parser": "json" 258 | } 259 | } 260 | ], 261 | "singleQuote": true 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /src/renderer/state/substates/test_states/tree.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "tree-0.1", 3 | "tree": { 4 | "id": "App", 5 | "path": "", 6 | "children": { 7 | "Tree": { 8 | "id": "Tree", 9 | "path": "Tree", 10 | "constructInfo": { 11 | "fqn": "constructs.Construct", 12 | "version": "10.0.122" 13 | } 14 | }, 15 | "my-stack-dev": { 16 | "id": "my-stack-dev", 17 | "path": "my-stack-dev", 18 | "children": { 19 | "TestFunction": { 20 | "id": "TestFunction", 21 | "path": "my-stack-dev/TestFunction", 22 | "children": { 23 | "ServiceRole": { 24 | "id": "ServiceRole", 25 | "path": "my-stack-dev/TestFunction/ServiceRole", 26 | "children": { 27 | "Resource": { 28 | "id": "Resource", 29 | "path": "my-stack-dev/TestFunction/ServiceRole/Resource", 30 | "attributes": { 31 | "aws:cdk:cloudformation:type": "AWS::IAM::Role", 32 | "aws:cdk:cloudformation:props": { 33 | "assumeRolePolicyDocument": { 34 | "Statement": [ 35 | { 36 | "Action": "sts:AssumeRole", 37 | "Effect": "Allow", 38 | "Principal": { 39 | "Service": "lambda.amazonaws.com" 40 | } 41 | } 42 | ], 43 | "Version": "2012-10-17" 44 | }, 45 | "managedPolicyArns": [ 46 | { 47 | "Fn::Join": [ 48 | "", 49 | [ 50 | "arn:", 51 | { 52 | "Ref": "AWS::Partition" 53 | }, 54 | ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" 55 | ] 56 | ] 57 | } 58 | ] 59 | } 60 | }, 61 | "constructInfo": { 62 | "fqn": "aws-cdk-lib.aws_iam.CfnRole", 63 | "version": "2.21.0" 64 | } 65 | } 66 | }, 67 | "constructInfo": { 68 | "fqn": "aws-cdk-lib.aws_iam.Role", 69 | "version": "2.21.0" 70 | } 71 | }, 72 | "Code": { 73 | "id": "Code", 74 | "path": "my-stack-dev/TestFunction/Code", 75 | "children": { 76 | "Stage": { 77 | "id": "Stage", 78 | "path": "my-stack-dev/TestFunction/Code/Stage", 79 | "constructInfo": { 80 | "fqn": "aws-cdk-lib.AssetStaging", 81 | "version": "2.21.0" 82 | } 83 | }, 84 | "AssetBucket": { 85 | "id": "AssetBucket", 86 | "path": "my-stack-dev/TestFunction/Code/AssetBucket", 87 | "constructInfo": { 88 | "fqn": "aws-cdk-lib.aws_s3.BucketBase", 89 | "version": "2.21.0" 90 | } 91 | } 92 | }, 93 | "constructInfo": { 94 | "fqn": "aws-cdk-lib.aws_s3_assets.Asset", 95 | "version": "2.21.0" 96 | } 97 | }, 98 | "Resource": { 99 | "id": "Resource", 100 | "path": "my-stack-dev/TestFunction/Resource", 101 | "attributes": { 102 | "aws:cdk:cloudformation:type": "AWS::Lambda::Function", 103 | "aws:cdk:cloudformation:props": { 104 | "code": { 105 | "s3Bucket": "cdk-hnb659fds-assets-581514672367-us-east-1", 106 | "s3Key": "6f868097e41742b8ffcf168d15bec69ebc5f85f0765ba35ddaf9b8df329e37bc.zip" 107 | }, 108 | "role": { 109 | "Fn::GetAtt": [ 110 | "TestFunctionServiceRole6ABD93C7", 111 | "Arn" 112 | ] 113 | }, 114 | "description": "src/test.lambda.ts", 115 | "environment": { 116 | "variables": { 117 | "AWS_NODEJS_CONNECTION_REUSE_ENABLED": "1" 118 | } 119 | }, 120 | "handler": "index.handler", 121 | "runtime": "nodejs14.x" 122 | } 123 | }, 124 | "constructInfo": { 125 | "fqn": "aws-cdk-lib.aws_lambda.CfnFunction", 126 | "version": "2.21.0" 127 | } 128 | }, 129 | "FunctionUrl": { 130 | "id": "FunctionUrl", 131 | "path": "my-stack-dev/TestFunction/FunctionUrl", 132 | "children": { 133 | "Resource": { 134 | "id": "Resource", 135 | "path": "my-stack-dev/TestFunction/FunctionUrl/Resource", 136 | "attributes": { 137 | "aws:cdk:cloudformation:type": "AWS::Lambda::Url", 138 | "aws:cdk:cloudformation:props": { 139 | "authType": "AWS_IAM", 140 | "targetFunctionArn": { 141 | "Fn::GetAtt": [ 142 | "TestFunction22AD90FC", 143 | "Arn" 144 | ] 145 | } 146 | } 147 | }, 148 | "constructInfo": { 149 | "fqn": "aws-cdk-lib.aws_lambda.CfnUrl", 150 | "version": "2.21.0" 151 | } 152 | } 153 | }, 154 | "constructInfo": { 155 | "fqn": "aws-cdk-lib.aws_lambda.FunctionUrl", 156 | "version": "2.21.0" 157 | } 158 | } 159 | }, 160 | "constructInfo": { 161 | "fqn": "aws-cdk-lib.aws_lambda.Function", 162 | "version": "2.21.0" 163 | } 164 | }, 165 | "AssumableRole": { 166 | "id": "AssumableRole", 167 | "path": "my-stack-dev/AssumableRole", 168 | "children": { 169 | "Resource": { 170 | "id": "Resource", 171 | "path": "my-stack-dev/AssumableRole/Resource", 172 | "attributes": { 173 | "aws:cdk:cloudformation:type": "AWS::IAM::Role", 174 | "aws:cdk:cloudformation:props": { 175 | "assumeRolePolicyDocument": { 176 | "Statement": [ 177 | { 178 | "Action": "sts:AssumeRole", 179 | "Effect": "Allow", 180 | "Principal": { 181 | "AWS": { 182 | "Fn::Join": [ 183 | "", 184 | [ 185 | "arn:", 186 | { 187 | "Ref": "AWS::Partition" 188 | }, 189 | ":iam::581514672367:root" 190 | ] 191 | ] 192 | } 193 | } 194 | } 195 | ], 196 | "Version": "2012-10-17" 197 | } 198 | } 199 | }, 200 | "constructInfo": { 201 | "fqn": "aws-cdk-lib.aws_iam.CfnRole", 202 | "version": "2.21.0" 203 | } 204 | }, 205 | "DefaultPolicy": { 206 | "id": "DefaultPolicy", 207 | "path": "my-stack-dev/AssumableRole/DefaultPolicy", 208 | "children": { 209 | "Resource": { 210 | "id": "Resource", 211 | "path": "my-stack-dev/AssumableRole/DefaultPolicy/Resource", 212 | "attributes": { 213 | "aws:cdk:cloudformation:type": "AWS::IAM::Policy", 214 | "aws:cdk:cloudformation:props": { 215 | "policyDocument": { 216 | "Statement": [ 217 | { 218 | "Action": "lambda:InvokeFunctionUrl", 219 | "Effect": "Allow", 220 | "Resource": { 221 | "Fn::GetAtt": [ 222 | "TestFunction22AD90FC", 223 | "Arn" 224 | ] 225 | } 226 | } 227 | ], 228 | "Version": "2012-10-17" 229 | }, 230 | "policyName": "AssumableRoleDefaultPolicy2A55320F", 231 | "roles": [ 232 | { 233 | "Ref": "AssumableRole68D2A207" 234 | } 235 | ] 236 | } 237 | }, 238 | "constructInfo": { 239 | "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", 240 | "version": "2.21.0" 241 | } 242 | } 243 | }, 244 | "constructInfo": { 245 | "fqn": "aws-cdk-lib.aws_iam.Policy", 246 | "version": "2.21.0" 247 | } 248 | } 249 | }, 250 | "constructInfo": { 251 | "fqn": "aws-cdk-lib.aws_iam.Role", 252 | "version": "2.21.0" 253 | } 254 | }, 255 | "CDKMetadata": { 256 | "id": "CDKMetadata", 257 | "path": "my-stack-dev/CDKMetadata", 258 | "children": { 259 | "Default": { 260 | "id": "Default", 261 | "path": "my-stack-dev/CDKMetadata/Default", 262 | "constructInfo": { 263 | "fqn": "aws-cdk-lib.CfnResource", 264 | "version": "2.21.0" 265 | } 266 | } 267 | }, 268 | "constructInfo": { 269 | "fqn": "constructs.Construct", 270 | "version": "10.0.122" 271 | } 272 | } 273 | }, 274 | "constructInfo": { 275 | "fqn": "aws-cdk-lib.Stack", 276 | "version": "2.21.0" 277 | } 278 | } 279 | }, 280 | "constructInfo": { 281 | "fqn": "aws-cdk-lib.App", 282 | "version": "2.21.0" 283 | } 284 | } 285 | } -------------------------------------------------------------------------------- /src/renderer/state/substates/test_states/workbench.json: -------------------------------------------------------------------------------- 1 | { 2 | "widgets": { 3 | "kmic8SnclikItSKQqRsnZ": { 4 | "id": "MyStackThing", 5 | "scope": {}, 6 | "x": 103, 7 | "y": 96, 8 | "forType": "@aws-cdk/core.Stack", 9 | "initializerParameters": { 10 | "env": { 11 | "ref": "WIDGET#F0qnVkilE3W0XF03V-GMk", 12 | "widgetShapes": { 13 | "F0qnVkilE3W0XF03V-GMk": "LOOSE" 14 | } 15 | }, 16 | "description": { 17 | "value": "some description", 18 | "widgetShapes": {} 19 | } 20 | } 21 | }, 22 | "OZjtiRABsk5H9s3Z9A2ub": { 23 | "scope": { 24 | "id": "MyStack", 25 | "scope": {}, 26 | "x": 100, 27 | "y": 100, 28 | "forType": "@aws-cdk/core.Stack", 29 | "initializerParameters": {} 30 | }, 31 | "id": "MyInstance", 32 | "x": 547, 33 | "y": 111, 34 | "forType": "@aws-cdk/aws-ec2.Instance", 35 | "initializerParameters": { 36 | "instanceType": { 37 | "ref": "WIDGET#_UxDZLU8MoM1lrOzJA1ku", 38 | "widgetShapes": { 39 | "_UxDZLU8MoM1lrOzJA1ku": "STATIC_FUNCTION", 40 | "iYCOHHppSW2oNz5JjiJ4L": "ENUM", 41 | "DNRbfO-EUKlckIsNOAW6k": "ENUM" 42 | } 43 | }, 44 | "vpc": { 45 | "ref": "WIDGET#naP4UUEniUtn4qI7I-22D", 46 | "widgetShapes": {} 47 | }, 48 | "machineImage": { 49 | "ref": "WIDGET#CUXNG3eUC4N0gfao6AoFh", 50 | "widgetShapes": { 51 | "CUXNG3eUC4N0gfao6AoFh": "STATIC_FUNCTION", 52 | "u5lKuJOXnCuvNGXWKrH2t": "LOOSE", 53 | "au5i7a7VnRgFQdxTI0IM0": "ENUM" 54 | } 55 | } 56 | } 57 | }, 58 | "_UxDZLU8MoM1lrOzJA1ku": { 59 | "id": "", 60 | "x": 1031, 61 | "y": 165, 62 | "isDragging": false, 63 | "forType": "@aws-cdk/aws-ec2.InstanceType", 64 | "type": "staticFunction", 65 | "method": { 66 | "docs": { 67 | "remarks": "This class takes a combination of a class and size.\n\nBe aware that not all combinations of class and size are available, and not all\nclasses are available in all regions.", 68 | "stability": "stable", 69 | "summary": "Instance type for EC2 instances." 70 | }, 71 | "locationInModule": { 72 | "filename": "lib/instance-types.ts", 73 | "line": 765 74 | }, 75 | "name": "of", 76 | "parameters": [ 77 | { 78 | "name": "instanceClass", 79 | "type": { 80 | "fqn": "@aws-cdk/aws-ec2.InstanceClass" 81 | } 82 | }, 83 | { 84 | "name": "instanceSize", 85 | "type": { 86 | "fqn": "@aws-cdk/aws-ec2.InstanceSize" 87 | } 88 | } 89 | ], 90 | "returns": { 91 | "type": { 92 | "fqn": "@aws-cdk/aws-ec2.InstanceType" 93 | } 94 | }, 95 | "static": true 96 | }, 97 | "parameters": { 98 | "instanceClass": { 99 | "ref": "WIDGET#iYCOHHppSW2oNz5JjiJ4L", 100 | "widgetShapes": { 101 | "iYCOHHppSW2oNz5JjiJ4L": "ENUM" 102 | } 103 | }, 104 | "instanceSize": { 105 | "ref": "WIDGET#DNRbfO-EUKlckIsNOAW6k", 106 | "widgetShapes": { 107 | "DNRbfO-EUKlckIsNOAW6k": "ENUM" 108 | } 109 | } 110 | }, 111 | "scope": { 112 | "id": "MyStack", 113 | "scope": {}, 114 | "x": 100, 115 | "y": 100, 116 | "forType": "@aws-cdk/core.Stack", 117 | "initializerParameters": {} 118 | }, 119 | "zipped": 1 120 | }, 121 | "iYCOHHppSW2oNz5JjiJ4L": { 122 | "id": "STANDARD3", 123 | "x": 1460, 124 | "y": 180, 125 | "isDragging": false, 126 | "forType": "@aws-cdk/aws-ec2.InstanceClass", 127 | "type": "enum", 128 | "method": { 129 | "docs": { 130 | "stability": "stable", 131 | "summary": "Standard instances, 3rd generation." 132 | }, 133 | "name": "STANDARD3" 134 | }, 135 | "scope": { 136 | "id": "MyStack", 137 | "scope": {}, 138 | "x": 100, 139 | "y": 100, 140 | "forType": "@aws-cdk/core.Stack", 141 | "initializerParameters": {} 142 | }, 143 | "zipped": 2 144 | }, 145 | "DNRbfO-EUKlckIsNOAW6k": { 146 | "id": "NANO", 147 | "x": 1476, 148 | "y": 240, 149 | "isDragging": false, 150 | "forType": "@aws-cdk/aws-ec2.InstanceSize", 151 | "type": "enum", 152 | "method": { 153 | "docs": { 154 | "stability": "stable", 155 | "summary": "Instance size NANO (nano)." 156 | }, 157 | "name": "NANO" 158 | }, 159 | "scope": { 160 | "id": "MyStack", 161 | "scope": {}, 162 | "x": 100, 163 | "y": 100, 164 | "forType": "@aws-cdk/core.Stack", 165 | "initializerParameters": {} 166 | }, 167 | "zipped": 2 168 | }, 169 | "naP4UUEniUtn4qI7I-22D": { 170 | "id": "", 171 | "x": 976.376383069125, 172 | "y": 103.21540821733007, 173 | "isDragging": false, 174 | "forType": "@aws-cdk/aws-ec2.Vpc", 175 | "type": "staticFunction", 176 | "method": { 177 | "docs": { 178 | "remarks": "This function only needs to be used to use VPCs not defined in your CDK\napplication. If you are looking to share a VPC between stacks, you can\npass the `Vpc` object between stacks and use it as normal.\n\nCalling this method will lead to a lookup when the CDK CLI is executed.\nYou can therefore not use any values that will only be available at\nCloudFormation execution time (i.e., Tokens).\n\nThe VPC information will be cached in `cdk.context.json` and the same VPC\nwill be used on future runs. To refresh the lookup, you will have to\nevict the value from the cache using the `cdk context` command. See\nhttps://docs.aws.amazon.com/cdk/latest/guide/context.html for more information.", 179 | "stability": "stable", 180 | "summary": "Import an existing VPC from by querying the AWS environment this stack is deployed to." 181 | }, 182 | "locationInModule": { 183 | "filename": "lib/vpc.ts", 184 | "line": 1122 185 | }, 186 | "name": "fromLookup", 187 | "parameters": [ 188 | { 189 | "name": "scope", 190 | "type": { 191 | "fqn": "constructs.Construct" 192 | } 193 | }, 194 | { 195 | "name": "id", 196 | "type": { 197 | "primitive": "string" 198 | } 199 | }, 200 | { 201 | "name": "options", 202 | "type": { 203 | "fqn": "@aws-cdk/aws-ec2.VpcLookupOptions" 204 | } 205 | } 206 | ], 207 | "returns": { 208 | "type": { 209 | "fqn": "@aws-cdk/aws-ec2.IVpc" 210 | } 211 | }, 212 | "static": true 213 | }, 214 | "parameters": { 215 | "id": { 216 | "value": "primaryVpc", 217 | "widgetShapes": {} 218 | }, 219 | "options": { 220 | "ref": "WIDGET#9viOTBZmqJVJMlPxKAqGn", 221 | "widgetShapes": { 222 | "9viOTBZmqJVJMlPxKAqGn": "LOOSE" 223 | } 224 | } 225 | }, 226 | "scope": { 227 | "id": "MyStack", 228 | "scope": {}, 229 | "x": 100, 230 | "y": 100, 231 | "forType": "@aws-cdk/core.Stack", 232 | "initializerParameters": {} 233 | } 234 | }, 235 | "9viOTBZmqJVJMlPxKAqGn": { 236 | "id": "MyVpcLookupOptions", 237 | "x": 1002, 238 | "y": 261, 239 | "isDragging": false, 240 | "forType": "@aws-cdk/aws-ec2.VpcLookupOptions", 241 | "initializerParameters": { 242 | "isDefault": { 243 | "value": true, 244 | "widgetShapes": {} 245 | }, 246 | "region": { 247 | "value": "sdfasdasd", 248 | "widgetShapes": {} 249 | } 250 | }, 251 | "scope": { 252 | "id": "MyStack", 253 | "scope": {}, 254 | "x": 100, 255 | "y": 100, 256 | "forType": "@aws-cdk/core.Stack", 257 | "initializerParameters": {} 258 | }, 259 | "zipped": 1 260 | }, 261 | "CUXNG3eUC4N0gfao6AoFh": { 262 | "id": "", 263 | "x": 1073, 264 | "y": 272, 265 | "isDragging": false, 266 | "forType": "@aws-cdk/aws-ec2.MachineImage", 267 | "type": "staticFunction", 268 | "method": { 269 | "docs": { 270 | "remarks": "This Machine Image automatically updates to the latest version on every\ndeployment. Be aware this will cause your instances to be replaced when a\nnew version of the image becomes available. Do not store stateful information\non the instance if you are using this image.", 271 | "stability": "stable", 272 | "summary": "An Amazon Linux image that is automatically kept up-to-date." 273 | }, 274 | "locationInModule": { 275 | "filename": "lib/machine-image.ts", 276 | "line": 46 277 | }, 278 | "name": "latestAmazonLinux", 279 | "parameters": [ 280 | { 281 | "name": "props", 282 | "optional": true, 283 | "type": { 284 | "fqn": "@aws-cdk/aws-ec2.AmazonLinuxImageProps" 285 | } 286 | } 287 | ], 288 | "returns": { 289 | "type": { 290 | "fqn": "@aws-cdk/aws-ec2.IMachineImage" 291 | } 292 | }, 293 | "static": true 294 | }, 295 | "parameters": { 296 | "props": { 297 | "ref": "WIDGET#u5lKuJOXnCuvNGXWKrH2t", 298 | "widgetShapes": { 299 | "u5lKuJOXnCuvNGXWKrH2t": "LOOSE", 300 | "au5i7a7VnRgFQdxTI0IM0": "ENUM" 301 | } 302 | } 303 | }, 304 | "scope": { 305 | "id": "MyStack", 306 | "scope": {}, 307 | "x": 100, 308 | "y": 100, 309 | "forType": "@aws-cdk/core.Stack", 310 | "initializerParameters": {} 311 | }, 312 | "zipped": 1 313 | }, 314 | "u5lKuJOXnCuvNGXWKrH2t": { 315 | "id": "MyAmazonLinuxImageProps", 316 | "x": 1536, 317 | "y": 282, 318 | "isDragging": false, 319 | "forType": "@aws-cdk/aws-ec2.AmazonLinuxImageProps", 320 | "initializerParameters": { 321 | "cpuType": { 322 | "ref": "WIDGET#au5i7a7VnRgFQdxTI0IM0", 323 | "widgetShapes": { 324 | "au5i7a7VnRgFQdxTI0IM0": "ENUM" 325 | } 326 | } 327 | }, 328 | "scope": { 329 | "id": "MyStack", 330 | "scope": {}, 331 | "x": 100, 332 | "y": 100, 333 | "forType": "@aws-cdk/core.Stack", 334 | "initializerParameters": {} 335 | }, 336 | "zipped": 2 337 | }, 338 | "au5i7a7VnRgFQdxTI0IM0": { 339 | "id": "X86_64", 340 | "x": 1908, 341 | "y": 216, 342 | "isDragging": false, 343 | "forType": "@aws-cdk/aws-ec2.AmazonLinuxCpuType", 344 | "type": "enum", 345 | "method": { 346 | "docs": { 347 | "stability": "stable", 348 | "summary": "x86_64 CPU type." 349 | }, 350 | "name": "X86_64" 351 | }, 352 | "scope": { 353 | "id": "MyStack", 354 | "scope": {}, 355 | "x": 100, 356 | "y": 100, 357 | "forType": "@aws-cdk/core.Stack", 358 | "initializerParameters": {} 359 | }, 360 | "zipped": 3 361 | }, 362 | "F0qnVkilE3W0XF03V-GMk": { 363 | "id": "MyEnvironment", 364 | "x": 530, 365 | "y": 227, 366 | "isDragging": false, 367 | "forType": "@aws-cdk/core.Environment", 368 | "initializerParameters": { 369 | "account": { 370 | "value": "0123456689", 371 | "widgetShapes": {} 372 | }, 373 | "region": { 374 | "value": "us-east-1", 375 | "widgetShapes": {} 376 | } 377 | }, 378 | "scope": {}, 379 | "zipped": 1 380 | } 381 | } 382 | } 383 | -------------------------------------------------------------------------------- /.erb/img/erb-banner.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | --------------------------------------------------------------------------------