react-rx 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/jest.config.js +0 -5
- package/website/.babelrc +0 -21
- package/website/.prettierrc +0 -7
- package/website/README.mdx +0 -1
- package/website/package.json +0 -84
- package/website/src/@types/babel.d.ts +0 -4
- package/website/src/@types/mdx.d.ts +0 -11
- package/website/src/@types/react-css-burger.d.ts +0 -4
- package/website/src/App.tsx +0 -68
- package/website/src/components/Header.tsx +0 -118
- package/website/src/components/Link.tsx +0 -18
- package/website/src/components/LoadPage.tsx +0 -60
- package/website/src/components/Sidebar.tsx +0 -88
- package/website/src/components/logos/Github.tsx +0 -10
- package/website/src/components/logos/React.tsx +0 -27
- package/website/src/components/logos/ReactRxLogo.tsx +0 -39
- package/website/src/components/logos/RxJs.tsx +0 -69
- package/website/src/components/repl/Checkerboard.tsx +0 -25
- package/website/src/components/repl/CodeBlock.tsx +0 -147
- package/website/src/components/repl/CodeMirror.tsx +0 -37
- package/website/src/components/repl/CodeMirrorMode.tsx +0 -67
- package/website/src/components/repl/EvalCode.tsx +0 -55
- package/website/src/components/repl/Prelude.tsx +0 -50
- package/website/src/components/repl/ShowError.tsx +0 -27
- package/website/src/components/repl/codemirror-lib.ts +0 -8
- package/website/src/components/repl/codemirror-theme.css +0 -131
- package/website/src/components/repl/compile/babel.ts +0 -21
- package/website/src/components/repl/eval/evalCallback.ts +0 -27
- package/website/src/components/repl/eval/evalCode.ts +0 -7
- package/website/src/components/repl/eval/evalExpression.ts +0 -4
- package/website/src/components/repl/eval/evalReactDomRender.ts +0 -23
- package/website/src/components/repl/index.ts +0 -1
- package/website/src/components/repl/runMode.ts +0 -42
- package/website/src/datastores/location.ts +0 -14
- package/website/src/datastores/page.ts +0 -11
- package/website/src/datastores/pageTransition.ts +0 -97
- package/website/src/entries/main.css +0 -2
- package/website/src/entries/main.tsx +0 -6
- package/website/src/examples/FizzBuzz/FizzBuzzExample.tsx +0 -39
- package/website/src/examples/FizzBuzz/index.tsx +0 -9
- package/website/src/examples/_utils/globalScope.ts +0 -45
- package/website/src/examples/animation/AnimationExample.tsx +0 -152
- package/website/src/examples/animation/easings.ts +0 -0
- package/website/src/examples/animation/index.tsx +0 -15
- package/website/src/examples/context/Context.example.jsx +0 -67
- package/website/src/examples/context/index.tsx +0 -9
- package/website/src/examples/errors/Errors.example.jsx +0 -69
- package/website/src/examples/errors/index.tsx +0 -9
- package/website/src/examples/event-handlers/EventHandlersExample.tsx +0 -48
- package/website/src/examples/event-handlers/index.tsx +0 -9
- package/website/src/examples/fetch/FetchExample.jsx +0 -43
- package/website/src/examples/fetch/a.txt +0 -1
- package/website/src/examples/fetch/b.txt +0 -1
- package/website/src/examples/fetch/index.tsx +0 -9
- package/website/src/examples/form-data/FormDataExample.jsx +0 -119
- package/website/src/examples/form-data/index.tsx +0 -12
- package/website/src/examples/form-data/storage.ts +0 -27
- package/website/src/examples/forward-ref/ForwardRefExample.tsx +0 -55
- package/website/src/examples/forward-ref/index.tsx +0 -9
- package/website/src/examples/hello-world/HelloWorld.example.jsx +0 -6
- package/website/src/examples/hello-world/index.tsx +0 -9
- package/website/src/examples/hooks-interop/HooksInterop.example.tsx +0 -42
- package/website/src/examples/hooks-interop/index.tsx +0 -9
- package/website/src/examples/passthrough-props/PassThroughPropsExample.jsx +0 -57
- package/website/src/examples/passthrough-props/index.tsx +0 -11
- package/website/src/examples/reactive-state/ReactiveState.example.jsx +0 -43
- package/website/src/examples/reactive-state/index.ts +0 -9
- package/website/src/examples/readme-examples/README.mdx +0 -0
- package/website/src/examples/readme-examples/index.ts +0 -11
- package/website/src/examples/shared-state/SharedState.example.tsx +0 -59
- package/website/src/examples/shared-state/index.tsx +0 -9
- package/website/src/examples/simple/Counter.example.tsx +0 -14
- package/website/src/examples/simple/index.tsx +0 -9
- package/website/src/examples/sync/Sync.example.tsx +0 -9
- package/website/src/examples/sync/index.tsx +0 -9
- package/website/src/examples/tick/TickExample.jsx +0 -51
- package/website/src/examples/tick/index.ts +0 -9
- package/website/src/examples/todo-app/TodoApp.example.tsx +0 -88
- package/website/src/examples/todo-app/index.tsx +0 -12
- package/website/src/examples/todo-app/storage.ts +0 -27
- package/website/src/examples/use-element/UseElementExample.tsx +0 -70
- package/website/src/examples/use-element/index.tsx +0 -9
- package/website/src/examples/use-observable/search/SearchExample.tsx +0 -82
- package/website/src/examples/use-observable/search/index.tsx +0 -8
- package/website/src/examples/use-observable/use-observable/UseObservableExample.tsx +0 -70
- package/website/src/examples/use-observable/use-observable/index.tsx +0 -9
- package/website/src/index.html +0 -10
- package/website/src/mdx-components.tsx +0 -74
- package/website/src/pages/Api/Api.mdx +0 -134
- package/website/src/pages/Api/ApiPage.tsx +0 -25
- package/website/src/pages/Examples/Examples.tsx +0 -105
- package/website/src/pages/Examples/ExamplesPage.tsx +0 -13
- package/website/src/pages/Guide/Guide.mdx +0 -275
- package/website/src/pages/Guide/GuidePage.tsx +0 -25
- package/website/src/pages/Index/IndexPage.tsx +0 -50
- package/website/src/pages/Index/ReactRxReadme.md +0 -20
- package/website/src/pages/NotFound.tsx +0 -3
- package/website/src/pages/pages.ts +0 -46
- package/website/src/pages/styles.tsx +0 -24
- package/website/src/theme.ts +0 -61
- package/website/src/utils/parseCodeFenceHeader.ts +0 -32
- package/website/tsconfig.json +0 -30
- package/website/vercel.json +0 -4
- package/website/webpack/config.js +0 -5
- package/website/webpack/createConfig.js +0 -95
- package/website/webpack/mdx-toc-loader.js +0 -38
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
|
|
3
|
-
export const RxJSLogo = (props: React.ComponentProps<'svg'>) => (
|
|
4
|
-
<svg
|
|
5
|
-
{...props}
|
|
6
|
-
viewBox="12.1 8.4 262.8 272.2"
|
|
7
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
8
|
-
>
|
|
9
|
-
<linearGradient
|
|
10
|
-
id="a"
|
|
11
|
-
gradientUnits="userSpaceOnUse"
|
|
12
|
-
x1="53.496"
|
|
13
|
-
x2="177.932"
|
|
14
|
-
y1="247.701"
|
|
15
|
-
y2="115.323"
|
|
16
|
-
>
|
|
17
|
-
<stop offset="0" stopColor="#e01d84" />
|
|
18
|
-
<stop offset=".401" stopColor="#df1d85" />
|
|
19
|
-
<stop offset=".77" stopColor="#932c87" />
|
|
20
|
-
<stop offset="1" stopColor="#5d2f88" />
|
|
21
|
-
</linearGradient>
|
|
22
|
-
<radialGradient
|
|
23
|
-
id="b"
|
|
24
|
-
cx="190.456"
|
|
25
|
-
cy="80.2"
|
|
26
|
-
gradientTransform="matrix(1 .00239 -.002 .8362 .16 12.685)"
|
|
27
|
-
gradientUnits="userSpaceOnUse"
|
|
28
|
-
r="121.582"
|
|
29
|
-
>
|
|
30
|
-
<stop offset="0" stopColor="#e01d84" />
|
|
31
|
-
<stop offset=".139" stopColor="#de1e85" />
|
|
32
|
-
<stop offset=".285" stopColor="#d62085" />
|
|
33
|
-
<stop offset=".434" stopColor="#c92386" />
|
|
34
|
-
<stop offset=".586" stopColor="#b72786" />
|
|
35
|
-
<stop offset=".739" stopColor="#9d2b87" />
|
|
36
|
-
<stop offset=".891" stopColor="#7c2e88" />
|
|
37
|
-
<stop offset="1" stopColor="#5d2f88" />
|
|
38
|
-
</radialGradient>
|
|
39
|
-
<linearGradient
|
|
40
|
-
id="c"
|
|
41
|
-
gradientUnits="userSpaceOnUse"
|
|
42
|
-
x1="83.212"
|
|
43
|
-
x2="137.371"
|
|
44
|
-
y1="62.336"
|
|
45
|
-
y2="62.336"
|
|
46
|
-
>
|
|
47
|
-
<stop offset="0" stopColor="#e01d84" />
|
|
48
|
-
<stop offset=".238" stopColor="#da1e85" />
|
|
49
|
-
<stop offset=".658" stopColor="#c72085" />
|
|
50
|
-
<stop offset=".999" stopColor="#b52284" />
|
|
51
|
-
</linearGradient>
|
|
52
|
-
<path
|
|
53
|
-
d="M29.6 175.3c-5.2-16.2-6.7-33.3-3.7-50.9 1.3-7.3 3.3-14.3 5.5-21.4 0 0 13.8-45.3 60.5-66 0 0 16.1-8.5 40.3-9.1 0 0-3.3-3.2-5.4-4.6-11.4-7.6-28.4-10.1-38.7.6-3.1 3.2-5.7 6.7-8.6 9.9-3.3 3.6-7.3 6.6-11.9 8.3-4 1.5-8 1.2-12.1 1.9-4.2.7-8.5 2.2-11.9 4.9-3.7 3-5.2 7-5.6 11.6-.4 3.6-.3 7.3-.5 10.9C37 82 33.6 85 26 90.9c-3.2 2.4-5.9 5.6-7.9 9-6 10.6 3.6 21.6 4.1 32.3.1 2.2-.1 4.4-.9 6.5-.8 2.3-2.4 3.8-3.7 5.7-1.8 2.5-3 5.5-2.5 8.6s2.1 6 3.6 8.7c2.9 4.8 6.5 9.1 10.3 13.2.2 0 .4.2.6.4"
|
|
54
|
-
fill="#e32286"
|
|
55
|
-
/>
|
|
56
|
-
<path
|
|
57
|
-
d="M220.4 213.7c23-10 32.8-27.3 32.8-27.3 21.5-29.3 14.2-60.2 14.2-60.2-13.7 29.8-26.2 38-26.2 38 33.7-51.3.2-82.3.2-82.3 13.7 29.2-4.5 64.8-4.5 64.8-15.3 32.2-37 43.7-37 43.7 24.2 4.5 42-11.8 42-11.8-34.7 37.5-72.3 35.7-72.3 35.7 15.8 17.7 39.5 16.2 39.5 16.2-31 7.3-60.1-3-84-22.9-4.5-3.7-8.8-7.7-12.8-12 0 0-3.6-3.8-4.3-4.8l-.1-.1c-.5 18.5 18.8 35.7 18.8 35.7-24.2-10-35.3-31.7-35.3-31.7s-16.3-27.8-4.5-59.5 47.5-38.5 47.5-38.5c29.5 14.3 54.5 18.8 54.5 18.8 52.7 8.8 49.7-17 49.7-17 .5-22.2-33-45.8-33-45.8C145.9 8.4 91.9 37 91.9 37c-46.7 20.7-60.5 66-60.5 66-2.2 7.1-4.2 14.1-5.5 21.4-5.1 29.7 2.6 57.8 19.3 82.8 26 38.8 68.2 52.2 68.2 52.2 62.5 21.2 105.2-10 105.2-10 39.3-27 47.2-58.2 47.2-58.2-31.7 24.8-45.4 22.5-45.4 22.5zM171.6 67.8c3 0 5.4 2.4 5.4 5.4s-2.4 5.4-5.4 5.4-5.4-2.4-5.4-5.4 2.4-5.4 5.4-5.4z"
|
|
58
|
-
fill="url(#a)"
|
|
59
|
-
/>
|
|
60
|
-
<path
|
|
61
|
-
d="M238.5 98.4c.5-22.2-33-45.8-33-45.8C145.8 8.4 91.8 37 91.8 37c-46.7 20.7-60.5 66-60.5 66-2.7 7.7-5.1 19.5-5.1 19.5-2.9 14.8-1.6 28.5-1.6 28.5 1.2 13.1 4.1 21.9 4.1 21.9 3 9.4 4.4 12.3 4.4 12.3-.1-.3-.6-2.5-.6-2.5s-4.2-20.2-.3-39.6c0 0 3.4-20.2 17.2-35.8 0 0 22.4-31.9 64.1-19.4 0 0 9 3.2 12.1 4.8 3.1 1.5 8.5 3.8 8.5 3.8 29.5 14.3 54.5 18.8 54.5 18.8 52.9 8.9 49.9-16.9 49.9-16.9zm-66.9-19.7c-3 0-5.4-2.4-5.4-5.4s2.4-5.4 5.4-5.4 5.4 2.4 5.4 5.4-2.4 5.4-5.4 5.4z"
|
|
62
|
-
fill="url(#b)"
|
|
63
|
-
/>
|
|
64
|
-
<path
|
|
65
|
-
d="M137.4 58.2l-34.1-10.6c-.2 0-1.2-.5-3 0 0 0-20.1 5.1-16.6 16.1 0 0 2.1 6.9 7.8 13.6l37.5-1.8z"
|
|
66
|
-
fill="url(#c)"
|
|
67
|
-
/>
|
|
68
|
-
</svg>
|
|
69
|
-
)
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import styled from 'styled-components'
|
|
2
|
-
|
|
3
|
-
const CHECKER_SIZE = 60
|
|
4
|
-
const CHECKER_FG = '#252525'
|
|
5
|
-
const CHECKER_BG = '#222'
|
|
6
|
-
|
|
7
|
-
export const Checkerboard = styled.div`
|
|
8
|
-
display: flex;
|
|
9
|
-
/*align-items: center;*/
|
|
10
|
-
justify-content: center;
|
|
11
|
-
color: #fff;
|
|
12
|
-
height: calc(100% - 1.95em);
|
|
13
|
-
width: 100%;
|
|
14
|
-
background-color: ${CHECKER_FG};
|
|
15
|
-
background-image: linear-gradient(45deg, ${CHECKER_BG} 25%, transparent 25%),
|
|
16
|
-
linear-gradient(-45deg, ${CHECKER_BG} 25%, transparent 25%),
|
|
17
|
-
linear-gradient(45deg, transparent 75%, ${CHECKER_BG} 75%),
|
|
18
|
-
linear-gradient(-45deg, transparent 75%, ${CHECKER_BG} 75%);
|
|
19
|
-
background-size: 20px 20px;
|
|
20
|
-
background-position: 0 0, 0 10px, 10px -10px, -10px 0;
|
|
21
|
-
|
|
22
|
-
background-size: ${CHECKER_SIZE}px ${CHECKER_SIZE}px;
|
|
23
|
-
background-position: 0 0, 0 ${CHECKER_SIZE / 2}px,
|
|
24
|
-
${CHECKER_SIZE / 2}px -${CHECKER_SIZE / 2}px, -${CHECKER_SIZE / 2}px 0;
|
|
25
|
-
`
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
|
|
3
|
-
import * as globalScope from '../../examples/_utils/globalScope'
|
|
4
|
-
import {Checkerboard} from './Checkerboard'
|
|
5
|
-
import {ShowError} from './ShowError'
|
|
6
|
-
import {CodeMirror} from './CodeMirror'
|
|
7
|
-
import {compile} from './compile/babel'
|
|
8
|
-
import {evalReactDomRender} from './eval/evalReactDomRender'
|
|
9
|
-
import {Prelude} from './Prelude'
|
|
10
|
-
import {EvalCode} from './EvalCode'
|
|
11
|
-
import './codemirror-lib'
|
|
12
|
-
import styled from 'styled-components'
|
|
13
|
-
|
|
14
|
-
const fs = require('fs')
|
|
15
|
-
|
|
16
|
-
interface Scope {
|
|
17
|
-
[variableName: string]: any
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface Props {
|
|
21
|
-
source: string
|
|
22
|
-
scope?: Scope
|
|
23
|
-
filename: string
|
|
24
|
-
prelude?: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const tryCompile = (code: string, filename: string) => {
|
|
28
|
-
try {
|
|
29
|
-
return [null, compile(code, {filename})?.code || '']
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return [error]
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const evalRender = (code: string, scope: Scope = {}) => {
|
|
36
|
-
return evalReactDomRender(code, {
|
|
37
|
-
...scope,
|
|
38
|
-
...globalScope
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const COMMON_PRELUDE = `import {rxComponent, observeEvent, observeContext, observeState, forwardRef} from 'react-rx'\n${
|
|
43
|
-
fs
|
|
44
|
-
.readFileSync(`${__dirname}/../../examples/_utils/globalScope.ts`, 'utf-8')
|
|
45
|
-
.split('//@endimport')[0]
|
|
46
|
-
}`
|
|
47
|
-
|
|
48
|
-
const stripImports = (str: string) => {
|
|
49
|
-
return str
|
|
50
|
-
.split('//@endimport')
|
|
51
|
-
.slice(-1)[0]
|
|
52
|
-
.trim()
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const CODEMIRROR_MODE = {
|
|
56
|
-
name: 'jsx',
|
|
57
|
-
base: {name: 'javascript', typescript: true}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const CODEMIRROR_OPTIONS = {
|
|
61
|
-
theme: 'custom',
|
|
62
|
-
smartIndent: false,
|
|
63
|
-
tabSize: 2,
|
|
64
|
-
mode: CODEMIRROR_MODE
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const StyledWrapper = styled.div`
|
|
68
|
-
@media (max-width: 979px) {
|
|
69
|
-
display: block;
|
|
70
|
-
}
|
|
71
|
-
@media (min-width: 1280px) {
|
|
72
|
-
display: flex;
|
|
73
|
-
align-items: stretch;
|
|
74
|
-
flex-direction: row;
|
|
75
|
-
}
|
|
76
|
-
`
|
|
77
|
-
const Header = styled.div`
|
|
78
|
-
color: #d8d8d8;
|
|
79
|
-
font-size: 0.9em;
|
|
80
|
-
text-transform: uppercase;
|
|
81
|
-
padding: 0.5em 1.5em;
|
|
82
|
-
`
|
|
83
|
-
const BORDER_RADIUS = 0.5
|
|
84
|
-
const Column = styled.div<{type: 'editor' | 'result'}>`
|
|
85
|
-
@media (min-width: 1280px) {
|
|
86
|
-
border-radius: ${props =>
|
|
87
|
-
props.type === 'editor'
|
|
88
|
-
? `${BORDER_RADIUS}em 0 0 ${BORDER_RADIUS}em`
|
|
89
|
-
: `0 ${BORDER_RADIUS}em ${BORDER_RADIUS}em 0`};
|
|
90
|
-
padding: ${props =>
|
|
91
|
-
props.type === 'editor' ? '0 1px 0.5em 0' : '0 0 0.5em 1px'};
|
|
92
|
-
}
|
|
93
|
-
@media (max-width: 1279px) {
|
|
94
|
-
border-radius: ${props =>
|
|
95
|
-
props.type === 'editor'
|
|
96
|
-
? `${BORDER_RADIUS}em ${BORDER_RADIUS}em 0 0`
|
|
97
|
-
: `0 0 ${BORDER_RADIUS}em ${BORDER_RADIUS}em`};
|
|
98
|
-
padding: ${props => (props.type === 'editor' ? '0' : '0 0 0.5em 0')};
|
|
99
|
-
}
|
|
100
|
-
flex: 0 0 ${props => (props.type === 'editor' ? 60 : 40)}%;
|
|
101
|
-
background: #282c34;
|
|
102
|
-
`
|
|
103
|
-
|
|
104
|
-
export function CodeBlock(props: Props) {
|
|
105
|
-
const source = stripImports(props.source)
|
|
106
|
-
const [code, setCode] = React.useState(source.trim())
|
|
107
|
-
|
|
108
|
-
const [compileError, transformed] = tryCompile(code, props.filename)
|
|
109
|
-
return (
|
|
110
|
-
<StyledWrapper>
|
|
111
|
-
<Column type="editor">
|
|
112
|
-
<Header>Live editor</Header>
|
|
113
|
-
<Prelude
|
|
114
|
-
mode={CODEMIRROR_MODE}
|
|
115
|
-
value={`${COMMON_PRELUDE}${props.prelude ? props.prelude : ''}`}
|
|
116
|
-
/>
|
|
117
|
-
<CodeMirror
|
|
118
|
-
value={code}
|
|
119
|
-
options={CODEMIRROR_OPTIONS}
|
|
120
|
-
onBeforeChange={(editor, data, value) => {
|
|
121
|
-
setCode(value)
|
|
122
|
-
}}
|
|
123
|
-
/>
|
|
124
|
-
</Column>
|
|
125
|
-
<Column type="result">
|
|
126
|
-
<Header>Result</Header>
|
|
127
|
-
<Checkerboard>
|
|
128
|
-
<div style={{padding: '2em'}}>
|
|
129
|
-
{compileError ? (
|
|
130
|
-
<ShowError title="Compile error">
|
|
131
|
-
{compileError.message}
|
|
132
|
-
</ShowError>
|
|
133
|
-
) : (
|
|
134
|
-
<EvalCode
|
|
135
|
-
code={transformed}
|
|
136
|
-
evalWith={src => evalRender(src, props.scope)}
|
|
137
|
-
renderError={error => (
|
|
138
|
-
<ShowError title="Runtime error">{error.message}</ShowError>
|
|
139
|
-
)}
|
|
140
|
-
/>
|
|
141
|
-
)}
|
|
142
|
-
</div>
|
|
143
|
-
</Checkerboard>
|
|
144
|
-
</Column>
|
|
145
|
-
</StyledWrapper>
|
|
146
|
-
)
|
|
147
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import styled from 'styled-components'
|
|
2
|
-
import {Controlled} from 'react-codemirror2'
|
|
3
|
-
|
|
4
|
-
const SCROLLBAR_BG_COLOR = '#1f222a'
|
|
5
|
-
const SCROLLBAR_THUMB_COLOR = '#575757'
|
|
6
|
-
|
|
7
|
-
export const CodeMirror = styled(Controlled)`
|
|
8
|
-
font-size: 0.8em;
|
|
9
|
-
background-color: #282c34;
|
|
10
|
-
|
|
11
|
-
& ::-webkit-scrollbar {
|
|
12
|
-
width: 11px;
|
|
13
|
-
}
|
|
14
|
-
& {
|
|
15
|
-
scrollbar-width: thin;
|
|
16
|
-
scrollbar-color: ${SCROLLBAR_THUMB_COLOR} ${SCROLLBAR_BG_COLOR};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
& ::-webkit-scrollbar-track {
|
|
20
|
-
background: ${SCROLLBAR_BG_COLOR};
|
|
21
|
-
}
|
|
22
|
-
& ::-webkit-scrollbar-thumb {
|
|
23
|
-
background-color: ${SCROLLBAR_THUMB_COLOR} ;
|
|
24
|
-
border-radius: 6px;
|
|
25
|
-
border: 3px solid ${SCROLLBAR_BG_COLOR};
|
|
26
|
-
}
|
|
27
|
-
.CodeMirror-scroll {
|
|
28
|
-
max-height: calc(100vh - 24em);
|
|
29
|
-
}
|
|
30
|
-
.CodeMirror {
|
|
31
|
-
padding: 0.6rem;
|
|
32
|
-
height: auto;
|
|
33
|
-
font-family: source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace;
|
|
34
|
-
-webkit-font-smoothing: antialiased;
|
|
35
|
-
line-height: 1.4em;
|
|
36
|
-
}
|
|
37
|
-
}`
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {rxComponent} from 'react-rx'
|
|
2
|
-
import {map, switchMap, toArray} from 'rxjs/operators'
|
|
3
|
-
import * as React from 'react'
|
|
4
|
-
import styled from 'styled-components'
|
|
5
|
-
import {runMode} from './runMode'
|
|
6
|
-
|
|
7
|
-
export interface CodeMirrorModeProps {
|
|
8
|
-
mode: null | {name: string; base?: any}
|
|
9
|
-
highlighted?: number[]
|
|
10
|
-
children: string
|
|
11
|
-
className?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const CodeMirrorMode = rxComponent<CodeMirrorModeProps>(
|
|
15
|
-
(props$) => {
|
|
16
|
-
return props$.pipe(
|
|
17
|
-
switchMap((props) =>
|
|
18
|
-
runMode(props.children, props.mode).pipe(
|
|
19
|
-
toArray(),
|
|
20
|
-
map((lines, i) => (
|
|
21
|
-
<Code
|
|
22
|
-
key={`line-${i}`}
|
|
23
|
-
className={`cm-s-custom${
|
|
24
|
-
props.className ? ` ${props.className}` : ''
|
|
25
|
-
}`}
|
|
26
|
-
>
|
|
27
|
-
{lines.map((line, lineNo) => (
|
|
28
|
-
<div
|
|
29
|
-
key={`line-${i}-${lineNo}`}
|
|
30
|
-
className={`cm-line${
|
|
31
|
-
(props.highlighted || []).includes(lineNo + 1)
|
|
32
|
-
? ' CodeMirror-selected'
|
|
33
|
-
: ''
|
|
34
|
-
}`}
|
|
35
|
-
>
|
|
36
|
-
{line.map((token, i) =>
|
|
37
|
-
token.style ? (
|
|
38
|
-
<span key={i} className={`cm-${token.style}`}>
|
|
39
|
-
{token.token}
|
|
40
|
-
</span>
|
|
41
|
-
) : (
|
|
42
|
-
token.token
|
|
43
|
-
)
|
|
44
|
-
)}
|
|
45
|
-
</div>
|
|
46
|
-
))}
|
|
47
|
-
</Code>
|
|
48
|
-
))
|
|
49
|
-
)
|
|
50
|
-
)
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
const Code = styled.div`
|
|
56
|
-
font-size: 0.8em;
|
|
57
|
-
|
|
58
|
-
background-color: rgb(40, 44, 52);
|
|
59
|
-
color: #fff;
|
|
60
|
-
margin: 0;
|
|
61
|
-
white-space: pre;
|
|
62
|
-
overflow: auto;
|
|
63
|
-
padding: 0.9rem;
|
|
64
|
-
font-family: source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace;
|
|
65
|
-
-webkit-font-smoothing: antialiased;
|
|
66
|
-
line-height: 1.4em;
|
|
67
|
-
`
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
|
|
3
|
-
interface EvalErrorBoundaryProps {
|
|
4
|
-
code: string
|
|
5
|
-
renderError: (error: Error) => React.ReactNode
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface EvalErrorBoundaryState {
|
|
9
|
-
error: Error | null
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class EvalErrorBoundary extends React.Component<
|
|
13
|
-
EvalErrorBoundaryProps,
|
|
14
|
-
EvalErrorBoundaryState
|
|
15
|
-
> {
|
|
16
|
-
state: EvalErrorBoundaryState = {error: null}
|
|
17
|
-
|
|
18
|
-
static getDerivedStateFromError(error: Error) {
|
|
19
|
-
return {error}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
componentDidUpdate(
|
|
23
|
-
prevProps: Readonly<EvalErrorBoundaryProps>,
|
|
24
|
-
prevState: Readonly<EvalErrorBoundaryState>
|
|
25
|
-
) {
|
|
26
|
-
if (prevProps.code !== this.props.code) {
|
|
27
|
-
this.setState({error: null})
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
render() {
|
|
32
|
-
const {error} = this.state
|
|
33
|
-
return error ? this.props.renderError(error) : this.props.children
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type Runner = (code: string) => React.ReactNode
|
|
38
|
-
|
|
39
|
-
const Eval = (props: {with: Runner; code: string}) => (
|
|
40
|
-
<>{props.with(props.code)}</>
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
interface Props {
|
|
44
|
-
code: string
|
|
45
|
-
renderError: (error: Error) => React.ReactNode
|
|
46
|
-
evalWith: Runner
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function EvalCode(props: Props) {
|
|
50
|
-
return (
|
|
51
|
-
<EvalErrorBoundary code={props.code} renderError={props.renderError}>
|
|
52
|
-
<Eval with={props.evalWith} code={props.code} />
|
|
53
|
-
</EvalErrorBoundary>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
import styled from 'styled-components'
|
|
3
|
-
import {CodeMirrorMode} from './CodeMirrorMode'
|
|
4
|
-
|
|
5
|
-
const Details = styled.details`
|
|
6
|
-
text-align: right;
|
|
7
|
-
white-space: pre;
|
|
8
|
-
background-color: #1f222a;
|
|
9
|
-
line-height: 1.4em;
|
|
10
|
-
border: 0;
|
|
11
|
-
box-sizing: border-box;
|
|
12
|
-
`
|
|
13
|
-
|
|
14
|
-
const Summary = styled.summary`
|
|
15
|
-
background-color: #242831;
|
|
16
|
-
display: inline-block;
|
|
17
|
-
color: #65737e;
|
|
18
|
-
font-size: 0.8em;
|
|
19
|
-
border-radius: 2px 2px 0 0;
|
|
20
|
-
margin: 1px 0 0 0;
|
|
21
|
-
text-transform: uppercase;
|
|
22
|
-
padding: 0.4em 0.9em;
|
|
23
|
-
font-family: source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace;
|
|
24
|
-
-webkit-font-smoothing: antialiased;
|
|
25
|
-
outline: none;
|
|
26
|
-
`
|
|
27
|
-
|
|
28
|
-
const StyledCodeMirrorMode = styled(CodeMirrorMode)`
|
|
29
|
-
opacity: 0.7;
|
|
30
|
-
text-align: left;
|
|
31
|
-
`
|
|
32
|
-
|
|
33
|
-
interface Props {
|
|
34
|
-
mode: any
|
|
35
|
-
value: string
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const Prelude = (props: Props) => {
|
|
39
|
-
const [isOpen, setOpen] = React.useState(false)
|
|
40
|
-
return (
|
|
41
|
-
<Details>
|
|
42
|
-
<Summary onClick={() => setOpen(current => !current)}>
|
|
43
|
-
{isOpen ? 'hide prelude' : 'show prelude'}
|
|
44
|
-
</Summary>
|
|
45
|
-
<StyledCodeMirrorMode mode={props.mode}>
|
|
46
|
-
{props.value}
|
|
47
|
-
</StyledCodeMirrorMode>
|
|
48
|
-
</Details>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
import styled from 'styled-components'
|
|
3
|
-
|
|
4
|
-
interface Props {
|
|
5
|
-
title: string
|
|
6
|
-
children: React.ReactNode
|
|
7
|
-
className?: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const Pre = styled.pre`
|
|
11
|
-
color: rgb(255, 100, 100);
|
|
12
|
-
`
|
|
13
|
-
|
|
14
|
-
const Heading = styled.h2`
|
|
15
|
-
padding: 3px:
|
|
16
|
-
color: #fff
|
|
17
|
-
padding: 8px;
|
|
18
|
-
`
|
|
19
|
-
|
|
20
|
-
export function ShowError(props: Props) {
|
|
21
|
-
return (
|
|
22
|
-
<div className={props.className}>
|
|
23
|
-
<Heading>{props.title}</Heading>
|
|
24
|
-
<Pre>{props.children}</Pre>
|
|
25
|
-
</div>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as codemirror from 'codemirror'
|
|
2
|
-
import 'codemirror/mode/javascript/javascript'
|
|
3
|
-
import 'codemirror/mode/jsx/jsx'
|
|
4
|
-
import 'codemirror/addon/selection/active-line'
|
|
5
|
-
import 'codemirror/addon/edit/matchbrackets'
|
|
6
|
-
import 'codemirror/addon/edit/matchtags'
|
|
7
|
-
|
|
8
|
-
export default codemirror
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
.cm-s-custom.CodeMirror {
|
|
2
|
-
background: rgb(32, 35, 42);
|
|
3
|
-
color: #f8f8f2;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.cm-s-custom div.CodeMirror-selected {
|
|
7
|
-
background: rgba(101, 115, 126, 0.33);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.cm-s-custom .CodeMirror-line::selection,
|
|
11
|
-
.cm-s-custom .CodeMirror-line > span::selection,
|
|
12
|
-
.cm-s-custom .CodeMirror-line > span > span::selection {
|
|
13
|
-
background: rgba(101, 115, 126, 0.33);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.cm-s-custom .CodeMirror-line::-moz-selection,
|
|
17
|
-
.cm-s-custom .CodeMirror-line > span::-moz-selection,
|
|
18
|
-
.cm-s-custom .CodeMirror-line > span > span::-moz-selection {
|
|
19
|
-
background: rgba(101, 115, 126, 0.33);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.cm-s-custom .CodeMirror-gutters {
|
|
23
|
-
background: #304148;
|
|
24
|
-
border-right: 10px;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.cm-s-custom .CodeMirror-guttermarker {
|
|
28
|
-
color: white;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.cm-s-custom .CodeMirror-guttermarker-subtle {
|
|
32
|
-
color: #d0d0d0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.cm-s-custom .CodeMirror-linenumber {
|
|
36
|
-
color: #d0d0d0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.cm-s-custom .CodeMirror-cursor {
|
|
40
|
-
border-left: 1px solid #f8f8f0;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.cm-s-custom span.cm-comment {
|
|
44
|
-
color: #65737e;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.cm-s-custom span.cm-atom {
|
|
48
|
-
color: #c594c5;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.cm-s-custom span.cm-number {
|
|
52
|
-
color: #f99157;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.cm-s-custom span.cm-type {
|
|
56
|
-
color: #48aab5;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.cm-s-custom span.cm-property {
|
|
60
|
-
color: rgb(121, 182, 242);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.cm-s-custom span.cm-attribute,
|
|
64
|
-
.cm-s-custom span.cm-keyword {
|
|
65
|
-
color: rgb(197, 165, 197);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.cm-s-custom span.cm-builtin {
|
|
69
|
-
color: #66d9ef;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.cm-s-custom span.cm-string {
|
|
73
|
-
color: #8dc891;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
.cm-s-custom span.cm-variable {
|
|
77
|
-
color: #d8d8d8;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.cm-s-custom span.cm-variable-2,
|
|
81
|
-
.cm-s-custom span.cm-variable-3 {
|
|
82
|
-
color: #f8f8f2;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.cm-s-custom span.cm-def {
|
|
86
|
-
color: #fac863;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
.cm-s-custom span.cm-bracket {
|
|
90
|
-
color: #5fb3b3;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.cm-s-custom span.cm-tag {
|
|
94
|
-
color: rgb(252, 146, 158);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.cm-s-custom span.cm-tag.cm-bracket {
|
|
98
|
-
color: rgb(88, 200, 252);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.cm-s-custom span.cm-header {
|
|
102
|
-
color: #c594c5;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.cm-s-custom span.cm-link {
|
|
106
|
-
color: #c594c5;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.cm-s-custom span.cm-error {
|
|
110
|
-
background: #c594c5;
|
|
111
|
-
color: #f8f8f0;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
.cm-s-custom .CodeMirror-activeline-background {
|
|
115
|
-
background: rgba(101, 115, 126, 0.1);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
.cm-s-custom .CodeMirror-nonmatchingbracket {
|
|
119
|
-
color: #fa87b5 !important;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
.cm-s-custom .CodeMirror-matchingbracket {
|
|
123
|
-
color: #fa87b5 !important;
|
|
124
|
-
background-color: rgba(255, 255, 255, 0.22) !important;
|
|
125
|
-
border-radius: 2px;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
.cm-s-custom .CodeMirror-matchingtag {
|
|
129
|
-
background-color: rgba(255, 255, 255, 0.1) !important;
|
|
130
|
-
border-radius: 2px;
|
|
131
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as babel from '@babel/standalone'
|
|
2
|
-
import transformTs from '@babel/plugin-transform-typescript'
|
|
3
|
-
import transformJsx from '@babel/plugin-transform-react-jsx'
|
|
4
|
-
import optionalChaining from '@babel/plugin-proposal-optional-chaining'
|
|
5
|
-
|
|
6
|
-
interface Options {
|
|
7
|
-
filename?: string
|
|
8
|
-
plugins?: any[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function compile(code: string, options: Options = {}) {
|
|
12
|
-
return babel.transform(code, {
|
|
13
|
-
filename: options.filename || 'Unknown.tsx',
|
|
14
|
-
plugins: [
|
|
15
|
-
...(options.plugins || []),
|
|
16
|
-
optionalChaining,
|
|
17
|
-
[transformTs, {allExtensions: true, isTSX: true}],
|
|
18
|
-
transformJsx
|
|
19
|
-
]
|
|
20
|
-
})
|
|
21
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {evalCode} from './evalCode'
|
|
2
|
-
|
|
3
|
-
export const evalCallback = (
|
|
4
|
-
code: string,
|
|
5
|
-
callbackName = 'callback',
|
|
6
|
-
scope = {}
|
|
7
|
-
): any => {
|
|
8
|
-
let renderCount = 0
|
|
9
|
-
let renderRes = null
|
|
10
|
-
|
|
11
|
-
const callback = (arg: any) => {
|
|
12
|
-
renderCount++
|
|
13
|
-
renderRes = arg
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
evalCode(code, {...scope, [callbackName]: callback})
|
|
17
|
-
|
|
18
|
-
if (renderCount === 0) {
|
|
19
|
-
throw new Error(`${callbackName}() was not called`)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (renderCount > 1) {
|
|
23
|
-
throw new Error(`${callbackName}() was called more than once`)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return renderRes
|
|
27
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const evalCode = (code: string, scope: {[v: string]: any}) => {
|
|
2
|
-
const scopeKeys = Object.keys(scope)
|
|
3
|
-
const scopeValues = scopeKeys.map(key => scope[key])
|
|
4
|
-
// eslint-disable-next-line no-new-func
|
|
5
|
-
const res = new Function(...scopeKeys, code)
|
|
6
|
-
return res(...scopeValues)
|
|
7
|
-
}
|