react-cosmos-core 6.0.0-alpha.9 → 6.0.0-beta.2
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/fixtureTree/createFixtureTree/createRawFixtureTree.d.ts +1 -1
- package/dist/fixtureTree/createFixtureTree/createRawFixtureTree.js +3 -8
- package/dist/fixtureTree/createFixtureTree/index.d.ts +1 -1
- package/dist/fixtureTree/flattenFixtureTree.d.ts +1 -1
- package/dist/fixtureTree/flattenFixtureTree.js +3 -3
- package/dist/fixtureTree/types.d.ts +3 -3
- package/dist/index.d.ts +23 -18
- package/dist/index.js +23 -18
- package/dist/playground/playgroundParams.d.ts +4 -0
- package/dist/playground/playgroundQueryString.d.ts +3 -0
- package/dist/playground/playgroundQueryString.js +21 -0
- package/dist/{server → plugin}/cosmosPluginConfig.d.ts +2 -4
- package/dist/renderer/rendererConfig.d.ts +1 -0
- package/dist/renderer/{types.d.ts → rendererConnect.d.ts} +10 -5
- package/dist/renderer/rendererQueryString.d.ts +12 -0
- package/dist/renderer/rendererQueryString.js +27 -0
- package/dist/renderer/rendererUrl.d.ts +9 -0
- package/dist/renderer/rendererUrl.js +42 -0
- package/dist/server/serverTypes.d.ts +1 -0
- package/dist/userModules/getFixtureFromExport.d.ts +2 -0
- package/dist/{renderer/FixtureLoader/fixtureHelpers.js → userModules/getFixtureFromExport.js} +4 -3
- package/dist/userModules/getFixtureList.d.ts +7 -0
- package/dist/userModules/getFixtureList.js +24 -0
- package/dist/userModules/getSortedDecoratorsForFixturePath.d.ts +2 -0
- package/dist/{renderer → userModules}/isMultiFixture.d.ts +1 -1
- package/dist/userModules/stringifyFixtureId.d.ts +2 -0
- package/dist/userModules/stringifyFixtureId.js +4 -0
- package/dist/userModules/userModuleTypes.d.ts +44 -0
- package/dist/userModules/userModuleTypes.js +1 -0
- package/dist/utils/queryString.d.ts +2 -0
- package/dist/utils/queryString.js +7 -0
- package/dist/utils/react/ClassStateMock.d.ts +13 -0
- package/dist/utils/react/ClassStateMock.js +73 -0
- package/dist/utils/react/DelayRender.d.ts +7 -0
- package/dist/utils/react/DelayRender.js +10 -0
- package/dist/utils/string.d.ts +0 -2
- package/dist/utils/string.js +0 -6
- package/dist/utils/window.d.ts +1 -0
- package/dist/utils/window.js +8 -0
- package/package.json +4 -3
- package/dist/fixture/FixtureContext.d.ts +0 -7
- package/dist/fixture/FixtureContext.js +0 -5
- package/dist/fixture/Viewport.d.ts +0 -8
- package/dist/fixture/Viewport.js +0 -19
- package/dist/fixture/useSelect/index.d.ts +0 -2
- package/dist/fixture/useSelect/index.js +0 -11
- package/dist/fixture/useSelect/shared.d.ts +0 -6
- package/dist/fixture/useSelect/shared.js +0 -3
- package/dist/fixture/useSelect/useCreateFixtureState.d.ts +0 -2
- package/dist/fixture/useSelect/useCreateFixtureState.js +0 -32
- package/dist/fixture/useSelect/useCurrentValue.d.ts +0 -2
- package/dist/fixture/useSelect/useCurrentValue.js +0 -11
- package/dist/fixture/useSelect/useSetValue.d.ts +0 -2
- package/dist/fixture/useSelect/useSetValue.js +0 -25
- 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/useCreateFixtureState.d.ts +0 -2
- package/dist/fixture/useValue/useCreateFixtureState.js +0 -35
- package/dist/fixture/useValue/useCurrentValue.d.ts +0 -2
- package/dist/fixture/useValue/useCurrentValue.js +0 -13
- package/dist/fixture/useValue/useSetValue.d.ts +0 -3
- package/dist/fixture/useValue/useSetValue.js +0 -36
- package/dist/playground/playgroundUrl.d.ts +0 -13
- package/dist/playground/playgroundUrl.js +0 -36
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/decorateFixtureRefs/index.d.ts +0 -5
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/decorateFixtureRefs/index.js +0 -46
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/decorateFixtureRefs/isRefSupported.d.ts +0 -4
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/decorateFixtureRefs/isRefSupported.js +0 -19
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/index.d.ts +0 -3
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/index.js +0 -13
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/shared.d.ts +0 -18
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/shared.js +0 -14
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/useFixtureState.d.ts +0 -4
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/useFixtureState.js +0 -156
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/useReadClassState.d.ts +0 -4
- package/dist/renderer/FixtureLoader/FixtureCapture/classState/useReadClassState.js +0 -60
- package/dist/renderer/FixtureLoader/FixtureCapture/index.d.ts +0 -7
- package/dist/renderer/FixtureLoader/FixtureCapture/index.js +0 -9
- package/dist/renderer/FixtureLoader/FixtureCapture/props/index.d.ts +0 -3
- package/dist/renderer/FixtureLoader/FixtureCapture/props/index.js +0 -77
- package/dist/renderer/FixtureLoader/FixtureCapture/props/useFixtureProps.d.ts +0 -3
- package/dist/renderer/FixtureLoader/FixtureCapture/props/useFixtureProps.js +0 -70
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/findRelevantElementPaths.d.ts +0 -2
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/findRelevantElementPaths.js +0 -23
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/findElementPaths.d.ts +0 -2
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/findElementPaths.js +0 -22
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/getElementAtPath.d.ts +0 -3
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/getElementAtPath.js +0 -26
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/index.d.ts +0 -11
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/index.js +0 -11
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/setElementAtPath.d.ts +0 -2
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/setElementAtPath.js +0 -35
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/shared.d.ts +0 -2
- package/dist/renderer/FixtureLoader/FixtureCapture/shared/nodeTree/shared.js +0 -6
- package/dist/renderer/FixtureLoader/FixtureLoader.d.ts +0 -52
- package/dist/renderer/FixtureLoader/FixtureLoader.js +0 -226
- package/dist/renderer/FixtureLoader/FixtureProvider.d.ts +0 -18
- package/dist/renderer/FixtureLoader/FixtureProvider.js +0 -18
- package/dist/renderer/FixtureLoader/fixtureHelpers.d.ts +0 -2
- package/dist/renderer/FixtureLoader/getDecoratedFixtureElement/FixtureElement.d.ts +0 -9
- package/dist/renderer/FixtureLoader/getDecoratedFixtureElement/FixtureElement.js +0 -5
- package/dist/renderer/FixtureLoader/getDecoratedFixtureElement/index.d.ts +0 -2
- package/dist/renderer/FixtureLoader/getDecoratedFixtureElement/index.js +0 -15
- package/dist/renderer/FixtureLoader/postMessage.d.ts +0 -2
- package/dist/renderer/FixtureLoader/postMessage.js +0 -22
- package/dist/renderer/FixtureLoader/webSockets.d.ts +0 -2
- package/dist/renderer/FixtureLoader/webSockets.js +0 -32
- package/dist/renderer/getFixtureList.d.ts +0 -8
- package/dist/renderer/getFixtureList.js +0 -19
- package/dist/renderer/getSortedDecoratorsForFixturePath.d.ts +0 -2
- package/dist/renderer/reactTypes.d.ts +0 -28
- /package/dist/{server → message}/serverMessage.d.ts +0 -0
- /package/dist/{server → message}/serverMessage.js +0 -0
- /package/dist/{server → message}/socketMessage.d.ts +0 -0
- /package/dist/{server → message}/socketMessage.js +0 -0
- /package/dist/{fixture/types.js → playground/playgroundParams.js} +0 -0
- /package/dist/{renderer → playground}/registerPlaygroundShortcuts.d.ts +0 -0
- /package/dist/{renderer → playground}/registerPlaygroundShortcuts.js +0 -0
- /package/dist/{server → plugin}/cosmosPluginConfig.js +0 -0
- /package/dist/{fixture/useValue/shared.js → renderer/rendererConnect.js} +0 -0
- /package/dist/{renderer/reactTypes.js → server/serverTypes.js} +0 -0
- /package/dist/{fixture/types.d.ts → userModules/fixtureTypes.d.ts} +0 -0
- /package/dist/{renderer/types.js → userModules/fixtureTypes.js} +0 -0
- /package/dist/{renderer → userModules}/getSortedDecoratorsForFixturePath.js +0 -0
- /package/dist/{renderer → userModules}/isMultiFixture.js +0 -0
package/dist/utils/string.d.ts
CHANGED
package/dist/utils/string.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
export function replaceKeys(str, map) {
|
|
2
2
|
return Object.keys(map).reduce((res, key) => res.replace(key, map[key]), str);
|
|
3
3
|
}
|
|
4
|
-
export function removeLeadingSlash(fromPath) {
|
|
5
|
-
return fromPath.replace(/^\/+/, '');
|
|
6
|
-
}
|
|
7
|
-
export function removeLeadingDot(fromPath) {
|
|
8
|
-
return fromPath.indexOf('.') === 0 ? fromPath.slice(1) : fromPath;
|
|
9
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isInsideWindowIframe(): boolean;
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-core",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-beta.2",
|
|
4
4
|
"description": "React Cosmos Core",
|
|
5
5
|
"repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-core",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
8
|
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"js-base64": "^3.7.5",
|
|
11
12
|
"lodash-es": "^4.17.21",
|
|
12
13
|
"react-is": "^18.2.0"
|
|
13
14
|
},
|
|
14
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "f3e3893b0439132e083228f312c62e4379f39762"
|
|
15
16
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { FixtureState, SetFixtureState } from '../fixtureState/types.js';
|
|
3
|
-
export type FixtureContextValue = {
|
|
4
|
-
fixtureState: FixtureState;
|
|
5
|
-
setFixtureState: SetFixtureState;
|
|
6
|
-
};
|
|
7
|
-
export declare const FixtureContext: import("react").Context<FixtureContextValue>;
|
package/dist/fixture/Viewport.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { FixtureContext } from './FixtureContext.js';
|
|
3
|
-
// This awkward declaration is required because of the cosmosCapture static
|
|
4
|
-
// property, which makes TS generate a declaration for Viewport that doesn't
|
|
5
|
-
// conform to React's component interface. Without this explicit type TS would
|
|
6
|
-
// allow clients to pass any props to Viewport.
|
|
7
|
-
export const Viewport = function Viewport({ children, width, height, }) {
|
|
8
|
-
const { setFixtureState } = React.useContext(FixtureContext);
|
|
9
|
-
React.useEffect(() => {
|
|
10
|
-
setFixtureState(fixtureState => ({
|
|
11
|
-
...fixtureState,
|
|
12
|
-
viewport: { width, height },
|
|
13
|
-
}));
|
|
14
|
-
}, [setFixtureState, width, height]);
|
|
15
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18051
|
|
16
|
-
return React.createElement(React.Fragment, null, children);
|
|
17
|
-
};
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
Viewport.cosmosCapture = false;
|
|
@@ -1,11 +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
|
-
useCreateFixtureState(selectName, args);
|
|
8
|
-
const currentValue = useCurrentValue(selectName, args);
|
|
9
|
-
const setValue = useSetValue(selectName);
|
|
10
|
-
return [currentValue, setValue];
|
|
11
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type UseSelectArgs<Option extends string> = {
|
|
2
|
-
options: Option[];
|
|
3
|
-
defaultValue?: Option;
|
|
4
|
-
};
|
|
5
|
-
export type SetSelectValue<Option extends string> = (value: Option) => void;
|
|
6
|
-
export declare function getDefaultSelectValue<Option extends string>({ options, defaultValue, }: UseSelectArgs<Option>): Option;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
4
|
-
import { getDefaultSelectValue } from './shared.js';
|
|
5
|
-
export function useCreateFixtureState(selectName, args) {
|
|
6
|
-
const { setFixtureState } = React.useContext(FixtureContext);
|
|
7
|
-
const defaultValue = getDefaultSelectValue(args);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
// The fixture state for this select is (re)created in two situations:
|
|
10
|
-
// 1. Initially: No corresponding fixture state select is found
|
|
11
|
-
// 2: Default value change: Current value is reset to new default value
|
|
12
|
-
setFixtureState(prevFs => {
|
|
13
|
-
const fsControl = findFixtureStateControl(prevFs, selectName);
|
|
14
|
-
if (fsControl &&
|
|
15
|
-
fsControl.type === 'select' &&
|
|
16
|
-
fsControl.defaultValue === defaultValue)
|
|
17
|
-
return prevFs;
|
|
18
|
-
return {
|
|
19
|
-
...prevFs,
|
|
20
|
-
controls: {
|
|
21
|
-
...prevFs.controls,
|
|
22
|
-
[selectName]: {
|
|
23
|
-
type: 'select',
|
|
24
|
-
options: args.options,
|
|
25
|
-
defaultValue,
|
|
26
|
-
currentValue: defaultValue,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
}, [args.options, defaultValue, selectName, setFixtureState]);
|
|
32
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
4
|
-
import { getDefaultSelectValue } from './shared.js';
|
|
5
|
-
export function useCurrentValue(selectName, args) {
|
|
6
|
-
const { fixtureState } = useContext(FixtureContext);
|
|
7
|
-
const fsControl = findFixtureStateControl(fixtureState, selectName);
|
|
8
|
-
return fsControl && fsControl.type === 'select'
|
|
9
|
-
? fsControl.currentValue
|
|
10
|
-
: getDefaultSelectValue(args);
|
|
11
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useCallback, useContext } from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
4
|
-
export function useSetValue(selectName) {
|
|
5
|
-
const { setFixtureState } = useContext(FixtureContext);
|
|
6
|
-
return useCallback(value => {
|
|
7
|
-
setFixtureState(prevFs => {
|
|
8
|
-
const fsControl = findFixtureStateControl(prevFs, selectName);
|
|
9
|
-
if (!fsControl || fsControl.type !== 'select') {
|
|
10
|
-
console.warn(`Invalid fixture state for select: ${selectName}`);
|
|
11
|
-
return prevFs;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
...prevFs,
|
|
15
|
-
controls: {
|
|
16
|
-
...prevFs.controls,
|
|
17
|
-
[selectName]: {
|
|
18
|
-
...fsControl,
|
|
19
|
-
currentValue: value,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
}, [selectName, setFixtureState]);
|
|
25
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FixtureStateData } from '../../fixtureState/types.js';
|
|
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,35 +0,0 @@
|
|
|
1
|
-
import { isEqual } from 'lodash-es';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
4
|
-
import { createValue } from '../../fixtureState/createValues.js';
|
|
5
|
-
import { extendWithValue } from '../../fixtureState/extendWithValues.js';
|
|
6
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
7
|
-
export function useCreateFixtureState(inputName, defaultValue) {
|
|
8
|
-
const { setFixtureState } = React.useContext(FixtureContext);
|
|
9
|
-
React.useEffect(() => {
|
|
10
|
-
// The fixture state for this value is (re)created in two situations:
|
|
11
|
-
// 1. Initially: No corresponding fixture state value is found
|
|
12
|
-
// 2: Default value change: Current value is reset to new default value
|
|
13
|
-
setFixtureState(prevFs => {
|
|
14
|
-
const fsControl = findFixtureStateControl(prevFs, inputName);
|
|
15
|
-
if (fsControl &&
|
|
16
|
-
fsControl.type === 'standard' &&
|
|
17
|
-
fsValueExtendsBaseValue(fsControl.defaultValue, defaultValue))
|
|
18
|
-
return prevFs;
|
|
19
|
-
return {
|
|
20
|
-
...prevFs,
|
|
21
|
-
controls: {
|
|
22
|
-
...prevFs.controls,
|
|
23
|
-
[inputName]: {
|
|
24
|
-
type: 'standard',
|
|
25
|
-
defaultValue: createValue(defaultValue),
|
|
26
|
-
currentValue: createValue(defaultValue),
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
}, [setFixtureState, inputName, defaultValue]);
|
|
32
|
-
}
|
|
33
|
-
function fsValueExtendsBaseValue(fsValue, baseValue) {
|
|
34
|
-
return isEqual(baseValue, extendWithValue(baseValue, fsValue));
|
|
35
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { extendWithValue } from '../../fixtureState/extendWithValues.js';
|
|
4
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
5
|
-
export function useCurrentValue(inputName, defaultValue) {
|
|
6
|
-
const { fixtureState } = React.useContext(FixtureContext);
|
|
7
|
-
const fsControl = findFixtureStateControl(fixtureState, inputName);
|
|
8
|
-
return fsControl && fsControl.type === 'standard'
|
|
9
|
-
? // Types of fixture state values cannot be guaranteed at read time, which
|
|
10
|
-
// means that tampering with the fixture state can cause runtime errors
|
|
11
|
-
extendWithValue(defaultValue, fsControl.currentValue)
|
|
12
|
-
: defaultValue;
|
|
13
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { createValue } from '../../fixtureState/createValues.js';
|
|
4
|
-
import { extendWithValue } from '../../fixtureState/extendWithValues.js';
|
|
5
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
6
|
-
export function useSetValue(inputName, defaultValue) {
|
|
7
|
-
const { setFixtureState } = React.useContext(FixtureContext);
|
|
8
|
-
return React.useCallback(stateChange => {
|
|
9
|
-
setFixtureState(prevFs => {
|
|
10
|
-
const currentValue = typeof stateChange === 'function'
|
|
11
|
-
? stateChange(
|
|
12
|
-
// Types of fixture state values cannot be guaranteed at read
|
|
13
|
-
// time, which means that tampering with the fixture state can
|
|
14
|
-
// cause runtime errors
|
|
15
|
-
getCurrentValueFromFixtureState(prevFs, inputName, defaultValue))
|
|
16
|
-
: stateChange;
|
|
17
|
-
return {
|
|
18
|
-
...prevFs,
|
|
19
|
-
controls: {
|
|
20
|
-
...prevFs.controls,
|
|
21
|
-
[inputName]: {
|
|
22
|
-
type: 'standard',
|
|
23
|
-
defaultValue: createValue(defaultValue),
|
|
24
|
-
currentValue: createValue(currentValue),
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
}, [setFixtureState, defaultValue, inputName]);
|
|
30
|
-
}
|
|
31
|
-
function getCurrentValueFromFixtureState(fixtureState, inputName, defaultValue) {
|
|
32
|
-
const fsControl = findFixtureStateControl(fixtureState, inputName);
|
|
33
|
-
return fsControl && fsControl.type === 'standard'
|
|
34
|
-
? extendWithValue(defaultValue, fsControl.currentValue)
|
|
35
|
-
: defaultValue;
|
|
36
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FixtureId } from '../fixture/types.js';
|
|
2
|
-
export type PlaygroundUrlParams = {
|
|
3
|
-
fixtureId?: FixtureId;
|
|
4
|
-
};
|
|
5
|
-
export type RendererUrlParams = {
|
|
6
|
-
_fixtureId?: FixtureId;
|
|
7
|
-
};
|
|
8
|
-
export declare function stringifyPlaygroundUrlQuery(urlParams: PlaygroundUrlParams): string;
|
|
9
|
-
export declare function parsePlaygroundUrlQuery(query: string): PlaygroundUrlParams;
|
|
10
|
-
export declare function stringifyRendererUrlQuery(urlParams: RendererUrlParams): string;
|
|
11
|
-
export declare function parseRendererUrlQuery(query: string): RendererUrlParams;
|
|
12
|
-
export declare function parseUrlQuery<T extends {}>(query: string): T;
|
|
13
|
-
export declare function stringifyUrlQuery(params: {}): string;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export function stringifyPlaygroundUrlQuery(urlParams) {
|
|
2
|
-
const encodedUrlParams = {};
|
|
3
|
-
if (urlParams.fixtureId) {
|
|
4
|
-
encodedUrlParams.fixtureId = JSON.stringify(urlParams.fixtureId);
|
|
5
|
-
}
|
|
6
|
-
return stringifyUrlQuery(encodedUrlParams);
|
|
7
|
-
}
|
|
8
|
-
export function parsePlaygroundUrlQuery(query) {
|
|
9
|
-
const encodedUrlParams = parseUrlQuery(query);
|
|
10
|
-
const decoded = {};
|
|
11
|
-
if (encodedUrlParams.fixtureId) {
|
|
12
|
-
decoded.fixtureId = JSON.parse(encodedUrlParams.fixtureId);
|
|
13
|
-
}
|
|
14
|
-
return decoded;
|
|
15
|
-
}
|
|
16
|
-
export function stringifyRendererUrlQuery(urlParams) {
|
|
17
|
-
const encodedUrlParams = {};
|
|
18
|
-
if (urlParams._fixtureId) {
|
|
19
|
-
encodedUrlParams._fixtureId = JSON.stringify(urlParams._fixtureId);
|
|
20
|
-
}
|
|
21
|
-
return stringifyUrlQuery(encodedUrlParams);
|
|
22
|
-
}
|
|
23
|
-
export function parseRendererUrlQuery(query) {
|
|
24
|
-
const encodedUrlParams = parseUrlQuery(query);
|
|
25
|
-
const decoded = {};
|
|
26
|
-
if (encodedUrlParams._fixtureId) {
|
|
27
|
-
decoded._fixtureId = JSON.parse(encodedUrlParams._fixtureId);
|
|
28
|
-
}
|
|
29
|
-
return decoded;
|
|
30
|
-
}
|
|
31
|
-
export function parseUrlQuery(query) {
|
|
32
|
-
return Object.fromEntries(new URLSearchParams(query));
|
|
33
|
-
}
|
|
34
|
-
export function stringifyUrlQuery(params) {
|
|
35
|
-
return new URLSearchParams(params).toString();
|
|
36
|
-
}
|
package/dist/renderer/FixtureLoader/FixtureCapture/classState/decorateFixtureRefs/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Component, ReactNode } from 'react';
|
|
2
|
-
import { CachedRefHandlers } from '../shared.js';
|
|
3
|
-
type SpyRef = (elPath: string, elRef: null | Component) => unknown;
|
|
4
|
-
export declare function decorateFixtureRefs(fixture: ReactNode, spyRef: SpyRef, cachedRefHandlers: CachedRefHandlers): ReactNode;
|
|
5
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { cloneElement, } from 'react';
|
|
2
|
-
import { findRelevantElementPaths } from '../../shared/findRelevantElementPaths.js';
|
|
3
|
-
import { setElementAtPath } from '../../shared/nodeTree/index.js';
|
|
4
|
-
import { isRefSupported } from './isRefSupported.js';
|
|
5
|
-
export function decorateFixtureRefs(fixture, spyRef, cachedRefHandlers) {
|
|
6
|
-
const elPaths = findRelevantElementPaths(fixture);
|
|
7
|
-
return elPaths.reduce((decoratedFixture, elPath) => {
|
|
8
|
-
return setElementAtPath(decoratedFixture, elPath, element => {
|
|
9
|
-
if (!isRefSupported(element.type)) {
|
|
10
|
-
return element;
|
|
11
|
-
}
|
|
12
|
-
return cloneElement(element, {
|
|
13
|
-
ref: getDecoratedRef(element.ref, spyRef, elPath, cachedRefHandlers),
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
}, fixture);
|
|
17
|
-
}
|
|
18
|
-
function getDecoratedRef(origRef, spyRef, elPath, cachedRefHandlers) {
|
|
19
|
-
const found = cachedRefHandlers[elPath];
|
|
20
|
-
if (found && found.origRef === origRef) {
|
|
21
|
-
return found.handler;
|
|
22
|
-
}
|
|
23
|
-
const handler = decorateRefWithSpy(origRef, spyRef, elPath);
|
|
24
|
-
cachedRefHandlers[elPath] = { origRef, handler };
|
|
25
|
-
return handler;
|
|
26
|
-
}
|
|
27
|
-
function decorateRefWithSpy(origRef, spyRef, elPath) {
|
|
28
|
-
return (elRef) => {
|
|
29
|
-
if (origRef) {
|
|
30
|
-
callOriginalRef(origRef, elRef);
|
|
31
|
-
}
|
|
32
|
-
spyRef(elPath, elRef);
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function callOriginalRef(ref, elRef) {
|
|
36
|
-
if (typeof ref === 'string') {
|
|
37
|
-
console.warn('[decorateFixtureRefs] String refs are not supported');
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (typeof ref === 'function') {
|
|
41
|
-
ref(elRef);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const refObj = ref;
|
|
45
|
-
refObj.current = elRef;
|
|
46
|
-
}
|
package/dist/renderer/FixtureLoader/FixtureCapture/classState/decorateFixtureRefs/isRefSupported.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ForwardRef } from 'react-is';
|
|
3
|
-
export function isRefSupported(elementType) {
|
|
4
|
-
if (typeof elementType === 'string') {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
const { $$typeof, prototype } = elementType;
|
|
8
|
-
return ($$typeof === ForwardRef ||
|
|
9
|
-
// Warning: Some functions don't have the .prototype property
|
|
10
|
-
(prototype &&
|
|
11
|
-
// ES6 Class
|
|
12
|
-
// Warning: This will return false is the component is extending a
|
|
13
|
-
// different copy of React than the one used by Cosmos. This is relevant
|
|
14
|
-
// when running Cosmos from an external location instead of node_modules.
|
|
15
|
-
(prototype instanceof React.Component ||
|
|
16
|
-
// React.createClass
|
|
17
|
-
prototype.getInitialState !== undefined) &&
|
|
18
|
-
true));
|
|
19
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useFixtureState } from './useFixtureState.js';
|
|
3
|
-
import { useReadClassState } from './useReadClassState.js';
|
|
4
|
-
export function useClassStateCapture(fixture, decoratorId) {
|
|
5
|
-
const elRefs = React.useRef({});
|
|
6
|
-
React.useEffect(() => {
|
|
7
|
-
return () => {
|
|
8
|
-
elRefs.current = {};
|
|
9
|
-
};
|
|
10
|
-
}, []);
|
|
11
|
-
useReadClassState(fixture, decoratorId, elRefs);
|
|
12
|
-
return useFixtureState(fixture, decoratorId, elRefs);
|
|
13
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export type ElRefs = {
|
|
3
|
-
[elPath: string]: React.Component;
|
|
4
|
-
};
|
|
5
|
-
export type InitialStates = {
|
|
6
|
-
[elPath: string]: {
|
|
7
|
-
type: React.ComponentClass<any>;
|
|
8
|
-
state: {};
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export type CachedRefHandler = {
|
|
12
|
-
origRef: null | React.Ref<any>;
|
|
13
|
-
handler: (elRef: null | React.Component) => unknown;
|
|
14
|
-
};
|
|
15
|
-
export type CachedRefHandlers = {
|
|
16
|
-
[elPath: string]: CachedRefHandler;
|
|
17
|
-
};
|
|
18
|
-
export declare function replaceState(elRef: React.Component, nextState: {}): void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { isEqual } from 'lodash-es';
|
|
2
|
-
// We need to do this because React doesn't provide a replaceState method
|
|
3
|
-
// (anymore) https://reactjs.org/docs/react-component.html#setstate
|
|
4
|
-
export function replaceState(elRef, nextState) {
|
|
5
|
-
const fullState = resetOriginalKeys(elRef.state, nextState);
|
|
6
|
-
if (!isEqual(fullState, elRef.state)) {
|
|
7
|
-
elRef.setState(fullState);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function resetOriginalKeys(original, current) {
|
|
11
|
-
return Object.keys(original).reduce((result, key) => Object.keys(result).indexOf(key) === -1
|
|
12
|
-
? { ...result, [key]: undefined }
|
|
13
|
-
: result, current);
|
|
14
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { MutableRefObject, ReactNode } from 'react';
|
|
2
|
-
import { FixtureDecoratorId } from '../../../../fixtureState/types.js';
|
|
3
|
-
import { ElRefs } from './shared.js';
|
|
4
|
-
export declare function useFixtureState(fixture: ReactNode, decoratorId: FixtureDecoratorId, elRefs: MutableRefObject<ElRefs>): ReactNode;
|