@iowas/toolpad 1.0.4 → 1.0.5

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,84 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ function _interopNamespace(e) {
6
+ if (e && e.__esModule) return e;
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
24
+
25
+ // src/toolpad-utils/collections.ts
26
+ function asArray(maybeArray) {
27
+ return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
28
+ }
29
+ function hasOwnProperty(obj, prop) {
30
+ return obj.hasOwnProperty(prop);
31
+ }
32
+ function mapProperties(obj, mapper) {
33
+ return Object.fromEntries(
34
+ Object.entries(obj).flatMap((entry) => {
35
+ const mapped = mapper(entry);
36
+ return mapped ? [mapped] : [];
37
+ })
38
+ );
39
+ }
40
+ function mapKeys(obj, mapper) {
41
+ return mapProperties(obj, ([key, value]) => [mapper(key), value]);
42
+ }
43
+ function mapValues(obj, mapper) {
44
+ return mapProperties(obj, ([key, value]) => [key, mapper(value, key)]);
45
+ }
46
+ function filterValues(obj, filter) {
47
+ return mapProperties(obj, ([key, value]) => filter(value) ? [key, value] : null);
48
+ }
49
+ function filterKeys(obj, filter) {
50
+ return mapProperties(obj, ([key, value]) => filter(key) ? [key, value] : null);
51
+ }
52
+ function equalProperties(obj1, obj2, subset) {
53
+ const keysToCheck = new Set(
54
+ subset != null ? subset : [...Object.keys(obj1), ...Object.keys(obj2)]
55
+ );
56
+ return Array.from(keysToCheck).every((key) => Object.is(obj1[key], obj2[key]));
57
+ }
58
+ function useBoolean(initialValue) {
59
+ const [value, setValue] = React__namespace.useState(initialValue);
60
+ const toggle = React__namespace.useCallback(() => setValue((existing) => !existing), []);
61
+ const setTrue = React__namespace.useCallback(() => setValue(true), []);
62
+ const setFalse = React__namespace.useCallback(() => setValue(false), []);
63
+ return { value, setValue, toggle, setTrue, setFalse };
64
+ }
65
+ function usePageTitle(title) {
66
+ React__namespace.useEffect(() => {
67
+ const original = document.title;
68
+ document.title = title;
69
+ return () => {
70
+ document.title = original;
71
+ };
72
+ }, [title]);
73
+ }
74
+
75
+ exports.asArray = asArray;
76
+ exports.equalProperties = equalProperties;
77
+ exports.filterKeys = filterKeys;
78
+ exports.filterValues = filterValues;
79
+ exports.hasOwnProperty = hasOwnProperty;
80
+ exports.mapKeys = mapKeys;
81
+ exports.mapProperties = mapProperties;
82
+ exports.mapValues = mapValues;
83
+ exports.useBoolean = useBoolean;
84
+ exports.usePageTitle = usePageTitle;