Skip to content

Commit b40ce13

Browse files
committed
feat: 0.2.0
1 parent 5154477 commit b40ce13

11 files changed

Lines changed: 3269 additions & 3874 deletions

File tree

.vscode/settings.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
{
22
"editor.formatOnSave": true,
3-
"[typescript]": {
4-
"editor.codeActionsOnSave": {
5-
"source.organizeImports": true,
6-
"source.fixAll": true
7-
}
8-
},
9-
"[typescriptreact]": {
10-
"editor.codeActionsOnSave": {
11-
"source.organizeImports": true,
12-
"source.fixAll": true
13-
}
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true
145
}
15-
}
6+
}

example/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
},
1010
"dependencies": {
1111
"react-app-polyfill": "^1.0.0",
12-
"react-three-fiber": "^2.4.3",
13-
"three": "^0.108.0"
12+
"react-three-fiber": "^4.2.20",
13+
"three": "^0.119.1",
14+
"trim-right": "^1.0.1"
1415
},
1516
"alias": {
1617
"react": "../node_modules/react",
@@ -21,7 +22,7 @@
2122
"devDependencies": {
2223
"@types/react": "^16.8.15",
2324
"@types/react-dom": "^16.8.4",
24-
"parcel": "^1.12.3",
25-
"typescript": "^3.4.5"
25+
"parcel": "^1.12.4",
26+
"typescript": "^3.9.7"
2627
}
2728
}

example/yarn.lock

Lines changed: 985 additions & 702 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-three-gui",
3-
"version": "0.1.5",
3+
"version": "0.2.0",
44
"main": "dist/index.js",
55
"module": "dist/react-three-gui.esm.js",
66
"typings": "dist/index.d.ts",
@@ -33,20 +33,20 @@
3333
"@types/react-color": "^3.0.1",
3434
"@types/react-dom": "^16.9.1",
3535
"@types/styled-components": "^4.1.19",
36-
"eslint-config-react-app": "5.0.1",
36+
"eslint-config-react-app": "^5.2.1",
3737
"husky": "^3.0.5",
3838
"react": "^16.9.0",
3939
"react-dom": "^16.9.0",
4040
"react-three-fiber": "^3.0.0-beta.16",
4141
"three": "^0.109.0",
42-
"tsdx": "^0.9.3",
43-
"tslib": "^1.10.0",
44-
"typescript": "^3.6.3"
42+
"tsdx": "^0.13.2",
43+
"tslib": "^2.0.1",
44+
"typescript": "^3.9.7"
4545
},
4646
"dependencies": {
4747
"react-color": "^2.17.3",
4848
"react-spring": "next",
4949
"react-use-gesture": "^6.0.1",
5050
"styled-components": "^4.4.0"
5151
}
52-
}
52+
}

src/Controls.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,30 @@ const groupByGroup = (items: any): any => {
5151
acc[groupName].push(item);
5252
return acc;
5353
}, {} as { [key: string]: any });
54-
}
54+
};
5555

5656
interface ControlsProps {
57-
defaultClosedGroups?: string[]
57+
defaultClosedGroups?: string[];
5858
}
5959

6060
export const Controls = React.memo((props?: ControlsProps) => {
6161
const [{ pos }, setPos] = useSpring(() => ({ pos: [0, 0] }));
62-
const bind = useDrag(({ movement, memo = ((pos as any).getValue ? (pos as any).getValue() : (pos as any).get()) }) => {
63-
setPos({
64-
pos: [
65-
clamp(movement[0] + memo[0], -window.innerWidth + WIDTH + 32, 1),
66-
clamp(movement[1] + memo[1], 0, window.innerHeight - 350),
67-
],
68-
});
69-
return memo;
70-
});
62+
const bind = useDrag(
63+
({
64+
movement,
65+
memo = (pos as any).getValue
66+
? (pos as any).getValue()
67+
: (pos as any).get(),
68+
}) => {
69+
setPos({
70+
pos: [
71+
clamp(movement[0] + memo[0], -window.innerWidth + WIDTH + 32, 1),
72+
clamp(movement[1] + memo[1], 0, window.innerHeight - 350),
73+
],
74+
});
75+
return memo;
76+
}
77+
);
7178
const [, set] = useState<number>(0);
7279

7380
useEffect(() => {
@@ -79,9 +86,9 @@ export const Controls = React.memo((props?: ControlsProps) => {
7986

8087
const getGroupConfig = (groupName: string): any => {
8188
return {
82-
defaultClosed: props?.defaultClosedGroups?.includes(groupName) ?? false
83-
}
84-
}
89+
defaultClosed: props?.defaultClosedGroups?.includes(groupName) ?? false,
90+
};
91+
};
8592

8693
return (
8794
<Float
@@ -94,9 +101,16 @@ export const Controls = React.memo((props?: ControlsProps) => {
94101
>
95102
<Header {...bind()} />
96103
<Items>
97-
{Object.entries(groupByGroup(controls)).map(([groupName, items]: any) => (
98-
<ControlGroup key={groupName} title={groupName} controls={items} config={getGroupConfig(groupName)} />
99-
))}
104+
{Object.entries(groupByGroup(controls)).map(
105+
([groupName, items]: any) => (
106+
<ControlGroup
107+
key={groupName}
108+
title={groupName}
109+
controls={items}
110+
config={getGroupConfig(groupName)}
111+
/>
112+
)
113+
)}
100114
</Items>
101115
</Float>
102116
);

src/components/ControlGroup.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Heading = styled.h2<{ open: boolean }>`
1414
1515
&:before,
1616
&:after {
17-
content: "";
17+
content: '';
1818
position: absolute;
1919
top: 8px;
2020
right: 16px;
@@ -24,18 +24,18 @@ const Heading = styled.h2<{ open: boolean }>`
2424
/* transition: transform 0.25s ease-out; */
2525
}
2626
&:before {
27-
transform: rotate(${props => props.open ? 0 : 90}deg);
27+
transform: rotate(${props => (props.open ? 0 : 90)}deg);
2828
}
2929
30-
&:after{
31-
transform: rotate(${props => props.open ? 0 : 180}deg);
30+
&:after {
31+
transform: rotate(${props => (props.open ? 0 : 180)}deg);
3232
}
3333
`;
3434

35-
const Container = styled.div<{ open: boolean, bg: boolean }>`
36-
background: ${props => props.bg ? '#f9f9f9' : '#fff'};
35+
const Container = styled.div<{ open: boolean; bg: boolean }>`
36+
background: ${props => (props.bg ? '#f9f9f9' : '#fff')};
3737
padding: 16px;
38-
display: ${props => props.open ? 'block' : 'none'};
38+
display: ${props => (props.open ? 'block' : 'none')};
3939
margin-bottom: 8px;
4040
`;
4141

@@ -44,12 +44,16 @@ export const ControlGroup = ({ title, controls, config }: any) => {
4444
const isDefault = title !== 'DEFAULT_GROUP';
4545
return (
4646
<div>
47-
{isDefault && <Heading open={open} onClick={() => setOpen(o => !o)}>{title}</Heading>}
47+
{isDefault && (
48+
<Heading open={open} onClick={() => setOpen(o => !o)}>
49+
{title}
50+
</Heading>
51+
)}
4852
<Container open={open} bg={isDefault}>
4953
{Array.from(controls).map(([id, control]: any) => (
5054
<ControlItem key={id.current} control={control} />
5155
))}
5256
</Container>
5357
</div>
54-
)
55-
}
58+
);
59+
};

src/components/ControlItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ export function ControlItem({ control }: any) {
2727
}, []);
2828
if (!Control) return null;
2929
return <Control key={control.id.current} control={control} value={value} />;
30-
}
30+
}

src/controls/NumberControl.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ export function NumberControl({ control, value }: any) {
4747
const { config } = control;
4848
const {
4949
min = config.scrub ? -Infinity : 0,
50-
max = config.scrub ? Infinity : Math.PI
50+
max = config.scrub ? Infinity : Math.PI,
5151
} = config;
5252

5353
let distance = config.distance;
5454
if (!distance) {
5555
distance = config.scrub ? 2 : max - min;
5656
}
57-
const [val, setVal] = useState(config.scrub ? CENTER : map(value, min, max, 0, PRECISION));
57+
const [val, setVal] = useState(
58+
config.scrub ? CENTER : map(value, min, max, 0, PRECISION)
59+
);
5860

5961
const handleChange = useCallback(() => {
6062
if (config.scrub) {

src/controls/XYPadControl.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
1616
x: value.x,
1717
y: value.y,
1818
},
19-
onFrame({ x, y }: any) {
20-
if (!scrub) {
21-
const vx = clamp(map(x, 0, width / 2, 0, distance), -distance, distance) || 0;
22-
const vy = clamp(map(y, 0, height / 2, 0, distance), -distance, distance) || 0
23-
control.set(() => ({
24-
x: vx < THRESHOLD && vx > -THRESHOLD ? 0 : vx,
25-
y: vy < THRESHOLD && vy > -THRESHOLD ? 0 : vy,
26-
}));
27-
}
19+
20+
onChange(value: any, b: any) {
21+
const v =
22+
clamp(map(value, 0, width / 2, 0, distance), -distance, distance) || 0;
23+
control.set((prev: any) => ({
24+
...prev,
25+
[b.key]: v < THRESHOLD && v > -THRESHOLD ? 0 : v,
26+
}));
2827
},
29-
}));
28+
})) as any;
3029

3130
const bind = useDrag(({ down, movement }) => {
3231
if (down && !stage.current) {
3332
stage.current = value;
3433
} else if (!down) {
3534
stage.current = null;
3635
}
36+
3737
setCursor({ x: down ? movement[0] : 0, y: down ? movement[1] : 0 });
38+
3839
if (scrub && down) {
3940
control.set(() => ({
4041
x:
@@ -48,7 +49,9 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
4849
});
4950

5051
const x = cursor.x.interpolate((n: number) => clamp(n + width / 2, 0, width));
51-
const y = cursor.y.interpolate((n: number) => clamp(n + height / 2, 0, height));
52+
const y = cursor.y.interpolate((n: number) =>
53+
clamp(n + height / 2, 0, height)
54+
);
5255

5356
return (
5457
<BaseControl
@@ -73,7 +76,10 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
7376
<animated.line x1={0} x2="100%" y1={y} y2={y} stroke="#ccc" />
7477
<animated.g
7578
style={{
76-
transform: interpolate([x, y], (x, y) => `translate(${x}px, ${y}px)`),
79+
transform: interpolate(
80+
[x, y],
81+
(x, y) => `translate(${x}px, ${y}px)`
82+
),
7783
}}
7884
>
7985
<circle r={8} fill="#ccc" />
@@ -84,4 +90,4 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
8490
);
8591
});
8692

87-
// (XYPadControl as any).skipEvents = true;
93+
// (XYPadControl as any).skipEvents = true;

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ export type ControlConfig = ControlConfigBase &
9292
| ControlConfigButton
9393
| ControlConfigColor
9494
| ControlConfigSelect
95-
| ControlConfigXYPad);
95+
| ControlConfigXYPad
96+
);

0 commit comments

Comments
 (0)