( props: EmailEditorProps<TDisplayMode>, ref: React.Ref<EditorRef<TDisplayMode>>, )
| 14 | win.__unlayer_lastEditorId = win.__unlayer_lastEditorId || 0; |
| 15 | |
| 16 | function EmailEditorInner<TDisplayMode extends DisplayMode | undefined = 'email'>( |
| 17 | props: EmailEditorProps<TDisplayMode>, |
| 18 | ref: React.Ref<EditorRef<TDisplayMode>>, |
| 19 | ) { |
| 20 | const { onLoad, onReady, scriptUrl, minHeight = 500, style = {} } = props; |
| 21 | |
| 22 | const [editor, setEditor] = useState<UnlayerEditor<TDisplayMode> | null>(null); |
| 23 | |
| 24 | const [hasLoadedEmbedScript, setHasLoadedEmbedScript] = useState(false); |
| 25 | |
| 26 | const editorId = useMemo( |
| 27 | () => props.editorId || `editor-${++win.__unlayer_lastEditorId}`, |
| 28 | [props.editorId] |
| 29 | ); |
| 30 | |
| 31 | const options = { |
| 32 | ...(props.options || {}), |
| 33 | appearance: props.appearance ?? props.options?.appearance, |
| 34 | displayMode: props?.displayMode || props.options?.displayMode || 'email' as const, |
| 35 | locale: props.locale ?? props.options?.locale, |
| 36 | projectId: props.projectId ?? props.options?.projectId, |
| 37 | tools: props.tools ?? props.options?.tools, |
| 38 | |
| 39 | id: editorId, |
| 40 | source: { |
| 41 | name: pkg.name, |
| 42 | version: pkg.version, |
| 43 | }, |
| 44 | }; |
| 45 | |
| 46 | useImperativeHandle( |
| 47 | ref, |
| 48 | () => ({ |
| 49 | editor, |
| 50 | }), |
| 51 | [editor] |
| 52 | ); |
| 53 | |
| 54 | useEffect(() => { |
| 55 | return () => { |
| 56 | editor?.destroy(); |
| 57 | }; |
| 58 | }, []); |
| 59 | |
| 60 | useEffect(() => { |
| 61 | setHasLoadedEmbedScript(false); |
| 62 | loadScript(() => setHasLoadedEmbedScript(true), scriptUrl); |
| 63 | }, [scriptUrl]); |
| 64 | |
| 65 | useEffect(() => { |
| 66 | if (!hasLoadedEmbedScript) return; |
| 67 | editor?.destroy(); |
| 68 | setEditor(unlayer.createEditor(options)); |
| 69 | }, [JSON.stringify(options), hasLoadedEmbedScript]); |
| 70 | |
| 71 | const methodProps = Object.keys(props).filter((propName) => |
| 72 | /^on/.test(propName) |
| 73 | ); |
nothing calls this directly
no test coverage detected