Skip to content

Commit e9d1c02

Browse files
committed
chore(deps): update dependency kkt to v7
1 parent c0304b1 commit e9d1c02

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

.kktrc.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import rawModules from '@kkt/raw-modules';
66
import scopePluginOptions from '@kkt/scope-plugin-options';
77
import pkg from './package.json';
88

9-
export default (conf: Configuration, env: string, options: LoaderConfOptions) => {
9+
export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
1010
conf = rawModules(conf, env, { ...options });
1111
conf = scopePluginOptions(conf, env, {
1212
...options,
@@ -19,6 +19,14 @@ export default (conf: Configuration, env: string, options: LoaderConfOptions) =>
1919
conf.plugins!.push(new webpack.DefinePlugin({
2020
VERSION: JSON.stringify(pkg.version),
2121
}));
22+
23+
if (conf.module && conf.module.rules && conf.module.rules[0]) {
24+
const rules = conf.module.rules[0];
25+
if (typeof rules === 'object' && typeof rules.loader === 'string' && /source-map-loader/.test(rules.loader)) {
26+
;(conf.module.rules[0] as any).exclude = /((@babel(?:\/|\\{1,2})runtime)|codesandbox-import-utils)/;
27+
}
28+
}
29+
2230
if (env === 'production') {
2331
conf.output = { ...conf.output, publicPath: './' }
2432
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@
3737
"codesandbox-import-utils": "2.2.3"
3838
},
3939
"devDependencies": {
40-
"@kkt/less-modules": "6.11.0",
41-
"@kkt/raw-modules": "6.11.0",
42-
"@kkt/scope-plugin-options": "6.11.0",
40+
"@kkt/less-modules": "7.0.1",
41+
"@kkt/raw-modules": "7.0.1",
42+
"@kkt/scope-plugin-options": "7.0.1",
4343
"@types/react": "17.0.38",
4444
"@types/react-dom": "17.0.11",
4545
"@uiw/react-github-corners": "1.5.3",
4646
"@uiw/react-markdown-preview": "3.4.5",
4747
"react": "17.0.2",
4848
"react-dom": "17.0.2",
49-
"kkt": "6.11.0",
49+
"kkt": "7.0.1",
5050
"tsbb": "3.5.4"
5151
},
5252
"eslintConfig": {

src/index.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState } from 'react';
22
import { getParameters } from 'codesandbox-import-utils/lib/api/define';
33

4-
export type CodeSandboxProps = React.FormHTMLAttributes<HTMLFormElement> & {
4+
export type CodeSandboxBase = {
55
/**
66
* Whether we should redirect to the embed instead of the editor.
77
*/
@@ -23,9 +23,11 @@ export type CodeSandboxProps = React.FormHTMLAttributes<HTMLFormElement> & {
2323
content?: string | Record<string, any>;
2424
isBinary?: boolean;
2525
}>
26-
};
26+
}
27+
28+
export type CodeSandboxProps<T> = React.FormHTMLAttributes<T> & CodeSandboxBase;
2729

28-
function request(files: CodeSandboxProps['files']) {
30+
function request<T>(files: CodeSandboxProps<T>['files']) {
2931
return fetch('https://codesandbox.io/api/v1/sandboxes/define?json=1', {
3032
method: "POST",
3133
headers: {
@@ -35,11 +37,10 @@ function request(files: CodeSandboxProps['files']) {
3537
body: JSON.stringify({
3638
files: files,
3739
})
38-
}).
39-
then(x => x.json())
40+
}).then(x => x.json());
4041
}
4142

42-
const codeSandbox: React.FC<CodeSandboxProps> = (props) => {
43+
const CodeSandbox: React.FC<CodeSandboxProps<HTMLFormElement | HTMLIFrameElement>> = (props) => {
4344
const { files = {}, embed, json, query, ...other } = props || {};
4445
const parameters = getParameters({ files } as any);
4546
const [url, setUrl] = useState<string>();
@@ -52,16 +53,20 @@ const codeSandbox: React.FC<CodeSandboxProps> = (props) => {
5253
}
5354
});
5455
}
56+
// eslint-disable-next-line react-hooks/exhaustive-deps
5557
}, [files]);
5658
if (!props.children) {
5759
return (
5860
<iframe
61+
{...other}
62+
title={other.title || 'Example.'}
5963
src={url}
6064
style={{
6165
width: '100%',
6266
height: '100%',
6367
border: 0,
64-
overflow: 'hidden'
68+
overflow: 'hidden',
69+
...other.style,
6570
}}
6671
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
6772
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
@@ -77,6 +82,7 @@ const codeSandbox: React.FC<CodeSandboxProps> = (props) => {
7782
<button type="submit">{props.children}</button>
7883
</form>
7984
)
85+
8086
}
8187

82-
export default codeSandbox;
88+
export default CodeSandbox;

0 commit comments

Comments
 (0)