@stoplight/elements-core 7.12.0 → 7.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import { ServerVariable } from '../../../utils/http-spec/IServer';
3
3
  interface ServerVariablesProps<P extends keyof any = string> {
4
4
  variables: readonly ServerVariable[];
5
5
  values: Record<P, string>;
6
- onChangeValue: (variableName: P, newValue: string) => void;
6
+ onChangeValue: (op: 'set' | 'unset', variableName: P, newValue: string) => void;
7
7
  }
8
8
  export declare const ServerVariables: React.FC<ServerVariablesProps>;
9
9
  export {};
@@ -1,4 +1,4 @@
1
1
  export declare const useServerVariables: () => {
2
2
  serverVariables: {};
3
- updateServerVariableValue: (name: string, value: string) => void;
3
+ updateServerVariableValue: (op: 'set' | 'unset', name: string, value: string) => void;
4
4
  };
package/index.esm.js CHANGED
@@ -1938,8 +1938,15 @@ const isNetworkError = (error) => error instanceof NetworkError;
1938
1938
  const persistedServerVariableValuesAtom = atom({});
1939
1939
  const useServerVariables = () => {
1940
1940
  const [serverVariables, setPersistedServerVariableValues] = useAtom(persistedServerVariableValuesAtom);
1941
- const updateServerVariableValue = (name, value) => {
1942
- setPersistedServerVariableValues(Object.assign({}, serverVariables, { [name]: value }));
1941
+ const updateServerVariableValue = (op, name, value) => {
1942
+ const newServerVariables = Object.assign({}, serverVariables);
1943
+ if (op === 'unset') {
1944
+ delete newServerVariables[name];
1945
+ }
1946
+ else {
1947
+ newServerVariables[name] = value;
1948
+ }
1949
+ setPersistedServerVariableValues(newServerVariables);
1943
1950
  };
1944
1951
  return { serverVariables, updateServerVariableValue };
1945
1952
  };
@@ -1982,7 +1989,10 @@ const VariableEditor = ({ variable, value, onChange }) => {
1982
1989
  const ServerVariables = ({ variables, values, onChangeValue }) => {
1983
1990
  return (React.createElement(Panel, { defaultIsOpen: true },
1984
1991
  React.createElement(Panel.Titlebar, null, "Server Variables"),
1985
- React.createElement(Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React.createElement(VariableEditor, { key: variable.name, variable: variable, value: values[variable.name], onChange: (value) => onChangeValue(variable.name, String(value)) }))))));
1992
+ React.createElement(Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React.createElement(VariableEditor, { key: variable.name, variable: variable, value: values[variable.name], onChange: (value) => {
1993
+ const actualValue = String(value);
1994
+ onChangeValue(variable.enum || actualValue !== '' ? 'set' : 'unset', variable.name, actualValue);
1995
+ } }))))));
1986
1996
  };
1987
1997
 
1988
1998
  const defaultServers = [];
package/index.js CHANGED
@@ -1994,8 +1994,15 @@ const isNetworkError = (error) => error instanceof NetworkError;
1994
1994
  const persistedServerVariableValuesAtom = jotai.atom({});
1995
1995
  const useServerVariables = () => {
1996
1996
  const [serverVariables, setPersistedServerVariableValues] = jotai.useAtom(persistedServerVariableValuesAtom);
1997
- const updateServerVariableValue = (name, value) => {
1998
- setPersistedServerVariableValues(Object.assign({}, serverVariables, { [name]: value }));
1997
+ const updateServerVariableValue = (op, name, value) => {
1998
+ const newServerVariables = Object.assign({}, serverVariables);
1999
+ if (op === 'unset') {
2000
+ delete newServerVariables[name];
2001
+ }
2002
+ else {
2003
+ newServerVariables[name] = value;
2004
+ }
2005
+ setPersistedServerVariableValues(newServerVariables);
1999
2006
  };
2000
2007
  return { serverVariables, updateServerVariableValue };
2001
2008
  };
@@ -2038,7 +2045,10 @@ const VariableEditor = ({ variable, value, onChange }) => {
2038
2045
  const ServerVariables = ({ variables, values, onChangeValue }) => {
2039
2046
  return (React__namespace.createElement(mosaic.Panel, { defaultIsOpen: true },
2040
2047
  React__namespace.createElement(mosaic.Panel.Titlebar, null, "Server Variables"),
2041
- React__namespace.createElement(mosaic.Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React__namespace.createElement(VariableEditor, { key: variable.name, variable: variable, value: values[variable.name], onChange: (value) => onChangeValue(variable.name, String(value)) }))))));
2048
+ React__namespace.createElement(mosaic.Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React__namespace.createElement(VariableEditor, { key: variable.name, variable: variable, value: values[variable.name], onChange: (value) => {
2049
+ const actualValue = String(value);
2050
+ onChangeValue(variable.enum || actualValue !== '' ? 'set' : 'unset', variable.name, actualValue);
2051
+ } }))))));
2042
2052
  };
2043
2053
 
2044
2054
  const defaultServers = [];
package/index.mjs CHANGED
@@ -1938,8 +1938,15 @@ const isNetworkError = (error) => error instanceof NetworkError;
1938
1938
  const persistedServerVariableValuesAtom = atom({});
1939
1939
  const useServerVariables = () => {
1940
1940
  const [serverVariables, setPersistedServerVariableValues] = useAtom(persistedServerVariableValuesAtom);
1941
- const updateServerVariableValue = (name, value) => {
1942
- setPersistedServerVariableValues(Object.assign({}, serverVariables, { [name]: value }));
1941
+ const updateServerVariableValue = (op, name, value) => {
1942
+ const newServerVariables = Object.assign({}, serverVariables);
1943
+ if (op === 'unset') {
1944
+ delete newServerVariables[name];
1945
+ }
1946
+ else {
1947
+ newServerVariables[name] = value;
1948
+ }
1949
+ setPersistedServerVariableValues(newServerVariables);
1943
1950
  };
1944
1951
  return { serverVariables, updateServerVariableValue };
1945
1952
  };
@@ -1982,7 +1989,10 @@ const VariableEditor = ({ variable, value, onChange }) => {
1982
1989
  const ServerVariables = ({ variables, values, onChangeValue }) => {
1983
1990
  return (React.createElement(Panel, { defaultIsOpen: true },
1984
1991
  React.createElement(Panel.Titlebar, null, "Server Variables"),
1985
- React.createElement(Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React.createElement(VariableEditor, { key: variable.name, variable: variable, value: values[variable.name], onChange: (value) => onChangeValue(variable.name, String(value)) }))))));
1992
+ React.createElement(Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React.createElement(VariableEditor, { key: variable.name, variable: variable, value: values[variable.name], onChange: (value) => {
1993
+ const actualValue = String(value);
1994
+ onChangeValue(variable.enum || actualValue !== '' ? 'set' : 'unset', variable.name, actualValue);
1995
+ } }))))));
1986
1996
  };
1987
1997
 
1988
1998
  const defaultServers = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "7.12.0",
3
+ "version": "7.12.1",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",