-
-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-theme-minimal-blog): Lazy load code component (#167)
* add loadable to code component of minimal blog * add bundle analyser to example * chore(deps): update dependency @types/theme-ui to ^0.2.5 (#161) * chore(deps): update dependency lerna to ^3.19.0 (#163) * chore(deps): update dependency ts-jest to ^24.2.0 (#164) * chore(deps): update linting & formatting + typescript (#165) * fix(deps): update gatsby (#166) Co-authored-by: null <29139614+renovate[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8b5cd32
commit fbfedee
Showing
7 changed files
with
270 additions
and
20 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
declare module "@theme-ui/components" | ||
declare module "@theme-ui/color" | ||
declare module "lodash.kebabcase" | ||
declare module "lodash.kebabcase" | ||
declare module "@loadable/component" |
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,149 @@ | ||
import * as React from "react" | ||
|
||
export type Language = | ||
| "markup" | ||
| "bash" | ||
| "clike" | ||
| "c" | ||
| "cpp" | ||
| "css" | ||
| "javascript" | ||
| "jsx" | ||
| "coffeescript" | ||
| "actionscript" | ||
| "css-extr" | ||
| "diff" | ||
| "git" | ||
| "go" | ||
| "graphql" | ||
| "handlebars" | ||
| "json" | ||
| "less" | ||
| "makefile" | ||
| "markdown" | ||
| "objectivec" | ||
| "ocaml" | ||
| "python" | ||
| "reason" | ||
| "sass" | ||
| "scss" | ||
| "sql" | ||
| "stylus" | ||
| "tsx" | ||
| "typescript" | ||
| "wasm" | ||
| "yaml" | ||
|
||
type Token = { | ||
types: string[] | ||
content: string | ||
empty?: boolean | ||
} | ||
|
||
type PrismGrammar = { | ||
[key: string]: any | ||
} | ||
|
||
type LanguageDict = { [lang in Language]: PrismGrammar } | ||
|
||
type PrismLib = { | ||
languages: LanguageDict | ||
tokenize: (code: string, grammar: PrismGrammar, language: Language) => PrismToken[] | string[] | ||
highlight: (code: string, grammar: PrismGrammar, language: Language) => string | ||
} | ||
|
||
type PrismThemeEntry = { | ||
color?: string | ||
backgroundColor?: string | ||
fontStyle?: "normal" | "italic" | ||
fontWeight?: "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | ||
textDecorationLine?: "none" | "underline" | "line-through" | "underline line-through" | ||
opacity?: number | ||
[styleKey: string]: string | number | void | ||
} | ||
|
||
type PrismTheme = { | ||
plain: PrismThemeEntry | ||
styles: Array<{ | ||
types: string[] | ||
style: PrismThemeEntry | ||
languages?: Language[] | ||
}> | ||
} | ||
|
||
type ThemeDict = { | ||
root: StyleObj | ||
plain: StyleObj | ||
[type: string]: StyleObj | ||
} | ||
|
||
type PrismToken = { | ||
type: string | ||
content: Array<PrismToken | string> | string | ||
} | ||
|
||
type StyleObj = { | ||
[key: string]: string | number | null | ||
} | ||
|
||
type LineInputProps = { | ||
key?: React.Key | ||
style?: StyleObj | ||
className?: string | ||
line: Token[] | ||
[otherProp: string]: any | ||
} | ||
|
||
type LineOutputProps = { | ||
key?: React.Key | ||
style?: StyleObj | ||
className: string | ||
[otherProps: string]: any | ||
} | ||
|
||
type TokenInputProps = { | ||
key?: React.Key | ||
style?: StyleObj | ||
className?: string | ||
token: Token | ||
[otherProp: string]: any | ||
} | ||
|
||
type TokenOutputProps = { | ||
key?: React.Key | ||
style?: StyleObj | ||
className: string | ||
children: string | ||
[otherProp: string]: any | ||
} | ||
|
||
type RenderProps = { | ||
tokens: Token[][] | ||
className: string | ||
style: StyleObj | ||
getLineProps: (input: LineInputProps) => LineOutputProps | ||
getTokenProps: (input: TokenInputProps) => TokenOutputProps | ||
} | ||
|
||
type DefaultProps = { | ||
Prism: PrismLib | ||
theme: PrismTheme | ||
} | ||
|
||
interface HighlightProps { | ||
Prism: PrismLib | ||
theme?: PrismTheme | ||
language: Language | ||
code: string | ||
children: (props: RenderProps) => React.ReactNode | ||
} | ||
|
||
export interface HighlightInnerProps { | ||
className: string | ||
style: StyleObj | ||
tokens: Token[][] | ||
themeDict: ThemeDict | ||
getLineProps: (lineInputProps: LineInputProps) => LineOutputProps | ||
getStyleForToken: (token: Token) => { [inlineStyle: string]: string } | ||
getTokenProps: (tokenInputPropsL: TokenInputProps) => TokenOutputProps | ||
} |
Oops, something went wrong.