react-cosmos-ui 6.0.0-alpha.11 → 6.0.0-alpha.13

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.
@@ -2,11 +2,11 @@ import { RefObject } from 'react';
2
2
  import { FixtureId } from 'react-cosmos-core';
3
3
  type Props = {
4
4
  name: string;
5
- fixtureId: FixtureId;
5
+ fixturePath: string;
6
6
  indentLevel: number;
7
7
  selected: boolean;
8
8
  selectedRef: RefObject<HTMLElement>;
9
9
  onSelect: (fixtureId: FixtureId) => unknown;
10
10
  };
11
- export declare function FixtureButton({ name, fixtureId, indentLevel, selected, selectedRef, onSelect, }: Props): JSX.Element;
11
+ export declare function FixtureButton({ name, fixturePath, indentLevel, selected, selectedRef, onSelect, }: Props): JSX.Element;
12
12
  export {};
@@ -3,8 +3,8 @@ import styled from 'styled-components';
3
3
  import { quick } from '../../../style/vars.js';
4
4
  import { FixtureLink } from './FixtureLink.js';
5
5
  import { FixtureTreeItem } from './FixtureTreeItem.js';
6
- export function FixtureButton({ name, fixtureId, indentLevel, selected, selectedRef, onSelect, }) {
7
- return (React.createElement(FixtureLink, { fixtureId: fixtureId, onSelect: onSelect },
6
+ export function FixtureButton({ name, fixturePath, indentLevel, selected, selectedRef, onSelect, }) {
7
+ return (React.createElement(FixtureLink, { fixtureId: { path: fixturePath }, onSelect: onSelect },
8
8
  React.createElement(FixtureTreeItem, { ref: selected ? selectedRef : undefined, indentLevel: indentLevel, selected: selected },
9
9
  React.createElement(Name, null, name))));
10
10
  }
@@ -1,8 +1,7 @@
1
- import { isEqual } from 'lodash-es';
2
1
  import React from 'react';
3
2
  import styled from 'styled-components';
4
3
  import { TreeView } from '../../../components/TreeView.js';
5
- import { nodeContainsFixtureId, recordContainsFixtureId, } from '../../../shared/fixtureTree.js';
4
+ import { fixtureTreeNodeContainsFixtureId } from '../../../shared/fixtureTree.js';
6
5
  import { grey32 } from '../../../style/colors.js';
7
6
  import { FixtureButton } from './FixtureButton.js';
8
7
  import { FixtureDir } from './FixtureDir.js';
@@ -12,19 +11,18 @@ export const FixtureTree = React.memo(function FixtureTree({ rootNode, selectedF
12
11
  React.createElement(TreeView, { node: rootNode, expansion: expansion, setExpansion: setExpansion, renderNode: ({ node, name, parents, expanded, onToggle }) => {
13
12
  const { data, children } = node;
14
13
  if (data.type === 'fixture') {
15
- const selected = isEqual(selectedFixtureId, data.fixtureId);
16
- return (React.createElement(FixtureButton, { name: name, fixtureId: data.fixtureId, indentLevel: parents.length, selected: selected, selectedRef: selectedRef, onSelect: onSelect }));
14
+ const selected = selectedFixtureId?.path === data.path;
15
+ return (React.createElement(FixtureButton, { name: name, fixturePath: data.path, indentLevel: parents.length, selected: selected, selectedRef: selectedRef, onSelect: onSelect }));
17
16
  }
18
17
  if (data.type === 'multiFixture') {
19
- const selected = selectedFixtureId !== null &&
20
- recordContainsFixtureId(data.fixtureIds, selectedFixtureId);
21
- return (React.createElement(MultiFixtureButton, { name: name, fixtureIds: data.fixtureIds, indentLevel: parents.length, selected: selected, selectedFixtureId: selectedFixtureId, selectedRef: selectedRef, onSelect: onSelect }));
18
+ const selected = selectedFixtureId?.path === data.path;
19
+ return (React.createElement(MultiFixtureButton, { name: name, fixturePath: data.path, fixtureNames: data.names, indentLevel: parents.length, selected: selected, selectedFixtureId: selectedFixtureId, selectedRef: selectedRef, onSelect: onSelect }));
22
20
  }
23
21
  if (!children)
24
22
  return null;
25
23
  const selected = !expanded &&
26
24
  selectedFixtureId !== null &&
27
- nodeContainsFixtureId(node, selectedFixtureId);
25
+ fixtureTreeNodeContainsFixtureId(node, selectedFixtureId);
28
26
  return (React.createElement(FixtureDir, { name: name, indentLevel: parents.length, expanded: expanded, selected: selected, onToggle: onToggle }));
29
27
  } })));
30
28
  });
@@ -2,12 +2,13 @@ import { RefObject } from 'react';
2
2
  import { FixtureId } from 'react-cosmos-core';
3
3
  type Props = {
4
4
  name: string;
5
- fixtureIds: Record<string, FixtureId>;
5
+ fixturePath: string;
6
+ fixtureNames: string[];
6
7
  indentLevel: number;
7
8
  selected: boolean;
8
9
  selectedFixtureId: null | FixtureId;
9
10
  selectedRef: RefObject<HTMLElement>;
10
11
  onSelect: (fixtureId: FixtureId) => unknown;
11
12
  };
12
- export declare function MultiFixtureButton({ name, fixtureIds, indentLevel, selected, selectedFixtureId, selectedRef, onSelect, }: Props): JSX.Element | null;
13
+ export declare function MultiFixtureButton({ name, fixturePath, fixtureNames, indentLevel, selected, selectedFixtureId, selectedRef, onSelect, }: Props): JSX.Element;
13
14
  export {};
@@ -1,17 +1,12 @@
1
- import { isEqual } from 'lodash-es';
2
1
  import React from 'react';
3
2
  import styled from 'styled-components';
4
3
  import { grey8 } from '../../../style/colors.js';
5
4
  import { FixtureLink } from './FixtureLink.js';
6
5
  import { FixtureTreeItem } from './FixtureTreeItem.js';
7
6
  import { MultiFixtureChildButton } from './MultiFixtureChildButton.js';
8
- export function MultiFixtureButton({ name, fixtureIds, indentLevel, selected, selectedFixtureId, selectedRef, onSelect, }) {
9
- const fixtureNames = Object.keys(fixtureIds);
10
- const firstFixtureId = fixtureIds[fixtureNames[0]];
11
- if (!firstFixtureId)
12
- return null;
7
+ export function MultiFixtureButton({ name, fixturePath, fixtureNames, indentLevel, selected, selectedFixtureId, selectedRef, onSelect, }) {
13
8
  if (!selected)
14
- return (React.createElement(FixtureLink, { fixtureId: firstFixtureId, onSelect: onSelect },
9
+ return (React.createElement(FixtureLink, { fixtureId: { path: fixturePath }, onSelect: onSelect },
15
10
  React.createElement(FixtureTreeItem, { indentLevel: indentLevel, selected: false },
16
11
  React.createElement(Name, null, name),
17
12
  React.createElement(Count, null, fixtureNames.length))));
@@ -19,9 +14,14 @@ export function MultiFixtureButton({ name, fixtureIds, indentLevel, selected, se
19
14
  React.createElement(FixtureTreeItem, { indentLevel: indentLevel, selected: true },
20
15
  React.createElement(Name, null, name),
21
16
  React.createElement(Count, null, fixtureNames.length)),
22
- fixtureNames.map(fixtureName => {
23
- const fixtureId = fixtureIds[fixtureName];
24
- const childSelected = isEqual(fixtureId, selectedFixtureId);
17
+ fixtureNames.map((fixtureName, index) => {
18
+ const fixtureId = { path: fixturePath, name: fixtureName };
19
+ // Select first child when only the path of a multi fixture is selected
20
+ const childSelected = selectedFixtureId !== null &&
21
+ selectedFixtureId.path === fixturePath &&
22
+ (selectedFixtureId.name === undefined
23
+ ? index === 0
24
+ : fixtureName === selectedFixtureId.name);
25
25
  return (React.createElement(MultiFixtureChildButton, { key: fixtureName, name: fixtureName, fixtureId: fixtureId, indentLevel: indentLevel + 1, selected: childSelected, selectedRef: selectedRef, onSelect: onSelect }));
26
26
  }),
27
27
  React.createElement(FooterPadding, null)));
@@ -1,5 +1,5 @@
1
1
  import { createFixtureTree, } from 'react-cosmos-core';
2
- import { nodeContainsFixtureId } from '../../shared/fixtureTree.js';
2
+ import { fixtureTreeNodeContainsFixtureId } from '../../shared/fixtureTree.js';
3
3
  import { getTreeExpansion, setTreeExpansion, } from './shared.js';
4
4
  export function revealFixture(context, fixtureId) {
5
5
  const { getMethodsOf } = context;
@@ -32,7 +32,7 @@ function findDirPath({ data, children }, fixtureId, parents = []) {
32
32
  for (let childName of childNames) {
33
33
  const childNode = children[childName];
34
34
  if (childNode.data.type !== 'fileDir') {
35
- if (nodeContainsFixtureId(childNode, fixtureId))
35
+ if (fixtureTreeNodeContainsFixtureId(childNode, fixtureId))
36
36
  return parents;
37
37
  }
38
38
  else {
@@ -9,8 +9,9 @@ export function isValidFixtureSelected(context) {
9
9
  return false;
10
10
  }
11
11
  const fixtureItem = fixtures[fixtureId.path];
12
- return fixtureItem.type === 'multi'
13
- ? fixtureId.name !== undefined &&
14
- fixtureItem.fixtureNames.indexOf(fixtureId.name) !== -1
15
- : fixtureId.name === undefined;
12
+ return ((fixtureItem.type === 'single' && fixtureId.name === undefined) ||
13
+ // Allow selecting multi fixtures by path only
14
+ (fixtureItem.type === 'multi' &&
15
+ (fixtureId.name === undefined ||
16
+ fixtureItem.fixtureNames.indexOf(fixtureId.name) !== -1)));
16
17
  }
@@ -0,0 +1,3 @@
1
+ import { FixtureListItemUpdateResponse } from 'react-cosmos-core';
2
+ import { RendererCoreContext } from '../shared/index.js';
3
+ export declare function receiveFixtureListItemUpdateResponse(context: RendererCoreContext, { payload }: FixtureListItemUpdateResponse): void;
@@ -0,0 +1,14 @@
1
+ export function receiveFixtureListItemUpdateResponse(context, { payload }) {
2
+ const { rendererId, fixturePath, fixtureItem } = payload;
3
+ const { primaryRendererId } = context.getState();
4
+ // Discard updates from secondary renderers
5
+ if (rendererId === primaryRendererId) {
6
+ context.setState(prevState => ({
7
+ ...prevState,
8
+ fixtures: {
9
+ ...prevState.fixtures,
10
+ [fixturePath]: fixtureItem,
11
+ },
12
+ }));
13
+ }
14
+ }
@@ -1,3 +1,4 @@
1
+ import { receiveFixtureListItemUpdateResponse } from './fixtureListItemUpdate.js';
1
2
  import { receiveFixtureListUpdateResponse } from './fixtureListUpdate.js';
2
3
  import { receiveFixtureStateChangeResponse } from './fixtureStateChange.js';
3
4
  import { receivePlaygroundCommandResponse } from './playgroundCommand.js';
@@ -10,6 +11,8 @@ export function receiveResponse(context, msg) {
10
11
  return receiveRendererReadyResponse(context, rendererResponse);
11
12
  case 'fixtureListUpdate':
12
13
  return receiveFixtureListUpdateResponse(context, rendererResponse);
14
+ case 'fixtureListItemUpdate':
15
+ return receiveFixtureListItemUpdateResponse(context, rendererResponse);
13
16
  case 'fixtureStateChange':
14
17
  return receiveFixtureStateChangeResponse(context, rendererResponse);
15
18
  case 'playgroundCommand':
@@ -24,7 +24,12 @@ export const RendererHeader = React.memo(function RendererHeader({ fixtureItems,
24
24
  React.createElement(IconButton32, { icon: React.createElement(SlidersIcon, null), title: "Toggle control panel", selected: panelOpen, onClick: onTogglePanel }))));
25
25
  });
26
26
  function findFixtureItemById(fixtureItems, fixtureId) {
27
- return fixtureItems.find(fixtureItem => isEqual(fixtureItem.fixtureId, fixtureId));
27
+ if (fixtureId.name) {
28
+ return fixtureItems.find(fixtureItem => isEqual(fixtureItem.fixtureId, fixtureId));
29
+ }
30
+ // When a multi fixture is selected by path only, the first of its named
31
+ // fixtures will be selected.
32
+ return fixtureItems.find(fixtureItem => fixtureItem.fixtureId.path === fixtureId.path);
28
33
  }
29
34
  function getFixtureName({ name, fileName }) {
30
35
  return name ? `${fileName} ${name}` : fileName;
@@ -1,3 +1,2 @@
1
1
  import { FixtureId, FixtureTreeNode } from 'react-cosmos-core';
2
- export declare function recordContainsFixtureId(fixtureIds: Record<string, FixtureId>, fixtureId: FixtureId): boolean;
3
- export declare function nodeContainsFixtureId({ data, children }: FixtureTreeNode, fixtureId: FixtureId): boolean;
2
+ export declare function fixtureTreeNodeContainsFixtureId({ data, children }: FixtureTreeNode, fixtureId: FixtureId): boolean;
@@ -1,12 +1,7 @@
1
- import { isEqual } from 'lodash-es';
2
- export function recordContainsFixtureId(fixtureIds, fixtureId) {
3
- return Object.keys(fixtureIds).some(fixtureName => isEqual(fixtureIds[fixtureName], fixtureId));
4
- }
5
- export function nodeContainsFixtureId({ data, children }, fixtureId) {
6
- if (data.type === 'fixture')
7
- return isEqual(data.fixtureId, fixtureId);
8
- if (data.type === 'multiFixture')
9
- return recordContainsFixtureId(data.fixtureIds, fixtureId);
1
+ export function fixtureTreeNodeContainsFixtureId({ data, children }, fixtureId) {
2
+ if (data.type === 'fixture' || data.type === 'multiFixture') {
3
+ return data.path === fixtureId.path;
4
+ }
10
5
  return (children !== undefined &&
11
- Object.keys(children).some(childName => nodeContainsFixtureId(children[childName], fixtureId)));
6
+ Object.keys(children).some(childName => fixtureTreeNodeContainsFixtureId(children[childName], fixtureId)));
12
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos-ui",
3
- "version": "6.0.0-alpha.11",
3
+ "version": "6.0.0-alpha.13",
4
4
  "description": "React Cosmos UI",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-ui",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "lodash-es": "^4.17.21",
18
- "react-cosmos-core": "^6.0.0-alpha.11"
18
+ "react-cosmos-core": "6.0.0-alpha.13"
19
19
  },
20
20
  "devDependencies": {
21
21
  "fuzzaldrin-plus": "^0.6.0",
@@ -23,5 +23,5 @@
23
23
  "react-plugin": "^3.0.0-alpha.4",
24
24
  "styled-components": "^5.3.8"
25
25
  },
26
- "gitHead": "8e9d1e52749388f471f6ec848a8c904ec8b89f67"
26
+ "gitHead": "cf95e67ce942f6a242f023ecebe45d6916d5b753"
27
27
  }