react-cosmos-renderer 7.0.1-canary.e020233.0 → 7.1.0

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.
@@ -1,8 +1,8 @@
1
1
  import { NotificationItem, TimedNotificationItem } from 'react-cosmos-core';
2
2
  type UseCosmosNotificationReturn = {
3
- pushStickyNotification(notification: NotificationItem): void;
4
- removeStickyNotification(notificationId: string): void;
5
- pushTimedNotification(notification: TimedNotificationItem): void;
3
+ pushSticky(notification: NotificationItem): void;
4
+ removeSticky(notificationId: string): void;
5
+ pushTimed(notification: TimedNotificationItem): void;
6
6
  };
7
7
  export declare function useCosmosNotification(): UseCosmosNotificationReturn;
8
8
  export {};
@@ -1,4 +1,4 @@
1
- import { useContext } from 'react';
1
+ import { useContext, useMemo } from 'react';
2
2
  import { RendererContext } from '../../rendererConnect/RendererContext.js';
3
3
  export function useCosmosNotification() {
4
4
  const rendererContext = useContext(RendererContext);
@@ -7,39 +7,37 @@ export function useCosmosNotification() {
7
7
  throw new Error('useCosmosNotification can only be used inside a Cosmos fixture');
8
8
  }
9
9
  const { fixtureId } = selectedFixture;
10
- const pushStickyNotification = (notification) => {
11
- rendererConnect.postMessage({
12
- type: 'pushStickyNotification',
13
- payload: {
14
- rendererId,
15
- fixtureId,
16
- notification,
17
- },
18
- });
19
- };
20
- const removeStickyNotification = (notificationId) => {
21
- rendererConnect.postMessage({
22
- type: 'removeStickyNotification',
23
- payload: {
24
- rendererId,
25
- fixtureId,
26
- notificationId,
27
- },
28
- });
29
- };
30
- const pushTimedNotification = (notification) => {
31
- rendererConnect.postMessage({
32
- type: 'pushTimedNotification',
33
- payload: {
34
- rendererId,
35
- fixtureId,
36
- notification,
37
- },
38
- });
39
- };
40
- return {
41
- pushStickyNotification,
42
- removeStickyNotification,
43
- pushTimedNotification,
44
- };
10
+ const { postMessage } = rendererConnect;
11
+ return useMemo(() => ({
12
+ pushSticky: (notification) => {
13
+ postMessage({
14
+ type: 'pushStickyNotification',
15
+ payload: {
16
+ rendererId,
17
+ fixtureId,
18
+ notification,
19
+ },
20
+ });
21
+ },
22
+ removeSticky: (notificationId) => {
23
+ postMessage({
24
+ type: 'removeStickyNotification',
25
+ payload: {
26
+ rendererId,
27
+ fixtureId,
28
+ notificationId,
29
+ },
30
+ });
31
+ },
32
+ pushTimed: (notification) => {
33
+ postMessage({
34
+ type: 'pushTimedNotification',
35
+ payload: {
36
+ rendererId,
37
+ fixtureId,
38
+ notification,
39
+ },
40
+ });
41
+ },
42
+ }), [fixtureId, postMessage, rendererId]);
45
43
  }
@@ -6,6 +6,7 @@ type Props = {
6
6
  globalDecorators?: ReactDecorator[];
7
7
  renderMessage?: (msg: string) => React.ReactNode;
8
8
  selectedFixture: SelectedFixture | null;
9
+ fixtureProps?: Record<string, unknown>;
9
10
  };
10
- export declare function ServerFixtureLoader({ moduleWrappers, globalDecorators, renderMessage, selectedFixture, }: Props): React.JSX.Element;
11
+ export declare function ServerFixtureLoader({ moduleWrappers, globalDecorators, renderMessage, selectedFixture, fixtureProps }: Props): React.JSX.Element;
11
12
  export {};
@@ -5,10 +5,10 @@ import { FixtureModule } from '../fixtureModule/FixtureModule.js';
5
5
  import { AsyncModuleLoader } from '../moduleLoaders/AsyncModuleLoader.js';
6
6
  import { FixtureLoaderConnect } from './FixtureLoaderConnect.js';
7
7
  import { defaultRenderMessage } from './defaultRenderMessage.js';
8
- export function ServerFixtureLoader({ moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, selectedFixture, }) {
8
+ export function ServerFixtureLoader({ moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, selectedFixture, fixtureProps }) {
9
9
  return (React.createElement(FixtureLoaderConnect, { moduleWrappers: moduleWrappers, selectedFixture: selectedFixture, renderMessage: renderMessage, renderFixture: selected => (
10
10
  // The suspense boundary allows the rendererReady response to be sent
11
11
  // before loading the fixture modules.
12
12
  React.createElement(Suspense, null,
13
- React.createElement(AsyncModuleLoader, { moduleWrappers: moduleWrappers, fixturePath: selected.fixtureId.path, renderModules: modules => (React.createElement(FixtureModule, { ...modules, ...selected, globalDecorators: globalDecorators, lazy: moduleWrappers.lazy, renderMessage: renderMessage })) }))) }));
13
+ React.createElement(AsyncModuleLoader, { moduleWrappers: moduleWrappers, fixturePath: selected.fixtureId.path, renderModules: modules => (React.createElement(FixtureModule, { ...modules, ...selected, globalDecorators: globalDecorators, fixtureProps: fixtureProps, lazy: moduleWrappers.lazy, renderMessage: renderMessage })) }))) }));
14
14
  }
@@ -3,8 +3,9 @@ import { ReactDecorator, ReactDecoratorModule, ReactFixture } from 'react-cosmos
3
3
  type Props = {
4
4
  fixture: ReactFixture;
5
5
  fixtureOptions: {};
6
+ fixtureProps?: Record<string, unknown>;
6
7
  userDecoratorModules: ReactDecoratorModule[];
7
8
  globalDecorators?: ReactDecorator[];
8
9
  };
9
- export declare function DecoratedFixture({ fixture, fixtureOptions, userDecoratorModules, globalDecorators, }: Props): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
10
+ export declare function DecoratedFixture({ fixture, fixtureOptions, fixtureProps, userDecoratorModules, globalDecorators, }: Props): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
10
11
  export {};
@@ -2,12 +2,18 @@ import React, { useMemo } from 'react';
2
2
  import { FixtureCapture } from '../fixture/FixtureCapture/FixtureCapture.js';
3
3
  import { createFixtureNode } from './createFixtureNode.js';
4
4
  import { decorateFixture } from './decorateFixture.js';
5
- export function DecoratedFixture({ fixture, fixtureOptions, userDecoratorModules, globalDecorators = [], }) {
5
+ export function DecoratedFixture({ fixture, fixtureOptions, fixtureProps, userDecoratorModules, globalDecorators = [], }) {
6
6
  return useMemo(() => {
7
7
  const decorators = [
8
8
  ...globalDecorators,
9
9
  ...userDecoratorModules.map(m => m.default).flat(),
10
10
  ];
11
- return decorateFixture(React.createElement(FixtureCapture, { decoratorId: "root" }, createFixtureNode(fixture)), fixtureOptions, decorators);
12
- }, [fixture, fixtureOptions, globalDecorators, userDecoratorModules]);
11
+ return decorateFixture(React.createElement(FixtureCapture, { decoratorId: "root" }, createFixtureNode(fixture, fixtureProps)), fixtureOptions, decorators);
12
+ }, [
13
+ fixture,
14
+ fixtureOptions,
15
+ fixtureProps,
16
+ globalDecorators,
17
+ userDecoratorModules,
18
+ ]);
13
19
  }
@@ -6,9 +6,10 @@ type Props = {
6
6
  globalDecorators?: ReactDecorator[];
7
7
  fixtureId: FixtureId;
8
8
  initialFixtureState?: FixtureState;
9
+ fixtureProps?: Record<string, unknown>;
9
10
  renderKey: number;
10
11
  lazy: boolean;
11
12
  renderMessage: (msg: string) => React.ReactNode;
12
13
  };
13
- export declare function FixtureModule({ fixtureModule, decoratorModules, globalDecorators, fixtureId, initialFixtureState, renderKey, lazy, renderMessage, }: Props): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
14
+ export declare function FixtureModule({ fixtureModule, decoratorModules, globalDecorators, fixtureId, initialFixtureState, fixtureProps, renderKey, lazy, renderMessage, }: Props): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
14
15
  export {};
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { getFixtureFromExport, getFixtureItemFromExport, pickSerializableValues, stringifyFixtureId, } from 'react-cosmos-core';
3
3
  import { DecoratedFixture } from './DecoratedFixture.js';
4
4
  import { FixtureProvider } from './FixtureProvider.js';
5
- export function FixtureModule({ fixtureModule, decoratorModules, globalDecorators, fixtureId, initialFixtureState, renderKey, lazy, renderMessage, }) {
5
+ export function FixtureModule({ fixtureModule, decoratorModules, globalDecorators, fixtureId, initialFixtureState, fixtureProps, renderKey, lazy, renderMessage, }) {
6
6
  const fixtureItem = React.useMemo(() => getFixtureItemFromExport(fixtureModule.default), [fixtureModule.default]);
7
7
  const fixtureKey = React.useMemo(() => `${stringifyFixtureId(fixtureId)}-${renderKey}`, [fixtureId, renderKey]);
8
8
  const fixture = getFixtureFromExport(fixtureModule.default, fixtureId.name);
@@ -12,5 +12,5 @@ export function FixtureModule({ fixtureModule, decoratorModules, globalDecorator
12
12
  return renderMessage(`Invalid fixture name: ${fixtureId.name}`);
13
13
  }
14
14
  return (React.createElement(FixtureProvider, { key: fixtureKey, fixtureId: fixtureId, initialFixtureState: initialFixtureState, fixtureItem: fixtureItem, fixtureOptions: serializableOptions, lazy: lazy },
15
- React.createElement(DecoratedFixture, { fixture: fixture, fixtureOptions: options, userDecoratorModules: decoratorModules, globalDecorators: globalDecorators })));
15
+ React.createElement(DecoratedFixture, { fixture: fixture, fixtureOptions: options, fixtureProps: fixtureProps, userDecoratorModules: decoratorModules, globalDecorators: globalDecorators })));
16
16
  }
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import { ReactFixture } from 'react-cosmos-core';
3
- export declare function createFixtureNode(fixture: ReactFixture): React.ReactNode;
3
+ export declare function createFixtureNode(fixture: ReactFixture, fixtureProps?: Record<string, unknown>): React.ReactNode;
@@ -1,12 +1,12 @@
1
1
  import React, { isValidElement } from 'react';
2
- export function createFixtureNode(fixture) {
2
+ export function createFixtureNode(fixture, fixtureProps) {
3
3
  // Warning: In a React Server Components setup this function is called on the
4
4
  // server. When a fixture module uses the 'use client' directive, the fixture
5
5
  // export will be a Promise wrapper (imbued with magical properties methinks).
6
6
  // This results in the following limitation: In a React Server Components
7
7
  // setup, Client fixtures have to export a single function component. They
8
8
  // can't be multi fixtures and they can't export React elements directly.
9
- return isNodeFixture(fixture) ? (fixture) : (React.createElement(FixtureElement, { Component: fixture }));
9
+ return isNodeFixture(fixture) ? (fixture) : (React.createElement(FixtureElement, { Component: fixture, fixtureProps: fixtureProps }));
10
10
  }
11
11
  function isNodeFixture(fixture) {
12
12
  // If you're curious what the exact type of ReactNode is:
@@ -21,7 +21,7 @@ function isNodeFixture(fixture) {
21
21
  // https://github.com/facebook/react/blob/1b0132c05acabae5aebd32c2cadddfb16bda70bc/packages/react-is/src/ReactIs.js#L108-L114
22
22
  isValidElement(fixture));
23
23
  }
24
- function FixtureElement({ Component }) {
25
- return React.createElement(Component, null);
24
+ function FixtureElement({ Component, fixtureProps, }) {
25
+ return React.createElement(Component, { ...fixtureProps });
26
26
  }
27
27
  FixtureElement.cosmosCapture = false;
@@ -1 +1 @@
1
- {"root":["../src/client.ts","../src/index.ts","../src/wrapSetTimeoutAct.ts","../src/fixture/ClassStateMock.tsx","../src/fixture/FixtureContext.ts","../src/fixture/Viewport.tsx","../src/fixture/useFixtureState.ts","../src/fixture/FixtureCapture/FixtureCapture.tsx","../src/fixture/FixtureCapture/classState/index.ts","../src/fixture/FixtureCapture/classState/shared.ts","../src/fixture/FixtureCapture/classState/useFixtureClassState.ts","../src/fixture/FixtureCapture/classState/useReadClassState.ts","../src/fixture/FixtureCapture/classState/decorateFixtureRefs/index.ts","../src/fixture/FixtureCapture/classState/decorateFixtureRefs/isRefSupported.ts","../src/fixture/FixtureCapture/props/index.ts","../src/fixture/FixtureCapture/props/useFixtureProps.ts","../src/fixture/FixtureCapture/shared/findRelevantElementPaths.ts","../src/fixture/FixtureCapture/shared/nodeTree/findElementPaths.ts","../src/fixture/FixtureCapture/shared/nodeTree/getElementAtPath.ts","../src/fixture/FixtureCapture/shared/nodeTree/index.ts","../src/fixture/FixtureCapture/shared/nodeTree/setElementAtPath.ts","../src/fixture/FixtureCapture/shared/nodeTree/shared.ts","../src/fixture/useCosmosNotification/useCosmosNotification.ts","../src/fixture/useFixtureInput/useCurrentInputValue.ts","../src/fixture/useFixtureInput/useFixtureInput.ts","../src/fixture/useFixtureInput/useInputFixtureState.ts","../src/fixture/useFixtureInput/useSetInputValue.ts","../src/fixture/useFixtureInput/useValue.ts","../src/fixture/useFixtureSelect/shared.ts","../src/fixture/useFixtureSelect/useCurrentSelectValue.ts","../src/fixture/useFixtureSelect/useFixtureSelect.ts","../src/fixture/useFixtureSelect/useSelect.ts","../src/fixture/useFixtureSelect/useSelectFixtureState.ts","../src/fixture/useFixtureSelect/useSetSelectValue.ts","../src/fixtureLoaders/ClientFixtureLoader.tsx","../src/fixtureLoaders/FixtureLoaderConnect.tsx","../src/fixtureLoaders/RendererSync.tsx","../src/fixtureLoaders/SelectedFixture.ts","../src/fixtureLoaders/ServerFixtureLoader.tsx","../src/fixtureLoaders/defaultRenderMessage.tsx","../src/fixtureModule/DecoratedFixture.tsx","../src/fixtureModule/FixtureModule.tsx","../src/fixtureModule/FixtureProvider.tsx","../src/fixtureModule/createFixtureNode.tsx","../src/fixtureModule/decorateFixture.tsx","../src/moduleLoaders/AsyncModuleLoader.tsx","../src/moduleLoaders/LazyModuleLoader.tsx","../src/moduleLoaders/StaticModuleLoader.tsx","../src/moduleLoaders/importLazyFixtureModules.ts","../src/rendererConnect/RendererContext.ts","../src/rendererConnect/RendererProvider.tsx","../src/rendererConnect/StatefulRendererProvider.tsx","../src/rendererConnect/createNoopRendererConnect.ts","../src/rendererConnect/createPostMessageConnect.ts","../src/rendererConnect/createWebSocketsConnect.ts","../src/rendererConnect/globals.d.ts"],"version":"5.8.3"}
1
+ {"root":["../src/client.ts","../src/index.ts","../src/wrapsettimeoutact.ts","../src/fixture/classstatemock.tsx","../src/fixture/fixturecontext.ts","../src/fixture/viewport.tsx","../src/fixture/usefixturestate.ts","../src/fixture/fixturecapture/fixturecapture.tsx","../src/fixture/fixturecapture/classstate/index.ts","../src/fixture/fixturecapture/classstate/shared.ts","../src/fixture/fixturecapture/classstate/usefixtureclassstate.ts","../src/fixture/fixturecapture/classstate/usereadclassstate.ts","../src/fixture/fixturecapture/classstate/decoratefixturerefs/index.ts","../src/fixture/fixturecapture/classstate/decoratefixturerefs/isrefsupported.ts","../src/fixture/fixturecapture/props/index.ts","../src/fixture/fixturecapture/props/usefixtureprops.ts","../src/fixture/fixturecapture/shared/findrelevantelementpaths.ts","../src/fixture/fixturecapture/shared/nodetree/findelementpaths.ts","../src/fixture/fixturecapture/shared/nodetree/getelementatpath.ts","../src/fixture/fixturecapture/shared/nodetree/index.ts","../src/fixture/fixturecapture/shared/nodetree/setelementatpath.ts","../src/fixture/fixturecapture/shared/nodetree/shared.ts","../src/fixture/usecosmosnotification/usecosmosnotification.ts","../src/fixture/usefixtureinput/usecurrentinputvalue.ts","../src/fixture/usefixtureinput/usefixtureinput.ts","../src/fixture/usefixtureinput/useinputfixturestate.ts","../src/fixture/usefixtureinput/usesetinputvalue.ts","../src/fixture/usefixtureinput/usevalue.ts","../src/fixture/usefixtureselect/shared.ts","../src/fixture/usefixtureselect/usecurrentselectvalue.ts","../src/fixture/usefixtureselect/usefixtureselect.ts","../src/fixture/usefixtureselect/useselect.ts","../src/fixture/usefixtureselect/useselectfixturestate.ts","../src/fixture/usefixtureselect/usesetselectvalue.ts","../src/fixtureloaders/clientfixtureloader.tsx","../src/fixtureloaders/fixtureloaderconnect.tsx","../src/fixtureloaders/renderersync.tsx","../src/fixtureloaders/selectedfixture.ts","../src/fixtureloaders/serverfixtureloader.tsx","../src/fixtureloaders/defaultrendermessage.tsx","../src/fixturemodule/decoratedfixture.tsx","../src/fixturemodule/fixturemodule.tsx","../src/fixturemodule/fixtureprovider.tsx","../src/fixturemodule/createfixturenode.tsx","../src/fixturemodule/decoratefixture.tsx","../src/moduleloaders/asyncmoduleloader.tsx","../src/moduleloaders/lazymoduleloader.tsx","../src/moduleloaders/staticmoduleloader.tsx","../src/moduleloaders/importlazyfixturemodules.ts","../src/rendererconnect/renderercontext.ts","../src/rendererconnect/rendererprovider.tsx","../src/rendererconnect/statefulrendererprovider.tsx","../src/rendererconnect/createnooprendererconnect.ts","../src/rendererconnect/createpostmessageconnect.ts","../src/rendererconnect/createwebsocketsconnect.ts","../src/rendererconnect/globals.d.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos-renderer",
3
- "version": "7.0.1-canary.e020233.0+e020233",
3
+ "version": "7.1.0",
4
4
  "description": "React Cosmos Renderer",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-renderer",
6
6
  "license": "MIT",
@@ -11,8 +11,8 @@
11
11
  "./client": "./client.js"
12
12
  },
13
13
  "dependencies": {
14
- "lodash-es": "4.17.21",
15
- "react-cosmos-core": "7.0.1-canary.e020233.0+e020233"
14
+ "lodash-es": "4.17.22",
15
+ "react-cosmos-core": "^7.1.0"
16
16
  },
17
- "gitHead": "e020233e2219ca8639138933bd0898c4bd980902"
17
+ "gitHead": "f3b201374cdb9ea8937e9e5584829c22f29122eb"
18
18
  }