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 {
toObject
,
toString
,
}
from
'../../shared/type-coercions'
;
/** @typedef {import('../../types/config').ConfigFromAnnotator} ConfigFromAnnotator */
import
type
{
ConfigFromAnnotator
}
from
'../../types/config'
;
/**
* Return the app configuration specified by the frame embedding the Hypothesis
* client.
*
* @param {Window} window
* @return {ConfigFromAnnotator}
*/
export
function
hostPageConfig
(
window
)
{
export
function
hostPageConfig
(
window
:
Window
):
ConfigFromAnnotator
{
const
config
=
parseConfigFragment
(
window
.
location
.
href
);
// Known configuration parameters which we will import from the host page.
...
...
@@ -70,7 +66,7 @@ export function hostPageConfig(window) {
// into the config and this ensures they safely work downstream even if they
// 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.
// - requestConfigFromFrame
// - openSidebar
...
...
@@ -79,20 +75,18 @@ export function hostPageConfig(window) {
// even validate all such config values.
// See https://github.com/hypothesis/client/issues/1968
/** @type {Record<string, (value: unknown) => unknown>} */
const
coercions
=
{
const
coercions
:
Record
<
string
,
(
value
:
unknown
)
=>
unknown
>
=
{
openSidebar
:
toBoolean
,
/** @param {unknown} value */
requestConfigFromFrame
:
value
=>
{
if
(
typeof
value
===
'string'
)
{
// Legacy `requestConfigFromFrame` value which holds only the origin.
return
value
;
}
const
objectVal
=
/** @type {{ origin: unknown, ancestorLevel: unknown }} */
(
toObject
(
value
)
)
;
const
objectVal
=
toObject
(
value
)
as
{
origin
:
unknown
;
ancestorLevel
:
unknown
;
}
;
return
{
origin
:
toString
(
objectVal
.
origin
),
ancestorLevel
:
toInteger
(
objectVal
.
ancestorLevel
),
...
...
@@ -100,9 +94,8 @@ export function hostPageConfig(window) {
},
};
/** @type {Record<string, unknown>} */
const
result
=
{};
for
(
let
[
key
,
value
]
of
Object
.
entries
(
config
))
{
const
result
:
Record
<
string
,
unknown
>
=
{};
for
(
const
[
key
,
value
]
of
Object
.
entries
(
config
))
{
if
(
!
paramWhiteList
.
includes
(
key
))
{
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