react-rx 1.0.0-beta.6 → 2.0.0

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.
Files changed (128) hide show
  1. package/.idea/compiler.xml +1 -1
  2. package/.idea/inspectionProfiles/Project_Default.xml +1 -0
  3. package/.idea/markdown.xml +9 -0
  4. package/.idea/misc.xml +0 -6
  5. package/dist/cjs/WithObservable.js +3 -3
  6. package/dist/cjs/displayName.js +1 -1
  7. package/dist/cjs/reactiveComponent.js +6 -6
  8. package/dist/cjs/useAsObservable.js +10 -18
  9. package/dist/cjs/useObservable.js +26 -31
  10. package/dist/cjs/useObservableCallback.js +4 -4
  11. package/dist/cjs/useWithObservable.js +2 -2
  12. package/dist/cjs/utils.js +7 -7
  13. package/dist/cjs/withPropsStream.js +8 -4
  14. package/dist/es2015/useAsObservable.js +10 -18
  15. package/dist/es2015/useObservable.js +24 -31
  16. package/dist/esm/displayName.js +1 -1
  17. package/dist/esm/useAsObservable.js +10 -18
  18. package/dist/esm/useObservable.js +26 -31
  19. package/package.json +5 -3
  20. package/src/useAsObservable.ts +13 -18
  21. package/src/useObservable.ts +39 -34
  22. package/.idea/workspace.xml +0 -228
  23. package/jest.config.js +0 -5
  24. package/website/.babelrc +0 -21
  25. package/website/.prettierrc +0 -7
  26. package/website/README.mdx +0 -1
  27. package/website/package.json +0 -84
  28. package/website/src/@types/babel.d.ts +0 -4
  29. package/website/src/@types/mdx.d.ts +0 -11
  30. package/website/src/@types/react-css-burger.d.ts +0 -4
  31. package/website/src/App.tsx +0 -68
  32. package/website/src/components/Header.tsx +0 -118
  33. package/website/src/components/Link.tsx +0 -18
  34. package/website/src/components/LoadPage.tsx +0 -60
  35. package/website/src/components/Sidebar.tsx +0 -88
  36. package/website/src/components/logos/Github.tsx +0 -10
  37. package/website/src/components/logos/React.tsx +0 -27
  38. package/website/src/components/logos/ReactRxLogo.tsx +0 -39
  39. package/website/src/components/logos/RxJs.tsx +0 -69
  40. package/website/src/components/repl/Checkerboard.tsx +0 -25
  41. package/website/src/components/repl/CodeBlock.tsx +0 -147
  42. package/website/src/components/repl/CodeMirror.tsx +0 -37
  43. package/website/src/components/repl/CodeMirrorMode.tsx +0 -67
  44. package/website/src/components/repl/EvalCode.tsx +0 -55
  45. package/website/src/components/repl/Prelude.tsx +0 -50
  46. package/website/src/components/repl/ShowError.tsx +0 -27
  47. package/website/src/components/repl/codemirror-lib.ts +0 -8
  48. package/website/src/components/repl/codemirror-theme.css +0 -131
  49. package/website/src/components/repl/compile/babel.ts +0 -21
  50. package/website/src/components/repl/eval/evalCallback.ts +0 -27
  51. package/website/src/components/repl/eval/evalCode.ts +0 -7
  52. package/website/src/components/repl/eval/evalExpression.ts +0 -4
  53. package/website/src/components/repl/eval/evalReactDomRender.ts +0 -23
  54. package/website/src/components/repl/index.ts +0 -1
  55. package/website/src/components/repl/runMode.ts +0 -42
  56. package/website/src/datastores/location.ts +0 -14
  57. package/website/src/datastores/page.ts +0 -11
  58. package/website/src/datastores/pageTransition.ts +0 -97
  59. package/website/src/entries/main.css +0 -2
  60. package/website/src/entries/main.tsx +0 -6
  61. package/website/src/examples/FizzBuzz/FizzBuzzExample.tsx +0 -39
  62. package/website/src/examples/FizzBuzz/index.tsx +0 -9
  63. package/website/src/examples/_utils/globalScope.ts +0 -45
  64. package/website/src/examples/animation/AnimationExample.tsx +0 -152
  65. package/website/src/examples/animation/easings.ts +0 -0
  66. package/website/src/examples/animation/index.tsx +0 -15
  67. package/website/src/examples/context/Context.example.jsx +0 -67
  68. package/website/src/examples/context/index.tsx +0 -9
  69. package/website/src/examples/errors/Errors.example.jsx +0 -69
  70. package/website/src/examples/errors/index.tsx +0 -9
  71. package/website/src/examples/event-handlers/EventHandlersExample.tsx +0 -48
  72. package/website/src/examples/event-handlers/index.tsx +0 -9
  73. package/website/src/examples/fetch/FetchExample.jsx +0 -43
  74. package/website/src/examples/fetch/a.txt +0 -1
  75. package/website/src/examples/fetch/b.txt +0 -1
  76. package/website/src/examples/fetch/index.tsx +0 -9
  77. package/website/src/examples/form-data/FormDataExample.jsx +0 -119
  78. package/website/src/examples/form-data/index.tsx +0 -12
  79. package/website/src/examples/form-data/storage.ts +0 -27
  80. package/website/src/examples/forward-ref/ForwardRefExample.tsx +0 -55
  81. package/website/src/examples/forward-ref/index.tsx +0 -9
  82. package/website/src/examples/hello-world/HelloWorld.example.jsx +0 -6
  83. package/website/src/examples/hello-world/index.tsx +0 -9
  84. package/website/src/examples/hooks-interop/HooksInterop.example.tsx +0 -42
  85. package/website/src/examples/hooks-interop/index.tsx +0 -9
  86. package/website/src/examples/passthrough-props/PassThroughPropsExample.jsx +0 -57
  87. package/website/src/examples/passthrough-props/index.tsx +0 -11
  88. package/website/src/examples/reactive-state/ReactiveState.example.jsx +0 -43
  89. package/website/src/examples/reactive-state/index.ts +0 -9
  90. package/website/src/examples/readme-examples/README.mdx +0 -0
  91. package/website/src/examples/readme-examples/index.ts +0 -11
  92. package/website/src/examples/shared-state/SharedState.example.tsx +0 -59
  93. package/website/src/examples/shared-state/index.tsx +0 -9
  94. package/website/src/examples/simple/Counter.example.tsx +0 -14
  95. package/website/src/examples/simple/index.tsx +0 -9
  96. package/website/src/examples/sync/Sync.example.tsx +0 -9
  97. package/website/src/examples/sync/index.tsx +0 -9
  98. package/website/src/examples/tick/TickExample.jsx +0 -51
  99. package/website/src/examples/tick/index.ts +0 -9
  100. package/website/src/examples/todo-app/TodoApp.example.tsx +0 -88
  101. package/website/src/examples/todo-app/index.tsx +0 -12
  102. package/website/src/examples/todo-app/storage.ts +0 -27
  103. package/website/src/examples/use-element/UseElementExample.tsx +0 -70
  104. package/website/src/examples/use-element/index.tsx +0 -9
  105. package/website/src/examples/use-observable/search/SearchExample.tsx +0 -82
  106. package/website/src/examples/use-observable/search/index.tsx +0 -8
  107. package/website/src/examples/use-observable/use-observable/UseObservableExample.tsx +0 -70
  108. package/website/src/examples/use-observable/use-observable/index.tsx +0 -9
  109. package/website/src/index.html +0 -10
  110. package/website/src/mdx-components.tsx +0 -74
  111. package/website/src/pages/Api/Api.mdx +0 -134
  112. package/website/src/pages/Api/ApiPage.tsx +0 -25
  113. package/website/src/pages/Examples/Examples.tsx +0 -105
  114. package/website/src/pages/Examples/ExamplesPage.tsx +0 -13
  115. package/website/src/pages/Guide/Guide.mdx +0 -275
  116. package/website/src/pages/Guide/GuidePage.tsx +0 -25
  117. package/website/src/pages/Index/IndexPage.tsx +0 -50
  118. package/website/src/pages/Index/ReactRxReadme.md +0 -20
  119. package/website/src/pages/NotFound.tsx +0 -3
  120. package/website/src/pages/pages.ts +0 -46
  121. package/website/src/pages/styles.tsx +0 -24
  122. package/website/src/theme.ts +0 -61
  123. package/website/src/utils/parseCodeFenceHeader.ts +0 -32
  124. package/website/tsconfig.json +0 -30
  125. package/website/vercel.json +0 -4
  126. package/website/webpack/config.js +0 -5
  127. package/website/webpack/createConfig.js +0 -95
  128. package/website/webpack/mdx-toc-loader.js +0 -38
@@ -1,275 +0,0 @@
1
- # Reactive components
2
-
3
- ## Intro
4
-
5
- A _reactive component_ is a React component that turns an observable of props into an observable of [values React can render](https://reactjs.org/docs/react-component.html#render) (e.g. element, strings, fragments)
6
-
7
- A _reactive component_ enables you to create components that composes different RxJS streams into a single render function, making your view purely a function of state and providing an explicit dataflow that's easier to reason about.
8
-
9
- The `rxComponent()` utility wraps a function component that is very similar to a regular React function component, with two notable differences:
10
-
11
- 1. Instead of being called with a _props object_, it is called with an _Observable of props_
12
- 2. Instead of returning _renderable values_, it returns an _Observable of renderable values_
13
-
14
- Here's an example component that fetches some text from the url passed as the `url` prop:
15
-
16
- ```jsx
17
- import * as ReactRx from 'react-rx'
18
-
19
- const Fetch = ReactRx.component((props$) =>
20
- props$.pipe(
21
- switchMap((props) => fetch(props.url).then((response) => response.text())),
22
- map((responseText) => <>Response is {responseText}</>)
23
- )
24
- )
25
-
26
- // Usage
27
- ReactDOM.render(<Fetch url="/some/url" />, container)
28
- ```
29
-
30
- Instead of a _function_, `rxComponent` can also take an `Observable` as argument as long as it's an observable of [something React can render](https://reactjs.org/docs/react-component.html#render). This is neat when you have component that doesn't take any props, but still depends on values coming from an `Observable`:
31
-
32
- ```jsx
33
- import * as ReactRx from 'react-rx'
34
-
35
- const Counter = ReactRx.component(
36
- timer(0, 100).pipe(map((counter) => <>The number is {counter}</>))
37
- )
38
-
39
- ReactDOM.render(<Counter />, container)
40
- ```
41
-
42
- ## Local component state
43
-
44
- Instead of calling `React.useState()` directly, you can also use the `useState` function exported from this package. Instead of the actual state value it will return an observable representing the state changes, along with a function to update it. Here's the example above rewritten to use `useState` from this package instead.
45
-
46
- ```jsx{4}
47
- import {rxComponent, useState} from 'react-rx'
48
-
49
- const Counter = rxComponent(() => {
50
- const [count$, setCount] = useState(0)
51
-
52
- return count$.pipe(
53
- map((currentCount) => (
54
- <>
55
- <div>Click count: {currentCount}</div>
56
- <button onClick={() => setCount(currentCount + 1)}>Click!</button>
57
- </>
58
- ))
59
- )
60
- })
61
- ```
62
-
63
- ## Responding to events
64
-
65
- Sometimes your state comes as a function of an event triggered by the user. Let's say you want to display the mouse cursors x,y position as the user moves the mouse inside a component. This can be done by using the `useEvent()` utility:
66
-
67
- ```js{4}
68
- import {useEvent, rxComponent} from 'react-rx'
69
-
70
- const MouseTracker = rxComponent(() => {
71
- const [mouseMove$, onMouseMove] = event()
72
-
73
- return mouseMove$.pipe(
74
- map((event) => (
75
- <>
76
- <div onMouseMove={handleMouseMove}>Hover me!</div>
77
- <pre>
78
- x={event.screenX},y={event.screenY}
79
- </pre>
80
- </>
81
- ))
82
- )
83
- })
84
- ```
85
-
86
- ### Gotcha: Initial render
87
-
88
- The above example will not produce any DOM before a mousemove event has been triggered, and the mouse event can't be triggered before the DOM has been rendered, which puts us in a catch-22 situation. To cope with it, we can make the observable start by emitting an initial value for the event.
89
-
90
- We can do this by using the `startWith` operator that comes with RxJS:
91
-
92
- ```js{8}
93
- import {rxComponent, useEvent} from 'react-rx'
94
- import {map, startWith} from 'rxjs/operators'
95
-
96
- const MouseTracker = rxComponent(() => {
97
- const [mouseMove$, handleMouseMove] = useEvent()
98
-
99
- return mouseMove$.pipe(
100
- startWith(null),
101
- map((event) => (
102
- <>
103
- <div onMouseMove={handleMouseMove}>Hover me!</div>
104
- {event && (
105
- <pre>
106
- x={event.screenX},y={event.screenY}
107
- </pre>
108
- )}
109
- </>
110
- ))
111
- )
112
- })
113
- ```
114
-
115
- This means the `event` argument now can also be `null` so we also need to guard about that in our render function.
116
-
117
- ## Consuming React hooks
118
-
119
- Reactive components will not automatically re-render when a `useState()` value updates. In order to respond to state updates from React hooks, the value needs to be converted to an observable. This is done by wrapping it using the `toObservable()` utility before combining it with the returned observable. Here's an example:
120
-
121
- ```jsx{4}
122
- import {rxComponent} from 'react-rx
123
-
124
- const Counter = rxComponent(props$ => {
125
- const [count, setCount] = React.useState(0)
126
-
127
- return toObservable(count).pipe(
128
- map(currentCount => (
129
- <>
130
- <div>Click count: {currentCount}</div>
131
- <button onClick={() => setCount(currentCount + 1)}>Click!</button>
132
- </>
133
- )))
134
- })
135
- ```
136
-
137
- The `toObservable` function makes it possible to consume community provided React hooks inside a reactive component. However, this package also export some utility functions that wraps regular hooks so you can use them with less boilerplate, for example, the `ReactRx.useState` function described above.
138
-
139
- ### React ecosystem interop
140
-
141
- Using `reactiveComponent` in a project with regular react components or components installed from the React ecosystem just works. Although it's advisable to not consume React hooks inside a `reactiveComponent`, but it's still possible by turning a value into an observable with `useAsObservable`. Here's an example:
142
-
143
- ```tsx
144
- import {useAsObservable, rxComponent} from 'react-rx
145
-
146
- function useClickCounter(): [number, () => void] {
147
- const [clickCount, setClickCount] = React.useState(0)
148
- const inc = React.useCallback(() => setClickCount((c) => c + 1), [])
149
-
150
- return [clickCount, inc]
151
- }
152
-
153
- const HooksInteropExample = rxComponent(() => {
154
- const [clickCount, inc] = useClickCounter()
155
-
156
- // This is required in order to turn clickCount into an observable value
157
- const click$ = useAsObservable(clickCount)
158
-
159
- return click$.pipe(
160
- map((clickCount) => (
161
- <button onClick={inc}>
162
- This button has been clicked {clickCount} times
163
- </button>
164
- ))
165
- )
166
- })
167
- ```
168
-
169
- # Observable Hooks
170
-
171
- ## useObservable()
172
-
173
- Use observables in React components with the `useObservable` hook.
174
-
175
- If you need to subscribe to an observable in your component, this hook will give you the current value from it
176
-
177
- Example:
178
-
179
- ```jsx
180
- import {useObservable} from 'react-rx'
181
- import {interval} from 'rxjs'
182
-
183
- function MyComponent(props) {
184
- const number = useObservable(interval(100), 0)
185
-
186
- return <>The number is {number}</>
187
- }
188
- ```
189
-
190
- The `initialValue` argument is optional. If its omitted, the value returned from `useObservable` may be `null` initially. If the observable emits a value _synchronously_ at subscription time, that value will be used as the initial value, and any `initialValue` passed as argument to `useObservable` will be ignored:
191
-
192
- ```jsx
193
- import {of} from 'rxjs'
194
- import {useObservable} from 'react-rx'
195
-
196
- // This component will never render "Hello mars!" since the observable emits "world" synchronously.
197
- function MyComponent(props) {
198
- const planet = useObservable(of('world'), 'mars')
199
-
200
- return <>Hello {planet}!</>
201
- }
202
- ```
203
-
204
- ## useObservableState()
205
-
206
- If you need to represent some piece of state as an observable and also want the ability to change this state during the lifetime of the component, `useObservableState` is for you. It acts like `React.useState()`, only that it returns an observable representing changes to the value instead of the value itself. The callback/setter returned acts like a the regular callback you would otherwise get from `React.useState`. This is useful when you want to compose the state change together with other observables.
207
-
208
- Note: this is exact same hook as the `useState()` function described in the section about Reactive Component above, it's only been exported under a different and more explicit name to distinguish better from `React.useState()`.
209
-
210
- Here's an example of a component that count numbers at a certain speed, allowing the user to adjust the counting speed by adjusting a slider:
211
-
212
- ```jsx
213
- import {useObservableState} from 'react-rx'
214
-
215
- function MyComponent(props) {
216
- const [speed$, setSpeed] = useObservableState(1)
217
-
218
- const count$ = speed$.pipe(
219
- switchMap((speed) => timer(0, 1000 / speed)),
220
- scan((count) => count + 1, 0)
221
- )
222
-
223
- const currentSpeed = useObservable(speed$)
224
- const currentCount = useObservable(count$)
225
-
226
- return (
227
- <div>
228
- <div>Counter value: {currentCount}</div>
229
- <div>Counting speed: {Math.round((1 / currentSpeed) * 100) / 100}s</div>
230
- <input
231
- type="range"
232
- value={currentSpeed}
233
- min={1}
234
- max={10}
235
- onChange={(event) => setSpeed(Number(event.currentTarget.value))}
236
- />
237
- </div>
238
- )
239
- }
240
- ```
241
-
242
- ## useObservableEvent()
243
-
244
- This creates an event handler and an observable that represents calls to that handler.
245
-
246
- Here's an example of a component thad displays the current value from a range input:
247
-
248
- ```jsx
249
- import {useObservableEvent} from 'react-rx'
250
-
251
- const ShowSliderValue = () => {
252
- const [onSliderChange$, onSliderChange] = useObservableEvent()
253
-
254
- const sliderValue = useObservable(
255
- onSliderChange$.pipe(
256
- map((event) => event.currentTarget.value),
257
- map((value) => Number(value)),
258
- startWith(1)
259
- )
260
- )
261
-
262
- return (
263
- <>
264
- <input
265
- type="range"
266
- value={sliderValue}
267
- min={1}
268
- max={10}
269
- onChange={onSliderChange}
270
- />
271
- <div>Value is: {sliderValue}</div>
272
- </>
273
- )
274
- }
275
- ```
@@ -1,25 +0,0 @@
1
- import {Header} from '../../components/Header'
2
- import MDXContent, {Toc} from './Guide.mdx'
3
- import * as React from 'react'
4
- import {MDXProvider} from '@mdx-js/react'
5
- import {components, tocComponents} from '../../mdx-components'
6
- import {Container, Content} from '../styles'
7
- import {Sidebar} from '../../components/Sidebar'
8
-
9
- export const GuidePage = () => (
10
- <>
11
- <Header />
12
- <Container>
13
- <Sidebar heading="Guide">
14
- <MDXProvider components={tocComponents}>
15
- <Toc />
16
- </MDXProvider>
17
- </Sidebar>
18
- <Content>
19
- <MDXProvider components={components}>
20
- <MDXContent />
21
- </MDXProvider>
22
- </Content>
23
- </Container>
24
- </>
25
- )
@@ -1,50 +0,0 @@
1
- import * as React from 'react'
2
- import {Header} from '../../components/Header'
3
- import {MDXProvider} from '@mdx-js/react'
4
- import ReactRxReadme from './ReactRxReadme.md'
5
- import {components} from '../../mdx-components'
6
- import {ReactRxLogo} from '../../components/logos/ReactRxLogo'
7
- import styled from 'styled-components'
8
- import {COLORS} from '../../theme'
9
-
10
- const Content = styled.div`
11
- margin-top: 5em;
12
- `
13
- const ContentInner = styled.div`
14
- padding: 1em 1em;
15
- `
16
- const Cover = styled.div`
17
- background: ${COLORS.shadow};
18
- color: ${COLORS.background};
19
- padding-top: 2em;
20
- font-size: 2em;
21
- display: flex;
22
- flex-direction: row;
23
- justify-content: center;
24
- h1 {
25
- padding: 0 0 0 0.1em;
26
- }
27
- `
28
-
29
- const Subsection = styled.div`
30
- display: flex;
31
- flex-direction: column;
32
- `
33
- export const IndexPage = () => (
34
- <>
35
- <Header />
36
- <Content>
37
- <Cover>
38
- <ReactRxLogo size="4em" />
39
- <h1>ReactRx</h1>
40
- </Cover>
41
- <ContentInner>
42
- <Subsection>
43
- <MDXProvider components={components}>
44
- <ReactRxReadme />
45
- </MDXProvider>
46
- </Subsection>
47
- </ContentInner>
48
- </Content>
49
- </>
50
- )
@@ -1,20 +0,0 @@
1
- > Hooks and utilities for combining React with RxJS Observables
2
-
3
- Features:
4
-
5
- - Works well with Observables emitting values synchronously. You don't pay the re-render-on-mount tax.
6
- - Lightweight. Implemented on top of a small React Hook based core.
7
- - Full TypeScript support.
8
-
9
- This package offers two slightly different utilities for working with RxJS and React:
10
-
11
- - A set of utilities for creating _Reactive components_
12
- - A set of React hooks for using with observables with React
13
-
14
- Although they share a lot of similarities, and reactiveComponent is built on top of `useObservable` are not intended to be used together inside the same component as they represent two different programming styles.
15
-
16
- ---
17
-
18
- - [Reactive components](https://react-rx.dev/guide#reactive-components)
19
- - [Observable hooks](https://react-rx.dev/guide#observable-hooks)
20
- - [Code examples](https://react-rx.dev/examples)
@@ -1,3 +0,0 @@
1
- import React from 'react'
2
-
3
- export const NotFoundPage = () => <h2>Not found!</h2>
@@ -1,46 +0,0 @@
1
- import {NotFoundPage} from './NotFound'
2
-
3
- export interface Page {
4
- id: string
5
- title: string
6
- route: string
7
- load: () => Promise<React.ComponentType<any>>
8
- }
9
-
10
- function get<T extends {}, K extends keyof T>(key: K): (res: T) => T[K] {
11
- return (res: T) => res[key]
12
- }
13
-
14
- export const pages: Page[] = [
15
- {
16
- id: 'home',
17
- title: 'Home',
18
- route: '/',
19
- load: () => import('./Index/IndexPage').then(get('IndexPage'))
20
- },
21
- {
22
- id: 'guide',
23
- title: 'Guide',
24
- route: '/guide',
25
- load: () => import('./Guide/GuidePage').then(get('GuidePage'))
26
- },
27
- {
28
- id: 'api',
29
- title: 'API',
30
- route: '/api',
31
- load: () => import('./Api/ApiPage').then(get('ApiPage'))
32
- },
33
- {
34
- id: 'examples',
35
- title: 'Examples',
36
- route: '/examples',
37
- load: () => import('./Examples/ExamplesPage').then(get('ExamplesPage'))
38
- }
39
- ]
40
-
41
- export const NOT_FOUND: Page = {
42
- id: 'not-found',
43
- title: 'Not found',
44
- route: '',
45
- load: () => Promise.resolve(NotFoundPage)
46
- }
@@ -1,24 +0,0 @@
1
- import styled from 'styled-components'
2
- import * as React from 'react'
3
-
4
- export const Container = styled.div`
5
- margin-top: 7em;
6
- display: flex;
7
- flex-direction: row;
8
- `
9
-
10
- export const ContentWrapper = styled.div`
11
- width: 100%;
12
- margin: 0;
13
- `
14
-
15
- export const ContentInner = styled.div`
16
- padding: 0 1em;
17
- `
18
- export const Content = (props: {children: React.ReactNode}) => {
19
- return (
20
- <ContentWrapper>
21
- <ContentInner>{props.children}</ContentInner>
22
- </ContentWrapper>
23
- )
24
- }
@@ -1,61 +0,0 @@
1
- const SIZES = {
2
- xsmall: {min: 0, max: 599},
3
- small: {min: 600, max: 779},
4
- medium: {min: 780, max: 979},
5
- large: {min: 980, max: 1279},
6
- xlarge: {min: 1280, max: 1339},
7
- xxlarge: {min: 1340, max: Infinity}
8
- }
9
-
10
- export type Size = keyof typeof SIZES
11
-
12
- export const media = {
13
- between(smallKey: Size, largeKey: Size, excludeLarge = false) {
14
- if (excludeLarge) {
15
- return `@media (min-width: ${
16
- SIZES[smallKey].min
17
- }px) and (max-width: ${SIZES[largeKey].min - 1}px)`
18
- } else {
19
- if (SIZES[largeKey].max === Infinity) {
20
- return `@media (min-width: ${SIZES[smallKey].min}px)`
21
- } else {
22
- return `@media (min-width: ${SIZES[smallKey].min}px) and (max-width: ${SIZES[largeKey].max}px)`
23
- }
24
- }
25
- },
26
-
27
- greaterThan(key: Size) {
28
- return `@media (min-width: ${SIZES[key].min}px)`
29
- },
30
-
31
- lessThan(key: Size) {
32
- return `@media (max-width: ${SIZES[key].min - 1}px)`
33
- },
34
-
35
- size(key: Size) {
36
- const size = SIZES[key]
37
-
38
- if (size.min == null) {
39
- return media.lessThan(key)
40
- } else if (size.max == null) {
41
- return media.greaterThan(key)
42
- } else {
43
- return media.between(key, key)
44
- }
45
- }
46
- }
47
-
48
- const PRIMARY = '#d9376e'
49
- const LIGHT = '#eff0f3'
50
- export const COLORS = {
51
- header: {
52
- background: PRIMARY,
53
- text: LIGHT
54
- },
55
- background: LIGHT,
56
- text: '#2a2a2a',
57
- link: PRIMARY,
58
- secondary: '#ff8e3c',
59
- tertiary: '#ff8e3c',
60
- shadow: '#444'
61
- }
@@ -1,32 +0,0 @@
1
- import {flatten, range, uniq} from 'lodash'
2
-
3
- const regex = /^([a-z0-9\s_-]+)({([0-9,-]+)})*/
4
-
5
- function isNum(v: any) {
6
- return !isNaN(v)
7
- }
8
-
9
- export function parseCodeFenceHeader(header: string): [string, number[]?] {
10
- const match = regex.exec(header)
11
- if (!match) {
12
- throw new Error(`Unparseable code fence header: ${header}`)
13
- }
14
- const [, lang, , range] = match
15
-
16
- return range ? [lang, parseRange(range)] : [lang]
17
- }
18
-
19
- function parseRange(nums: string) {
20
- return uniq(flatten(nums.split(',').map(expandRange))).filter(isNum)
21
- }
22
-
23
- function expandRange(rangeStr: string) {
24
- if (rangeStr.includes('-')) {
25
- const numRange = rangeStr
26
- .split('-')
27
- .map(n => Number(n))
28
- .sort()
29
- return range(numRange[numRange.length - 1], numRange[0])
30
- }
31
- return [Number(rangeStr)]
32
- }
@@ -1,30 +0,0 @@
1
- {
2
- "//": "NOTE: TypeScript is only used for typechecking, not transpiling as that's handled by babel",
3
- "include": [
4
- "src/**/*"
5
- ],
6
- "exclude": [
7
- "node_modules/**/*"
8
- ],
9
- "compilerOptions": {
10
- "types": [
11
- "./webpack/type-stubs.d.ts"
12
- ],
13
- "strict": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "noEmit": true,
16
- "lib": [
17
- "dom",
18
- "ES2015"
19
- ],
20
- "target": "es2015",
21
- "moduleResolution": "node",
22
- "module": "esnext",
23
- "esModuleInterop": true,
24
- "skipLibCheck": true,
25
- "jsx": "preserve",
26
- "allowJs": true,
27
- "resolveJsonModule": true,
28
- "isolatedModules": true
29
- }
30
- }
@@ -1,4 +0,0 @@
1
- {
2
- "version": 2,
3
- "routes": [{"handle": "filesystem"}, {"src": "/.*", "dest": "/index.html"}]
4
- }
@@ -1,5 +0,0 @@
1
- const createConfig = require('./createConfig')
2
-
3
- const env = process.env.NODE_ENV === 'production' ? 'production' : 'development'
4
-
5
- module.exports = createConfig(env)
@@ -1,95 +0,0 @@
1
- const path = require('path')
2
- const CopyPlugin = require('copy-webpack-plugin')
3
- const HtmlWebpackPlugin = require('html-webpack-plugin')
4
- const webpack = require('webpack')
5
- const {CleanWebpackPlugin} = require('clean-webpack-plugin')
6
-
7
- module.exports = function createConfig(env) {
8
- return {
9
- mode: env,
10
- entry: './src/entries/main.tsx',
11
- output: {
12
- path: path.resolve(__dirname, '..', 'public'),
13
- filename: '[name]-[hash].js'
14
- },
15
- resolve: {
16
- extensions: ['.tsx', '.ts', '.js']
17
- },
18
- plugins: [
19
- new CleanWebpackPlugin(),
20
- env === 'development' && new webpack.ProgressPlugin(),
21
- new CopyPlugin({
22
- patterns: ['a', 'b'].map((n) => ({
23
- from: `src/examples/fetch/${n}.txt`,
24
- to: `${n}.txt`
25
- }))
26
- }),
27
- new HtmlWebpackPlugin({
28
- template: 'src/index.html',
29
- inject: true
30
- })
31
- ].filter(Boolean),
32
- node: {
33
- global: true,
34
- fs: 'empty',
35
- __filename: 'mock',
36
- __dirname: 'mock'
37
- },
38
- module: {
39
- rules: [
40
- {
41
- test: /\.([tj])sx?$/,
42
- use: 'babel-loader',
43
- exclude: /node_modules/
44
- },
45
- {
46
- test: /\.mdx?$/,
47
- use: ['babel-loader', path.resolve(__dirname, './mdx-toc-loader.js')]
48
- },
49
- {
50
- test: /\.html$/,
51
- use: 'html-loader'
52
- },
53
- {
54
- test: /\.css$/i,
55
- use: ['style-loader', 'css-loader']
56
- }
57
- ]
58
- },
59
- ...(env === 'development' && {
60
- devServer: {
61
- port: 3000,
62
- host: '0.0.0.0',
63
- historyApiFallback: true,
64
- disableHostCheck: true
65
- }
66
- }),
67
- devtool: env === 'development' ? 'source-map' : false,
68
- ...(env === 'production' && {
69
- optimization: {
70
- usedExports: true,
71
- minimize: true,
72
- splitChunks: {
73
- chunks: 'async',
74
- minSize: 30000,
75
- maxSize: 0,
76
- minChunks: 1,
77
- maxAsyncRequests: 6,
78
- maxInitialRequests: 4,
79
- automaticNameDelimiter: '~',
80
- cacheGroups: {
81
- defaultVendors: {
82
- test: /[\\/]node_modules[\\/]/,
83
- priority: -10
84
- },
85
- default: {
86
- minChunks: 2,
87
- priority: -20,
88
- reuseExistingChunk: true
89
- }
90
- }
91
- }
92
- }
93
- })
94
- }
95
- }