Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax-prosemirror
Manage
Activity
Members
Labels
Plan
Issues
34
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wax
wax-prosemirror
Commits
5ca1a596
Commit
5ca1a596
authored
4 years ago
by
chris
Browse files
Options
Downloads
Patches
Plain Diff
add new tag to the list
parent
24e446ca
No related branches found
No related tags found
1 merge request
!232
feat(custom-tag-block): added custom-tag-block
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js
+15
-37
15 additions, 37 deletions
...nents/src/components/customtag/CustomTagBlockComponent.js
with
15 additions
and
37 deletions
wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js
+
15
−
37
View file @
5ca1a596
import
React
,
{
useContext
,
useMemo
,
useRef
,
useState
}
from
'
react
'
;
import
React
,
{
useContext
,
useMemo
,
useRef
,
useState
,
useEffect
}
from
'
react
'
;
import
styled
from
'
styled-components
'
;
import
styled
from
'
styled-components
'
;
import
{
WaxContext
}
from
'
wax-prosemirror-core
'
;
import
{
WaxContext
}
from
'
wax-prosemirror-core
'
;
import
useDeepCompareEffect
from
'
use-deep-compare-effect
'
;
import
useDeepCompareEffect
from
'
use-deep-compare-effect
'
;
...
@@ -11,6 +11,7 @@ const Input = styled.input`
...
@@ -11,6 +11,7 @@ const Input = styled.input`
border-bottom: 1px solid grey;
border-bottom: 1px solid grey;
font-size: 14px;
font-size: 14px;
font-weight: 400;
font-weight: 400;
width: 150px;
&:focus {
&:focus {
outline: none;
outline: none;
...
@@ -19,6 +20,7 @@ const Input = styled.input`
...
@@ -19,6 +20,7 @@ const Input = styled.input`
const
FlexDiv
=
styled
.
div
`
const
FlexDiv
=
styled
.
div
`
display: flex;
display: flex;
width: 150px;
`
;
`
;
const
Add
=
styled
.
button
`
const
Add
=
styled
.
button
`
...
@@ -48,12 +50,10 @@ const Box = styled.div`
...
@@ -48,12 +50,10 @@ const Box = styled.div`
const
StyledButton
=
styled
.
div
``
;
const
StyledButton
=
styled
.
div
``
;
const
CustomTagBlockComponent
=
props
=>
{
const
CustomTagBlockComponent
=
({
isShowTag
,
item
})
=>
{
const
{
isShowTag
,
item
}
=
props
;
const
ref
=
useRef
();
const
ref
=
useRef
();
const
[
inputValue
,
setInputValue
]
=
useState
(
''
);
const
[
inputValue
,
setInputValue
]
=
useState
(
''
);
const
[
tagName
,
setTagName
]
=
useState
(
''
);
const
[
tagName
,
setTagName
]
=
useState
(
''
);
const
localTagList
=
JSON
.
parse
(
localStorage
.
getItem
(
'
tagBlockList
'
));
const
{
const
{
app
,
app
,
...
@@ -66,27 +66,20 @@ const CustomTagBlockComponent = props => {
...
@@ -66,27 +66,20 @@ const CustomTagBlockComponent = props => {
const
{
$from
}
=
state
.
selection
;
const
{
$from
}
=
state
.
selection
;
const
type
=
$from
.
parent
.
attrs
.
class
?
$from
.
parent
.
attrs
.
class
:
''
;
const
type
=
$from
.
parent
.
attrs
.
class
?
$from
.
parent
.
attrs
.
class
:
''
;
const
serviceC
onfig
=
app
.
config
.
get
(
'
config.CustomTagService
'
);
const
c
onfig
Tags
=
app
.
config
.
get
(
'
config.CustomTagService
'
)
.
tags
;
const
[
serviceList
,
setServiceList
]
=
useState
(
[]
);
const
[
allTags
,
setAllTags
]
=
useState
(
configTags
);
const
isActive
=
item
.
active
(
activeView
.
state
,
activeViewId
,
type
);
const
isActive
=
item
.
active
(
activeView
.
state
,
activeViewId
,
type
);
const
onChangeTagName
=
e
=>
{
const
onChangeTagName
=
()
=>
{
setTagName
(
e
.
targe
t
.
value
);
setTagName
(
ref
.
curren
t
.
value
);
setInputValue
(
e
.
targe
t
.
value
);
setInputValue
(
ref
.
curren
t
.
value
);
};
};
const
onClickAdd
=
()
=>
{
const
onClickAdd
=
()
=>
{
if
(
tagName
.
trim
()
===
''
)
return
;
if
(
tagName
.
trim
()
===
''
)
return
;
let
tagNameList
=
[];
if
(
localStorage
.
getItem
(
'
tagBlockList
'
)
===
null
)
{
configTags
.
push
({
label
:
tagName
,
tagType
:
'
block
'
});
tagNameList
.
push
({
label
:
tagName
,
type
:
'
block
'
});
setAllTags
(
configTags
);
localStorage
.
setItem
(
'
tagBlockList
'
,
JSON
.
stringify
(
tagNameList
));
}
else
{
tagNameList
=
JSON
.
parse
(
localStorage
.
getItem
(
'
tagBlockList
'
));
tagNameList
.
push
({
label
:
tagName
,
type
:
'
block
'
});
localStorage
.
clear
(
'
tagBlockList
'
);
localStorage
.
setItem
(
'
tagBlockList
'
,
JSON
.
stringify
(
tagNameList
));
}
setInputValue
(
'
'
);
setInputValue
(
'
'
);
};
};
...
@@ -94,22 +87,7 @@ const CustomTagBlockComponent = props => {
...
@@ -94,22 +87,7 @@ const CustomTagBlockComponent = props => {
item
.
run
(
state
,
dispatch
,
val
.
replace
(
/ /g
,
'
-
'
));
item
.
run
(
state
,
dispatch
,
val
.
replace
(
/ /g
,
'
-
'
));
};
};
useDeepCompareEffect
(()
=>
{
console
.
log
(
allTags
);
const
labels
=
[];
if
(
serviceConfig
!==
undefined
)
{
serviceConfig
.
tags
.
forEach
(
tag
=>
{
if
(
tag
.
tagType
===
'
block
'
)
{
labels
.
push
(
tag
.
label
);
}
});
}
if
(
localTagList
!==
null
)
{
localTagList
.
forEach
(
tag
=>
{
labels
.
push
(
tag
.
label
);
});
}
setServiceList
(
labels
);
},
[
localTagList
,
serviceConfig
]);
return
useMemo
(
return
useMemo
(
()
=>
(
()
=>
(
...
@@ -117,7 +95,7 @@ const CustomTagBlockComponent = props => {
...
@@ -117,7 +95,7 @@ const CustomTagBlockComponent = props => {
{
isShowTag
&&
(
{
isShowTag
&&
(
<
FlexDiv
>
<
FlexDiv
>
<
Input
<
Input
onChange
=
{
e
=>
onChangeTagName
(
e
)
}
onChange
=
{
onChangeTagName
}
ref
=
{
ref
}
ref
=
{
ref
}
type
=
"
text
"
type
=
"
text
"
value
=
{
inputValue
}
value
=
{
inputValue
}
...
@@ -127,7 +105,7 @@ const CustomTagBlockComponent = props => {
...
@@ -127,7 +105,7 @@ const CustomTagBlockComponent = props => {
)}
)}
<
/Wrapper
>
<
/Wrapper
>
),
),
[],
[
isShowTag
,
inputValue
],
);
);
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment