Skip to content

Commit

Permalink
prefer localStorage over window.localStorage (graphql#3646)
Browse files Browse the repository at this point in the history
add `packageManager` field in `package.json` (graphql#3654)

[graphiql] add `className` prop. Additional class names which will be appended to the GraphiQL container element (graphql#3643)

disable shrinking while changing the operation name

Update packages/graphiql-react/src/ui/tabs.css

Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>
  • Loading branch information
dimaMachina and TallTed committed Jul 24, 2024
1 parent 2583302 commit 8e81102
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 134 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-beers-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"graphiql": minor
---

add `className` prop. Additional class names which will be appended to the GraphiQL container element
5 changes: 5 additions & 0 deletions .changeset/light-geckos-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphiql/toolkit": patch
---

prefer `localStorage` over `window.localStorage`
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ module.exports = {
'no-octal-escape': 'error',
'no-param-reassign': 'error',
'no-proto': 'error',
'no-restricted-properties': 'off',
'no-restricted-properties': [
'error',
{
object: 'window',
property: 'localStorage',
message: 'Use `localStorage` instead',
},
],
'no-return-assign': 'error',
'no-return-await': 'error',
'no-script-url': 'error',
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
"pre-commit": "lint-staged"
}
},
"engines": {
"npm": "please_use_yarn_instead"
},
"packageManager": "yarn@1.22.22",
"scripts": {
"build": "yarn build-clean && yarn tsc && yarn build:nontsc",
"build-bundles": "yarn prebuild-bundles && yarn wsrun:noexamples --stages build-bundles",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"codemirror": "^5.65.3",
"codemirror-graphql": "^2.0.12",
"copy-to-clipboard": "^3.2.0",
"framer-motion": "^6.5.1",
"framer-motion": "^11.0.0",
"graphql-language-service": "^5.2.1",
"markdown-it": "^14.1.0",
"set-value": "^4.1.0"
Expand Down
7 changes: 6 additions & 1 deletion packages/graphiql-react/src/ui/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gap: var(--px-8);
padding: var(--px-8) 0;
margin: 0 var(--px-8)
/* when using padding while scrolling tab items will overflow to padding area */;
/* when using padding while scrolling, tab items will overflow to padding area */;
overflow-x: auto;
list-style: none;
}
Expand All @@ -17,6 +17,11 @@
.graphiql-tab {
background: hsla(var(--color-neutral), var(--alpha-background-light));

/* disable shrinking while changing the operation name */
&:not(:focus-within) {
transform: none !important;
}

.graphiql-tab-wrapper {
position: relative;
display: flex;
Expand Down
12 changes: 6 additions & 6 deletions packages/graphiql-toolkit/src/storage/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export class StorageAPI {
this.storage = null;
} else {
this.storage = {
getItem: window.localStorage.getItem.bind(window.localStorage),
setItem: window.localStorage.setItem.bind(window.localStorage),
removeItem: window.localStorage.removeItem.bind(window.localStorage),
getItem: localStorage.getItem.bind(localStorage),
setItem: localStorage.setItem.bind(localStorage),
removeItem: localStorage.removeItem.bind(localStorage),

get length() {
let keys = 0;
for (const key in window.localStorage) {
for (const key in localStorage) {
if (key.indexOf(`${STORAGE_NAMESPACE}:`) === 0) {
keys += 1;
}
Expand All @@ -80,9 +80,9 @@ export class StorageAPI {

clear() {
// We only want to clear the namespaced items
for (const key in window.localStorage) {
for (const key in localStorage) {
if (key.indexOf(`${STORAGE_NAMESPACE}:`) === 0) {
window.localStorage.removeItem(key);
localStorage.removeItem(key);
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/graphiql-toolkit/src/storage/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createLocalStorage({
removeItem: key => localStorage.removeItem(getStorageKey(key)),
get length() {
let keys = 0;
for (const key in window.localStorage) {
for (const key in localStorage) {
if (key.indexOf(storageKeyPrefix) === 0) {
keys += 1;
}
Expand All @@ -35,9 +35,9 @@ export function createLocalStorage({

clear() {
// We only want to clear the namespaced items
for (const key in window.localStorage) {
for (const key in localStorage) {
if (key.indexOf(storageKeyPrefix) === 0) {
window.localStorage.removeItem(key);
localStorage.removeItem(key);
}
}
},
Expand Down
11 changes: 10 additions & 1 deletion packages/graphiql/src/components/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ export type GraphiQLInterfaceProps = WriteableEditorProps &
* rendered with a specific theme
*/
forcedTheme?: (typeof THEMES)[number];
/**
* Additional class names which will be appended to the container element.
*/
className?: string;
};

const THEMES = ['light', 'dark', 'system'] as const;
Expand Down Expand Up @@ -454,9 +458,14 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {

const hasMultipleTabs = editorContext.tabs.length > 1;

const className = props.className ? ` ${props.className}` : '';

return (
<Tooltip.Provider>
<div data-testid="graphiql-container" className="graphiql-container">
<div
data-testid="graphiql-container"
className={`graphiql-container${className}`}
>
<div className="graphiql-sidebar">
<div className="graphiql-sidebar-section">
{pluginContext?.plugins.map((plugin, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const simpleIntrospection = {
};

beforeEach(() => {
window.localStorage.clear();
localStorage.clear();
});

describe('GraphiQL', () => {
Expand Down
Loading

0 comments on commit 8e81102

Please sign in to comment.