UNPKG

2.7 kBJavaScriptView Raw
1import {PressResponderContext as $ae1eeba8b9eafd08$export$5165eccb35aaadb5} from "./context.module.js";
2import {useObjectRef as $87RPk$useObjectRef, mergeProps as $87RPk$mergeProps, useSyncRef as $87RPk$useSyncRef} from "@react-aria/utils";
3import $87RPk$react, {useRef as $87RPk$useRef, useContext as $87RPk$useContext, useEffect as $87RPk$useEffect, useMemo as $87RPk$useMemo} from "react";
4
5/*
6 * Copyright 2020 Adobe. All rights reserved.
7 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License. You may obtain a copy
9 * of the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software distributed under
12 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13 * OF ANY KIND, either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16
17
18const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ (0, $87RPk$react).forwardRef(({ children: children, ...props }, ref)=>{
19 let isRegistered = (0, $87RPk$useRef)(false);
20 let prevContext = (0, $87RPk$useContext)((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5));
21 ref = (0, $87RPk$useObjectRef)(ref || (prevContext === null || prevContext === void 0 ? void 0 : prevContext.ref));
22 let context = (0, $87RPk$mergeProps)(prevContext || {}, {
23 ...props,
24 ref: ref,
25 register () {
26 isRegistered.current = true;
27 if (prevContext) prevContext.register();
28 }
29 });
30 (0, $87RPk$useSyncRef)(prevContext, ref);
31 (0, $87RPk$useEffect)(()=>{
32 if (!isRegistered.current) {
33 console.warn("A PressResponder was rendered without a pressable child. Either call the usePress hook, or wrap your DOM node with <Pressable> component.");
34 isRegistered.current = true; // only warn once in strict mode.
35 }
36 }, []);
37 return /*#__PURE__*/ (0, $87RPk$react).createElement((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5).Provider, {
38 value: context
39 }, children);
40});
41function $f1ab8c75478c6f73$export$cf75428e0b9ed1ea({ children: children }) {
42 let context = (0, $87RPk$useMemo)(()=>({
43 register: ()=>{}
44 }), []);
45 return /*#__PURE__*/ (0, $87RPk$react).createElement((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5).Provider, {
46 value: context
47 }, children);
48}
49
50
51export {$f1ab8c75478c6f73$export$3351871ee4b288b8 as PressResponder, $f1ab8c75478c6f73$export$cf75428e0b9ed1ea as ClearPressResponder};
52//# sourceMappingURL=PressResponder.module.js.map