Skip to content

Commit 8acbcaf

Browse files
committed
feat: publish all stories UI components to npm!
significantly improve quality of some components, cleanup
1 parent 826c66b commit 8acbcaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+672
-280
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- run: pnpm check-build
1919
- run: pnpm test-unit
2020
- run: pnpm lint
21+
- run: tsx scripts/buildNpmReact.ts
2122
- run: nohup pnpm prod-start &
2223
- run: nohup pnpm test-mc-server &
2324
- uses: cypress-io/github-action@v5

.github/workflows/publish.yml

+7
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ jobs:
3333
pnpx zardoy-release node --footer "This release URL: ${{ steps.deploy.outputs.stdout }}"
3434
env:
3535
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
- run: |
37+
pnpx zardoy-release npm
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3640
- run: cp vercel.json .vercel/output/static/vercel.json
3741
- uses: peaceiris/actions-gh-pages@v3
3842
with:
3943
github_token: ${{ secrets.GITHUB_TOKEN }}
4044
publish_dir: .vercel/output/static
4145
force_orphan: true
46+
- run: tsx scripts/buildNpmReact.ts
47+
env:
48+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package-lock.json
77
Thumbs.db
88
build
99
localSettings.mjs
10-
dist
10+
dist*
1111
.DS_Store
1212
.idea/
1313
world
@@ -17,3 +17,5 @@ out
1717
.vercel
1818
generated
1919
storybook-static
20+
21+
src/react/npmReactComponents.ts

README.MD

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
A true Minecraft client running in your browser! A port of the original game to the web, written in JavaScript using modern web technologies.
66

7-
This project is a work in progress, but I consider it to be usable. If you encounter any bugs or usability issues, please report them!
7+
If you encounter any bugs or usability issues, please report them!
88

99
You can try this out at [mcraft.fun](https://mcraft.fun/), [pcm.gg](https://pcm.gg) (short link) [mcon.vercel.app](https://mcon.vercel.app/) or the GitHub pages deploy. Every commit from the `develop` (default) branch is deployed to [s.mcraft.fun](https://s.mcraft.fun/) - so it's usually newer, but might be less stable.
1010

@@ -19,6 +19,8 @@ You can try this out at [mcraft.fun](https://mcraft.fun/), [pcm.gg](https://pcm.
1919
- Resource pack support
2020
- even even more!
2121

22+
All components that are in [Storybook](https://mcraft.fun/storybook) are published as npm module and can be used in other projects: [`minecraft-react`](https://npmjs.com/minecraft-react)
23+
2224
### Recommended Settings
2325

2426
- Controls -> **Raw Input** -> **On** - This will make the controls more precise
@@ -65,7 +67,6 @@ To open the console, press `F12`, or if you are on mobile, you can type `#debug`
6567

6668
It should be easy to build/start the project locally. See [CONTRIBUTING.MD](./CONTRIBUTING.md) for more info.
6769

68-
There is storybook for fast UI development. Run `pnpm storybook` to start it.
6970
There is world renderer playground ([link](https://mcon.vercel.app/playground.html)).
7071

7172
However, there are many things that can be done in online version. You can access some global variables in the console and useful examples:

README.NPM.MD

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Minecraft React
2+
3+
```bash
4+
yarn add minecraft-react
5+
```
6+
7+
## Usage
8+
9+
```jsx
10+
import { Scoreboard } from 'minecraft-react'
11+
12+
const App = () => {
13+
return (
14+
<Scoreboard
15+
open
16+
title="Scoreboard"
17+
items={[
18+
{ name: 'Player 1', value: 10 },
19+
{ name: 'Player 2', value: 20 },
20+
{ name: 'Player 3', value: 30 },
21+
]}
22+
/>
23+
)
24+
}
25+
```
26+
27+
See [Storybook](https://mcraft.fun/storybook/) or [Storybook (Mirror link)](https://mcon.vercel.app/storybook/) for more examples and full components list. Also take a look at the full [standalone example](https://github.com/zardoy/prismarine-web-client/tree/experiments/UiStandaloneExample.tsx).
28+
29+
There are two types of components:
30+
31+
- Small UI components or HUD components
32+
- Full screen components (like sign editor, worlds selector)

experiments/UiStandaloneExample.tsx

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React, { useState } from 'react'
2+
import { createRoot } from 'react-dom/client'
3+
import {
4+
Button,
5+
Slider,
6+
ArmorBar,
7+
BreathBar,
8+
Chat,
9+
HealthBar,
10+
PlayerListOverlay,
11+
Scoreboard,
12+
MessageFormattedString,
13+
XPBar,
14+
FoodBar
15+
} from '../dist-npm'
16+
17+
const ExampleDemo = () => {
18+
const [sliderValue, setSliderValue] = useState(0)
19+
20+
return (
21+
<div style={{ scale: '2', transformOrigin: 'top left', width: '50%', height: '50dvh', fontFamily: 'mojangles, sans-serif', background: 'gray' }}>
22+
<Button>Button</Button>
23+
<Slider label="Slider" value={sliderValue} updateValue={value => setSliderValue(value)} />
24+
<ArmorBar armorValue={10} />
25+
<Chat
26+
messages={[
27+
{ id: 0, parts: [{ text: 'A formmated message in the chat', color: 'blue' }] },
28+
{ id: 1, parts: [{ text: 'An other message in the chat', color: 'red' }] },
29+
]}
30+
usingTouch={false}
31+
opened
32+
sendMessage={message => {
33+
console.log('typed', message)
34+
// close
35+
}}
36+
/>
37+
<BreathBar oxygen={10} />
38+
<HealthBar isHardcore={false} healthValue={10} damaged={false} />
39+
<FoodBar food={10} />
40+
<PlayerListOverlay
41+
style={{
42+
position: 'static',
43+
}}
44+
clientId="" // needed for current player highlight
45+
serverIP="Server IP"
46+
tablistHeader="Tab §aHeader"
47+
tablistFooter="Tab §bFooter"
48+
playersLists={[
49+
[
50+
{ username: 'Player 1', ping: 10, uuid: undefined },
51+
{ username: 'Player 2', ping: 20, uuid: undefined },
52+
{ username: 'Player 3', ping: 30, uuid: undefined },
53+
],
54+
]}
55+
/>
56+
"§bRed" displays as <MessageFormattedString message="§bRed" />
57+
<Scoreboard
58+
open
59+
title="Scoreboard"
60+
items={[
61+
{ name: 'Player 1', value: 10 },
62+
{ name: 'Player 2', value: 20 },
63+
{ name: 'Player 3', value: 30 },
64+
]}
65+
/>
66+
<XPBar gamemode="survival" level={10} progress={0.5} />
67+
</div>
68+
)
69+
}
70+
71+
createRoot(document.body as Element).render(<ExampleDemo />)

package.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
"web",
3030
"client"
3131
],
32-
"author": "PrismarineJS",
32+
"publish": {
33+
"preset": {
34+
"publishOnlyIfChanged": true,
35+
"runBuild": false
36+
}
37+
},
3338
"license": "MIT",
3439
"dependencies": {
3540
"@dimaka/interface": "0.0.3-alpha.0",
@@ -48,6 +53,7 @@
4853
"adm-zip": "^0.5.12",
4954
"browserfs": "github:zardoy/browserfs#build",
5055
"change-case": "^5.1.2",
56+
"classnames": "^2.5.1",
5157
"compression": "^1.7.4",
5258
"cors": "^2.8.5",
5359
"cypress-plugin-snapshots": "^1.4.4",
@@ -78,11 +84,15 @@
7884
"react-dom": "^18.2.0",
7985
"react-transition-group": "^4.4.5",
8086
"remark": "^15.0.1",
87+
"filesize": "^10.0.12",
8188
"sanitize-filename": "^1.6.3",
8289
"skinview3d": "^3.0.1",
8390
"source-map-js": "^1.0.2",
8491
"stats-gl": "^1.0.5",
8592
"stats.js": "^0.17.0",
93+
"use-typed-event-listener": "^4.0.2",
94+
"mojangson": "^2.0.4",
95+
"prosemirror-menu": "^1.2.4",
8696
"tabbable": "^6.2.0",
8797
"title-case": "3.x",
8898
"ua-parser-js": "^1.0.37",
@@ -115,7 +125,6 @@
115125
"eslint": "^8.50.0",
116126
"eslint-config-zardoy": "^0.2.17",
117127
"events": "^3.3.0",
118-
"filesize": "^10.0.12",
119128
"http-browserify": "^1.7.0",
120129
"http-server": "^14.1.1",
121130
"https-browserify": "^1.0.0",
@@ -134,7 +143,6 @@
134143
"three": "0.154.0",
135144
"timers-browserify": "^2.0.12",
136145
"typescript": "5.5.0-beta",
137-
"use-typed-event-listener": "^4.0.2",
138146
"vitest": "^0.34.6",
139147
"yaml": "^2.3.2"
140148
},

package.npm.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "minecraft-react",
3+
"description": "A Minecraft-like React UI library",
4+
"keywords": [
5+
"minecraft",
6+
"minecraft style"
7+
],
8+
"license": "MIT",
9+
"sideEffects": false,
10+
"files": [
11+
"**"
12+
],
13+
"exports": {
14+
".": {
15+
"default": "./dist/react/npmReactComponents.js",
16+
"types": "./dist/react/npmReactComponents.d.ts"
17+
},
18+
"./*": {
19+
"default": "./dist/react/*",
20+
"types": "./dist/react/*"
21+
},
22+
"./dist": {
23+
"default": "./dist/*",
24+
"types": "./dist/*"
25+
}
26+
},
27+
"module": "./dist/react/npmReactComponents.js",
28+
"types": "./dist/react/npmReactComponents.d.ts",
29+
"repository": "zardoy/prismarine-web-client",
30+
"version": "0.0.0-dev",
31+
"dependencies": {},
32+
"peerDependencies": {
33+
"react": "^18.0.0",
34+
"react-dom": "^18.0.0"
35+
}
36+
}

pnpm-lock.yaml

+18-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)