Skip to content

Commit

Permalink
Basic placement editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Sep 16, 2023
1 parent 339e5cd commit 43445e8
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 16 deletions.
17 changes: 15 additions & 2 deletions src/components/palette/PaletteProperty.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,12 +138,24 @@
{:else if property.type === 'content'}
<ContentEditor {project} list={values.getList()} {editable} />
{: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}
<PlaceEditor {project} {place} {editable} convertable={true} />
{:else if motion}
<MotionEditor {project} {motion} {editable} />
{:else if placement}
<PlacementEditor {project} {placement} {editable} />
{/if}
{/if}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/palette/PlaceEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
project.shares.input.Placement.getReference(
project.locales
),
[]
[place]
),
],
])}>→{project.shares.input.Placement.getNames()[0]}</Button
Expand Down
38 changes: 38 additions & 0 deletions src/components/palette/PlacementEditor.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script lang="ts">
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)
);
</script>

<div class="motion">
{project.shares.input.Placement.names.getPreferredNameString([], true)}
{#if place instanceof Evaluate}
<div class="field"
><PlaceEditor {project} {place} {editable} convertable={false} />
</div>
{/if}
</div>

<style>
.motion {
display: flex;
flex-direction: column;
gap: var(--wordplay-spacing);
}
.field {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
font-family: var(--wordplay-code-font);
width: 100%;
}
</style>
17 changes: 7 additions & 10 deletions src/edit/OutputPropertyValueSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 22 additions & 3 deletions src/edit/ShapeProperties.ts
Original file line number Diff line number Diff line change
@@ -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),
];
}

0 comments on commit 43445e8

Please sign in to comment.