react-cosmos-renderer 6.2.4-canary.97b077a.0 → 6.2.4-canary.b5c8a03.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.d.ts +6 -2
- package/dist/fixture/ClassStateMock.js +2 -3
- package/dist/fixture/FixtureCapture/classState/decorateFixtureRefs/index.js +5 -6
- package/dist/fixture/FixtureCapture/classState/decorateFixtureRefs/isRefSupported.js +1 -2
- package/dist/fixture/FixtureCapture/classState/shared.d.ts +3 -3
- package/dist/fixture/FixtureCapture/classState/useFixtureClassState.d.ts +2 -2
- package/dist/fixture/FixtureCapture/classState/useReadClassState.d.ts +2 -2
- package/dist/fixture/FixtureCapture/shared/nodeTree/getElementAtPath.d.ts +4 -3
- package/dist/fixture/FixtureCapture/shared/nodeTree/setElementAtPath.d.ts +3 -2
- package/dist/fixtureModule/DecoratedFixture.d.ts +1 -1
- package/dist/fixtureModule/FixtureModule.d.ts +1 -1
- package/dist/fixtureModule/createFixtureNode.js +2 -3
- package/dist/moduleLoaders/AsyncModuleLoader.d.ts +1 -1
- package/dist/moduleLoaders/LazyModuleLoader.d.ts +1 -1
- package/dist/moduleLoaders/StaticModuleLoader.d.ts +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/wrapSetTimeoutAct.d.ts +2 -0
- package/dist/wrapSetTimeoutAct.js +14 -0
- package/package.json +3 -4
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
type Props = {
|
|
3
|
-
children: React.
|
|
3
|
+
children: React.ReactElement<{
|
|
4
|
+
ref?: React.Ref<unknown>;
|
|
5
|
+
}>;
|
|
4
6
|
state?: {};
|
|
5
7
|
};
|
|
6
8
|
export declare class ClassStateMock extends React.Component<Props> {
|
|
7
9
|
static cosmosCapture: boolean;
|
|
8
10
|
childRef: React.Component | null;
|
|
9
|
-
render(): React.
|
|
11
|
+
render(): React.ReactElement<{
|
|
12
|
+
ref?: React.Ref<unknown>;
|
|
13
|
+
}, string | React.JSXElementConstructor<any>>;
|
|
10
14
|
componentDidUpdate(prevProps: Props): void;
|
|
11
15
|
handleRef: (childRef: React.Component | null) => void;
|
|
12
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isEqual } from 'lodash-es';
|
|
2
2
|
import React from 'react';
|
|
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;
|
|
6
6
|
childRef = null;
|
|
@@ -22,7 +22,7 @@ export class ClassStateMock extends React.Component {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
handleRef = (childRef) => {
|
|
25
|
-
const prevRef = this.props.children.ref;
|
|
25
|
+
const prevRef = this.props.children.props.ref;
|
|
26
26
|
this.childRef = childRef;
|
|
27
27
|
if (!childRef) {
|
|
28
28
|
if (prevRef)
|
|
@@ -66,7 +66,6 @@ function manuallyCallRef(ref, elRef) {
|
|
|
66
66
|
ref(elRef);
|
|
67
67
|
}
|
|
68
68
|
else if (ref && typeof ref === 'object') {
|
|
69
|
-
// @ts-ignore
|
|
70
69
|
ref.current = elRef;
|
|
71
70
|
}
|
|
72
71
|
}
|
|
@@ -9,8 +9,9 @@ export function decorateFixtureRefs(fixture, spyRef, cachedRefHandlers) {
|
|
|
9
9
|
if (!isRefSupported(element.type)) {
|
|
10
10
|
return element;
|
|
11
11
|
}
|
|
12
|
+
const origRef = element.props.ref;
|
|
12
13
|
return cloneElement(element, {
|
|
13
|
-
ref: getDecoratedRef(
|
|
14
|
+
ref: getDecoratedRef(origRef, spyRef, elPath, cachedRefHandlers),
|
|
14
15
|
});
|
|
15
16
|
});
|
|
16
17
|
}, fixture);
|
|
@@ -26,10 +27,9 @@ function getDecoratedRef(origRef, spyRef, elPath, cachedRefHandlers) {
|
|
|
26
27
|
}
|
|
27
28
|
function decorateRefWithSpy(origRef, spyRef, elPath) {
|
|
28
29
|
return (elRef) => {
|
|
29
|
-
|
|
30
|
-
callOriginalRef(origRef, elRef);
|
|
31
|
-
}
|
|
30
|
+
const callback = origRef ? callOriginalRef(origRef, elRef) : undefined;
|
|
32
31
|
spyRef(elPath, elRef);
|
|
32
|
+
return callback;
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function callOriginalRef(ref, elRef) {
|
|
@@ -38,8 +38,7 @@ function callOriginalRef(ref, elRef) {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
if (typeof ref === 'function') {
|
|
41
|
-
ref(elRef);
|
|
42
|
-
return;
|
|
41
|
+
return ref(elRef);
|
|
43
42
|
}
|
|
44
43
|
const refObj = ref;
|
|
45
44
|
refObj.current = elRef;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ForwardRef } from 'react-is';
|
|
3
2
|
export function isRefSupported(elementType) {
|
|
4
3
|
if (typeof elementType === 'string') {
|
|
5
4
|
return false;
|
|
6
5
|
}
|
|
7
6
|
const { $$typeof, prototype } = elementType;
|
|
8
|
-
return ($$typeof ===
|
|
7
|
+
return ($$typeof === Symbol.for('react.forward_ref') ||
|
|
9
8
|
// Warning: Some functions don't have the .prototype property
|
|
10
9
|
(prototype &&
|
|
11
10
|
// ES6 Class
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { RefCallback } from 'react';
|
|
2
2
|
export type ElRefs = {
|
|
3
3
|
[elPath: string]: React.Component;
|
|
4
4
|
};
|
|
@@ -9,8 +9,8 @@ export type InitialStates = {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
export type CachedRefHandler = {
|
|
12
|
-
origRef:
|
|
13
|
-
handler:
|
|
12
|
+
origRef: undefined | React.Ref<unknown>;
|
|
13
|
+
handler: RefCallback<unknown>;
|
|
14
14
|
};
|
|
15
15
|
export type CachedRefHandlers = {
|
|
16
16
|
[elPath: string]: CachedRefHandler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode, RefObject } from 'react';
|
|
2
2
|
import { FixtureDecoratorId } from 'react-cosmos-core';
|
|
3
3
|
import { ElRefs } from './shared.js';
|
|
4
|
-
export declare function useFixtureClassState(fixture: ReactNode, decoratorId: FixtureDecoratorId, elRefs:
|
|
4
|
+
export declare function useFixtureClassState(fixture: ReactNode, decoratorId: FixtureDecoratorId, elRefs: RefObject<ElRefs>): ReactNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactNode, RefObject } from 'react';
|
|
2
2
|
import { FixtureDecoratorId } from 'react-cosmos-core';
|
|
3
3
|
import { ElRefs } from './shared.js';
|
|
4
|
-
export declare function useReadClassState(fixture: ReactNode, decoratorId: FixtureDecoratorId, elRefs:
|
|
4
|
+
export declare function useReadClassState(fixture: ReactNode, decoratorId: FixtureDecoratorId, elRefs: RefObject<ElRefs>): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactElementWithChildren } from 'react-cosmos-core';
|
|
3
|
+
export declare function getElementAtPath(node: ReactNode, elPath: string): null | ReactElementWithChildren;
|
|
4
|
+
export declare function getExpectedElementAtPath(node: ReactNode, elPath: string): ReactElementWithChildren;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ReactElementWithChildren } from 'react-cosmos-core';
|
|
3
|
+
export declare function setElementAtPath(node: ReactNode, elPath: string, updater: (el: ReactElementWithChildren) => ReactElementWithChildren): ReactNode;
|
|
@@ -6,5 +6,5 @@ type Props = {
|
|
|
6
6
|
userDecoratorModules: ReactDecoratorModule[];
|
|
7
7
|
globalDecorators?: ReactDecorator[];
|
|
8
8
|
};
|
|
9
|
-
export declare function DecoratedFixture({ fixture, fixtureOptions, userDecoratorModules, globalDecorators, }: Props): React.ReactElement<
|
|
9
|
+
export declare function DecoratedFixture({ fixture, fixtureOptions, userDecoratorModules, globalDecorators, }: Props): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
10
10
|
export {};
|
|
@@ -10,5 +10,5 @@ type Props = {
|
|
|
10
10
|
lazy: boolean;
|
|
11
11
|
renderMessage: (msg: string) => React.ReactNode;
|
|
12
12
|
};
|
|
13
|
-
export declare function FixtureModule({ fixtureModule, decoratorModules, globalDecorators, fixtureId, initialFixtureState, renderKey, lazy, renderMessage, }: Props): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<React.
|
|
13
|
+
export declare function FixtureModule({ fixtureModule, decoratorModules, globalDecorators, fixtureId, initialFixtureState, renderKey, lazy, renderMessage, }: Props): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
|
|
14
14
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { isElement } from 'react-is';
|
|
1
|
+
import React, { isValidElement } from 'react';
|
|
3
2
|
export function createFixtureNode(fixture) {
|
|
4
3
|
// Warning: In a React Server Components setup this function is called on the
|
|
5
4
|
// server. When a fixture module uses the 'use client' directive, the fixture
|
|
@@ -20,7 +19,7 @@ function isNodeFixture(fixture) {
|
|
|
20
19
|
Array.isArray(fixture) ||
|
|
21
20
|
// If you're curious what isElement checks:
|
|
22
21
|
// https://github.com/facebook/react/blob/1b0132c05acabae5aebd32c2cadddfb16bda70bc/packages/react-is/src/ReactIs.js#L108-L114
|
|
23
|
-
|
|
22
|
+
isValidElement(fixture));
|
|
24
23
|
}
|
|
25
24
|
function FixtureElement({ Component }) {
|
|
26
25
|
return React.createElement(Component, null);
|
|
@@ -5,5 +5,5 @@ type Props = {
|
|
|
5
5
|
fixturePath: string;
|
|
6
6
|
renderModules: (modules: FixtureModules) => React.ReactElement;
|
|
7
7
|
};
|
|
8
|
-
export declare function AsyncModuleLoader({ moduleWrappers, fixturePath, renderModules, }: Props): Promise<React.ReactElement<
|
|
8
|
+
export declare function AsyncModuleLoader({ moduleWrappers, fixturePath, renderModules, }: Props): Promise<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>;
|
|
9
9
|
export {};
|
|
@@ -6,5 +6,5 @@ type Props = {
|
|
|
6
6
|
fixturePath: string;
|
|
7
7
|
renderModules: (modules: FixtureModules) => React.ReactElement;
|
|
8
8
|
};
|
|
9
|
-
export declare function LazyModuleLoader({ fixtureWrapper, decorators, fixturePath, renderModules, }: Props): React.ReactElement<
|
|
9
|
+
export declare function LazyModuleLoader({ fixtureWrapper, decorators, fixturePath, renderModules, }: Props): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | null;
|
|
10
10
|
export {};
|
|
@@ -6,5 +6,5 @@ type Props = {
|
|
|
6
6
|
fixturePath: string;
|
|
7
7
|
renderModules: (modules: FixtureModules) => React.ReactElement;
|
|
8
8
|
};
|
|
9
|
-
export declare function StaticModuleLoader({ fixtureWrapper, decorators, fixturePath, renderModules, }: Props): React.ReactElement<
|
|
9
|
+
export declare function StaticModuleLoader({ fixtureWrapper, decorators, fixturePath, renderModules, }: Props): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
10
10
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/client.ts","../src/index.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/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/FixtureCapture/shared/nodeTree/shared.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"],"version":"5.7.
|
|
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/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/FixtureCapture/shared/nodeTree/shared.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"],"version":"5.7.3"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { act } from '@testing-library/react';
|
|
2
|
+
const _setTimeout = window.setTimeout;
|
|
3
|
+
export function wrapSetTimeoutAct() {
|
|
4
|
+
window.setTimeout = ((handler, timeout) => {
|
|
5
|
+
return _setTimeout(() => {
|
|
6
|
+
act(() => {
|
|
7
|
+
handler();
|
|
8
|
+
});
|
|
9
|
+
}, timeout);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function clearSetTimeoutAct() {
|
|
13
|
+
window.setTimeout = _setTimeout;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-renderer",
|
|
3
|
-
"version": "6.2.4-canary.
|
|
3
|
+
"version": "6.2.4-canary.b5c8a03.0+b5c8a03",
|
|
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,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"lodash-es": "4.17.21",
|
|
15
|
-
"react-cosmos-core": "6.2.4-canary.
|
|
16
|
-
"react-is": "18.3.1"
|
|
15
|
+
"react-cosmos-core": "6.2.4-canary.b5c8a03.0+b5c8a03"
|
|
17
16
|
},
|
|
18
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "b5c8a035146467474bb975c2ae92f7b1631731c0"
|
|
19
18
|
}
|