Server IP : 104.21.14.103 / Your IP : 3.138.37.174 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/thread-self/root/home/giankuin/thietke365.net/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/context/providers/ |
Upload File : |
/** * External dependencies */ import { createContext, useContext, useCallback } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; interface EditorContextType { // Indicates whether in the editor context. isEditor: boolean; // The post ID being edited. currentPostId: number; // The current view name, if using a view switcher. currentView: string; // Object containing preview data for the editor. previewData: Record< string, unknown >; // Get data by name. getPreviewData: ( name: string ) => Record< string, unknown >; // Indicates whether in the preview context. isPreview?: boolean; } const EditorContext = createContext( { isEditor: false, currentPostId: 0, currentView: '', previewData: {}, getPreviewData: () => ( {} ), } as EditorContextType ); export const useEditorContext = (): EditorContextType => { return useContext( EditorContext ); }; export const EditorProvider = ( { children, currentPostId = 0, previewData = {}, currentView = '', isPreview = false, }: { children: React.ReactChildren; currentPostId?: number | undefined; previewData?: Record< string, unknown > | undefined; currentView?: string | undefined; isPreview?: boolean | undefined; } ) => { const editingPostId = useSelect( ( select ): number => currentPostId ? currentPostId : select( 'core/editor' ).getCurrentPostId(), [ currentPostId ] ); const getPreviewData = useCallback( ( name: string ): Record< string, unknown > => { if ( previewData && name in previewData ) { return previewData[ name ] as Record< string, unknown >; } return {}; }, [ previewData ] ); const editorData: EditorContextType = { isEditor: true, currentPostId: editingPostId, currentView, previewData, getPreviewData, isPreview, }; return ( <EditorContext.Provider value={ editorData }> { children } </EditorContext.Provider> ); };