From 43445e8d8654c23fc9f362848d538955a3d1da23 Mon Sep 17 00:00:00 2001 From: "Amy J. Ko" Date: Sat, 16 Sep 2023 11:16:31 -0700 Subject: [PATCH] Basic placement editor. --- src/components/palette/PaletteProperty.svelte | 17 ++++++++- src/components/palette/PlaceEditor.svelte | 2 +- src/components/palette/PlacementEditor.svelte | 38 +++++++++++++++++++ src/edit/OutputPropertyValueSet.ts | 17 ++++----- src/edit/ShapeProperties.ts | 25 ++++++++++-- 5 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 src/components/palette/PlacementEditor.svelte diff --git a/src/components/palette/PaletteProperty.svelte b/src/components/palette/PaletteProperty.svelte index 1086c7444..963d72933 100644 --- a/src/components/palette/PaletteProperty.svelte +++ b/src/components/palette/PaletteProperty.svelte @@ -25,6 +25,7 @@ import { tick } from 'svelte'; import { DOCUMENTATION_SYMBOL, EDIT_SYMBOL } from '../../parser/Symbols'; import MotionEditor from './MotionEditor.svelte'; + import PlacementEditor from './PlacementEditor.svelte'; export let project: Project; export let property: OutputProperty; @@ -137,12 +138,24 @@ {:else if property.type === 'content'} {:else if property.type === 'place'} - {@const place = values.getPlace(project)} - {@const motion = values.getMotion(project)} + {@const place = values.getEvaluationOf( + project, + project.shares.output.Place + )} + {@const motion = values.getEvaluationOf( + project, + project.shares.input.Motion + )} + {@const placement = values.getEvaluationOf( + project, + project.shares.input.Placement + )} {#if place} {:else if motion} + {:else if placement} + {/if} {/if} diff --git a/src/components/palette/PlaceEditor.svelte b/src/components/palette/PlaceEditor.svelte index 95d8b77a3..b13b94844 100644 --- a/src/components/palette/PlaceEditor.svelte +++ b/src/components/palette/PlaceEditor.svelte @@ -134,7 +134,7 @@ project.shares.input.Placement.getReference( project.locales ), - [] + [place] ), ], ])}>→{project.shares.input.Placement.getNames()[0]} + import Evaluate from '../../nodes/Evaluate'; + import type Project from '@models/Project'; + import PlaceEditor from './PlaceEditor.svelte'; + + export let project: Project; + export let placement: Evaluate; + export let editable: boolean; + + $: place = placement.getInput( + project.shares.input.Placement.inputs[0], + project.getNodeContext(placement) + ); + + +
+ {project.shares.input.Placement.names.getPreferredNameString([], true)} + {#if place instanceof Evaluate} +
+
+ {/if} +
+ + diff --git a/src/edit/OutputPropertyValueSet.ts b/src/edit/OutputPropertyValueSet.ts index 333f72b76..d5fc60dbe 100644 --- a/src/edit/OutputPropertyValueSet.ts +++ b/src/edit/OutputPropertyValueSet.ts @@ -14,6 +14,8 @@ import type Bind from '../nodes/Bind'; import type { Database } from '../db/Database'; import MarkupValue from '@values/MarkupValue'; import type Locale from '../locale/Locale'; +import type StructureDefinition from '../nodes/StructureDefinition'; +import type StreamDefinition from '../nodes/StreamDefinition'; /** * Represents one or more equivalent inputs to an output expression. @@ -124,18 +126,13 @@ export default class OutputPropertyValueSet { return expr instanceof ListLiteral ? expr : undefined; } - getPlace(project: Project) { + getEvaluationOf( + project: Project, + definition: StructureDefinition | StreamDefinition + ) { const expr = this.getExpression(); return expr instanceof Evaluate && - expr.is(project.shares.output.Place, project.getNodeContext(expr)) - ? expr - : undefined; - } - - getMotion(project: Project) { - const expr = this.getExpression(); - return expr instanceof Evaluate && - expr.is(project.shares.input.Motion, project.getNodeContext(expr)) + expr.is(definition, project.getNodeContext(expr)) ? expr : undefined; } diff --git a/src/edit/ShapeProperties.ts b/src/edit/ShapeProperties.ts index 4b727ce95..9a568411d 100644 --- a/src/edit/ShapeProperties.ts +++ b/src/edit/ShapeProperties.ts @@ -1,3 +1,22 @@ -import NumberLiteral from '../nodes/NumberLiteral'; -import Unit from '../nodes/Unit'; -import OutputPropertyRange from './OutputPropertyRange'; +import type Locale from '../locale/Locale'; +import type Project from '../models/Project'; +import ListLiteral from '../nodes/ListLiteral'; +import { getOutputProperties } from './OutputProperties'; +import OutputProperty from './OutputProperty'; + +export default function getShapeProperties( + project: Project, + locale: Locale +): OutputProperty[] { + return [ + new OutputProperty( + locale.output.Stage.content, + 'content', + true, + false, + (expr) => expr instanceof ListLiteral, + () => ListLiteral.make([]) + ), + ...getOutputProperties(project, locale), + ]; +}