Skip to content

Commit 025815d

Browse files
committed
ci: add example #46
1 parent bfd10bc commit 025815d

File tree

10 files changed

+175
-1
lines changed

10 files changed

+175
-1
lines changed

example/.kktrc.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import path from 'path';
2+
import webpack from 'webpack';
3+
import { LoaderConfOptions, WebpackConfiguration } from 'kkt';
4+
import rawModules from '@kkt/raw-modules';
5+
import scopePluginOptions from '@kkt/scope-plugin-options';
6+
import { mdCodeModulesLoader } from 'markdown-react-code-preview-loader';
7+
import pkg from './package.json';
8+
9+
export default (conf: WebpackConfiguration, env: 'production' | 'development', options: LoaderConfOptions) => {
10+
conf = rawModules(conf, env, { ...options });
11+
conf = mdCodeModulesLoader(conf);
12+
conf = scopePluginOptions(conf, env, {
13+
...options,
14+
allowedFiles: [path.resolve(process.cwd(), 'README.md')],
15+
});
16+
// Get the project version.
17+
conf.plugins!.push(
18+
new webpack.DefinePlugin({
19+
VERSION: JSON.stringify(pkg.version),
20+
}),
21+
);
22+
23+
conf.ignoreWarnings = [{ module: /node_modules[\\/]parse5[\\/]/ }];
24+
25+
conf.module!.exprContextCritical = false;
26+
if (env === 'production') {
27+
conf.output = { ...conf.output, publicPath: './' };
28+
conf.optimization = {
29+
...conf.optimization,
30+
splitChunks: {
31+
automaticNameDelimiter: '.',
32+
maxSize: 500000,
33+
minSize: 100000,
34+
cacheGroups: {
35+
reactvendor: {
36+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
37+
name: 'react-vendor',
38+
reuseExistingChunk: true,
39+
chunks: 'all',
40+
priority: -10,
41+
},
42+
refractor: {
43+
test: /[\\/]node_modules[\\/](refractor)[\\/]/,
44+
name: 'refractor-prismjs-vendor',
45+
chunks: 'all',
46+
},
47+
},
48+
},
49+
};
50+
}
51+
return conf;
52+
};

example/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
For testing purposes

example/package.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "example",
3+
"version": "2.0.0-alpha.21",
4+
"preview": true,
5+
"scripts": {
6+
"build": "kkt build",
7+
"start": "kkt start"
8+
},
9+
"dependencies": {
10+
"@uiw/react-json-view": "2.0.0-alpha.21",
11+
"react": "^18.2.0",
12+
"react-dom": "^18.2.0"
13+
},
14+
"devDependencies": {
15+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
16+
"@kkt/raw-modules": "^7.5.1",
17+
"@kkt/scope-plugin-options": "^7.5.1",
18+
"@types/react": "^18.0.31",
19+
"@types/react-dom": "^18.0.11",
20+
"kkt": "^7.5.1",
21+
"markdown-react-code-preview-loader": "^2.1.2",
22+
"source-map-explorer": "^2.5.3"
23+
},
24+
"eslintConfig": {
25+
"extends": [
26+
"react-app",
27+
"react-app/jest"
28+
]
29+
},
30+
"browserslist": {
31+
"production": [
32+
">0.2%",
33+
"not dead",
34+
"not op_mini all"
35+
],
36+
"development": [
37+
"last 1 chrome version",
38+
"last 1 firefox version",
39+
"last 1 safari version"
40+
]
41+
}
42+
}

example/public/favicon.ico

15 KB
Binary file not shown.

example/public/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
<meta name="theme-color" content="#000000">
8+
<meta name="keywords" content="react,react-component,array-viewer,base-16,component,interactive,interactive-json,json,json-component,json-display,json-tree,json-view,json-viewer,json-inspector,json-tree,react,react-component,react-json,theme,tree,tree-view,treeview,jaywcjlove">
9+
<meta name="description" content="A React component for displaying and editing javascript arrays and JSON objects.">
10+
<!--<link rel="manifest" href="%PUBLIC_URL%/manifest.json">-->
11+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
12+
<!--
13+
Notice the use of %PUBLIC_URL% in the tags above.
14+
It will be replaced with the URL of the `public` folder during the build.
15+
Only files inside the `public` folder can be referenced from the HTML.
16+
17+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
18+
work correctly both with client-side routing and a non-root public URL.
19+
Learn how to configure a non-root public URL by running `npm run build`.
20+
-->
21+
<title>react-json-view</title>
22+
</head>
23+
24+
<body>
25+
<noscript>
26+
You need to enable JavaScript to run this app.
27+
</noscript>
28+
<div id="root"></div>
29+
<!--
30+
This HTML file is a template.
31+
If you open it directly in the browser, you will see an empty page.
32+
33+
You can add webfonts, meta tags, or analytics to this file.
34+
The build step will place the bundled scripts into the <body> tag.
35+
36+
To begin the development, run `npm start` or `yarn start`.
37+
To create a production bundle, use `npm run build` or `yarn build`.
38+
-->
39+
</body>
40+
41+
</html>

example/src/demo.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import JsonView from '@uiw/react-json-view';
2+
3+
const example = {
4+
nestedArray: [],
5+
object: {},
6+
data: {
7+
value: 1,
8+
},
9+
};
10+
11+
export default function App() {
12+
return (
13+
<JsonView value={example}>
14+
<JsonView.KeyName
15+
as="span"
16+
render={({ style, onClick, ...props }, { keyName, keys }) => {
17+
console.log('~~:', keyName, keys); // keys undefined
18+
return <span {...props} style={{ ...style, backgroundColor: 'red' }} />;
19+
}}
20+
/>
21+
</JsonView>
22+
);
23+
}

example/src/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import Example from './demo';
4+
5+
const container = document.getElementById('root');
6+
const root = createRoot(container!);
7+
root.render(<Example />);

example/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig",
3+
"include": ["src/*", ".kktrc.ts"],
4+
"compilerOptions": {
5+
"noEmit": false
6+
}
7+
}

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"version": "2.0.0-alpha.21",
3-
"packages": ["core", "www"]
3+
"packages": ["core", "www", "example"]
44
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"license": "MIT",
1919
"workspaces": [
2020
"core",
21+
"example",
2122
"www"
2223
],
2324
"engines": {

0 commit comments

Comments
 (0)