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
ed40dd31
Commit
ed40dd31
authored
Jun 19, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jun 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trigger custom DOM event when layout changes
parent
304a9e53
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
1 deletion
+46
-1
events.ts
src/annotator/events.ts
+16
-0
guest.ts
src/annotator/guest.ts
+12
-1
guest-test.js
src/annotator/test/guest-test.js
+18
-0
No files found.
src/annotator/events.ts
0 → 100644
View file @
ed40dd31
import
type
{
SidebarLayout
}
from
'../types/annotator'
;
type
LayoutChangeEventDetail
=
{
isSideBySideActive
:
boolean
;
sidebarLayout
:
SidebarLayout
;
};
export
class
LayoutChangeEvent
extends
CustomEvent
<
LayoutChangeEventDetail
>
{
constructor
(
detail
:
LayoutChangeEventDetail
)
{
super
(
'hypothesis:layoutchange'
,
{
bubbles
:
true
,
cancelable
:
false
,
detail
,
});
}
}
src/annotator/guest.ts
View file @
ed40dd31
...
...
@@ -24,6 +24,7 @@ import type {
import
{
Adder
}
from
'./adder'
;
import
{
TextRange
}
from
'./anchoring/text-range'
;
import
{
BucketBarClient
}
from
'./bucket-bar-client'
;
import
{
LayoutChangeEvent
}
from
'./events'
;
import
{
FeatureFlags
}
from
'./features'
;
import
{
HighlightClusterController
}
from
'./highlight-clusters'
;
import
{
...
...
@@ -453,6 +454,16 @@ export class Guest extends TinyEmitter implements Annotator, Destroyable {
if
(
frameFillsAncestor
(
window
,
hostFrame
))
{
this
.
fitSideBySide
(
sidebarLayout
);
}
// Emit a custom event that the host page can respond to. This is useful
// if the host app needs to change its layout depending on the sidebar's
// visibility and size.
this
.
element
.
dispatchEvent
(
new
LayoutChangeEvent
({
sidebarLayout
,
isSideBySideActive
:
this
.
_sideBySideActive
,
})
);
});
this
.
_hostRPC
.
on
(
'close'
,
()
=>
this
.
emit
(
'hostDisconnected'
));
...
...
@@ -748,7 +759,7 @@ export class Guest extends TinyEmitter implements Annotator, Destroyable {
}
/**
* Scroll to the closest off
screen anchor.
* Scroll to the closest off
-
screen anchor.
*/
private
async
_scrollToClosestOffScreenAnchor
(
tags
:
string
[],
...
...
src/annotator/test/guest-test.js
View file @
ed40dd31
...
...
@@ -259,6 +259,24 @@ describe('Guest', () => {
assert
.
notCalled
(
fakeIntegration
.
fitSideBySide
);
});
it
(
'emits a "hypothesis:layoutchange" DOM event'
,
done
=>
{
const
guest
=
createGuest
();
const
dummyLayout
=
{
expanded
:
true
,
width
:
100
,
height
:
300
,
toolbarWidth
:
10
,
};
guest
.
element
.
addEventListener
(
'hypothesis:layoutchange'
,
e
=>
{
assert
.
equal
(
e
.
detail
.
sidebarLayout
,
dummyLayout
);
// This ensures the test will timeout if this event is not emitted
done
();
});
emitHostEvent
(
'sidebarLayoutChanged'
,
dummyLayout
);
});
});
describe
(
'on "hoverAnnotations" event'
,
()
=>
{
...
...
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