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
Show 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
type
{
Destroyable
}
from
'../types/annotator'
;
import
NotebookModal
from
'./components/NotebookModal'
;
import
NotebookModal
from
'./components/NotebookModal'
;
import
type
{
NotebookConfig
}
from
'./components/NotebookModal'
;
import
type
{
NotebookConfig
}
from
'./components/NotebookModal'
;
import
type
{
EventBus
}
from
'./util/emitter'
;
import
type
{
EventBus
}
from
'./util/emitter'
;
import
{
createShadowRoot
}
from
'./util/shadow-root
'
;
import
{
PreactContainer
}
from
'./util/preact-container
'
;
export
class
Notebook
implements
Destroyable
{
export
class
Notebook
implements
Destroyable
{
private
_outerContainer
:
HTMLElement
;
private
_container
:
PreactContainer
;
private
_shadowRoot
:
ShadowRoot
;
/**
/**
* @param eventBus - Enables communication between components sharing the
* @param eventBus - Enables communication between components sharing the
...
@@ -19,22 +16,14 @@ export class Notebook implements Destroyable {
...
@@ -19,22 +16,14 @@ export class Notebook implements Destroyable {
eventBus
:
EventBus
,
eventBus
:
EventBus
,
config
:
NotebookConfig
,
config
:
NotebookConfig
,
)
{
)
{
/**
this
.
_container
=
new
PreactContainer
(
'notebook'
,
()
=>
(
* Un-styled shadow host for the notebook content.
<
NotebookModal
eventBus=
{
eventBus
}
config=
{
config
}
/>
* This isolates the notebook from the page's styles.
));
*/
element
.
append
(
this
.
_container
.
element
);
this
.
_outerContainer
=
document
.
createElement
(
'hypothesis-notebook'
);
this
.
_container
.
render
();
element
.
appendChild
(
this
.
_outerContainer
);
this
.
_shadowRoot
=
createShadowRoot
(
this
.
_outerContainer
);
render
(
<
NotebookModal
eventBus=
{
eventBus
}
config=
{
config
}
/>,
this
.
_shadowRoot
,
);
}
}
destroy
()
{
destroy
()
{
render
(
null
,
this
.
_shadowRoot
);
this
.
_container
.
destroy
();
this
.
_outerContainer
.
remove
();
}
}
}
}
src/annotator/profile.tsx
View file @
aa7aa7a6
import
{
render
}
from
'preact'
;
import
type
{
Destroyable
}
from
'../types/annotator'
;
import
type
{
Destroyable
}
from
'../types/annotator'
;
import
type
{
ProfileConfig
}
from
'./components/ProfileModal'
;
import
type
{
ProfileConfig
}
from
'./components/ProfileModal'
;
import
ProfileModal
from
'./components/ProfileModal'
;
import
ProfileModal
from
'./components/ProfileModal'
;
import
type
{
EventBus
}
from
'./util/emitter'
;
import
type
{
EventBus
}
from
'./util/emitter'
;
import
{
createShadowRoot
}
from
'./util/shadow-root
'
;
import
{
PreactContainer
}
from
'./util/preact-container
'
;
export
class
Profile
implements
Destroyable
{
export
class
Profile
implements
Destroyable
{
private
_outerContainer
:
HTMLElement
;
private
_container
:
PreactContainer
;
public
shadowRoot
:
ShadowRoot
;
constructor
(
element
:
HTMLElement
,
eventBus
:
EventBus
,
config
:
ProfileConfig
)
{
constructor
(
element
:
HTMLElement
,
eventBus
:
EventBus
,
config
:
ProfileConfig
)
{
this
.
_outerContainer
=
document
.
createElement
(
'hypothesis-profile'
);
this
.
_container
=
new
PreactContainer
(
'profile'
,
()
=>
(
element
.
appendChild
(
this
.
_outerContainer
);
<
ProfileModal
eventBus=
{
eventBus
}
config=
{
config
}
/>
this
.
shadowRoot
=
createShadowRoot
(
this
.
_outerContainer
);
));
element
.
append
(
this
.
_container
.
element
);
render
(
this
.
_container
.
render
();
<
ProfileModal
eventBus=
{
eventBus
}
config=
{
config
}
/>,
this
.
shadowRoot
,
);
}
}
destroy
():
void
{
destroy
():
void
{
render
(
null
,
this
.
shadowRoot
);
this
.
_container
.
destroy
();
this
.
_outerContainer
.
remove
();
}
}
}
}
src/annotator/test/notebook-test.js
View file @
aa7aa7a6
...
@@ -47,7 +47,7 @@ describe('Notebook', () => {
...
@@ -47,7 +47,7 @@ describe('Notebook', () => {
it
(
'creates the container'
,
()
=>
{
it
(
'creates the container'
,
()
=>
{
assert
.
isFalse
(
container
.
hasChildNodes
());
assert
.
isFalse
(
container
.
hasChildNodes
());
const
notebook
=
createNotebook
();
const
notebook
=
createNotebook
();
const
shadowRoot
=
notebook
.
_
outerContainer
.
shadowRoot
;
const
shadowRoot
=
notebook
.
_
container
.
element
.
shadowRoot
;
assert
.
isNotNull
(
shadowRoot
);
assert
.
isNotNull
(
shadowRoot
);
assert
.
isNotNull
(
shadowRoot
.
querySelector
(
'#notebook-modal'
));
assert
.
isNotNull
(
shadowRoot
.
querySelector
(
'#notebook-modal'
));
});
});
...
...
src/annotator/test/profile-test.js
View file @
aa7aa7a6
...
@@ -47,7 +47,7 @@ describe('Profile', () => {
...
@@ -47,7 +47,7 @@ describe('Profile', () => {
it
(
'creates the container'
,
()
=>
{
it
(
'creates the container'
,
()
=>
{
assert
.
isFalse
(
container
.
hasChildNodes
());
assert
.
isFalse
(
container
.
hasChildNodes
());
const
profile
=
createProfile
();
const
profile
=
createProfile
();
const
shadowRoot
=
profile
.
_
outerContainer
.
shadowRoot
;
const
shadowRoot
=
profile
.
_
container
.
element
.
shadowRoot
;
assert
.
isNotNull
(
shadowRoot
);
assert
.
isNotNull
(
shadowRoot
);
assert
.
isNotNull
(
shadowRoot
.
querySelector
(
'#profile-modal'
));
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