react-cosmos-renderer 7.2.0 → 7.2.1-canary.3822d76.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/fixture/ClassStateMock.js +1 -1
- package/dist/fixture/FixtureCapture/classState/shared.js +1 -1
- package/dist/fixture/FixtureCapture/classState/useFixtureClassState.js +1 -1
- package/dist/fixture/FixtureCapture/classState/useReadClassState.js +1 -2
- package/dist/fixture/FixtureCapture/props/useFixtureProps.js +11 -8
- package/dist/fixture/FixtureCapture/shared/nodeTree/findElementPaths.js +4 -3
- package/dist/fixture/FixtureCapture/shared/nodeTree/getElementAtPath.js +5 -4
- package/dist/fixture/FixtureCapture/shared/nodeTree/index.d.ts +1 -1
- package/dist/fixture/FixtureCapture/shared/nodeTree/index.js +1 -1
- package/dist/fixture/FixtureCapture/shared/nodeTree/setElementAtPath.js +4 -25
- package/dist/fixture/useFixtureInput/useInputFixtureState.js +1 -2
- package/dist/fixtureLoaders/ClientFixtureLoader.js +1 -1
- package/dist/fixtureLoaders/ServerFixtureLoader.js +1 -1
- package/dist/fixtureModule/FixtureProvider.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -4
- /package/dist/fixture/FixtureCapture/shared/nodeTree/{shared.d.ts → elPath.d.ts} +0 -0
- /package/dist/fixture/FixtureCapture/shared/nodeTree/{shared.js → elPath.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isEqual } from 'lodash-es';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { isEqual } from 'react-cosmos-core';
|
|
3
3
|
// Copied from https://github.com/skidding/react-mock/blob/c33dfa1d6f0c9ce7b3eaba073618d61731a0e82e/packages/state/src/index.js
|
|
4
4
|
export class ClassStateMock extends React.Component {
|
|
5
5
|
static cosmosCapture = false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEqual } from '
|
|
1
|
+
import { isEqual } from 'react-cosmos-core';
|
|
2
2
|
// We need to do this because React doesn't provide a replaceState method
|
|
3
3
|
// (anymore) https://reactjs.org/docs/react-component.html#setstate
|
|
4
4
|
export function replaceState(elRef, nextState) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isEqual } from 'lodash-es';
|
|
2
1
|
import { useEffect, useRef, } from 'react';
|
|
2
|
+
import { isEqual } from 'react-cosmos-core';
|
|
3
3
|
import { createClassStateFixtureStateItem, createValues, extendWithValues, filterClassStateFixtureState, findClassStateFixtureStateItem, getComponentName, removeClassStateFixtureStateItem, } from 'react-cosmos-core';
|
|
4
4
|
import { useFixtureState } from '../../useFixtureState.js';
|
|
5
5
|
import { findRelevantElementPaths } from '../shared/findRelevantElementPaths.js';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { isEqual } from 'lodash-es';
|
|
2
1
|
import { useEffect, useRef } from 'react';
|
|
3
|
-
import { createValues, extendWithValues, findClassStateFixtureStateItem, updateClassStateFixtureStateItem, } from 'react-cosmos-core';
|
|
2
|
+
import { createValues, extendWithValues, findClassStateFixtureStateItem, isEqual, updateClassStateFixtureStateItem, } from 'react-cosmos-core';
|
|
4
3
|
import { useFixtureState } from '../../useFixtureState.js';
|
|
5
4
|
import { findRelevantElementPaths } from '../shared/findRelevantElementPaths.js';
|
|
6
5
|
// How often to check the state of the loaded component and update the fixture
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { isEqual, mapValues } from 'lodash-es';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { DEFAULT_RENDER_KEY, extendWithValues, findPropsFixtureStateItem, getComponentName, } from 'react-cosmos-core';
|
|
2
|
+
import { DEFAULT_RENDER_KEY, extendWithValues, findPropsFixtureStateItem, getComponentName, isEqual, } from 'react-cosmos-core';
|
|
4
3
|
import { findRelevantElementPaths } from '../shared/findRelevantElementPaths.js';
|
|
5
4
|
import { getChildrenPath, setElementAtPath } from '../shared/nodeTree/index.js';
|
|
6
5
|
export function useFixtureProps(fixture, propsFs, decoratorId) {
|
|
@@ -25,15 +24,19 @@ export function useFixtureProps(fixture, propsFs, decoratorId) {
|
|
|
25
24
|
const originalProps = element.props;
|
|
26
25
|
const extendedProps = extendWithValues(originalProps, fsItem.values);
|
|
27
26
|
// Preserve identity between renders for indentical non-primitive props
|
|
28
|
-
const cachedProps =
|
|
27
|
+
const cachedProps = {};
|
|
28
|
+
for (const [propName, value] of Object.entries(extendedProps)) {
|
|
29
29
|
const key = getPropCacheKey(elPath, propName);
|
|
30
30
|
if (!propCache.hasOwnProperty(key))
|
|
31
31
|
propCache[key] = originalProps[propName];
|
|
32
|
-
if (isEqual(propCache[key], value))
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
if (isEqual(propCache[key], value)) {
|
|
33
|
+
cachedProps[propName] = propCache[key];
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
propCache[key] = value;
|
|
37
|
+
cachedProps[propName] = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
37
40
|
// HACK alert: Editing React Element by hand
|
|
38
41
|
// This is blasphemy, but there are two reasons why React.cloneElement
|
|
39
42
|
// isn't ideal:
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { flatten } from 'lodash-es';
|
|
2
1
|
import { Fragment } from 'react';
|
|
3
2
|
import { isReactElement } from 'react-cosmos-core';
|
|
4
|
-
import { getChildrenPath } from './
|
|
3
|
+
import { getChildrenPath } from './elPath.js';
|
|
5
4
|
export function findElementPaths(node, curPath = '') {
|
|
6
5
|
if (Array.isArray(node)) {
|
|
7
6
|
// Array.from is used to fill array holes with undefined values. Array holes
|
|
8
7
|
// have been observed in Next.js server components that receive undefined
|
|
9
8
|
// children inside an array of children.
|
|
10
|
-
return
|
|
9
|
+
return Array.from(node)
|
|
10
|
+
.map((child, idx) => findElementPaths(child, `${curPath}[${idx}]`))
|
|
11
|
+
.flat();
|
|
11
12
|
}
|
|
12
13
|
if (!isReactElement(node)) {
|
|
13
14
|
// At this point the node can be null, boolean, string, number, Portal, etc.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isRootPath } from './shared.js';
|
|
1
|
+
import { getByPath, isReactElement, } from 'react-cosmos-core';
|
|
2
|
+
import { isRootPath } from './elPath.js';
|
|
4
3
|
// Why be silent about trying to fetch a node that isn't an element?
|
|
5
4
|
// Because users of this utility only care about elements. Whether the child
|
|
6
5
|
// node was removed or replaced by a different type of node (eg. string,
|
|
@@ -11,7 +10,9 @@ export function getElementAtPath(node, elPath) {
|
|
|
11
10
|
return null;
|
|
12
11
|
}
|
|
13
12
|
const rootNode = node;
|
|
14
|
-
const childNode = isRootPath(elPath)
|
|
13
|
+
const childNode = isRootPath(elPath)
|
|
14
|
+
? rootNode
|
|
15
|
+
: getByPath(rootNode, elPath);
|
|
15
16
|
if (!isReactElement(childNode)) {
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
export { findElementPaths } from './findElementPaths.js';
|
|
9
9
|
export { getElementAtPath, getExpectedElementAtPath, } from './getElementAtPath.js';
|
|
10
10
|
export { setElementAtPath } from './setElementAtPath.js';
|
|
11
|
-
export { getChildrenPath } from './
|
|
11
|
+
export { getChildrenPath } from './elPath.js';
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
export { findElementPaths } from './findElementPaths.js';
|
|
9
9
|
export { getElementAtPath, getExpectedElementAtPath, } from './getElementAtPath.js';
|
|
10
10
|
export { setElementAtPath } from './setElementAtPath.js';
|
|
11
|
-
export { getChildrenPath } from './
|
|
11
|
+
export { getChildrenPath } from './elPath.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { setByPath } from 'react-cosmos-core';
|
|
2
|
+
import { isRootPath } from './elPath.js';
|
|
3
3
|
import { getExpectedElementAtPath } from './getElementAtPath.js';
|
|
4
|
-
import { isRootPath } from './shared.js';
|
|
5
4
|
export function setElementAtPath(node, elPath, updater) {
|
|
6
5
|
const childEl = getExpectedElementAtPath(node, elPath);
|
|
7
6
|
const newEl = updater(childEl);
|
|
@@ -10,26 +9,6 @@ export function setElementAtPath(node, elPath, updater) {
|
|
|
10
9
|
}
|
|
11
10
|
// If the root is a non-Array non-Element Node we should be at the root path
|
|
12
11
|
// and returned already
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
// https://github.com/lodash/lodash/blob/6018350ac10d5ce6a5b7db625140b82aeab804df/isObject.js#L15-L16
|
|
16
|
-
return set(clonedRoot, elPath, newEl);
|
|
17
|
-
}
|
|
18
|
-
function cloneNode(value) {
|
|
19
|
-
return Array.isArray(value)
|
|
20
|
-
? value.map(n => cloneNodeItem(n))
|
|
21
|
-
: cloneNodeItem(value);
|
|
22
|
-
}
|
|
23
|
-
function cloneNodeItem(value) {
|
|
24
|
-
return isReactElement(value) ? cloneReactElement(value) : value;
|
|
25
|
-
}
|
|
26
|
-
function cloneReactElement(value) {
|
|
27
|
-
const { children, ...otherProps } = value.props;
|
|
28
|
-
return {
|
|
29
|
-
...value,
|
|
30
|
-
props: {
|
|
31
|
-
...otherProps,
|
|
32
|
-
children: cloneNode(children),
|
|
33
|
-
},
|
|
34
|
-
};
|
|
12
|
+
const root = node;
|
|
13
|
+
return setByPath(root, elPath, newEl);
|
|
35
14
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { isEqual } from 'lodash-es';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { createValue, extendWithValue, } from 'react-cosmos-core';
|
|
2
|
+
import { createValue, extendWithValue, isEqual, } from 'react-cosmos-core';
|
|
4
3
|
import { useFixtureState } from '../useFixtureState.js';
|
|
5
4
|
export function useInputFixtureState(inputName, defaultValue) {
|
|
6
5
|
const [, setFixtureState] = useFixtureState('inputs');
|
|
@@ -4,8 +4,8 @@ import { FixtureModule } from '../fixtureModule/FixtureModule.js';
|
|
|
4
4
|
import { LazyModuleLoader } from '../moduleLoaders/LazyModuleLoader.js';
|
|
5
5
|
import { StaticModuleLoader } from '../moduleLoaders/StaticModuleLoader.js';
|
|
6
6
|
import { RendererContext } from '../rendererConnect/RendererContext.js';
|
|
7
|
-
import { FixtureLoaderConnect } from './FixtureLoaderConnect.js';
|
|
8
7
|
import { defaultRenderMessage } from './defaultRenderMessage.js';
|
|
8
|
+
import { FixtureLoaderConnect } from './FixtureLoaderConnect.js';
|
|
9
9
|
export function ClientFixtureLoader({ moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, }) {
|
|
10
10
|
const { selectedFixture } = React.useContext(RendererContext);
|
|
11
11
|
return (React.createElement(FixtureLoaderConnect, { moduleWrappers: moduleWrappers, selectedFixture: selectedFixture, renderMessage: renderMessage, renderFixture: selected => {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import React, { Suspense } from 'react';
|
|
4
4
|
import { FixtureModule } from '../fixtureModule/FixtureModule.js';
|
|
5
5
|
import { AsyncModuleLoader } from '../moduleLoaders/AsyncModuleLoader.js';
|
|
6
|
-
import { FixtureLoaderConnect } from './FixtureLoaderConnect.js';
|
|
7
6
|
import { defaultRenderMessage } from './defaultRenderMessage.js';
|
|
7
|
+
import { FixtureLoaderConnect } from './FixtureLoaderConnect.js';
|
|
8
8
|
export function ServerFixtureLoader({ moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, selectedFixture, fixtureProps, }) {
|
|
9
9
|
return (React.createElement(FixtureLoaderConnect, { moduleWrappers: moduleWrappers, selectedFixture: selectedFixture, renderMessage: renderMessage, renderFixture: selected => (
|
|
10
10
|
// The suspense boundary allows the rendererReady response to be sent
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { isEqual } from 'lodash-es';
|
|
3
2
|
import React from 'react';
|
|
3
|
+
import { isEqual, } from 'react-cosmos-core';
|
|
4
4
|
import { FixtureContext } from '../fixture/FixtureContext.js';
|
|
5
5
|
import { RendererContext } from '../rendererConnect/RendererContext.js';
|
|
6
6
|
export function FixtureProvider(props) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/client.ts","../src/index.ts","../src/
|
|
1
|
+
{"root":["../src/client.ts","../src/index.ts","../src/wrapSetTimeoutAct.ts","../src/fixture/ClassStateMock.tsx","../src/fixture/FixtureContext.ts","../src/fixture/Viewport.tsx","../src/fixture/useFixtureState.ts","../src/fixture/FixtureCapture/FixtureCapture.tsx","../src/fixture/FixtureCapture/classState/index.ts","../src/fixture/FixtureCapture/classState/shared.ts","../src/fixture/FixtureCapture/classState/useFixtureClassState.ts","../src/fixture/FixtureCapture/classState/useReadClassState.ts","../src/fixture/FixtureCapture/classState/decorateFixtureRefs/index.ts","../src/fixture/FixtureCapture/classState/decorateFixtureRefs/isRefSupported.ts","../src/fixture/FixtureCapture/props/index.ts","../src/fixture/FixtureCapture/props/useFixtureProps.ts","../src/fixture/FixtureCapture/shared/findRelevantElementPaths.ts","../src/fixture/FixtureCapture/shared/nodeTree/elPath.ts","../src/fixture/FixtureCapture/shared/nodeTree/findElementPaths.ts","../src/fixture/FixtureCapture/shared/nodeTree/getElementAtPath.ts","../src/fixture/FixtureCapture/shared/nodeTree/index.ts","../src/fixture/FixtureCapture/shared/nodeTree/setElementAtPath.ts","../src/fixture/useCosmosNotification/useCosmosNotification.ts","../src/fixture/useFixtureInput/useCurrentInputValue.ts","../src/fixture/useFixtureInput/useFixtureInput.ts","../src/fixture/useFixtureInput/useInputFixtureState.ts","../src/fixture/useFixtureInput/useSetInputValue.ts","../src/fixture/useFixtureInput/useValue.ts","../src/fixture/useFixtureSelect/shared.ts","../src/fixture/useFixtureSelect/useCurrentSelectValue.ts","../src/fixture/useFixtureSelect/useFixtureSelect.ts","../src/fixture/useFixtureSelect/useSelect.ts","../src/fixture/useFixtureSelect/useSelectFixtureState.ts","../src/fixture/useFixtureSelect/useSetSelectValue.ts","../src/fixtureLoaders/ClientFixtureLoader.tsx","../src/fixtureLoaders/FixtureLoaderConnect.tsx","../src/fixtureLoaders/RendererSync.tsx","../src/fixtureLoaders/SelectedFixture.ts","../src/fixtureLoaders/ServerFixtureLoader.tsx","../src/fixtureLoaders/defaultRenderMessage.tsx","../src/fixtureModule/DecoratedFixture.tsx","../src/fixtureModule/FixtureModule.tsx","../src/fixtureModule/FixtureProvider.tsx","../src/fixtureModule/createFixtureNode.tsx","../src/fixtureModule/decorateFixture.tsx","../src/moduleLoaders/AsyncModuleLoader.tsx","../src/moduleLoaders/LazyModuleLoader.tsx","../src/moduleLoaders/StaticModuleLoader.tsx","../src/moduleLoaders/importLazyFixtureModules.ts","../src/rendererConnect/RendererContext.ts","../src/rendererConnect/RendererProvider.tsx","../src/rendererConnect/StatefulRendererProvider.tsx","../src/rendererConnect/createNoopRendererConnect.ts","../src/rendererConnect/createPostMessageConnect.ts","../src/rendererConnect/createWebSocketsConnect.ts","../src/rendererConnect/globals.d.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-renderer",
|
|
3
|
-
"version": "7.2.0",
|
|
3
|
+
"version": "7.2.1-canary.3822d76.0+3822d76",
|
|
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",
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
"./client": "./client.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"react-cosmos-core": "^7.2.0"
|
|
14
|
+
"react-cosmos-core": "7.2.1-canary.3822d76.0+3822d76"
|
|
16
15
|
},
|
|
17
16
|
"peerDependencies": {
|
|
18
17
|
"react": ">=18"
|
|
19
18
|
},
|
|
20
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "3822d7614f71ce82c282b1516ad18552042ff71a"
|
|
21
20
|
}
|
|
File without changes
|
|
File without changes
|