react-cosmos-core 6.0.0-alpha.19 → 6.0.0-alpha.21

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/index.d.ts CHANGED
@@ -15,12 +15,14 @@ export * from './playground/registerPlaygroundShortcuts.js';
15
15
  export * from './plugin/cosmosPluginConfig.js';
16
16
  export * from './renderer/rendererConfig.js';
17
17
  export * from './renderer/rendererConnect.js';
18
- export * from './renderer/rendererParams.js';
19
18
  export * from './renderer/rendererQueryString.js';
19
+ export * from './renderer/rendererUrl.js';
20
+ export * from './server/serverTypes.js';
20
21
  export * from './userModules/fixtureTypes.js';
21
22
  export * from './userModules/getFixtureFromExport.js';
22
23
  export * from './userModules/getFixtureList.js';
23
24
  export * from './userModules/getSortedDecoratorsForFixturePath.js';
25
+ export * from './userModules/stringifyFixtureId.js';
24
26
  export * from './userModules/userModuleTypes.js';
25
27
  export * from './utils/array.js';
26
28
  export * from './utils/keys.js';
package/dist/index.js CHANGED
@@ -15,12 +15,14 @@ export * from './playground/registerPlaygroundShortcuts.js';
15
15
  export * from './plugin/cosmosPluginConfig.js';
16
16
  export * from './renderer/rendererConfig.js';
17
17
  export * from './renderer/rendererConnect.js';
18
- export * from './renderer/rendererParams.js';
19
18
  export * from './renderer/rendererQueryString.js';
19
+ export * from './renderer/rendererUrl.js';
20
+ export * from './server/serverTypes.js';
20
21
  export * from './userModules/fixtureTypes.js';
21
22
  export * from './userModules/getFixtureFromExport.js';
22
23
  export * from './userModules/getFixtureList.js';
23
24
  export * from './userModules/getSortedDecoratorsForFixturePath.js';
25
+ export * from './userModules/stringifyFixtureId.js';
24
26
  export * from './userModules/userModuleTypes.js';
25
27
  export * from './utils/array.js';
26
28
  export * from './utils/keys.js';
@@ -1,3 +1,4 @@
1
1
  export type RendererConfig = {
2
2
  playgroundUrl: string;
3
+ rendererUrl?: null | string;
3
4
  };
@@ -1,10 +1,12 @@
1
- import { RendererParams } from './rendererParams.js';
1
+ import { FixtureId } from '../userModules/fixtureTypes.js';
2
+ type RendererParams = {
3
+ fixtureId?: FixtureId;
4
+ locked?: boolean;
5
+ };
2
6
  export type RendererSearchParams = {
3
7
  fixtureId?: string;
4
8
  locked?: string;
5
- key?: string;
6
9
  };
7
10
  export declare function buildRendererQueryString(params: RendererParams): string;
8
11
  export declare function parseRendererQueryString(query: string): RendererParams;
9
- export declare function encodeRendererSearchParams(params: RendererParams): RendererSearchParams;
10
- export declare function decodeRendererSearchParams(stringParams: RendererSearchParams): RendererParams;
12
+ export {};
@@ -5,7 +5,7 @@ export function buildRendererQueryString(params) {
5
5
  export function parseRendererQueryString(query) {
6
6
  return decodeRendererSearchParams(parseQueryString(query));
7
7
  }
8
- export function encodeRendererSearchParams(params) {
8
+ function encodeRendererSearchParams(params) {
9
9
  const stringParams = {};
10
10
  if (params.fixtureId) {
11
11
  stringParams.fixtureId = JSON.stringify(params.fixtureId);
@@ -13,12 +13,9 @@ export function encodeRendererSearchParams(params) {
13
13
  if (params.locked) {
14
14
  stringParams.locked = 'true';
15
15
  }
16
- if (params.key) {
17
- stringParams.key = params.key.toString();
18
- }
19
16
  return stringParams;
20
17
  }
21
- export function decodeRendererSearchParams(stringParams) {
18
+ function decodeRendererSearchParams(stringParams) {
22
19
  const params = {};
23
20
  if (stringParams.fixtureId) {
24
21
  params.fixtureId = JSON.parse(stringParams.fixtureId);
@@ -26,8 +23,5 @@ export function decodeRendererSearchParams(stringParams) {
26
23
  if (stringParams.locked) {
27
24
  params.locked = stringParams.locked === 'true';
28
25
  }
29
- if (stringParams.key) {
30
- params.key = parseInt(stringParams.key, 10);
31
- }
32
26
  return params;
33
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,2 @@
1
+ import { FixtureId } from './fixtureTypes.js';
2
+ export declare function stringifyFixtureId(fixtureId: FixtureId): string;
@@ -0,0 +1,4 @@
1
+ export function stringifyFixtureId(fixtureId) {
2
+ const { path, name } = fixtureId;
3
+ return name ? `${path}-${name}` : path;
4
+ }
@@ -1,5 +1,3 @@
1
1
  export declare function replaceKeys(str: string, map: {
2
2
  [key: string]: string;
3
3
  }): string;
4
- export declare function removeLeadingSlash(fromPath: string): string;
5
- export declare function removeLeadingDot(fromPath: string): string;
@@ -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
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos-core",
3
- "version": "6.0.0-alpha.19",
3
+ "version": "6.0.0-alpha.21",
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",
@@ -8,8 +8,9 @@
8
8
  "sideEffects": false,
9
9
  "main": "./dist/index.js",
10
10
  "dependencies": {
11
+ "js-base64": "^3.7.5",
11
12
  "lodash-es": "^4.17.21",
12
13
  "react-is": "^18.2.0"
13
14
  },
14
- "gitHead": "e2ac66d70184f04b23853c3f57b2ec31c5684eb0"
15
+ "gitHead": "1b7472f75075853e5eaf9a427a4c3138818fbcd0"
15
16
  }
@@ -1,6 +0,0 @@
1
- import { FixtureId } from '../userModules/fixtureTypes.js';
2
- export type RendererParams = {
3
- fixtureId?: FixtureId;
4
- locked?: boolean;
5
- key?: number;
6
- };