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
bce4c251
Commit
bce4c251
authored
Apr 20, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Apr 20, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate host-config module to TS
parent
9110ab0b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
17 deletions
+10
-17
host-config.ts
src/sidebar/config/host-config.ts
+10
-17
No files found.
src/sidebar/config/host-config.
j
s
→
src/sidebar/config/host-config.
t
s
View file @
bce4c251
...
@@ -5,17 +5,13 @@ import {
...
@@ -5,17 +5,13 @@ import {
toObject
,
toObject
,
toString
,
toString
,
}
from
'../../shared/type-coercions'
;
}
from
'../../shared/type-coercions'
;
import
type
{
ConfigFromAnnotator
}
from
'../../types/config'
;
/** @typedef {import('../../types/config').ConfigFromAnnotator} ConfigFromAnnotator */
/**
/**
* Return the app configuration specified by the frame embedding the Hypothesis
* Return the app configuration specified by the frame embedding the Hypothesis
* client.
* client.
*
* @param {Window} window
* @return {ConfigFromAnnotator}
*/
*/
export
function
hostPageConfig
(
window
)
{
export
function
hostPageConfig
(
window
:
Window
):
ConfigFromAnnotator
{
const
config
=
parseConfigFragment
(
window
.
location
.
href
);
const
config
=
parseConfigFragment
(
window
.
location
.
href
);
// Known configuration parameters which we will import from the host page.
// Known configuration parameters which we will import from the host page.
...
@@ -70,7 +66,7 @@ export function hostPageConfig(window) {
...
@@ -70,7 +66,7 @@ export function hostPageConfig(window) {
// into the config and this ensures they safely work downstream even if they
// into the config and this ensures they safely work downstream even if they
// are incorrect.
// are incorrect.
//
//
// Currently
we are only handling the following config values do
to the fact
// Currently
, we are only handling the following config values due
to the fact
// that via3 will soon discontinue passing boolean types or integer types.
// that via3 will soon discontinue passing boolean types or integer types.
// - requestConfigFromFrame
// - requestConfigFromFrame
// - openSidebar
// - openSidebar
...
@@ -79,20 +75,18 @@ export function hostPageConfig(window) {
...
@@ -79,20 +75,18 @@ export function hostPageConfig(window) {
// even validate all such config values.
// even validate all such config values.
// See https://github.com/hypothesis/client/issues/1968
// See https://github.com/hypothesis/client/issues/1968
/** @type {Record<string, (value: unknown) => unknown>} */
const
coercions
:
Record
<
string
,
(
value
:
unknown
)
=>
unknown
>
=
{
const
coercions
=
{
openSidebar
:
toBoolean
,
openSidebar
:
toBoolean
,
/** @param {unknown} value */
requestConfigFromFrame
:
value
=>
{
requestConfigFromFrame
:
value
=>
{
if
(
typeof
value
===
'string'
)
{
if
(
typeof
value
===
'string'
)
{
// Legacy `requestConfigFromFrame` value which holds only the origin.
// Legacy `requestConfigFromFrame` value which holds only the origin.
return
value
;
return
value
;
}
}
const
objectVal
=
const
objectVal
=
toObject
(
value
)
as
{
/** @type {{ origin: unknown, ancestorLevel: unknown }} */
(
origin
:
unknown
;
toObject
(
value
)
ancestorLevel
:
unknown
;
)
;
}
;
return
{
return
{
origin
:
toString
(
objectVal
.
origin
),
origin
:
toString
(
objectVal
.
origin
),
ancestorLevel
:
toInteger
(
objectVal
.
ancestorLevel
),
ancestorLevel
:
toInteger
(
objectVal
.
ancestorLevel
),
...
@@ -100,9 +94,8 @@ export function hostPageConfig(window) {
...
@@ -100,9 +94,8 @@ export function hostPageConfig(window) {
},
},
};
};
/** @type {Record<string, unknown>} */
const
result
:
Record
<
string
,
unknown
>
=
{};
const
result
=
{};
for
(
const
[
key
,
value
]
of
Object
.
entries
(
config
))
{
for
(
let
[
key
,
value
]
of
Object
.
entries
(
config
))
{
if
(
!
paramWhiteList
.
includes
(
key
))
{
if
(
!
paramWhiteList
.
includes
(
key
))
{
continue
;
continue
;
}
}
...
...
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