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
aa7aa7a6
Commit
aa7aa7a6
authored
Feb 01, 2024
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Notebook and Profile modal controllers to use PreactContainer
parent
1a40d976
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
36 deletions
+18
-36
notebook.tsx
src/annotator/notebook.tsx
+8
-19
profile.tsx
src/annotator/profile.tsx
+8
-15
notebook-test.js
src/annotator/test/notebook-test.js
+1
-1
profile-test.js
src/annotator/test/profile-test.js
+1
-1
No files found.
src/annotator/notebook.tsx
View file @
aa7aa7a6
import
{
render
}
from
'preact'
;
import
type
{
Destroyable
}
from
'../types/annotator'
;
import
NotebookModal
from
'./components/NotebookModal'
;
import
type
{
NotebookConfig
}
from
'./components/NotebookModal'
;
import
type
{
EventBus
}
from
'./util/emitter'
;
import
{
createShadowRoot
}
from
'./util/shadow-root
'
;
import
{
PreactContainer
}
from
'./util/preact-container
'
;
export
class
Notebook
implements
Destroyable
{
private
_outerContainer
:
HTMLElement
;
private
_shadowRoot
:
ShadowRoot
;
private
_container
:
PreactContainer
;
/**
* @param eventBus - Enables communication between components sharing the
...
...
@@ -19,22 +16,14 @@ export class Notebook implements Destroyable {
eventBus
:
EventBus
,
config
:
NotebookConfig
,
)
{
/**
* Un-styled shadow host for the notebook content.
* This isolates the notebook from the page's styles.
*/
this
.
_outerContainer
=
document
.
createElement
(
'hypothesis-notebook'
);
element
.
appendChild
(
this
.
_outerContainer
);
this
.
_shadowRoot
=
createShadowRoot
(
this
.
_outerContainer
);
render
(
<
NotebookModal
eventBus=
{
eventBus
}
config=
{
config
}
/>,
this
.
_shadowRoot
,
);
this
.
_container
=
new
PreactContainer
(
'notebook'
,
()
=>
(
<
NotebookModal
eventBus=
{
eventBus
}
config=
{
config
}
/>
));
element
.
append
(
this
.
_container
.
element
);
this
.
_container
.
render
();
}
destroy
()
{
render
(
null
,
this
.
_shadowRoot
);
this
.
_outerContainer
.
remove
();
this
.
_container
.
destroy
();
}
}
src/annotator/profile.tsx
View file @
aa7aa7a6
import
{
render
}
from
'preact'
;
import
type
{
Destroyable
}
from
'../types/annotator'
;
import
type
{
ProfileConfig
}
from
'./components/ProfileModal'
;
import
ProfileModal
from
'./components/ProfileModal'
;
import
type
{
EventBus
}
from
'./util/emitter'
;
import
{
createShadowRoot
}
from
'./util/shadow-root
'
;
import
{
PreactContainer
}
from
'./util/preact-container
'
;
export
class
Profile
implements
Destroyable
{
private
_outerContainer
:
HTMLElement
;
public
shadowRoot
:
ShadowRoot
;
private
_container
:
PreactContainer
;
constructor
(
element
:
HTMLElement
,
eventBus
:
EventBus
,
config
:
ProfileConfig
)
{
this
.
_outerContainer
=
document
.
createElement
(
'hypothesis-profile'
);
element
.
appendChild
(
this
.
_outerContainer
);
this
.
shadowRoot
=
createShadowRoot
(
this
.
_outerContainer
);
render
(
<
ProfileModal
eventBus=
{
eventBus
}
config=
{
config
}
/>,
this
.
shadowRoot
,
);
this
.
_container
=
new
PreactContainer
(
'profile'
,
()
=>
(
<
ProfileModal
eventBus=
{
eventBus
}
config=
{
config
}
/>
));
element
.
append
(
this
.
_container
.
element
);
this
.
_container
.
render
();
}
destroy
():
void
{
render
(
null
,
this
.
shadowRoot
);
this
.
_outerContainer
.
remove
();
this
.
_container
.
destroy
();
}
}
src/annotator/test/notebook-test.js
View file @
aa7aa7a6
...
...
@@ -47,7 +47,7 @@ describe('Notebook', () => {
it
(
'creates the container'
,
()
=>
{
assert
.
isFalse
(
container
.
hasChildNodes
());
const
notebook
=
createNotebook
();
const
shadowRoot
=
notebook
.
_
outerContainer
.
shadowRoot
;
const
shadowRoot
=
notebook
.
_
container
.
element
.
shadowRoot
;
assert
.
isNotNull
(
shadowRoot
);
assert
.
isNotNull
(
shadowRoot
.
querySelector
(
'#notebook-modal'
));
});
...
...
src/annotator/test/profile-test.js
View file @
aa7aa7a6
...
...
@@ -47,7 +47,7 @@ describe('Profile', () => {
it
(
'creates the container'
,
()
=>
{
assert
.
isFalse
(
container
.
hasChildNodes
());
const
profile
=
createProfile
();
const
shadowRoot
=
profile
.
_
outerContainer
.
shadowRoot
;
const
shadowRoot
=
profile
.
_
container
.
element
.
shadowRoot
;
assert
.
isNotNull
(
shadowRoot
);
assert
.
isNotNull
(
shadowRoot
.
querySelector
(
'#profile-modal'
));
});
...
...
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