react-cosmos-core 6.0.0-alpha.9 → 6.0.0-canary.0b048af.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/fixtureTree/createFixtureTree/createRawFixtureTree.js +3 -8
- package/dist/fixtureTree/flattenFixtureTree.js +3 -3
- package/dist/fixtureTree/types.d.ts +3 -3
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/renderer/DecoratedFixture.d.ts +13 -0
- package/dist/renderer/DecoratedFixture.js +33 -0
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/index.d.ts +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/useFixtureState.d.ts +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/useFixtureState.js +5 -5
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/useReadClassState.d.ts +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/useReadClassState.js +4 -4
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/index.d.ts +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/props/index.d.ts +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/props/index.js +5 -5
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/props/useFixtureProps.d.ts +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/props/useFixtureProps.js +3 -3
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/findElementPaths.js +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/getElementAtPath.js +1 -1
- package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/setElementAtPath.js +1 -1
- package/dist/renderer/FixtureConnect.d.ts +16 -0
- package/dist/renderer/FixtureConnect.js +25 -0
- package/dist/renderer/FixtureLoader.d.ts +17 -0
- package/dist/renderer/FixtureLoader.js +16 -0
- package/dist/renderer/FixtureStateChangeResponse.d.ts +11 -0
- package/dist/renderer/FixtureStateChangeResponse.js +34 -0
- package/dist/renderer/LazyFixtureListItemUpdate.d.ts +10 -0
- package/dist/renderer/LazyFixtureListItemUpdate.js +15 -0
- package/dist/renderer/LazyFixtureLoader.d.ts +20 -0
- package/dist/renderer/LazyFixtureLoader.js +22 -0
- package/dist/renderer/{FixtureLoader/postMessage.d.ts → createPostMessageConnect.d.ts} +1 -1
- package/dist/renderer/{FixtureLoader/postMessage.js → createPostMessageConnect.js} +1 -1
- package/dist/renderer/{FixtureLoader/webSockets.d.ts → createWebSocketsConnect.d.ts} +1 -1
- package/dist/renderer/{FixtureLoader/webSockets.js → createWebSocketsConnect.js} +1 -1
- package/dist/renderer/{FixtureLoader/getDecoratedFixtureElement → getDecoratedFixtureElement}/index.d.ts +1 -1
- package/dist/renderer/{FixtureLoader/fixtureHelpers.d.ts → getFixture.d.ts} +1 -1
- package/dist/renderer/{FixtureLoader/fixtureHelpers.js → getFixture.js} +3 -2
- package/dist/renderer/getFixtureList.d.ts +5 -6
- package/dist/renderer/getFixtureList.js +12 -7
- package/dist/renderer/getSortedDecoratorsForFixturePath.d.ts +2 -2
- package/dist/renderer/isMultiFixture.d.ts +1 -1
- package/dist/renderer/{types.d.ts → rendererConnectTypes.d.ts} +10 -2
- package/dist/renderer/useFixtureModules.d.ts +2 -0
- package/dist/renderer/useFixtureModules.js +10 -0
- package/dist/renderer/useLazyFixtureModules.d.ts +2 -0
- package/dist/renderer/useLazyFixtureModules.js +24 -0
- package/dist/renderer/useRendererRequest.d.ts +5 -0
- package/dist/renderer/useRendererRequest.js +81 -0
- package/dist/renderer/useRendererResponse.d.ts +4 -0
- package/dist/renderer/useRendererResponse.js +23 -0
- package/dist/renderer/useSelectedFixture.d.ts +14 -0
- package/dist/renderer/useSelectedFixture.js +31 -0
- package/dist/renderer/userModuleTypes.d.ts +49 -0
- package/dist/server/cosmosPluginConfig.d.ts +2 -4
- package/package.json +2 -2
- 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/reactTypes.d.ts +0 -28
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/decorateFixtureRefs/index.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/decorateFixtureRefs/index.js +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/decorateFixtureRefs/isRefSupported.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/decorateFixtureRefs/isRefSupported.js +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/index.js +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/shared.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/shared.js +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/index.js +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/findRelevantElementPaths.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/findRelevantElementPaths.js +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/findElementPaths.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/getElementAtPath.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/index.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/index.js +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/setElementAtPath.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/shared.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/shared/nodeTree/shared.js +0 -0
- /package/dist/renderer/{FixtureLoader/getDecoratedFixtureElement → getDecoratedFixtureElement}/FixtureElement.d.ts +0 -0
- /package/dist/renderer/{FixtureLoader/getDecoratedFixtureElement → getDecoratedFixtureElement}/FixtureElement.js +0 -0
- /package/dist/renderer/{FixtureLoader/getDecoratedFixtureElement → getDecoratedFixtureElement}/index.js +0 -0
- /package/dist/renderer/{reactTypes.js → rendererConnectTypes.js} +0 -0
- /package/dist/renderer/{types.js → userModuleTypes.js} +0 -0
|
@@ -13,7 +13,7 @@ function addFixturePathToTree(rootNode, fixturePath, fixtureItem) {
|
|
|
13
13
|
injectNode(rootNode, parents, fileName, {
|
|
14
14
|
data: {
|
|
15
15
|
type: 'fixture',
|
|
16
|
-
|
|
16
|
+
path: fixturePath,
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -21,7 +21,8 @@ function addFixturePathToTree(rootNode, fixturePath, fixtureItem) {
|
|
|
21
21
|
injectNode(rootNode, parents, fileName, {
|
|
22
22
|
data: {
|
|
23
23
|
type: 'multiFixture',
|
|
24
|
-
|
|
24
|
+
path: fixturePath,
|
|
25
|
+
names: fixtureItem.fixtureNames,
|
|
25
26
|
},
|
|
26
27
|
});
|
|
27
28
|
}
|
|
@@ -39,12 +40,6 @@ function parseFixturePath(fixturePath) {
|
|
|
39
40
|
function removeFixtureNameExtension(fixtureName) {
|
|
40
41
|
return fixtureName.replace(/\.(j|t)sx?$/, '');
|
|
41
42
|
}
|
|
42
|
-
function createFixtureIds(fixturePath, fixtureNames) {
|
|
43
|
-
return fixtureNames.reduce((fixtureIds, fixtureName) => ({
|
|
44
|
-
...fixtureIds,
|
|
45
|
-
[fixtureName]: { path: fixturePath, name: fixtureName },
|
|
46
|
-
}), {});
|
|
47
|
-
}
|
|
48
43
|
function injectNode(rootNode, parents, childName, childNode) {
|
|
49
44
|
if (parents.length === 0)
|
|
50
45
|
return addTreeNodeChild(rootNode, childName, childNode);
|
|
@@ -10,16 +10,16 @@ export function flattenFixtureTree(treeNode, parents = []) {
|
|
|
10
10
|
if (childData.type === 'fileDir')
|
|
11
11
|
flatFixtureTree.push(...flattenFixtureTree(childNode, [...parents, childName]));
|
|
12
12
|
if (childData.type === 'multiFixture')
|
|
13
|
-
|
|
13
|
+
childData.names.forEach(fixtureName => flatFixtureTree.push({
|
|
14
14
|
fileName: childName,
|
|
15
|
-
fixtureId: childData.
|
|
15
|
+
fixtureId: { path: childData.path, name: fixtureName },
|
|
16
16
|
parents,
|
|
17
17
|
name: fixtureName,
|
|
18
18
|
}));
|
|
19
19
|
if (childData.type === 'fixture')
|
|
20
20
|
flatFixtureTree.push({
|
|
21
21
|
fileName: childName,
|
|
22
|
-
fixtureId: childData.
|
|
22
|
+
fixtureId: { path: childData.path },
|
|
23
23
|
parents,
|
|
24
24
|
name: null,
|
|
25
25
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { FixtureId } from '../fixture/types.js';
|
|
2
1
|
import { TreeNode } from '../utils/tree.js';
|
|
3
2
|
export type FixtureTreeNode = TreeNode<{
|
|
4
3
|
type: 'fileDir';
|
|
5
4
|
} | {
|
|
6
5
|
type: 'fixture';
|
|
7
|
-
|
|
6
|
+
path: string;
|
|
8
7
|
} | {
|
|
9
8
|
type: 'multiFixture';
|
|
10
|
-
|
|
9
|
+
path: string;
|
|
10
|
+
names: string[];
|
|
11
11
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,16 +10,16 @@ export * from './fixtureTree/createFixtureTree/index.js';
|
|
|
10
10
|
export * from './fixtureTree/flattenFixtureTree.js';
|
|
11
11
|
export * from './fixtureTree/types.js';
|
|
12
12
|
export * from './playground/playgroundUrl.js';
|
|
13
|
-
export * from './renderer/
|
|
14
|
-
export * from './renderer/
|
|
15
|
-
export * from './renderer/
|
|
16
|
-
export * from './renderer/
|
|
13
|
+
export * from './renderer/createPostMessageConnect.js';
|
|
14
|
+
export * from './renderer/createWebSocketsConnect.js';
|
|
15
|
+
export * from './renderer/FixtureConnect.js';
|
|
16
|
+
export * from './renderer/getDecoratedFixtureElement/index.js';
|
|
17
17
|
export * from './renderer/getFixtureList.js';
|
|
18
18
|
export * from './renderer/getSortedDecoratorsForFixturePath.js';
|
|
19
|
-
export * from './renderer/reactTypes.js';
|
|
20
19
|
export * from './renderer/registerPlaygroundShortcuts.js';
|
|
21
20
|
export * from './renderer/rendererConfig.js';
|
|
22
|
-
export * from './renderer/
|
|
21
|
+
export * from './renderer/rendererConnectTypes.js';
|
|
22
|
+
export * from './renderer/userModuleTypes.js';
|
|
23
23
|
export * from './server/cosmosPluginConfig.js';
|
|
24
24
|
export * from './server/serverMessage.js';
|
|
25
25
|
export * from './server/socketMessage.js';
|
package/dist/index.js
CHANGED
|
@@ -10,16 +10,16 @@ export * from './fixtureTree/createFixtureTree/index.js';
|
|
|
10
10
|
export * from './fixtureTree/flattenFixtureTree.js';
|
|
11
11
|
export * from './fixtureTree/types.js';
|
|
12
12
|
export * from './playground/playgroundUrl.js';
|
|
13
|
-
export * from './renderer/
|
|
14
|
-
export * from './renderer/
|
|
15
|
-
export * from './renderer/
|
|
16
|
-
export * from './renderer/
|
|
13
|
+
export * from './renderer/createPostMessageConnect.js';
|
|
14
|
+
export * from './renderer/createWebSocketsConnect.js';
|
|
15
|
+
export * from './renderer/FixtureConnect.js';
|
|
16
|
+
export * from './renderer/getDecoratedFixtureElement/index.js';
|
|
17
17
|
export * from './renderer/getFixtureList.js';
|
|
18
18
|
export * from './renderer/getSortedDecoratorsForFixturePath.js';
|
|
19
|
-
export * from './renderer/reactTypes.js';
|
|
20
19
|
export * from './renderer/registerPlaygroundShortcuts.js';
|
|
21
20
|
export * from './renderer/rendererConfig.js';
|
|
22
|
-
export * from './renderer/
|
|
21
|
+
export * from './renderer/rendererConnectTypes.js';
|
|
22
|
+
export * from './renderer/userModuleTypes.js';
|
|
23
23
|
export * from './server/cosmosPluginConfig.js';
|
|
24
24
|
export * from './server/serverMessage.js';
|
|
25
25
|
export * from './server/socketMessage.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FixtureState, SetFixtureState } from '../fixtureState/types.js';
|
|
2
|
+
import { ReactDecorator, ReactDecoratorModule, ReactFixture } from './userModuleTypes.js';
|
|
3
|
+
type Props = {
|
|
4
|
+
fixture: ReactFixture;
|
|
5
|
+
systemDecorators: ReactDecorator[];
|
|
6
|
+
userDecoratorModules: ReactDecoratorModule[];
|
|
7
|
+
fixtureState: FixtureState;
|
|
8
|
+
setFixtureState: SetFixtureState;
|
|
9
|
+
renderKey: number;
|
|
10
|
+
onErrorReset?: () => unknown;
|
|
11
|
+
};
|
|
12
|
+
export declare function DecoratedFixture({ fixture, systemDecorators, userDecoratorModules, fixtureState, setFixtureState, renderKey, onErrorReset, }: Props): JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { FixtureContext } from '../fixture/FixtureContext.js';
|
|
3
|
+
import { getDecoratedFixtureElement } from './getDecoratedFixtureElement/index.js';
|
|
4
|
+
export function DecoratedFixture({ fixture, systemDecorators, userDecoratorModules, fixtureState, setFixtureState, renderKey, onErrorReset = noop, }) {
|
|
5
|
+
// Prevent unintentional renders https://reactjs.org/docs/context.html#caveats
|
|
6
|
+
const contextValue = useMemo(() => ({ fixtureState, setFixtureState }), [fixtureState, setFixtureState]);
|
|
7
|
+
const decoratedFixture = useMemo(() => {
|
|
8
|
+
const decorators = [
|
|
9
|
+
...systemDecorators,
|
|
10
|
+
...userDecoratorModules.map(m => m.default),
|
|
11
|
+
];
|
|
12
|
+
return getDecoratedFixtureElement(fixture, decorators, {
|
|
13
|
+
fixtureState,
|
|
14
|
+
setFixtureState,
|
|
15
|
+
onErrorReset,
|
|
16
|
+
});
|
|
17
|
+
}, [
|
|
18
|
+
fixture,
|
|
19
|
+
fixtureState,
|
|
20
|
+
onErrorReset,
|
|
21
|
+
setFixtureState,
|
|
22
|
+
systemDecorators,
|
|
23
|
+
userDecoratorModules,
|
|
24
|
+
]);
|
|
25
|
+
return (React.createElement(FixtureContext.Provider
|
|
26
|
+
// renderKey controls whether to reuse previous instances (and
|
|
27
|
+
// transition props) or rebuild render tree from scratch
|
|
28
|
+
, {
|
|
29
|
+
// renderKey controls whether to reuse previous instances (and
|
|
30
|
+
// transition props) or rebuild render tree from scratch
|
|
31
|
+
key: renderKey, value: contextValue }, decoratedFixture));
|
|
32
|
+
}
|
|
33
|
+
function noop() { }
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FixtureDecoratorId } from '
|
|
2
|
+
import { FixtureDecoratorId } from '../../../fixtureState/types.js';
|
|
3
3
|
export declare function useClassStateCapture(fixture: React.ReactNode, decoratorId: FixtureDecoratorId): React.ReactNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MutableRefObject, ReactNode } from 'react';
|
|
2
|
-
import { FixtureDecoratorId } from '
|
|
2
|
+
import { FixtureDecoratorId } from '../../../fixtureState/types.js';
|
|
3
3
|
import { ElRefs } from './shared.js';
|
|
4
4
|
export declare function useFixtureState(fixture: ReactNode, decoratorId: FixtureDecoratorId, elRefs: MutableRefObject<ElRefs>): ReactNode;
|
package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/classState/useFixtureState.js
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isEqual } from 'lodash-es';
|
|
2
2
|
import { useContext, useEffect, useRef, } from 'react';
|
|
3
|
-
import { FixtureContext } from '
|
|
4
|
-
import { createFixtureStateClassState, findFixtureStateClassState, getFixtureStateClassState, removeFixtureStateClassState, } from '
|
|
5
|
-
import { createValues } from '
|
|
6
|
-
import { extendWithValues } from '
|
|
7
|
-
import { getComponentName } from '
|
|
3
|
+
import { FixtureContext } from '../../../fixture/FixtureContext.js';
|
|
4
|
+
import { createFixtureStateClassState, findFixtureStateClassState, getFixtureStateClassState, removeFixtureStateClassState, } from '../../../fixtureState/classState.js';
|
|
5
|
+
import { createValues } from '../../../fixtureState/createValues.js';
|
|
6
|
+
import { extendWithValues } from '../../../fixtureState/extendWithValues.js';
|
|
7
|
+
import { getComponentName } from '../../../utils/react/getComponentName.js';
|
|
8
8
|
import { findRelevantElementPaths } from '../shared/findRelevantElementPaths.js';
|
|
9
9
|
import { decorateFixtureRefs } from './decorateFixtureRefs/index.js';
|
|
10
10
|
import { replaceState, } from './shared.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MutableRefObject, ReactNode } from 'react';
|
|
2
|
-
import { FixtureDecoratorId } from '
|
|
2
|
+
import { FixtureDecoratorId } from '../../../fixtureState/types.js';
|
|
3
3
|
import { ElRefs } from './shared.js';
|
|
4
4
|
export declare function useReadClassState(fixture: ReactNode, decoratorId: FixtureDecoratorId, elRefs: MutableRefObject<ElRefs>): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isEqual } from 'lodash-es';
|
|
2
2
|
import { useContext, useEffect, useRef, } from 'react';
|
|
3
|
-
import { FixtureContext } from '
|
|
4
|
-
import { findFixtureStateClassState, updateFixtureStateClassState, } from '
|
|
5
|
-
import { createValues } from '
|
|
6
|
-
import { extendWithValues } from '
|
|
3
|
+
import { FixtureContext } from '../../../fixture/FixtureContext.js';
|
|
4
|
+
import { findFixtureStateClassState, updateFixtureStateClassState, } from '../../../fixtureState/classState.js';
|
|
5
|
+
import { createValues } from '../../../fixtureState/createValues.js';
|
|
6
|
+
import { extendWithValues } from '../../../fixtureState/extendWithValues.js';
|
|
7
7
|
import { findRelevantElementPaths } from '../shared/findRelevantElementPaths.js';
|
|
8
8
|
// How often to check the state of the loaded component and update the fixture
|
|
9
9
|
// state if it changed
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { FixtureDecoratorId } from '
|
|
2
|
+
import { FixtureDecoratorId } from '../../../fixtureState/types.js';
|
|
3
3
|
export declare function usePropsCapture(fixture: ReactNode, decoratorId: FixtureDecoratorId): ReactNode;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useContext, useEffect, useRef } from 'react';
|
|
2
|
-
import { FixtureContext } from '
|
|
3
|
-
import { createValues } from '
|
|
4
|
-
import { createFixtureStateProps, findFixtureStateProps, getFixtureStateProps, removeFixtureStateProps, updateFixtureStateProps, } from '
|
|
5
|
-
import { areNodesEqual } from '
|
|
6
|
-
import { getComponentName } from '
|
|
2
|
+
import { FixtureContext } from '../../../fixture/FixtureContext.js';
|
|
3
|
+
import { createValues } from '../../../fixtureState/createValues.js';
|
|
4
|
+
import { createFixtureStateProps, findFixtureStateProps, getFixtureStateProps, removeFixtureStateProps, updateFixtureStateProps, } from '../../../fixtureState/props.js';
|
|
5
|
+
import { areNodesEqual } from '../../../utils/react/areNodesEqual.js';
|
|
6
|
+
import { getComponentName } from '../../../utils/react/getComponentName.js';
|
|
7
7
|
import { findRelevantElementPaths } from '../shared/findRelevantElementPaths.js';
|
|
8
8
|
import { getElementAtPath, getExpectedElementAtPath, } from '../shared/nodeTree/index.js';
|
|
9
9
|
import { useFixtureProps } from './useFixtureProps.js';
|
package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/props/useFixtureProps.d.ts
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FixtureDecoratorId, FixtureState } from '
|
|
2
|
+
import { FixtureDecoratorId, FixtureState } from '../../../fixtureState/types.js';
|
|
3
3
|
export declare function useFixtureProps(fixture: React.ReactNode, fixtureState: FixtureState, decoratorId: FixtureDecoratorId): React.ReactNode;
|
package/dist/renderer/{FixtureLoader/FixtureCapture → FixtureCapture}/props/useFixtureProps.js
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isEqual, mapValues } from 'lodash-es';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { extendWithValues } from '
|
|
4
|
-
import { DEFAULT_RENDER_KEY, findFixtureStateProps, } from '
|
|
5
|
-
import { getComponentName } from '
|
|
3
|
+
import { extendWithValues } from '../../../fixtureState/extendWithValues.js';
|
|
4
|
+
import { DEFAULT_RENDER_KEY, findFixtureStateProps, } from '../../../fixtureState/props.js';
|
|
5
|
+
import { getComponentName } from '../../../utils/react/getComponentName.js';
|
|
6
6
|
import { findRelevantElementPaths } from '../shared/findRelevantElementPaths.js';
|
|
7
7
|
import { getChildrenPath, setElementAtPath } from '../shared/nodeTree/index.js';
|
|
8
8
|
export function useFixtureProps(fixture, fixtureState, decoratorId) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { flatten } from 'lodash-es';
|
|
2
2
|
import { Fragment } from 'react';
|
|
3
|
-
import { isReactElement } from '
|
|
3
|
+
import { isReactElement } from '../../../../utils/react/isReactElement.js';
|
|
4
4
|
import { getChildrenPath } from './shared.js';
|
|
5
5
|
export function findElementPaths(node, curPath = '') {
|
|
6
6
|
if (Array.isArray(node)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { get } from 'lodash-es';
|
|
2
|
-
import { isReactElement } from '
|
|
2
|
+
import { isReactElement } from '../../../../utils/react/isReactElement.js';
|
|
3
3
|
import { isRootPath } from './shared.js';
|
|
4
4
|
// Why be silent about trying to fetch a node that isn't an element?
|
|
5
5
|
// Because users of this utility only care about elements. Whether the child
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { set } from 'lodash-es';
|
|
2
|
-
import { isReactElement } from '
|
|
2
|
+
import { isReactElement } from '../../../../utils/react/isReactElement.js';
|
|
3
3
|
import { getExpectedElementAtPath } from './getElementAtPath.js';
|
|
4
4
|
import { isRootPath } from './shared.js';
|
|
5
5
|
export function setElementAtPath(node, elPath, updater) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { FixtureId } from '../fixture/types.js';
|
|
3
|
+
import { RendererConnect } from './rendererConnectTypes.js';
|
|
4
|
+
import { ReactDecorator, UserModuleWrappers } from './userModuleTypes.js';
|
|
5
|
+
type Props = {
|
|
6
|
+
rendererId: string;
|
|
7
|
+
rendererConnect: RendererConnect;
|
|
8
|
+
moduleWrappers: UserModuleWrappers;
|
|
9
|
+
systemDecorators: ReactDecorator[];
|
|
10
|
+
initialFixtureId?: FixtureId;
|
|
11
|
+
selectedFixtureId?: null | FixtureId;
|
|
12
|
+
renderMessage?: (msg: string) => ReactElement;
|
|
13
|
+
onErrorReset?: () => unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare function FixtureConnect({ rendererId, rendererConnect, moduleWrappers, systemDecorators, initialFixtureId, selectedFixtureId, onErrorReset, renderMessage, }: Props): JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FixtureLoader } from './FixtureLoader.js';
|
|
3
|
+
import { FixtureStateChangeResponse } from './FixtureStateChangeResponse.js';
|
|
4
|
+
import { LazyFixtureLoader } from './LazyFixtureLoader.js';
|
|
5
|
+
import { useRendererRequest } from './useRendererRequest.js';
|
|
6
|
+
import { useRendererResponse } from './useRendererResponse.js';
|
|
7
|
+
import { useSelectedFixture } from './useSelectedFixture.js';
|
|
8
|
+
export function FixtureConnect({ rendererId, rendererConnect, moduleWrappers, systemDecorators, initialFixtureId, selectedFixtureId, onErrorReset, renderMessage = defaultRenderMessage, }) {
|
|
9
|
+
const { selectedFixture, setSelectedFixture, setFixtureState } = useSelectedFixture(initialFixtureId, selectedFixtureId);
|
|
10
|
+
useRendererRequest(rendererId, rendererConnect, moduleWrappers, setSelectedFixture, onErrorReset);
|
|
11
|
+
useRendererResponse(rendererId, rendererConnect, moduleWrappers, initialFixtureId);
|
|
12
|
+
if (!selectedFixture) {
|
|
13
|
+
return renderMessage('No fixture selected.');
|
|
14
|
+
}
|
|
15
|
+
const { fixtureId, fixtureState, renderKey } = selectedFixture;
|
|
16
|
+
if (!moduleWrappers.fixtures[fixtureId.path]) {
|
|
17
|
+
return renderMessage(`Fixture path not found: ${fixtureId.path}`);
|
|
18
|
+
}
|
|
19
|
+
return (React.createElement(React.Fragment, null,
|
|
20
|
+
moduleWrappers.lazy ? (React.createElement(LazyFixtureLoader, { rendererId: rendererId, rendererConnect: rendererConnect, fixtureWrapper: moduleWrappers.fixtures[fixtureId.path], decorators: moduleWrappers.decorators, systemDecorators: systemDecorators, fixtureId: fixtureId, fixtureState: fixtureState, setFixtureState: setFixtureState, renderMessage: renderMessage, renderKey: renderKey, onErrorReset: onErrorReset })) : (React.createElement(FixtureLoader, { fixtureWrapper: moduleWrappers.fixtures[fixtureId.path], decorators: moduleWrappers.decorators, systemDecorators: systemDecorators, fixtureId: fixtureId, fixtureState: fixtureState, setFixtureState: setFixtureState, renderMessage: renderMessage, renderKey: renderKey, onErrorReset: onErrorReset })),
|
|
21
|
+
React.createElement(FixtureStateChangeResponse, { rendererId: rendererId, rendererConnect: rendererConnect, selectedFixture: selectedFixture, setSelectedFixture: setSelectedFixture })));
|
|
22
|
+
}
|
|
23
|
+
function defaultRenderMessage(msg) {
|
|
24
|
+
return React.createElement(React.Fragment, null, msg);
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { FixtureId } from '../fixture/types.js';
|
|
3
|
+
import { FixtureState, SetFixtureState } from '../fixtureState/types.js';
|
|
4
|
+
import { ByPath, ReactDecorator, ReactDecoratorWrapper, ReactFixtureWrapper } from './userModuleTypes.js';
|
|
5
|
+
type Props = {
|
|
6
|
+
fixtureWrapper: ReactFixtureWrapper;
|
|
7
|
+
decorators: ByPath<ReactDecoratorWrapper>;
|
|
8
|
+
systemDecorators: ReactDecorator[];
|
|
9
|
+
fixtureId: FixtureId;
|
|
10
|
+
fixtureState: FixtureState;
|
|
11
|
+
setFixtureState: SetFixtureState;
|
|
12
|
+
renderMessage: (msg: string) => ReactElement;
|
|
13
|
+
renderKey: number;
|
|
14
|
+
onErrorReset?: () => unknown;
|
|
15
|
+
};
|
|
16
|
+
export declare function FixtureLoader({ fixtureWrapper, decorators, systemDecorators, fixtureId, fixtureState, setFixtureState, renderMessage, renderKey, onErrorReset, }: Props): JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { DecoratedFixture } from './DecoratedFixture.js';
|
|
3
|
+
import { getFixture } from './getFixture.js';
|
|
4
|
+
import { getSortedDecoratorsForFixturePath } from './getSortedDecoratorsForFixturePath.js';
|
|
5
|
+
import { useFixtureModules } from './useFixtureModules.js';
|
|
6
|
+
export function FixtureLoader({ fixtureWrapper, decorators, systemDecorators, fixtureId, fixtureState, setFixtureState, renderMessage, renderKey, onErrorReset, }) {
|
|
7
|
+
const decoratorWrappers = useMemo(() => getSortedDecoratorsForFixturePath(fixtureId.path, decorators), [decorators, fixtureId.path]);
|
|
8
|
+
const modules = useFixtureModules(fixtureId.path, fixtureWrapper, decoratorWrappers);
|
|
9
|
+
const { fixtureModule, decoratorModules } = modules;
|
|
10
|
+
const fixtureExport = fixtureModule.default;
|
|
11
|
+
const fixture = getFixture(fixtureExport, fixtureId.name);
|
|
12
|
+
if (typeof fixture === 'undefined') {
|
|
13
|
+
return renderMessage(`Invalid fixture ID: ${JSON.stringify(fixtureId)}`);
|
|
14
|
+
}
|
|
15
|
+
return (React.createElement(DecoratedFixture, { fixture: fixture, systemDecorators: systemDecorators, userDecoratorModules: decoratorModules, fixtureState: fixtureState, setFixtureState: setFixtureState, renderKey: renderKey, onErrorReset: onErrorReset }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { RendererConnect } from './rendererConnectTypes.js';
|
|
3
|
+
import { SelectedFixture } from './useSelectedFixture.js';
|
|
4
|
+
type Props = {
|
|
5
|
+
rendererId: string;
|
|
6
|
+
rendererConnect: RendererConnect;
|
|
7
|
+
selectedFixture: SelectedFixture;
|
|
8
|
+
setSelectedFixture: Dispatch<SetStateAction<SelectedFixture | null>>;
|
|
9
|
+
};
|
|
10
|
+
export declare function FixtureStateChangeResponse({ rendererId, rendererConnect, selectedFixture, setSelectedFixture, }: Props): null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
export function FixtureStateChangeResponse({ rendererId, rendererConnect, selectedFixture, setSelectedFixture, }) {
|
|
4
|
+
const { fixtureId, fixtureState, syncedFixtureState } = selectedFixture;
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (!isEqual(fixtureState, syncedFixtureState)) {
|
|
7
|
+
rendererConnect.postMessage({
|
|
8
|
+
type: 'fixtureStateChange',
|
|
9
|
+
payload: {
|
|
10
|
+
rendererId,
|
|
11
|
+
fixtureId,
|
|
12
|
+
fixtureState,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
setSelectedFixture(prev => {
|
|
16
|
+
// Ensure fixture state applies to currently selected fixture
|
|
17
|
+
if (prev && isEqual(prev.fixtureId, fixtureId)) {
|
|
18
|
+
return { ...prev, syncedFixtureState: fixtureState };
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return prev;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}, [
|
|
26
|
+
fixtureId,
|
|
27
|
+
fixtureState,
|
|
28
|
+
rendererConnect,
|
|
29
|
+
rendererId,
|
|
30
|
+
setSelectedFixture,
|
|
31
|
+
syncedFixtureState,
|
|
32
|
+
]);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RendererConnect } from './rendererConnectTypes.js';
|
|
2
|
+
import { ReactFixtureModule } from './userModuleTypes.js';
|
|
3
|
+
type Props = {
|
|
4
|
+
rendererId: string;
|
|
5
|
+
rendererConnect: RendererConnect;
|
|
6
|
+
fixturePath: string;
|
|
7
|
+
fixtureModule: ReactFixtureModule;
|
|
8
|
+
};
|
|
9
|
+
export declare function LazyFixtureListItemUpdate({ rendererId, rendererConnect, fixturePath, fixtureModule, }: Props): null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { getFixtureItemFromExport } from './getFixtureList.js';
|
|
3
|
+
export function LazyFixtureListItemUpdate({ rendererId, rendererConnect, fixturePath, fixtureModule, }) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
rendererConnect.postMessage({
|
|
6
|
+
type: 'fixtureListItemUpdate',
|
|
7
|
+
payload: {
|
|
8
|
+
rendererId,
|
|
9
|
+
fixturePath,
|
|
10
|
+
fixtureItem: getFixtureItemFromExport(fixtureModule.default),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}, [fixtureModule.default, fixturePath, rendererConnect, rendererId]);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { FixtureId } from '../fixture/types.js';
|
|
3
|
+
import { FixtureState, SetFixtureState } from '../fixtureState/types.js';
|
|
4
|
+
import { RendererConnect } from './rendererConnectTypes.js';
|
|
5
|
+
import { ByPath, LazyReactDecoratorWrapper, LazyReactFixtureWrapper, ReactDecorator } from './userModuleTypes.js';
|
|
6
|
+
type Props = {
|
|
7
|
+
rendererId: string;
|
|
8
|
+
rendererConnect: RendererConnect;
|
|
9
|
+
fixtureWrapper: LazyReactFixtureWrapper;
|
|
10
|
+
decorators: ByPath<LazyReactDecoratorWrapper>;
|
|
11
|
+
systemDecorators: ReactDecorator[];
|
|
12
|
+
fixtureId: FixtureId;
|
|
13
|
+
fixtureState: FixtureState;
|
|
14
|
+
setFixtureState: SetFixtureState;
|
|
15
|
+
renderMessage: (msg: string) => ReactElement;
|
|
16
|
+
renderKey: number;
|
|
17
|
+
onErrorReset?: () => unknown;
|
|
18
|
+
};
|
|
19
|
+
export declare function LazyFixtureLoader({ rendererId, rendererConnect, fixtureWrapper, decorators, systemDecorators, fixtureId, fixtureState, setFixtureState, renderMessage, renderKey, onErrorReset, }: Props): JSX.Element | null;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { DecoratedFixture } from './DecoratedFixture.js';
|
|
3
|
+
import { getFixture } from './getFixture.js';
|
|
4
|
+
import { getSortedDecoratorsForFixturePath } from './getSortedDecoratorsForFixturePath.js';
|
|
5
|
+
import { LazyFixtureListItemUpdate } from './LazyFixtureListItemUpdate.js';
|
|
6
|
+
import { useLazyFixtureModules } from './useLazyFixtureModules.js';
|
|
7
|
+
export function LazyFixtureLoader({ rendererId, rendererConnect, fixtureWrapper, decorators, systemDecorators, fixtureId, fixtureState, setFixtureState, renderMessage, renderKey, onErrorReset, }) {
|
|
8
|
+
const decoratorWrappers = useMemo(() => getSortedDecoratorsForFixturePath(fixtureId.path, decorators), [decorators, fixtureId.path]);
|
|
9
|
+
const modules = useLazyFixtureModules(fixtureId.path, fixtureWrapper, decoratorWrappers);
|
|
10
|
+
if (!modules) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const { fixtureModule, decoratorModules } = modules;
|
|
14
|
+
const fixtureExport = fixtureModule.default;
|
|
15
|
+
const fixture = getFixture(fixtureExport, fixtureId.name);
|
|
16
|
+
if (typeof fixture === 'undefined') {
|
|
17
|
+
return renderMessage(`Invalid fixture ID: ${JSON.stringify(fixtureId)}`);
|
|
18
|
+
}
|
|
19
|
+
return (React.createElement(React.Fragment, null,
|
|
20
|
+
React.createElement(DecoratedFixture, { fixture: fixture, systemDecorators: systemDecorators, userDecoratorModules: decoratorModules, fixtureState: fixtureState, setFixtureState: setFixtureState, renderKey: renderKey, onErrorReset: onErrorReset }),
|
|
21
|
+
React.createElement(LazyFixtureListItemUpdate, { rendererId: rendererId, rendererConnect: rendererConnect, fixturePath: fixtureId.path, fixtureModule: fixtureModule })));
|
|
22
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RendererConnect } from '
|
|
1
|
+
import { RendererConnect } from './rendererConnectTypes.js';
|
|
2
2
|
export declare function createPostMessageConnect(): RendererConnect;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RendererConnect } from '
|
|
1
|
+
import { RendererConnect } from './rendererConnectTypes.js';
|
|
2
2
|
export declare function createWebSocketsConnect(url: string): RendererConnect;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ReactDecorator, ReactDecoratorProps, ReactFixture } from '
|
|
1
|
+
import { ReactDecorator, ReactDecoratorProps, ReactFixture } from '../userModuleTypes.js';
|
|
2
2
|
export declare function getDecoratedFixtureElement(fixture: ReactFixture, decorators: ReactDecorator[], decoratorProps: Omit<ReactDecoratorProps, 'children'>): JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ReactFixture, ReactFixtureExport } from '
|
|
1
|
+
import { ReactFixture, ReactFixtureExport } from './userModuleTypes.js';
|
|
2
2
|
export declare function getFixture(fixtureExport: ReactFixtureExport, fixtureName?: string): void | ReactFixture;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { isMultiFixture } from '
|
|
1
|
+
import { isMultiFixture } from './isMultiFixture.js';
|
|
2
2
|
export function getFixture(fixtureExport, fixtureName) {
|
|
3
3
|
if (fixtureName === undefined) {
|
|
4
4
|
if (isMultiFixture(fixtureExport)) {
|
|
5
5
|
// Fixture name missing in multi fixture
|
|
6
|
-
|
|
6
|
+
const fixtureNames = Object.keys(fixtureExport);
|
|
7
|
+
return fixtureExport[fixtureNames[0]];
|
|
7
8
|
}
|
|
8
9
|
return fixtureExport;
|
|
9
10
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { FixtureListItem } from '../fixture/types.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare function getFixtureListFromWrappers(wrappers:
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export declare function getFixtureListFromExports(exports: ReactFixtureExports): {
|
|
1
|
+
import { FixtureList, FixtureListItem } from '../fixture/types.js';
|
|
2
|
+
import { ByPath, ReactFixtureExport, UserModuleWrappers } from './userModuleTypes.js';
|
|
3
|
+
export declare function getFixtureListFromWrappers(wrappers: UserModuleWrappers): FixtureList;
|
|
4
|
+
export declare function getFixtureListFromExports(exports: ByPath<ReactFixtureExport>): {
|
|
7
5
|
[x: string]: FixtureListItem;
|
|
8
6
|
};
|
|
7
|
+
export declare function getFixtureItemFromExport(fixtureExport: ReactFixtureExport): FixtureListItem;
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { isMultiFixture } from './isMultiFixture.js';
|
|
2
2
|
export function getFixtureListFromWrappers(wrappers) {
|
|
3
|
-
return Object.keys(wrappers).reduce((acc, fixturePath) => {
|
|
4
|
-
return {
|
|
3
|
+
return Object.keys(wrappers.fixtures).reduce((acc, fixturePath) => {
|
|
4
|
+
return {
|
|
5
|
+
...acc,
|
|
6
|
+
[fixturePath]: wrappers.lazy
|
|
7
|
+
? { type: 'single' }
|
|
8
|
+
: getFixtureItemFromExport(wrappers.fixtures[fixturePath].module.default),
|
|
9
|
+
};
|
|
5
10
|
}, {});
|
|
6
11
|
}
|
|
7
12
|
export function getFixtureListFromExports(exports) {
|
|
8
13
|
return Object.keys(exports).reduce((acc, fixturePath) => {
|
|
9
|
-
return {
|
|
14
|
+
return {
|
|
15
|
+
...acc,
|
|
16
|
+
[fixturePath]: getFixtureItemFromExport(exports[fixturePath]),
|
|
17
|
+
};
|
|
10
18
|
}, {});
|
|
11
19
|
}
|
|
12
|
-
function
|
|
13
|
-
return getItemFromExport(wrapper.module.default);
|
|
14
|
-
}
|
|
15
|
-
function getItemFromExport(fixtureExport) {
|
|
20
|
+
export function getFixtureItemFromExport(fixtureExport) {
|
|
16
21
|
return isMultiFixture(fixtureExport)
|
|
17
22
|
? { type: 'multi', fixtureNames: Object.keys(fixtureExport) }
|
|
18
23
|
: { type: 'single' };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getSortedDecoratorsForFixturePath(fixturePath: string, decoratorsByPath:
|
|
1
|
+
import { ByPath } from './userModuleTypes.js';
|
|
2
|
+
export declare function getSortedDecoratorsForFixturePath<T>(fixturePath: string, decoratorsByPath: ByPath<T>): T[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ReactFixtureExport, ReactFixtureMap } from './
|
|
1
|
+
import { ReactFixtureExport, ReactFixtureMap } from './userModuleTypes.js';
|
|
2
2
|
export declare function isMultiFixture(fixtureExport: ReactFixtureExport): fixtureExport is ReactFixtureMap;
|