@react-fabric/utilities 1.0.0-beta.15 → 1.0.0-beta.18
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/cjs/_cloneElement.js +44 -0
- package/dist/cjs/_getByPath.js +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/esm/_cloneElement.js +44 -0
- package/dist/esm/_getByPath.js +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/types/_cloneElement.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/_cloneElement.ts +42 -0
- package/src/_getByPath.ts +3 -3
- package/src/index.ts +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* React Fabric
|
|
8
|
+
* @version: 1.0.0
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
15
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
16
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
+
* subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
21
|
+
* portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
24
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
25
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
26
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
var cloneChildren = function cloneChildren(children, callback) {
|
|
30
|
+
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
31
|
+
return react.Children.map(children, function (c) {
|
|
32
|
+
if ( /*#__PURE__*/react.isValidElement(c)) {
|
|
33
|
+
if (c.type === jsxRuntime.Fragment) {
|
|
34
|
+
var _c$props;
|
|
35
|
+
// just compare to `Fragment`
|
|
36
|
+
return cloneChildren((_c$props = c.props) === null || _c$props === void 0 ? void 0 : _c$props.children, callback);
|
|
37
|
+
}
|
|
38
|
+
return callback(c, index++);
|
|
39
|
+
}
|
|
40
|
+
return c;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.cloneChildren = cloneChildren;
|
package/dist/cjs/_getByPath.js
CHANGED
|
@@ -36,7 +36,7 @@ var _get = function _get(hit, field) {
|
|
|
36
36
|
if (_isType.isNil(field)) {
|
|
37
37
|
return hit;
|
|
38
38
|
}
|
|
39
|
-
if (_isType.isObject(hit)) {
|
|
39
|
+
if (_isType.isObject(hit) || _isType.isArray(hit)) {
|
|
40
40
|
/** ***************** return value if object.property is not empty *******************/
|
|
41
41
|
if (!_isType.isNil(hit[field])) {
|
|
42
42
|
return hit[field];
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _ascii = require('./_ascii.js');
|
|
4
4
|
var _boundingBox = require('./_boundingBox.js');
|
|
5
|
+
var _cloneElement = require('./_cloneElement.js');
|
|
5
6
|
var _countries = require('./_countries.js');
|
|
6
7
|
var _debounce = require('./_debounce.js');
|
|
7
8
|
var _dedupe = require('./_dedupe.js');
|
|
@@ -70,6 +71,7 @@ Object.freeze(EMPTY_OBJECT);
|
|
|
70
71
|
exports.ascii = _ascii.ascii;
|
|
71
72
|
exports.getBoundingBox = _boundingBox.getBoundingBox;
|
|
72
73
|
exports.getBox = _boundingBox.getBox;
|
|
74
|
+
exports.cloneChildren = _cloneElement.cloneChildren;
|
|
73
75
|
exports.Countries = _countries;
|
|
74
76
|
exports.debounce = _debounce.debounce;
|
|
75
77
|
exports.dedupe = _dedupe.dedupe;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Children, isValidElement } from 'react';
|
|
4
|
+
import { Fragment } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* React Fabric
|
|
8
|
+
* @version: 1.0.0
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
13
|
+
*
|
|
14
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
15
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
16
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
+
* subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
21
|
+
* portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
24
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
25
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
26
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
var cloneChildren = function cloneChildren(children, callback) {
|
|
30
|
+
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
31
|
+
return Children.map(children, function (c) {
|
|
32
|
+
if ( /*#__PURE__*/isValidElement(c)) {
|
|
33
|
+
if (c.type === Fragment) {
|
|
34
|
+
var _c$props;
|
|
35
|
+
// just compare to `Fragment`
|
|
36
|
+
return cloneChildren((_c$props = c.props) === null || _c$props === void 0 ? void 0 : _c$props.children, callback);
|
|
37
|
+
}
|
|
38
|
+
return callback(c, index++);
|
|
39
|
+
}
|
|
40
|
+
return c;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { cloneChildren };
|
package/dist/esm/_getByPath.js
CHANGED
|
@@ -36,7 +36,7 @@ var _get = function _get(hit, field) {
|
|
|
36
36
|
if (isNil(field)) {
|
|
37
37
|
return hit;
|
|
38
38
|
}
|
|
39
|
-
if (isObject(hit)) {
|
|
39
|
+
if (isObject(hit) || isArray(hit)) {
|
|
40
40
|
/** ***************** return value if object.property is not empty *******************/
|
|
41
41
|
if (!isNil(hit[field])) {
|
|
42
42
|
return hit[field];
|
package/dist/esm/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export { ascii } from './_ascii.js';
|
|
4
4
|
export { getBoundingBox, getBox } from './_boundingBox.js';
|
|
5
|
+
export { cloneChildren } from './_cloneElement.js';
|
|
5
6
|
export { default as Countries } from './_countries.js';
|
|
6
7
|
export { debounce } from './_debounce.js';
|
|
7
8
|
export { dedupe, flatten, flattenAndDedupe, groupBy } from './_dedupe.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./_ascii";
|
|
2
2
|
export * from "./_boundingBox";
|
|
3
3
|
export { getBoundingBox, getBox } from "./_boundingBox";
|
|
4
|
+
export * from "./_cloneElement";
|
|
4
5
|
export { default as Countries } from "./_countries";
|
|
5
6
|
export type { Country } from "./_countries";
|
|
6
7
|
export * from "./_debounce";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/utilities",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.18",
|
|
4
4
|
"description": "RUF: Utility package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"node": ">=18.12.0",
|
|
45
45
|
"npm": ">=8.19.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4795fee60aa3e7411934a688f7c53e42ca3297ed"
|
|
48
48
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { type ReactNode, Children, isValidElement } from "react";
|
|
25
|
+
import { Fragment } from "react/jsx-runtime";
|
|
26
|
+
|
|
27
|
+
export const cloneChildren = (
|
|
28
|
+
children: ReactNode,
|
|
29
|
+
callback: (child: ReactNode, index: number) => ReactNode,
|
|
30
|
+
index = 0,
|
|
31
|
+
): ReactNode => {
|
|
32
|
+
return Children.map(children, (c: ReactNode) => {
|
|
33
|
+
if (isValidElement(c)) {
|
|
34
|
+
if (c.type === Fragment) {
|
|
35
|
+
// just compare to `Fragment`
|
|
36
|
+
return cloneChildren(c.props?.children, callback);
|
|
37
|
+
}
|
|
38
|
+
return callback(c, index++);
|
|
39
|
+
}
|
|
40
|
+
return c;
|
|
41
|
+
});
|
|
42
|
+
};
|
package/src/_getByPath.ts
CHANGED
|
@@ -35,10 +35,10 @@ const _get = (hit: any, field: string): any => {
|
|
|
35
35
|
return hit;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if (isObject(hit)) {
|
|
38
|
+
if (isObject(hit) || isArray(hit)) {
|
|
39
39
|
/** ***************** return value if object.property is not empty *******************/
|
|
40
|
-
if (!isNil(hit[field])) {
|
|
41
|
-
return hit[field];
|
|
40
|
+
if (!isNil(hit[field as any])) {
|
|
41
|
+
return hit[field as any];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** ***************** if property name contains `.` separator split to multiple property names *******************/
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
export * from "./_ascii";
|
|
27
27
|
export * from "./_boundingBox";
|
|
28
28
|
export { getBoundingBox, getBox } from "./_boundingBox";
|
|
29
|
+
export * from "./_cloneElement";
|
|
29
30
|
export { default as Countries } from "./_countries";
|
|
30
31
|
export type { Country } from "./_countries";
|
|
31
32
|
export * from "./_debounce";
|