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
ac984496
Commit
ac984496
authored
Mar 13, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate annotation-sharing to TypeScript
parent
6baca3e7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
26 deletions
+10
-26
annotation-sharing.ts
src/sidebar/helpers/annotation-sharing.ts
+10
-26
No files found.
src/sidebar/helpers/annotation-sharing.
j
s
→
src/sidebar/helpers/annotation-sharing.
t
s
View file @
ac984496
/**
* @typedef {import('../../types/api').Annotation} Annotation
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
import
type
{
Annotation
}
from
'../../types/api'
;
import
type
{
SidebarSettings
}
from
'../../types/config'
;
import
{
serviceConfig
}
from
'../config/service-config'
;
/**
...
...
@@ -16,11 +14,8 @@ import { serviceConfig } from '../config/service-config';
*
* Note that `html` links are not provided by the service for third-party
* annotations.
*
* @param {Annotation} annotation
* @return {string|null}
*/
export
function
annotationSharingLink
(
annotation
)
{
export
function
annotationSharingLink
(
annotation
:
Annotation
):
string
|
null
{
if
(
isShareableURI
(
annotation
.
uri
))
{
return
annotation
.
links
?.
incontext
??
annotation
.
links
?.
html
??
null
;
}
else
{
...
...
@@ -32,12 +27,11 @@ export function annotationSharingLink(annotation) {
* Generate a URI for sharing: a bouncer link built to share annotations in
* a specific group (groupID) on a specific document (documentURI). If the
* `documentURI` provided is not a web-accessible URL, no link is generated.
*
* @param {string} documentURI
* @param {string} groupID
* @return {string|null}
*/
export
function
pageSharingLink
(
documentURI
,
groupID
)
{
export
function
pageSharingLink
(
documentURI
:
string
,
groupID
:
string
):
string
|
null
{
if
(
!
isShareableURI
(
documentURI
))
{
return
null
;
}
...
...
@@ -50,26 +44,16 @@ export function pageSharingLink(documentURI, groupID) {
* Are annotations made against `uri` meaningfully shareable? The
* target URI needs to be available on the web, which here is determined by
* a protocol of `http` or `https`.
*
* @param {string} uri
* @return {boolean}
*/
export
function
isShareableURI
(
uri
)
{
export
function
isShareableURI
(
uri
:
string
):
boolean
{
return
/^http
(
s
?)
:/i
.
test
(
uri
);
}
/**
* Is the sharing of annotations enabled? Check for any defined `serviceConfig`,
* but default to `true` if none found.
*
* @param {SidebarSettings} settings
* @return {boolean}
*/
export
function
sharingEnabled
(
settings
)
{
export
function
sharingEnabled
(
settings
:
SidebarSettings
):
boolean
{
const
service
=
serviceConfig
(
settings
);
if
(
service
?.
enableShareLinks
===
false
)
{
return
false
;
}
return
true
;
return
service
?.
enableShareLinks
!==
false
;
}
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