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
Hide 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';
import
{
configFuncSettingsFrom
}
from
'./config-func-settings-from'
;
import
{
urlFromLinkTag
}
from
'./url-from-link-tag'
;
/**
* @typedef SettingsGetters
* @prop {string|null} annotations
* @prop {string|null} query
* @prop {string|null} group
* @prop {string} showHighlights
* @prop {string} clientUrl
* @prop {string} sidebarAppUrl
* @prop {string} notebookAppUrl
* @prop {string} profileAppUrl
* @prop {(name: string) => unknown} hostPageSetting
*/
export
type
SettingsGetters
=
{
annotations
:
string
|
null
;
query
:
string
|
null
;
group
:
string
|
null
;
showHighlights
:
string
;
clientUrl
:
string
;
sidebarAppUrl
:
string
;
notebookAppUrl
:
string
;
profileAppUrl
:
string
;
hostPageSetting
:
(
name
:
string
)
=>
unknown
;
};
/**
* 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
;
}
/**
* @param {Window} window_
* @return {SettingsGetters}
*/
export
function
settingsFrom
(
window_
)
{
export
function
settingsFrom
(
window_
:
Window
):
SettingsGetters
{
// Prioritize the `window.hypothesisConfig` function over the JSON format
// Via uses `window.hypothesisConfig` and makes it non-configurable and non-writable.
// In addition, Via sets the `ignoreOtherConfiguration` option to prevent configuration merging.
const
configFuncSettings
=
configFuncSettingsFrom
(
window_
);
/** @type {Record<string, unknown>} */
let
jsonConfigs
;
if
(
toBoolean
(
configFuncSettings
.
ignoreOtherConfiguration
))
{
jsonConfigs
=
{};
}
else
{
jsonConfigs
=
parseJsonConfig
(
window_
.
document
);
}
const
jsonConfigs
:
Record
<
string
,
unknown
>
=
toBoolean
(
configFuncSettings
.
ignoreOtherConfiguration
)
?
{}
:
parseJsonConfig
(
window_
.
document
);
/**
* Return the `#annotations:*` ID from the given URL's fragment.
...
...
@@ -50,9 +41,9 @@ export function settingsFrom(window_) {
* If the URL contains a `#annotations:<ANNOTATION_ID>` fragment then return
* 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. */
function
annotationsFromURL
()
{
// Annotation IDs are url-safe-base64 identifiers
...
...
@@ -75,9 +66,9 @@ export function settingsFrom(window_) {
* If the URL contains a `#annotations:group:<GROUP_ID>` fragment then return
* 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
()
{
const
groupFragmentMatch
=
window_
.
location
.
href
.
match
(
/#annotations:group:
([
A-Za-z0-9_-
]
+
)
$/
...
...
@@ -119,9 +110,9 @@ export function settingsFrom(window_) {
*
* 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. */
function
queryFromURL
()
{
const
queryFragmentMatch
=
window_
.
location
.
href
.
match
(
...
...
@@ -148,9 +139,9 @@ export function settingsFrom(window_) {
*
* 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
))
{
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