react-cosmos 6.0.0-alpha.18 → 6.0.0-alpha.20
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/client.d.ts +1 -0
- package/client.js +1 -0
- package/config.schema.json +5 -5
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -0
- package/dist/getFixtures/getFixtures.js +12 -14
- package/dist/shared/playgroundHtml.js +26 -30
- package/dist/userModules/generateUserImports.d.ts +4 -4
- package/dist/userModules/shared.d.ts +2 -2
- package/package.json +7 -6
package/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/client.js';
|
package/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/client.js';
|
package/config.schema.json
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-04/schema",
|
|
3
|
-
"title": "JSON schema for React Cosmos configs",
|
|
4
|
-
"type": "object",
|
|
2
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
5
3
|
"additionalProperties": false,
|
|
6
4
|
"properties": {
|
|
7
5
|
"$schema": {
|
|
@@ -22,7 +20,7 @@
|
|
|
22
20
|
"type": "boolean"
|
|
23
21
|
},
|
|
24
22
|
"disablePlugins": {
|
|
25
|
-
"description": "Disable
|
|
23
|
+
"description": "Disable plugins",
|
|
26
24
|
"type": "boolean"
|
|
27
25
|
},
|
|
28
26
|
"staticPath": {
|
|
@@ -228,5 +226,7 @@
|
|
|
228
226
|
}
|
|
229
227
|
}
|
|
230
228
|
}
|
|
231
|
-
}
|
|
229
|
+
},
|
|
230
|
+
"title": "JSON schema for React Cosmos configs",
|
|
231
|
+
"type": "object"
|
|
232
232
|
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Viewport, useSelect, useValue } from 'react-cosmos-renderer/client';
|
package/dist/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Viewport, useSelect, useValue } from 'react-cosmos-renderer/client';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { createFixtureTree, flattenFixtureTree,
|
|
2
|
+
import { buildPlaygroundQueryString, buildRendererQueryString, createFixtureTree, flattenFixtureTree, getFixtureFromExport, getFixtureListFromExports, getSortedDecoratorsForFixturePath, } from 'react-cosmos-core';
|
|
3
|
+
import { createFixtureNode, decorateFixture } from 'react-cosmos-renderer';
|
|
3
4
|
import { RENDERER_FILENAME } from '../shared/playgroundHtml.js';
|
|
4
5
|
import { resolveRendererUrl } from '../shared/resolveRendererUrl.js';
|
|
5
6
|
import { importUserModules } from '../userModules/importUserModules.js';
|
|
@@ -16,9 +17,10 @@ export function getFixtures(cosmosConfig) {
|
|
|
16
17
|
const flatFixtureTree = flattenFixtureTree(fixtureTree);
|
|
17
18
|
flatFixtureTree.forEach(({ fileName, fixtureId, name, parents }) => {
|
|
18
19
|
const fixtureExport = fixtures[fixtureId.path];
|
|
19
|
-
const fixture = fixtureId.name
|
|
20
|
-
|
|
21
|
-
:
|
|
20
|
+
const fixture = getFixtureFromExport(fixtureExport, fixtureId.name);
|
|
21
|
+
if (!fixture) {
|
|
22
|
+
throw new Error(`Could not read fixture: ${JSON.stringify(fixtureId)}`);
|
|
23
|
+
}
|
|
22
24
|
const treePath = [...parents, fileName];
|
|
23
25
|
if (name)
|
|
24
26
|
treePath.push(name);
|
|
@@ -38,26 +40,22 @@ export function getFixtures(cosmosConfig) {
|
|
|
38
40
|
}
|
|
39
41
|
function getPlaygroundUrl(cosmosConfig, fixtureId) {
|
|
40
42
|
const host = getPlaygroundHost(cosmosConfig);
|
|
41
|
-
const query =
|
|
42
|
-
return `${host}
|
|
43
|
+
const query = buildPlaygroundQueryString({ fixtureId });
|
|
44
|
+
return `${host}/${query}`;
|
|
43
45
|
}
|
|
44
46
|
function getRendererUrl(cosmosConfig, fixtureId) {
|
|
45
47
|
const { publicUrl, rendererUrl } = cosmosConfig;
|
|
46
|
-
const query =
|
|
48
|
+
const query = buildRendererQueryString({ fixtureId });
|
|
47
49
|
if (rendererUrl)
|
|
48
|
-
return
|
|
50
|
+
return rendererUrl + query;
|
|
49
51
|
const host = getPlaygroundHost(cosmosConfig);
|
|
50
52
|
const urlPath = resolveRendererUrl(publicUrl, RENDERER_FILENAME);
|
|
51
|
-
return new URL(
|
|
53
|
+
return new URL(urlPath + query, host).toString();
|
|
52
54
|
}
|
|
53
55
|
function getPlaygroundHost({ hostname, port, https }) {
|
|
54
56
|
return `${https ? 'https' : 'http'}://${hostname || 'localhost'}:${port}`;
|
|
55
57
|
}
|
|
56
58
|
function createFixtureElementGetter(fixture, fixturePath, decoratorsByPath) {
|
|
57
59
|
const decorators = getSortedDecoratorsForFixturePath(fixturePath, decoratorsByPath);
|
|
58
|
-
return () =>
|
|
59
|
-
fixtureState: {},
|
|
60
|
-
setFixtureState: () => { },
|
|
61
|
-
onErrorReset: () => { },
|
|
62
|
-
});
|
|
60
|
+
return () => decorateFixture(createFixtureNode(fixture), decorators);
|
|
63
61
|
}
|
|
@@ -13,8 +13,11 @@ export async function getDevPlaygroundHtml(platformType, cosmosConfig, pluginCon
|
|
|
13
13
|
return getPlaygroundHtml({
|
|
14
14
|
playgroundConfig: {
|
|
15
15
|
...ui,
|
|
16
|
-
core: await
|
|
17
|
-
rendererCore: {
|
|
16
|
+
core: await getCoreConfig(cosmosConfig, true),
|
|
17
|
+
rendererCore: {
|
|
18
|
+
fixtures: getFixtureList(cosmosConfig),
|
|
19
|
+
webRendererUrl: getDevServerWebRendereUrl(platformType, cosmosConfig),
|
|
20
|
+
},
|
|
18
21
|
},
|
|
19
22
|
pluginConfigs,
|
|
20
23
|
});
|
|
@@ -24,45 +27,38 @@ export async function getExportPlaygroundHtml(cosmosConfig, pluginConfigs) {
|
|
|
24
27
|
return getPlaygroundHtml({
|
|
25
28
|
playgroundConfig: {
|
|
26
29
|
...ui,
|
|
27
|
-
core: await
|
|
28
|
-
rendererCore: {
|
|
30
|
+
core: await getCoreConfig(cosmosConfig, false),
|
|
31
|
+
rendererCore: {
|
|
32
|
+
fixtures: getFixtureList(cosmosConfig),
|
|
33
|
+
webRendererUrl: getExportWebRendereUrl(cosmosConfig),
|
|
34
|
+
},
|
|
29
35
|
},
|
|
30
36
|
pluginConfigs,
|
|
31
37
|
});
|
|
32
38
|
}
|
|
33
|
-
async function
|
|
39
|
+
async function getCoreConfig(cosmosConfig, devServerOn) {
|
|
40
|
+
const { rootDir, fixturesDir, fixtureFileSuffix } = cosmosConfig;
|
|
41
|
+
return {
|
|
42
|
+
projectId: await getProjectId(rootDir),
|
|
43
|
+
fixturesDir,
|
|
44
|
+
fixtureFileSuffix,
|
|
45
|
+
devServerOn,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function getDevServerWebRendereUrl(platformType, cosmosConfig) {
|
|
34
49
|
switch (platformType) {
|
|
35
50
|
case 'native':
|
|
36
|
-
return
|
|
37
|
-
...(await getSharedCoreConfig(cosmosConfig)),
|
|
38
|
-
devServerOn: true,
|
|
39
|
-
webRendererUrl: null,
|
|
40
|
-
};
|
|
51
|
+
return null;
|
|
41
52
|
case 'web':
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
devServerOn: true,
|
|
45
|
-
webRendererUrl: cosmosConfig.rendererUrl ||
|
|
46
|
-
resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME),
|
|
47
|
-
};
|
|
53
|
+
return (cosmosConfig.rendererUrl ||
|
|
54
|
+
resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME));
|
|
48
55
|
default:
|
|
49
56
|
throw new Error(`Invalid platform type: ${platformType}`);
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
devServerOn: false,
|
|
56
|
-
webRendererUrl: resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
async function getSharedCoreConfig(cosmosConfig) {
|
|
60
|
-
const { rootDir, fixturesDir, fixtureFileSuffix } = cosmosConfig;
|
|
61
|
-
return {
|
|
62
|
-
projectId: await getProjectId(rootDir),
|
|
63
|
-
fixturesDir,
|
|
64
|
-
fixtureFileSuffix,
|
|
65
|
-
};
|
|
59
|
+
function getExportWebRendereUrl(cosmosConfig) {
|
|
60
|
+
// TODO: Allow user to customize renderer URL in static export
|
|
61
|
+
return resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME);
|
|
66
62
|
}
|
|
67
63
|
async function getProjectId(rootDir) {
|
|
68
64
|
const pkgPath = pkgUpSync({ cwd: rootDir });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { RendererConfig } from 'react-cosmos-core';
|
|
1
2
|
import { CosmosConfig } from '../cosmosConfig/types.js';
|
|
2
|
-
|
|
3
|
-
type Args = {
|
|
3
|
+
type Args<T extends RendererConfig> = {
|
|
4
4
|
cosmosConfig: CosmosConfig;
|
|
5
|
-
rendererConfig:
|
|
5
|
+
rendererConfig: T;
|
|
6
6
|
relativeToDir: string | null;
|
|
7
7
|
typeScript: boolean;
|
|
8
8
|
};
|
|
9
|
-
export declare function generateUserImports({ cosmosConfig, rendererConfig, relativeToDir, typeScript, }: Args): string;
|
|
9
|
+
export declare function generateUserImports<T extends RendererConfig>({ cosmosConfig, rendererConfig, relativeToDir, typeScript, }: Args<T>): string;
|
|
10
10
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RendererConfig } from 'react-cosmos-core';
|
|
2
2
|
export type UserImportsTemplateArgs = {
|
|
3
3
|
globalImports: string[];
|
|
4
4
|
fixturePaths: string[];
|
|
5
5
|
decoratorPaths: string[];
|
|
6
|
-
rendererConfig:
|
|
6
|
+
rendererConfig: RendererConfig;
|
|
7
7
|
rootDir: string;
|
|
8
8
|
relativeToDir: string | null;
|
|
9
9
|
typeScript: boolean;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.20",
|
|
4
4
|
"description": "Sandbox for developing and testing UI components in isolation",
|
|
5
5
|
"repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "index.js",
|
|
8
|
+
"main": "./index.js",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@skidding/launch-editor": "^2.2.3",
|
|
11
11
|
"chokidar": "^3.5.3",
|
|
@@ -17,15 +17,16 @@
|
|
|
17
17
|
"open": "^8.4.2",
|
|
18
18
|
"pem": "^1.14.7",
|
|
19
19
|
"pkg-up": "^4.0.0",
|
|
20
|
-
"react-cosmos-core": "6.0.0-alpha.
|
|
21
|
-
"react-cosmos-
|
|
20
|
+
"react-cosmos-core": "6.0.0-alpha.20",
|
|
21
|
+
"react-cosmos-renderer": "6.0.0-alpha.20",
|
|
22
|
+
"react-cosmos-ui": "6.0.0-alpha.20",
|
|
22
23
|
"ws": "^8.13.0",
|
|
23
|
-
"yargs": "^17.7.
|
|
24
|
+
"yargs": "^17.7.2"
|
|
24
25
|
},
|
|
25
26
|
"bin": {
|
|
26
27
|
"cosmos": "./bin/cosmos.js",
|
|
27
28
|
"cosmos-export": "./bin/cosmos-export.js",
|
|
28
29
|
"cosmos-native": "./bin/cosmos-native.js"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "31201ce4185919b054f42b8f15b3e87033af4e69"
|
|
31
32
|
}
|