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.b87d3fe.0 to 6.0.0-canary.c00ca07.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 {};

@@ -5,3 +5,3 @@ import { isEqual } from 'lodash-es';

import { FixtureContext, } from 'react-cosmos-renderer/client';
class ErrorCatch extends React.Component {
export class ErrorCatch extends React.Component {
static contextType = FixtureContext;

@@ -44,3 +44,2 @@ static prevContext = null;

}
export { ErrorCatch };
function fixtureChanged(f1, f2) {

@@ -47,0 +46,0 @@ return !areNodesEqual(f1, f2, true);

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.b87d3fe.0+b87d3fe",
"version": "6.0.0-canary.c00ca07.0+c00ca07",
"description": "React Cosmos DOM",

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

"dependencies": {
"lodash-es": "^4.17.21",
"react-cosmos-core": "6.0.0-canary.b87d3fe.0+b87d3fe",
"react-cosmos-renderer": "6.0.0-canary.b87d3fe.0+b87d3fe"
"lodash-es": "4.17.21",
"react-cosmos-core": "6.0.0-canary.c00ca07.0+c00ca07",
"react-cosmos-renderer": "6.0.0-canary.c00ca07.0+c00ca07"
},
"gitHead": "b87d3fe06a56c8e3c4c87e731e31092df67d52c0"
"gitHead": "c00ca07a5b6a2cad4a218d8aae72fa4c2310cc1e"
}
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