|
@@ -4,16 +4,23 @@ import Icon from '../../../../shared/components/icon'
|
|
|
import { useCallback } from 'react'
|
|
import { useCallback } from 'react'
|
|
|
import { FigureModalSource } from '../figure-modal/figure-modal-context'
|
|
import { FigureModalSource } from '../figure-modal/figure-modal-context'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
+import { emitCommandEvent } from '../../extensions/toolbar/utils/analytics'
|
|
|
|
|
+import { useCodeMirrorViewContext } from '../codemirror-editor'
|
|
|
|
|
|
|
|
export const InsertFigureDropdown = () => {
|
|
export const InsertFigureDropdown = () => {
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
- const openFigureModal = useCallback((source: FigureModalSource) => {
|
|
|
|
|
- window.dispatchEvent(
|
|
|
|
|
- new CustomEvent('figure-modal:open', {
|
|
|
|
|
- detail: source,
|
|
|
|
|
- })
|
|
|
|
|
- )
|
|
|
|
|
- }, [])
|
|
|
|
|
|
|
+ const view = useCodeMirrorViewContext()
|
|
|
|
|
+ const openFigureModal = useCallback(
|
|
|
|
|
+ (source: FigureModalSource, sourceName: string) => {
|
|
|
|
|
+ emitCommandEvent(view, `toolbar-figure-modal-${sourceName}`)
|
|
|
|
|
+ window.dispatchEvent(
|
|
|
|
|
+ new CustomEvent('figure-modal:open', {
|
|
|
|
|
+ detail: source,
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
|
|
+ },
|
|
|
|
|
+ [view]
|
|
|
|
|
+ )
|
|
|
return (
|
|
return (
|
|
|
<ToolbarButtonMenu
|
|
<ToolbarButtonMenu
|
|
|
id="toolbar-figure"
|
|
id="toolbar-figure"
|
|
@@ -21,22 +28,28 @@ export const InsertFigureDropdown = () => {
|
|
|
icon="picture-o"
|
|
icon="picture-o"
|
|
|
>
|
|
>
|
|
|
<ListGroupItem
|
|
<ListGroupItem
|
|
|
- onClick={() => openFigureModal(FigureModalSource.FILE_UPLOAD)}
|
|
|
|
|
|
|
+ onClick={() =>
|
|
|
|
|
+ openFigureModal(FigureModalSource.FILE_UPLOAD, 'file-upload')
|
|
|
|
|
+ }
|
|
|
>
|
|
>
|
|
|
<Icon type="upload" fw /> Upload from computer
|
|
<Icon type="upload" fw /> Upload from computer
|
|
|
</ListGroupItem>
|
|
</ListGroupItem>
|
|
|
<ListGroupItem
|
|
<ListGroupItem
|
|
|
- onClick={() => openFigureModal(FigureModalSource.FILE_TREE)}
|
|
|
|
|
|
|
+ onClick={() =>
|
|
|
|
|
+ openFigureModal(FigureModalSource.FILE_TREE, 'current-project')
|
|
|
|
|
+ }
|
|
|
>
|
|
>
|
|
|
<Icon type="archive" fw /> From project files
|
|
<Icon type="archive" fw /> From project files
|
|
|
</ListGroupItem>
|
|
</ListGroupItem>
|
|
|
<ListGroupItem
|
|
<ListGroupItem
|
|
|
- onClick={() => openFigureModal(FigureModalSource.OTHER_PROJECT)}
|
|
|
|
|
|
|
+ onClick={() =>
|
|
|
|
|
+ openFigureModal(FigureModalSource.OTHER_PROJECT, 'other-project')
|
|
|
|
|
+ }
|
|
|
>
|
|
>
|
|
|
<Icon type="folder-open" fw /> From another project
|
|
<Icon type="folder-open" fw /> From another project
|
|
|
</ListGroupItem>
|
|
</ListGroupItem>
|
|
|
<ListGroupItem
|
|
<ListGroupItem
|
|
|
- onClick={() => openFigureModal(FigureModalSource.FROM_URL)}
|
|
|
|
|
|
|
+ onClick={() => openFigureModal(FigureModalSource.FROM_URL, 'from-url')}
|
|
|
>
|
|
>
|
|
|
<Icon type="globe" fw /> From URL
|
|
<Icon type="globe" fw /> From URL
|
|
|
</ListGroupItem>
|
|
</ListGroupItem>
|