Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
7e301ed7
Commit
7e301ed7
authored
Oct 13, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Dec 05, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update shared components in `MarkdownEditor`
parent
9c550f78
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
52 deletions
+38
-52
MarkdownEditor.js
src/sidebar/components/MarkdownEditor.js
+38
-52
No files found.
src/sidebar/components/MarkdownEditor.js
View file @
7e301ed7
import
{
import
{
Icon
,
ButtonBase
,
IconButton
,
IconButton
,
LabeledButton
,
LinkBase
,
Link
,
}
from
'@hypothesis/frontend-shared/lib/next'
;
}
from
'@hypothesis/frontend-shared'
;
import
{
EditorLatexIcon
,
EditorQuoteIcon
,
EditorTextBoldIcon
,
EditorTextItalicIcon
,
HelpIcon
,
ImageIcon
,
LinkIcon
,
ListOrderedIcon
,
ListUnorderedIcon
,
}
from
'@hypothesis/frontend-shared/lib/next'
;
import
classnames
from
'classnames'
;
import
classnames
from
'classnames'
;
import
{
useEffect
,
useMemo
,
useRef
,
useState
}
from
'preact/hooks'
;
import
{
useEffect
,
useMemo
,
useRef
,
useState
}
from
'preact/hooks'
;
...
@@ -24,7 +35,7 @@ import MarkdownView from './MarkdownView';
...
@@ -24,7 +35,7 @@ import MarkdownView from './MarkdownView';
*/
*/
/**
/**
* @typedef {import(
"@hypothesis/frontend-shared/lib/components/Link").LinkProps} LinkProps
* @typedef {import(
'@hypothesis/frontend-shared/lib/types').IconComponent} IconComponent
* @typedef {import('preact').JSX.HTMLAttributes<HTMLTextAreaElement>} TextAreaAttributes
* @typedef {import('preact').JSX.HTMLAttributes<HTMLTextAreaElement>} TextAreaAttributes
* @typedef {import('../markdown-commands').EditorState} EditorState
* @typedef {import('../markdown-commands').EditorState} EditorState
*/
*/
...
@@ -130,33 +141,10 @@ function handleToolbarCommand(command, inputEl) {
...
@@ -130,33 +141,10 @@ function handleToolbarCommand(command, inputEl) {
}
}
}
}
/**
* Style a Link to look like an IconButton, including touch sizing
* affordances.
*
* @param {Omit<LinkProps, 'children'> & { icon: string }} props
*/
function
IconLink
({
classes
,
icon
,
linkRef
,
...
restProps
})
{
return
(
<
Link
classes
=
{
classnames
(
'flex justify-center items-center'
,
'text-grey-7 hover:!text-grey-7'
,
'touch:h-touch-minimum touch:w-touch-minimum'
,
classes
)}
linkRef
=
{
linkRef
}
{...
restProps
}
>
<
Icon
classes
=
"text-tiny touch:text-base"
name
=
{
icon
}
/
>
<
/Link
>
);
}
/**
/**
* @typedef ToolbarButtonProps
* @typedef ToolbarButtonProps
* @prop {boolean} [disabled]
* @prop {boolean} [disabled]
* @prop {
string} [iconName
]
* @prop {
IconComponent} [icon
]
* @prop {string} [label]
* @prop {string} [label]
* @prop {(e: MouseEvent) => void} onClick
* @prop {(e: MouseEvent) => void} onClick
* @prop {string} [shortcutKey]
* @prop {string} [shortcutKey]
...
@@ -166,7 +154,7 @@ function IconLink({ classes, icon, linkRef, ...restProps }) {
...
@@ -166,7 +154,7 @@ function IconLink({ classes, icon, linkRef, ...restProps }) {
/** @param {ToolbarButtonProps} props */
/** @param {ToolbarButtonProps} props */
function
ToolbarButton
({
function
ToolbarButton
({
disabled
=
false
,
disabled
=
false
,
icon
Name
=
''
,
icon
,
label
,
label
,
onClick
,
onClick
,
shortcutKey
,
shortcutKey
,
...
@@ -181,24 +169,19 @@ function ToolbarButton({
...
@@ -181,24 +169,19 @@ function ToolbarButton({
const
buttonProps
=
{
const
buttonProps
=
{
disabled
,
disabled
,
icon
:
iconName
,
icon
,
onClick
,
onClick
,
title
:
tooltip
,
title
:
tooltip
,
};
};
if
(
label
)
{
if
(
label
)
{
return
(
return
(
<
LabeledButton
<
ButtonBase
classes
=
{
classnames
(
classes
=
"text-grey-7 hover:text-grey-9 p-1.5"
'font-normal bg-transparent'
,
// TODO: Refactor shared button styles to reduce specificity and make
// this !important rule unnecessary
'hover:!bg-transparent'
)}
{...
buttonProps
}
{...
buttonProps
}
>
>
{
label
}
{
label
}
<
/
LabeledButton
>
<
/
ButtonBase
>
);
);
}
}
return
(
return
(
...
@@ -266,72 +249,75 @@ function Toolbar({ isPreviewing, onCommand, onTogglePreview }) {
...
@@ -266,72 +249,75 @@ function Toolbar({ isPreviewing, onCommand, onTogglePreview }) {
>
>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"format-bold"
icon
=
{
EditorTextBoldIcon
}
onClick
=
{()
=>
onCommand
(
'bold'
)}
onClick
=
{()
=>
onCommand
(
'bold'
)}
shortcutKey
=
{
SHORTCUT_KEYS
.
bold
}
shortcutKey
=
{
SHORTCUT_KEYS
.
bold
}
title
=
"Bold"
title
=
"Bold"
/>
/>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"format-italic"
icon
=
{
EditorTextItalicIcon
}
onClick
=
{()
=>
onCommand
(
'italic'
)}
onClick
=
{()
=>
onCommand
(
'italic'
)}
shortcutKey
=
{
SHORTCUT_KEYS
.
italic
}
shortcutKey
=
{
SHORTCUT_KEYS
.
italic
}
title
=
"Italic"
title
=
"Italic"
/>
/>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"format-quote"
icon
=
{
EditorQuoteIcon
}
onClick
=
{()
=>
onCommand
(
'quote'
)}
onClick
=
{()
=>
onCommand
(
'quote'
)}
shortcutKey
=
{
SHORTCUT_KEYS
.
quote
}
shortcutKey
=
{
SHORTCUT_KEYS
.
quote
}
title
=
"Quote"
title
=
"Quote"
/>
/>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"link"
icon
=
{
LinkIcon
}
onClick
=
{()
=>
onCommand
(
'link'
)}
onClick
=
{()
=>
onCommand
(
'link'
)}
shortcutKey
=
{
SHORTCUT_KEYS
.
link
}
shortcutKey
=
{
SHORTCUT_KEYS
.
link
}
title
=
"Insert link"
title
=
"Insert link"
/>
/>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"image"
icon
=
{
ImageIcon
}
onClick
=
{()
=>
onCommand
(
'image'
)}
onClick
=
{()
=>
onCommand
(
'image'
)}
shortcutKey
=
{
SHORTCUT_KEYS
.
image
}
shortcutKey
=
{
SHORTCUT_KEYS
.
image
}
title
=
"Insert image"
title
=
"Insert image"
/>
/>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"format-functions"
icon
=
{
EditorLatexIcon
}
onClick
=
{()
=>
onCommand
(
'math'
)}
onClick
=
{()
=>
onCommand
(
'math'
)}
title
=
"Insert math (LaTeX is supported)"
title
=
"Insert math (LaTeX is supported)"
/>
/>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"format-list-numbered"
icon
=
{
ListOrderedIcon
}
onClick
=
{()
=>
onCommand
(
'numlist'
)}
onClick
=
{()
=>
onCommand
(
'numlist'
)}
shortcutKey
=
{
SHORTCUT_KEYS
.
numlist
}
shortcutKey
=
{
SHORTCUT_KEYS
.
numlist
}
title
=
"Numbered list"
title
=
"Numbered list"
/>
/>
<
ToolbarButton
<
ToolbarButton
disabled
=
{
isPreviewing
}
disabled
=
{
isPreviewing
}
icon
Name
=
"format-list-unordered"
icon
=
{
ListUnorderedIcon
}
onClick
=
{()
=>
onCommand
(
'list'
)}
onClick
=
{()
=>
onCommand
(
'list'
)}
shortcutKey
=
{
SHORTCUT_KEYS
.
list
}
shortcutKey
=
{
SHORTCUT_KEYS
.
list
}
title
=
"Bulleted list"
title
=
"Bulleted list"
/>
/>
<
div
className
=
"grow flex justify-end"
>
<
div
className
=
"grow flex justify-end"
>
<
IconLink
<
LinkBase
classes
=
{
classnames
(
classes
=
{
classnames
(
// Adjust padding to make element a little taller than wide
'flex justify-center items-center'
,
// This matches ToolbarButton styling
'text-grey-7 hover:!text-grey-7'
,
'touch:h-touch-minimum touch:w-touch-minimum'
,
'px-2 py-2.5'
'px-2 py-2.5'
)}
)}
href
=
"https://web.hypothes.is/help/formatting-annotations-with-markdown/"
href
=
"https://web.hypothes.is/help/formatting-annotations-with-markdown/"
icon
=
"help"
target
=
"_blank"
target
=
"_blank"
title
=
"Formatting help"
title
=
"Formatting help"
aria
-
label
=
"Formatting help"
aria
-
label
=
"Formatting help"
/>
>
<
HelpIcon
className
=
"w-2.5 h-2.5"
/>
<
/LinkBase
>
<
ToolbarButton
<
ToolbarButton
label
=
{
isPreviewing
?
'Write'
:
'Preview'
}
label
=
{
isPreviewing
?
'Write'
:
'Preview'
}
onClick
=
{
onTogglePreview
}
onClick
=
{
onTogglePreview
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment