react-cosmos-core
Advanced tools
Comparing version 6.0.0-canary.86644b2.0 to 6.0.0-canary.86b9647.0
@@ -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 @@ }, {}), |
@@ -41,3 +41,3 @@ import { get, set } from 'lodash-es'; | ||
function removeFixtureNameExtension(fixtureName) { | ||
return fixtureName.replace(/\.(j|t)sx?$/, ''); | ||
return fixtureName.replace(/\.(js|jsx|ts|tsx|md|mdx)$/, ''); | ||
} | ||
@@ -44,0 +44,0 @@ function injectNode(rootNode, parents, childName, childNode) { |
export * from './fixtureState/classState.js'; | ||
export * from './fixtureState/controls.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'; | ||
@@ -19,2 +23,4 @@ export * from './fixtureTree/flattenFixtureTree.js'; | ||
export * from './renderer/rendererQueryString.js'; | ||
export * from './renderer/rendererUrl.js'; | ||
export * from './server/serverTypes.js'; | ||
export * from './userModules/fixtureTypes.js'; | ||
@@ -34,6 +40,6 @@ export * from './userModules/getFixtureFromExport.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 * from './fixtureState/classState.js'; | ||
export * from './fixtureState/controls.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'; | ||
@@ -19,2 +23,4 @@ export * from './fixtureTree/flattenFixtureTree.js'; | ||
export * from './renderer/rendererQueryString.js'; | ||
export * from './renderer/rendererUrl.js'; | ||
export * from './server/serverTypes.js'; | ||
export * from './userModules/fixtureTypes.js'; | ||
@@ -34,6 +40,6 @@ export * from './userModules/getFixtureFromExport.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'; |
@@ -8,3 +8,4 @@ export function registerPlaygroundShortcuts(runCommand) { | ||
function handleWindowKeyDown(e) { | ||
if (isEditing()) { | ||
// Allow meta key shortcuts to work when focused on input fields | ||
if (isEditing() && !e.metaKey) { | ||
return; | ||
@@ -14,17 +15,20 @@ } | ||
const metaKey = e.metaKey || e.ctrlKey; | ||
if (keyChar === 'P' && metaKey) { | ||
if (keyChar === 'K' && metaKey) { | ||
run(e, 'searchFixtures'); | ||
} | ||
else if (keyChar === 'L' && metaKey && e.shiftKey) { | ||
else if (keyChar === 'L') { | ||
run(e, 'toggleFixtureList'); | ||
} | ||
else if (keyChar === 'K' && metaKey && e.shiftKey) { | ||
else if (keyChar === 'P') { | ||
run(e, 'toggleControlPanel'); | ||
} | ||
else if (keyChar === 'F' && metaKey && e.shiftKey) { | ||
else if (keyChar === 'F') { | ||
run(e, 'goFullScreen'); | ||
} | ||
else if (keyChar === 'E' && metaKey && e.shiftKey) { | ||
else if (keyChar === 'E') { | ||
run(e, 'editFixture'); | ||
} | ||
else if (keyChar === 'R') { | ||
run(e, 'reloadRenderer'); | ||
} | ||
} | ||
@@ -31,0 +35,0 @@ return () => { |
export type RawCosmosPluginConfig = { | ||
name: string; | ||
server?: string; | ||
ui?: string; | ||
server?: string; | ||
}; | ||
@@ -9,4 +9,4 @@ export type CosmosPluginConfig = { | ||
rootDir: string; | ||
server?: string; | ||
ui?: string; | ||
server?: string; | ||
}; | ||
@@ -13,0 +13,0 @@ export type UiCosmosPluginConfig = CosmosPluginConfig & { |
export type RendererConfig = { | ||
playgroundUrl: string; | ||
rendererUrl?: null | string; | ||
}; |
@@ -12,3 +12,2 @@ import { FixtureId } from '../userModules/fixtureTypes.js'; | ||
export declare function parseRendererQueryString(query: string): RendererParams; | ||
export declare function decodeRendererSearchParams(stringParams: RendererSearchParams): RendererParams; | ||
export {}; |
@@ -18,3 +18,3 @@ import { buildQueryString, parseQueryString } from '../utils/queryString.js'; | ||
} | ||
export function decodeRendererSearchParams(stringParams) { | ||
function decodeRendererSearchParams(stringParams) { | ||
const params = {}; | ||
@@ -21,0 +21,0 @@ if (stringParams.fixtureId) { |
import { isEqual } from 'lodash-es'; | ||
import React from 'react'; | ||
// Compied from https://github.com/skidding/react-mock/blob/c33dfa1d6f0c9ce7b3eaba073618d61731a0e82e/packages/state/src/index.js | ||
class ClassStateMock extends React.Component { | ||
export class ClassStateMock extends React.Component { | ||
static cosmosCapture = false; | ||
@@ -45,3 +45,2 @@ childRef = null; | ||
} | ||
export { ClassStateMock }; | ||
function replaceState(childRef, state, cb) { | ||
@@ -48,0 +47,0 @@ // We need to unset existing state keys because React doesn't provide a |
@@ -6,3 +6,3 @@ import React from 'react'; | ||
}; | ||
export declare function DelayRender({ children, delay }: Props): JSX.Element; | ||
export declare function DelayRender({ children, delay }: Props): React.ReactNode; | ||
export {}; |
@@ -9,3 +9,3 @@ 'use client'; | ||
}, [delay]); | ||
return React.createElement(React.Fragment, null, render && children); | ||
return render && children; | ||
} |
{ | ||
"name": "react-cosmos-core", | ||
"version": "6.0.0-canary.86644b2.0+86644b2", | ||
"version": "6.0.0-canary.86b9647.0+86b9647", | ||
"description": "React Cosmos Core", | ||
@@ -11,6 +11,7 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-core", | ||
"dependencies": { | ||
"lodash-es": "^4.17.21", | ||
"react-is": "^18.2.0" | ||
"js-base64": "3.7.5", | ||
"lodash-es": "4.17.21", | ||
"react-is": "18.2.0" | ||
}, | ||
"gitHead": "86644b27e838006a0b58c8e917fa1b10e92c956b" | ||
"gitHead": "86b9647915f4e0fc03d27f2f89dcfa7668e8fbf1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
55489
106
1378
3
+ Addedjs-base64@3.7.5
+ Addedjs-base64@3.7.5(transitive)
+ Addedreact-is@18.2.0(transitive)
- Removedreact-is@18.3.1(transitive)
Updatedlodash-es@4.17.21
Updatedreact-is@18.2.0