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

react-cosmos-ui

Package Overview
Dependencies
Maintainers
1
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cosmos-ui - npm Package Compare versions

Comparing version 6.0.0-beta.8 to 6.0.0-beta.9

dist/plugins/ControlPanel/shared.d.ts

9

dist/plugins/ClassStatePanel/ClassStatePanel/ComponentClassState.d.ts
import React from 'react';
import { FixtureState, FixtureStateClassState, StateUpdater } from 'react-cosmos-core';
import { ClassStateFixtureStateItem } from 'react-cosmos-core';
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
import { SetClassStateFixtureState } from '../shared.js';
type Props = {
fsClassState: FixtureStateClassState;
classStateFsItem: ClassStateFixtureStateItem;
fixtureExpansion: FixtureExpansion;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
onFixtureStateChange: SetClassStateFixtureState;
onElementExpansionChange: OnElementExpansionChange;
};
export declare function ComponentClassState({ fsClassState, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }: Props): React.JSX.Element;
export declare function ComponentClassState({ classStateFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }: Props): React.JSX.Element;
export {};
import { isEqual } from 'lodash-es';
import React, { useCallback } from 'react';
import { updateFixtureStateClassState, } from 'react-cosmos-core';
import { updateClassStateFixtureStateItem, } from 'react-cosmos-core';
import { SidePanelActions, SidePanelBody, SidePanelContainer, SidePanelHeader, SidePanelTitle, } from '../../../components/SidePanel.js';

@@ -9,8 +9,8 @@ import { ExpandCollapseValues } from '../../../components/ValueInputTree/ExpandCollapseValues.js';

import { RotateCcwIcon } from '../../../components/icons/index.js';
import { createClassStateFsUpdater } from './shared.js';
export function ComponentClassState({ fsClassState, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
const { componentName, elementId, values } = fsClassState;
import { classStateFsItemUpdater } from './shared.js';
export function ComponentClassState({ classStateFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
const { componentName, elementId, values } = classStateFsItem;
const [initialValues] = React.useState(() => values);
const handleValuesReset = React.useCallback(() => onFixtureStateChange(createClassStateFsUpdater(elementId, prevFs => updateFixtureStateClassState({
fixtureState: prevFs,
const handleValuesReset = React.useCallback(() => onFixtureStateChange(classStateFsItemUpdater(elementId, prevFs => updateClassStateFixtureStateItem({
classStateFs: prevFs,
elementId,

@@ -20,4 +20,4 @@ values: initialValues,

const handleValueChange = React.useCallback((newValues) => {
onFixtureStateChange(createClassStateFsUpdater(elementId, prevFs => updateFixtureStateClassState({
fixtureState: prevFs,
onFixtureStateChange(classStateFsItemUpdater(elementId, prevFs => updateClassStateFixtureStateItem({
classStateFs: prevFs,
elementId,

@@ -24,0 +24,0 @@ values: newValues,

import React from 'react';
import { FixtureState, StateUpdater } from 'react-cosmos-core';
import { ClassStateFixtureState } from 'react-cosmos-core';
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
import { SetClassStateFixtureState } from '../shared.js';
type Props = {
fixtureState: FixtureState;
fixtureState: ClassStateFixtureState | undefined;
fixtureExpansion: FixtureExpansion;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
onFixtureStateChange: SetClassStateFixtureState;
onElementExpansionChange: OnElementExpansionChange;

@@ -9,0 +10,0 @@ };

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

export const ClassStatePanel = React.memo(function ClassStatePanel({ fixtureState, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
if (!fixtureState.classState) {
if (!fixtureState) {
return null;
}
const classStateWithValues = fixtureState.classState.filter(hasFsValues);
return (React.createElement(React.Fragment, null, sortFsValueGroups(classStateWithValues).map(fsClassState => {
const strElementId = stringifyElementId(fsClassState.elementId);
return (React.createElement(ComponentClassState, { key: strElementId, fsClassState: fsClassState, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
const classStateWithValues = fixtureState.filter(hasFsValues);
return (React.createElement(React.Fragment, null, sortFsValueGroups(classStateWithValues).map(fsItem => {
const strElementId = stringifyElementId(fsItem.elementId);
return (React.createElement(ComponentClassState, { key: strElementId, classStateFsItem: fsItem, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
})));
});

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

import { FixtureElementId, FixtureState, FixtureStateClassState, StateUpdater } from 'react-cosmos-core';
export declare function createClassStateFsUpdater(elementId: FixtureElementId, cb: (prevFs: FixtureState) => FixtureStateClassState[]): StateUpdater<FixtureState>;
import { ClassStateFixtureState, FixtureElementId, FixtureStateUpdater } from 'react-cosmos-core';
export declare function classStateFsItemUpdater(elementId: FixtureElementId, cb: FixtureStateUpdater<ClassStateFixtureState>): FixtureStateUpdater<ClassStateFixtureState>;

@@ -1,16 +0,13 @@

import { findFixtureStateClassState, } from 'react-cosmos-core';
import { findClassStateFixtureStateItem, } from 'react-cosmos-core';
import { stringifyElementId } from '../../../components/ValueInputTree/index.js';
export function createClassStateFsUpdater(elementId, cb) {
export function classStateFsItemUpdater(elementId, cb) {
return prevFs => {
const fsClassState = findFixtureStateClassState(prevFs, elementId);
if (!fsClassState) {
const fsItem = findClassStateFixtureStateItem(prevFs, elementId);
if (!fsItem) {
const elId = stringifyElementId(elementId);
console.warn(`Trying to update missing element with ID: ${elId}`);
return prevFs;
return prevFs ?? [];
}
return {
...prevFs,
classState: cb(prevFs),
};
return cb(prevFs);
};
}

@@ -1,6 +0,6 @@

import React from 'react';
import React, { useCallback } from 'react';
import { createPlugin } from 'react-plugin';
import { getFixtureExpansion, updateElementExpansion, } from '../../components/ValueInputTree/index.js';
import { ClassStatePanel } from './ClassStatePanel/index.js';
import { CLASS_STATE_TREE_EXPANSION_STORAGE_KEY } from './shared.js';
import { CLASS_STATE_TREE_EXPANSION_STORAGE_KEY, } from './shared.js';
const { namedPlug, register } = createPlugin({

@@ -10,4 +10,6 @@ name: 'classStatePanel',

namedPlug('sidePanelRow', 'classState', ({ pluginContext, slotProps }) => {
const { fixtureId, fixtureState, onFixtureStateChange } = slotProps;
const { fixtureId, getFixtureState, setFixtureState } = slotProps;
const { fixtureExpansion, onElementExpansionChange } = useFixtureExpansion(pluginContext, fixtureId);
const fixtureState = getFixtureState('classState');
const onFixtureStateChange = useCallback(update => setFixtureState('classState', update), [setFixtureState]);
return (React.createElement(ClassStatePanel, { fixtureState: fixtureState, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));

@@ -14,0 +16,0 @@ });

@@ -0,1 +1,3 @@

import { ClassStateFixtureState, FixtureStateUpdater } from 'react-cosmos-core';
export type SetClassStateFixtureState = (updater: FixtureStateUpdater<ClassStateFixtureState>) => void;
export declare const CLASS_STATE_TREE_EXPANSION_STORAGE_KEY = "classStateTreeExpansion";
import React from 'react';
import { FixtureState, StateUpdater } from 'react-cosmos-core';
import { ControlsFixtureState } from 'react-cosmos-core';
import { SetControlsFixtureState } from './shared.js';
type Props = {
fixtureState: FixtureState;
fixtureState: ControlsFixtureState | undefined;
controlActionOrder: string[];
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
onFixtureStateChange: SetControlsFixtureState;
};
export declare function ControlPanel({ fixtureState, controlActionOrder, onFixtureStateChange, }: Props): React.JSX.Element | null;
export {};

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

const handleControlsReset = React.useCallback(() => onFixtureStateChange(resetControls), [onFixtureStateChange]);
const controls = fixtureState.controls || {};
const controls = fixtureState ?? {};
if (Object.keys(controls).length === 0)

@@ -30,7 +30,7 @@ return null;

function resetControls(fixtureState) {
const controls = fixtureState.controls ? { ...fixtureState.controls } : {};
const controls = fixtureState ? { ...fixtureState } : {};
Object.keys(controls).forEach(controlName => {
controls[controlName] = resetControl(controls[controlName]);
});
return { ...fixtureState, controls };
return controls;
}

@@ -37,0 +37,0 @@ function resetControl(control) {

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

import React from 'react';
import React, { useCallback } from 'react';
import { createPlugin } from 'react-plugin';

@@ -12,3 +12,5 @@ import { ControlPanel } from './ControlPanel.js';

const { controlActionOrder } = pluginContext.getConfig();
const { fixtureState, onFixtureStateChange } = slotProps;
const { getFixtureState, setFixtureState } = slotProps;
const fixtureState = getFixtureState('controls');
const onFixtureStateChange = useCallback(update => setFixtureState('controls', update), [setFixtureState]);
return (React.createElement(ControlPanel, { fixtureState: fixtureState, controlActionOrder: controlActionOrder, onFixtureStateChange: onFixtureStateChange }));

@@ -15,0 +17,0 @@ });

@@ -10,8 +10,5 @@ import React, { useCallback } from 'react';

const handleChange = useCallback((selectName, updatedControl) => {
onFixtureStateChange(fixtureState => ({
...fixtureState,
controls: {
...fixtureState.controls,
[selectName]: updatedControl,
},
onFixtureStateChange(prevFs => ({
...prevFs,
[selectName]: updatedControl,
}));

@@ -18,0 +15,0 @@ }, [onFixtureStateChange]);

import React from 'react';
import { FixtureStateSelectControl } from 'react-cosmos-core';
import { SelectControlFixtureState } from 'react-cosmos-core';
type Props = {
name: string;
control: FixtureStateSelectControl;
onChange: (name: string, select: FixtureStateSelectControl) => unknown;
control: SelectControlFixtureState;
onChange: (name: string, select: SelectControlFixtureState) => unknown;
};
export declare function SelectValueInput({ name, control, onChange }: Props): React.JSX.Element;
export {};

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

import React from 'react';
import React, { useCallback } from 'react';
import { createPlugin } from 'react-plugin';

@@ -6,3 +6,3 @@ import { getFixtureExpansion, hasFsValues, updateElementExpansion, } from '../../components/ValueInputTree/index.js';

import { PropsPanel } from './PropsPanel/index.js';
import { PROPS_TREE_EXPANSION_STORAGE_KEY } from './shared.js';
import { PROPS_TREE_EXPANSION_STORAGE_KEY, } from './shared.js';
const { namedPlug, register } = createPlugin({

@@ -12,4 +12,6 @@ name: 'propsPanel',

namedPlug('sidePanelRow', 'props', ({ pluginContext, slotProps }) => {
const { fixtureId, fixtureState, onFixtureStateChange } = slotProps;
const { fixtureId, getFixtureState, setFixtureState } = slotProps;
const { fixtureExpansion, onElementExpansionChange } = useFixtureExpansion(pluginContext, fixtureId);
const fixtureState = getFixtureState('props');
const onFixtureStateChange = useCallback(change => setFixtureState('props', change), [setFixtureState]);
return (React.createElement(PropsPanel, { fixtureState: fixtureState, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));

@@ -22,4 +24,4 @@ });

namedPlug('sidePanelRow', 'blankState', ({ slotProps }) => {
const { fixtureState } = slotProps;
return shouldShowBlankState(fixtureState) ? React.createElement(BlankState, null) : null;
const { getFixtureState } = slotProps;
return shouldShowBlankState(getFixtureState) ? React.createElement(BlankState, null) : null;
});

@@ -44,10 +46,13 @@ export { register };

}
function shouldShowBlankState(fixtureState) {
const hasProps = fixtureState.props && fixtureState.props.some(hasFsValues);
function shouldShowBlankState(getFixtureState) {
const props = getFixtureState('props');
const hasProps = props && props.some(hasFsValues);
if (hasProps)
return false;
const hasClassState = fixtureState.classState && fixtureState.classState.some(hasFsValues);
const classState = getFixtureState('classState');
const hasClassState = classState && classState.some(hasFsValues);
if (hasClassState)
return false;
const hasControls = fixtureState.controls && Object.keys(fixtureState.controls).length > 0;
const controls = getFixtureState('controls');
const hasControls = controls && Object.keys(controls).length > 0;
if (hasControls)

@@ -54,0 +59,0 @@ return false;

import React from 'react';
import { FixtureState, FixtureStateProps, StateUpdater } from 'react-cosmos-core';
import { PropsFixtureStateItem } from 'react-cosmos-core';
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
import { SetPropsFixtureState } from '../shared.js';
type Props = {
fsProps: FixtureStateProps;
propsFsItem: PropsFixtureStateItem;
fixtureExpansion: FixtureExpansion;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
onFixtureStateChange: SetPropsFixtureState;
onElementExpansionChange: OnElementExpansionChange;
};
export declare function ComponentProps({ fsProps, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }: Props): React.JSX.Element;
export declare function ComponentProps({ propsFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }: Props): React.JSX.Element;
export {};
import { isEqual } from 'lodash-es';
import React, { useCallback } from 'react';
import { resetFixtureStateProps, updateFixtureStateProps, } from 'react-cosmos-core';
import { resetPropsFixtureStateItem, updatePropsFixtureStateItem, } from 'react-cosmos-core';
import { SidePanelActions, SidePanelBody, SidePanelContainer, SidePanelHeader, SidePanelTitle, } from '../../../components/SidePanel.js';
import { ExpandCollapseValues } from '../../../components/ValueInputTree/ExpandCollapseValues.js';
import { ValueInputTree, stringifyElementId, } from '../../../components/ValueInputTree/index.js';
import { IconButton32 } from '../../../components/buttons/index.js';
import { CopyIcon, RotateCcwIcon } from '../../../components/icons/index.js';
import { SidePanelActions, SidePanelBody, SidePanelContainer, SidePanelHeader, SidePanelTitle, } from '../../../components/SidePanel.js';
import { ExpandCollapseValues } from '../../../components/ValueInputTree/ExpandCollapseValues.js';
import { stringifyElementId, ValueInputTree, } from '../../../components/ValueInputTree/index.js';
import { createPropsFsUpdater } from './shared.js';
export function ComponentProps({ fsProps, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
const { componentName, elementId, values } = fsProps;
import { propsFsItemUpdater } from './shared.js';
export function ComponentProps({ propsFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
const { componentName, elementId, values } = propsFsItem;
const [reset, setReset] = React.useState(true);
const handleResetToggle = React.useCallback(() => setReset(!reset), [reset]);
const [initialValues] = React.useState(() => values);
const handleValuesReset = React.useCallback(() => onFixtureStateChange(createPropsFsUpdater(elementId, prevFs => resetFixtureStateProps({
fixtureState: prevFs,
const handleValuesReset = React.useCallback(() => onFixtureStateChange(propsFsItemUpdater(elementId, prevFs => resetPropsFixtureStateItem({
propsFs: prevFs,
elementId,

@@ -21,5 +21,7 @@ values: initialValues,

const handleValueChange = React.useCallback((newValues) => {
const changeFn = reset ? resetFixtureStateProps : updateFixtureStateProps;
onFixtureStateChange(createPropsFsUpdater(elementId, prevFs => changeFn({
fixtureState: prevFs,
const changeFn = reset
? resetPropsFixtureStateItem
: updatePropsFixtureStateItem;
onFixtureStateChange(propsFsItemUpdater(elementId, prevFs => changeFn({
propsFs: prevFs,
elementId,

@@ -26,0 +28,0 @@ values: newValues,

import React from 'react';
import { FixtureState, StateUpdater } from 'react-cosmos-core';
import { PropsFixtureState } from 'react-cosmos-core';
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
import { SetPropsFixtureState } from '../shared.js';
type Props = {
fixtureState: FixtureState;
fixtureState: PropsFixtureState | undefined;
fixtureExpansion: FixtureExpansion;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
onFixtureStateChange: SetPropsFixtureState;
onElementExpansionChange: OnElementExpansionChange;

@@ -9,0 +10,0 @@ };

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

export const PropsPanel = React.memo(function PropsPanel({ fixtureState, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
if (!fixtureState.props) {
if (!fixtureState) {
return null;
}
const propsWithValues = fixtureState.props.filter(hasFsValues);
return (React.createElement(React.Fragment, null, sortFsValueGroups(propsWithValues).map(fsProps => {
const strElementId = stringifyElementId(fsProps.elementId);
return (React.createElement(ComponentProps, { key: strElementId, fsProps: fsProps, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
const propsWithValues = fixtureState.filter(hasFsValues);
return (React.createElement(React.Fragment, null, sortFsValueGroups(propsWithValues).map(fsItem => {
const strElementId = stringifyElementId(fsItem.elementId);
return (React.createElement(ComponentProps, { key: strElementId, propsFsItem: fsItem, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
})));
});

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

import { FixtureElementId, FixtureState, FixtureStateProps, StateUpdater } from 'react-cosmos-core';
export declare function createPropsFsUpdater(elementId: FixtureElementId, cb: (prevFs: FixtureState) => FixtureStateProps[]): StateUpdater<FixtureState>;
import { FixtureElementId, FixtureStateUpdater, PropsFixtureState } from 'react-cosmos-core';
export declare function propsFsItemUpdater(elementId: FixtureElementId, cb: FixtureStateUpdater<PropsFixtureState>): FixtureStateUpdater<PropsFixtureState>;

@@ -1,16 +0,13 @@

import { findFixtureStateProps, } from 'react-cosmos-core';
import { findPropsFixtureStateItem, } from 'react-cosmos-core';
import { stringifyElementId } from '../../../components/ValueInputTree/index.js';
export function createPropsFsUpdater(elementId, cb) {
export function propsFsItemUpdater(elementId, cb) {
return prevFs => {
const fsProps = findFixtureStateProps(prevFs, elementId);
if (!fsProps) {
const fsItem = findPropsFixtureStateItem(prevFs, elementId);
if (!fsItem) {
const elId = stringifyElementId(elementId);
console.warn(`Trying to update missing element with ID: ${elId}`);
return prevFs;
return prevFs ?? [];
}
return {
...prevFs,
props: cb(prevFs),
};
return cb(prevFs);
};
}

@@ -0,1 +1,3 @@

import { FixtureStateUpdater, PropsFixtureState } from 'react-cosmos-core';
export type SetPropsFixtureState = (updater: FixtureStateUpdater<PropsFixtureState>) => void;
export declare const PROPS_TREE_EXPANSION_STORAGE_KEY = "propsTreeExpansion";

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

import { fixtureStateByName } from 'react-cosmos-core';
import { createPlugin } from 'react-plugin';

@@ -8,2 +9,3 @@ import { onRouterFixtureReselect } from './onRouterFixtureReselect.js';

import { setFixtureState } from './setFixtureState.js';
import { setGlobalFixtureState } from './setGlobalFixtureState.js';
const { on, register, onLoad } = createPlugin({

@@ -20,2 +22,3 @@ name: 'rendererCore',

fixtureState: {},
globalFixtureState: {},
},

@@ -27,8 +30,10 @@ methods: {

getFixtures,
getFixtureState,
isRendererConnected,
reloadRenderer,
setFixtureState,
selectPrimaryRenderer,
receiveResponse,
getAllFixtureState,
getFixtureState,
setFixtureState,
setGlobalFixtureState,
},

@@ -60,5 +65,8 @@ });

}
function getFixtureState({ getState }) {
function getAllFixtureState({ getState }) {
return getState().fixtureState;
}
function getFixtureState({ getState }, name) {
return fixtureStateByName(getState().fixtureState, name);
}
function isRendererConnected({ getState }) {

@@ -65,0 +73,0 @@ return getState().connectedRendererIds.length > 0;

import { postSelectFixtureRequest } from './shared/postRequest.js';
export function onRouterFixtureReselect(context, fixtureId) {
const { connectedRendererIds } = context.getState();
const { connectedRendererIds, globalFixtureState } = context.getState();
connectedRendererIds.forEach(rendererId => {
postSelectFixtureRequest(context, rendererId, fixtureId, {});
postSelectFixtureRequest(context, rendererId, fixtureId, globalFixtureState);
});
}
import { postSelectFixtureRequest } from './shared/postRequest.js';
export function onRouterFixtureSelect(context, fixtureId) {
context.setState(prevState => ({ ...prevState, fixtureState: {} }), () => {
const { connectedRendererIds } = context.getState();
const { connectedRendererIds, globalFixtureState } = context.getState();
connectedRendererIds.forEach(rendererId => {
postSelectFixtureRequest(context, rendererId, fixtureId, {});
postSelectFixtureRequest(context, rendererId, fixtureId, globalFixtureState);
});
});
}
import { isEqual } from 'lodash-es';
import { postSelectFixtureRequest } from '../shared/postRequest.js';
import { postSelectFixtureRequest, postSetFixtureStateRequest, } from '../shared/postRequest.js';
export function receiveRendererReadyResponse(context, { payload }) {
const { rendererId } = payload;
const { connectedRendererIds: prevRendererIds } = context.getState();
const { connectedRendererIds: prevRendererIds, globalFixtureState } = context.getState();
context.setState(stateUpdater, afterStateChanged);

@@ -15,3 +15,3 @@ function stateUpdater(prevState) {

primaryRendererId,
fixtureState: rendererId === primaryRendererId ? {} : fixtureState,
fixtureState: rendererId === primaryRendererId ? globalFixtureState : fixtureState,
};

@@ -27,2 +27,7 @@ }

}
else if (rendererFixtureId) {
if (Object.keys(globalFixtureState).length > 0) {
postSetFixtureStateRequest(context, rendererId, rendererFixtureId, globalFixtureState);
}
}
// Notify about connected renderers that weren't connected before

@@ -29,0 +34,0 @@ if (!prevRendererIds.includes(rendererId)) {

@@ -1,3 +0,3 @@

import { FixtureState, StateUpdater } from 'react-cosmos-core';
import { FixtureStateChange } from 'react-cosmos-core';
import { RendererCoreContext } from './shared/index.js';
export declare function setFixtureState(context: RendererCoreContext, stateUpdater: StateUpdater<FixtureState>): void;
export declare function setFixtureState(context: RendererCoreContext, name: string, change: FixtureStateChange<unknown>): void;

@@ -0,4 +1,5 @@

import { updateFixtureState, } from 'react-cosmos-core';
import { postSetFixtureStateRequest } from './shared/postRequest.js';
import { getSelectedFixtureId } from './shared/router.js';
export function setFixtureState(context, stateUpdater) {
export function setFixtureState(context, name, change) {
const fixtureId = getSelectedFixtureId(context);

@@ -9,9 +10,9 @@ if (!fixtureId) {

}
context.setState(change, () => {
context.setState(stateUpdater, () => {
postRendererRequest(fixtureId);
});
function change(prevState) {
function stateUpdater(prevState) {
return {
...prevState,
fixtureState: stateUpdater(prevState.fixtureState),
fixtureState: updateFixtureState(prevState.fixtureState, name, change),
};

@@ -18,0 +19,0 @@ }

import { FixtureId, FixtureState, RendererId } from 'react-cosmos-core';
import { RendererCoreContext } from '../shared/index.js';
import { RendererCoreContext } from './index.js';
export declare function postReloadRendererRequest(context: RendererCoreContext, rendererId: RendererId): void;

@@ -4,0 +4,0 @@ export declare function postSelectFixtureRequest(context: RendererCoreContext, rendererId: RendererId, fixtureId: FixtureId, fixtureState: FixtureState): void;

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

import { FixtureList, FixtureState, MessageType, RendererId, StateUpdater } from 'react-cosmos-core';
import { FixtureList, FixtureState, FixtureStateChange, MessageType, RendererId } from 'react-cosmos-core';
export type GetFixtureState = <T>(name: string) => T | undefined;
export type SetFixtureStateByName = <T>(name: string, change: FixtureStateChange<T>) => void;
export type RendererCoreSpec = {

@@ -13,2 +15,3 @@ name: 'rendererCore';

fixtureState: FixtureState;
globalFixtureState: FixtureState;
};

@@ -20,8 +23,10 @@ methods: {

getFixtures(): FixtureList;
getFixtureState(): FixtureState;
isRendererConnected(): boolean;
reloadRenderer(): void;
setFixtureState(stateUpdater: StateUpdater<FixtureState>): void;
selectPrimaryRenderer(primaryRendererId: RendererId): void;
receiveResponse(msg: MessageType): void;
getAllFixtureState(): FixtureState;
getFixtureState: GetFixtureState;
setFixtureState: SetFixtureStateByName;
setGlobalFixtureState<T>(name: string, state: T): void;
};

@@ -28,0 +33,0 @@ events: {

@@ -30,7 +30,7 @@ import React from 'react';

setViewportState(pluginContext, { ...viewportState, enabled: false });
setFixtureStateViewport(pluginContext, null);
setViewportFixtureState(pluginContext, null);
}
else {
setViewportState(pluginContext, { ...viewportState, enabled: true });
setFixtureStateViewport(pluginContext, viewport);
setViewportFixtureState(pluginContext, viewport);
}

@@ -44,8 +44,6 @@ } }));

const viewportState = getViewportState(context);
return React.useCallback((viewportChange) => {
const viewport = typeof viewportChange === 'function'
? viewportChange(viewportState.viewport)
: viewportChange;
return React.useCallback((change) => {
const viewport = typeof change === 'function' ? change(viewportState.viewport) : change;
setViewportState(context, { ...viewportState, enabled: true, viewport });
setFixtureStateViewport(context, viewport);
setViewportFixtureState(context, viewport);
}, [context, viewportState]);

@@ -63,5 +61,5 @@ }

const rendererCore = getMethodsOf('rendererCore');
const fixtureState = rendererCore.getFixtureState();
return fixtureState.viewport
? { ...viewportState, enabled: true, viewport: fixtureState.viewport }
const viewport = rendererCore.getFixtureState('viewport');
return viewport
? { ...viewportState, enabled: true, viewport }
: viewportState;

@@ -74,9 +72,6 @@ }

}
function setFixtureStateViewport(context, viewport) {
function setViewportFixtureState(context, viewport) {
const { getMethodsOf } = context;
const rendererCore = getMethodsOf('rendererCore');
rendererCore.setFixtureState(fixtureState => ({
...fixtureState,
viewport,
}));
rendererCore.setFixtureState('viewport', viewport);
}
import React from 'react';
import { ResponsiveDevice, ResponsiveViewport } from '../spec.js';
import { Viewport } from 'react-cosmos-core';
import { ResponsiveDevice } from '../spec.js';
type Props = {
devices: ResponsiveDevice[];
selectedViewport: ResponsiveViewport;
selectedViewport: Viewport;
scaleFactor: number;
scaled: boolean;
selectViewport: (viewport: ResponsiveViewport) => unknown;
selectViewport: (viewport: Viewport) => unknown;
toggleScale: () => unknown;

@@ -10,0 +11,0 @@ };

import React, { Dispatch, ReactNode, SetStateAction } from 'react';
import { ResponsiveDevice, ResponsiveViewport } from '../spec.js';
import { Viewport } from 'react-cosmos-core';
import { ResponsiveDevice } from '../spec.js';
type Props = {

@@ -7,5 +8,5 @@ children?: ReactNode;

enabled: boolean;
viewport: ResponsiveViewport;
viewport: Viewport;
scaled: boolean;
setViewport: Dispatch<SetStateAction<ResponsiveViewport>>;
setViewport: Dispatch<SetStateAction<Viewport>>;
setScaled: (scaled: boolean) => unknown;

@@ -12,0 +13,0 @@ };

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

import { ResponsiveViewport } from '../spec.js';
import { Viewport } from 'react-cosmos-core';
export declare const responsivePreviewPadding: {

@@ -14,4 +14,4 @@ top: number;

export declare function getStyles({ container, viewport, scaled, }: {
container: ResponsiveViewport;
viewport: ResponsiveViewport;
container: Viewport;
viewport: Viewport;
scaled: boolean;

@@ -46,2 +46,2 @@ }): {

};
export declare function getViewportScaleFactor(viewport: ResponsiveViewport, container: ResponsiveViewport): number;
export declare function getViewportScaleFactor(viewport: Viewport, container: Viewport): number;

@@ -1,14 +0,11 @@

import { FixtureState } from 'react-cosmos-core';
import { Viewport } from 'react-cosmos-core';
import { PluginContext } from 'react-plugin';
import { StorageSpec } from '../Storage/spec.js';
import { ResponsivePreviewSpec, ResponsiveViewport } from './spec.js';
import { ResponsivePreviewSpec } from './spec.js';
export type ResponsivePreviewContext = PluginContext<ResponsivePreviewSpec>;
export type StorageMethods = StorageSpec['methods'];
export type FixtureStateWithViewport = FixtureState & {
viewport?: ResponsiveViewport;
};
export type ViewportState = {
enabled: boolean;
scaled: boolean;
viewport: ResponsiveViewport;
viewport: Viewport;
};

@@ -15,0 +12,0 @@ export declare const DEFAULT_DEVICES: {

@@ -1,6 +0,3 @@

export type ResponsiveViewport = {
width: number;
height: number;
};
export type ResponsiveDevice = ResponsiveViewport & {
import { Viewport } from 'react-cosmos-core';
export type ResponsiveDevice = Viewport & {
label: string;

@@ -7,0 +4,0 @@ };

@@ -52,3 +52,3 @@ import React from 'react';

const { sidePanelRowOrder, globalActionOrder, globalOrder, navRowOrder, fixtureActionOrder, rendererActionOrder, } = getConfig();
return (React.createElement(Root, { fixtureItems: fixtureItems, selectedFixtureId: router.getSelectedFixtureId(), rendererConnected: rendererCore.isRendererConnected(), fixtureState: rendererCore.getFixtureState(), navOpen: isNavOpen(pluginContext), panelOpen: isPanelOpen(pluginContext), navWidth: navWidth, panelWidth: panelWidth, sidePanelRowOrder: sidePanelRowOrder, globalActionOrder: globalActionOrder, globalOrder: globalOrder, navRowOrder: navRowOrder, fixtureActionOrder: fixtureActionOrder, rendererActionOrder: rendererActionOrder, onToggleNav: onToggleNav, onTogglePanel: onTogglePanel, onReloadRenderer: rendererCore.reloadRenderer, onCloseFixture: router.unselectFixture, onFixtureStateChange: rendererCore.setFixtureState, setNavWidth: setNavWidth, setPanelWidth: setPanelWidth, welcomeDismissed: welcomeDismiss.isWelcomeDismissed(), onDismissWelcome: welcomeDismiss.onDismissWelcome, onShowWelcome: welcomeDismiss.onShowWelcome }));
return (React.createElement(Root, { fixtureItems: fixtureItems, selectedFixtureId: router.getSelectedFixtureId(), rendererConnected: rendererCore.isRendererConnected(), getFixtureState: rendererCore.getFixtureState, setFixtureState: rendererCore.setFixtureState, navOpen: isNavOpen(pluginContext), panelOpen: isPanelOpen(pluginContext), navWidth: navWidth, panelWidth: panelWidth, sidePanelRowOrder: sidePanelRowOrder, globalActionOrder: globalActionOrder, globalOrder: globalOrder, navRowOrder: navRowOrder, fixtureActionOrder: fixtureActionOrder, rendererActionOrder: rendererActionOrder, onToggleNav: onToggleNav, onTogglePanel: onTogglePanel, onReloadRenderer: rendererCore.reloadRenderer, onCloseFixture: router.unselectFixture, setNavWidth: setNavWidth, setPanelWidth: setPanelWidth, welcomeDismissed: welcomeDismiss.isWelcomeDismissed(), onDismissWelcome: welcomeDismiss.onDismissWelcome, onShowWelcome: welcomeDismiss.onShowWelcome }));
});

@@ -55,0 +55,0 @@ export { register };

import React from 'react';
import { FixtureId, FixtureState, FlatFixtureTreeItem, StateUpdater } from 'react-cosmos-core';
import { FixtureId, FlatFixtureTreeItem } from 'react-cosmos-core';
import { GetFixtureState, SetFixtureStateByName } from '../RendererCore/spec.js';
type Props = {

@@ -7,3 +8,4 @@ fixtureItems: FlatFixtureTreeItem[];

rendererConnected: boolean;
fixtureState: FixtureState;
getFixtureState: GetFixtureState;
setFixtureState: SetFixtureStateByName;
navOpen: boolean;

@@ -23,3 +25,2 @@ panelOpen: boolean;

onCloseFixture: () => unknown;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
setNavWidth: (width: number) => unknown;

@@ -31,3 +32,3 @@ setPanelWidth: (width: number) => unknown;

};
export declare function Root({ fixtureItems, selectedFixtureId, rendererConnected, fixtureState, navOpen, panelOpen, navWidth, panelWidth, sidePanelRowOrder, globalActionOrder, globalOrder, navRowOrder, fixtureActionOrder, rendererActionOrder, onToggleNav, onTogglePanel, onReloadRenderer, onCloseFixture, onFixtureStateChange, setNavWidth, setPanelWidth, welcomeDismissed, onDismissWelcome, onShowWelcome, }: Props): React.JSX.Element;
export declare function Root({ fixtureItems, selectedFixtureId, rendererConnected, getFixtureState, setFixtureState, navOpen, panelOpen, navWidth, panelWidth, sidePanelRowOrder, globalActionOrder, globalOrder, navRowOrder, fixtureActionOrder, rendererActionOrder, onToggleNav, onTogglePanel, onReloadRenderer, onCloseFixture, setNavWidth, setPanelWidth, welcomeDismissed, onDismissWelcome, onShowWelcome, }: Props): React.JSX.Element;
export {};

@@ -11,3 +11,3 @@ import React from 'react';

import { SidePanel } from './SidePanel.js';
export function Root({ fixtureItems, selectedFixtureId, rendererConnected, fixtureState, navOpen, panelOpen, navWidth, panelWidth, sidePanelRowOrder, globalActionOrder, globalOrder, navRowOrder, fixtureActionOrder, rendererActionOrder, onToggleNav, onTogglePanel, onReloadRenderer, onCloseFixture, onFixtureStateChange, setNavWidth, setPanelWidth, welcomeDismissed, onDismissWelcome, onShowWelcome, }) {
export function Root({ fixtureItems, selectedFixtureId, rendererConnected, getFixtureState, setFixtureState, navOpen, panelOpen, navWidth, panelWidth, sidePanelRowOrder, globalActionOrder, globalOrder, navRowOrder, fixtureActionOrder, rendererActionOrder, onToggleNav, onTogglePanel, onReloadRenderer, onCloseFixture, setNavWidth, setPanelWidth, welcomeDismissed, onDismissWelcome, onShowWelcome, }) {
const navDrag = useDrag({

@@ -39,3 +39,3 @@ value: navWidth,

selectedFixtureId && panelOpen && (React.createElement(ControlPanelContainer, { style: { width: panelWidth, zIndex: 3 } },
React.createElement(SidePanel, { fixtureId: selectedFixtureId, fixtureState: fixtureState, sidePanelRowOrder: sidePanelRowOrder, onFixtureStateChange: onFixtureStateChange }),
React.createElement(SidePanel, { fixtureId: selectedFixtureId, getFixtureState: getFixtureState, setFixtureState: setFixtureState, sidePanelRowOrder: sidePanelRowOrder }),
panelDrag.dragging && React.createElement(DragOverlay, null),

@@ -42,0 +42,0 @@ React.createElement(PanelDragHandle, { ref: panelDrag.dragElRef })))),

import React from 'react';
import { FixtureId, FixtureState, StateUpdater } from 'react-cosmos-core';
import { FixtureId } from 'react-cosmos-core';
import { GetFixtureState, SetFixtureStateByName } from '../RendererCore/spec.js';
type Props = {
fixtureId: FixtureId;
fixtureState: FixtureState;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
getFixtureState: GetFixtureState;
setFixtureState: SetFixtureStateByName;
sidePanelRowOrder: string[];

@@ -8,0 +9,0 @@ };

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

import { grey32 } from '../../style/colors.js';
export const SidePanel = React.memo(function SidePanel({ fixtureId, fixtureState, onFixtureStateChange, sidePanelRowOrder, }) {
const slotProps = React.useMemo(() => ({ fixtureId, fixtureState, onFixtureStateChange }), [fixtureId, fixtureState, onFixtureStateChange]);
export const SidePanel = React.memo(function SidePanel({ fixtureId, getFixtureState, setFixtureState, sidePanelRowOrder, }) {
const slotProps = React.useMemo(() => ({ fixtureId, getFixtureState, setFixtureState }), [fixtureId, getFixtureState, setFixtureState]);
return (React.createElement(Container, null,

@@ -9,0 +9,0 @@ React.createElement(Content, null,

@@ -16,8 +16,5 @@ import React, { useCallback, useMemo } from 'react';

...fixtureState,
controls: {
...fixtureState.controls,
[controlName]: {
...control,
currentValue: updatedValues[controlName],
},
[controlName]: {
...control,
currentValue: updatedValues[controlName],
},

@@ -24,0 +21,0 @@ }));

import React from 'react';
import { FixtureStateControls } from 'react-cosmos-core';
import { ControlsFixtureState } from 'react-cosmos-core';
export type ControlActionSlotProps = {
controls: FixtureStateControls;
controls: ControlsFixtureState;
};

@@ -6,0 +6,0 @@ type Props = {

import React from 'react';
import { FixtureState, FixtureStateControl, StateUpdater } from 'react-cosmos-core';
export type ControlSlotProps<TControl extends FixtureStateControl> = {
import { ControlFixtureState, ControlsFixtureState, FixtureStateUpdater } from 'react-cosmos-core';
export type ControlSlotProps<TControl extends ControlFixtureState> = {
controlName: string;
control: TControl;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
onFixtureStateChange: (updater: FixtureStateUpdater<ControlsFixtureState>) => void;
};

@@ -8,0 +8,0 @@ type Props = {

import React from 'react';
import { FixtureId, FixtureState, StateUpdater } from 'react-cosmos-core';
import { FixtureId } from 'react-cosmos-core';
import { GetFixtureState, SetFixtureStateByName } from '../plugins/RendererCore/spec.js';
export type SidePanelRowSlotProps = {
fixtureId: FixtureId;
fixtureState: FixtureState;
onFixtureStateChange: (stateUpdater: StateUpdater<FixtureState>) => void;
getFixtureState: GetFixtureState;
setFixtureState: SetFixtureStateByName;
};

@@ -8,0 +9,0 @@ type Props = {

@@ -39,8 +39,10 @@ /// <reference types="jest" />

getFixtures(): import("react-cosmos-core").FixtureList;
getFixtureState(): import("react-cosmos-core").FixtureState;
isRendererConnected(): boolean;
reloadRenderer(): void;
setFixtureState(stateUpdater: import("react-cosmos-core").StateUpdater<import("react-cosmos-core").FixtureState>): void;
selectPrimaryRenderer(primaryRendererId: string): void;
receiveResponse(msg: import("react-cosmos-core").MessageType): void;
getAllFixtureState(): import("react-cosmos-core").FixtureState;
getFixtureState: import("../plugins/RendererCore/spec.js").GetFixtureState;
setFixtureState: import("../plugins/RendererCore/spec.js").SetFixtureStateByName;
setGlobalFixtureState<T>(name: string, state: T): void;
};

@@ -83,8 +85,10 @@ export declare function getNotificationsMethods(): {

getFixtures: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>) => import("react-cosmos-core").FixtureList);
getFixtureState: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>) => import("react-cosmos-core").FixtureState);
isRendererConnected: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>) => boolean);
reloadRenderer: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>) => void);
setFixtureState: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>, stateUpdater: import("react-cosmos-core").StateUpdater<import("react-cosmos-core").FixtureState>) => void);
selectPrimaryRenderer: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>, primaryRendererId: string) => void);
receiveResponse: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>, msg: import("react-cosmos-core").MessageType) => void);
getAllFixtureState: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>) => import("react-cosmos-core").FixtureState);
getFixtureState: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>, name: string) => unknown);
setFixtureState: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>, name: string, change: unknown) => void);
setGlobalFixtureState: jest.Mock<any, any, any> | ((context: import("react-plugin").PluginContext<RendererCoreSpec>, name: string, state: unknown) => void);
};

@@ -91,0 +95,0 @@ export declare function mockRendererPreview(methods?: MethodsOf<RendererPreviewSpec>): {

@@ -76,8 +76,10 @@ import { getPluginContext, } from 'react-plugin';

getFixtures: jest.fn(),
getFixtureState: jest.fn(),
isRendererConnected: jest.fn(),
reloadRenderer: jest.fn(),
setFixtureState: jest.fn(),
selectPrimaryRenderer: jest.fn(),
receiveResponse: jest.fn(),
getAllFixtureState: jest.fn(),
getFixtureState: jest.fn(),
setFixtureState: jest.fn(),
setGlobalFixtureState: jest.fn(),
...methods,

@@ -84,0 +86,0 @@ };

{
"name": "react-cosmos-ui",
"version": "6.0.0-beta.8",
"version": "6.0.0-beta.9",
"description": "React Cosmos UI",

@@ -18,3 +18,3 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-ui",

"lodash-es": "4.17.21",
"react-cosmos-core": "6.0.0-beta.8"
"react-cosmos-core": "6.0.0-beta.9"
},

@@ -27,3 +27,3 @@ "devDependencies": {

},
"gitHead": "2f47b29e24c6a68c4a62b7862d67909905648f7e"
"gitHead": "0cb520839737c38b295b2baefe0cef8702e31324"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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