-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SY-1098 Add Ability to Resize Most Schematic Symbols (#813)
- feat(pluto): Add scaling to most schematic elements - refactor(pluto): Make separate light aether component
- Loading branch information
Showing
12 changed files
with
409 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in the file | ||
// licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business Source | ||
// License, use of this software will be governed by the Apache License, Version 2.0, | ||
// included in the file licenses/APL.txt. | ||
|
||
export * as light from "@/vis/light/aether/light"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in the file | ||
// licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business Source | ||
// License, use of this software will be governed by the Apache License, Version 2.0, | ||
// included in the file licenses/APL.txt. | ||
|
||
import { type Destructor } from "@synnaxlabs/x"; | ||
import { z } from "zod"; | ||
|
||
import { aether } from "@/aether/aether"; | ||
import { status } from "@/status/aether"; | ||
import { telem } from "@/telem/aether"; | ||
import { type diagram } from "@/vis/diagram/aether"; | ||
|
||
export const lightStateZ = z.object({ | ||
enabled: z.boolean(), | ||
source: telem.booleanSourceSpecZ.optional().default(telem.noopBooleanSourceSpec), | ||
}); | ||
|
||
export type LightState = z.input<typeof lightStateZ>; | ||
|
||
interface InternalState { | ||
source: telem.BooleanSource; | ||
addStatus: status.Aggregate; | ||
stopListening: Destructor; | ||
} | ||
|
||
// Light is a component that listens to a boolean telemetry source to update its state. | ||
export class Light | ||
extends aether.Leaf<typeof lightStateZ, InternalState> | ||
implements diagram.Element | ||
{ | ||
static readonly TYPE = "Light"; | ||
|
||
schema = lightStateZ; | ||
|
||
async afterUpdate(): Promise<void> { | ||
this.internal.addStatus = status.useOptionalAggregate(this.ctx); | ||
const { source: sourceProps } = this.state; | ||
const { internal: i } = this; | ||
this.internal.source = await telem.useSource( | ||
this.ctx, | ||
sourceProps, | ||
this.internal.source, | ||
); | ||
|
||
await this.updateEnabledState(); | ||
i.stopListening?.(); | ||
i.stopListening = i.source.onChange(() => | ||
this.updateEnabledState().catch(this.reportError.bind(this)), | ||
); | ||
} | ||
|
||
private reportError(e: Error): void { | ||
this.internal.addStatus({ | ||
key: this.key, | ||
variant: "error", | ||
message: `Failed to update Light: ${e.message}`, | ||
}); | ||
} | ||
|
||
private async updateEnabledState(): Promise<void> { | ||
const nextEnabled = await this.internal.source.value(); | ||
if (nextEnabled !== this.state.enabled) | ||
this.setState((p) => ({ ...p, enabled: nextEnabled })); | ||
} | ||
|
||
async afterDelete(): Promise<void> { | ||
await this.internalAfterDelete(); | ||
} | ||
|
||
private async internalAfterDelete(): Promise<void> { | ||
this.internal.stopListening(); | ||
await this.internal.source.cleanup?.(); | ||
} | ||
|
||
async render(): Promise<void> {} | ||
} | ||
|
||
export const REGISTRY: aether.ComponentRegistry = { [Light.TYPE]: Light }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in the file | ||
// licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business Source | ||
// License, use of this software will be governed by the Apache License, Version 2.0, | ||
// included in the file licenses/APL.txt. | ||
|
||
export * as Light from "@/vis/light/use"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in the file | ||
// licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business Source | ||
// License, use of this software will be governed by the Apache License, Version 2.0, | ||
// included in the file licenses/APL.txt. | ||
|
||
import { useEffect } from "react"; | ||
import { type z } from "zod"; | ||
|
||
import { Aether } from "@/aether"; | ||
import { useMemoDeepEqualProps } from "@/memo"; | ||
import { light } from "@/vis/light/aether"; | ||
|
||
export interface UseProps extends Pick<z.input<typeof light.lightStateZ>, "source"> { | ||
aetherKey: string; | ||
} | ||
|
||
export interface UseReturn | ||
extends Pick<z.output<typeof light.lightStateZ>, "enabled"> {} | ||
|
||
export const use = ({ aetherKey, source }: UseProps): UseReturn => { | ||
const memoProps = useMemoDeepEqualProps({ source }); | ||
const [, { enabled }, setState] = Aether.use({ | ||
aetherKey, | ||
type: light.Light.TYPE, | ||
schema: light.lightStateZ, | ||
initialState: { | ||
enabled: false, | ||
...memoProps, | ||
}, | ||
}); | ||
console.log("use.ts: enabled", enabled); | ||
|
||
useEffect( | ||
() => setState((state) => ({ ...state, ...memoProps })), | ||
[memoProps, setState], | ||
); | ||
|
||
return { enabled }; | ||
}; |
Oops, something went wrong.