Skip to main content
Glama
useEditor.ts1.75 kB
import { MessageKey } from '@intlayer/editor'; import { onDestroy } from 'svelte'; import { get } from 'svelte/store'; import { useDictionariesRecord } from './dictionariesRecord'; import { useEditorEnabled } from './editorEnabled'; import { useCrossFrameMessageListener } from './useCrossFrameMessageListener'; import { useIframeClickMerger } from './useIframeClickInterceptor'; let initialized = false; let unsubscribeIsInIframe: (() => void) | null = null; export const useEditor = () => { if (typeof window === 'undefined') return; if (initialized) return; initialized = true; const editorEnabled = useEditorEnabled(); useDictionariesRecord(); useIframeClickMerger(); // Listen for editor enabled useCrossFrameMessageListener<boolean>( `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`, (data) => { editorEnabled.wrapperEnabled.set(data); }, false ); const getEditorEnabled = useCrossFrameMessageListener<boolean>( `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`, (data) => { editorEnabled.wrapperEnabled.set(data); }, false ); // Initial check const checkEnabled = () => { const inIframe = get(editorEnabled.isInIframe); const setting = get(editorEnabled.settingEnabled); if (inIframe && setting) { getEditorEnabled(); } }; checkEnabled(); // Subscribe to changes editorEnabled.isInIframe.subscribe(() => checkEnabled()); // Keep track of unsubscribe so we *could* clean up if we ever wanted unsubscribeIsInIframe = editorEnabled.isInIframe.subscribe(() => checkEnabled() ); onDestroy(() => { initialized = false; if (unsubscribeIsInIframe) { unsubscribeIsInIframe(); unsubscribeIsInIframe = null; } }); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server