react-simplikit 0.0.25 → 0.0.27
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.
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/mergeProps/index.ts
|
|
21
|
+
var mergeProps_exports = {};
|
|
22
|
+
__export(mergeProps_exports, {
|
|
23
|
+
mergeProps: () => mergeProps
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(mergeProps_exports);
|
|
26
|
+
|
|
27
|
+
// src/utils/mergeProps/mergeProps.ts
|
|
28
|
+
function mergeProps(...props) {
|
|
29
|
+
return props.reduce(pushProp, {});
|
|
30
|
+
}
|
|
31
|
+
function pushProp(prev, curr) {
|
|
32
|
+
for (const key in curr) {
|
|
33
|
+
if (curr[key] === void 0) continue;
|
|
34
|
+
switch (key) {
|
|
35
|
+
case "className": {
|
|
36
|
+
prev[key] = [prev[key], curr[key]].join(" ").trim();
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "style": {
|
|
40
|
+
prev[key] = mergeStyle(prev[key], curr[key]);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
default: {
|
|
44
|
+
const mergedFunction = mergeFunction(prev[key], curr[key]);
|
|
45
|
+
if (mergedFunction) {
|
|
46
|
+
prev[key] = mergedFunction;
|
|
47
|
+
} else if (curr[key] !== void 0) {
|
|
48
|
+
prev[key] = curr[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return prev;
|
|
54
|
+
}
|
|
55
|
+
function mergeStyle(a, b) {
|
|
56
|
+
if (a == null) return b;
|
|
57
|
+
return { ...a, ...b };
|
|
58
|
+
}
|
|
59
|
+
function mergeFunction(a, b) {
|
|
60
|
+
if (typeof a === "function" && typeof b === "function") {
|
|
61
|
+
return (...args) => {
|
|
62
|
+
a(...args);
|
|
63
|
+
b(...args);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
mergeProps
|
|
70
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
type BaseProps = {
|
|
4
|
+
style?: CSSProperties;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
type TupleToIntersection<T extends Record<string, unknown>[]> = {
|
|
8
|
+
[I in keyof T]: (x: T[I]) => void;
|
|
9
|
+
}[number] extends (x: infer I) => void ? I : never;
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* `mergeProps` is a utility function that merges multiple props objects into a single object.
|
|
13
|
+
* It handles merging of `className`, `style`, and `function` properties.
|
|
14
|
+
*
|
|
15
|
+
* @template PropsList - The type of the props objects to merge.
|
|
16
|
+
*
|
|
17
|
+
* @param {PropsList} props - The props objects to merge.
|
|
18
|
+
* @returns {TupleToIntersection<PropsList>} The merged props object.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const mergedProps = mergeProps({ className: 'foo', style: { color: 'red' } }, { className: 'bar', style: { backgroundColor: 'blue' } });
|
|
22
|
+
* console.log(mergedProps); // { className: 'foo bar', style: { color: 'red', backgroundColor: 'blue' } }
|
|
23
|
+
*/
|
|
24
|
+
declare function mergeProps<PropsList extends BaseProps[]>(...props: PropsList): TupleToIntersection<PropsList>;
|
|
25
|
+
|
|
26
|
+
export { mergeProps };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
type BaseProps = {
|
|
4
|
+
style?: CSSProperties;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
type TupleToIntersection<T extends Record<string, unknown>[]> = {
|
|
8
|
+
[I in keyof T]: (x: T[I]) => void;
|
|
9
|
+
}[number] extends (x: infer I) => void ? I : never;
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* `mergeProps` is a utility function that merges multiple props objects into a single object.
|
|
13
|
+
* It handles merging of `className`, `style`, and `function` properties.
|
|
14
|
+
*
|
|
15
|
+
* @template PropsList - The type of the props objects to merge.
|
|
16
|
+
*
|
|
17
|
+
* @param {PropsList} props - The props objects to merge.
|
|
18
|
+
* @returns {TupleToIntersection<PropsList>} The merged props object.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const mergedProps = mergeProps({ className: 'foo', style: { color: 'red' } }, { className: 'bar', style: { backgroundColor: 'blue' } });
|
|
22
|
+
* console.log(mergedProps); // { className: 'foo bar', style: { color: 'red', backgroundColor: 'blue' } }
|
|
23
|
+
*/
|
|
24
|
+
declare function mergeProps<PropsList extends BaseProps[]>(...props: PropsList): TupleToIntersection<PropsList>;
|
|
25
|
+
|
|
26
|
+
export { mergeProps };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/utils/mergeProps/mergeProps.ts
|
|
2
|
+
function mergeProps(...props) {
|
|
3
|
+
return props.reduce(pushProp, {});
|
|
4
|
+
}
|
|
5
|
+
function pushProp(prev, curr) {
|
|
6
|
+
for (const key in curr) {
|
|
7
|
+
if (curr[key] === void 0) continue;
|
|
8
|
+
switch (key) {
|
|
9
|
+
case "className": {
|
|
10
|
+
prev[key] = [prev[key], curr[key]].join(" ").trim();
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case "style": {
|
|
14
|
+
prev[key] = mergeStyle(prev[key], curr[key]);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
default: {
|
|
18
|
+
const mergedFunction = mergeFunction(prev[key], curr[key]);
|
|
19
|
+
if (mergedFunction) {
|
|
20
|
+
prev[key] = mergedFunction;
|
|
21
|
+
} else if (curr[key] !== void 0) {
|
|
22
|
+
prev[key] = curr[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return prev;
|
|
28
|
+
}
|
|
29
|
+
function mergeStyle(a, b) {
|
|
30
|
+
if (a == null) return b;
|
|
31
|
+
return { ...a, ...b };
|
|
32
|
+
}
|
|
33
|
+
function mergeFunction(a, b) {
|
|
34
|
+
if (typeof a === "function" && typeof b === "function") {
|
|
35
|
+
return (...args) => {
|
|
36
|
+
a(...args);
|
|
37
|
+
b(...args);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
mergeProps
|
|
43
|
+
};
|