react-cosmos 6.0.0-alpha.17 → 6.0.0-alpha.19

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 ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/client.js';
package/client.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/client.js';
@@ -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';
@@ -38,12 +38,7 @@ async function generateImportsFile(cosmosConfig) {
38
38
  });
39
39
  await fs.writeFile(filePath, fileSource, 'utf8');
40
40
  const relModulesPath = path.relative(process.cwd(), filePath);
41
- if (typeScript && typeof exposeImports === 'boolean') {
42
- console.log(`[Cosmos] Generated ${relModulesPath} (TypeScript detected)`);
43
- }
44
- else {
45
- console.log(`[Cosmos] Generated ${relModulesPath}`);
46
- }
41
+ console.log(`[Cosmos] Generated ${relModulesPath}`);
47
42
  }
48
43
  function getDefaultFilePath(rootDir) {
49
44
  const ext = moduleExists('typescript') ? 'ts' : 'js';
@@ -1,5 +1,6 @@
1
1
  import path from 'path';
2
- import { createFixtureTree, flattenFixtureTree, getDecoratedFixtureElement, getFixtureListFromExports, getSortedDecoratorsForFixturePath, stringifyPlaygroundUrlQuery, stringifyRendererUrlQuery, } from 'react-cosmos-core';
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 === undefined
20
- ? fixtureExport
21
- : fixtureExport[fixtureId.name];
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 = stringifyPlaygroundUrlQuery({ fixtureId });
42
- return `${host}/?${query}`;
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 = stringifyRendererUrlQuery({ _fixtureId: fixtureId });
48
+ const query = buildRendererQueryString({ fixtureId });
47
49
  if (rendererUrl)
48
- return `${rendererUrl}?${query}`;
50
+ return rendererUrl + query;
49
51
  const host = getPlaygroundHost(cosmosConfig);
50
52
  const urlPath = resolveRendererUrl(publicUrl, RENDERER_FILENAME);
51
- return new URL(`${urlPath}?${query}`, host).toString();
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 () => getDecoratedFixtureElement(fixture, decorators, {
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 getDevCoreConfig(platformType, cosmosConfig),
17
- rendererCore: { fixtures: getFixtureList(cosmosConfig) },
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,37 @@ export async function getExportPlaygroundHtml(cosmosConfig, pluginConfigs) {
24
27
  return getPlaygroundHtml({
25
28
  playgroundConfig: {
26
29
  ...ui,
27
- core: await getExportCoreConfig(cosmosConfig),
28
- rendererCore: { fixtures: getFixtureList(cosmosConfig) },
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 getDevCoreConfig(platformType, cosmosConfig) {
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
- ...(await getSharedCoreConfig(cosmosConfig)),
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
- async function getExportCoreConfig(cosmosConfig) {
53
- return {
54
- ...(await getSharedCoreConfig(cosmosConfig)),
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
+ return resolveRendererUrl(cosmosConfig.publicUrl, RENDERER_FILENAME);
66
61
  }
67
62
  async function getProjectId(rootDir) {
68
63
  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
- import { Json } from '../utils/json.js';
3
- type Args = {
3
+ type Args<T extends RendererConfig> = {
4
4
  cosmosConfig: CosmosConfig;
5
- rendererConfig: Json;
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 { Json } from '../utils/json.js';
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: Json;
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.17",
3
+ "version": "6.0.0-alpha.19",
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.17",
21
- "react-cosmos-ui": "6.0.0-alpha.17",
20
+ "react-cosmos-core": "6.0.0-alpha.19",
21
+ "react-cosmos-renderer": "6.0.0-alpha.19",
22
+ "react-cosmos-ui": "6.0.0-alpha.19",
22
23
  "ws": "^8.13.0",
23
- "yargs": "^17.7.1"
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": "2369058dc27280b59ef854a9246086d99e94990b"
31
+ "gitHead": "e2ac66d70184f04b23853c3f57b2ec31c5684eb0"
31
32
  }