react-cosmos-core 6.0.0-alpha.9 → 6.0.0-beta.10
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/fixtureState/classState.d.ts +11 -10
- package/dist/fixtureState/classState.js +16 -25
- package/dist/fixtureState/classStateTypes.d.ts +7 -0
- package/dist/fixtureState/controlsTypes.d.ts +14 -0
- package/dist/fixtureState/fixtureState.d.ts +6 -0
- package/dist/fixtureState/fixtureState.js +21 -0
- package/dist/fixtureState/props.d.ts +15 -14
- package/dist/fixtureState/props.js +20 -25
- package/dist/fixtureState/propsTypes.d.ts +9 -0
- package/dist/fixtureState/types.d.ts +2 -31
- package/dist/fixtureState/viewport.d.ts +5 -0
- package/dist/fixtureTree/createFixtureTree/collapseNamedIndexes.js +6 -2
- package/dist/fixtureTree/createFixtureTree/createRawFixtureTree.d.ts +1 -1
- package/dist/fixtureTree/createFixtureTree/createRawFixtureTree.js +4 -9
- 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 +28 -19
- package/dist/index.js +28 -19
- 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/rendererConnect.js +1 -0
- 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/server/serverTypes.js +1 -0
- package/dist/userModules/fixtureTypes.js +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 +72 -0
- package/dist/utils/react/DelayRender.d.ts +7 -0
- package/dist/utils/react/DelayRender.js +10 -0
- package/dist/utils/state.js +1 -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 +6 -5
- 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/fixtureState/controls.d.ts +0 -2
- package/dist/fixtureState/controls.js +0 -4
- 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/{fixture/types.js → fixtureState/classStateTypes.js} +0 -0
- /package/dist/{fixture/useValue/shared.js → fixtureState/controlsTypes.js} +0 -0
- /package/dist/{renderer/reactTypes.js → fixtureState/propsTypes.js} +0 -0
- /package/dist/{renderer/types.js → fixtureState/viewport.js} +0 -0
- /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/{server/cosmosPluginConfig.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/{utils/types.js → plugin/cosmosPluginConfig.js} +0 -0
- /package/dist/{fixture/types.d.ts → userModules/fixtureTypes.d.ts} +0 -0
- /package/dist/{renderer → userModules}/getSortedDecoratorsForFixturePath.js +0 -0
- /package/dist/{renderer → userModules}/isMultiFixture.js +0 -0
- /package/dist/utils/{types.d.ts → state.d.ts} +0 -0
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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,72 @@
|
|
|
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
|
+
export 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
|
+
function replaceState(childRef, state, cb) {
|
|
46
|
+
// We need to unset existing state keys because React doesn't provide a
|
|
47
|
+
// replaceState method (anymore)
|
|
48
|
+
// https://reactjs.org/docs/react-component.html#setstate
|
|
49
|
+
const nextState = resetOriginalKeys(childRef.state, state);
|
|
50
|
+
if (!isEqual(nextState, childRef.state)) {
|
|
51
|
+
childRef.setState(nextState, cb);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function resetOriginalKeys(original, current) {
|
|
55
|
+
const { keys } = Object;
|
|
56
|
+
return keys(original).reduce((result, key) => keys(result).indexOf(key) === -1
|
|
57
|
+
? { ...result, [key]: undefined }
|
|
58
|
+
: result, current);
|
|
59
|
+
}
|
|
60
|
+
function manuallyCallRef(ref, elRef) {
|
|
61
|
+
if (typeof ref === 'string') {
|
|
62
|
+
throw new Error('StateMock does not support string refs');
|
|
63
|
+
}
|
|
64
|
+
// https://reactjs.org/docs/refs-and-the-dom.html#creating-refs
|
|
65
|
+
if (typeof ref === 'function') {
|
|
66
|
+
ref(elRef);
|
|
67
|
+
}
|
|
68
|
+
else if (ref && typeof ref === 'object') {
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
ref.current = elRef;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -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 render && children;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils/string.d.ts
CHANGED
package/dist/utils/string.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
export function replaceKeys(str, map) {
|
|
2
2
|
return Object.keys(map).reduce((res, key) => res.replace(key, map[key]), str);
|
|
3
3
|
}
|
|
4
|
-
export function removeLeadingSlash(fromPath) {
|
|
5
|
-
return fromPath.replace(/^\/+/, '');
|
|
6
|
-
}
|
|
7
|
-
export function removeLeadingDot(fromPath) {
|
|
8
|
-
return fromPath.indexOf('.') === 0 ? fromPath.slice(1) : fromPath;
|
|
9
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isInsideWindowIframe(): boolean;
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-core",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-beta.10",
|
|
4
4
|
"description": "React Cosmos Core",
|
|
5
5
|
"repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-core",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
8
|
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"js-base64": "3.7.5",
|
|
12
|
+
"lodash-es": "4.17.21",
|
|
13
|
+
"react-is": "18.2.0"
|
|
13
14
|
},
|
|
14
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "6e8136d65a0e78ead6dd27d65e1c08cde6999d26"
|
|
15
16
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { FixtureState, SetFixtureState } from '../fixtureState/types.js';
|
|
3
|
-
export type FixtureContextValue = {
|
|
4
|
-
fixtureState: FixtureState;
|
|
5
|
-
setFixtureState: SetFixtureState;
|
|
6
|
-
};
|
|
7
|
-
export declare const FixtureContext: import("react").Context<FixtureContextValue>;
|
package/dist/fixture/Viewport.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { FixtureContext } from './FixtureContext.js';
|
|
3
|
-
// This awkward declaration is required because of the cosmosCapture static
|
|
4
|
-
// property, which makes TS generate a declaration for Viewport that doesn't
|
|
5
|
-
// conform to React's component interface. Without this explicit type TS would
|
|
6
|
-
// allow clients to pass any props to Viewport.
|
|
7
|
-
export const Viewport = function Viewport({ children, width, height, }) {
|
|
8
|
-
const { setFixtureState } = React.useContext(FixtureContext);
|
|
9
|
-
React.useEffect(() => {
|
|
10
|
-
setFixtureState(fixtureState => ({
|
|
11
|
-
...fixtureState,
|
|
12
|
-
viewport: { width, height },
|
|
13
|
-
}));
|
|
14
|
-
}, [setFixtureState, width, height]);
|
|
15
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18051
|
|
16
|
-
return React.createElement(React.Fragment, null, children);
|
|
17
|
-
};
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
Viewport.cosmosCapture = false;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useCreateFixtureState } from './useCreateFixtureState.js';
|
|
2
|
-
import { useCurrentValue } from './useCurrentValue.js';
|
|
3
|
-
import { useSetValue } from './useSetValue.js';
|
|
4
|
-
export function useSelect(selectName, args) {
|
|
5
|
-
if (!args || !args.options || !args.options.length)
|
|
6
|
-
throw new Error('No options provided to useSelect');
|
|
7
|
-
useCreateFixtureState(selectName, args);
|
|
8
|
-
const currentValue = useCurrentValue(selectName, args);
|
|
9
|
-
const setValue = useSetValue(selectName);
|
|
10
|
-
return [currentValue, setValue];
|
|
11
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type UseSelectArgs<Option extends string> = {
|
|
2
|
-
options: Option[];
|
|
3
|
-
defaultValue?: Option;
|
|
4
|
-
};
|
|
5
|
-
export type SetSelectValue<Option extends string> = (value: Option) => void;
|
|
6
|
-
export declare function getDefaultSelectValue<Option extends string>({ options, defaultValue, }: UseSelectArgs<Option>): Option;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
4
|
-
import { getDefaultSelectValue } from './shared.js';
|
|
5
|
-
export function useCreateFixtureState(selectName, args) {
|
|
6
|
-
const { setFixtureState } = React.useContext(FixtureContext);
|
|
7
|
-
const defaultValue = getDefaultSelectValue(args);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
// The fixture state for this select is (re)created in two situations:
|
|
10
|
-
// 1. Initially: No corresponding fixture state select is found
|
|
11
|
-
// 2: Default value change: Current value is reset to new default value
|
|
12
|
-
setFixtureState(prevFs => {
|
|
13
|
-
const fsControl = findFixtureStateControl(prevFs, selectName);
|
|
14
|
-
if (fsControl &&
|
|
15
|
-
fsControl.type === 'select' &&
|
|
16
|
-
fsControl.defaultValue === defaultValue)
|
|
17
|
-
return prevFs;
|
|
18
|
-
return {
|
|
19
|
-
...prevFs,
|
|
20
|
-
controls: {
|
|
21
|
-
...prevFs.controls,
|
|
22
|
-
[selectName]: {
|
|
23
|
-
type: 'select',
|
|
24
|
-
options: args.options,
|
|
25
|
-
defaultValue,
|
|
26
|
-
currentValue: defaultValue,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
}, [args.options, defaultValue, selectName, setFixtureState]);
|
|
32
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
4
|
-
import { getDefaultSelectValue } from './shared.js';
|
|
5
|
-
export function useCurrentValue(selectName, args) {
|
|
6
|
-
const { fixtureState } = useContext(FixtureContext);
|
|
7
|
-
const fsControl = findFixtureStateControl(fixtureState, selectName);
|
|
8
|
-
return fsControl && fsControl.type === 'select'
|
|
9
|
-
? fsControl.currentValue
|
|
10
|
-
: getDefaultSelectValue(args);
|
|
11
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useCallback, useContext } from 'react';
|
|
2
|
-
import { findFixtureStateControl } from '../../fixtureState/controls.js';
|
|
3
|
-
import { FixtureContext } from '../FixtureContext.js';
|
|
4
|
-
export function useSetValue(selectName) {
|
|
5
|
-
const { setFixtureState } = useContext(FixtureContext);
|
|
6
|
-
return useCallback(value => {
|
|
7
|
-
setFixtureState(prevFs => {
|
|
8
|
-
const fsControl = findFixtureStateControl(prevFs, selectName);
|
|
9
|
-
if (!fsControl || fsControl.type !== 'select') {
|
|
10
|
-
console.warn(`Invalid fixture state for select: ${selectName}`);
|
|
11
|
-
return prevFs;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
...prevFs,
|
|
15
|
-
controls: {
|
|
16
|
-
...prevFs.controls,
|
|
17
|
-
[selectName]: {
|
|
18
|
-
...fsControl,
|
|
19
|
-
currentValue: value,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
}, [selectName, setFixtureState]);
|
|
25
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FixtureStateData } from '../../fixtureState/types.js';
|
|
2
|
-
import { SetValue } from './shared.js';
|
|
3
|
-
type Opts<T extends FixtureStateData> = {
|
|
4
|
-
defaultValue: T;
|
|
5
|
-
};
|
|
6
|
-
export declare function useValue<T extends FixtureStateData>(inputName: string, { defaultValue }: Opts<T>): [T, SetValue<T>];
|
|
7
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useCreateFixtureState } from './useCreateFixtureState.js';
|
|
2
|
-
import { useCurrentValue } from './useCurrentValue.js';
|
|
3
|
-
import { useSetValue } from './useSetValue.js';
|
|
4
|
-
export function useValue(inputName, { defaultValue }) {
|
|
5
|
-
useCreateFixtureState(inputName, defaultValue);
|
|
6
|
-
const currentValue = useCurrentValue(inputName, defaultValue);
|
|
7
|
-
const setValue = useSetValue(inputName, defaultValue);
|
|
8
|
-
return [currentValue, setValue];
|
|
9
|
-
}
|