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
1a40d976
Commit
1a40d976
authored
Feb 01, 2024
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert HighlightClusterController to use PreactContainer
parent
a13024c2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
18 deletions
+12
-18
highlight-clusters.tsx
src/annotator/highlight-clusters.tsx
+12
-18
No files found.
src/annotator/highlight-clusters.tsx
View file @
1a40d976
import
{
render
}
from
'preact'
;
import
type
{
Destroyable
,
FeatureFlags
as
IFeatureFlags
,
...
...
@@ -7,7 +5,7 @@ import type {
import
type
{
HighlightCluster
}
from
'../types/shared'
;
import
ClusterToolbar
from
'./components/ClusterToolbar'
;
import
{
updateClusters
}
from
'./highlighter'
;
import
{
createShadowRoot
}
from
'./util/shadow-root
'
;
import
{
PreactContainer
}
from
'./util/preact-container
'
;
export
type
HighlightStyle
=
{
color
:
string
;
...
...
@@ -67,24 +65,22 @@ export const defaultClusterStyles: AppliedStyles = {
export
class
HighlightClusterController
implements
Destroyable
{
appliedStyles
:
AppliedStyles
;
private
_container
:
PreactContainer
;
private
_element
:
HTMLElement
;
private
_features
:
IFeatureFlags
;
private
_outerContainer
:
HTMLElement
;
private
_shadowRoot
:
ShadowRoot
;
private
_updateTimeout
?:
number
;
constructor
(
element
:
HTMLElement
,
options
:
{
features
:
IFeatureFlags
})
{
this
.
_element
=
element
;
this
.
_features
=
options
.
features
;
this
.
_
outerContainer
=
document
.
createElement
(
'hypothesis-highlight-cluster-toolbar'
,
this
.
_
container
=
new
PreactContainer
(
'highlight-cluster-toolbar'
,
()
=>
this
.
_render
()
,
);
this
.
_element
.
appendChild
(
this
.
_outerContainer
);
this
.
_shadowRoot
=
createShadowRoot
(
this
.
_outerContainer
);
this
.
_element
.
appendChild
(
this
.
_container
.
element
);
// For now, the controls are fixed at top-left of screen. This is temporary.
Object
.
assign
(
this
.
_
outerContainer
.
style
,
{
Object
.
assign
(
this
.
_
container
.
element
.
style
,
{
position
:
'fixed'
,
top
:
`
${
this
.
_element
.
offsetTop
+
4
}
px`
,
left
:
'4px'
,
...
...
@@ -98,14 +94,13 @@ export class HighlightClusterController implements Destroyable {
this
.
_activate
(
this
.
_isActive
());
});
this
.
_render
();
this
.
_
container
.
render
();
}
destroy
()
{
clearTimeout
(
this
.
_updateTimeout
);
render
(
null
,
this
.
_shadowRoot
);
// unload the Preact component
this
.
_activate
(
false
);
// De-activate cluster styling
this
.
_
outerContainer
.
remove
();
this
.
_
container
.
destroy
();
}
/**
...
...
@@ -149,7 +144,7 @@ export class HighlightClusterController implements Destroyable {
*/
_activate
(
active
:
boolean
)
{
this
.
_element
.
classList
.
toggle
(
'hypothesis-highlights-clustered'
,
active
);
this
.
_render
();
this
.
_
container
.
render
();
}
/**
...
...
@@ -188,11 +183,11 @@ export class HighlightClusterController implements Destroyable {
)
{
this
.
appliedStyles
[
cluster
]
=
styleName
;
this
.
_setClusterStyles
(
cluster
,
styleName
);
this
.
_render
();
this
.
_
container
.
render
();
}
_render
()
{
re
nder
(
re
turn
(
<
ClusterToolbar
active=
{
this
.
_isActive
()
}
availableStyles=
{
highlightStyles
}
...
...
@@ -200,8 +195,7 @@ export class HighlightClusterController implements Destroyable {
onStyleChange=
{
(
cluster
,
styleName
)
=>
this
.
_onChangeClusterStyle
(
cluster
,
styleName
)
}
/>,
this
.
_shadowRoot
,
/>
);
}
}
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