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
2b09fdc9
Commit
2b09fdc9
authored
Mar 31, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Apr 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate annotator config settings to TypeScript
parent
06a0a5bb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
35 deletions
+26
-35
settings.ts
src/annotator/config/settings.ts
+26
-35
No files found.
src/annotator/config/settings.
j
s
→
src/annotator/config/settings.
t
s
View file @
2b09fdc9
...
@@ -4,45 +4,36 @@ import { toBoolean } from '../../shared/type-coercions';
...
@@ -4,45 +4,36 @@ import { toBoolean } from '../../shared/type-coercions';
import
{
configFuncSettingsFrom
}
from
'./config-func-settings-from'
;
import
{
configFuncSettingsFrom
}
from
'./config-func-settings-from'
;
import
{
urlFromLinkTag
}
from
'./url-from-link-tag'
;
import
{
urlFromLinkTag
}
from
'./url-from-link-tag'
;
/**
export
type
SettingsGetters
=
{
* @typedef SettingsGetters
annotations
:
string
|
null
;
* @prop {string|null} annotations
query
:
string
|
null
;
* @prop {string|null} query
group
:
string
|
null
;
* @prop {string|null} group
showHighlights
:
string
;
* @prop {string} showHighlights
clientUrl
:
string
;
* @prop {string} clientUrl
sidebarAppUrl
:
string
;
* @prop {string} sidebarAppUrl
notebookAppUrl
:
string
;
* @prop {string} notebookAppUrl
profileAppUrl
:
string
;
* @prop {string} profileAppUrl
hostPageSetting
:
(
name
:
string
)
=>
unknown
;
* @prop {(name: string) => unknown} hostPageSetting
};
*/
/**
/**
* Discard a setting if it is not a string.
* Discard a setting if it is not a string.
*
* @param {unknown} value
*/
*/
function
checkIfString
(
value
)
{
function
checkIfString
(
value
:
unknown
):
string
|
null
{
return
typeof
value
===
'string'
?
value
:
null
;
return
typeof
value
===
'string'
?
value
:
null
;
}
}
/**
export
function
settingsFrom
(
window_
:
Window
):
SettingsGetters
{
* @param {Window} window_
* @return {SettingsGetters}
*/
export
function
settingsFrom
(
window_
)
{
// Prioritize the `window.hypothesisConfig` function over the JSON format
// Prioritize the `window.hypothesisConfig` function over the JSON format
// Via uses `window.hypothesisConfig` and makes it non-configurable and non-writable.
// Via uses `window.hypothesisConfig` and makes it non-configurable and non-writable.
// In addition, Via sets the `ignoreOtherConfiguration` option to prevent configuration merging.
// In addition, Via sets the `ignoreOtherConfiguration` option to prevent configuration merging.
const
configFuncSettings
=
configFuncSettingsFrom
(
window_
);
const
configFuncSettings
=
configFuncSettingsFrom
(
window_
);
/** @type {Record<string, unknown>} */
const
jsonConfigs
:
Record
<
string
,
unknown
>
=
toBoolean
(
let
jsonConfigs
;
configFuncSettings
.
ignoreOtherConfiguration
if
(
toBoolean
(
configFuncSettings
.
ignoreOtherConfiguration
))
{
)
jsonConfigs
=
{};
?
{}
}
else
{
:
parseJsonConfig
(
window_
.
document
);
jsonConfigs
=
parseJsonConfig
(
window_
.
document
);
}
/**
/**
* Return the `#annotations:*` ID from the given URL's fragment.
* Return the `#annotations:*` ID from the given URL's fragment.
...
@@ -50,9 +41,9 @@ export function settingsFrom(window_) {
...
@@ -50,9 +41,9 @@ export function settingsFrom(window_) {
* If the URL contains a `#annotations:<ANNOTATION_ID>` fragment then return
* If the URL contains a `#annotations:<ANNOTATION_ID>` fragment then return
* the annotation ID extracted from the fragment. Otherwise return `null`.
* the annotation ID extracted from the fragment. Otherwise return `null`.
*
*
* @return
{string|null} -
The extracted ID, or null.
* @return The extracted ID, or null.
*/
*/
function
annotations
()
{
function
annotations
()
:
string
|
null
{
/** Return the annotations from the URL, or null. */
/** Return the annotations from the URL, or null. */
function
annotationsFromURL
()
{
function
annotationsFromURL
()
{
// Annotation IDs are url-safe-base64 identifiers
// Annotation IDs are url-safe-base64 identifiers
...
@@ -75,9 +66,9 @@ export function settingsFrom(window_) {
...
@@ -75,9 +66,9 @@ export function settingsFrom(window_) {
* If the URL contains a `#annotations:group:<GROUP_ID>` fragment then return
* If the URL contains a `#annotations:group:<GROUP_ID>` fragment then return
* the group ID extracted from the fragment. Otherwise return `null`.
* the group ID extracted from the fragment. Otherwise return `null`.
*
*
* @return
{string|null} -
The extracted ID, or null.
* @return The extracted ID, or null.
*/
*/
function
group
()
{
function
group
()
:
string
|
null
{
function
groupFromURL
()
{
function
groupFromURL
()
{
const
groupFragmentMatch
=
window_
.
location
.
href
.
match
(
const
groupFragmentMatch
=
window_
.
location
.
href
.
match
(
/#annotations:group:
([
A-Za-z0-9_-
]
+
)
$/
/#annotations:group:
([
A-Za-z0-9_-
]
+
)
$/
...
@@ -119,9 +110,9 @@ export function settingsFrom(window_) {
...
@@ -119,9 +110,9 @@ export function settingsFrom(window_) {
*
*
* Otherwise return null.
* Otherwise return null.
*
*
* @return
{string|null} -
The config.query setting, or null.
* @return The config.query setting, or null.
*/
*/
function
query
()
{
function
query
()
:
string
|
null
{
/** Return the query from the URL, or null. */
/** Return the query from the URL, or null. */
function
queryFromURL
()
{
function
queryFromURL
()
{
const
queryFragmentMatch
=
window_
.
location
.
href
.
match
(
const
queryFragmentMatch
=
window_
.
location
.
href
.
match
(
...
@@ -148,9 +139,9 @@ export function settingsFrom(window_) {
...
@@ -148,9 +139,9 @@ export function settingsFrom(window_) {
*
*
* If the setting is not found in either source, then return undefined.
* If the setting is not found in either source, then return undefined.
*
*
* @param
{string}
name - Unique name of the setting
* @param name - Unique name of the setting
*/
*/
function
hostPageSetting
(
name
)
{
function
hostPageSetting
(
name
:
string
)
{
if
(
hasOwn
(
configFuncSettings
,
name
))
{
if
(
hasOwn
(
configFuncSettings
,
name
))
{
return
configFuncSettings
[
name
];
return
configFuncSettings
[
name
];
}
}
...
...
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