react-cosmos-renderer
Advanced tools
Comparing version 6.0.0-canary.151523c.0 to 6.0.0-canary.2cf8bd0.0
import React from 'react'; | ||
import { getFixtureListFromWrappers, isInsideWindowIframe, } from 'react-cosmos-core'; | ||
import { DelayRender, getFixtureListFromWrappers, } from 'react-cosmos-core'; | ||
import { RendererSync } from './RendererSync.js'; | ||
@@ -8,5 +8,3 @@ export function FixtureLoaderConnect({ moduleWrappers, fixtureSelection, renderMessage, renderFixture, }) { | ||
if (!fixtureSelection) { | ||
return isInsideWindowIframe() | ||
? null | ||
: renderMessage('No fixture selected.'); | ||
return (React.createElement(DelayRender, { delay: 500 }, renderMessage('No fixture selected.'))); | ||
} | ||
@@ -13,0 +11,0 @@ const { fixtureId } = fixtureSelection; |
@@ -5,4 +5,3 @@ 'use client'; | ||
export function RendererSync({ children, fixtures }) { | ||
const { searchParams, rendererId, rendererConnect, reloadRenderer, lazyItems, } = React.useContext(RendererContext); | ||
const { fixtureId: selectedFixtureId } = searchParams; | ||
const { params: { fixtureId: selectedFixtureId }, rendererId, rendererConnect, reloadRenderer, lazyItems, } = React.useContext(RendererContext); | ||
const readyRef = React.useRef(false); | ||
@@ -9,0 +8,0 @@ React.useEffect(() => { |
@@ -5,17 +5,20 @@ 'use client'; | ||
export function ServerFixtureChangeListener({ children }) { | ||
const { rendererId, rendererConnect, searchParams, setSearchParams } = React.useContext(RendererContext); | ||
const { rendererId, rendererConnect, params, setParams } = React.useContext(RendererContext); | ||
React.useEffect(() => rendererConnect.onMessage(msg => { | ||
if (!searchParams.locked && | ||
if (!params.locked && | ||
msg.type === 'selectFixture' && | ||
msg.payload.rendererId === rendererId) { | ||
const { fixtureId } = msg.payload; | ||
setSearchParams({ fixtureId }); | ||
setParams({ | ||
fixtureId, | ||
key: (params.key ?? 0) + 1, | ||
}); | ||
} | ||
else if (!searchParams.locked && | ||
else if (!params.locked && | ||
msg.type === 'unselectFixture' && | ||
msg.payload.rendererId === rendererId) { | ||
setSearchParams({}); | ||
setParams({}); | ||
} | ||
}), [rendererConnect, rendererId, searchParams.locked, setSearchParams]); | ||
}), [params.key, params.locked, rendererConnect, rendererId, setParams]); | ||
return React.createElement(React.Fragment, null, children); | ||
} |
import React from 'react'; | ||
import { ReactDecorator, StringRendererSearchParams, UserModuleWrappers } from 'react-cosmos-core'; | ||
import { ReactDecorator, RendererParams, UserModuleWrappers } from 'react-cosmos-core'; | ||
type Props = { | ||
searchParams: StringRendererSearchParams; | ||
params: RendererParams; | ||
moduleWrappers: UserModuleWrappers; | ||
@@ -9,3 +9,3 @@ globalDecorators?: ReactDecorator[]; | ||
}; | ||
export declare function ServerFixtureLoader({ searchParams, moduleWrappers, globalDecorators, renderMessage, }: Props): JSX.Element; | ||
export declare function ServerFixtureLoader({ params, moduleWrappers, globalDecorators, renderMessage, }: Props): JSX.Element; | ||
export {}; |
import React, { Suspense } from 'react'; | ||
import { decodeRendererSearchParams, } from 'react-cosmos-core'; | ||
import { FixtureModule } from '../fixtureModule/FixtureModule.js'; | ||
@@ -8,8 +7,8 @@ import { AsyncModuleLoader } from '../moduleLoaders/AsyncModuleLoader.js'; | ||
import { defaultRenderMessage } from './defaultRenderMessage.js'; | ||
export function ServerFixtureLoader({ searchParams, moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, }) { | ||
const { fixtureId = null } = decodeRendererSearchParams(searchParams); | ||
export function ServerFixtureLoader({ params, moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, }) { | ||
const { fixtureId = null, key = 0 } = params; | ||
const fixtureSelection = fixtureId && { | ||
fixtureId, | ||
initialFixtureState: {}, | ||
renderKey: 0, | ||
renderKey: key, | ||
}; | ||
@@ -16,0 +15,0 @@ return (React.createElement(ServerFixtureChangeListener, null, |
import React from 'react'; | ||
import { RendererContext } from '../rendererConnect/RendererContext.js'; | ||
export function useFixtureSelection() { | ||
const { rendererId, rendererConnect, searchParams } = React.useContext(RendererContext); | ||
const { fixtureId: selectedFixtureId = null } = searchParams; | ||
const { rendererId, rendererConnect, params } = React.useContext(RendererContext); | ||
const { fixtureId: selectedFixtureId = null } = params; | ||
const [selection, setSelection] = React.useState(() => selectedFixtureId && { | ||
@@ -12,3 +12,3 @@ fixtureId: selectedFixtureId, | ||
React.useEffect(() => rendererConnect.onMessage(msg => { | ||
if (!searchParams.locked && | ||
if (!params.locked && | ||
msg.type === 'selectFixture' && | ||
@@ -25,3 +25,3 @@ msg.payload.rendererId === rendererId) { | ||
} | ||
else if (!searchParams.locked && | ||
else if (!params.locked && | ||
msg.type === 'unselectFixture' && | ||
@@ -31,4 +31,4 @@ msg.payload.rendererId === rendererId) { | ||
} | ||
}), [rendererConnect, rendererId, searchParams.locked]); | ||
}), [params.locked, rendererConnect, rendererId]); | ||
return selection; | ||
} |
import React from 'react'; | ||
import { FixtureList, RendererConnect, RendererSearchParams } from 'react-cosmos-core'; | ||
import { FixtureList, RendererConnect, RendererParams } from 'react-cosmos-core'; | ||
export type RendererContextValue = { | ||
rendererId: string; | ||
rendererConnect: RendererConnect; | ||
searchParams: RendererSearchParams; | ||
setSearchParams(nextParams: RendererSearchParams): void; | ||
params: RendererParams; | ||
setParams(nextParams: RendererParams): void; | ||
reloadRenderer(): void; | ||
@@ -9,0 +9,0 @@ lazyItems: FixtureList; |
@@ -8,4 +8,4 @@ import React from 'react'; | ||
}, | ||
searchParams: {}, | ||
setSearchParams: () => { }, | ||
params: {}, | ||
setParams: () => { }, | ||
reloadRenderer: () => { }, | ||
@@ -12,0 +12,0 @@ lazyItems: {}, |
import React from 'react'; | ||
import { RendererConnect, RendererSearchParams } from 'react-cosmos-core'; | ||
import { RendererConnect, RendererParams } from 'react-cosmos-core'; | ||
export type Props = { | ||
@@ -7,6 +7,6 @@ children: React.ReactNode; | ||
rendererConnect: RendererConnect; | ||
searchParams: RendererSearchParams; | ||
setSearchParams(nextParams: RendererSearchParams): void; | ||
params: RendererParams; | ||
setParams(nextParams: RendererParams): void; | ||
reloadRenderer(): void; | ||
}; | ||
export declare function RendererProvider(props: Props): JSX.Element; |
@@ -10,4 +10,4 @@ 'use client'; | ||
rendererConnect: props.rendererConnect, | ||
searchParams: props.searchParams, | ||
setSearchParams: props.setSearchParams, | ||
params: props.params, | ||
setParams: props.setParams, | ||
reloadRenderer: props.reloadRenderer, | ||
@@ -19,9 +19,9 @@ lazyItems, | ||
lazyItems, | ||
props.params, | ||
props.reloadRenderer, | ||
props.rendererConnect, | ||
props.rendererId, | ||
props.searchParams, | ||
props.setSearchParams, | ||
props.setParams, | ||
]); | ||
return (React.createElement(RendererContext.Provider, { value: value }, props.children)); | ||
} |
{ | ||
"name": "react-cosmos-renderer", | ||
"version": "6.0.0-canary.151523c.0+151523c", | ||
"version": "6.0.0-canary.2cf8bd0.0+2cf8bd0", | ||
"description": "React Cosmos Renderer", | ||
@@ -15,6 +15,6 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-renderer", | ||
"lodash-es": "^4.17.21", | ||
"react-cosmos-core": "6.0.0-canary.151523c.0+151523c", | ||
"react-cosmos-core": "6.0.0-canary.2cf8bd0.0+2cf8bd0", | ||
"react-is": "^18.2.0" | ||
}, | ||
"gitHead": "151523cc4fd20b3ccf0287336a75c89997b622c4" | ||
"gitHead": "2cf8bd0439299cd1a57d59d4b03fff4b62fc7acf" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
70616
1520