Skip to content

Commit fec352a

Browse files
draedfulevtaranov
andauthored
feat: add Playground story (#5)
* feat(): Add gravity playground. Add some fixes and features for playground * fix(Block): fix block's selection * fix(Block): fix growing zIndex on select block * fix(Selection) fix ts in SelectionArea --------- Co-authored-by: evtaranov <[email protected]>
1 parent 79f3783 commit fec352a

Some content is hidden

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

43 files changed

+1830
-204
lines changed

.storybook/styles/global.css

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
11

2+
@mixin nv-legacy-text {
3+
@font-face {
4+
font-family: "YS Text";
5+
src: url("https://yastatic.net/s3/home/fonts/ys/1/text-light.woff2") format("woff2");
6+
font-weight: 300;
7+
font-style: normal;
8+
font-stretch: normal;
9+
font-display: swap;
10+
}
11+
12+
@font-face {
13+
font-family: "YS Text";
14+
src: url("https://yastatic.net/s3/home/fonts/ys/1/text-regular.woff2") format("woff2");
15+
font-weight: 400;
16+
font-style: normal;
17+
font-stretch: normal;
18+
font-display: swap;
19+
}
20+
21+
@font-face {
22+
font-family: "YS Text";
23+
src: url("https://yastatic.net/s3/home/fonts/ys/1/text-medium.woff2") format("woff2");
24+
font-weight: 500;
25+
font-style: normal;
26+
font-stretch: normal;
27+
font-display: swap;
28+
}
29+
30+
@font-face {
31+
font-family: "YS Text";
32+
src: url("https://yastatic.net/s3/home/fonts/ys/1/text-bold.woff2") format("woff2");
33+
font-weight: bold;
34+
font-style: normal;
35+
font-stretch: normal;
36+
font-display: swap;
37+
}
38+
}
39+
40+
241
.sb-show-main {
342
padding: 0 !important;
4-
margin: 0;
43+
margin: 0;
44+
font-family: "YS Text";
545
}
646

747
.toolbox {

package-lock.json

Lines changed: 37 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
}
4040
],
4141
"dependencies": {
42+
"@monaco-editor/react": "^4.6.0",
4243
"@preact/signals-core": "^1.5.1",
4344
"intersects": "^2.7.2",
4445
"lodash-es": "^4.17.21",

src/components/canvas/anchors/index.ts

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventedComponent } from "../../../mixins/withEvents";
2-
import { withHitTest } from "../../../mixins/withHitTest";
2+
import { debugHitBox, withHitTest } from "../../../mixins/withHitTest";
33
import { ECameraScaleLevel } from "../../../services/camera/CameraService";
44
import { frameDebouncer } from "../../../services/optimizations/frameDebouncer";
55
import { AnchorState, EAnchorType } from "../../../store/anchor/Anchor";
@@ -13,7 +13,7 @@ export type TAnchor = {
1313
id: string;
1414
blockId: TBlockId;
1515
type: EAnchorType | string;
16-
index: number;
16+
index?: number;
1717
};
1818

1919
export type TAnchorProps = TAnchor & {
@@ -30,6 +30,9 @@ type TAnchorState = {
3030
};
3131

3232
export class Anchor extends withHitTest(EventedComponent) {
33+
34+
public readonly cursor = 'pointer';
35+
3336
public get zIndex() {
3437
// @ts-ignore this.__comp.parent instanceOf Block
3538
return this.__comp.parent.zIndex + 1;
@@ -45,7 +48,7 @@ export class Anchor extends withHitTest(EventedComponent) {
4548

4649
private shift: number;
4750

48-
private hitBoxHash: number;
51+
private hitBoxHash: string;
4952

5053
private debouncedSetHitBox: (...args: any[]) => void;
5154

@@ -75,6 +78,10 @@ export class Anchor extends withHitTest(EventedComponent) {
7578
this.shift = this.props.size / 2 + props.lineWidth;
7679
}
7780

81+
public getPosition() {
82+
return this.props.getPosition(this.props);
83+
}
84+
7885
protected subscribe() {
7986
return [
8087
this.connectedState.$selected.subscribe((selected) => {
@@ -95,9 +102,21 @@ export class Anchor extends withHitTest(EventedComponent) {
95102

96103
public willIterate() {
97104
super.willIterate();
105+
98106
const { x, y, width, height } = this.hitBox.getRect();
99107

100108
this.shouldRender = width && height ? this.context.camera.isRectVisible(x, y, width, height) : true;
109+
110+
}
111+
112+
public didIterate(): void {
113+
const { x: poxX, y: posY } = this.props.getPosition(this.props);
114+
const hash = `${poxX}/${posY}/${this.shift}`;
115+
116+
if (this.hitBoxHash !== hash) {
117+
this.hitBoxHash = hash;
118+
this.debouncedSetHitBox();
119+
}
101120
}
102121

103122
public handleEvent(event: MouseEvent | KeyboardEvent) {
@@ -108,14 +127,16 @@ export class Anchor extends withHitTest(EventedComponent) {
108127
case "click":
109128
this.toggleSelected();
110129
break;
111-
case "mouseenter":
130+
case "mouseenter":{
112131
this.setState({ raised: true });
113132
this.computeRenderSize(this.props.size, true);
114133
break;
115-
case "mouseleave":
134+
}
135+
case "mouseleave": {
116136
this.setState({ raised: false });
117137
this.computeRenderSize(this.props.size, false);
118138
break;
139+
}
119140
}
120141
}
121142

@@ -124,18 +145,6 @@ export class Anchor extends withHitTest(EventedComponent) {
124145
this.setHitBox(x - this.shift, y - this.shift, x + this.shift, y + this.shift);
125146
}
126147

127-
public didRender() {
128-
super.didRender();
129-
const { x, y } = this.props.getPosition(this.props);
130-
131-
const hash = x / y + this.shift;
132-
133-
if (this.hitBoxHash !== hash) {
134-
this.hitBoxHash = hash;
135-
this.debouncedSetHitBox();
136-
}
137-
}
138-
139148
private computeRenderSize(size: number, raised: boolean) {
140149
if (raised) {
141150
this.setState({ size: size * 1.8 });
@@ -145,25 +154,21 @@ export class Anchor extends withHitTest(EventedComponent) {
145154
}
146155

147156
protected render() {
148-
// debugHitBox(this.context.ctx, this);
149-
150157
if (this.context.camera.getCameraBlockScaleLevel() === ECameraScaleLevel.Detailed) {
151158
return;
152159
}
153160
const { x, y } = this.props.getPosition(this.props);
154-
render(this.context.ctx, (ctx) => {
155-
ctx.save();
156-
ctx.fillStyle = this.context.colors.anchor.background;
157-
ctx.beginPath();
158-
ctx.arc(x, y, this.state.size * 0.5, 0, 2 * Math.PI);
159-
ctx.fill();
160-
161-
if (this.state.selected) {
162-
ctx.strokeStyle = this.context.colors.anchor.selectedBorder;
163-
ctx.lineWidth = this.props.lineWidth + 3;
164-
ctx.stroke();
165-
}
166-
ctx.closePath();
167-
})
161+
const ctx = this.context.ctx;
162+
ctx.fillStyle = this.context.colors.anchor.background;
163+
ctx.beginPath();
164+
ctx.arc(x, y, this.state.size * 0.5, 0, 2 * Math.PI);
165+
ctx.fill();
166+
167+
if (this.state.selected) {
168+
ctx.strokeStyle = this.context.colors.anchor.selectedBorder;
169+
ctx.lineWidth = this.props.lineWidth + 3;
170+
ctx.stroke();
171+
}
172+
ctx.closePath();
168173
}
169174
}

0 commit comments

Comments
 (0)