Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-cosmos-core

Package Overview
Dependencies
Maintainers
1
Versions
253
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cosmos-core - npm Package Compare versions

Comparing version 6.0.0-canary.a552ff02.9 to 6.0.0-canary.a687430.0

dist/fixtureState/classStateTypes.d.ts

21

dist/fixtureState/classState.d.ts

@@ -1,6 +0,7 @@

import { FixtureDecoratorId, FixtureElementId, FixtureState, FixtureStateClassState, FixtureStateValues } from './types.js';
export declare function getFixtureStateClassState(fixtureState: FixtureState, decoratorId: FixtureDecoratorId): FixtureStateClassState[];
export declare function findFixtureStateClassState(fixtureState: FixtureState, elementId: FixtureElementId): void | FixtureStateClassState;
type CreateFixtureStateClassStateArgs = {
fixtureState: FixtureState;
import { ClassStateFixtureState, ClassStateFixtureStateItem } from './classStateTypes.js';
import { FixtureDecoratorId, FixtureElementId, FixtureStateValues } from './types.js';
export declare function filterClassStateFixtureState(classStateFs: ClassStateFixtureState | undefined, decoratorId: FixtureDecoratorId): ClassStateFixtureState;
export declare function findClassStateFixtureStateItem(classStateFs: ClassStateFixtureState | undefined, elementId: FixtureElementId): void | ClassStateFixtureStateItem;
type CreateClassStateFixtureStateArgs = {
classStateFs: ClassStateFixtureState | undefined;
elementId: FixtureElementId;

@@ -10,3 +11,3 @@ values: FixtureStateValues;

};
export declare function createFixtureStateClassState({ fixtureState, elementId, values, componentName, }: CreateFixtureStateClassStateArgs): {
export declare function createClassStateFixtureStateItem({ classStateFs, elementId, values, componentName, }: CreateClassStateFixtureStateArgs): {
elementId: FixtureElementId;

@@ -16,9 +17,9 @@ values: FixtureStateValues;

}[];
type UpdateFixtureStateClassStateArgs = {
fixtureState: FixtureState;
type UpdateClassStateFixtureStateArgs = {
classStateFs: ClassStateFixtureState | undefined;
elementId: FixtureElementId;
values: FixtureStateValues;
};
export declare function updateFixtureStateClassState({ fixtureState, elementId, values, }: UpdateFixtureStateClassStateArgs): FixtureStateClassState[];
export declare function removeFixtureStateClassState(fixtureState: FixtureState, elementId: FixtureElementId): FixtureStateClassState[];
export declare function updateClassStateFixtureStateItem({ classStateFs, elementId, values, }: UpdateClassStateFixtureStateArgs): ClassStateFixtureStateItem[];
export declare function removeClassStateFixtureStateItem(classStateFs: ClassStateFixtureState | undefined, elementId: FixtureElementId): ClassStateFixtureStateItem[];
export {};
import { find, isEqual } from 'lodash-es';
import { removeItemMatch, replaceOrAddItem, updateItem, } from '../utils/array.js';
export function getFixtureStateClassState(fixtureState, decoratorId) {
const { classState } = fixtureState;
return classState
? classState.filter(s => s.elementId.decoratorId === decoratorId)
export function filterClassStateFixtureState(classStateFs, decoratorId) {
return classStateFs
? classStateFs.filter(s => s.elementId.decoratorId === decoratorId)
: [];
}
export function findFixtureStateClassState(fixtureState, elementId) {
const { classState } = fixtureState;
return classState && find(classState, s => isEqual(s.elementId, elementId));
export function findClassStateFixtureStateItem(classStateFs, elementId) {
return (classStateFs && find(classStateFs, s => isEqual(s.elementId, elementId)));
}
export function createFixtureStateClassState({ fixtureState, elementId, values, componentName, }) {
const { classState = [] } = fixtureState;
return replaceOrAddItem(classState, createClassStateMatcher(elementId), {
elementId,
values,
componentName,
});
export function createClassStateFixtureStateItem({ classStateFs, elementId, values, componentName, }) {
return replaceOrAddItem(classStateFs ?? [], createClassStateMatcher(elementId), { elementId, values, componentName });
}
export function updateFixtureStateClassState({ fixtureState, elementId, values, }) {
const classStateItem = expectFixtureStateClassState(fixtureState, elementId);
return updateItem(fixtureState.classState, classStateItem, {
values,
});
export function updateClassStateFixtureStateItem({ classStateFs, elementId, values, }) {
const item = expectClassStateItem(classStateFs, elementId);
return updateItem(classStateFs, item, { values });
}
export function removeFixtureStateClassState(fixtureState, elementId) {
return removeItemMatch(fixtureState.classState || [], createClassStateMatcher(elementId));
export function removeClassStateFixtureStateItem(classStateFs, elementId) {
return removeItemMatch(classStateFs ?? [], createClassStateMatcher(elementId));
}

@@ -33,9 +24,9 @@ function createClassStateMatcher(elementId) {

}
function expectFixtureStateClassState(fixtureState, elementId) {
const classStateItem = findFixtureStateClassState(fixtureState, elementId);
if (!classStateItem) {
function expectClassStateItem(classStateFs, elementId) {
const item = findClassStateFixtureStateItem(classStateFs, elementId);
if (!item) {
const elId = JSON.stringify(elementId);
throw new Error(`Fixture state class state missing for element "${elId}"`);
}
return classStateItem;
return item;
}

@@ -1,7 +0,8 @@

import { FixtureDecoratorId, FixtureElementId, FixtureRenderKey, FixtureState, FixtureStateProps, FixtureStateValues } from './types.js';
export declare const DEFAULT_RENDER_KEY: FixtureRenderKey;
export declare function getFixtureStateProps(fixtureState: FixtureState, decoratorId: FixtureDecoratorId): FixtureStateProps[];
export declare function findFixtureStateProps(fixtureState: FixtureState, elementId: FixtureElementId): void | FixtureStateProps;
type CreateFixtureStatePropsArgs = {
fixtureState: FixtureState;
import { PropsFixtureState, PropsFixtureStateItem, PropsFixtureStateRenderKey } from './propsTypes.js';
import { FixtureDecoratorId, FixtureElementId, FixtureStateValues } from './types.js';
export declare const DEFAULT_RENDER_KEY: PropsFixtureStateRenderKey;
export declare function filterPropsFixtureState(propsFs: PropsFixtureState | undefined, decoratorId: FixtureDecoratorId): PropsFixtureState;
export declare function findPropsFixtureStateItem(propsFs: PropsFixtureState | undefined, elementId: FixtureElementId): void | PropsFixtureStateItem;
type CreatePropsFixtureStateArgs = {
propsFs: PropsFixtureState | undefined;
elementId: FixtureElementId;

@@ -11,3 +12,3 @@ values: FixtureStateValues;

};
export declare function createFixtureStateProps({ fixtureState, elementId, values, componentName, }: CreateFixtureStatePropsArgs): {
export declare function createPropsFixtureStateItem({ propsFs, elementId, values, componentName, }: CreatePropsFixtureStateArgs): {
elementId: FixtureElementId;

@@ -18,15 +19,15 @@ values: FixtureStateValues;

}[];
type ResetFixtureStatePropsArgs = {
fixtureState: FixtureState;
type ResetPropsFixtureStateItemArgs = {
propsFs: PropsFixtureState | undefined;
elementId: FixtureElementId;
values: FixtureStateValues;
};
export declare function resetFixtureStateProps({ fixtureState, elementId, values, }: ResetFixtureStatePropsArgs): FixtureStateProps[];
type UpdateFixtureStatePropsArgs = {
fixtureState: FixtureState;
export declare function resetPropsFixtureStateItem({ propsFs, elementId, values, }: ResetPropsFixtureStateItemArgs): PropsFixtureStateItem[];
type UpdatePropsFixtureStateItemArgs = {
propsFs: PropsFixtureState | undefined;
elementId: FixtureElementId;
values: FixtureStateValues;
};
export declare function updateFixtureStateProps({ fixtureState, elementId, values, }: UpdateFixtureStatePropsArgs): FixtureStateProps[];
export declare function removeFixtureStateProps(fixtureState: FixtureState, elementId: FixtureElementId): FixtureStateProps[];
export declare function updatePropsFixtureStateItem({ propsFs, elementId, values, }: UpdatePropsFixtureStateItemArgs): PropsFixtureStateItem[];
export declare function removePropsFixtureStateItem(propsFs: PropsFixtureState | undefined, elementId: FixtureElementId): PropsFixtureStateItem[];
export {};
import { find, isEqual } from 'lodash-es';
import { removeItemMatch, replaceOrAddItem, updateItem, } from '../utils/array.js';
export const DEFAULT_RENDER_KEY = 0;
export function getFixtureStateProps(fixtureState, decoratorId) {
const { props } = fixtureState;
return props
? props.filter(p => p.elementId.decoratorId === decoratorId)
export function filterPropsFixtureState(propsFs, decoratorId) {
return propsFs
? propsFs.filter(p => p.elementId.decoratorId === decoratorId)
: [];
}
export function findFixtureStateProps(fixtureState, elementId) {
const { props } = fixtureState;
return props && find(props, p => isEqual(p.elementId, elementId));
export function findPropsFixtureStateItem(propsFs, elementId) {
return propsFs && find(propsFs, p => isEqual(p.elementId, elementId));
}
export function createFixtureStateProps({ fixtureState, elementId, values, componentName, }) {
const { props = [] } = fixtureState;
return replaceOrAddItem(props, createPropsMatcher(elementId), {
export function createPropsFixtureStateItem({ propsFs, elementId, values, componentName, }) {
return replaceOrAddItem(propsFs ?? [], createPropsMatcher(elementId), {
elementId,

@@ -23,17 +20,15 @@ values,

}
export function resetFixtureStateProps({ fixtureState, elementId, values, }) {
const propsItem = expectFixtureStateProps(fixtureState, elementId);
return updateItem(fixtureState.props, propsItem, {
export function resetPropsFixtureStateItem({ propsFs, elementId, values, }) {
const item = expectPropsItem(propsFs, elementId);
return updateItem(propsFs, item, {
values,
renderKey: propsItem.renderKey + 1,
renderKey: item.renderKey + 1,
});
}
export function updateFixtureStateProps({ fixtureState, elementId, values, }) {
const propsItem = expectFixtureStateProps(fixtureState, elementId);
return updateItem(fixtureState.props, propsItem, {
values,
});
export function updatePropsFixtureStateItem({ propsFs, elementId, values, }) {
const item = expectPropsItem(propsFs, elementId);
return updateItem(propsFs, item, { values });
}
export function removeFixtureStateProps(fixtureState, elementId) {
return removeItemMatch(fixtureState.props || [], createPropsMatcher(elementId));
export function removePropsFixtureStateItem(propsFs, elementId) {
return removeItemMatch(propsFs ?? [], createPropsMatcher(elementId));
}

@@ -43,9 +38,9 @@ function createPropsMatcher(elementId) {

}
function expectFixtureStateProps(fixtureState, elementId) {
const propsItem = findFixtureStateProps(fixtureState, elementId);
if (!propsItem) {
function expectPropsItem(propsFs, elementId) {
const item = findPropsFixtureStateItem(propsFs, elementId);
if (!item) {
const elId = JSON.stringify(elementId);
throw new Error(`Fixture state props missing for element "${elId}"`);
}
return propsItem;
return item;
}

@@ -1,2 +0,2 @@

import { StateUpdater } from '../utils/types.js';
import { StateUpdater } from '../utils/state.js';
export type FixtureDecoratorId = string;

@@ -29,32 +29,3 @@ export type FixtureElementId = {

export type FixtureStateValues = Record<string, FixtureStateValue>;
export type FixtureRenderKey = number;
export type FixtureStateProps = {
elementId: FixtureElementId;
values: FixtureStateValues;
renderKey: FixtureRenderKey;
componentName: string;
};
export type FixtureStateClassState = {
elementId: FixtureElementId;
values: FixtureStateValues;
componentName: string;
};
export type FixtureStateStandardControl = {
type: 'standard';
defaultValue: FixtureStateValue;
currentValue: FixtureStateValue;
};
export type FixtureStateSelectControl = {
type: 'select';
options: string[];
defaultValue: string;
currentValue: string;
};
export type FixtureStateControl = FixtureStateStandardControl | FixtureStateSelectControl;
export type FixtureStateControls = Record<string, FixtureStateControl>;
export type FixtureState = {
props?: FixtureStateProps[];
classState?: FixtureStateClassState[];
controls?: FixtureStateControls;
} & Record<string, unknown>;
export type FixtureState = Record<string, unknown>;
export type SetFixtureState = (update: StateUpdater<FixtureState>) => unknown;

@@ -21,5 +21,9 @@ export function collapseNamedIndexes(treeNode) {

const firstGrandchildNode = grandchildren[firstGrandchildName];
const isUnnamed = firstGrandchildName === 'fixture';
if (firstGrandchildNode.data.type !== 'fileDir' &&
noCaseEqual(childName, firstGrandchildName))
return { ...newChildren, [firstGrandchildName]: firstGrandchildNode };
(noCaseEqual(childName, firstGrandchildName) || isUnnamed))
return {
...newChildren,
[isUnnamed ? childName : firstGrandchildName]: firstGrandchildNode,
};
return next();

@@ -26,0 +30,0 @@ }, {}),

@@ -1,3 +0,3 @@

import { FixtureList } from '../../fixture/types.js';
import { FixtureList } from '../../userModules/fixtureTypes.js';
import { FixtureTreeNode } from '../types.js';
export declare function createRawFixtureTree(fixtures: FixtureList): FixtureTreeNode;

@@ -16,3 +16,3 @@ import { get, set } from 'lodash-es';

type: 'fixture',
fixtureId: { path: fixturePath },
path: fixturePath,
},

@@ -25,3 +25,4 @@ });

type: 'multiFixture',
fixtureIds: createFixtureIds(fixturePath, fixtureItem.fixtureNames),
path: fixturePath,
names: fixtureItem.fixtureNames,
},

@@ -42,10 +43,4 @@ });

function removeFixtureNameExtension(fixtureName) {
return fixtureName.replace(/\.(j|t)sx?$/, '');
return fixtureName.replace(/\.(js|jsx|ts|tsx|md|mdx)$/, '');
}
function createFixtureIds(fixturePath, fixtureNames) {
return fixtureNames.reduce((fixtureIds, fixtureName) => ({
...fixtureIds,
[fixtureName]: { path: fixturePath, name: fixtureName },
}), {});
}
function injectNode(rootNode, parents, childName, childNode) {

@@ -52,0 +47,0 @@ if (parents.length === 0)

@@ -1,2 +0,2 @@

import { FixtureList } from '../../fixture/types.js';
import { FixtureList } from '../../userModules/fixtureTypes.js';
import { FixtureTreeNode } from '../types.js';

@@ -3,0 +3,0 @@ export declare function createFixtureTree({ fixtures, fixturesDir, fixtureFileSuffix, }: {

@@ -1,2 +0,2 @@

import { FixtureId } from '../fixture/types.js';
import { FixtureId } from '../userModules/fixtureTypes.js';
import { FixtureTreeNode } from './types.js';

@@ -3,0 +3,0 @@ export type FlatFixtureTreeItem = {

@@ -13,5 +13,5 @@ export function flattenFixtureTree(treeNode, parents = []) {

if (childData.type === 'multiFixture')
Object.keys(childData.fixtureIds).forEach(fixtureName => flatFixtureTree.push({
childData.names.forEach(fixtureName => flatFixtureTree.push({
fileName: childName,
fixtureId: childData.fixtureIds[fixtureName],
fixtureId: { path: childData.path, name: fixtureName },
parents,

@@ -23,3 +23,3 @@ name: fixtureName,

fileName: childName,
fixtureId: childData.fixtureId,
fixtureId: { path: childData.path },
parents,

@@ -26,0 +26,0 @@ name: null,

@@ -1,2 +0,1 @@

import { FixtureId } from '../fixture/types.js';
import { TreeNode } from '../utils/tree.js';

@@ -7,6 +6,7 @@ export type FixtureTreeNode = TreeNode<{

type: 'fixture';
fixtureId: FixtureId;
path: string;
} | {
type: 'multiFixture';
fixtureIds: Record<string, FixtureId>;
path: string;
names: string[];
}>;

@@ -1,34 +0,43 @@

export * from './fixture/FixtureContext.js';
export * from './fixture/types.js';
export * from './fixture/useSelect/index.js';
export * from './fixture/useValue/index.js';
export * from './fixture/Viewport.js';
export * from './fixtureState/classState.js';
export * from './fixtureState/classStateTypes.js';
export * from './fixtureState/controlsTypes.js';
export * from './fixtureState/createValues.js';
export * from './fixtureState/extendWithValues.js';
export * from './fixtureState/fixtureState.js';
export * from './fixtureState/props.js';
export * from './fixtureState/propsTypes.js';
export * from './fixtureState/types.js';
export * from './fixtureState/viewport.js';
export * from './fixtureTree/createFixtureTree/index.js';
export * from './fixtureTree/flattenFixtureTree.js';
export * from './fixtureTree/types.js';
export * from './playground/playgroundUrl.js';
export * from './renderer/FixtureLoader/FixtureLoader.js';
export * from './renderer/FixtureLoader/getDecoratedFixtureElement/index.js';
export * from './renderer/FixtureLoader/postMessage.js';
export * from './renderer/FixtureLoader/webSockets.js';
export * from './renderer/getFixtureList.js';
export * from './renderer/getSortedDecoratorsForFixturePath.js';
export * from './renderer/reactTypes.js';
export * from './renderer/registerPlaygroundShortcuts.js';
export * from './message/serverMessage.js';
export * from './message/socketMessage.js';
export * from './playground/playgroundParams.js';
export * from './playground/playgroundQueryString.js';
export * from './playground/registerPlaygroundShortcuts.js';
export * from './plugin/cosmosPluginConfig.js';
export * from './renderer/rendererConfig.js';
export * from './renderer/types.js';
export * from './server/cosmosPluginConfig.js';
export * from './server/serverMessage.js';
export * from './server/socketMessage.js';
export * from './renderer/rendererConnect.js';
export * from './renderer/rendererQueryString.js';
export * from './renderer/rendererUrl.js';
export * from './server/serverTypes.js';
export * from './userModules/fixtureTypes.js';
export * from './userModules/getFixtureFromExport.js';
export * from './userModules/getFixtureList.js';
export * from './userModules/getSortedDecoratorsForFixturePath.js';
export * from './userModules/stringifyFixtureId.js';
export * from './userModules/userModuleTypes.js';
export * from './utils/array.js';
export * from './utils/keys.js';
export * from './utils/queryString.js';
export * from './utils/react/ClassStateMock.js';
export * from './utils/react/DelayRender.js';
export * from './utils/react/areNodesEqual.js';
export * from './utils/react/getComponentName.js';
export * from './utils/react/isReactElement.js';
export * from './utils/state.js';
export * from './utils/string.js';
export * from './utils/tree.js';
export * from './utils/types.js';
export * from './utils/uuid.js';
export * from './utils/window.js';

@@ -1,34 +0,43 @@

export * from './fixture/FixtureContext.js';
export * from './fixture/types.js';
export * from './fixture/useSelect/index.js';
export * from './fixture/useValue/index.js';
export * from './fixture/Viewport.js';
export * from './fixtureState/classState.js';
export * from './fixtureState/classStateTypes.js';
export * from './fixtureState/controlsTypes.js';
export * from './fixtureState/createValues.js';
export * from './fixtureState/extendWithValues.js';
export * from './fixtureState/fixtureState.js';
export * from './fixtureState/props.js';
export * from './fixtureState/propsTypes.js';
export * from './fixtureState/types.js';
export * from './fixtureState/viewport.js';
export * from './fixtureTree/createFixtureTree/index.js';
export * from './fixtureTree/flattenFixtureTree.js';
export * from './fixtureTree/types.js';
export * from './playground/playgroundUrl.js';
export * from './renderer/FixtureLoader/FixtureLoader.js';
export * from './renderer/FixtureLoader/getDecoratedFixtureElement/index.js';
export * from './renderer/FixtureLoader/postMessage.js';
export * from './renderer/FixtureLoader/webSockets.js';
export * from './renderer/getFixtureList.js';
export * from './renderer/getSortedDecoratorsForFixturePath.js';
export * from './renderer/reactTypes.js';
export * from './renderer/registerPlaygroundShortcuts.js';
export * from './message/serverMessage.js';
export * from './message/socketMessage.js';
export * from './playground/playgroundParams.js';
export * from './playground/playgroundQueryString.js';
export * from './playground/registerPlaygroundShortcuts.js';
export * from './plugin/cosmosPluginConfig.js';
export * from './renderer/rendererConfig.js';
export * from './renderer/types.js';
export * from './server/cosmosPluginConfig.js';
export * from './server/serverMessage.js';
export * from './server/socketMessage.js';
export * from './renderer/rendererConnect.js';
export * from './renderer/rendererQueryString.js';
export * from './renderer/rendererUrl.js';
export * from './server/serverTypes.js';
export * from './userModules/fixtureTypes.js';
export * from './userModules/getFixtureFromExport.js';
export * from './userModules/getFixtureList.js';
export * from './userModules/getSortedDecoratorsForFixturePath.js';
export * from './userModules/stringifyFixtureId.js';
export * from './userModules/userModuleTypes.js';
export * from './utils/array.js';
export * from './utils/keys.js';
export * from './utils/queryString.js';
export * from './utils/react/ClassStateMock.js';
export * from './utils/react/DelayRender.js';
export * from './utils/react/areNodesEqual.js';
export * from './utils/react/getComponentName.js';
export * from './utils/react/isReactElement.js';
export * from './utils/state.js';
export * from './utils/string.js';
export * from './utils/tree.js';
export * from './utils/types.js';
export * from './utils/uuid.js';
export * from './utils/window.js';
export type RendererConfig = {
playgroundUrl: string;
rendererUrl?: null | string;
};
export declare function replaceKeys(str: string, map: {
[key: string]: string;
}): string;
export declare function removeLeadingSlash(fromPath: string): string;
export declare function removeLeadingDot(fromPath: string): string;
export function replaceKeys(str, map) {
return Object.keys(map).reduce((res, key) => res.replace(key, map[key]), str);
}
export function removeLeadingSlash(fromPath) {
return fromPath.replace(/^\/+/, '');
}
export function removeLeadingDot(fromPath) {
return fromPath.indexOf('.') === 0 ? fromPath.slice(1) : fromPath;
}
{
"name": "react-cosmos-core",
"version": "6.0.0-canary.a552ff02.9+5304dfbb",
"version": "6.0.0-canary.a687430.0+a687430",
"description": "React Cosmos Core",

@@ -8,9 +8,10 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-core",

"type": "module",
"sideEffects": false,
"main": "./dist/index.js",
"sideEffects": false,
"dependencies": {
"lodash-es": "^4.17.21",
"react-is": "^18.0.0"
"js-base64": "3.7.6",
"lodash-es": "4.17.21",
"react-is": "18.2.0"
},
"gitHead": "5304dfbb885b206f595a76f2fca0baab7cc20b78"
"gitHead": "a687430156d020fdecd1a6ec53b10ae43d9892c2"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc