This repository has been archived by the owner on May 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widget): Add deep object extraction and fix styles
- Loading branch information
Showing
9 changed files
with
169 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { StateSelector } from 'zustand'; | ||
import { | ||
ColorSchemeState, | ||
useColorScheme | ||
} from '@wuespace/telestion-client-common'; | ||
|
||
// color scheme selector | ||
const selector: StateSelector< | ||
ColorSchemeState, | ||
ColorSchemeState['colorScheme'] | ||
> = state => state.colorScheme; | ||
|
||
export function useDarkColorScheme(): boolean { | ||
const colorScheme = useColorScheme(selector); | ||
|
||
switch (colorScheme) { | ||
case 'system': | ||
return matchMedia('(prefers-color-scheme: dark)').matches; | ||
case 'light': | ||
return false; | ||
case 'dark': | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { JsonSerializable } from '@wuespace/telestion-client-types'; | ||
import { isObj } from './utils'; | ||
|
||
export function extractValue(obj: JsonSerializable, key: string): number { | ||
// replace [$1] with .$1 and split on . | ||
const accessors = key.replace(/\[(\w+)\]/g, '.$1').split('.'); | ||
|
||
let reduce = obj; | ||
|
||
for (let i = 0; i < accessors.length; i++) { | ||
if (!isObj(reduce)) { | ||
throw new TypeError( | ||
`Invalid message body received. (iteration: ${i}, accessor: ${ | ||
accessors[i] | ||
}, expected: object, received: ${JSON.stringify(reduce)}` | ||
); | ||
} | ||
|
||
reduce = reduce[accessors[i]]; | ||
} | ||
|
||
if (typeof reduce !== 'number') { | ||
throw new TypeError( | ||
`Invalid value received. (access expected: number, received: ${JSON.stringify( | ||
reduce | ||
)}` | ||
); | ||
} | ||
|
||
return reduce; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters