react-cosmos-core 6.0.0-alpha.9 → 6.0.0-beta.1
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
|
@@ -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);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FixtureList } from '../../
|
|
1
|
+
import { FixtureList } from '../../userModules/fixtureTypes.js';
|
|
2
2
|
import { FixtureTreeNode } from '../types.js';
|
|
3
3
|
export declare function createFixtureTree({ fixtures, fixturesDir, fixtureFileSuffix, }: {
|
|
4
4
|
fixtures: FixtureList;
|
|
@@ -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
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
export * from './fixture/FixtureContext.js';
|
|
2
|
-
export * from './fixture/types.js';
|
|
3
|
-
export * from './fixture/useSelect/index.js';
|
|
4
|
-
export * from './fixture/useValue/index.js';
|
|
5
|
-
export * from './fixture/Viewport.js';
|
|
6
1
|
export * from './fixtureState/classState.js';
|
|
2
|
+
export * from './fixtureState/controls.js';
|
|
3
|
+
export * from './fixtureState/createValues.js';
|
|
4
|
+
export * from './fixtureState/extendWithValues.js';
|
|
7
5
|
export * from './fixtureState/props.js';
|
|
8
6
|
export * from './fixtureState/types.js';
|
|
9
7
|
export * from './fixtureTree/createFixtureTree/index.js';
|
|
10
8
|
export * from './fixtureTree/flattenFixtureTree.js';
|
|
11
9
|
export * from './fixtureTree/types.js';
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './renderer/getSortedDecoratorsForFixturePath.js';
|
|
19
|
-
export * from './renderer/reactTypes.js';
|
|
20
|
-
export * from './renderer/registerPlaygroundShortcuts.js';
|
|
10
|
+
export * from './message/serverMessage.js';
|
|
11
|
+
export * from './message/socketMessage.js';
|
|
12
|
+
export * from './playground/playgroundParams.js';
|
|
13
|
+
export * from './playground/playgroundQueryString.js';
|
|
14
|
+
export * from './playground/registerPlaygroundShortcuts.js';
|
|
15
|
+
export * from './plugin/cosmosPluginConfig.js';
|
|
21
16
|
export * from './renderer/rendererConfig.js';
|
|
22
|
-
export * from './renderer/
|
|
23
|
-
export * from './
|
|
24
|
-
export * from './
|
|
25
|
-
export * from './server/
|
|
17
|
+
export * from './renderer/rendererConnect.js';
|
|
18
|
+
export * from './renderer/rendererQueryString.js';
|
|
19
|
+
export * from './renderer/rendererUrl.js';
|
|
20
|
+
export * from './server/serverTypes.js';
|
|
21
|
+
export * from './userModules/fixtureTypes.js';
|
|
22
|
+
export * from './userModules/getFixtureFromExport.js';
|
|
23
|
+
export * from './userModules/getFixtureList.js';
|
|
24
|
+
export * from './userModules/getSortedDecoratorsForFixturePath.js';
|
|
25
|
+
export * from './userModules/stringifyFixtureId.js';
|
|
26
|
+
export * from './userModules/userModuleTypes.js';
|
|
26
27
|
export * from './utils/array.js';
|
|
27
28
|
export * from './utils/keys.js';
|
|
29
|
+
export * from './utils/queryString.js';
|
|
30
|
+
export * from './utils/react/ClassStateMock.js';
|
|
31
|
+
export * from './utils/react/DelayRender.js';
|
|
28
32
|
export * from './utils/react/areNodesEqual.js';
|
|
29
33
|
export * from './utils/react/getComponentName.js';
|
|
30
34
|
export * from './utils/react/isReactElement.js';
|
|
@@ -32,3 +36,4 @@ export * from './utils/string.js';
|
|
|
32
36
|
export * from './utils/tree.js';
|
|
33
37
|
export * from './utils/types.js';
|
|
34
38
|
export * from './utils/uuid.js';
|
|
39
|
+
export * from './utils/window.js';
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
export * from './fixture/FixtureContext.js';
|
|
2
|
-
export * from './fixture/types.js';
|
|
3
|
-
export * from './fixture/useSelect/index.js';
|
|
4
|
-
export * from './fixture/useValue/index.js';
|
|
5
|
-
export * from './fixture/Viewport.js';
|
|
6
1
|
export * from './fixtureState/classState.js';
|
|
2
|
+
export * from './fixtureState/controls.js';
|
|
3
|
+
export * from './fixtureState/createValues.js';
|
|
4
|
+
export * from './fixtureState/extendWithValues.js';
|
|
7
5
|
export * from './fixtureState/props.js';
|
|
8
6
|
export * from './fixtureState/types.js';
|
|
9
7
|
export * from './fixtureTree/createFixtureTree/index.js';
|
|
10
8
|
export * from './fixtureTree/flattenFixtureTree.js';
|
|
11
9
|
export * from './fixtureTree/types.js';
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './renderer/getSortedDecoratorsForFixturePath.js';
|
|
19
|
-
export * from './renderer/reactTypes.js';
|
|
20
|
-
export * from './renderer/registerPlaygroundShortcuts.js';
|
|
10
|
+
export * from './message/serverMessage.js';
|
|
11
|
+
export * from './message/socketMessage.js';
|
|
12
|
+
export * from './playground/playgroundParams.js';
|
|
13
|
+
export * from './playground/playgroundQueryString.js';
|
|
14
|
+
export * from './playground/registerPlaygroundShortcuts.js';
|
|
15
|
+
export * from './plugin/cosmosPluginConfig.js';
|
|
21
16
|
export * from './renderer/rendererConfig.js';
|
|
22
|
-
export * from './renderer/
|
|
23
|
-
export * from './
|
|
24
|
-
export * from './
|
|
25
|
-
export * from './server/
|
|
17
|
+
export * from './renderer/rendererConnect.js';
|
|
18
|
+
export * from './renderer/rendererQueryString.js';
|
|
19
|
+
export * from './renderer/rendererUrl.js';
|
|
20
|
+
export * from './server/serverTypes.js';
|
|
21
|
+
export * from './userModules/fixtureTypes.js';
|
|
22
|
+
export * from './userModules/getFixtureFromExport.js';
|
|
23
|
+
export * from './userModules/getFixtureList.js';
|
|
24
|
+
export * from './userModules/getSortedDecoratorsForFixturePath.js';
|
|
25
|
+
export * from './userModules/stringifyFixtureId.js';
|
|
26
|
+
export * from './userModules/userModuleTypes.js';
|
|
26
27
|
export * from './utils/array.js';
|
|
27
28
|
export * from './utils/keys.js';
|
|
29
|
+
export * from './utils/queryString.js';
|
|
30
|
+
export * from './utils/react/ClassStateMock.js';
|
|
31
|
+
export * from './utils/react/DelayRender.js';
|
|
28
32
|
export * from './utils/react/areNodesEqual.js';
|
|
29
33
|
export * from './utils/react/getComponentName.js';
|
|
30
34
|
export * from './utils/react/isReactElement.js';
|
|
@@ -32,3 +36,4 @@ export * from './utils/string.js';
|
|
|
32
36
|
export * from './utils/tree.js';
|
|
33
37
|
export * from './utils/types.js';
|
|
34
38
|
export * from './utils/uuid.js';
|
|
39
|
+
export * from './utils/window.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildQueryString, parseQueryString } from '../utils/queryString.js';
|
|
2
|
+
export function buildPlaygroundQueryString(params) {
|
|
3
|
+
return buildQueryString(encodePlaygroundSearchParams(params));
|
|
4
|
+
}
|
|
5
|
+
export function parsePlaygroundQueryString(query) {
|
|
6
|
+
return decodePlaygroundSearchParams(parseQueryString(query));
|
|
7
|
+
}
|
|
8
|
+
function encodePlaygroundSearchParams(params) {
|
|
9
|
+
const stringParams = {};
|
|
10
|
+
if (params.fixtureId) {
|
|
11
|
+
stringParams.fixtureId = JSON.stringify(params.fixtureId);
|
|
12
|
+
}
|
|
13
|
+
return stringParams;
|
|
14
|
+
}
|
|
15
|
+
function decodePlaygroundSearchParams(stringParams) {
|
|
16
|
+
const params = {};
|
|
17
|
+
if (stringParams.fixtureId) {
|
|
18
|
+
params.fixtureId = JSON.parse(stringParams.fixtureId);
|
|
19
|
+
}
|
|
20
|
+
return params;
|
|
21
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
export type RawCosmosPluginConfig = {
|
|
2
2
|
name: string;
|
|
3
3
|
ui?: string;
|
|
4
|
-
|
|
5
|
-
export?: string;
|
|
4
|
+
server?: string;
|
|
6
5
|
};
|
|
7
6
|
export type CosmosPluginConfig = {
|
|
8
7
|
name: string;
|
|
9
8
|
rootDir: string;
|
|
10
9
|
ui?: string;
|
|
11
|
-
|
|
12
|
-
export?: string;
|
|
10
|
+
server?: string;
|
|
13
11
|
};
|
|
14
12
|
export type UiCosmosPluginConfig = CosmosPluginConfig & {
|
|
15
13
|
ui: string;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { FixtureState } from '../fixtureState/types.js';
|
|
2
|
-
import { FixtureId, FixtureList } from '../
|
|
2
|
+
import { FixtureId, FixtureList } from '../userModules/fixtureTypes.js';
|
|
3
3
|
export type RendererId = string;
|
|
4
4
|
export type PingRenderersRequest = {
|
|
5
5
|
type: 'pingRenderers';
|
|
6
6
|
};
|
|
7
|
+
export type ReloadRendererRequest = {
|
|
8
|
+
type: 'reloadRenderer';
|
|
9
|
+
payload: {
|
|
10
|
+
rendererId: RendererId;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
7
13
|
export type SelectFixtureRequest = {
|
|
8
14
|
type: 'selectFixture';
|
|
9
15
|
payload: {
|
|
@@ -26,13 +32,12 @@ export type SetFixtureStateRequest = {
|
|
|
26
32
|
fixtureState: FixtureState;
|
|
27
33
|
};
|
|
28
34
|
};
|
|
29
|
-
export type RendererRequest = PingRenderersRequest | SelectFixtureRequest | UnselectFixtureRequest | SetFixtureStateRequest;
|
|
35
|
+
export type RendererRequest = PingRenderersRequest | ReloadRendererRequest | SelectFixtureRequest | UnselectFixtureRequest | SetFixtureStateRequest;
|
|
30
36
|
export type RendererReadyResponse = {
|
|
31
37
|
type: 'rendererReady';
|
|
32
38
|
payload: {
|
|
33
39
|
rendererId: RendererId;
|
|
34
|
-
|
|
35
|
-
initialFixtureId?: FixtureId;
|
|
40
|
+
selectedFixtureId?: FixtureId | null;
|
|
36
41
|
};
|
|
37
42
|
};
|
|
38
43
|
export type RendererErrorResponse = {
|
|
@@ -65,5 +70,5 @@ export type PlaygroundCommandResponse = {
|
|
|
65
70
|
export type RendererResponse = RendererReadyResponse | RendererErrorResponse | FixtureListUpdateResponse | FixtureStateChangeResponse | PlaygroundCommandResponse;
|
|
66
71
|
export type RendererConnect<Request = RendererRequest, Response = RendererResponse> = {
|
|
67
72
|
postMessage: (msg: Response) => unknown;
|
|
68
|
-
onMessage(handler: (msg: Request) => unknown): () =>
|
|
73
|
+
onMessage(handler: (msg: Request) => unknown): () => void;
|
|
69
74
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FixtureId } from '../userModules/fixtureTypes.js';
|
|
2
|
+
type RendererParams = {
|
|
3
|
+
fixtureId?: FixtureId;
|
|
4
|
+
locked?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type RendererSearchParams = {
|
|
7
|
+
fixtureId?: string;
|
|
8
|
+
locked?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function buildRendererQueryString(params: RendererParams): string;
|
|
11
|
+
export declare function parseRendererQueryString(query: string): RendererParams;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { buildQueryString, parseQueryString } from '../utils/queryString.js';
|
|
2
|
+
export function buildRendererQueryString(params) {
|
|
3
|
+
return buildQueryString(encodeRendererSearchParams(params));
|
|
4
|
+
}
|
|
5
|
+
export function parseRendererQueryString(query) {
|
|
6
|
+
return decodeRendererSearchParams(parseQueryString(query));
|
|
7
|
+
}
|
|
8
|
+
function encodeRendererSearchParams(params) {
|
|
9
|
+
const stringParams = {};
|
|
10
|
+
if (params.fixtureId) {
|
|
11
|
+
stringParams.fixtureId = JSON.stringify(params.fixtureId);
|
|
12
|
+
}
|
|
13
|
+
if (params.locked) {
|
|
14
|
+
stringParams.locked = 'true';
|
|
15
|
+
}
|
|
16
|
+
return stringParams;
|
|
17
|
+
}
|
|
18
|
+
function decodeRendererSearchParams(stringParams) {
|
|
19
|
+
const params = {};
|
|
20
|
+
if (stringParams.fixtureId) {
|
|
21
|
+
params.fixtureId = JSON.parse(stringParams.fixtureId);
|
|
22
|
+
}
|
|
23
|
+
if (stringParams.locked) {
|
|
24
|
+
params.locked = stringParams.locked === 'true';
|
|
25
|
+
}
|
|
26
|
+
return params;
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CosmosCommand } from '../server/serverTypes.js';
|
|
2
|
+
import { FixtureId } from '../userModules/fixtureTypes.js';
|
|
3
|
+
export declare function createRendererUrl(rendererUrl: string, fixtureId?: FixtureId, locked?: boolean): string;
|
|
4
|
+
export declare function pickRendererUrl(rendererUrl: undefined | null | string | {
|
|
5
|
+
dev: string;
|
|
6
|
+
export: string;
|
|
7
|
+
}, command: CosmosCommand): null | string;
|
|
8
|
+
export declare function encodeRendererUrlFixture(fixtureId: FixtureId): string;
|
|
9
|
+
export declare function decodeRendererUrlFixture(fixture: string): FixtureId;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Base64 } from 'js-base64';
|
|
2
|
+
import { buildRendererQueryString } from './rendererQueryString.js';
|
|
3
|
+
export function createRendererUrl(rendererUrl, fixtureId, locked) {
|
|
4
|
+
if (hasFixtureVar(rendererUrl)) {
|
|
5
|
+
if (!fixtureId)
|
|
6
|
+
return replaceFixtureVar(rendererUrl, 'index');
|
|
7
|
+
return (replaceFixtureVar(rendererUrl, encodeRendererUrlFixture(fixtureId)) +
|
|
8
|
+
buildRendererQueryString({ locked }));
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
if (!fixtureId)
|
|
12
|
+
return rendererUrl;
|
|
13
|
+
const baseUrl = hostOnlyUrl(rendererUrl) ? rendererUrl + '/' : rendererUrl;
|
|
14
|
+
return baseUrl + buildRendererQueryString({ fixtureId, locked });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function pickRendererUrl(rendererUrl, command) {
|
|
18
|
+
return rendererUrl && typeof rendererUrl === 'object'
|
|
19
|
+
? rendererUrl[command]
|
|
20
|
+
: rendererUrl ?? null;
|
|
21
|
+
}
|
|
22
|
+
export function encodeRendererUrlFixture(fixtureId) {
|
|
23
|
+
return Base64.encode(JSON.stringify(fixtureId));
|
|
24
|
+
}
|
|
25
|
+
export function decodeRendererUrlFixture(fixture) {
|
|
26
|
+
return JSON.parse(Base64.decode(fixture));
|
|
27
|
+
}
|
|
28
|
+
function hasFixtureVar(rendererUrl) {
|
|
29
|
+
return rendererUrl.includes('<fixture>');
|
|
30
|
+
}
|
|
31
|
+
function replaceFixtureVar(rendererUrl, fixture) {
|
|
32
|
+
return rendererUrl.replace(/<fixture>/g, fixture);
|
|
33
|
+
}
|
|
34
|
+
function hostOnlyUrl(url) {
|
|
35
|
+
try {
|
|
36
|
+
const { protocol, pathname } = new URL(url);
|
|
37
|
+
return (protocol === 'http:' || protocol === 'https:') && pathname === '/';
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type CosmosCommand = 'dev' | 'export';
|
package/dist/{renderer/FixtureLoader/fixtureHelpers.js → userModules/getFixtureFromExport.js}
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { isMultiFixture } from '
|
|
2
|
-
export function
|
|
1
|
+
import { isMultiFixture } from './isMultiFixture.js';
|
|
2
|
+
export function getFixtureFromExport(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
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FixtureList, FixtureListItem } from './fixtureTypes.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>): {
|
|
5
|
+
[x: string]: FixtureListItem;
|
|
6
|
+
};
|
|
7
|
+
export declare function getFixtureItemFromExport(fixtureExport: ReactFixtureExport): FixtureListItem;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isMultiFixture } from './isMultiFixture.js';
|
|
2
|
+
export function getFixtureListFromWrappers(wrappers) {
|
|
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
|
+
};
|
|
10
|
+
}, {});
|
|
11
|
+
}
|
|
12
|
+
export function getFixtureListFromExports(exports) {
|
|
13
|
+
return Object.keys(exports).reduce((acc, fixturePath) => {
|
|
14
|
+
return {
|
|
15
|
+
...acc,
|
|
16
|
+
[fixturePath]: getFixtureItemFromExport(exports[fixturePath]),
|
|
17
|
+
};
|
|
18
|
+
}, {});
|
|
19
|
+
}
|
|
20
|
+
export function getFixtureItemFromExport(fixtureExport) {
|
|
21
|
+
return isMultiFixture(fixtureExport)
|
|
22
|
+
? { type: 'multi', fixtureNames: Object.keys(fixtureExport) }
|
|
23
|
+
: { type: 'single' };
|
|
24
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ComponentType, FunctionComponent, ReactNode } from 'react';
|
|
2
|
+
type FixtureMap<FixtureType> = {
|
|
3
|
+
[fixtureName: string]: FixtureType;
|
|
4
|
+
};
|
|
5
|
+
type FixtureExport<FixtureType> = FixtureType | FixtureMap<FixtureType>;
|
|
6
|
+
type FixtureModule<FixtureType> = {
|
|
7
|
+
default: FixtureExport<FixtureType>;
|
|
8
|
+
};
|
|
9
|
+
type ModuleWrapper<ModuleType> = {
|
|
10
|
+
module: ModuleType;
|
|
11
|
+
};
|
|
12
|
+
type LazyModuleWrapper<ModuleType> = {
|
|
13
|
+
getModule: () => Promise<ModuleType>;
|
|
14
|
+
};
|
|
15
|
+
export type ReactFixture = ReactNode | FunctionComponent;
|
|
16
|
+
export type ReactFixtureMap = FixtureMap<ReactFixture>;
|
|
17
|
+
export type ReactFixtureExport = FixtureExport<ReactFixture>;
|
|
18
|
+
export type ReactFixtureModule = FixtureModule<ReactFixture>;
|
|
19
|
+
export type ReactFixtureWrapper = ModuleWrapper<ReactFixtureModule>;
|
|
20
|
+
export type LazyReactFixtureWrapper = LazyModuleWrapper<ReactFixtureModule>;
|
|
21
|
+
export type ReactDecoratorProps = {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
};
|
|
24
|
+
export type ReactDecorator = ComponentType<ReactDecoratorProps>;
|
|
25
|
+
export type ReactDecoratorModule = {
|
|
26
|
+
default: ReactDecorator;
|
|
27
|
+
};
|
|
28
|
+
export type ReactDecoratorWrapper = ModuleWrapper<ReactDecoratorModule>;
|
|
29
|
+
export type LazyReactDecoratorWrapper = LazyModuleWrapper<ReactDecoratorModule>;
|
|
30
|
+
export type ByPath<T> = Record<string, T>;
|
|
31
|
+
export type UserModuleWrappers = {
|
|
32
|
+
lazy: true;
|
|
33
|
+
fixtures: ByPath<LazyReactFixtureWrapper>;
|
|
34
|
+
decorators: ByPath<LazyReactDecoratorWrapper>;
|
|
35
|
+
} | {
|
|
36
|
+
lazy: false;
|
|
37
|
+
fixtures: ByPath<ReactFixtureWrapper>;
|
|
38
|
+
decorators: ByPath<ReactDecoratorWrapper>;
|
|
39
|
+
};
|
|
40
|
+
export type FixtureModules = {
|
|
41
|
+
fixtureModule: ReactFixtureModule;
|
|
42
|
+
decoratorModules: ReactDecoratorModule[];
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function parseQueryString(query) {
|
|
2
|
+
return Object.fromEntries(new URLSearchParams(query));
|
|
3
|
+
}
|
|
4
|
+
export function buildQueryString(searchParams) {
|
|
5
|
+
const queryString = new URLSearchParams(searchParams).toString();
|
|
6
|
+
return queryString && `?${queryString}`;
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type Props = {
|
|
3
|
+
children: React.ClassicElement<unknown>;
|
|
4
|
+
state?: {};
|
|
5
|
+
};
|
|
6
|
+
export declare class ClassStateMock extends React.Component<Props> {
|
|
7
|
+
static cosmosCapture: boolean;
|
|
8
|
+
childRef: React.Component | null;
|
|
9
|
+
render(): React.CElement<unknown, React.Component<{}, {}, any>>;
|
|
10
|
+
componentDidUpdate(prevProps: Props): void;
|
|
11
|
+
handleRef: (childRef: React.Component | null) => void;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
// Compied from https://github.com/skidding/react-mock/blob/c33dfa1d6f0c9ce7b3eaba073618d61731a0e82e/packages/state/src/index.js
|
|
4
|
+
class ClassStateMock extends React.Component {
|
|
5
|
+
static cosmosCapture = false;
|
|
6
|
+
childRef = null;
|
|
7
|
+
render() {
|
|
8
|
+
const { children } = this.props;
|
|
9
|
+
if (Array.isArray(children)) {
|
|
10
|
+
throw new Error('ClassStateMock only accepts a single child element');
|
|
11
|
+
}
|
|
12
|
+
return React.cloneElement(children, { ref: this.handleRef });
|
|
13
|
+
}
|
|
14
|
+
componentDidUpdate(prevProps) {
|
|
15
|
+
const { childRef } = this;
|
|
16
|
+
const { state } = this.props;
|
|
17
|
+
if (!childRef) {
|
|
18
|
+
throw new Error('childRef missing in ClassStateMock.componentDidUpdate');
|
|
19
|
+
}
|
|
20
|
+
if (state && !isEqual(state, prevProps.state)) {
|
|
21
|
+
replaceState(childRef, state);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
handleRef = (childRef) => {
|
|
25
|
+
const prevRef = this.props.children.ref;
|
|
26
|
+
this.childRef = childRef;
|
|
27
|
+
if (!childRef) {
|
|
28
|
+
if (prevRef)
|
|
29
|
+
manuallyCallRef(prevRef, childRef);
|
|
30
|
+
// Nothing else to do on the unmount branch (when refs are set to NULL)
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (this.props.state) {
|
|
34
|
+
// Wait until state has been set to call prev ref. This will give the
|
|
35
|
+
// impression that the mocked state is the initial state.
|
|
36
|
+
replaceState(childRef, this.props.state, () => {
|
|
37
|
+
manuallyCallRef(prevRef, childRef);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
manuallyCallRef(prevRef, childRef);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export { ClassStateMock };
|
|
46
|
+
function replaceState(childRef, state, cb) {
|
|
47
|
+
// We need to unset existing state keys because React doesn't provide a
|
|
48
|
+
// replaceState method (anymore)
|
|
49
|
+
// https://reactjs.org/docs/react-component.html#setstate
|
|
50
|
+
const nextState = resetOriginalKeys(childRef.state, state);
|
|
51
|
+
if (!isEqual(nextState, childRef.state)) {
|
|
52
|
+
childRef.setState(nextState, cb);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function resetOriginalKeys(original, current) {
|
|
56
|
+
const { keys } = Object;
|
|
57
|
+
return keys(original).reduce((result, key) => keys(result).indexOf(key) === -1
|
|
58
|
+
? { ...result, [key]: undefined }
|
|
59
|
+
: result, current);
|
|
60
|
+
}
|
|
61
|
+
function manuallyCallRef(ref, elRef) {
|
|
62
|
+
if (typeof ref === 'string') {
|
|
63
|
+
throw new Error('StateMock does not support string refs');
|
|
64
|
+
}
|
|
65
|
+
// https://reactjs.org/docs/refs-and-the-dom.html#creating-refs
|
|
66
|
+
if (typeof ref === 'function') {
|
|
67
|
+
ref(elRef);
|
|
68
|
+
}
|
|
69
|
+
else if (ref && typeof ref === 'object') {
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
ref.current = elRef;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export function DelayRender({ children, delay }) {
|
|
4
|
+
const [render, setRender] = React.useState(false);
|
|
5
|
+
React.useEffect(() => {
|
|
6
|
+
const timeoutId = setTimeout(() => setRender(true), delay);
|
|
7
|
+
return () => clearTimeout(timeoutId);
|
|
8
|
+
}, [delay]);
|
|
9
|
+
return React.createElement(React.Fragment, null, render && children);
|
|
10
|
+
}
|