react-cosmos-core 7.2.0 → 7.2.1-canary.3822d76.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.
- package/dist/fixtureState/classState.js +2 -2
- package/dist/fixtureState/props.js +2 -2
- package/dist/fixtureTree/createFixtureTree/collapseFixtureDirs.js +1 -2
- package/dist/fixtureTree/createFixtureTree/createRawFixtureTree.js +9 -15
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/renderer/rendererUrl.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/array.js +2 -3
- package/dist/utils/data.js +4 -2
- package/dist/utils/isEqual.d.ts +15 -0
- package/dist/utils/isEqual.js +61 -0
- package/dist/utils/mapValues.d.ts +1 -0
- package/dist/utils/mapValues.js +3 -0
- package/dist/utils/pathUtils.d.ts +2 -0
- package/dist/utils/pathUtils.js +35 -0
- package/dist/utils/react/areNodesEqual.js +22 -5
- package/dist/utils/serializable.js +1 -1
- package/dist/utils/window.js +1 -1
- package/package.json +3 -4
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { find, isEqual } from 'lodash-es';
|
|
2
1
|
import { removeItemMatch, replaceOrAddItem, updateItem, } from '../utils/array.js';
|
|
2
|
+
import { isEqual } from '../utils/isEqual.js';
|
|
3
3
|
export function filterClassStateFixtureState(classStateFs, decoratorId) {
|
|
4
4
|
return classStateFs
|
|
5
5
|
? classStateFs.filter(s => s.elementId.decoratorId === decoratorId)
|
|
6
6
|
: [];
|
|
7
7
|
}
|
|
8
8
|
export function findClassStateFixtureStateItem(classStateFs, elementId) {
|
|
9
|
-
return (classStateFs && find(
|
|
9
|
+
return (classStateFs && classStateFs.find(s => isEqual(s.elementId, elementId)));
|
|
10
10
|
}
|
|
11
11
|
export function createClassStateFixtureStateItem({ classStateFs, elementId, values, componentName, }) {
|
|
12
12
|
return replaceOrAddItem(classStateFs ?? [], createClassStateMatcher(elementId), { elementId, values, componentName });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { find, isEqual } from 'lodash-es';
|
|
2
1
|
import { removeItemMatch, replaceOrAddItem, updateItem, } from '../utils/array.js';
|
|
2
|
+
import { isEqual } from '../utils/isEqual.js';
|
|
3
3
|
export const DEFAULT_RENDER_KEY = 0;
|
|
4
4
|
export function filterPropsFixtureState(propsFs, decoratorId) {
|
|
5
5
|
return propsFs
|
|
@@ -7,7 +7,7 @@ export function filterPropsFixtureState(propsFs, decoratorId) {
|
|
|
7
7
|
: [];
|
|
8
8
|
}
|
|
9
9
|
export function findPropsFixtureStateItem(propsFs, elementId) {
|
|
10
|
-
return propsFs && find(
|
|
10
|
+
return propsFs && propsFs.find(p => isEqual(p.elementId, elementId));
|
|
11
11
|
}
|
|
12
12
|
export function createPropsFixtureStateItem({ propsFs, elementId, values, componentName, }) {
|
|
13
13
|
return replaceOrAddItem(propsFs ?? [], createPropsMatcher(elementId), {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { omit } from 'lodash-es';
|
|
2
1
|
export function collapseFixtureDirs(treeNode, fixturesDir) {
|
|
3
2
|
const { data, children } = treeNode;
|
|
4
3
|
if (data.type !== 'fileDir' || !children)
|
|
5
4
|
return treeNode;
|
|
6
5
|
const collapsableDirNode = children[fixturesDir];
|
|
7
6
|
if (collapsableDirNode && collapsableDirNode.data.type === 'fileDir') {
|
|
8
|
-
const otherChildren =
|
|
7
|
+
const { [fixturesDir]: _, ...otherChildren } = children;
|
|
9
8
|
const innerChildren = collapsableDirNode.children;
|
|
10
9
|
// Make sure children of the collapsed dir don't overlap with children of
|
|
11
10
|
// the parent dir
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { get, set } from 'lodash-es';
|
|
2
1
|
import { addTreeNodeChild } from '../../utils/tree.js';
|
|
3
2
|
import { removeFixtureNameExtension } from '../fixtureUtils.js';
|
|
4
3
|
export function createRawFixtureTree(fixtures) {
|
|
@@ -41,19 +40,14 @@ function parseFixturePath(fixturePath) {
|
|
|
41
40
|
function injectNode(rootNode, parents, childName, childNode) {
|
|
42
41
|
if (parents.length === 0)
|
|
43
42
|
return addTreeNodeChild(rootNode, childName, childNode);
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!curParent) {
|
|
51
|
-
curParent = {
|
|
52
|
-
data: { type: 'fileDir' },
|
|
53
|
-
};
|
|
54
|
-
set(rootNode, curPath, curParent);
|
|
43
|
+
let curNode = rootNode;
|
|
44
|
+
for (const dirName of parents) {
|
|
45
|
+
if (!curNode.children)
|
|
46
|
+
curNode.children = {};
|
|
47
|
+
if (!curNode.children[dirName]) {
|
|
48
|
+
curNode.children[dirName] = { data: { type: 'fileDir' } };
|
|
55
49
|
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
addTreeNodeChild(
|
|
50
|
+
curNode = curNode.children[dirName];
|
|
51
|
+
}
|
|
52
|
+
addTreeNodeChild(curNode, childName, childNode);
|
|
59
53
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ export * from './userModules/stringifyFixtureId.js';
|
|
|
32
32
|
export * from './userModules/userModuleTypes.js';
|
|
33
33
|
export * from './utils/array.js';
|
|
34
34
|
export * from './utils/data.js';
|
|
35
|
+
export * from './utils/isEqual.js';
|
|
36
|
+
export * from './utils/mapValues.js';
|
|
37
|
+
export * from './utils/pathUtils.js';
|
|
35
38
|
export * from './utils/keys.js';
|
|
36
39
|
export * from './utils/queryString.js';
|
|
37
40
|
export * from './utils/react/areNodesEqual.js';
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,9 @@ export * from './userModules/stringifyFixtureId.js';
|
|
|
32
32
|
export * from './userModules/userModuleTypes.js';
|
|
33
33
|
export * from './utils/array.js';
|
|
34
34
|
export * from './utils/data.js';
|
|
35
|
+
export * from './utils/isEqual.js';
|
|
36
|
+
export * from './utils/mapValues.js';
|
|
37
|
+
export * from './utils/pathUtils.js';
|
|
35
38
|
export * from './utils/keys.js';
|
|
36
39
|
export * from './utils/queryString.js';
|
|
37
40
|
export * from './utils/react/areNodesEqual.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/
|
|
1
|
+
{"root":["../src/index.ts","../src/fixtureState/classState.ts","../src/fixtureState/classStateTypes.ts","../src/fixtureState/createValues.ts","../src/fixtureState/extendWithValues.ts","../src/fixtureState/fixtureState.ts","../src/fixtureState/inputsTypes.ts","../src/fixtureState/props.ts","../src/fixtureState/propsTypes.ts","../src/fixtureState/types.ts","../src/fixtureState/viewport.ts","../src/fixtureTree/fixtureUtils.ts","../src/fixtureTree/flattenFixtureTree.tsx","../src/fixtureTree/types.ts","../src/fixtureTree/createFixtureTree/collapseFixtureDirs.ts","../src/fixtureTree/createFixtureTree/collapseIndexes.ts","../src/fixtureTree/createFixtureTree/collapseNamedIndexes.ts","../src/fixtureTree/createFixtureTree/collapseOuterDirs.ts","../src/fixtureTree/createFixtureTree/createRawFixtureTree.ts","../src/fixtureTree/createFixtureTree/hideFixtureSuffix.ts","../src/fixtureTree/createFixtureTree/index.ts","../src/message/serverMessage.ts","../src/message/socketMessage.ts","../src/playground/notifications.ts","../src/playground/playgroundParams.ts","../src/playground/playgroundQueryString.ts","../src/playground/registerPlaygroundShortcuts.ts","../src/plugin/cosmosPluginConfig.ts","../src/renderer/rendererConfig.ts","../src/renderer/rendererConnect.ts","../src/renderer/rendererQueryString.ts","../src/renderer/rendererUrl.ts","../src/server/serverTypes.ts","../src/userModules/fixtureTypes.ts","../src/userModules/getFixtureFromExport.ts","../src/userModules/getFixtureList.ts","../src/userModules/getSortedDecoratorsForFixturePath.ts","../src/userModules/isMultiFixture.ts","../src/userModules/stringifyFixtureId.ts","../src/userModules/userModuleTypes.ts","../src/utils/array.ts","../src/utils/data.ts","../src/utils/isEqual.ts","../src/utils/keys.ts","../src/utils/mapValues.ts","../src/utils/pathUtils.ts","../src/utils/queryString.ts","../src/utils/serializable.ts","../src/utils/state.ts","../src/utils/string.ts","../src/utils/tree.ts","../src/utils/uuid.ts","../src/utils/window.ts","../src/utils/react/DelayRender.tsx","../src/utils/react/areNodesEqual.ts","../src/utils/react/getComponentName.ts","../src/utils/react/isReactElement.ts"],"version":"5.9.3"}
|
package/dist/utils/array.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { findIndex } from 'lodash-es';
|
|
2
1
|
export function updateItem(items, item, update) {
|
|
3
2
|
const index = items.indexOf(item);
|
|
4
3
|
return [
|
|
@@ -8,13 +7,13 @@ export function updateItem(items, item, update) {
|
|
|
8
7
|
];
|
|
9
8
|
}
|
|
10
9
|
export function replaceOrAddItem(items, matcher, item) {
|
|
11
|
-
const index = findIndex(
|
|
10
|
+
const index = items.findIndex(matcher);
|
|
12
11
|
return index !== -1
|
|
13
12
|
? [...items.slice(0, index), item, ...items.slice(index + 1)]
|
|
14
13
|
: [...items, item];
|
|
15
14
|
}
|
|
16
15
|
export function removeItemMatch(items, matcher) {
|
|
17
|
-
const index = findIndex(
|
|
16
|
+
const index = items.findIndex(matcher);
|
|
18
17
|
return index === -1
|
|
19
18
|
? [...items]
|
|
20
19
|
: [...items.slice(0, index), ...items.slice(index + 1)];
|
package/dist/utils/data.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isPlainObject } from 'lodash-es';
|
|
2
1
|
import { isValidElement } from 'react';
|
|
3
2
|
export function isString(value) {
|
|
4
3
|
return typeof value === 'string';
|
|
@@ -23,7 +22,10 @@ export function isPrimitiveData(data) {
|
|
|
23
22
|
isUndefined(data));
|
|
24
23
|
}
|
|
25
24
|
export function isObject(data) {
|
|
26
|
-
|
|
25
|
+
if (data === null || typeof data !== 'object' || isValidElement(data))
|
|
26
|
+
return false;
|
|
27
|
+
const proto = Object.getPrototypeOf(data);
|
|
28
|
+
return proto === Object.prototype || proto === null;
|
|
27
29
|
}
|
|
28
30
|
export function isArray(data) {
|
|
29
31
|
return Array.isArray(data);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep equality for the subset of values that appear in react-cosmos
|
|
3
|
+
* fixture state, props, and element IDs.
|
|
4
|
+
*
|
|
5
|
+
* Handles: primitives (NaN and +0/-0 are treated as equal), Date, RegExp,
|
|
6
|
+
* Map, Set, arrays, and plain objects (enumerable own keys only).
|
|
7
|
+
*
|
|
8
|
+
* Not handled — do not rely on correct results for these:
|
|
9
|
+
* - Circular references (will stack overflow).
|
|
10
|
+
* - Sets containing non-primitives (compared by identity, not structure).
|
|
11
|
+
* - Symbol-keyed properties (ignored).
|
|
12
|
+
* - TypedArrays / ArrayBuffer / Error / arguments objects (fall through
|
|
13
|
+
* to the plain-object branch).
|
|
14
|
+
*/
|
|
15
|
+
export declare function isEqual(a: unknown, b: unknown): boolean;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep equality for the subset of values that appear in react-cosmos
|
|
3
|
+
* fixture state, props, and element IDs.
|
|
4
|
+
*
|
|
5
|
+
* Handles: primitives (NaN and +0/-0 are treated as equal), Date, RegExp,
|
|
6
|
+
* Map, Set, arrays, and plain objects (enumerable own keys only).
|
|
7
|
+
*
|
|
8
|
+
* Not handled — do not rely on correct results for these:
|
|
9
|
+
* - Circular references (will stack overflow).
|
|
10
|
+
* - Sets containing non-primitives (compared by identity, not structure).
|
|
11
|
+
* - Symbol-keyed properties (ignored).
|
|
12
|
+
* - TypedArrays / ArrayBuffer / Error / arguments objects (fall through
|
|
13
|
+
* to the plain-object branch).
|
|
14
|
+
*/
|
|
15
|
+
export function isEqual(a, b) {
|
|
16
|
+
if (a === b || (Number.isNaN(a) && Number.isNaN(b)))
|
|
17
|
+
return true;
|
|
18
|
+
if (a === null ||
|
|
19
|
+
b === null ||
|
|
20
|
+
typeof a !== 'object' ||
|
|
21
|
+
typeof b !== 'object')
|
|
22
|
+
return false;
|
|
23
|
+
if (a.constructor !== b.constructor)
|
|
24
|
+
return false;
|
|
25
|
+
if (a instanceof Date)
|
|
26
|
+
return a.getTime() === b.getTime();
|
|
27
|
+
if (a instanceof RegExp)
|
|
28
|
+
return a.source === b.source && a.flags === b.flags;
|
|
29
|
+
if (a instanceof Map) {
|
|
30
|
+
const mb = b;
|
|
31
|
+
if (a.size !== mb.size)
|
|
32
|
+
return false;
|
|
33
|
+
for (const [key, val] of a) {
|
|
34
|
+
if (!mb.has(key) || !isEqual(val, mb.get(key)))
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (a instanceof Set) {
|
|
40
|
+
const sb = b;
|
|
41
|
+
if (a.size !== sb.size)
|
|
42
|
+
return false;
|
|
43
|
+
for (const val of a) {
|
|
44
|
+
if (!sb.has(val))
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(a)) {
|
|
50
|
+
const arrB = b;
|
|
51
|
+
if (a.length !== arrB.length)
|
|
52
|
+
return false;
|
|
53
|
+
return a.every((val, i) => isEqual(val, arrB[i]));
|
|
54
|
+
}
|
|
55
|
+
const keysA = Object.keys(a);
|
|
56
|
+
const keysB = Object.keys(b);
|
|
57
|
+
if (keysA.length !== keysB.length)
|
|
58
|
+
return false;
|
|
59
|
+
return keysA.every(key => Object.hasOwn(b, key) &&
|
|
60
|
+
isEqual(a[key], b[key]));
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mapValues<T, R>(obj: Record<string, T>, fn: (value: T, key: string) => R): Record<string, R>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function getByPath(obj, path) {
|
|
2
|
+
let cur = obj;
|
|
3
|
+
for (const key of parsePath(path)) {
|
|
4
|
+
if (cur === null || cur === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
cur = cur[key];
|
|
7
|
+
}
|
|
8
|
+
return cur;
|
|
9
|
+
}
|
|
10
|
+
export function setByPath(obj, path, value) {
|
|
11
|
+
const keys = parsePath(path);
|
|
12
|
+
function set(current, index) {
|
|
13
|
+
if (index === keys.length)
|
|
14
|
+
return value;
|
|
15
|
+
const key = keys[index];
|
|
16
|
+
const cur = current;
|
|
17
|
+
const next = set(cur?.[key], index + 1);
|
|
18
|
+
if (Array.isArray(current)) {
|
|
19
|
+
const copy = [...current];
|
|
20
|
+
copy[key] = next;
|
|
21
|
+
return copy;
|
|
22
|
+
}
|
|
23
|
+
return { ...cur, [key]: next };
|
|
24
|
+
}
|
|
25
|
+
return set(obj, 0);
|
|
26
|
+
}
|
|
27
|
+
// Parse paths like "props.children[0].props.children"
|
|
28
|
+
// into segments like ["props", "children", 0, "props", "children"]
|
|
29
|
+
function parsePath(path) {
|
|
30
|
+
return path
|
|
31
|
+
.replace(/\[(\d+)]/g, '.$1') // [0] → .0
|
|
32
|
+
.split('.')
|
|
33
|
+
.filter(s => s !== '')
|
|
34
|
+
.map(s => (/^\d+$/.test(s) ? Number(s) : s));
|
|
35
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isObject } from '../data.js';
|
|
2
|
+
import { isEqual } from '../isEqual.js';
|
|
2
3
|
import { getComponentName } from './getComponentName.js';
|
|
3
4
|
import { isReactElement } from './isReactElement.js';
|
|
4
5
|
export function areNodesEqual(node1, node2, strictTypeCheck) {
|
|
@@ -29,9 +30,25 @@ function areArrayNodesEqual(node1, node2, strictTypeCheck) {
|
|
|
29
30
|
return node1.every((node, nodeIndex) => areNodesEqual(node, node2[nodeIndex], strictTypeCheck));
|
|
30
31
|
}
|
|
31
32
|
function arePropsEqual(object1, object2) {
|
|
32
|
-
|
|
33
|
+
const keys1 = Object.keys(object1);
|
|
34
|
+
const keys2 = Object.keys(object2);
|
|
35
|
+
if (keys1.length !== keys2.length)
|
|
33
36
|
return false;
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
return keys1.every(key => Object.prototype.hasOwnProperty.call(object2, key) &&
|
|
38
|
+
arePropValuesEqual(object1[key], object2[key]));
|
|
39
|
+
}
|
|
40
|
+
// Recurse into plain objects and arrays so that functions at any depth are
|
|
41
|
+
// compared by their source code, not by reference. This makes prop comparison
|
|
42
|
+
// resilient to HMR, which creates fresh function instances on every reload.
|
|
43
|
+
function arePropValuesEqual(value1, value2) {
|
|
44
|
+
if (typeof value1 === 'function' && typeof value2 === 'function')
|
|
45
|
+
return value1 === value2 || value1.toString() === value2.toString();
|
|
46
|
+
if (isObject(value1) && isObject(value2))
|
|
47
|
+
return arePropsEqual(value1, value2);
|
|
48
|
+
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
49
|
+
if (value1.length !== value2.length)
|
|
50
|
+
return false;
|
|
51
|
+
return value1.every((v, i) => arePropValuesEqual(v, value2[i]));
|
|
52
|
+
}
|
|
53
|
+
return isEqual(value1, value2);
|
|
37
54
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isArray, isObject, isPrimitiveData } from './data.js';
|
|
2
2
|
export function pickSerializableValues(object) {
|
|
3
|
-
return Object.fromEntries(Object.entries(object).filter(([
|
|
3
|
+
return Object.fromEntries(Object.entries(object).filter(([, v]) => isSerializable(v)));
|
|
4
4
|
}
|
|
5
5
|
export function isSerializable(data) {
|
|
6
6
|
if (isObject(data))
|
package/dist/utils/window.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-core",
|
|
3
|
-
"version": "7.2.0",
|
|
3
|
+
"version": "7.2.1-canary.3822d76.0+3822d76",
|
|
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,11 +8,10 @@
|
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"js-base64": "3.7.8"
|
|
12
|
-
"lodash-es": "4.17.23"
|
|
11
|
+
"js-base64": "3.7.8"
|
|
13
12
|
},
|
|
14
13
|
"peerDependencies": {
|
|
15
14
|
"react": ">=18"
|
|
16
15
|
},
|
|
17
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "3822d7614f71ce82c282b1516ad18552042ff71a"
|
|
18
17
|
}
|