Skip to content

Commit

Permalink
Merge branch 'reorder-variadic-ports' of https://github.com/tokens-st…
Browse files Browse the repository at this point in the history
…udio/graph-engine into reorder-variadic-ports
  • Loading branch information
roppazvan committed Jun 11, 2024
2 parents 319bb6d + 7b35267 commit 491f40e
Show file tree
Hide file tree
Showing 66 changed files with 496 additions and 433 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ['custom'],
// This tells ESLint to load the config from the package `@tokens-studio/eslint-custom-config`
extends: ['@tokens-studio/eslint-custom-config'],
settings: {
next: {
rootDir: ['packages/*/']
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: "yarn"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: "yarn"

- name: Install dependencies
Expand Down
45 changes: 38 additions & 7 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
name: Verify changes
name: CI

on: pull_request

env:
HUSKY: 0
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_TELEMETRY_DISABLED: 1
DO_NOT_TRACK: 1

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
verify:
name: Verify changes
Expand All @@ -15,14 +26,34 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: "yarn"

- name: Install turbo
run: yarn global add turbo@1.9.8

- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v3
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.head_ref }}-${{ github.sha }}
restore-keys: |
turbo-${{ github.job }}-${{ github.head_ref }}-
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn --frozen-lockfile --prefer-offline
run: yarn --frozen-lockfile --immutable

- name: Lint
run: npm run lint

- name: Test
run: npm run test:ci
run: yarn run test
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
progress=false
strict-peer-deps=false
legacy-peer-deps=true
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"eslint.options": {
"extensions": [
".js",
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"dev:ui:live": "turbo run dev --filter=@tokens-studio/graph-engine-ui...",
"docs": "turbo run docs",
"format": "turbo run format --parallel --continue",
"postinstall": "husky install",
"lint": "turbo run lint",
"lint-staged": "npx lint-staged",
"prepare": "husky install",
Expand All @@ -44,8 +43,6 @@
},
"dependencies": {},
"devDependencies": {
"eslint": "^8.30.0",
"eslint-config-custom": "*",
"husky": "^8.0.3",
"lint-staged": "^13.2.1",
"listr2": "5.0.8",
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable no-undef */
/** @type {import("eslint").Linter.Config} */

module.exports = {
root:true,
extends: ["custom"],
extends: [require.resolve('@tokens-studio/eslint-custom-config/index.js')]
};
5 changes: 1 addition & 4 deletions packages/backend/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export default {
// Yes it should be an array to ensure consistency, but jest does not offer this
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/tests/__mocks__/file-mock.js",
".+\\.(css|less|scss|sass|styl)$": "identity-obj-proxy",
...pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: "<rootDir>/",
}),
".+\\.(css|less|scss|sass|styl)$": "identity-obj-proxy"
},
transform: {
"^.+\\.(js|jsx)$": "babel-jest",
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"release": "npm run build && changeset publish",
"test": "jest"
"test": "jest --passWithNoTests"
},
"sideEffects": true,
"types": "./dist/esm/index.d.ts",
Expand Down Expand Up @@ -63,6 +63,7 @@
"@types/node": "^20.12.7",
"@types/swagger-ui-express": "^4.1.6",
"nodemon": "^3.1.0",
"eslint": "8.57.0",
"prisma": "^5.13.0",
"supertest": "^6.3.4",
"tsup": "^8.0.2",
Expand All @@ -76,4 +77,4 @@
"backend"
],
"jsnext:main": "./dist/esm/index.js"
}
}
21 changes: 20 additions & 1 deletion packages/eslint-config-custom/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const { resolve } = require("node:path");
const project = resolve(process.cwd(), "tsconfig.json");



// Eslint does not support module exports, so we need to use CommonJS syntax
// eslint-disable-next-line no-undef


/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [
"eslint:recommended",
Expand All @@ -9,6 +16,18 @@ module.exports = {
],
parser: "@typescript-eslint/parser",
plugins: ["sort-imports-es6-autofix", "jest", "@typescript-eslint"],
settings: {
"import/resolver": {
typescript: {
project,
},
},
},
overrides: [
{
files: ["*.js?(x)", "*.ts?(x)"],
},
],
rules: {
"react/jsx-key": "off",
//If we do this, it must be a good reason
Expand Down
12 changes: 7 additions & 5 deletions packages/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"private": true,
"name": "@tokens-studio/eslint-config-custom",
"name": "@tokens-studio/eslint-custom-config",
"version": "0.0.0",
"license": "MIT",
"main": "index.js",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "8.30.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.1.0",
"eslint-config-prettier": "8.8.0",
"eslint-config-turbo": "latest",
"eslint-import-resolver-typescript": "3.5.5",
Expand All @@ -19,9 +18,12 @@
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"eslint-plugin-turbo": "^1.9.3"
},
"files": [
"index.js"
],
"devDependencies": {
"react": "18.2",
"react-dom": "18.2",
"typescript": "4.8.4"
}
}
}
2 changes: 1 addition & 1 deletion packages/graph-editor/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
root:true,
extends: ["custom"],
extends: ['@tokens-studio/eslint-custom-config'],
};
1 change: 1 addition & 0 deletions packages/graph-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"esbuild-sass-plugin": "^3.2.0",
"prettier": "2.8.7",
"resp": "^0.1.1",
"eslint": "8.57.0",
"storybook": "^8.0.9",
"tsup": "^7.2.0",
"typescript": "^5.4.5",
Expand Down
18 changes: 14 additions & 4 deletions packages/graph-editor/src/components/commandPalette/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NodeTypes } from '@tokens-studio/graph-engine';
import { styled } from '@/lib/stitches';
import { Search } from 'iconoir-react';
import { observer } from 'mobx-react-lite';
import { isActiveElementTextEditable } from '@/utils/isActiveElementTextEditable.js';

export interface ICommandMenu {
reactFlowWrapper: React.MutableRefObject<HTMLDivElement | null>;
Expand Down Expand Up @@ -107,10 +108,10 @@ const CommandMenu = ({
return () => document.removeEventListener('mousemove', move);
}, [wrapperBounds]);

// Toggle the menu when K is pressed
// Toggle the menu when shift + K is pressed
React.useEffect(() => {
const down = (e) => {
if (e.key === 'K' && e.shiftKey) {
const down = (e) => {
if (e.key === 'K' && e.shiftKey && !isActiveElementTextEditable()) {
e.preventDefault();

dispatch.ui.setNodeInsertPosition(cursorPositionRef.current);
Expand All @@ -122,6 +123,15 @@ const CommandMenu = ({
return () => document.removeEventListener('keydown', down);
}, [dispatch.ui, showNodesCmdPalette]);

// Close the menu when Escape key is pressed inside the input
const handleKeyDown = (e) => {
if (e.key === 'Escape') {
e.preventDefault();

dispatch.ui.setShowNodesCmdPalette(false);
}
}

return (
<Command.Dialog
open={showNodesCmdPalette}
Expand All @@ -143,7 +153,7 @@ const CommandMenu = ({
}}
>
<Search />
<Command.Input placeholder="Find nodes to add…" />
<Command.Input placeholder="Find nodes to add…" onKeyDown={handleKeyDown} />
</Box>
<Command.List>
<Command.Empty>
Expand Down
15 changes: 9 additions & 6 deletions packages/graph-editor/src/editor/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { GraphContextProvider } from '@/context/graph.js';
import { SelectionContextMenu } from '@/components/contextMenus/selectionContextMenu.js';
import { ActionProvider } from './actions/provider.js';
import { HotKeys } from '@/components/hotKeys/index.js';
import { currentPanelIdSelector } from '@/redux/selectors/graph.js';

const snapGridCoords: SnapGrid = [16, 16];
const defaultViewport = { x: 0, y: 0, zoom: 1.5 };
Expand Down Expand Up @@ -113,6 +114,7 @@ export const EditorApp = React.forwardRef<ImperativeEditorRef, GraphEditorProps>
const showGridValue = useSelector(showGrid);
const snapGridValue = useSelector(snapGrid);
const internalRef = useRef<ImperativeEditorRef>(null);
const activeGraphId = useSelector(currentPanelIdSelector);

const refProxy = useCallback((v) => {
//@ts-ignore
Expand Down Expand Up @@ -764,12 +766,13 @@ export const EditorApp = React.forwardRef<ImperativeEditorRef, GraphEditorProps>
/>
)}
{nodeCount === 0 && props.emptyContent}

<CommandMenu
reactFlowWrapper={reactFlowWrapper}
items={panelItems}
handleSelectNewNodeType={handleSelectNewNodeType}
/>
{activeGraphId === id && (
<CommandMenu
reactFlowWrapper={reactFlowWrapper}
items={panelItems}
handleSelectNewNodeType={handleSelectNewNodeType}
/>
)}
{props.children}
</ReactFlow>
</HotKeys>
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-editor/src/redux/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const settingsState = createModel<RootModel>()({
inlineTypes: false,
snapGrid: false,
debugMode: false,
showMinimap:true,
showMinimap: false,
delayedUpdate: false
} as SettingsState,
reducers: {
Expand Down
5 changes: 5 additions & 0 deletions packages/graph-editor/src/redux/selectors/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ export const graphEditorSelector = createSelector(
graph,
(state) => state.currentPanel?.ref
);

export const currentPanelIdSelector = createSelector(
graph,
(state) => state.currentPanelId
);
12 changes: 12 additions & 0 deletions packages/graph-editor/src/utils/isActiveElementTextEditable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const isActiveElementTextEditable = () => {
const activeElement = document.activeElement as HTMLElement;

if (!activeElement) {
return false;
}

const tagName = activeElement.tagName.toLowerCase();
const isContentEditable = activeElement.isContentEditable;

return ['input', 'textarea'].includes(tagName) || isContentEditable;
}
2 changes: 1 addition & 1 deletion packages/graph-editor/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineConfig({
bundle: true,
splitting: true,
sourcemap: env === 'production', // source map is only available in prod
format: env === 'production' ? ['cjs', 'esm'] : ['esm'],
format: ['cjs', 'esm'] ,
skipNodeModulesBundle: true,
clean: false,
esbuildPlugins: [sassPlugin()]
Expand Down
5 changes: 4 additions & 1 deletion packages/graph-engine/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable no-undef */
/** @type {import("eslint").Linter.Config} */

module.exports = {
root:true,
extends: ["custom"],
extends: [require.resolve('@tokens-studio/eslint-custom-config/index.js')]
};
Loading

0 comments on commit 491f40e

Please sign in to comment.