msw-dev-tool 1.1.6 → 1.1.7

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.
package/dist/cjs/index.js CHANGED
@@ -28129,41 +28129,35 @@ const RequestPreview = ({ url, paramValues, headers = {}, searchParams = {}, })
28129
28129
  } }, JSON.stringify(response, null, 2)))))));
28130
28130
  };
28131
28131
 
28132
+ /**
28133
+ * - It uses `zustand` global state.
28134
+ * - remounting of the inner component that uses local states.
28135
+ * - To force a component to be remounted, use `key` prop.
28136
+ */
28132
28137
  const HandlerDebugger = () => {
28133
- var _a;
28134
28138
  const { currentHandler: handler } = useUiControlStore();
28135
- const path = (_a = handler === null || handler === void 0 ? void 0 : handler.info.path) !== null && _a !== void 0 ? _a : "";
28139
+ const key = `${handler === null || handler === void 0 ? void 0 : handler.info.path}-${handler === null || handler === void 0 ? void 0 : handler.info.method}`;
28140
+ return (React.createElement(Container, null, handler ? (React.createElement(_HandlerDebugger, { handler: handler, key: key })) : (React.createElement(p$b, null, "Select a handler from the table to debug"))));
28141
+ };
28142
+ const _HandlerDebugger = ({ handler }) => {
28143
+ const path = handler === null || handler === void 0 ? void 0 : handler.info.path;
28136
28144
  const url = new URL(String(path), location.href);
28137
28145
  const { params } = msw.matchRequestUrl(url, path, url.origin);
28138
- const [paramValues, setParamValues] = React.useState(undefined);
28146
+ const [paramValues, setParamValues] = React.useState(params
28147
+ ? Object.keys(params).reduce((acc, key) => ({
28148
+ ...acc,
28149
+ [key]: "",
28150
+ }), {})
28151
+ : undefined);
28139
28152
  const [headers, setHeaders] = React.useState({});
28140
28153
  const [searchParams, setSearchParams] = React.useState({});
28141
- /**
28142
- * Initialize state to clear previous handler data
28143
- */
28144
- React.useEffect(() => {
28145
- if (params) {
28146
- setParamValues(Object.keys(params).reduce((acc, key) => ({
28147
- ...acc,
28148
- [key]: "",
28149
- }), {}));
28150
- }
28151
- else {
28152
- setParamValues(undefined);
28153
- }
28154
- setHeaders({});
28155
- setSearchParams({});
28156
- }, [handler]);
28157
28154
  const handleParamChange = (key, value) => {
28158
28155
  setParamValues((prev) => ({
28159
28156
  ...prev,
28160
28157
  [key]: value,
28161
28158
  }));
28162
28159
  };
28163
- if (!handler)
28164
- return (React.createElement(Container, null,
28165
- React.createElement(p$b, null, "Select a handler from the table to debug")));
28166
- return (React.createElement(Container, null,
28160
+ return (React.createElement(React.Fragment, null,
28167
28161
  React.createElement(p$b, { className: "msw-dt-sub-text", style: { overflowX: "scroll" } }, url.toString()),
28168
28162
  React.createElement(PathParamSetter, { paramValues: paramValues, onParamChange: handleParamChange }),
28169
28163
  React.createElement(KeyValueInputList, { items: searchParams, setItems: setSearchParams, title: "Search Params" }),
@@ -28208,6 +28202,7 @@ const MSWDevTool = () => {
28208
28202
  borderRadius: "50%",
28209
28203
  width: "3.5rem",
28210
28204
  height: "3.5rem",
28205
+ margin: "1rem",
28211
28206
  } }, "M")),
28212
28207
  React.createElement(Drawer.Portal, null,
28213
28208
  React.createElement(ThemeProvider, null,