@mantine/hooks 5.10.1 → 6.0.0-alpha.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.
@@ -4,27 +4,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var useIsomorphicEffect = require('../use-isomorphic-effect/use-isomorphic-effect.js');
7
+ var useReactId = require('./use-react-id.js');
8
+ var randomId = require('../utils/random-id/random-id.js');
7
9
 
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
9
-
10
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
11
-
12
- const randomId = () => `mantine-${Math.random().toString(36).slice(2, 11)}`;
13
- const useReactId = React__default["useId".toString()] || (() => void 0);
14
- function useClientId() {
15
- const [uuid, setUuid] = React.useState("");
10
+ function useId(staticId) {
11
+ const reactId = useReactId.useReactId();
12
+ const [uuid, setUuid] = React.useState(reactId);
16
13
  useIsomorphicEffect.useIsomorphicEffect(() => {
17
- setUuid(randomId());
14
+ setUuid(randomId.randomId());
18
15
  }, []);
16
+ if (typeof staticId === "string") {
17
+ return staticId;
18
+ }
19
+ if (typeof window === "undefined") {
20
+ return reactId;
21
+ }
19
22
  return uuid;
20
23
  }
21
- function getReactId() {
22
- const id = useReactId();
23
- return id ? `mantine-${id.replace(/:/g, "")}` : "";
24
- }
25
- function useId(staticId) {
26
- return typeof staticId === "string" ? staticId : getReactId() || useClientId();
27
- }
28
24
 
29
25
  exports.useId = useId;
30
26
  //# sourceMappingURL=use-id.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-id.js","sources":["../../src/use-id/use-id.ts"],"sourcesContent":["import React, { useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nconst randomId = () => `mantine-${Math.random().toString(36).slice(2, 11)}`;\n\nconst useReactId: () => string | undefined =\n (React as any)['useId'.toString()] || (() => undefined);\n\nfunction useClientId() {\n const [uuid, setUuid] = useState('');\n\n useIsomorphicEffect(() => {\n setUuid(randomId());\n }, []);\n\n return uuid;\n}\n\nfunction getReactId() {\n const id = useReactId();\n return id ? `mantine-${id.replace(/:/g, '')}` : '';\n}\n\nexport function useId(staticId?: string) {\n return typeof staticId === 'string' ? staticId : getReactId() || useClientId();\n}\n"],"names":["React","useState","useIsomorphicEffect"],"mappings":";;;;;;;;;;;AAEA,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5E,MAAM,UAAU,GAAGA,cAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,CAAC;AAC/D,SAAS,WAAW,GAAG;AACvB,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGC,cAAQ,CAAC,EAAE,CAAC,CAAC;AACvC,EAAEC,uCAAmB,CAAC,MAAM;AAC5B,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AACxB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;AACD,SAAS,UAAU,GAAG;AACtB,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;AAC1B,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACrD,CAAC;AACM,SAAS,KAAK,CAAC,QAAQ,EAAE;AAChC,EAAE,OAAO,OAAO,QAAQ,KAAK,QAAQ,GAAG,QAAQ,GAAG,UAAU,EAAE,IAAI,WAAW,EAAE,CAAC;AACjF;;;;"}
1
+ {"version":3,"file":"use-id.js","sources":["../../src/use-id/use-id.ts"],"sourcesContent":["import { useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\nimport { randomId } from '../utils';\nimport { useReactId } from './use-react-id';\n\nexport function useId(staticId?: string) {\n const reactId = useReactId();\n const [uuid, setUuid] = useState(reactId);\n\n useIsomorphicEffect(() => {\n setUuid(randomId());\n }, []);\n\n if (typeof staticId === 'string') {\n return staticId;\n }\n\n if (typeof window === 'undefined') {\n return reactId;\n }\n\n return uuid;\n}\n"],"names":["useReactId","useState","useIsomorphicEffect","randomId"],"mappings":";;;;;;;;;AAIO,SAAS,KAAK,CAAC,QAAQ,EAAE;AAChC,EAAE,MAAM,OAAO,GAAGA,qBAAU,EAAE,CAAC;AAC/B,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGC,cAAQ,CAAC,OAAO,CAAC,CAAC;AAC5C,EAAEC,uCAAmB,CAAC,MAAM;AAC5B,IAAI,OAAO,CAACC,iBAAQ,EAAE,CAAC,CAAC;AACxB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;AACpC,IAAI,OAAO,QAAQ,CAAC;AACpB,GAAG;AACH,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACrC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,IAAI,CAAC;AACd;;;;"}
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
8
+
9
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
10
+
11
+ const __useId = React__default["useId".toString()] || (() => void 0);
12
+ function useReactId() {
13
+ const id = __useId();
14
+ return id ? `mantine-${id.replace(/:/g, "")}` : "";
15
+ }
16
+
17
+ exports.useReactId = useReactId;
18
+ //# sourceMappingURL=use-react-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-react-id.js","sources":["../../src/use-id/use-react-id.ts"],"sourcesContent":["import React from 'react';\n\nconst __useId: () => string | undefined = (React as any)['useId'.toString()] || (() => undefined);\n\nexport function useReactId() {\n const id = __useId();\n return id ? `mantine-${id.replace(/:/g, '')}` : '';\n}\n"],"names":["React"],"mappings":";;;;;;;;;;AACA,MAAM,OAAO,GAAGA,cAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,CAAC;AACrD,SAAS,UAAU,GAAG;AAC7B,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;AACvB,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACrD;;;;"}
@@ -2,7 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var React = require('react');
6
+ var useIsomorphicEffect = require('../use-isomorphic-effect/use-isomorphic-effect.js');
7
+
5
8
  function getOS() {
9
+ if (typeof window === "undefined") {
10
+ return "undetermined";
11
+ }
6
12
  const { userAgent } = window.navigator;
7
13
  const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;
8
14
  const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i;
@@ -24,11 +30,14 @@ function getOS() {
24
30
  }
25
31
  return "undetermined";
26
32
  }
27
- function useOs() {
28
- if (typeof window !== "undefined") {
29
- return getOS();
30
- }
31
- return "undetermined";
33
+ function useOs(options = { getValueInEffect: true }) {
34
+ const [value, setValue] = React.useState(options.getValueInEffect ? "undetermined" : getOS());
35
+ useIsomorphicEffect.useIsomorphicEffect(() => {
36
+ if (options.getValueInEffect) {
37
+ setValue(getOS);
38
+ }
39
+ }, []);
40
+ return value;
32
41
  }
33
42
 
34
43
  exports.useOs = useOs;
@@ -1 +1 @@
1
- {"version":3,"file":"use-os.js","sources":["../../src/use-os/use-os.ts"],"sourcesContent":["export type OS = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';\n\nfunction getOS(): OS {\n const { userAgent } = window.navigator;\n const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;\n const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i;\n const iosPlatforms = /(iPhone)|(iPad)|(iPod)/i;\n\n if (macosPlatforms.test(userAgent)) {\n return 'macos';\n }\n if (iosPlatforms.test(userAgent)) {\n return 'ios';\n }\n if (windowsPlatforms.test(userAgent)) {\n return 'windows';\n }\n if (/Android/i.test(userAgent)) {\n return 'android';\n }\n if (/Linux/i.test(userAgent)) {\n return 'linux';\n }\n\n return 'undetermined';\n}\n\nexport function useOs(): OS {\n if (typeof window !== 'undefined') {\n return getOS();\n }\n\n return 'undetermined';\n}\n"],"names":[],"mappings":";;;;AAAA,SAAS,KAAK,GAAG;AACjB,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;AACzC,EAAE,MAAM,cAAc,GAAG,2CAA2C,CAAC;AACrE,EAAE,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAChE,EAAE,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACjD,EAAE,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACtC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,IAAI,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACpC,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACxC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAClC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,cAAc,CAAC;AACxB,CAAC;AACM,SAAS,KAAK,GAAG;AACxB,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACrC,IAAI,OAAO,KAAK,EAAE,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,cAAc,CAAC;AACxB;;;;"}
1
+ {"version":3,"file":"use-os.js","sources":["../../src/use-os/use-os.ts"],"sourcesContent":["import { useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nexport type OS = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';\n\nfunction getOS(): OS {\n if (typeof window === 'undefined') {\n return 'undetermined';\n }\n\n const { userAgent } = window.navigator;\n const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;\n const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i;\n const iosPlatforms = /(iPhone)|(iPad)|(iPod)/i;\n\n if (macosPlatforms.test(userAgent)) {\n return 'macos';\n }\n if (iosPlatforms.test(userAgent)) {\n return 'ios';\n }\n if (windowsPlatforms.test(userAgent)) {\n return 'windows';\n }\n if (/Android/i.test(userAgent)) {\n return 'android';\n }\n if (/Linux/i.test(userAgent)) {\n return 'linux';\n }\n\n return 'undetermined';\n}\n\ninterface UseOsOptions {\n getValueInEffect: boolean;\n}\n\nexport function useOs(options: UseOsOptions = { getValueInEffect: true }): OS {\n const [value, setValue] = useState<OS>(options.getValueInEffect ? 'undetermined' : getOS());\n\n useIsomorphicEffect(() => {\n if (options.getValueInEffect) {\n setValue(getOS);\n }\n }, []);\n\n return value;\n}\n"],"names":["useState","useIsomorphicEffect"],"mappings":";;;;;;;AAEA,SAAS,KAAK,GAAG;AACjB,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACrC,IAAI,OAAO,cAAc,CAAC;AAC1B,GAAG;AACH,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;AACzC,EAAE,MAAM,cAAc,GAAG,2CAA2C,CAAC;AACrE,EAAE,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAChE,EAAE,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACjD,EAAE,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACtC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,IAAI,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACpC,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACxC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAClC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,cAAc,CAAC;AACxB,CAAC;AACM,SAAS,KAAK,CAAC,OAAO,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE;AAC5D,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,OAAO,CAAC,gBAAgB,GAAG,cAAc,GAAG,KAAK,EAAE,CAAC,CAAC;AAC1F,EAAEC,uCAAmB,CAAC,MAAM;AAC5B,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE;AAClC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtB,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,KAAK,CAAC;AACf;;;;"}
@@ -1,22 +1,22 @@
1
- import React, { useState } from 'react';
1
+ import { useState } from 'react';
2
2
  import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.js';
3
+ import { useReactId } from './use-react-id.js';
4
+ import { randomId } from '../utils/random-id/random-id.js';
3
5
 
4
- const randomId = () => `mantine-${Math.random().toString(36).slice(2, 11)}`;
5
- const useReactId = React["useId".toString()] || (() => void 0);
6
- function useClientId() {
7
- const [uuid, setUuid] = useState("");
6
+ function useId(staticId) {
7
+ const reactId = useReactId();
8
+ const [uuid, setUuid] = useState(reactId);
8
9
  useIsomorphicEffect(() => {
9
10
  setUuid(randomId());
10
11
  }, []);
12
+ if (typeof staticId === "string") {
13
+ return staticId;
14
+ }
15
+ if (typeof window === "undefined") {
16
+ return reactId;
17
+ }
11
18
  return uuid;
12
19
  }
13
- function getReactId() {
14
- const id = useReactId();
15
- return id ? `mantine-${id.replace(/:/g, "")}` : "";
16
- }
17
- function useId(staticId) {
18
- return typeof staticId === "string" ? staticId : getReactId() || useClientId();
19
- }
20
20
 
21
21
  export { useId };
22
22
  //# sourceMappingURL=use-id.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-id.js","sources":["../../src/use-id/use-id.ts"],"sourcesContent":["import React, { useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nconst randomId = () => `mantine-${Math.random().toString(36).slice(2, 11)}`;\n\nconst useReactId: () => string | undefined =\n (React as any)['useId'.toString()] || (() => undefined);\n\nfunction useClientId() {\n const [uuid, setUuid] = useState('');\n\n useIsomorphicEffect(() => {\n setUuid(randomId());\n }, []);\n\n return uuid;\n}\n\nfunction getReactId() {\n const id = useReactId();\n return id ? `mantine-${id.replace(/:/g, '')}` : '';\n}\n\nexport function useId(staticId?: string) {\n return typeof staticId === 'string' ? staticId : getReactId() || useClientId();\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5E,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,CAAC;AAC/D,SAAS,WAAW,GAAG;AACvB,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvC,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AACxB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;AACD,SAAS,UAAU,GAAG;AACtB,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;AAC1B,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACrD,CAAC;AACM,SAAS,KAAK,CAAC,QAAQ,EAAE;AAChC,EAAE,OAAO,OAAO,QAAQ,KAAK,QAAQ,GAAG,QAAQ,GAAG,UAAU,EAAE,IAAI,WAAW,EAAE,CAAC;AACjF;;;;"}
1
+ {"version":3,"file":"use-id.js","sources":["../../src/use-id/use-id.ts"],"sourcesContent":["import { useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\nimport { randomId } from '../utils';\nimport { useReactId } from './use-react-id';\n\nexport function useId(staticId?: string) {\n const reactId = useReactId();\n const [uuid, setUuid] = useState(reactId);\n\n useIsomorphicEffect(() => {\n setUuid(randomId());\n }, []);\n\n if (typeof staticId === 'string') {\n return staticId;\n }\n\n if (typeof window === 'undefined') {\n return reactId;\n }\n\n return uuid;\n}\n"],"names":[],"mappings":";;;;;AAIO,SAAS,KAAK,CAAC,QAAQ,EAAE;AAChC,EAAE,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;AAC/B,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC5C,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AACxB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;AACpC,IAAI,OAAO,QAAQ,CAAC;AACpB,GAAG;AACH,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACrC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,IAAI,CAAC;AACd;;;;"}
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+
3
+ const __useId = React["useId".toString()] || (() => void 0);
4
+ function useReactId() {
5
+ const id = __useId();
6
+ return id ? `mantine-${id.replace(/:/g, "")}` : "";
7
+ }
8
+
9
+ export { useReactId };
10
+ //# sourceMappingURL=use-react-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-react-id.js","sources":["../../src/use-id/use-react-id.ts"],"sourcesContent":["import React from 'react';\n\nconst __useId: () => string | undefined = (React as any)['useId'.toString()] || (() => undefined);\n\nexport function useReactId() {\n const id = __useId();\n return id ? `mantine-${id.replace(/:/g, '')}` : '';\n}\n"],"names":[],"mappings":";;AACA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,CAAC;AACrD,SAAS,UAAU,GAAG;AAC7B,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;AACvB,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACrD;;;;"}
@@ -1,4 +1,10 @@
1
+ import { useState } from 'react';
2
+ import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.js';
3
+
1
4
  function getOS() {
5
+ if (typeof window === "undefined") {
6
+ return "undetermined";
7
+ }
2
8
  const { userAgent } = window.navigator;
3
9
  const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;
4
10
  const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i;
@@ -20,11 +26,14 @@ function getOS() {
20
26
  }
21
27
  return "undetermined";
22
28
  }
23
- function useOs() {
24
- if (typeof window !== "undefined") {
25
- return getOS();
26
- }
27
- return "undetermined";
29
+ function useOs(options = { getValueInEffect: true }) {
30
+ const [value, setValue] = useState(options.getValueInEffect ? "undetermined" : getOS());
31
+ useIsomorphicEffect(() => {
32
+ if (options.getValueInEffect) {
33
+ setValue(getOS);
34
+ }
35
+ }, []);
36
+ return value;
28
37
  }
29
38
 
30
39
  export { useOs };
@@ -1 +1 @@
1
- {"version":3,"file":"use-os.js","sources":["../../src/use-os/use-os.ts"],"sourcesContent":["export type OS = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';\n\nfunction getOS(): OS {\n const { userAgent } = window.navigator;\n const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;\n const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i;\n const iosPlatforms = /(iPhone)|(iPad)|(iPod)/i;\n\n if (macosPlatforms.test(userAgent)) {\n return 'macos';\n }\n if (iosPlatforms.test(userAgent)) {\n return 'ios';\n }\n if (windowsPlatforms.test(userAgent)) {\n return 'windows';\n }\n if (/Android/i.test(userAgent)) {\n return 'android';\n }\n if (/Linux/i.test(userAgent)) {\n return 'linux';\n }\n\n return 'undetermined';\n}\n\nexport function useOs(): OS {\n if (typeof window !== 'undefined') {\n return getOS();\n }\n\n return 'undetermined';\n}\n"],"names":[],"mappings":"AAAA,SAAS,KAAK,GAAG;AACjB,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;AACzC,EAAE,MAAM,cAAc,GAAG,2CAA2C,CAAC;AACrE,EAAE,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAChE,EAAE,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACjD,EAAE,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACtC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,IAAI,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACpC,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACxC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAClC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,cAAc,CAAC;AACxB,CAAC;AACM,SAAS,KAAK,GAAG;AACxB,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACrC,IAAI,OAAO,KAAK,EAAE,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,cAAc,CAAC;AACxB;;;;"}
1
+ {"version":3,"file":"use-os.js","sources":["../../src/use-os/use-os.ts"],"sourcesContent":["import { useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nexport type OS = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';\n\nfunction getOS(): OS {\n if (typeof window === 'undefined') {\n return 'undetermined';\n }\n\n const { userAgent } = window.navigator;\n const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;\n const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i;\n const iosPlatforms = /(iPhone)|(iPad)|(iPod)/i;\n\n if (macosPlatforms.test(userAgent)) {\n return 'macos';\n }\n if (iosPlatforms.test(userAgent)) {\n return 'ios';\n }\n if (windowsPlatforms.test(userAgent)) {\n return 'windows';\n }\n if (/Android/i.test(userAgent)) {\n return 'android';\n }\n if (/Linux/i.test(userAgent)) {\n return 'linux';\n }\n\n return 'undetermined';\n}\n\ninterface UseOsOptions {\n getValueInEffect: boolean;\n}\n\nexport function useOs(options: UseOsOptions = { getValueInEffect: true }): OS {\n const [value, setValue] = useState<OS>(options.getValueInEffect ? 'undetermined' : getOS());\n\n useIsomorphicEffect(() => {\n if (options.getValueInEffect) {\n setValue(getOS);\n }\n }, []);\n\n return value;\n}\n"],"names":[],"mappings":";;;AAEA,SAAS,KAAK,GAAG;AACjB,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACrC,IAAI,OAAO,cAAc,CAAC;AAC1B,GAAG;AACH,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;AACzC,EAAE,MAAM,cAAc,GAAG,2CAA2C,CAAC;AACrE,EAAE,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAChE,EAAE,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACjD,EAAE,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACtC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,IAAI,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACpC,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACxC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAClC,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AAChC,IAAI,OAAO,OAAO,CAAC;AACnB,GAAG;AACH,EAAE,OAAO,cAAc,CAAC;AACxB,CAAC;AACM,SAAS,KAAK,CAAC,OAAO,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE;AAC5D,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,gBAAgB,GAAG,cAAc,GAAG,KAAK,EAAE,CAAC,CAAC;AAC1F,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE;AAClC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtB,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,KAAK,CAAC;AACf;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-id.d.ts","sourceRoot":"","sources":["../../src/use-id/use-id.ts"],"names":[],"mappings":"AAuBA,wBAAgB,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,UAEtC"}
1
+ {"version":3,"file":"use-id.d.ts","sourceRoot":"","sources":["../../src/use-id/use-id.ts"],"names":[],"mappings":"AAKA,wBAAgB,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,UAiBtC"}
@@ -0,0 +1,2 @@
1
+ export declare function useReactId(): string;
2
+ //# sourceMappingURL=use-react-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-react-id.d.ts","sourceRoot":"","sources":["../../src/use-id/use-react-id.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,WAGzB"}
@@ -1,3 +1,7 @@
1
1
  export type OS = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';
2
- export declare function useOs(): OS;
2
+ interface UseOsOptions {
3
+ getValueInEffect: boolean;
4
+ }
5
+ export declare function useOs(options?: UseOsOptions): OS;
6
+ export {};
3
7
  //# sourceMappingURL=use-os.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-os.d.ts","sourceRoot":"","sources":["../../src/use-os/use-os.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,cAAc,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AA2BpF,wBAAgB,KAAK,IAAI,EAAE,CAM1B"}
1
+ {"version":3,"file":"use-os.d.ts","sourceRoot":"","sources":["../../src/use-os/use-os.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,EAAE,GAAG,cAAc,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AA+BpF,UAAU,YAAY;IACpB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAyC,GAAG,EAAE,CAU5E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantine/hooks",
3
- "version": "5.10.1",
3
+ "version": "6.0.0-alpha.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "lib/index.d.ts",