Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MS-19] fix build error #10

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/docs/src/components/diagram/fixture/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
note: "",
fields: [
{
note: '',
id: 1,
name: "id",
type: { args: null, schemaName: "", typeName: "uuid" },
Expand All @@ -32,6 +33,7 @@ export default {
},
},
{
note: '',
id: 2,
name: "name",
type: { args: "200", schemaName: "", typeName: "varchar(200)" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { Project as _Project } from '$lib/components/diagram/type';
import type { Project as _Project } from '../../../../components/diagram/type';

export type Project = _Project;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DiagramController } from '$lib/components/diagram/controller';
import type { DiagramController } from '../../controller';
import {
type EventManager,
NodeInsertEvent,
Expand All @@ -7,7 +7,7 @@ import {
NodeTranslationEndEvent,
NodeAlignTranslationEvent,
NodeLayoutChangeEvent
} from '$lib/components/diagram/event';
} from '../../event';
import {
BuildContext,
Offset,
Expand Down
138 changes: 76 additions & 62 deletions packages/docs/src/components/diagram/widget/AlignLiner/Line.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,88 @@
import { CustomPaint, Element, State, StatefulWidget } from '@moonmoonbrothers/flutterjs';
import type { Line as LineProps } from './type';
import type { DiagramController } from '$lib/components/diagram/controller';
import { DiagramControllerProvider } from '../Provider';
import { classToFunction } from '../utils';
import {
CustomPaint,
Element,
State,
StatefulWidget,
} from "@moonmoonbrothers/flutterjs";
import type { Line as LineProps } from "./type";
import type { DiagramController } from "../../controller";
import { DiagramControllerProvider } from "../Provider";
import { classToFunction } from "../utils";

class Line extends StatefulWidget {
line: LineProps;
constructor({ line, key }: { line: LineProps; key?: unknown }) {
super(key);
this.line = line;
}
line: LineProps;
constructor({ line, key }: { line: LineProps; key?: unknown }) {
super(key);
this.line = line;
}

createState(): State<StatefulWidget> {
return new LineState();
}
createState(): State<StatefulWidget> {
return new LineState();
}
}

class LineState extends State<Line> {
controller!: DiagramController;
initState(context: Element): void {
super.initState(context);
this.controller = DiagramControllerProvider.of(context);
}
controller!: DiagramController;
initState(context: Element): void {
super.initState(context);
this.controller = DiagramControllerProvider.of(context);
}

resolveProps(props: LineProps): { x1: number; x2: number; y1: number; y2: number } {
let result: { x1: number; x2: number; y1: number; y2: number };
const rootRect = this.controller.getRootRect();
const canvasRect = this.controller.getCanvasRect();
const scale = this.controller.getScale();
if (props.type === 'horizontal') {
const { y } = props;
result = {
x1: (canvasRect.left - rootRect.left) / scale + rootRect.left,
x2: (rootRect.width + canvasRect.right - rootRect.right) / scale + rootRect.left,
y1: y,
y2: y
};
} else {
const { x } = props;
result = {
x1: x,
x2: x,
y1: (canvasRect.top - rootRect.top) / scale + rootRect.top,
y2: (rootRect.height + canvasRect.bottom - rootRect.bottom) / scale + rootRect.top
};
}
return result;
}
resolveProps(props: LineProps): {
x1: number;
x2: number;
y1: number;
y2: number;
} {
let result: { x1: number; x2: number; y1: number; y2: number };
const rootRect = this.controller.getRootRect();
const canvasRect = this.controller.getCanvasRect();
const scale = this.controller.getScale();
if (props.type === "horizontal") {
const { y } = props;
result = {
x1: (canvasRect.left - rootRect.left) / scale + rootRect.left,
x2:
(rootRect.width + canvasRect.right - rootRect.right) / scale +
rootRect.left,
y1: y,
y2: y,
};
} else {
const { x } = props;
result = {
x1: x,
x2: x,
y1: (canvasRect.top - rootRect.top) / scale + rootRect.top,
y2:
(rootRect.height + canvasRect.bottom - rootRect.bottom) / scale +
rootRect.top,
};
}
return result;
}

override build() {
return CustomPaint({
painter: {
shouldRepaint: () => true,
createDefaultSvgEl: (paintContext) => ({
line: paintContext.createSvgEl('line')
}),
paint: ({ line }) => {
const { x1, y1, x2, y2 } = this.resolveProps(this.widget.line);
line.setAttribute('x1', `${x1}`);
line.setAttribute('y1', `${y1}`);
line.setAttribute('x2', `${x2}`);
line.setAttribute('y2', `${y2}`);
override build() {
return CustomPaint({
painter: {
shouldRepaint: () => true,
createDefaultSvgEl: (paintContext) => ({
line: paintContext.createSvgEl("line"),
}),
paint: ({ line }) => {
const { x1, y1, x2, y2 } = this.resolveProps(this.widget.line);
line.setAttribute("x1", `${x1}`);
line.setAttribute("y1", `${y1}`);
line.setAttribute("x2", `${x2}`);
line.setAttribute("y2", `${y2}`);

line.setAttribute('stroke', 'black');
line.setAttribute('stroke-width', '1');
line.setAttribute('stroke-dasharray', '5,5');
}
}
});
}
line.setAttribute("stroke", "black");
line.setAttribute("stroke-width", "1");
line.setAttribute("stroke-dasharray", "5,5");
},
},
});
}
}

export default classToFunction(Line);
4 changes: 2 additions & 2 deletions packages/docs/src/components/diagram/widget/Edge/Edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import drawEdge from './drawEdge';
import EventManagerProvider from '../Provider/EventManagerProvider';
import { ActiveRelationEvent, EventManager, FieldLayoutChangeEvent } from '../../event';
import DiagramControllerProvider from '../Provider/DiagramControllerProvider';
import type { DiagramController } from '$lib/components/diagram/controller';
import type { FieldId } from '$lib/components/diagram/type';
import type { DiagramController } from '../../controller';
import type { FieldId } from '../../type';

type Vertex<FIELD_ID = FieldId> = {
id: FIELD_ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RenderFakeIntrinsicWidth extends SingleChildRenderObject {
super({ isPainter: false });
}

getIntrinsicWidth(height: number): number {
getIntrinsicWidth(_: number): number {
return 0;
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/src/components/diagram/widget/Node/BaseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
Element,
ConstraintsTransformBox,
Constraints,
BorderRadius,
Padding
} from '@moonmoonbrothers/flutterjs';
import { classToFunction } from '../utils';
Expand All @@ -37,7 +36,7 @@ import {
NodeLayoutChangeEvent
} from '../../event';
import DiagramControllerProvider from '../Provider/DiagramControllerProvider';
import type { DiagramController } from '$lib/components/diagram/controller';
import type { DiagramController } from '../../controller';
import { ChangedLayoutNotifier } from '../ChangeNotifier';

class baseNode extends StatefulWidget {
Expand Down
1 change: 0 additions & 1 deletion packages/docs/src/components/pages/Intro.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
import Diagram from "../../components/diagram/Diagram.svelte";
import Widget from "@moonmoonbrothers/flutterjs-svelte";
---

<div
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/pages/docs/Toc.astro
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const { headings } = Astro.props;
</ul>
</nav>

<script type="text/javascript">
<script is:inline type="text/javascript">
const content = document.querySelector(".layout");
const headings = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
const toc = document.querySelector(".toc");
Expand Down