@reactuses/core 4.0.10 → 4.0.11

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/index.d.ts CHANGED
@@ -753,7 +753,10 @@ interface WindowSize {
753
753
  width: number;
754
754
  height: number;
755
755
  }
756
- declare function useWindowSize(): WindowSize;
756
+ declare function useWindowSize(): {
757
+ readonly width: number;
758
+ readonly height: number;
759
+ };
757
760
 
758
761
  interface UseWindowScrollState {
759
762
  x: number;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useRef, useEffect, useLayoutEffect, useCallback, useMemo, useState, useReducer, useSyncExternalStore } from 'react';
1
+ import require$$0, { useRef, useEffect, useLayoutEffect, useCallback, useMemo, useState, useReducer } from 'react';
2
2
 
3
3
  function usePrevious(state) {
4
4
  const ref = useRef();
@@ -47,7 +47,7 @@ const isNavigator = typeof navigator !== "undefined";
47
47
  const noop = () => {
48
48
  };
49
49
  const isIOS = isBrowser && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
50
- !React.useId;
50
+ !require$$0.useId;
51
51
 
52
52
  function guessSerializerType(rawInit) {
53
53
  return rawInit == null || rawInit === void 0 ? "any" : rawInit instanceof Set ? "set" : rawInit instanceof Map ? "map" : rawInit instanceof Date ? "date" : typeof rawInit === "boolean" ? "boolean" : typeof rawInit === "string" ? "string" : typeof rawInit === "object" ? "object" : Array.isArray(rawInit) ? "object" : !Number.isNaN(rawInit) ? "number" : "any";
@@ -4817,22 +4817,333 @@ function useWindowsFocus(defauleValue = false) {
4817
4817
  return focused;
4818
4818
  }
4819
4819
 
4820
+ var shim = {exports: {}};
4821
+
4822
+ var useSyncExternalStoreShim_production_min = {};
4823
+
4824
+ /**
4825
+ * @license React
4826
+ * use-sync-external-store-shim.production.min.js
4827
+ *
4828
+ * Copyright (c) Facebook, Inc. and its affiliates.
4829
+ *
4830
+ * This source code is licensed under the MIT license found in the
4831
+ * LICENSE file in the root directory of this source tree.
4832
+ */
4833
+
4834
+ var hasRequiredUseSyncExternalStoreShim_production_min;
4835
+
4836
+ function requireUseSyncExternalStoreShim_production_min () {
4837
+ if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
4838
+ hasRequiredUseSyncExternalStoreShim_production_min = 1;
4839
+ var e=require$$0;function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p=e.useDebugValue;function q(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r(c)&&g({inst:c});},[a,d,b]);m(function(){r(c)&&g({inst:c});return a(function(){r(c)&&g({inst:c});})},[a]);p(d);return d}
4840
+ function r(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t(a,b){return b()}var u="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t:q;useSyncExternalStoreShim_production_min.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u;
4841
+ return useSyncExternalStoreShim_production_min;
4842
+ }
4843
+
4844
+ var useSyncExternalStoreShim_development = {};
4845
+
4846
+ /**
4847
+ * @license React
4848
+ * use-sync-external-store-shim.development.js
4849
+ *
4850
+ * Copyright (c) Facebook, Inc. and its affiliates.
4851
+ *
4852
+ * This source code is licensed under the MIT license found in the
4853
+ * LICENSE file in the root directory of this source tree.
4854
+ */
4855
+
4856
+ var hasRequiredUseSyncExternalStoreShim_development;
4857
+
4858
+ function requireUseSyncExternalStoreShim_development () {
4859
+ if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
4860
+ hasRequiredUseSyncExternalStoreShim_development = 1;
4861
+
4862
+ if (process.env.NODE_ENV !== "production") {
4863
+ (function() {
4864
+
4865
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
4866
+ if (
4867
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
4868
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
4869
+ 'function'
4870
+ ) {
4871
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
4872
+ }
4873
+ var React = require$$0;
4874
+
4875
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
4876
+
4877
+ function error(format) {
4878
+ {
4879
+ {
4880
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
4881
+ args[_key2 - 1] = arguments[_key2];
4882
+ }
4883
+
4884
+ printWarning('error', format, args);
4885
+ }
4886
+ }
4887
+ }
4888
+
4889
+ function printWarning(level, format, args) {
4890
+ // When changing this logic, you might want to also
4891
+ // update consoleWithStackDev.www.js as well.
4892
+ {
4893
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
4894
+ var stack = ReactDebugCurrentFrame.getStackAddendum();
4895
+
4896
+ if (stack !== '') {
4897
+ format += '%s';
4898
+ args = args.concat([stack]);
4899
+ } // eslint-disable-next-line react-internal/safe-string-coercion
4900
+
4901
+
4902
+ var argsWithFormat = args.map(function (item) {
4903
+ return String(item);
4904
+ }); // Careful: RN currently depends on this prefix
4905
+
4906
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
4907
+ // breaks IE9: https://github.com/facebook/react/issues/13610
4908
+ // eslint-disable-next-line react-internal/no-production-logging
4909
+
4910
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
4911
+ }
4912
+ }
4913
+
4914
+ /**
4915
+ * inlined Object.is polyfill to avoid requiring consumers ship their own
4916
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
4917
+ */
4918
+ function is(x, y) {
4919
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
4920
+ ;
4921
+ }
4922
+
4923
+ var objectIs = typeof Object.is === 'function' ? Object.is : is;
4924
+
4925
+ // dispatch for CommonJS interop named imports.
4926
+
4927
+ var useState = React.useState,
4928
+ useEffect = React.useEffect,
4929
+ useLayoutEffect = React.useLayoutEffect,
4930
+ useDebugValue = React.useDebugValue;
4931
+ var didWarnOld18Alpha = false;
4932
+ var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
4933
+ // because of a very particular set of implementation details and assumptions
4934
+ // -- change any one of them and it will break. The most important assumption
4935
+ // is that updates are always synchronous, because concurrent rendering is
4936
+ // only available in versions of React that also have a built-in
4937
+ // useSyncExternalStore API. And we only use this shim when the built-in API
4938
+ // does not exist.
4939
+ //
4940
+ // Do not assume that the clever hacks used by this hook also work in general.
4941
+ // The point of this shim is to replace the need for hacks by other libraries.
4942
+
4943
+ function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
4944
+ // React do not expose a way to check if we're hydrating. So users of the shim
4945
+ // will need to track that themselves and return the correct value
4946
+ // from `getSnapshot`.
4947
+ getServerSnapshot) {
4948
+ {
4949
+ if (!didWarnOld18Alpha) {
4950
+ if (React.startTransition !== undefined) {
4951
+ didWarnOld18Alpha = true;
4952
+
4953
+ error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
4954
+ }
4955
+ }
4956
+ } // Read the current snapshot from the store on every render. Again, this
4957
+ // breaks the rules of React, and only works here because of specific
4958
+ // implementation details, most importantly that updates are
4959
+ // always synchronous.
4960
+
4961
+
4962
+ var value = getSnapshot();
4963
+
4964
+ {
4965
+ if (!didWarnUncachedGetSnapshot) {
4966
+ var cachedValue = getSnapshot();
4967
+
4968
+ if (!objectIs(value, cachedValue)) {
4969
+ error('The result of getSnapshot should be cached to avoid an infinite loop');
4970
+
4971
+ didWarnUncachedGetSnapshot = true;
4972
+ }
4973
+ }
4974
+ } // Because updates are synchronous, we don't queue them. Instead we force a
4975
+ // re-render whenever the subscribed state changes by updating an some
4976
+ // arbitrary useState hook. Then, during render, we call getSnapshot to read
4977
+ // the current value.
4978
+ //
4979
+ // Because we don't actually use the state returned by the useState hook, we
4980
+ // can save a bit of memory by storing other stuff in that slot.
4981
+ //
4982
+ // To implement the early bailout, we need to track some things on a mutable
4983
+ // object. Usually, we would put that in a useRef hook, but we can stash it in
4984
+ // our useState hook instead.
4985
+ //
4986
+ // To force a re-render, we call forceUpdate({inst}). That works because the
4987
+ // new object always fails an equality check.
4988
+
4989
+
4990
+ var _useState = useState({
4991
+ inst: {
4992
+ value: value,
4993
+ getSnapshot: getSnapshot
4994
+ }
4995
+ }),
4996
+ inst = _useState[0].inst,
4997
+ forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
4998
+ // in the layout phase so we can access it during the tearing check that
4999
+ // happens on subscribe.
5000
+
5001
+
5002
+ useLayoutEffect(function () {
5003
+ inst.value = value;
5004
+ inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
5005
+ // commit phase if there was an interleaved mutation. In concurrent mode
5006
+ // this can happen all the time, but even in synchronous mode, an earlier
5007
+ // effect may have mutated the store.
5008
+
5009
+ if (checkIfSnapshotChanged(inst)) {
5010
+ // Force a re-render.
5011
+ forceUpdate({
5012
+ inst: inst
5013
+ });
5014
+ }
5015
+ }, [subscribe, value, getSnapshot]);
5016
+ useEffect(function () {
5017
+ // Check for changes right before subscribing. Subsequent changes will be
5018
+ // detected in the subscription handler.
5019
+ if (checkIfSnapshotChanged(inst)) {
5020
+ // Force a re-render.
5021
+ forceUpdate({
5022
+ inst: inst
5023
+ });
5024
+ }
5025
+
5026
+ var handleStoreChange = function () {
5027
+ // TODO: Because there is no cross-renderer API for batching updates, it's
5028
+ // up to the consumer of this library to wrap their subscription event
5029
+ // with unstable_batchedUpdates. Should we try to detect when this isn't
5030
+ // the case and print a warning in development?
5031
+ // The store changed. Check if the snapshot changed since the last time we
5032
+ // read from the store.
5033
+ if (checkIfSnapshotChanged(inst)) {
5034
+ // Force a re-render.
5035
+ forceUpdate({
5036
+ inst: inst
5037
+ });
5038
+ }
5039
+ }; // Subscribe to the store and return a clean-up function.
5040
+
5041
+
5042
+ return subscribe(handleStoreChange);
5043
+ }, [subscribe]);
5044
+ useDebugValue(value);
5045
+ return value;
5046
+ }
5047
+
5048
+ function checkIfSnapshotChanged(inst) {
5049
+ var latestGetSnapshot = inst.getSnapshot;
5050
+ var prevValue = inst.value;
5051
+
5052
+ try {
5053
+ var nextValue = latestGetSnapshot();
5054
+ return !objectIs(prevValue, nextValue);
5055
+ } catch (error) {
5056
+ return true;
5057
+ }
5058
+ }
5059
+
5060
+ function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
5061
+ // Note: The shim does not use getServerSnapshot, because pre-18 versions of
5062
+ // React do not expose a way to check if we're hydrating. So users of the shim
5063
+ // will need to track that themselves and return the correct value
5064
+ // from `getSnapshot`.
5065
+ return getSnapshot();
5066
+ }
5067
+
5068
+ var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
5069
+
5070
+ var isServerEnvironment = !canUseDOM;
5071
+
5072
+ var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
5073
+ var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
5074
+
5075
+ useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
5076
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
5077
+ if (
5078
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
5079
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
5080
+ 'function'
5081
+ ) {
5082
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
5083
+ }
5084
+
5085
+ })();
5086
+ }
5087
+ return useSyncExternalStoreShim_development;
5088
+ }
5089
+
5090
+ (function (module) {
5091
+
5092
+ if (process.env.NODE_ENV === 'production') {
5093
+ module.exports = requireUseSyncExternalStoreShim_production_min();
5094
+ } else {
5095
+ module.exports = requireUseSyncExternalStoreShim_development();
5096
+ }
5097
+ } (shim));
5098
+
5099
+ const subscribe$1 = (callback) => {
5100
+ window.addEventListener("resize", callback);
5101
+ return () => {
5102
+ window.removeEventListener("resize", callback);
5103
+ };
5104
+ };
4820
5105
  function useWindowSize() {
4821
- const [windowSize, setWindowSize] = useState({
5106
+ const stateDependencies = useRef({}).current;
5107
+ const previous = useRef({
4822
5108
  width: 0,
4823
5109
  height: 0
4824
5110
  });
4825
- const handleSize = () => {
4826
- setWindowSize({
4827
- width: window.innerWidth,
4828
- height: window.innerHeight
4829
- });
5111
+ const isEqual = (prev, current) => {
5112
+ for (const _ in stateDependencies) {
5113
+ const t = _;
5114
+ if (current[t] !== prev[t]) {
5115
+ return false;
5116
+ }
5117
+ }
5118
+ return true;
5119
+ };
5120
+ const cached = shim.exports.useSyncExternalStore(
5121
+ subscribe$1,
5122
+ () => {
5123
+ const data = {
5124
+ width: window.innerWidth,
5125
+ height: window.innerHeight
5126
+ };
5127
+ if (!isEqual(previous.current, data)) {
5128
+ previous.current = data;
5129
+ return data;
5130
+ }
5131
+ return previous.current;
5132
+ },
5133
+ () => {
5134
+ return previous.current;
5135
+ }
5136
+ );
5137
+ return {
5138
+ get width() {
5139
+ stateDependencies.width = true;
5140
+ return cached.width;
5141
+ },
5142
+ get height() {
5143
+ stateDependencies.height = true;
5144
+ return cached.height;
5145
+ }
4830
5146
  };
4831
- useEventListener("resize", handleSize);
4832
- useIsomorphicLayoutEffect(() => {
4833
- handleSize();
4834
- }, []);
4835
- return windowSize;
4836
5147
  }
4837
5148
 
4838
5149
  const listenerOptions$1 = {
@@ -5807,7 +6118,7 @@ function subscribe(callback) {
5807
6118
  };
5808
6119
  }
5809
6120
  function useLocationSelector(selector, fallback) {
5810
- return useSyncExternalStore(
6121
+ return shim.exports.useSyncExternalStore(
5811
6122
  subscribe,
5812
6123
  () => selector(location),
5813
6124
  () => fallback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "4.0.10",
3
+ "version": "4.0.11",
4
4
  "license": "Unlicense",
5
5
  "homepage": "https://www.reactuse.com/",
6
6
  "repository": {
@@ -23,7 +23,6 @@
23
23
  "exports": {
24
24
  "./package.json": "./package.json",
25
25
  ".": {
26
- "types": "./dist/index.d.ts",
27
26
  "import": "./dist/index.mjs",
28
27
  "require": "./dist/index.cjs"
29
28
  }
@@ -54,7 +53,8 @@
54
53
  "dependencies": {
55
54
  "js-cookie": "^3.0.5",
56
55
  "lodash-es": "^4.17.21",
57
- "screenfull": "^5.0.0"
56
+ "screenfull": "^5.0.0",
57
+ "use-sync-external-store": "^1.2.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@jsdevtools/version-bump-prompt": "^6.1.0",
@@ -67,6 +67,7 @@
67
67
  "@types/js-cookie": "^3.0.3",
68
68
  "@types/lodash": "^4.14.184",
69
69
  "@types/lodash-es": "^4.17.7",
70
+ "@types/use-sync-external-store": "^0.0.6",
70
71
  "babel-jest": "^29.0.2",
71
72
  "consola": "^2.15.3",
72
73
  "esbuild": "^0.17.15",