react-cosmos-ui 6.0.0-beta.7 → 6.0.0-beta.9
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/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/playground.bundle.js +103 -103
- package/dist/playground.bundle.js.map +1 -1
- package/dist/playground.js +2 -2
- package/dist/pluginMocks.d.ts +1 -0
- package/dist/pluginMocks.js +1 -0
- package/dist/plugins/ClassStatePanel/ClassStatePanel/ComponentClassState.d.ts +5 -4
- package/dist/plugins/ClassStatePanel/ClassStatePanel/ComponentClassState.js +8 -8
- package/dist/plugins/ClassStatePanel/ClassStatePanel/index.d.ts +4 -3
- package/dist/plugins/ClassStatePanel/ClassStatePanel/index.js +5 -5
- package/dist/plugins/ClassStatePanel/ClassStatePanel/shared.d.ts +2 -2
- package/dist/plugins/ClassStatePanel/ClassStatePanel/shared.js +6 -9
- package/dist/plugins/ClassStatePanel/index.js +5 -3
- package/dist/plugins/ClassStatePanel/shared.d.ts +2 -0
- package/dist/plugins/ControlPanel/ControlPanel.d.ts +4 -3
- package/dist/plugins/ControlPanel/ControlPanel.js +3 -3
- package/dist/plugins/ControlPanel/index.js +4 -2
- package/dist/plugins/ControlPanel/shared.d.ts +2 -0
- package/dist/plugins/ControlPanel/shared.js +1 -0
- package/dist/plugins/ControlSelect/SelectValueInput.d.ts +3 -3
- package/dist/plugins/ControlSelect/index.js +3 -6
- package/dist/plugins/PropsPanel/PropsPanel/ComponentProps.d.ts +5 -4
- package/dist/plugins/PropsPanel/PropsPanel/ComponentProps.js +14 -12
- package/dist/plugins/PropsPanel/PropsPanel/index.d.ts +4 -3
- package/dist/plugins/PropsPanel/PropsPanel/index.js +5 -5
- package/dist/plugins/PropsPanel/PropsPanel/shared.d.ts +2 -2
- package/dist/plugins/PropsPanel/PropsPanel/shared.js +6 -9
- package/dist/plugins/PropsPanel/index.js +14 -9
- package/dist/plugins/PropsPanel/shared.d.ts +2 -0
- package/dist/plugins/RendererCore/index.js +11 -3
- package/dist/plugins/RendererCore/onRouterFixtureReselect.js +2 -2
- package/dist/plugins/RendererCore/onRouterFixtureSelect.js +2 -2
- package/dist/plugins/RendererCore/receiveResponse/rendererReady.js +8 -3
- package/dist/plugins/RendererCore/setFixtureState.d.ts +2 -2
- package/dist/plugins/RendererCore/setFixtureState.js +5 -4
- package/dist/plugins/RendererCore/setGlobalFixtureState.d.ts +2 -0
- package/dist/plugins/RendererCore/setGlobalFixtureState.js +15 -0
- package/dist/plugins/RendererCore/shared/postRequest.d.ts +1 -1
- package/dist/plugins/RendererCore/spec.d.ts +8 -3
- package/dist/plugins/ResponsivePreview/ResponsivePreview/ResponsiveHeader.d.ts +4 -3
- package/dist/plugins/ResponsivePreview/ResponsivePreview/ResponsivePreview.d.ts +4 -3
- package/dist/plugins/ResponsivePreview/ResponsivePreview/style.d.ts +4 -4
- package/dist/plugins/ResponsivePreview/index.js +10 -15
- package/dist/plugins/ResponsivePreview/shared.d.ts +3 -6
- package/dist/plugins/ResponsivePreview/spec.d.ts +2 -5
- package/dist/plugins/Root/Root.d.ts +5 -4
- package/dist/plugins/Root/Root.js +2 -2
- package/dist/plugins/Root/SidePanel.d.ts +4 -3
- package/dist/plugins/Root/SidePanel.js +2 -2
- package/dist/plugins/Root/index.js +1 -1
- package/dist/plugins/StandardControl/index.js +3 -6
- package/dist/slots/ControlActionSlot.d.ts +2 -2
- package/dist/slots/ControlSlot.d.ts +3 -3
- package/dist/slots/SidePanelRowSlot.d.ts +4 -3
- package/dist/testHelpers/pluginMocks.d.ts +8 -4
- package/dist/testHelpers/pluginMocks.js +4 -2
- package/package.json +8 -8
- package/pluginMocks.d.ts +1 -0
- package/pluginMocks.js +1 -0
package/dist/playground.js
CHANGED
|
@@ -13,14 +13,14 @@ window.ReactDom = ReactDom;
|
|
|
13
13
|
window.StyledComponents = styled;
|
|
14
14
|
export default async function mount({ playgroundConfig, pluginConfigs, }) {
|
|
15
15
|
const { loadPlugins, Slot } = ReactPlugin;
|
|
16
|
-
const config = { ...DEFAULT_PLUGIN_CONFIG, ...playgroundConfig };
|
|
17
|
-
loadPlugins({ config });
|
|
18
16
|
// We can make plugin loading unblocking if react-plugin exports the
|
|
19
17
|
// reloadPlugins method.
|
|
20
18
|
await Promise.all(pluginConfigs.map(async (pluginConfig) => {
|
|
21
19
|
if (pluginConfig.ui)
|
|
22
20
|
await loadPluginScript(pluginConfig.ui);
|
|
23
21
|
}));
|
|
22
|
+
const config = { ...DEFAULT_PLUGIN_CONFIG, ...playgroundConfig };
|
|
23
|
+
loadPlugins({ config });
|
|
24
24
|
const root = ReactDom.createRoot(document.getElementById('root'));
|
|
25
25
|
root.render(React.createElement(React.Fragment, null,
|
|
26
26
|
React.createElement(GlobalStyle, null),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './testHelpers/pluginMocks.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './testHelpers/pluginMocks.js';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ClassStateFixtureStateItem } from 'react-cosmos-core';
|
|
3
3
|
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
|
|
4
|
+
import { SetClassStateFixtureState } from '../shared.js';
|
|
4
5
|
type Props = {
|
|
5
|
-
|
|
6
|
+
classStateFsItem: ClassStateFixtureStateItem;
|
|
6
7
|
fixtureExpansion: FixtureExpansion;
|
|
7
|
-
onFixtureStateChange:
|
|
8
|
+
onFixtureStateChange: SetClassStateFixtureState;
|
|
8
9
|
onElementExpansionChange: OnElementExpansionChange;
|
|
9
10
|
};
|
|
10
|
-
export declare function ComponentClassState({
|
|
11
|
+
export declare function ComponentClassState({ classStateFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }: Props): React.JSX.Element;
|
|
11
12
|
export {};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { isEqual } from 'lodash-es';
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { updateClassStateFixtureStateItem, } from 'react-cosmos-core';
|
|
4
4
|
import { SidePanelActions, SidePanelBody, SidePanelContainer, SidePanelHeader, SidePanelTitle, } from '../../../components/SidePanel.js';
|
|
5
5
|
import { ExpandCollapseValues } from '../../../components/ValueInputTree/ExpandCollapseValues.js';
|
|
6
6
|
import { ValueInputTree, stringifyElementId, } from '../../../components/ValueInputTree/index.js';
|
|
7
7
|
import { IconButton32 } from '../../../components/buttons/index.js';
|
|
8
8
|
import { RotateCcwIcon } from '../../../components/icons/index.js';
|
|
9
|
-
import {
|
|
10
|
-
export function ComponentClassState({
|
|
11
|
-
const { componentName, elementId, values } =
|
|
9
|
+
import { classStateFsItemUpdater } from './shared.js';
|
|
10
|
+
export function ComponentClassState({ classStateFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
|
|
11
|
+
const { componentName, elementId, values } = classStateFsItem;
|
|
12
12
|
const [initialValues] = React.useState(() => values);
|
|
13
|
-
const handleValuesReset = React.useCallback(() => onFixtureStateChange(
|
|
14
|
-
|
|
13
|
+
const handleValuesReset = React.useCallback(() => onFixtureStateChange(classStateFsItemUpdater(elementId, prevFs => updateClassStateFixtureStateItem({
|
|
14
|
+
classStateFs: prevFs,
|
|
15
15
|
elementId,
|
|
16
16
|
values: initialValues,
|
|
17
17
|
}))), [elementId, initialValues, onFixtureStateChange]);
|
|
18
18
|
const handleValueChange = React.useCallback((newValues) => {
|
|
19
|
-
onFixtureStateChange(
|
|
20
|
-
|
|
19
|
+
onFixtureStateChange(classStateFsItemUpdater(elementId, prevFs => updateClassStateFixtureStateItem({
|
|
20
|
+
classStateFs: prevFs,
|
|
21
21
|
elementId,
|
|
22
22
|
values: newValues,
|
|
23
23
|
})));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ClassStateFixtureState } from 'react-cosmos-core';
|
|
3
3
|
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
|
|
4
|
+
import { SetClassStateFixtureState } from '../shared.js';
|
|
4
5
|
type Props = {
|
|
5
|
-
fixtureState:
|
|
6
|
+
fixtureState: ClassStateFixtureState | undefined;
|
|
6
7
|
fixtureExpansion: FixtureExpansion;
|
|
7
|
-
onFixtureStateChange:
|
|
8
|
+
onFixtureStateChange: SetClassStateFixtureState;
|
|
8
9
|
onElementExpansionChange: OnElementExpansionChange;
|
|
9
10
|
};
|
|
10
11
|
export declare const ClassStatePanel: React.NamedExoticComponent<Props>;
|
|
@@ -2,12 +2,12 @@ import React from 'react';
|
|
|
2
2
|
import { hasFsValues, sortFsValueGroups, stringifyElementId, } from '../../../components/ValueInputTree/index.js';
|
|
3
3
|
import { ComponentClassState } from './ComponentClassState.js';
|
|
4
4
|
export const ClassStatePanel = React.memo(function ClassStatePanel({ fixtureState, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
|
|
5
|
-
if (!fixtureState
|
|
5
|
+
if (!fixtureState) {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
const classStateWithValues = fixtureState.
|
|
9
|
-
return (React.createElement(React.Fragment, null, sortFsValueGroups(classStateWithValues).map(
|
|
10
|
-
const strElementId = stringifyElementId(
|
|
11
|
-
return (React.createElement(ComponentClassState, { key: strElementId,
|
|
8
|
+
const classStateWithValues = fixtureState.filter(hasFsValues);
|
|
9
|
+
return (React.createElement(React.Fragment, null, sortFsValueGroups(classStateWithValues).map(fsItem => {
|
|
10
|
+
const strElementId = stringifyElementId(fsItem.elementId);
|
|
11
|
+
return (React.createElement(ComponentClassState, { key: strElementId, classStateFsItem: fsItem, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
|
|
12
12
|
})));
|
|
13
13
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function
|
|
1
|
+
import { ClassStateFixtureState, FixtureElementId, FixtureStateUpdater } from 'react-cosmos-core';
|
|
2
|
+
export declare function classStateFsItemUpdater(elementId: FixtureElementId, cb: FixtureStateUpdater<ClassStateFixtureState>): FixtureStateUpdater<ClassStateFixtureState>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findClassStateFixtureStateItem, } from 'react-cosmos-core';
|
|
2
2
|
import { stringifyElementId } from '../../../components/ValueInputTree/index.js';
|
|
3
|
-
export function
|
|
3
|
+
export function classStateFsItemUpdater(elementId, cb) {
|
|
4
4
|
return prevFs => {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
5
|
+
const fsItem = findClassStateFixtureStateItem(prevFs, elementId);
|
|
6
|
+
if (!fsItem) {
|
|
7
7
|
const elId = stringifyElementId(elementId);
|
|
8
8
|
console.warn(`Trying to update missing element with ID: ${elId}`);
|
|
9
|
-
return prevFs;
|
|
9
|
+
return prevFs ?? [];
|
|
10
10
|
}
|
|
11
|
-
return
|
|
12
|
-
...prevFs,
|
|
13
|
-
classState: cb(prevFs),
|
|
14
|
-
};
|
|
11
|
+
return cb(prevFs);
|
|
15
12
|
};
|
|
16
13
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import { createPlugin } from 'react-plugin';
|
|
3
3
|
import { getFixtureExpansion, updateElementExpansion, } from '../../components/ValueInputTree/index.js';
|
|
4
4
|
import { ClassStatePanel } from './ClassStatePanel/index.js';
|
|
5
|
-
import { CLASS_STATE_TREE_EXPANSION_STORAGE_KEY } from './shared.js';
|
|
5
|
+
import { CLASS_STATE_TREE_EXPANSION_STORAGE_KEY, } from './shared.js';
|
|
6
6
|
const { namedPlug, register } = createPlugin({
|
|
7
7
|
name: 'classStatePanel',
|
|
8
8
|
});
|
|
9
9
|
namedPlug('sidePanelRow', 'classState', ({ pluginContext, slotProps }) => {
|
|
10
|
-
const { fixtureId,
|
|
10
|
+
const { fixtureId, getFixtureState, setFixtureState } = slotProps;
|
|
11
11
|
const { fixtureExpansion, onElementExpansionChange } = useFixtureExpansion(pluginContext, fixtureId);
|
|
12
|
+
const fixtureState = getFixtureState('classState');
|
|
13
|
+
const onFixtureStateChange = useCallback(update => setFixtureState('classState', update), [setFixtureState]);
|
|
12
14
|
return (React.createElement(ClassStatePanel, { fixtureState: fixtureState, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
|
|
13
15
|
});
|
|
14
16
|
export { register };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ControlsFixtureState } from 'react-cosmos-core';
|
|
3
|
+
import { SetControlsFixtureState } from './shared.js';
|
|
3
4
|
type Props = {
|
|
4
|
-
fixtureState:
|
|
5
|
+
fixtureState: ControlsFixtureState | undefined;
|
|
5
6
|
controlActionOrder: string[];
|
|
6
|
-
onFixtureStateChange:
|
|
7
|
+
onFixtureStateChange: SetControlsFixtureState;
|
|
7
8
|
};
|
|
8
9
|
export declare function ControlPanel({ fixtureState, controlActionOrder, onFixtureStateChange, }: Props): React.JSX.Element | null;
|
|
9
10
|
export {};
|
|
@@ -7,7 +7,7 @@ import { ControlActionSlot } from '../../slots/ControlActionSlot.js';
|
|
|
7
7
|
import { ControlSlot } from '../../slots/ControlSlot.js';
|
|
8
8
|
export function ControlPanel({ fixtureState, controlActionOrder, onFixtureStateChange, }) {
|
|
9
9
|
const handleControlsReset = React.useCallback(() => onFixtureStateChange(resetControls), [onFixtureStateChange]);
|
|
10
|
-
const controls = fixtureState
|
|
10
|
+
const controls = fixtureState ?? {};
|
|
11
11
|
if (Object.keys(controls).length === 0)
|
|
12
12
|
return null;
|
|
13
13
|
return (React.createElement(SidePanelContainer, null,
|
|
@@ -26,11 +26,11 @@ function areControlsUnchanged(controls) {
|
|
|
26
26
|
return Object.keys(controls).every(controlName => isEqual(controls[controlName].currentValue, controls[controlName].defaultValue));
|
|
27
27
|
}
|
|
28
28
|
function resetControls(fixtureState) {
|
|
29
|
-
const controls = fixtureState
|
|
29
|
+
const controls = fixtureState ? { ...fixtureState } : {};
|
|
30
30
|
Object.keys(controls).forEach(controlName => {
|
|
31
31
|
controls[controlName] = resetControl(controls[controlName]);
|
|
32
32
|
});
|
|
33
|
-
return
|
|
33
|
+
return controls;
|
|
34
34
|
}
|
|
35
35
|
function resetControl(control) {
|
|
36
36
|
return { ...control, currentValue: control.defaultValue };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import { createPlugin } from 'react-plugin';
|
|
3
3
|
import { ControlPanel } from './ControlPanel.js';
|
|
4
4
|
const { namedPlug, register } = createPlugin({
|
|
@@ -9,7 +9,9 @@ const { namedPlug, register } = createPlugin({
|
|
|
9
9
|
});
|
|
10
10
|
namedPlug('sidePanelRow', 'values', ({ pluginContext, slotProps }) => {
|
|
11
11
|
const { controlActionOrder } = pluginContext.getConfig();
|
|
12
|
-
const {
|
|
12
|
+
const { getFixtureState, setFixtureState } = slotProps;
|
|
13
|
+
const fixtureState = getFixtureState('controls');
|
|
14
|
+
const onFixtureStateChange = useCallback(update => setFixtureState('controls', update), [setFixtureState]);
|
|
13
15
|
return (React.createElement(ControlPanel, { fixtureState: fixtureState, controlActionOrder: controlActionOrder, onFixtureStateChange: onFixtureStateChange }));
|
|
14
16
|
});
|
|
15
17
|
export { register };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SelectControlFixtureState } from 'react-cosmos-core';
|
|
3
3
|
type Props = {
|
|
4
4
|
name: string;
|
|
5
|
-
control:
|
|
6
|
-
onChange: (name: string, select:
|
|
5
|
+
control: SelectControlFixtureState;
|
|
6
|
+
onChange: (name: string, select: SelectControlFixtureState) => unknown;
|
|
7
7
|
};
|
|
8
8
|
export declare function SelectValueInput({ name, control, onChange }: Props): React.JSX.Element;
|
|
9
9
|
export {};
|
|
@@ -7,12 +7,9 @@ const { plug, register } = createPlugin({
|
|
|
7
7
|
plug('control-select', ({ slotProps }) => {
|
|
8
8
|
const { controlName, control, onFixtureStateChange } = slotProps;
|
|
9
9
|
const handleChange = useCallback((selectName, updatedControl) => {
|
|
10
|
-
onFixtureStateChange(
|
|
11
|
-
...
|
|
12
|
-
|
|
13
|
-
...fixtureState.controls,
|
|
14
|
-
[selectName]: updatedControl,
|
|
15
|
-
},
|
|
10
|
+
onFixtureStateChange(prevFs => ({
|
|
11
|
+
...prevFs,
|
|
12
|
+
[selectName]: updatedControl,
|
|
16
13
|
}));
|
|
17
14
|
}, [onFixtureStateChange]);
|
|
18
15
|
return (React.createElement(SelectValueInput, { key: controlName, name: controlName, control: control, onChange: handleChange }));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { PropsFixtureStateItem } from 'react-cosmos-core';
|
|
3
3
|
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
|
|
4
|
+
import { SetPropsFixtureState } from '../shared.js';
|
|
4
5
|
type Props = {
|
|
5
|
-
|
|
6
|
+
propsFsItem: PropsFixtureStateItem;
|
|
6
7
|
fixtureExpansion: FixtureExpansion;
|
|
7
|
-
onFixtureStateChange:
|
|
8
|
+
onFixtureStateChange: SetPropsFixtureState;
|
|
8
9
|
onElementExpansionChange: OnElementExpansionChange;
|
|
9
10
|
};
|
|
10
|
-
export declare function ComponentProps({
|
|
11
|
+
export declare function ComponentProps({ propsFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }: Props): React.JSX.Element;
|
|
11
12
|
export {};
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { isEqual } from 'lodash-es';
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { IconButton32 } from '../../../components/buttons/index.js';
|
|
5
|
-
import { CopyIcon, RotateCcwIcon } from '../../../components/icons/index.js';
|
|
3
|
+
import { resetPropsFixtureStateItem, updatePropsFixtureStateItem, } from 'react-cosmos-core';
|
|
6
4
|
import { SidePanelActions, SidePanelBody, SidePanelContainer, SidePanelHeader, SidePanelTitle, } from '../../../components/SidePanel.js';
|
|
7
5
|
import { ExpandCollapseValues } from '../../../components/ValueInputTree/ExpandCollapseValues.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import { ValueInputTree, stringifyElementId, } from '../../../components/ValueInputTree/index.js';
|
|
7
|
+
import { IconButton32 } from '../../../components/buttons/index.js';
|
|
8
|
+
import { CopyIcon, RotateCcwIcon } from '../../../components/icons/index.js';
|
|
9
|
+
import { propsFsItemUpdater } from './shared.js';
|
|
10
|
+
export function ComponentProps({ propsFsItem, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
|
|
11
|
+
const { componentName, elementId, values } = propsFsItem;
|
|
12
12
|
const [reset, setReset] = React.useState(true);
|
|
13
13
|
const handleResetToggle = React.useCallback(() => setReset(!reset), [reset]);
|
|
14
14
|
const [initialValues] = React.useState(() => values);
|
|
15
|
-
const handleValuesReset = React.useCallback(() => onFixtureStateChange(
|
|
16
|
-
|
|
15
|
+
const handleValuesReset = React.useCallback(() => onFixtureStateChange(propsFsItemUpdater(elementId, prevFs => resetPropsFixtureStateItem({
|
|
16
|
+
propsFs: prevFs,
|
|
17
17
|
elementId,
|
|
18
18
|
values: initialValues,
|
|
19
19
|
}))), [elementId, initialValues, onFixtureStateChange]);
|
|
20
20
|
const handleValueChange = React.useCallback((newValues) => {
|
|
21
|
-
const changeFn = reset
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const changeFn = reset
|
|
22
|
+
? resetPropsFixtureStateItem
|
|
23
|
+
: updatePropsFixtureStateItem;
|
|
24
|
+
onFixtureStateChange(propsFsItemUpdater(elementId, prevFs => changeFn({
|
|
25
|
+
propsFs: prevFs,
|
|
24
26
|
elementId,
|
|
25
27
|
values: newValues,
|
|
26
28
|
})));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { PropsFixtureState } from 'react-cosmos-core';
|
|
3
3
|
import { FixtureExpansion, OnElementExpansionChange } from '../../../components/ValueInputTree/index.js';
|
|
4
|
+
import { SetPropsFixtureState } from '../shared.js';
|
|
4
5
|
type Props = {
|
|
5
|
-
fixtureState:
|
|
6
|
+
fixtureState: PropsFixtureState | undefined;
|
|
6
7
|
fixtureExpansion: FixtureExpansion;
|
|
7
|
-
onFixtureStateChange:
|
|
8
|
+
onFixtureStateChange: SetPropsFixtureState;
|
|
8
9
|
onElementExpansionChange: OnElementExpansionChange;
|
|
9
10
|
};
|
|
10
11
|
export declare const PropsPanel: React.NamedExoticComponent<Props>;
|
|
@@ -2,12 +2,12 @@ import React from 'react';
|
|
|
2
2
|
import { hasFsValues, sortFsValueGroups, stringifyElementId, } from '../../../components/ValueInputTree/index.js';
|
|
3
3
|
import { ComponentProps } from './ComponentProps.js';
|
|
4
4
|
export const PropsPanel = React.memo(function PropsPanel({ fixtureState, fixtureExpansion, onFixtureStateChange, onElementExpansionChange, }) {
|
|
5
|
-
if (!fixtureState
|
|
5
|
+
if (!fixtureState) {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
const propsWithValues = fixtureState.
|
|
9
|
-
return (React.createElement(React.Fragment, null, sortFsValueGroups(propsWithValues).map(
|
|
10
|
-
const strElementId = stringifyElementId(
|
|
11
|
-
return (React.createElement(ComponentProps, { key: strElementId,
|
|
8
|
+
const propsWithValues = fixtureState.filter(hasFsValues);
|
|
9
|
+
return (React.createElement(React.Fragment, null, sortFsValueGroups(propsWithValues).map(fsItem => {
|
|
10
|
+
const strElementId = stringifyElementId(fsItem.elementId);
|
|
11
|
+
return (React.createElement(ComponentProps, { key: strElementId, propsFsItem: fsItem, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
|
|
12
12
|
})));
|
|
13
13
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FixtureElementId,
|
|
2
|
-
export declare function
|
|
1
|
+
import { FixtureElementId, FixtureStateUpdater, PropsFixtureState } from 'react-cosmos-core';
|
|
2
|
+
export declare function propsFsItemUpdater(elementId: FixtureElementId, cb: FixtureStateUpdater<PropsFixtureState>): FixtureStateUpdater<PropsFixtureState>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findPropsFixtureStateItem, } from 'react-cosmos-core';
|
|
2
2
|
import { stringifyElementId } from '../../../components/ValueInputTree/index.js';
|
|
3
|
-
export function
|
|
3
|
+
export function propsFsItemUpdater(elementId, cb) {
|
|
4
4
|
return prevFs => {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
5
|
+
const fsItem = findPropsFixtureStateItem(prevFs, elementId);
|
|
6
|
+
if (!fsItem) {
|
|
7
7
|
const elId = stringifyElementId(elementId);
|
|
8
8
|
console.warn(`Trying to update missing element with ID: ${elId}`);
|
|
9
|
-
return prevFs;
|
|
9
|
+
return prevFs ?? [];
|
|
10
10
|
}
|
|
11
|
-
return
|
|
12
|
-
...prevFs,
|
|
13
|
-
props: cb(prevFs),
|
|
14
|
-
};
|
|
11
|
+
return cb(prevFs);
|
|
15
12
|
};
|
|
16
13
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import { createPlugin } from 'react-plugin';
|
|
3
3
|
import { getFixtureExpansion, hasFsValues, updateElementExpansion, } from '../../components/ValueInputTree/index.js';
|
|
4
4
|
import { BlankState } from './BlankState.js';
|
|
5
5
|
import { PropsPanel } from './PropsPanel/index.js';
|
|
6
|
-
import { PROPS_TREE_EXPANSION_STORAGE_KEY } from './shared.js';
|
|
6
|
+
import { PROPS_TREE_EXPANSION_STORAGE_KEY, } from './shared.js';
|
|
7
7
|
const { namedPlug, register } = createPlugin({
|
|
8
8
|
name: 'propsPanel',
|
|
9
9
|
});
|
|
10
10
|
namedPlug('sidePanelRow', 'props', ({ pluginContext, slotProps }) => {
|
|
11
|
-
const { fixtureId,
|
|
11
|
+
const { fixtureId, getFixtureState, setFixtureState } = slotProps;
|
|
12
12
|
const { fixtureExpansion, onElementExpansionChange } = useFixtureExpansion(pluginContext, fixtureId);
|
|
13
|
+
const fixtureState = getFixtureState('props');
|
|
14
|
+
const onFixtureStateChange = useCallback(change => setFixtureState('props', change), [setFixtureState]);
|
|
13
15
|
return (React.createElement(PropsPanel, { fixtureState: fixtureState, fixtureExpansion: fixtureExpansion, onFixtureStateChange: onFixtureStateChange, onElementExpansionChange: onElementExpansionChange }));
|
|
14
16
|
});
|
|
15
17
|
// WARNING: This plug has to be aware of all control types and only show up
|
|
@@ -17,8 +19,8 @@ namedPlug('sidePanelRow', 'props', ({ pluginContext, slotProps }) => {
|
|
|
17
19
|
// TODO: Replace this with a more generic blank state (controls in general not
|
|
18
20
|
// just props)
|
|
19
21
|
namedPlug('sidePanelRow', 'blankState', ({ slotProps }) => {
|
|
20
|
-
const {
|
|
21
|
-
return shouldShowBlankState(
|
|
22
|
+
const { getFixtureState } = slotProps;
|
|
23
|
+
return shouldShowBlankState(getFixtureState) ? React.createElement(BlankState, null) : null;
|
|
22
24
|
});
|
|
23
25
|
export { register };
|
|
24
26
|
if (process.env.NODE_ENV !== 'test')
|
|
@@ -38,14 +40,17 @@ function useFixtureExpansion(context, fixtureId) {
|
|
|
38
40
|
onElementExpansionChange,
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
|
-
function shouldShowBlankState(
|
|
42
|
-
const
|
|
43
|
+
function shouldShowBlankState(getFixtureState) {
|
|
44
|
+
const props = getFixtureState('props');
|
|
45
|
+
const hasProps = props && props.some(hasFsValues);
|
|
43
46
|
if (hasProps)
|
|
44
47
|
return false;
|
|
45
|
-
const
|
|
48
|
+
const classState = getFixtureState('classState');
|
|
49
|
+
const hasClassState = classState && classState.some(hasFsValues);
|
|
46
50
|
if (hasClassState)
|
|
47
51
|
return false;
|
|
48
|
-
const
|
|
52
|
+
const controls = getFixtureState('controls');
|
|
53
|
+
const hasControls = controls && Object.keys(controls).length > 0;
|
|
49
54
|
if (hasControls)
|
|
50
55
|
return false;
|
|
51
56
|
return true;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fixtureStateByName } from 'react-cosmos-core';
|
|
1
2
|
import { createPlugin } from 'react-plugin';
|
|
2
3
|
import { onRouterFixtureReselect } from './onRouterFixtureReselect.js';
|
|
3
4
|
import { onRouterFixtureSelect } from './onRouterFixtureSelect.js';
|
|
@@ -5,6 +6,7 @@ import { onRouterFixtureUnselect } from './onRouterFixtureUnselect.js';
|
|
|
5
6
|
import { receiveResponse } from './receiveResponse/index.js';
|
|
6
7
|
import { reloadRenderer } from './reloadRenderer.js';
|
|
7
8
|
import { setFixtureState } from './setFixtureState.js';
|
|
9
|
+
import { setGlobalFixtureState } from './setGlobalFixtureState.js';
|
|
8
10
|
const { on, register, onLoad } = createPlugin({
|
|
9
11
|
name: 'rendererCore',
|
|
10
12
|
defaultConfig: {
|
|
@@ -16,18 +18,21 @@ const { on, register, onLoad } = createPlugin({
|
|
|
16
18
|
primaryRendererId: null,
|
|
17
19
|
fixtures: {},
|
|
18
20
|
fixtureState: {},
|
|
21
|
+
globalFixtureState: {},
|
|
19
22
|
},
|
|
20
23
|
methods: {
|
|
21
24
|
getRendererUrl,
|
|
22
25
|
getConnectedRendererIds,
|
|
23
26
|
getPrimaryRendererId,
|
|
24
27
|
getFixtures,
|
|
25
|
-
getFixtureState,
|
|
26
28
|
isRendererConnected,
|
|
27
29
|
reloadRenderer,
|
|
28
|
-
setFixtureState,
|
|
29
30
|
selectPrimaryRenderer,
|
|
30
31
|
receiveResponse,
|
|
32
|
+
getAllFixtureState,
|
|
33
|
+
getFixtureState,
|
|
34
|
+
setFixtureState,
|
|
35
|
+
setGlobalFixtureState,
|
|
31
36
|
},
|
|
32
37
|
});
|
|
33
38
|
onLoad(({ getConfig, setState }) => {
|
|
@@ -54,9 +59,12 @@ function getPrimaryRendererId({ getState }) {
|
|
|
54
59
|
function getFixtures({ getState }) {
|
|
55
60
|
return getState().fixtures;
|
|
56
61
|
}
|
|
57
|
-
function
|
|
62
|
+
function getAllFixtureState({ getState }) {
|
|
58
63
|
return getState().fixtureState;
|
|
59
64
|
}
|
|
65
|
+
function getFixtureState({ getState }, name) {
|
|
66
|
+
return fixtureStateByName(getState().fixtureState, name);
|
|
67
|
+
}
|
|
60
68
|
function isRendererConnected({ getState }) {
|
|
61
69
|
return getState().connectedRendererIds.length > 0;
|
|
62
70
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { postSelectFixtureRequest } from './shared/postRequest.js';
|
|
2
2
|
export function onRouterFixtureReselect(context, fixtureId) {
|
|
3
|
-
const { connectedRendererIds } = context.getState();
|
|
3
|
+
const { connectedRendererIds, globalFixtureState } = context.getState();
|
|
4
4
|
connectedRendererIds.forEach(rendererId => {
|
|
5
|
-
postSelectFixtureRequest(context, rendererId, fixtureId,
|
|
5
|
+
postSelectFixtureRequest(context, rendererId, fixtureId, globalFixtureState);
|
|
6
6
|
});
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { postSelectFixtureRequest } from './shared/postRequest.js';
|
|
2
2
|
export function onRouterFixtureSelect(context, fixtureId) {
|
|
3
3
|
context.setState(prevState => ({ ...prevState, fixtureState: {} }), () => {
|
|
4
|
-
const { connectedRendererIds } = context.getState();
|
|
4
|
+
const { connectedRendererIds, globalFixtureState } = context.getState();
|
|
5
5
|
connectedRendererIds.forEach(rendererId => {
|
|
6
|
-
postSelectFixtureRequest(context, rendererId, fixtureId,
|
|
6
|
+
postSelectFixtureRequest(context, rendererId, fixtureId, globalFixtureState);
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isEqual } from 'lodash-es';
|
|
2
|
-
import { postSelectFixtureRequest } from '../shared/postRequest.js';
|
|
2
|
+
import { postSelectFixtureRequest, postSetFixtureStateRequest, } from '../shared/postRequest.js';
|
|
3
3
|
export function receiveRendererReadyResponse(context, { payload }) {
|
|
4
4
|
const { rendererId } = payload;
|
|
5
|
-
const { connectedRendererIds: prevRendererIds } = context.getState();
|
|
5
|
+
const { connectedRendererIds: prevRendererIds, globalFixtureState } = context.getState();
|
|
6
6
|
context.setState(stateUpdater, afterStateChanged);
|
|
7
7
|
function stateUpdater(prevState) {
|
|
8
8
|
// The first announced renderer becomes the primary one
|
|
@@ -12,7 +12,7 @@ export function receiveRendererReadyResponse(context, { payload }) {
|
|
|
12
12
|
...prevState,
|
|
13
13
|
connectedRendererIds: addToSet(connectedRendererIds, rendererId),
|
|
14
14
|
primaryRendererId,
|
|
15
|
-
fixtureState: rendererId === primaryRendererId ?
|
|
15
|
+
fixtureState: rendererId === primaryRendererId ? globalFixtureState : fixtureState,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
function afterStateChanged() {
|
|
@@ -23,6 +23,11 @@ export function receiveRendererReadyResponse(context, { payload }) {
|
|
|
23
23
|
const { fixtureState } = context.getState();
|
|
24
24
|
postSelectFixtureRequest(context, rendererId, routerFixtureId, fixtureState);
|
|
25
25
|
}
|
|
26
|
+
else if (rendererFixtureId) {
|
|
27
|
+
if (Object.keys(globalFixtureState).length > 0) {
|
|
28
|
+
postSetFixtureStateRequest(context, rendererId, rendererFixtureId, globalFixtureState);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
26
31
|
// Notify about connected renderers that weren't connected before
|
|
27
32
|
if (!prevRendererIds.includes(rendererId)) {
|
|
28
33
|
notifyRendererConnection(context, rendererId);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FixtureStateChange } from 'react-cosmos-core';
|
|
2
2
|
import { RendererCoreContext } from './shared/index.js';
|
|
3
|
-
export declare function setFixtureState(context: RendererCoreContext,
|
|
3
|
+
export declare function setFixtureState(context: RendererCoreContext, name: string, change: FixtureStateChange<unknown>): void;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { updateFixtureState, } from 'react-cosmos-core';
|
|
1
2
|
import { postSetFixtureStateRequest } from './shared/postRequest.js';
|
|
2
3
|
import { getSelectedFixtureId } from './shared/router.js';
|
|
3
|
-
export function setFixtureState(context,
|
|
4
|
+
export function setFixtureState(context, name, change) {
|
|
4
5
|
const fixtureId = getSelectedFixtureId(context);
|
|
5
6
|
if (!fixtureId) {
|
|
6
7
|
console.warn('[Renderer] Trying to set fixture state with no fixture selected');
|
|
7
8
|
return;
|
|
8
9
|
}
|
|
9
|
-
context.setState(
|
|
10
|
+
context.setState(stateUpdater, () => {
|
|
10
11
|
postRendererRequest(fixtureId);
|
|
11
12
|
});
|
|
12
|
-
function
|
|
13
|
+
function stateUpdater(prevState) {
|
|
13
14
|
return {
|
|
14
15
|
...prevState,
|
|
15
|
-
fixtureState:
|
|
16
|
+
fixtureState: updateFixtureState(prevState.fixtureState, name, change),
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
function postRendererRequest(selectedFixtureId) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { setFixtureState } from './setFixtureState.js';
|
|
2
|
+
import { getSelectedFixtureId } from './shared/router.js';
|
|
3
|
+
export function setGlobalFixtureState(context, name, state) {
|
|
4
|
+
context.setState(prevState => ({
|
|
5
|
+
...prevState,
|
|
6
|
+
globalFixtureState: {
|
|
7
|
+
...prevState.globalFixtureState,
|
|
8
|
+
[name]: state,
|
|
9
|
+
},
|
|
10
|
+
}));
|
|
11
|
+
const fixtureId = getSelectedFixtureId(context);
|
|
12
|
+
if (fixtureId) {
|
|
13
|
+
setFixtureState(context, name, state);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FixtureId, FixtureState, RendererId } from 'react-cosmos-core';
|
|
2
|
-
import { RendererCoreContext } from '
|
|
2
|
+
import { RendererCoreContext } from './index.js';
|
|
3
3
|
export declare function postReloadRendererRequest(context: RendererCoreContext, rendererId: RendererId): void;
|
|
4
4
|
export declare function postSelectFixtureRequest(context: RendererCoreContext, rendererId: RendererId, fixtureId: FixtureId, fixtureState: FixtureState): void;
|
|
5
5
|
export declare function postUnselectFixtureRequest(context: RendererCoreContext, rendererId: RendererId): void;
|