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
3deaed68
Commit
3deaed68
authored
Nov 22, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert annotator entry point to TypeScript
parent
146898d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
26 deletions
+14
-26
rollup.config.mjs
rollup.config.mjs
+1
-1
index.ts
src/annotator/index.ts
+13
-25
No files found.
rollup.config.mjs
View file @
3deaed68
...
@@ -101,7 +101,7 @@ function bundleConfig({ name, entry, format = 'es' }) {
...
@@ -101,7 +101,7 @@ function bundleConfig({ name, entry, format = 'es' }) {
export
default
[
export
default
[
bundleConfig
({
bundleConfig
({
name
:
'annotator'
,
name
:
'annotator'
,
entry
:
'src/annotator/index.
j
s'
,
entry
:
'src/annotator/index.
t
s'
,
// The annotator bundle is created as a non-module script because module
// The annotator bundle is created as a non-module script because module
// scripts are not supported in Safari in XHTML documents.
// scripts are not supported in Safari in XHTML documents.
...
...
src/annotator/index.
j
s
→
src/annotator/index.
t
s
View file @
3deaed68
...
@@ -13,34 +13,27 @@ import {
...
@@ -13,34 +13,27 @@ import {
PortProvider
,
PortProvider
,
installPortCloseWorkaroundForSafari
,
installPortCloseWorkaroundForSafari
,
}
from
'../shared/messaging'
;
}
from
'../shared/messaging'
;
import
type
{
Destroyable
}
from
'../types/annotator'
;
import
{
getConfig
}
from
'./config/index'
;
import
{
getConfig
}
from
'./config/index'
;
import
type
{
NotebookConfig
}
from
'./components/NotebookModal'
;
import
{
Guest
}
from
'./guest'
;
import
{
Guest
}
from
'./guest'
;
import
type
{
GuestConfig
}
from
'./guest'
;
import
{
HypothesisInjector
}
from
'./hypothesis-injector'
;
import
{
HypothesisInjector
}
from
'./hypothesis-injector'
;
import
type
{
InjectConfig
}
from
'./hypothesis-injector'
;
import
{
import
{
VitalSourceInjector
,
VitalSourceInjector
,
vitalSourceFrameRole
,
vitalSourceFrameRole
,
}
from
'./integrations/vitalsource'
;
}
from
'./integrations/vitalsource'
;
import
{
Notebook
}
from
'./notebook'
;
import
{
Notebook
}
from
'./notebook'
;
import
{
Sidebar
}
from
'./sidebar'
;
import
{
Sidebar
}
from
'./sidebar'
;
import
type
{
SidebarConfig
}
from
'./sidebar'
;
import
{
EventBus
}
from
'./util/emitter'
;
import
{
EventBus
}
from
'./util/emitter'
;
/** @typedef {import('../types/annotator').Destroyable} Destroyable */
// Look up the URL of the sidebar. This element is added to the page by the
// Look up the URL of the sidebar. This element is added to the page by the
// boot script before the "annotator" bundle loads.
// boot script before the "annotator" bundle loads.
const
sidebarLinkElement
=
/** @type {HTMLLinkElement} */
(
const
sidebarLinkElement
=
document
.
querySelector
(
document
.
querySelector
(
'link[type="application/annotator+html"][rel="sidebar"]'
'link[type="application/annotator+html"][rel="sidebar"]'
)
as
HTMLLinkElement
;
)
);
/**
* @typedef {import('./components/NotebookModal').NotebookConfig} NotebookConfig
* @typedef {import('./guest').GuestConfig} GuestConfig
* @typedef {import('./hypothesis-injector').InjectConfig} InjectConfig
* @typedef {import('./sidebar').SidebarConfig} SidebarConfig
* @typedef {import('./sidebar').SidebarContainerConfig} SidebarContainerConfig
*/
/**
/**
* Entry point for the part of the Hypothesis client that runs in the page being
* Entry point for the part of the Hypothesis client that runs in the page being
...
@@ -55,21 +48,18 @@ const sidebarLinkElement = /** @type {HTMLLinkElement} */ (
...
@@ -55,21 +48,18 @@ const sidebarLinkElement = /** @type {HTMLLinkElement} */ (
* client is initially loaded, is also the only guest frame.
* client is initially loaded, is also the only guest frame.
*/
*/
function
init
()
{
function
init
()
{
const
annotatorConfig
=
/** @type {GuestConfig & InjectConfig} */
(
const
annotatorConfig
=
getConfig
(
'annotator'
)
as
GuestConfig
&
InjectConfig
;
getConfig
(
'annotator'
)
);
const
hostFrame
=
annotatorConfig
.
subFrameIdentifier
?
window
.
parent
:
window
;
const
hostFrame
=
annotatorConfig
.
subFrameIdentifier
?
window
.
parent
:
window
;
/** @type {Destroyable[]} */
const
destroyables
=
[]
as
Destroyable
[];
const
destroyables
=
[];
if
(
hostFrame
===
window
)
{
if
(
hostFrame
===
window
)
{
// Ensure port "close" notifications from eg. guest frames are delivered properly.
// Ensure port "close" notifications from eg. guest frames are delivered properly.
const
removeWorkaround
=
installPortCloseWorkaroundForSafari
();
const
removeWorkaround
=
installPortCloseWorkaroundForSafari
();
destroyables
.
push
({
destroy
:
removeWorkaround
});
destroyables
.
push
({
destroy
:
removeWorkaround
});
const
sidebarConfig
=
/** @type {SidebarConfig} */
(
getConfig
(
'sidebar'
))
;
const
sidebarConfig
=
getConfig
(
'sidebar'
)
as
SidebarConfig
;
const
hypothesisAppsOrigin
=
new
URL
(
sidebarConfig
.
sidebarAppUrl
).
origin
;
const
hypothesisAppsOrigin
=
new
URL
(
sidebarConfig
.
sidebarAppUrl
).
origin
;
const
portProvider
=
new
PortProvider
(
hypothesisAppsOrigin
);
const
portProvider
=
new
PortProvider
(
hypothesisAppsOrigin
);
...
@@ -79,7 +69,7 @@ function init() {
...
@@ -79,7 +69,7 @@ function init() {
const
notebook
=
new
Notebook
(
const
notebook
=
new
Notebook
(
document
.
body
,
document
.
body
,
eventBus
,
eventBus
,
/** @type {NotebookConfig} */
(
getConfig
(
'notebook'
))
getConfig
(
'notebook'
)
as
NotebookConfig
);
);
portProvider
.
on
(
'frameConnected'
,
(
source
,
port
)
=>
portProvider
.
on
(
'frameConnected'
,
(
source
,
port
)
=>
...
@@ -116,10 +106,8 @@ function init() {
...
@@ -116,10 +106,8 @@ function init() {
/**
/**
* Returns a Promise that resolves when the document has loaded (but subresources
* Returns a Promise that resolves when the document has loaded (but subresources
* may still be loading).
* may still be loading).
*
* @return {Promise<void>}
*/
*/
function
documentReady
()
{
function
documentReady
()
:
Promise
<
void
>
{
return
new
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
if
(
document
.
readyState
!==
'loading'
)
{
if
(
document
.
readyState
!==
'loading'
)
{
resolve
();
resolve
();
...
...
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