fix: super improvements (#1995)
* feat(super): autolink selection with cmd + k * feat: super note importer * feat: handle html import * fix: ignore load change event emitted by on change plugin
This commit is contained in:
@@ -36,7 +36,7 @@ const BlockDragEnabled = false;
|
|||||||
type BlocksEditorProps = {
|
type BlocksEditorProps = {
|
||||||
onChange: (value: string, preview: string) => void;
|
onChange: (value: string, preview: string) => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
children: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
previewLength: number;
|
previewLength: number;
|
||||||
spellcheck?: boolean;
|
spellcheck?: boolean;
|
||||||
};
|
};
|
||||||
@@ -48,8 +48,14 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
|
|||||||
previewLength,
|
previewLength,
|
||||||
spellcheck,
|
spellcheck,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [didIgnoreFirstChange, setDidIgnoreFirstChange] = useState(false);
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
(editorState: EditorState, _editor: LexicalEditor) => {
|
(editorState: EditorState, _editor: LexicalEditor) => {
|
||||||
|
if (!didIgnoreFirstChange) {
|
||||||
|
setDidIgnoreFirstChange(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
editorState.read(() => {
|
editorState.read(() => {
|
||||||
const childrenNodes = $getRoot().getAllTextNodes().slice(0, 2);
|
const childrenNodes = $getRoot().getAllTextNodes().slice(0, 2);
|
||||||
let previewText = '';
|
let previewText = '';
|
||||||
@@ -65,7 +71,7 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
|
|||||||
onChange(stringifiedEditorState, previewText);
|
onChange(stringifiedEditorState, previewText);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[onChange],
|
[onChange, didIgnoreFirstChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const [floatingAnchorElem, setFloatingAnchorElem] =
|
const [floatingAnchorElem, setFloatingAnchorElem] =
|
||||||
|
|||||||
@@ -7,17 +7,19 @@ import {Klass, LexicalNode} from 'lexical';
|
|||||||
type BlocksEditorComposerProps = {
|
type BlocksEditorComposerProps = {
|
||||||
initialValue: string;
|
initialValue: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
nodes: Array<Klass<LexicalNode>>;
|
nodes?: Array<Klass<LexicalNode>>;
|
||||||
|
readonly?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const BlocksEditorComposer: FunctionComponent<
|
export const BlocksEditorComposer: FunctionComponent<
|
||||||
BlocksEditorComposerProps
|
BlocksEditorComposerProps
|
||||||
> = ({initialValue, children, nodes}) => {
|
> = ({initialValue, children, readonly, nodes = []}) => {
|
||||||
return (
|
return (
|
||||||
<LexicalComposer
|
<LexicalComposer
|
||||||
initialConfig={{
|
initialConfig={{
|
||||||
namespace: 'BlocksEditor',
|
namespace: 'BlocksEditor',
|
||||||
theme: BlocksEditorTheme,
|
theme: BlocksEditorTheme,
|
||||||
|
editable: !readonly,
|
||||||
onError: (error: Error) => console.error(error),
|
onError: (error: Error) => console.error(error),
|
||||||
editorState:
|
editorState:
|
||||||
initialValue && initialValue.length > 0 ? initialValue : undefined,
|
initialValue && initialValue.length > 0 ? initialValue : undefined,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { NodeObserverPlugin } from './Plugins/NodeObserverPlugin/NodeObserverPlu
|
|||||||
import { FilesController } from '@/Controllers/FilesController'
|
import { FilesController } from '@/Controllers/FilesController'
|
||||||
import FilesControllerProvider from '@/Controllers/FilesControllerProvider'
|
import FilesControllerProvider from '@/Controllers/FilesControllerProvider'
|
||||||
import DatetimePlugin from './Plugins/DateTimePlugin/DateTimePlugin'
|
import DatetimePlugin from './Plugins/DateTimePlugin/DateTimePlugin'
|
||||||
|
import AutoLinkPlugin from './Plugins/AutoLinkPlugin/AutoLinkPlugin'
|
||||||
|
|
||||||
const NotePreviewCharLimit = 160
|
const NotePreviewCharLimit = 160
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ export const BlockEditor: FunctionComponent<Props> = ({
|
|||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<LinkingControllerProvider controller={linkingController}>
|
<LinkingControllerProvider controller={linkingController}>
|
||||||
<FilesControllerProvider controller={filesController}>
|
<FilesControllerProvider controller={filesController}>
|
||||||
<BlocksEditorComposer initialValue={note.text} nodes={[FileNode, BubbleNode]}>
|
<BlocksEditorComposer readonly={note.locked} initialValue={note.text} nodes={[FileNode, BubbleNode]}>
|
||||||
<BlocksEditor
|
<BlocksEditor
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
className="relative relative resize-none text-base focus:shadow-none focus:outline-none"
|
className="relative relative resize-none text-base focus:shadow-none focus:outline-none"
|
||||||
@@ -70,6 +71,7 @@ export const BlockEditor: FunctionComponent<Props> = ({
|
|||||||
<ItemBubblePlugin />
|
<ItemBubblePlugin />
|
||||||
<BlockPickerMenuPlugin />
|
<BlockPickerMenuPlugin />
|
||||||
<DatetimePlugin />
|
<DatetimePlugin />
|
||||||
|
<AutoLinkPlugin />
|
||||||
<NodeObserverPlugin nodeType={BubbleNode} onRemove={handleBubbleRemove} />
|
<NodeObserverPlugin nodeType={BubbleNode} onRemove={handleBubbleRemove} />
|
||||||
<NodeObserverPlugin nodeType={FileNode} onRemove={handleBubbleRemove} />
|
<NodeObserverPlugin nodeType={FileNode} onRemove={handleBubbleRemove} />
|
||||||
</BlocksEditor>
|
</BlocksEditor>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
||||||
|
import { COMMAND_PRIORITY_EDITOR, KEY_MODIFIER_COMMAND, $getSelection } from 'lexical'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { TOGGLE_LINK_COMMAND } from '@lexical/link'
|
||||||
|
import { mergeRegister } from '@lexical/utils'
|
||||||
|
|
||||||
|
export default function AutoLinkPlugin(): JSX.Element | null {
|
||||||
|
const [editor] = useLexicalComposerContext()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return mergeRegister(
|
||||||
|
editor.registerCommand(
|
||||||
|
KEY_MODIFIER_COMMAND,
|
||||||
|
(event: KeyboardEvent) => {
|
||||||
|
const isCmdK = event.key === 'k' && !event.altKey && (event.metaKey || event.ctrlKey)
|
||||||
|
if (isCmdK) {
|
||||||
|
const selection = $getSelection()
|
||||||
|
if (selection) {
|
||||||
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, selection.getTextContent())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
COMMAND_PRIORITY_EDITOR,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}, [editor])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { $convertFromMarkdownString, TRANSFORMERS } from '@lexical/markdown'
|
||||||
|
import { $generateNodesFromDOM } from '@lexical/html'
|
||||||
|
import { $createParagraphNode, $createRangeSelection } from 'lexical'
|
||||||
|
|
||||||
|
/** Note that markdown conversion does not insert new lines. See: https://github.com/facebook/lexical/issues/2815 */
|
||||||
|
export default function ImportPlugin({ text, format }: { text: string; format: 'md' | 'html' }): JSX.Element | null {
|
||||||
|
const [editor] = useLexicalComposerContext()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
editor.update(() => {
|
||||||
|
if (format === 'md') {
|
||||||
|
$convertFromMarkdownString(text, [...TRANSFORMERS])
|
||||||
|
} else {
|
||||||
|
const parser = new DOMParser()
|
||||||
|
const dom = parser.parseFromString(text, 'text/html')
|
||||||
|
const nodes = $generateNodesFromDOM(editor, dom)
|
||||||
|
const selection = $createRangeSelection()
|
||||||
|
const newLineNode = $createParagraphNode()
|
||||||
|
selection.insertNodes([newLineNode, ...nodes])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, [editor, text, format])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { WebApplication } from '@/Application/Application'
|
||||||
|
import { NoteType, SNNote } from '@standardnotes/snjs'
|
||||||
|
import { FunctionComponent, useCallback, useState } from 'react'
|
||||||
|
import { BlockEditorController } from './BlockEditorController'
|
||||||
|
import { BlocksEditor, BlocksEditorComposer } from '@standardnotes/blocks-editor'
|
||||||
|
import { ErrorBoundary } from '@/Utils/ErrorBoundary'
|
||||||
|
import ModalDialog from '@/Components/Shared/ModalDialog'
|
||||||
|
import ModalDialogButtons from '@/Components/Shared/ModalDialogButtons'
|
||||||
|
import ModalDialogDescription from '@/Components/Shared/ModalDialogDescription'
|
||||||
|
import ModalDialogLabel from '@/Components/Shared/ModalDialogLabel'
|
||||||
|
import Button from '@/Components/Button/Button'
|
||||||
|
import ImportPlugin from './Plugins/ImportPlugin/ImportPlugin'
|
||||||
|
|
||||||
|
export function spaceSeparatedStrings(...strings: string[]): string {
|
||||||
|
return strings.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
const NotePreviewCharLimit = 160
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
application: WebApplication
|
||||||
|
note: SNNote
|
||||||
|
closeDialog: () => void
|
||||||
|
onConvertComplete: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application, closeDialog, onConvertComplete }) => {
|
||||||
|
const [lastValue, setLastValue] = useState({ text: '', previewPlain: '' })
|
||||||
|
|
||||||
|
const format =
|
||||||
|
!note.noteType || [NoteType.Plain, NoteType.Markdown, NoteType.Code, NoteType.Task].includes(note.noteType)
|
||||||
|
? 'md'
|
||||||
|
: 'html'
|
||||||
|
|
||||||
|
const handleChange = useCallback((value: string, preview: string) => {
|
||||||
|
setLastValue({ text: value, previewPlain: preview })
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const confirmConvert = useCallback(() => {
|
||||||
|
const controller = new BlockEditorController(note, application)
|
||||||
|
void controller.save({ text: lastValue.text, previewPlain: lastValue.previewPlain, previewHtml: undefined })
|
||||||
|
closeDialog()
|
||||||
|
onConvertComplete()
|
||||||
|
}, [closeDialog, application, lastValue, note, onConvertComplete])
|
||||||
|
|
||||||
|
const convertAsIs = useCallback(async () => {
|
||||||
|
const confirmed = await application.alertService.confirm(
|
||||||
|
spaceSeparatedStrings(
|
||||||
|
"This option is useful if you switched this note's type from Super to another plaintext-based format, and want to return to Super.",
|
||||||
|
'To use this option, the preview in the convert window should display a language format known as JSON.',
|
||||||
|
'If this is not the case, cancel this prompt.',
|
||||||
|
),
|
||||||
|
'Are you sure?',
|
||||||
|
)
|
||||||
|
if (!confirmed) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const controller = new BlockEditorController(note, application)
|
||||||
|
void controller.save({ text: note.text, previewPlain: note.preview_plain, previewHtml: undefined })
|
||||||
|
closeDialog()
|
||||||
|
onConvertComplete()
|
||||||
|
}, [closeDialog, application, note, onConvertComplete])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ModalDialog>
|
||||||
|
<ModalDialogLabel closeDialog={closeDialog}>
|
||||||
|
Convert to Super note
|
||||||
|
<p className="text-sm font-normal text-neutral">
|
||||||
|
The following is a preview of how your note will look when converted to Super. Super notes use a custom format
|
||||||
|
under the hood. Converting your note will transition it from plaintext to the custom Super format.
|
||||||
|
</p>
|
||||||
|
</ModalDialogLabel>
|
||||||
|
<ModalDialogDescription>
|
||||||
|
<div className="relative w-full">
|
||||||
|
<ErrorBoundary>
|
||||||
|
<BlocksEditorComposer readonly initialValue={''}>
|
||||||
|
<BlocksEditor
|
||||||
|
onChange={handleChange}
|
||||||
|
className="relative relative resize-none text-base focus:shadow-none focus:outline-none"
|
||||||
|
previewLength={NotePreviewCharLimit}
|
||||||
|
spellcheck={note.spellcheck}
|
||||||
|
>
|
||||||
|
<ImportPlugin text={note.text} format={format} />
|
||||||
|
</BlocksEditor>
|
||||||
|
</BlocksEditorComposer>
|
||||||
|
</ErrorBoundary>
|
||||||
|
</div>
|
||||||
|
</ModalDialogDescription>
|
||||||
|
<ModalDialogButtons>
|
||||||
|
<div className="flex w-full justify-between">
|
||||||
|
<div>
|
||||||
|
<Button onClick={convertAsIs}>Convert As-Is</Button>
|
||||||
|
</div>
|
||||||
|
<div className="flex">
|
||||||
|
<Button onClick={closeDialog}>Cancel</Button>
|
||||||
|
<div className="min-w-3" />
|
||||||
|
<Button primary onClick={confirmConvert}>
|
||||||
|
Convert to Super
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ModalDialogButtons>
|
||||||
|
</ModalDialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ const ChangeEditorButton: FunctionComponent<Props> = ({
|
|||||||
return note ? application.componentManager.editorForNote(note) : undefined
|
return note ? application.componentManager.editorForNote(note) : undefined
|
||||||
})
|
})
|
||||||
const [selectedEditorIcon, selectedEditorIconTint] = getIconAndTintForNoteType(selectedEditor?.package_info.note_type)
|
const [selectedEditorIcon, selectedEditorIconTint] = getIconAndTintForNoteType(selectedEditor?.package_info.note_type)
|
||||||
|
const [isClickOutsideDisabled, setIsClickOutsideDisabled] = useState(false)
|
||||||
|
|
||||||
const toggleMenu = useCallback(async () => {
|
const toggleMenu = useCallback(async () => {
|
||||||
const willMenuOpen = !isOpen
|
const willMenuOpen = !isOpen
|
||||||
@@ -35,6 +36,10 @@ const ChangeEditorButton: FunctionComponent<Props> = ({
|
|||||||
setIsOpen(willMenuOpen)
|
setIsOpen(willMenuOpen)
|
||||||
}, [onClickPreprocessing, isOpen])
|
}, [onClickPreprocessing, isOpen])
|
||||||
|
|
||||||
|
const disableClickOutside = useCallback(() => {
|
||||||
|
setIsClickOutsideDisabled(true)
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef}>
|
<div ref={containerRef}>
|
||||||
<RoundIconButton
|
<RoundIconButton
|
||||||
@@ -44,11 +49,18 @@ const ChangeEditorButton: FunctionComponent<Props> = ({
|
|||||||
icon={selectedEditorIcon}
|
icon={selectedEditorIcon}
|
||||||
iconClassName={`text-accessory-tint-${selectedEditorIconTint}`}
|
iconClassName={`text-accessory-tint-${selectedEditorIconTint}`}
|
||||||
/>
|
/>
|
||||||
<Popover togglePopover={toggleMenu} anchorElement={buttonRef.current} open={isOpen} className="pt-2 md:pt-0">
|
<Popover
|
||||||
|
togglePopover={toggleMenu}
|
||||||
|
disableClickOutside={isClickOutsideDisabled}
|
||||||
|
anchorElement={buttonRef.current}
|
||||||
|
open={isOpen}
|
||||||
|
className="pt-2 md:pt-0"
|
||||||
|
>
|
||||||
<ChangeEditorMenu
|
<ChangeEditorMenu
|
||||||
application={application}
|
application={application}
|
||||||
isVisible={isOpen}
|
isVisible={isOpen}
|
||||||
note={note}
|
note={note}
|
||||||
|
handleDisableClickoutsideRequest={disableClickOutside}
|
||||||
closeMenu={() => {
|
closeMenu={() => {
|
||||||
setIsOpen(false)
|
setIsOpen(false)
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import { MenuItemType } from '@/Components/Menu/MenuItemType'
|
|||||||
import { usePremiumModal } from '@/Hooks/usePremiumModal'
|
import { usePremiumModal } from '@/Hooks/usePremiumModal'
|
||||||
import { STRING_EDIT_LOCKED_ATTEMPT } from '@/Constants/Strings'
|
import { STRING_EDIT_LOCKED_ATTEMPT } from '@/Constants/Strings'
|
||||||
import { WebApplication } from '@/Application/Application'
|
import { WebApplication } from '@/Application/Application'
|
||||||
import { ComponentArea, NoteMutator, PrefKey, SNComponent, SNNote } from '@standardnotes/snjs'
|
import { ComponentArea, NoteMutator, NoteType, PrefKey, SNComponent, SNNote } from '@standardnotes/snjs'
|
||||||
import { Fragment, FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react'
|
import { Fragment, FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { EditorMenuGroup } from '@/Components/NotesOptions/EditorMenuGroup'
|
import { EditorMenuGroup } from '@/Components/NotesOptions/EditorMenuGroup'
|
||||||
import { EditorMenuItem } from '@/Components/NotesOptions/EditorMenuItem'
|
import { EditorMenuItem } from '@/Components/NotesOptions/EditorMenuItem'
|
||||||
import { createEditorMenuGroups } from '../../Utils/createEditorMenuGroups'
|
import { createEditorMenuGroups } from '../../Utils/createEditorMenuGroups'
|
||||||
import { reloadFont } from '../NoteView/FontFunctions'
|
import { reloadFont } from '../NoteView/FontFunctions'
|
||||||
import { PremiumFeatureIconClass, PremiumFeatureIconName } from '../Icon/PremiumFeatureIcon'
|
import { PremiumFeatureIconClass, PremiumFeatureIconName } from '../Icon/PremiumFeatureIcon'
|
||||||
|
import { SuperNoteImporter } from '../BlockEditor/SuperNoteImporter'
|
||||||
|
|
||||||
type ChangeEditorMenuProps = {
|
type ChangeEditorMenuProps = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -19,6 +20,7 @@ type ChangeEditorMenuProps = {
|
|||||||
isVisible: boolean
|
isVisible: boolean
|
||||||
note: SNNote | undefined
|
note: SNNote | undefined
|
||||||
onSelect?: (component: SNComponent | undefined) => void
|
onSelect?: (component: SNComponent | undefined) => void
|
||||||
|
handleDisableClickoutsideRequest?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const getGroupId = (group: EditorMenuGroup) => group.title.toLowerCase().replace(/\s/, '-')
|
const getGroupId = (group: EditorMenuGroup) => group.title.toLowerCase().replace(/\s/, '-')
|
||||||
@@ -29,6 +31,7 @@ const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
|
|||||||
isVisible,
|
isVisible,
|
||||||
note,
|
note,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
handleDisableClickoutsideRequest,
|
||||||
}) => {
|
}) => {
|
||||||
const editors = useMemo(
|
const editors = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -39,6 +42,8 @@ const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
|
|||||||
)
|
)
|
||||||
const groups = useMemo(() => createEditorMenuGroups(application, editors), [application, editors])
|
const groups = useMemo(() => createEditorMenuGroups(application, editors), [application, editors])
|
||||||
const [currentComponent, setCurrentComponent] = useState<SNComponent>()
|
const [currentComponent, setCurrentComponent] = useState<SNComponent>()
|
||||||
|
const [showSuperImporter, setShowSuperImporter] = useState(false)
|
||||||
|
const [pendingSuperItem, setPendingSuperItem] = useState<EditorMenuItem | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (note) {
|
if (note) {
|
||||||
@@ -54,7 +59,7 @@ const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
|
|||||||
return item.component?.identifier === currentComponent.identifier
|
return item.component?.identifier === currentComponent.identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
return item.noteType === note?.noteType
|
return item.noteType === note?.noteType || (!note?.noteType && item.noteType === NoteType.Plain)
|
||||||
},
|
},
|
||||||
[currentComponent, note],
|
[currentComponent, note],
|
||||||
)
|
)
|
||||||
@@ -109,6 +114,13 @@ const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (itemToBeSelected.noteType === NoteType.Blocks) {
|
||||||
|
setPendingSuperItem(itemToBeSelected)
|
||||||
|
handleDisableClickoutsideRequest?.()
|
||||||
|
setShowSuperImporter(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let shouldMakeSelection = true
|
let shouldMakeSelection = true
|
||||||
|
|
||||||
if (itemToBeSelected.component) {
|
if (itemToBeSelected.component) {
|
||||||
@@ -136,46 +148,77 @@ const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
|
|||||||
onSelect(itemToBeSelected.component)
|
onSelect(itemToBeSelected.component)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[application, closeMenu, currentComponent, note, onSelect, premiumModal, selectComponent, selectNonComponent],
|
[
|
||||||
|
application,
|
||||||
|
closeMenu,
|
||||||
|
currentComponent,
|
||||||
|
note,
|
||||||
|
onSelect,
|
||||||
|
premiumModal,
|
||||||
|
selectComponent,
|
||||||
|
selectNonComponent,
|
||||||
|
handleDisableClickoutsideRequest,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
const handleSuperNoteConversionCompletion = useCallback(() => {
|
||||||
<Menu className="pt-0.5 pb-1" a11yLabel="Change note type menu" isOpen={isVisible}>
|
if (!pendingSuperItem || !note) {
|
||||||
{groups
|
return
|
||||||
.filter((group) => group.items && group.items.length)
|
}
|
||||||
.map((group, index) => {
|
|
||||||
const groupId = getGroupId(group)
|
|
||||||
|
|
||||||
return (
|
selectNonComponent(pendingSuperItem, note).catch(console.error)
|
||||||
<Fragment key={groupId}>
|
closeMenu()
|
||||||
<div className={`border-0 border-t border-solid border-border py-1 ${index === 0 ? 'border-t-0' : ''}`}>
|
}, [note, pendingSuperItem, selectNonComponent, closeMenu])
|
||||||
{group.items.map((item) => {
|
|
||||||
const onClickEditorItem = () => {
|
return (
|
||||||
selectItem(item).catch(console.error)
|
<>
|
||||||
}
|
<Menu className="pt-0.5 pb-1" a11yLabel="Change note type menu" isOpen={isVisible}>
|
||||||
return (
|
{groups
|
||||||
<MenuItem
|
.filter((group) => group.items && group.items.length)
|
||||||
key={item.name}
|
.map((group, index) => {
|
||||||
type={MenuItemType.RadioButton}
|
const groupId = getGroupId(group)
|
||||||
onClick={onClickEditorItem}
|
|
||||||
className={'flex-row-reverse py-2'}
|
return (
|
||||||
checked={item.isEntitled ? isSelected(item) : undefined}
|
<Fragment key={groupId}>
|
||||||
>
|
<div className={`border-0 border-t border-solid border-border py-1 ${index === 0 ? 'border-t-0' : ''}`}>
|
||||||
<div className="flex flex-grow items-center justify-between">
|
{group.items.map((item) => {
|
||||||
<div className="flex items-center">
|
const onClickEditorItem = () => {
|
||||||
{group.icon && <Icon type={group.icon} className={`mr-2 ${group.iconClassName}`} />}
|
selectItem(item).catch(console.error)
|
||||||
{item.name}
|
}
|
||||||
|
return (
|
||||||
|
<MenuItem
|
||||||
|
key={item.name}
|
||||||
|
type={MenuItemType.RadioButton}
|
||||||
|
onClick={onClickEditorItem}
|
||||||
|
className={'flex-row-reverse py-2'}
|
||||||
|
checked={item.isEntitled ? isSelected(item) : undefined}
|
||||||
|
>
|
||||||
|
<div className="flex flex-grow items-center justify-between">
|
||||||
|
<div className={`flex items-center ${group.featured ? 'font-bold' : ''}`}>
|
||||||
|
{group.icon && <Icon type={group.icon} className={`mr-2 ${group.iconClassName}`} />}
|
||||||
|
{item.name}
|
||||||
|
</div>
|
||||||
|
{!item.isEntitled && (
|
||||||
|
<Icon type={PremiumFeatureIconName} className={PremiumFeatureIconClass} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!item.isEntitled && <Icon type={PremiumFeatureIconName} className={PremiumFeatureIconClass} />}
|
</MenuItem>
|
||||||
</div>
|
)
|
||||||
</MenuItem>
|
})}
|
||||||
)
|
</div>
|
||||||
})}
|
</Fragment>
|
||||||
</div>
|
)
|
||||||
</Fragment>
|
})}
|
||||||
)
|
</Menu>
|
||||||
})}
|
{showSuperImporter && note && (
|
||||||
</Menu>
|
<SuperNoteImporter
|
||||||
|
note={note}
|
||||||
|
application={application}
|
||||||
|
onConvertComplete={handleSuperNoteConversionCompletion}
|
||||||
|
closeDialog={() => setShowSuperImporter(false)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -334,6 +334,8 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
editorFeatureIdentifier: note.editorIdentifier,
|
editorFeatureIdentifier: note.editorIdentifier,
|
||||||
noteType: note.noteType,
|
noteType: note.noteType,
|
||||||
|
editorText: note.text,
|
||||||
|
editorTitle: note.title,
|
||||||
})
|
})
|
||||||
|
|
||||||
void this.reloadEditorComponent()
|
void this.reloadEditorComponent()
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ export type AccordionMenuGroup<T> = {
|
|||||||
iconClassName?: string
|
iconClassName?: string
|
||||||
title: string
|
title: string
|
||||||
items: Array<T>
|
items: Array<T>
|
||||||
|
featured?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ const useRegisterPopoverToParent = (popoverId: string) => {
|
|||||||
|
|
||||||
type Props = PopoverProps & {
|
type Props = PopoverProps & {
|
||||||
open: boolean
|
open: boolean
|
||||||
|
disableClickOutside?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const Popover = ({
|
const Popover = ({
|
||||||
@@ -39,6 +40,7 @@ const Popover = ({
|
|||||||
overrideZIndex,
|
overrideZIndex,
|
||||||
side,
|
side,
|
||||||
togglePopover,
|
togglePopover,
|
||||||
|
disableClickOutside,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const popoverId = useRef(UuidGenerator.GenerateUuid())
|
const popoverId = useRef(UuidGenerator.GenerateUuid())
|
||||||
|
|
||||||
@@ -96,6 +98,7 @@ const Popover = ({
|
|||||||
overrideZIndex={overrideZIndex}
|
overrideZIndex={overrideZIndex}
|
||||||
side={side}
|
side={side}
|
||||||
togglePopover={togglePopover}
|
togglePopover={togglePopover}
|
||||||
|
disableClickOutside={disableClickOutside}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</PositionedPopoverContent>
|
</PositionedPopoverContent>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const PositionedPopoverContent = ({
|
|||||||
overrideZIndex,
|
overrideZIndex,
|
||||||
side = 'bottom',
|
side = 'bottom',
|
||||||
togglePopover,
|
togglePopover,
|
||||||
|
disableClickOutside,
|
||||||
}: PopoverContentProps) => {
|
}: PopoverContentProps) => {
|
||||||
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
const [popoverElement, setPopoverElement] = useState<HTMLDivElement | null>(null)
|
||||||
const popoverRect = useAutoElementRect(popoverElement)
|
const popoverRect = useAutoElementRect(popoverElement)
|
||||||
@@ -50,6 +51,7 @@ const PositionedPopoverContent = ({
|
|||||||
anchorElement,
|
anchorElement,
|
||||||
togglePopover,
|
togglePopover,
|
||||||
childPopovers,
|
childPopovers,
|
||||||
|
disabled: disableClickOutside,
|
||||||
})
|
})
|
||||||
|
|
||||||
useDisableBodyScrollOnMobile()
|
useDisableBodyScrollOnMobile()
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export type PopoverContentProps = CommonPopoverProps & {
|
|||||||
anchorPoint?: Point
|
anchorPoint?: Point
|
||||||
childPopovers: Set<string>
|
childPopovers: Set<string>
|
||||||
id: string
|
id: string
|
||||||
|
disableClickOutside?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PopoverProps =
|
export type PopoverProps =
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ type Options = {
|
|||||||
anchorElement: HTMLElement | null | undefined
|
anchorElement: HTMLElement | null | undefined
|
||||||
togglePopover: () => void
|
togglePopover: () => void
|
||||||
childPopovers: Set<string>
|
childPopovers: Set<string>
|
||||||
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const usePopoverCloseOnClickOutside = ({
|
export const usePopoverCloseOnClickOutside = ({
|
||||||
@@ -13,6 +14,7 @@ export const usePopoverCloseOnClickOutside = ({
|
|||||||
anchorElement,
|
anchorElement,
|
||||||
togglePopover,
|
togglePopover,
|
||||||
childPopovers,
|
childPopovers,
|
||||||
|
disabled,
|
||||||
}: Options) => {
|
}: Options) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const closeIfClickedOutside = (event: MouseEvent) => {
|
const closeIfClickedOutside = (event: MouseEvent) => {
|
||||||
@@ -31,7 +33,9 @@ export const usePopoverCloseOnClickOutside = ({
|
|||||||
const isDescendantOfChallengeModal = !!target.closest('.challenge-modal')
|
const isDescendantOfChallengeModal = !!target.closest('.challenge-modal')
|
||||||
|
|
||||||
if (!isDescendantOfMenu && !isAnchorElement && !isDescendantOfChildPopover && !isDescendantOfChallengeModal) {
|
if (!isDescendantOfMenu && !isAnchorElement && !isDescendantOfChildPopover && !isDescendantOfChallengeModal) {
|
||||||
togglePopover()
|
if (!disabled) {
|
||||||
|
togglePopover()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,5 +45,5 @@ export const usePopoverCloseOnClickOutside = ({
|
|||||||
document.removeEventListener('click', closeIfClickedOutside, { capture: true })
|
document.removeEventListener('click', closeIfClickedOutside, { capture: true })
|
||||||
document.removeEventListener('contextmenu', closeIfClickedOutside, { capture: true })
|
document.removeEventListener('contextmenu', closeIfClickedOutside, { capture: true })
|
||||||
}
|
}
|
||||||
}, [anchorElement, childPopovers, popoverElement, togglePopover])
|
}, [anchorElement, childPopovers, popoverElement, togglePopover, disabled])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const ModalDialog = ({ children, onDismiss, className }: Props) => {
|
|||||||
<AlertDialogContent
|
<AlertDialogContent
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'flex w-full flex-col rounded border border-solid border-border bg-default p-0 shadow-main md:w-160',
|
'flex max-h-[85vh] w-full flex-col rounded border border-solid border-border bg-default p-0 shadow-main md:w-160',
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ModalDialogDescription: FunctionComponent<Props> = ({ children, className = '' }) => (
|
const ModalDialogDescription: FunctionComponent<Props> = ({ children, className = '' }) => (
|
||||||
<AlertDialogDescription className={`px-4 py-4 ${className}`}>{children}</AlertDialogDescription>
|
<AlertDialogDescription className={`overflow-y-scroll px-4 py-4 ${className}`}>{children}</AlertDialogDescription>
|
||||||
)
|
)
|
||||||
|
|
||||||
export default ModalDialogDescription
|
export default ModalDialogDescription
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const TAG_FOLDERS_FEATURE_TOOLTIP = 'A Plus or Pro plan is required to en
|
|||||||
export const SMART_TAGS_FEATURE_NAME = 'Smart Tags'
|
export const SMART_TAGS_FEATURE_NAME = 'Smart Tags'
|
||||||
|
|
||||||
export const PLAIN_EDITOR_NAME = 'Plain Text'
|
export const PLAIN_EDITOR_NAME = 'Plain Text'
|
||||||
export const BLOCKS_EDITOR_NAME = 'Super Note'
|
export const BLOCKS_EDITOR_NAME = 'Super'
|
||||||
|
|
||||||
export const SYNC_TIMEOUT_DEBOUNCE = 350
|
export const SYNC_TIMEOUT_DEBOUNCE = 350
|
||||||
export const SYNC_TIMEOUT_NO_DEBOUNCE = 100
|
export const SYNC_TIMEOUT_NO_DEBOUNCE = 100
|
||||||
|
|||||||
@@ -126,10 +126,11 @@ const createGroupsFromMap = (map: NoteTypeToEditorRowsMap): EditorMenuGroup[] =>
|
|||||||
|
|
||||||
if (featureTrunkEnabled(FeatureTrunkName.Blocks)) {
|
if (featureTrunkEnabled(FeatureTrunkName.Blocks)) {
|
||||||
groups.splice(1, 0, {
|
groups.splice(1, 0, {
|
||||||
icon: 'dashboard',
|
icon: 'file-doc',
|
||||||
iconClassName: 'text-accessory-tint-1',
|
iconClassName: 'text-accessory-tint-4',
|
||||||
title: BLOCKS_EDITOR_NAME,
|
title: BLOCKS_EDITOR_NAME,
|
||||||
items: map[NoteType.Blocks],
|
items: map[NoteType.Blocks],
|
||||||
|
featured: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user