Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Dec 22, 2020
1 parent b051abf commit dfd3ba0
Show file tree
Hide file tree
Showing 21 changed files with 3,140 additions and 113 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"graphql": "^15.4.0",
"hoofd": "^1.0.2",
"keez": "^1.0.1",
"monaco-textmate": "^3.0.1",
"onigasm": "^2.2.5",
"path": "npm:path-browserify",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-error-boundary": "^3.1.0",
"react-split-grid": "^1.0.3",
"recoil": "^0.1.2",
"use-monaco": "^0.0.29"
"use-monaco": "file:.yalc/use-monaco"
},
"peerDependencies": {
"graphql": "*",
Expand Down Expand Up @@ -60,6 +63,7 @@
"@prefresh/vite": "^1.2.2",
"@types/node": "^14.14.13",
"bundlesize": "^0.18.0",
"monaco-vscode-textmate-theme-converter": "^0.1.1",
"next": "^10.0.3",
"pluralize": "^8.0.0",
"preact": "^10.5.7",
Expand All @@ -74,6 +78,9 @@
"vite-plugin-react": "^4.0.1",
"xss": "^1.0.8"
},
"browser": {
"path": "path-browserify"
},
"scripts": {
"dev": "vite",
"build": "sucrase-node scripts/build.ts",
Expand Down
Empty file added scripts/interfaces.ts
Empty file.
72 changes: 39 additions & 33 deletions src/Browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import { QueryEditor } from "./panels/QueryEditor";
import { PanelConfigProvider, Panels } from "./components/Panels";
import { Tabs } from "./components/Tabs";
import { styled } from "./lib/styles";
import { GraphQLMonacoProvider } from "./GraphQLMonacoProvider";
import { GraphQLMonacoProvider, ThemeProvider } from "./MonacoProvider";
import * as icons from "./components/Icons";
import { EditorPanel } from "./components/EditorPanel";
import { useAtom } from "./lib/browser";

export const DEFAULT_PANELS = {
query: {
render: QueryEditor,
Expand Down Expand Up @@ -83,45 +84,50 @@ export function BrowserProvider({
children,
}) {
return (
<GraphQLMonacoProvider initialSchemaConfig={initialSchemaConfig}>
<RecoilRoot
initializeState={(snapshot) => {
snapshot.set(fs.persistedFiles, { "/browser.json": true });
const currentTab = snapshot.getLoadable(browser.currentTab)
.contents as string;
<ThemeProvider mode={"dark"}>
<GraphQLMonacoProvider initialSchemaConfig={initialSchemaConfig}>
<RecoilRoot
initializeState={(snapshot) => {
snapshot.set(fs.persistedFiles, { "/browser.json": true });
const currentTab = snapshot.getLoadable(browser.currentTab)
.contents as string;

const oldConfig = snapshot.getLoadable(
browser.getTabSchemaConfig(currentTab)
).contents;
const oldConfig = snapshot.getLoadable(
browser.getTabSchemaConfig(currentTab)
).contents;

if (schemaConfig) {
snapshot.set(browser.getTabSchemaConfig(currentTab), schemaConfig);
} else if (
initialSchemaConfig &&
!(oldConfig as SchemaConfig)?.uri?.length
) {
snapshot.set(
browser.getTabSchemaConfig(currentTab),
initialSchemaConfig
);
}
if (schemaConfig) {
snapshot.set(
browser.getTabSchemaConfig(currentTab),
schemaConfig
);
} else if (
initialSchemaConfig &&
!(oldConfig as SchemaConfig)?.uri?.length
) {
snapshot.set(
browser.getTabSchemaConfig(currentTab),
initialSchemaConfig
);
}

initializeState?.(snapshot, browser);
}}
>
<PanelConfigProvider panels={panels}>
<fs.Persist />
{children}
</PanelConfigProvider>
</RecoilRoot>
</GraphQLMonacoProvider>
initializeState?.(snapshot, browser);
}}
>
<PanelConfigProvider panels={panels}>
<fs.Persist />
{children}
</PanelConfigProvider>
</RecoilRoot>
</GraphQLMonacoProvider>
</ThemeProvider>
);
}

export const tabBreakpoints = [3, 5, 7, 9];

const Background = styled.div`h-screen w-screen pt-1 gap-2 bg-blueGray-300 w-full flex flex-col`;
const PanelWindow = styled.div`flex-1 w-full px-2 pb-3 flex flex-row overflow-hidden`;
const Background = styled.div`h-screen w-screen pt-1 gap-1 bg-blueGray-300 w-full flex flex-col`;
const PanelWindow = styled.div`flex-1 w-full px-1 pb-1 flex flex-row overflow-hidden`;

export function Browser({
initializeState,
Expand All @@ -140,7 +146,7 @@ export function Browser({
panels={DEFAULT_PANELS}
>
<Background>
<div className={bw`px-2 relative`}>
<div className={bw`px-1 relative`}>
<Tabs />
<Toolbar />
</div>
Expand Down
41 changes: 0 additions & 41 deletions src/GraphQLMonacoProvider.tsx

This file was deleted.

151 changes: 151 additions & 0 deletions src/MonacoProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import React from "react";
import { MonacoProvider } from "use-monaco";
import allThemes from "use-monaco/themes";
import { lightTheme, darkTheme } from "./lib/monaco.theme";
import * as graphqlLanguageConfig from "./lib/graphql.config";
import createContext from "create-hook-context";
import { darkBG, colors } from "./lib/colors";
import { setup } from "@beamwind/play";
import sand from "./themes/vscode-theme";
import type * as monacoApi from "monaco-editor";

export const [ThemeProvider, useTheme] = createContext(
({ mode = "light" as "light" | "dark" }: { mode: string }) => {
const [state, setState] = React.useState({ mode });

React.useEffect(() => {
if (state.mode === "light") {
setup({
theme: {
extend: {
colors: {
blueGray: colors["blueGray"],
},
},
},
});
} else {
console.log("hereee");
setup({
theme: {
extend: {
colors: {
blueGray: darkBG,
},
},
},
});
}
}, [state.mode]);

return [state, setState] as const;
}
);

import { loadWASM } from "onigasm"; // peer dependency of 'monaco-textmate'
import { Registry } from "monaco-textmate"; // peer dependency
import { wireTmGrammars } from "./themes";
import graphQLTMLang from "./graphql.tmlanguage.json";
import jsonTMLang from "./json.tmlanguage.json";
import { convertTheme } from "./themes/theme-convertor";

export async function textMatePlugin(monaco: typeof monacoApi) {
await loadWASM("../node_modules/onigasm/lib/onigasm.wasm"); // See https://www.npmjs.com/package/onigasm#light-it-up
const languageRepo = {
"source.graphql": {
format: "json",
content: JSON.stringify(graphQLTMLang, null, 2),
},
"source.json.comments": {
format: "json",
content: JSON.stringify(jsonTMLang, null, 2),
},
};

// map of monaco "language id's" to TextMate scopeNames
const grammars = new Map();

const registry = new Registry({
getGrammarDefinition: async (scopeName) => {
return (
languageRepo[scopeName] ?? {
format: "json",
content: JSON.stringify(jsonTMLang, null, 2),
}
);
},
});

grammars.set("graphql", "source.graphql");
grammars.set("json", "source.json.comments");

return monaco.editor.onCreatedEditor(async (editor) => {
try {
await wireTmGrammars(monaco, registry, grammars, editor);
} catch (e) {
console.error(e);
}
});
}

const converted = convertTheme(sand as any);
console.log(converted);
export function GraphQLMonacoProvider({ initialSchemaConfig, children }) {
const [theme, setTheme] = useTheme();

return (
<MonacoProvider
paths={{
monaco: "https://unpkg.com/monaco-editor-core/min/vs",
// monaco: "https://unpkg.com/@nksaraf/monaco-editor@0.21.2/min/vs/",
}}
theme={
// converted
lightTheme
// theme.mode === "light"
// ? lightTheme
// : ({
// ...darkTheme,
// colors: {
// ...darkTheme["colors"],
// "editor.background": darkBG["50"],
// },
// } as any)
}
plugins={{
json: (monaco) => {
monaco.languages.register({
id: "json",
extensions: [".json"],
});
},
prettier: ["graphql", "json"],
textmate: textMatePlugin,
"magiql-ide": async (monaco) => {
return monaco.languages.register({
id: "graphql",
worker: {
label: "graphql",
options: {
languageConfig: {
schemaConfig: initialSchemaConfig,
},
},
src: monaco.worker.baseWorkerPath + "graphql.monaco.worker.js",
providers: {
hover: true,
completionItem: true,
diagnostics: true,
},
},
extensions: [".graphql", ".gql"],
aliases: ["graphql"],
mimetypes: ["application/graphql", "text/graphql"],
});
},
}}
>
{children}
</MonacoProvider>
);
}
2 changes: 1 addition & 1 deletion src/ast/componnents/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function useUpdateCollection({ node, key }) {

Variable.displayName = "Variable";

export const tooltip = `bg-gray-700 text-white border-none rounded-md shadow-lg font-graphql`;
export const tooltip = `bg-gray-700 text-blueGray-50 border-none rounded-md shadow-lg font-graphql`;

export const withTooltip = (description, children) =>
description ? (
Expand Down
2 changes: 1 addition & 1 deletion src/ast/tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function Checkbox(props: any) {
{...props}
className={`${bw`w-3 h-3 rounded-sm ${
props.checked
? "text-white bg-blue-400 group-hover:(text-white bg-blue-200)"
? "text-blueGray-50 bg-blue-400 group-hover:(text-blueGray-50 bg-blue-200)"
: "text-blueGray-300 bg-blueGray-300 group-hover:(text-blueGray-600)"
}`} ${props.className ?? ""}`}
>
Expand Down
17 changes: 14 additions & 3 deletions src/components/PanelMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { usePanel, usePanelConfig } from "./Panels";
import * as browser from "../lib/browser";
import { AnimatePresence, motion } from "framer-motion";

export const menu = `relative px-0.5 py-1 bg-white border-white border-1 rounded-md shadow-2xl`;
export const menu = `relative px-0.5 py-1 bg-blueGray-50 border-blueGray-50 border-1 rounded-md shadow-2xl`;

const renderers = {
context: ContextMenu,
Expand Down Expand Up @@ -71,10 +71,18 @@ export function PanelMenu({
className={bw`${menuItem} items-center`}
>
<Menu.ItemIndicator
className={bw`absolute left-2 translate-y-0.5 group-hover:(text-white) text-blue-500 `}
className={bw`absolute left-2 translate-y-0.5 group-hover:(text-blueGray-50) text-blue-500 `}
>
<Check className={bw`w-3.5 h-3.5`} />
</Menu.ItemIndicator>
{!(panelName === panel.id) &&
panels.find((p) => p.find((i) => i === panelName)) && (
<div
className={bw`absolute left-2 translate-y-0.5 group-hover:(text-blueGray-50) text-blue-500 `}
>
<Check className={bw`w-3.5 h-3.5`} />
</div>
)}
<div
className={bw`flex font-graphql flex-row gap-2 items-center`}
>
Expand All @@ -93,4 +101,7 @@ export function PanelMenu({
);
}

export const menuItem = `cursor-pointer select-none group w-48 px-1 pl-8 py-1 font-graphql rounded-sm text-sm border-none text-blueGray-500 hover:(outline-none bg-blue-500 text-white)`;
export const menuItem = `cursor-pointer
select-none group w-48 px-1 pl-8 py-1 font-graphql
rounded-sm text-sm border-none text-blueGray-500
hover:(outline-none bg-blue-500 text-blueGray-50)`;

0 comments on commit dfd3ba0

Please sign in to comment.