Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-cosmos-dom

Package Overview
Dependencies
Maintainers
1
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cosmos-dom - npm Package Compare versions

Comparing version 6.0.0-canary.2cf8bd0.0 to 6.0.0-canary.2dc6672.0

dist/createWebSocketsUrl.d.ts

4

dist/DomFixtureLoader.d.ts

@@ -1,2 +0,2 @@

/// <reference types="react" />
import React from 'react';
import { RendererConfig, UserModuleWrappers } from 'react-cosmos-core';

@@ -7,3 +7,3 @@ type Props = {

};
export declare function DomFixtureLoader({ rendererConfig, moduleWrappers }: Props): JSX.Element;
export declare function DomFixtureLoader({ rendererConfig, moduleWrappers }: Props): React.JSX.Element;
export {};
import React from 'react';
import { parseQueryString, } from 'react-cosmos-core';
import { ClientFixtureLoader } from 'react-cosmos-renderer/client';

@@ -7,4 +6,3 @@ import { DomRendererProvider } from './DomRendererProvider.js';

export function DomFixtureLoader({ rendererConfig, moduleWrappers }) {
const searchParams = parseQueryString(location.search);
return (React.createElement(DomRendererProvider, { rendererConfig: rendererConfig, searchParams: searchParams },
return (React.createElement(DomRendererProvider, { rendererConfig: rendererConfig },
React.createElement(ClientFixtureLoader, { moduleWrappers: moduleWrappers, globalDecorators: globalDecorators, renderMessage: renderMessage })));

@@ -11,0 +9,0 @@ }

import React from 'react';
import { RendererConfig, RendererSearchParams } from 'react-cosmos-core';
import { RendererConfig } from 'react-cosmos-core';
type Props = {
children: React.ReactNode;
rendererConfig: RendererConfig;
searchParams: RendererSearchParams;
setSearchParams?: (nextParams: RendererSearchParams) => void;
};
export declare function DomRendererProvider({ children, rendererConfig, searchParams, setSearchParams, }: Props): JSX.Element;
export declare function DomRendererProvider({ children, rendererConfig }: Props): React.JSX.Element;
export {};
'use client';
import React from 'react';
import { decodeRendererSearchParams, encodeRendererSearchParams, isInsideWindowIframe, } from 'react-cosmos-core';
import { createNoopRendererConnect, createPostMessageConnect, createWebSocketsConnect, } from 'react-cosmos-renderer';
import { RendererContext, RendererProvider, } from 'react-cosmos-renderer/client';
import { getDomRendererId } from './domRendererId.js';
export function DomRendererProvider({ children, rendererConfig, searchParams, setSearchParams, }) {
const rendererId = React.useMemo(() => getDomRendererId(), []);
const rendererConnect = React.useMemo(() => createDomRendererConnect(rendererConfig.playgroundUrl), [rendererConfig.playgroundUrl]);
const params = React.useMemo(() => decodeRendererSearchParams(searchParams), [searchParams]);
const setParams = React.useCallback((nextParams) => {
// Implementing setSearchParams is optional. It is required for server
// fixture loaders that cannot listen to client-side 'selectFixture'
// requests from the Cosmos UI.
if (setSearchParams) {
setSearchParams(encodeRendererSearchParams(nextParams));
}
}, [setSearchParams]);
return (React.createElement(RendererProvider, { rendererId: rendererId, rendererConnect: rendererConnect, params: params, setParams: setParams, reloadRenderer: reloadRenderer },
import { parseRendererQueryString } from 'react-cosmos-core';
import { StatefulRendererProvider } from 'react-cosmos-renderer/client';
import { GlobalErrorHandler } from './GlobalErrorHandler.js';
import { reloadDomRenderer } from './reloadDomRenderer.js';
import { useDomRendererConnect } from './useDomRendererConnect.js';
import { useDomRendererId } from './useDomRendererId.js';
export function DomRendererProvider({ children, rendererConfig }) {
const rendererId = useDomRendererId();
const rendererConnect = useDomRendererConnect(rendererConfig.playgroundUrl);
const { locked = false, fixtureId = null } = React.useMemo(() => parseRendererQueryString(location.search), []);
return (React.createElement(StatefulRendererProvider, { rendererId: rendererId, rendererConnect: rendererConnect, locked: locked, selectedFixtureId: fixtureId, reloadRenderer: reloadDomRenderer },
children,
typeof window !== 'undefined' && React.createElement(GlobalErrorHandler, null)));
}
function reloadRenderer() {
window.location.reload();
}
function GlobalErrorHandler() {
const { rendererId, rendererConnect } = React.useContext(RendererContext);
React.useEffect(() => {
function handleGlobalError() {
rendererConnect.postMessage({
type: 'rendererError',
payload: { rendererId },
});
}
// Unhandled errors from async code will not be caught by the error event, but
// the unhandledrejection event instead.
window.addEventListener('error', handleGlobalError);
window.addEventListener('unhandledrejection', handleGlobalError);
return () => {
window.removeEventListener('error', handleGlobalError);
window.removeEventListener('unhandledrejection', handleGlobalError);
};
}, [rendererConnect, rendererId]);
return null;
}
function createDomRendererConnect(playgroundUrl) {
// TODO: Don't try to connect to WS in static exports.
if (typeof window === 'undefined') {
return createNoopRendererConnect();
}
else {
return isInsideWindowIframe()
? createPostMessageConnect()
: createWebSocketsConnect(getWebSocketsUrl(playgroundUrl));
}
}
function getWebSocketsUrl(playgroundUrl) {
return playgroundUrl.replace(/^https?:/, 'ws:');
}

@@ -20,5 +20,5 @@ import React from 'react';

componentDidUpdate(prevProps: Props): void;
render(): string | number | boolean | React.ReactFragment | JSX.Element | null | undefined;
renderError(error: string): JSX.Element;
render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
renderError(error: string): React.JSX.Element;
}
export {};
export * from './DomFixtureLoader.js';
export * from './DomRendererConfig.js';
export * from './DomRendererProvider.js';
export * from './GlobalErrorHandler.js';
export * from './mountDomRenderer.js';
export * from './reloadDomRenderer.js';
export * from './useDomRendererConnect.js';
export * from './useDomRendererId.js';
export * from './DomFixtureLoader.js';
export * from './DomRendererConfig.js';
export * from './DomRendererProvider.js';
export * from './GlobalErrorHandler.js';
export * from './mountDomRenderer.js';
export * from './reloadDomRenderer.js';
export * from './useDomRendererConnect.js';
export * from './useDomRendererId.js';
{
"name": "react-cosmos-dom",
"version": "6.0.0-canary.2cf8bd0.0+2cf8bd0",
"version": "6.0.0-canary.2dc6672.0+2dc6672",
"description": "React Cosmos DOM",

@@ -11,6 +11,6 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-dom",

"lodash-es": "^4.17.21",
"react-cosmos-core": "6.0.0-canary.2cf8bd0.0+2cf8bd0",
"react-cosmos-renderer": "6.0.0-canary.2cf8bd0.0+2cf8bd0"
"react-cosmos-core": "6.0.0-canary.2dc6672.0+2dc6672",
"react-cosmos-renderer": "6.0.0-canary.2dc6672.0+2dc6672"
},
"gitHead": "2cf8bd0439299cd1a57d59d4b03fff4b62fc7acf"
"gitHead": "2dc66726968260fe2d3f864e3aa834aa40f39144"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc