Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
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
Vũ Hoàng Anh
canifa_note
Commits
58941045
Commit
58941045
authored
Oct 01, 2022
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update inline image
parent
09732df0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
71 deletions
+20
-71
DailyMemo.tsx
web/src/components/DailyMemo.tsx
+0
-1
MemoContent.tsx
web/src/components/MemoContent.tsx
+5
-10
ShareMemoImageDialog.tsx
web/src/components/ShareMemoImageDialog.tsx
+4
-28
marked.ts
web/src/helpers/marked.ts
+3
-20
memo.less
web/src/less/memo.less
+8
-12
No files found.
web/src/components/DailyMemo.tsx
View file @
58941045
...
...
@@ -21,7 +21,6 @@ const DailyMemo: React.FC<Props> = (props: Props) => {
};
const
displayConfig
:
DisplayConfig
=
{
enableExpand
:
false
,
showInlineImage
:
true
,
};
return
(
...
...
web/src/components/MemoContent.tsx
View file @
58941045
...
...
@@ -3,14 +3,8 @@ import { formatMemoContent } from "../helpers/marked";
import
Icon
from
"./Icon"
;
import
"../less/memo-content.less"
;
const
defaultDisplayConfig
:
DisplayConfig
=
{
enableExpand
:
true
,
showInlineImage
:
false
,
};
export
interface
DisplayConfig
{
enableExpand
:
boolean
;
showInlineImage
:
boolean
;
}
interface
Props
{
...
...
@@ -27,6 +21,10 @@ interface State {
expandButtonStatus
:
ExpandButtonStatus
;
}
const
defaultDisplayConfig
:
DisplayConfig
=
{
enableExpand
:
true
,
};
const
MAX_MEMO_CONTAINER_HEIGHT
=
384
;
const
MemoContent
:
React
.
FC
<
Props
>
=
(
props
:
Props
)
=>
{
...
...
@@ -39,9 +37,6 @@ const MemoContent: React.FC<Props> = (props: Props) => {
...
defaultDisplayConfig
,
...
props
.
displayConfig
,
};
const
formatConfig
=
{
inlineImage
:
displayConfig
.
showInlineImage
,
};
useEffect
(()
=>
{
if
(
!
memoContentContainerRef
)
{
...
...
@@ -84,7 +79,7 @@ const MemoContent: React.FC<Props> = (props: Props) => {
className=
{
`memo-content-text ${state.expandButtonStatus === 0 ? "expanded" : ""}`
}
onClick=
{
handleMemoContentClick
}
onDoubleClick=
{
handleMemoContentDoubleClick
}
dangerouslySetInnerHTML=
{
{
__html
:
formatMemoContent
(
content
,
formatConfig
)
}
}
dangerouslySetInnerHTML=
{
{
__html
:
formatMemoContent
(
content
)
}
}
></
div
>
{
state
.
expandButtonStatus
!==
-
1
&&
(
<
div
className=
"expand-btn-container"
>
...
...
web/src/components/ShareMemoImageDialog.tsx
View file @
58941045
...
...
@@ -4,10 +4,8 @@ import { userService } from "../services";
import
toImage
from
"../labs/html2image"
;
import
{
ANIMATION_DURATION
}
from
"../helpers/consts"
;
import
*
as
utils
from
"../helpers/utils"
;
import
{
IMAGE_URL_REG
}
from
"../helpers/marked"
;
import
Icon
from
"./Icon"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
toastHelper
from
"./Toast"
;
import
MemoContent
from
"./MemoContent"
;
import
"../less/share-memo-image-dialog.less"
;
...
...
@@ -19,21 +17,14 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
const
{
memo
:
propsMemo
,
destroy
}
=
props
;
const
{
t
}
=
useTranslation
();
const
{
user
:
userinfo
}
=
userService
.
getState
();
const
[
shortcutImgUrl
,
setShortcutImgUrl
]
=
useState
(
""
);
const
memo
=
{
...
propsMemo
,
createdAtStr
:
utils
.
getDateTimeString
(
propsMemo
.
createdTs
),
};
const
imageUrls
=
Array
.
from
(
memo
.
content
.
match
(
IMAGE_URL_REG
)
??
[]).
map
((
s
)
=>
s
.
replace
(
IMAGE_URL_REG
,
"$1"
));
const
[
shortcutImgUrl
,
setShortcutImgUrl
]
=
useState
(
""
);
const
[
imgAmount
,
setImgAmount
]
=
useState
(
imageUrls
.
length
);
const
memoElRef
=
useRef
<
HTMLDivElement
>
(
null
);
useEffect
(()
=>
{
if
(
imgAmount
>
0
)
{
return
;
}
setTimeout
(()
=>
{
if
(
!
memoElRef
.
current
)
{
return
;
...
...
@@ -46,24 +37,16 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
.
then
((
url
)
=>
{
setShortcutImgUrl
(
url
);
})
.
catch
(()
=>
{
// do nth
.
catch
((
err
)
=>
{
console
.
error
(
err
);
});
},
ANIMATION_DURATION
);
},
[
imgAmount
]);
},
[]);
const
handleCloseBtnClick
=
()
=>
{
destroy
();
};
const
handleImageOnLoad
=
(
event
:
React
.
SyntheticEvent
<
HTMLImageElement
>
)
=>
{
if
(
event
.
type
===
"error"
)
{
toastHelper
.
error
(
t
(
"message.image-load-failed"
));
(
event
.
target
as
HTMLImageElement
).
remove
();
}
setImgAmount
(
imgAmount
-
1
);
};
const
handleDownloadBtnClick
=
()
=>
{
const
a
=
document
.
createElement
(
"a"
);
a
.
href
=
shortcutImgUrl
;
...
...
@@ -90,13 +73,6 @@ const ShareMemoImageDialog: React.FC<Props> = (props: Props) => {
{
shortcutImgUrl
!==
""
&&
<
img
className=
"memo-shortcut-img"
onClick=
{
handleDownloadBtnClick
}
src=
{
shortcutImgUrl
}
/>
}
<
span
className=
"time-text"
>
{
memo
.
createdAtStr
}
</
span
>
<
MemoContent
className=
"memo-content-wrapper"
content=
{
memo
.
content
}
displayConfig=
{
{
enableExpand
:
false
}
}
/>
{
imageUrls
.
length
>
0
&&
(
<
div
className=
"images-container"
>
{
imageUrls
.
map
((
imgUrl
,
idx
)
=>
(
<
img
decoding=
"async"
key=
{
idx
}
src=
{
imgUrl
}
onLoad=
{
handleImageOnLoad
}
onError=
{
handleImageOnLoad
}
/>
))
}
</
div
>
)
}
<
div
className=
"watermark-container"
>
<
span
className=
"normal-text"
>
<
span
className=
"icon-text"
>
✍️
</
span
>
by
<
span
className=
"name-text"
>
{
userinfo
?.
name
}
</
span
>
...
...
web/src/helpers/marked.ts
View file @
58941045
...
...
@@ -36,29 +36,12 @@ const parseHtmlToRawText = (htmlStr: string): string => {
return
text
;
};
interface
FormatterConfig
{
inlineImage
:
boolean
;
}
const
defaultFormatterConfig
:
FormatterConfig
=
{
inlineImage
:
false
,
};
const
formatMemoContent
=
(
content
:
string
,
additionConfig
?:
Partial
<
FormatterConfig
>
)
=>
{
const
config
=
{
...
defaultFormatterConfig
,
...
additionConfig
,
};
const
formatMemoContent
=
(
content
:
string
)
=>
{
const
tempElement
=
document
.
createElement
(
"div"
);
tempElement
.
innerHTML
=
parseMarkedToHtml
(
escape
(
content
));
let
outputString
=
tempElement
.
innerHTML
;
if
(
config
.
inlineImage
)
{
outputString
=
outputString
.
replace
(
IMAGE_URL_REG
,
"<img class='img' src='$1' />"
);
}
else
{
outputString
=
outputString
.
replace
(
IMAGE_URL_REG
,
""
);
}
return
outputString
return
tempElement
.
innerHTML
.
replace
(
IMAGE_URL_REG
,
"<img class='img' src='$1' />"
)
.
replace
(
MEMO_LINK_REG
,
"<span class='memo-link-text' data-value='$2'>$1</span>"
)
.
replace
(
LINK_URL_REG
,
"<a class='link' target='_blank' rel='noreferrer' href='$2'>$1</a>"
)
.
replace
(
TAG_REG
,
"<span class='tag-span'>#$1</span> "
);
...
...
web/src/less/memo.less
View file @
58941045
@import "./mixin.less";
@import "./memo-content.less";
.memo-wrapper {
@apply flex flex-col justify-start items-start w-full p-4 pt-3 mt-2 bg-white rounded-lg border border-white hover:border-gray-200;
...
...
@@ -100,18 +99,15 @@
}
}
> .memo-content-text {
@apply w-full h-auto transition-all;
&.expanded {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 8;
overflow: hidden;
}
> .memo-content-wrapper {
> .memo-content-text {
.tag-span {
@apply cursor-pointer hover:opacity-80;
}
.tag-span {
@apply cursor-pointer hover:opacity-80;
.img {
@apply max-w-xs;
}
}
}
...
...
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