PlaygroundContext.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { createContext, useContext } from 'react';
  16. /**
  17. * Context for Playground component to share image handling functionality
  18. */
  19. const PlaygroundContext = createContext(null);
  20. /**
  21. * Hook to access Playground context
  22. * @returns {Object} Context value with onPasteImage, imageUrls, and imageEnabled
  23. */
  24. export const usePlayground = () => {
  25. const context = useContext(PlaygroundContext);
  26. if (!context) {
  27. return {
  28. onPasteImage: () => {
  29. console.warn('PlaygroundContext not provided');
  30. },
  31. imageUrls: [],
  32. imageEnabled: false,
  33. };
  34. }
  35. return context;
  36. };
  37. /**
  38. * Provider component for Playground context
  39. * @param {Object} props - Component props
  40. * @param {React.ReactNode} props.children - Child components
  41. * @param {Object} props.value - Context value to provide
  42. * @returns {JSX.Element} Provider component
  43. */
  44. export const PlaygroundProvider = ({ children, value }) => {
  45. return (
  46. <PlaygroundContext.Provider value={value}>
  47. {children}
  48. </PlaygroundContext.Provider>
  49. );
  50. };
  51. export default PlaygroundContext;