react-cosmos-renderer 6.0.4-canary.a484ae0.0 → 6.1.0
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/client.d.ts +4 -2
- package/dist/client.js +4 -2
- package/dist/fixture/useFixtureInput/useCurrentInputValue.d.ts +1 -0
- package/dist/fixture/useFixtureInput/useCurrentInputValue.js +11 -0
- package/dist/fixture/useFixtureInput/useFixtureInput.d.ts +2 -0
- package/dist/fixture/useFixtureInput/useFixtureInput.js +9 -0
- package/dist/fixture/useFixtureInput/useInputFixtureState.d.ts +1 -0
- package/dist/fixture/{useValue/useCreateFixtureState.js → useFixtureInput/useInputFixtureState.js} +6 -6
- package/dist/fixture/useFixtureInput/useSetInputValue.d.ts +2 -0
- package/dist/fixture/useFixtureInput/useSetInputValue.js +33 -0
- package/dist/fixture/useFixtureInput/useValue.d.ts +6 -0
- package/dist/fixture/useFixtureInput/useValue.js +6 -0
- package/dist/fixture/useFixtureSelect/useCurrentSelectValue.d.ts +2 -0
- package/dist/fixture/useFixtureSelect/useCurrentSelectValue.js +9 -0
- package/dist/fixture/useFixtureSelect/useFixtureSelect.d.ts +2 -0
- package/dist/fixture/useFixtureSelect/useFixtureSelect.js +15 -0
- package/dist/fixture/useFixtureSelect/useSelect.js +6 -0
- package/dist/fixture/{useSelect/useCreateFixtureState.d.ts → useFixtureSelect/useSelectFixtureState.d.ts} +1 -1
- package/dist/fixture/{useSelect/useCreateFixtureState.js → useFixtureSelect/useSelectFixtureState.js} +6 -6
- package/dist/fixture/useFixtureSelect/useSetSelectValue.d.ts +2 -0
- package/dist/fixture/{useSelect/useSetValue.js → useFixtureSelect/useSetSelectValue.js} +5 -5
- package/package.json +3 -3
- package/dist/fixture/useSelect/index.js +0 -15
- package/dist/fixture/useSelect/useCurrentValue.d.ts +0 -2
- package/dist/fixture/useSelect/useCurrentValue.js +0 -9
- package/dist/fixture/useSelect/useSetValue.d.ts +0 -2
- package/dist/fixture/useValue/index.d.ts +0 -7
- package/dist/fixture/useValue/index.js +0 -9
- package/dist/fixture/useValue/shared.d.ts +0 -3
- package/dist/fixture/useValue/shared.js +0 -1
- package/dist/fixture/useValue/useCreateFixtureState.d.ts +0 -2
- package/dist/fixture/useValue/useCurrentValue.d.ts +0 -2
- package/dist/fixture/useValue/useCurrentValue.js +0 -11
- package/dist/fixture/useValue/useSetValue.d.ts +0 -3
- package/dist/fixture/useValue/useSetValue.js +0 -31
- /package/dist/fixture/{useSelect → useFixtureSelect}/shared.d.ts +0 -0
- /package/dist/fixture/{useSelect → useFixtureSelect}/shared.js +0 -0
- /package/dist/fixture/{useSelect/index.d.ts → useFixtureSelect/useSelect.d.ts} +0 -0
package/dist/client.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from './fixture/FixtureCapture/FixtureCapture.js';
|
|
2
2
|
export * from './fixture/FixtureContext.js';
|
|
3
3
|
export * from './fixture/Viewport.js';
|
|
4
|
+
export * from './fixture/useFixtureInput/useFixtureInput.js';
|
|
5
|
+
export * from './fixture/useFixtureInput/useValue.js';
|
|
6
|
+
export * from './fixture/useFixtureSelect/useFixtureSelect.js';
|
|
7
|
+
export * from './fixture/useFixtureSelect/useSelect.js';
|
|
4
8
|
export * from './fixture/useFixtureState.js';
|
|
5
|
-
export * from './fixture/useSelect/index.js';
|
|
6
|
-
export * from './fixture/useValue/index.js';
|
|
7
9
|
export * from './fixtureLoaders/ClientFixtureLoader.js';
|
|
8
10
|
export * from './rendererConnect/RendererContext.js';
|
|
9
11
|
export * from './rendererConnect/RendererProvider.js';
|
package/dist/client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from './fixture/FixtureCapture/FixtureCapture.js';
|
|
2
2
|
export * from './fixture/FixtureContext.js';
|
|
3
3
|
export * from './fixture/Viewport.js';
|
|
4
|
+
export * from './fixture/useFixtureInput/useFixtureInput.js';
|
|
5
|
+
export * from './fixture/useFixtureInput/useValue.js';
|
|
6
|
+
export * from './fixture/useFixtureSelect/useFixtureSelect.js';
|
|
7
|
+
export * from './fixture/useFixtureSelect/useSelect.js';
|
|
4
8
|
export * from './fixture/useFixtureState.js';
|
|
5
|
-
export * from './fixture/useSelect/index.js';
|
|
6
|
-
export * from './fixture/useValue/index.js';
|
|
7
9
|
export * from './fixtureLoaders/ClientFixtureLoader.js';
|
|
8
10
|
export * from './rendererConnect/RendererContext.js';
|
|
9
11
|
export * from './rendererConnect/RendererProvider.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useCurrentInputValue<T>(inputName: string, defaultValue: T): T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { extendWithValue } from 'react-cosmos-core';
|
|
2
|
+
import { useFixtureState } from '../useFixtureState.js';
|
|
3
|
+
export function useCurrentInputValue(inputName, defaultValue) {
|
|
4
|
+
const [fixtureState] = useFixtureState('inputs');
|
|
5
|
+
const inputFs = fixtureState && fixtureState[inputName];
|
|
6
|
+
return inputFs && inputFs.type === 'standard'
|
|
7
|
+
? // Types of fixture state values cannot be guaranteed at run time, which
|
|
8
|
+
// means that tampering with the fixture state can cause runtime errors
|
|
9
|
+
extendWithValue(defaultValue, inputFs.currentValue)
|
|
10
|
+
: defaultValue;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useCurrentInputValue } from './useCurrentInputValue.js';
|
|
2
|
+
import { useInputFixtureState } from './useInputFixtureState.js';
|
|
3
|
+
import { useSetInputValue } from './useSetInputValue.js';
|
|
4
|
+
export function useFixtureInput(inputName, defaultValue) {
|
|
5
|
+
useInputFixtureState(inputName, defaultValue);
|
|
6
|
+
const currentValue = useCurrentInputValue(inputName, defaultValue);
|
|
7
|
+
const setValue = useSetInputValue(inputName, defaultValue);
|
|
8
|
+
return [currentValue, setValue];
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useInputFixtureState(inputName: string, defaultValue: unknown): void;
|
package/dist/fixture/{useValue/useCreateFixtureState.js → useFixtureInput/useInputFixtureState.js}
RENAMED
|
@@ -2,17 +2,17 @@ import { isEqual } from 'lodash-es';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { createValue, extendWithValue, } from 'react-cosmos-core';
|
|
4
4
|
import { useFixtureState } from '../useFixtureState.js';
|
|
5
|
-
export function
|
|
6
|
-
const [, setFixtureState] = useFixtureState('
|
|
5
|
+
export function useInputFixtureState(inputName, defaultValue) {
|
|
6
|
+
const [, setFixtureState] = useFixtureState('inputs');
|
|
7
7
|
React.useEffect(() => {
|
|
8
8
|
// The fixture state for this value is (re)created in two situations:
|
|
9
9
|
// 1. Initially: No corresponding fixture state value is found
|
|
10
10
|
// 2: Default value change: Current value is reset to new default value
|
|
11
11
|
setFixtureState(prevFs => {
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
fsValueExtendsBaseValue(
|
|
12
|
+
const inputFs = prevFs && prevFs[inputName];
|
|
13
|
+
if (inputFs &&
|
|
14
|
+
inputFs.type === 'standard' &&
|
|
15
|
+
fsValueExtendsBaseValue(inputFs.defaultValue, defaultValue))
|
|
16
16
|
return prevFs;
|
|
17
17
|
return {
|
|
18
18
|
...prevFs,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createValue, extendWithValue, } from 'react-cosmos-core';
|
|
3
|
+
import { useFixtureState } from '../useFixtureState.js';
|
|
4
|
+
export function useSetInputValue(inputName, defaultValue) {
|
|
5
|
+
const [, setFixtureState] = useFixtureState('inputs');
|
|
6
|
+
return React.useCallback(stateChange => {
|
|
7
|
+
setFixtureState(prevFs => {
|
|
8
|
+
// Types of fixture state values cannot be guaranteed at run
|
|
9
|
+
// time, which means that tampering with the fixture state can
|
|
10
|
+
// cause runtime errors
|
|
11
|
+
function getNewState() {
|
|
12
|
+
if (typeof stateChange !== 'function')
|
|
13
|
+
return stateChange;
|
|
14
|
+
const stateUpdater = stateChange;
|
|
15
|
+
return stateUpdater(getCurrentValueFromFixtureState(prevFs, inputName, defaultValue));
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
...prevFs,
|
|
19
|
+
[inputName]: {
|
|
20
|
+
type: 'standard',
|
|
21
|
+
defaultValue: createValue(defaultValue),
|
|
22
|
+
currentValue: createValue(getNewState()),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}, [setFixtureState, defaultValue, inputName]);
|
|
27
|
+
}
|
|
28
|
+
function getCurrentValueFromFixtureState(fixtureState, inputName, defaultValue) {
|
|
29
|
+
const inputFs = fixtureState && fixtureState[inputName];
|
|
30
|
+
return inputFs && inputFs.type === 'standard'
|
|
31
|
+
? extendWithValue(defaultValue, inputFs.currentValue)
|
|
32
|
+
: defaultValue;
|
|
33
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useFixtureInput } from './useFixtureInput.js';
|
|
2
|
+
// NOTE: This is an alias for useFixtureInput kept for backwards compatibility
|
|
3
|
+
// with Cosmos versions older than 6.1
|
|
4
|
+
export function useValue(inputName, opts) {
|
|
5
|
+
return useFixtureInput(inputName, opts.defaultValue);
|
|
6
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useFixtureState } from '../useFixtureState.js';
|
|
2
|
+
import { getDefaultSelectValue } from './shared.js';
|
|
3
|
+
export function useCurrentSelectValue(selectName, args) {
|
|
4
|
+
const [fixtureState] = useFixtureState('inputs');
|
|
5
|
+
const inputFs = fixtureState && fixtureState[selectName];
|
|
6
|
+
return inputFs && inputFs.type === 'select'
|
|
7
|
+
? inputFs.currentValue
|
|
8
|
+
: getDefaultSelectValue(args);
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCurrentSelectValue } from './useCurrentSelectValue.js';
|
|
2
|
+
import { useSelectFixtureState } from './useSelectFixtureState.js';
|
|
3
|
+
import { useSetSelectValue } from './useSetSelectValue.js';
|
|
4
|
+
export function useFixtureSelect(selectName, args) {
|
|
5
|
+
if (!args || !args.options || !args.options.length)
|
|
6
|
+
throw new Error('No options provided to useSelect');
|
|
7
|
+
if (typeof args.options[0] === 'object') {
|
|
8
|
+
if (!args.options[0].options.length)
|
|
9
|
+
throw new Error('No options provided to useSelect');
|
|
10
|
+
}
|
|
11
|
+
useSelectFixtureState(selectName, args);
|
|
12
|
+
const currentValue = useCurrentSelectValue(selectName, args);
|
|
13
|
+
const setValue = useSetSelectValue(selectName);
|
|
14
|
+
return [currentValue, setValue];
|
|
15
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useFixtureSelect } from './useFixtureSelect.js';
|
|
2
|
+
// NOTE: This is an alias for useFixtureSelect kept for backwards compatibility
|
|
3
|
+
// with Cosmos versions older than 6.1
|
|
4
|
+
export function useSelect(selectName, args) {
|
|
5
|
+
return useFixtureSelect(selectName, args);
|
|
6
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UseSelectArgs } from './shared.js';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function useSelectFixtureState<Option extends string>(selectName: string, args: UseSelectArgs<Option>): void;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useFixtureState } from '../useFixtureState.js';
|
|
3
3
|
import { getDefaultSelectValue } from './shared.js';
|
|
4
|
-
export function
|
|
5
|
-
const [, setFixtureState] = useFixtureState('
|
|
4
|
+
export function useSelectFixtureState(selectName, args) {
|
|
5
|
+
const [, setFixtureState] = useFixtureState('inputs');
|
|
6
6
|
const defaultValue = getDefaultSelectValue(args);
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
// The fixture state for this select is (re)created in two situations:
|
|
9
9
|
// 1. Initially: No corresponding fixture state select is found
|
|
10
10
|
// 2: Default value change: Current value is reset to new default value
|
|
11
11
|
setFixtureState(prevFs => {
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const inputFs = prevFs && prevFs[selectName];
|
|
13
|
+
if (inputFs &&
|
|
14
|
+
inputFs.type === 'select' &&
|
|
15
|
+
inputFs.defaultValue === defaultValue)
|
|
16
16
|
return prevFs;
|
|
17
17
|
return {
|
|
18
18
|
...prevFs,
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { useFixtureState } from '../useFixtureState.js';
|
|
3
|
-
export function
|
|
4
|
-
const [, setFixtureState] = useFixtureState('
|
|
3
|
+
export function useSetSelectValue(selectName) {
|
|
4
|
+
const [, setFixtureState] = useFixtureState('inputs');
|
|
5
5
|
return useCallback(value => {
|
|
6
6
|
setFixtureState(prevFs => {
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
7
|
+
const inputFs = prevFs && prevFs[selectName];
|
|
8
|
+
if (!inputFs || inputFs.type !== 'select') {
|
|
9
9
|
console.warn(`Invalid fixture state for select: ${selectName}`);
|
|
10
10
|
return prevFs ?? {};
|
|
11
11
|
}
|
|
12
12
|
return {
|
|
13
13
|
...prevFs,
|
|
14
14
|
[selectName]: {
|
|
15
|
-
...
|
|
15
|
+
...inputFs,
|
|
16
16
|
currentValue: value,
|
|
17
17
|
},
|
|
18
18
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-renderer",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "React Cosmos Renderer",
|
|
5
5
|
"repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-renderer",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"lodash-es": "4.17.21",
|
|
15
|
-
"react-cosmos-core": "6.
|
|
15
|
+
"react-cosmos-core": "^6.1.0",
|
|
16
16
|
"react-is": "18.2.0"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "189ce69cb4c190459226ff7e550de0f1cc364242"
|
|
19
19
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useCreateFixtureState } from './useCreateFixtureState.js';
|
|
2
|
-
import { useCurrentValue } from './useCurrentValue.js';
|
|
3
|
-
import { useSetValue } from './useSetValue.js';
|
|
4
|
-
export function useSelect(selectName, args) {
|
|
5
|
-
if (!args || !args.options || !args.options.length)
|
|
6
|
-
throw new Error('No options provided to useSelect');
|
|
7
|
-
if (typeof args.options[0] === 'object') {
|
|
8
|
-
if (!args.options[0].options.length)
|
|
9
|
-
throw new Error('No options provided to useSelect');
|
|
10
|
-
}
|
|
11
|
-
useCreateFixtureState(selectName, args);
|
|
12
|
-
const currentValue = useCurrentValue(selectName, args);
|
|
13
|
-
const setValue = useSetValue(selectName);
|
|
14
|
-
return [currentValue, setValue];
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useFixtureState } from '../useFixtureState.js';
|
|
2
|
-
import { getDefaultSelectValue } from './shared.js';
|
|
3
|
-
export function useCurrentValue(selectName, args) {
|
|
4
|
-
const [fixtureState] = useFixtureState('controls');
|
|
5
|
-
const controlFs = fixtureState && fixtureState[selectName];
|
|
6
|
-
return controlFs && controlFs.type === 'select'
|
|
7
|
-
? controlFs.currentValue
|
|
8
|
-
: getDefaultSelectValue(args);
|
|
9
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FixtureStateData } from 'react-cosmos-core';
|
|
2
|
-
import { SetValue } from './shared.js';
|
|
3
|
-
type Opts<T extends FixtureStateData> = {
|
|
4
|
-
defaultValue: T;
|
|
5
|
-
};
|
|
6
|
-
export declare function useValue<T extends FixtureStateData>(inputName: string, { defaultValue }: Opts<T>): [T, SetValue<T>];
|
|
7
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useCreateFixtureState } from './useCreateFixtureState.js';
|
|
2
|
-
import { useCurrentValue } from './useCurrentValue.js';
|
|
3
|
-
import { useSetValue } from './useSetValue.js';
|
|
4
|
-
export function useValue(inputName, { defaultValue }) {
|
|
5
|
-
useCreateFixtureState(inputName, defaultValue);
|
|
6
|
-
const currentValue = useCurrentValue(inputName, defaultValue);
|
|
7
|
-
const setValue = useSetValue(inputName, defaultValue);
|
|
8
|
-
return [currentValue, setValue];
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { extendWithValue, } from 'react-cosmos-core';
|
|
2
|
-
import { useFixtureState } from '../useFixtureState.js';
|
|
3
|
-
export function useCurrentValue(inputName, defaultValue) {
|
|
4
|
-
const [fixtureState] = useFixtureState('controls');
|
|
5
|
-
const controlFs = fixtureState && fixtureState[inputName];
|
|
6
|
-
return controlFs && controlFs.type === 'standard'
|
|
7
|
-
? // Types of fixture state values cannot be guaranteed at read time, which
|
|
8
|
-
// means that tampering with the fixture state can cause runtime errors
|
|
9
|
-
extendWithValue(defaultValue, controlFs.currentValue)
|
|
10
|
-
: defaultValue;
|
|
11
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { createValue, extendWithValue, } from 'react-cosmos-core';
|
|
3
|
-
import { useFixtureState } from '../useFixtureState.js';
|
|
4
|
-
export function useSetValue(inputName, defaultValue) {
|
|
5
|
-
const [, setFixtureState] = useFixtureState('controls');
|
|
6
|
-
return React.useCallback(stateChange => {
|
|
7
|
-
setFixtureState(prevFs => {
|
|
8
|
-
const currentValue = typeof stateChange === 'function'
|
|
9
|
-
? stateChange(
|
|
10
|
-
// Types of fixture state values cannot be guaranteed at read
|
|
11
|
-
// time, which means that tampering with the fixture state can
|
|
12
|
-
// cause runtime errors
|
|
13
|
-
getCurrentValueFromFixtureState(prevFs, inputName, defaultValue))
|
|
14
|
-
: stateChange;
|
|
15
|
-
return {
|
|
16
|
-
...prevFs,
|
|
17
|
-
[inputName]: {
|
|
18
|
-
type: 'standard',
|
|
19
|
-
defaultValue: createValue(defaultValue),
|
|
20
|
-
currentValue: createValue(currentValue),
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
}, [setFixtureState, defaultValue, inputName]);
|
|
25
|
-
}
|
|
26
|
-
function getCurrentValueFromFixtureState(fixtureState, inputName, defaultValue) {
|
|
27
|
-
const controlFs = fixtureState && fixtureState[inputName];
|
|
28
|
-
return controlFs && controlFs.type === 'standard'
|
|
29
|
-
? extendWithValue(defaultValue, controlFs.currentValue)
|
|
30
|
-
: defaultValue;
|
|
31
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|