-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate playroom internals to TypeScript #313
base: master
Are you sure you want to change the base?
Changes from all commits
3a4d25e
bd53d59
42a9e7d
16f5864
05231ee
e57509e
c30fe00
eef522e
12f1e35
760bebd
83df43d
4425d38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'playroom': patch | ||
--- | ||
|
||
Migrate internals to Typescript. This moves all of the files under src/ to TypeScript. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
import type React from 'react'; | ||
import type { ReactNode } from 'react'; | ||
import type { ComponentType, ReactNode } from 'react'; | ||
import { useParams } from '../utils/params'; | ||
import CatchErrors from './CatchErrors/CatchErrors'; | ||
// @ts-expect-error | ||
import RenderCode from './RenderCode/RenderCode'; | ||
|
||
interface FrameProps { | ||
themes: Record<string, any>; | ||
components: Array<any>; | ||
FrameComponent: React.ComponentType<{ | ||
components: Record<string, ComponentType>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
FrameComponent: ComponentType<{ | ||
themeName: string | null; | ||
theme: string; | ||
children?: ReactNode; | ||
}>; | ||
} | ||
|
||
export default function Frame({ | ||
themes, | ||
components, | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { FrameSrcHandler } from '../../internalTypes'; | ||
|
||
import frameConfig from '__PLAYROOM_ALIAS__FRAME_COMPONENT__'; | ||
|
||
const defaultFrameSrc: FrameSrcHandler = ( | ||
{ code, themeName }, | ||
{ baseUrl, paramType } | ||
) => | ||
`${baseUrl}frame.html${ | ||
paramType === 'hash' ? '#' : '' | ||
}?themeName=${encodeURIComponent(themeName)}&code=${encodeURIComponent( | ||
code | ||
)}`; | ||
|
||
export default (frameConfig.frameSrc | ||
? frameConfig.frameSrc | ||
: defaultFrameSrc) as FrameSrcHandler; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React, { type ComponentType } from 'react'; | ||
import scopeEval from 'scope-eval'; | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
|
@@ -9,7 +9,13 @@ import { | |
ReactFragmentPragma, | ||
} from '../../utils/compileJsx'; | ||
|
||
export default function RenderCode({ code, scope }) { | ||
export default function RenderCode({ | ||
code, | ||
scope, | ||
}: { | ||
code: string | undefined; | ||
scope: Record<string, ComponentType>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
}) { | ||
const userScope = { | ||
...(useScope() ?? {}), | ||
...scope, | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as components from '__PLAYROOM_ALIAS__COMPONENTS__'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports | ||
export default components as typeof import('__PLAYROOM_ALIAS__COMPONENTS__').default; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { renderElement } from './render'; | ||
import Frame from './Playroom/Frame'; | ||
import { hmrAccept } from './utils/hmr'; | ||
import playroomThemes from './themes'; | ||
import playroomComponents from './components'; | ||
import PlayroomFrameComponent from './frameComponent'; | ||
|
||
const outlet = document.createElement('div'); | ||
document.body.appendChild(outlet); | ||
|
||
const renderFrame = ({ | ||
themes = playroomThemes, | ||
components = playroomComponents, | ||
FrameComponent = PlayroomFrameComponent, | ||
} = {}) => { | ||
renderElement( | ||
<Frame | ||
components={components} | ||
themes={themes} | ||
FrameComponent={FrameComponent} | ||
/>, | ||
outlet | ||
); | ||
}; | ||
renderFrame(); | ||
|
||
hmrAccept((accept) => { | ||
accept('./components', () => { | ||
renderFrame({ components: playroomComponents }); | ||
}); | ||
|
||
accept('./themes', () => { | ||
renderFrame({ themes: playroomThemes }); | ||
}); | ||
|
||
accept('./frameComponent', () => { | ||
renderFrame({ FrameComponent: PlayroomFrameComponent }); | ||
}); | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import frameComponent from '__PLAYROOM_ALIAS__FRAME_COMPONENT__'; | ||
|
||
export default frameComponent; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*.png' { | ||
const value: any; | ||
export default value; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to ship typescript as source? The alternative would be a build step. We could just run
tsc
for now, and graduate to something that offers proper CJS/ESM support later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reflecting on this, maybe for now we could just keep the separate
.js
and.d.ts
files for simplicity, and think about a potential build process later on.