Skip to content

Commit 0d360bf

Browse files
committed
fix: make widget class properties reactive
1 parent 9e0a583 commit 0d360bf

Some content is hidden

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

47 files changed

+268
-173
lines changed

frontend/src/components/floating-menus/ColorPicker.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import { onDestroy, getContext } from "svelte";
33
44
import type { Editor } from "@graphite/editor";
5-
import type { HSV, RGB, FillChoice } from "@graphite/messages";
6-
import type { MenuDirection } from "@graphite/messages";
7-
import { Color, contrastingOutlineFactor, Gradient } from "@graphite/messages";
5+
import type { HSV, RGB, FillChoice } from "@graphite/messages.svelte";
6+
import type { MenuDirection } from "@graphite/messages.svelte";
7+
import { Color, contrastingOutlineFactor, Gradient } from "@graphite/messages.svelte";
88
import { clamp } from "@graphite/utility-functions/math";
99
1010
import FloatingMenu from "@graphite/components/layout/FloatingMenu.svelte";

frontend/src/components/floating-menus/Dialog.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
<div class="widget-layout details">
4242
<div class="widget-span row"><TextLabel bold={true}>The editor crashed — sorry about that</TextLabel></div>
4343
<div class="widget-span row"><TextLabel>Please report this by filing an issue on GitHub:</TextLabel></div>
44-
<div class="widget-span row"><TextButton label="Report Bug" icon="Warning" flush={true} action={() => window.open(githubUrl($dialog.panicDetails), "_blank")} /></div>
44+
<div class="widget-span row"><TextButton label="Report Bug" icon="Warning" flush={true} onclick={() => window.open(githubUrl($dialog.panicDetails), "_blank")} /></div>
4545
<div class="widget-span row"><TextLabel multiline={true}>Reload the editor to continue. If this occurs<br />immediately on repeated reloads, clear storage:</TextLabel></div>
4646
<div class="widget-span row">
4747
<TextButton
4848
label="Clear Saved Documents"
4949
icon="Trash"
5050
flush={true}
51-
action={async () => {
51+
onclick={async () => {
5252
await wipeDocuments();
5353
window.location.reload();
5454
}}
@@ -68,8 +68,8 @@
6868
<WidgetLayout layout={$dialog.buttons} class="details" />
6969
{/if}
7070
{#if $dialog.panicDetails}
71-
<TextButton label="Copy Error Log" action={() => navigator.clipboard.writeText($dialog.panicDetails)} />
72-
<TextButton label="Reload" emphasized={true} action={() => window.location.reload()} />
71+
<TextButton label="Copy Error Log" onclick={() => navigator.clipboard.writeText($dialog.panicDetails)} />
72+
<TextButton label="Reload" emphasized={true} onclick={() => window.location.reload()} />
7373
{/if}
7474
</LayoutRow>
7575
</FloatingMenu>

frontend/src/components/floating-menus/MenuList.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { tick, onDestroy, onMount } from "svelte";
33
4-
import type { MenuListEntry, MenuDirection } from "@graphite/messages";
4+
import type { MenuListEntry, MenuDirection } from "@graphite/messages.svelte";
55
66
import MenuList from "@graphite/components/floating-menus/MenuList.svelte";
77
import FloatingMenu from "@graphite/components/layout/FloatingMenu.svelte";

frontend/src/components/floating-menus/NodeCatalog.svelte

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { getContext, onMount } from "svelte";
33
4-
import type { FrontendNodeType } from "@graphite/messages";
4+
import type { FrontendNodeType } from "@graphite/messages.svelte";
55
import type { NodeGraphState } from "@graphite/state-providers/node-graph";
66
77
import TextButton from "@graphite/components/widgets/buttons/TextButton.svelte";
@@ -112,7 +112,13 @@
112112
onMount(() => {
113113
setTimeout(() => nodeSearchInput?.focus(), 0);
114114
});
115-
let nodeCategories = $derived(buildNodeCategories($nodeGraph.nodeTypes, searchTerm));
115+
116+
let nodeCategories = $state<[string, NodeCategoryDetails][]>([]);
117+
118+
$effect(() => {
119+
nodeCategories = buildNodeCategories($nodeGraph.nodeTypes, searchTerm);
120+
})
121+
116122
</script>
117123

118124
<div class="node-catalog">
@@ -129,7 +135,7 @@
129135
<TextLabel>{nodeCategory[0]}</TextLabel>
130136
</summary>
131137
{#each nodeCategory[1].nodes as nodeType}
132-
<TextButton {disabled} label={nodeType.name} tooltip={$nodeGraph.nodeDescriptions.get(nodeType.name)} action={() => onselectNodeType?.(nodeType.name)} />
138+
<TextButton {disabled} label={nodeType.name} tooltip={$nodeGraph.nodeDescriptions.get(nodeType.name)} onclick={() => onselectNodeType?.(nodeType.name)} />
133139
{/each}
134140
</details>
135141
{:else}

frontend/src/components/layout/FloatingMenu.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
import { onMount, tick } from "svelte";
2323
24-
import type { MenuDirection } from "@graphite/messages";
24+
import type { MenuDirection } from "@graphite/messages.svelte";
2525
import { browserVersion } from "@graphite/utility-functions/platform";
2626
2727
import LayoutCol from "@graphite/components/layout/LayoutCol.svelte";

frontend/src/components/panels/Document.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
UpdateEyedropperSamplingState,
1616
UpdateMouseCursor,
1717
isWidgetSpanRow,
18-
} from "@graphite/messages";
18+
} from "@graphite/messages.svelte";
1919
import type { DocumentState } from "@graphite/state-providers/document";
2020
import { textInputCleanup } from "@graphite/utility-functions/keyboard-entry";
2121
import { extractPixelData, rasterizeSVGCanvas } from "@graphite/utility-functions/rasterization";

frontend/src/components/panels/Layers.svelte

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
UpdateLayersPanelControlBarLeftLayout,
1212
UpdateLayersPanelControlBarRightLayout,
1313
UpdateLayersPanelBottomBarLayout,
14-
} from "@graphite/messages";
15-
import type { DataBuffer, LayerPanelEntry } from "@graphite/messages";
14+
} from "@graphite/messages.svelte";
15+
import type { DataBuffer, LayerPanelEntry } from "@graphite/messages.svelte";
1616
import type { NodeGraphState } from "@graphite/state-providers/node-graph";
1717
import { platformIsMac } from "@graphite/utility-functions/platform";
1818
import { extractPixelData } from "@graphite/utility-functions/rasterization";
19+
import type { WidgetLayout as WidgetLayoutState } from "@graphite/messages.svelte";
1920
2021
import LayoutCol from "@graphite/components/layout/LayoutCol.svelte";
2122
import LayoutRow from "@graphite/components/layout/LayoutRow.svelte";
@@ -60,24 +61,21 @@
6061
let layerToClipAltKeyPressed = $state(false);
6162
6263
// Layouts
63-
let layersPanelControlBarLeftLayout = $state(defaultWidgetLayout());
64-
let layersPanelControlBarRightLayout = $state(defaultWidgetLayout());
65-
let layersPanelBottomBarLayout = $state(defaultWidgetLayout());
64+
let layersPanelControlBarLeftLayout = $state<WidgetLayoutState>(defaultWidgetLayout());
65+
let layersPanelControlBarRightLayout = $state<WidgetLayoutState>(defaultWidgetLayout());
66+
let layersPanelBottomBarLayout = $state<WidgetLayoutState>(defaultWidgetLayout());
6667
6768
onMount(() => {
6869
editor.subscriptions.subscribeJsMessage(UpdateLayersPanelControlBarLeftLayout, (updateLayersPanelControlBarLeftLayout) => {
6970
patchWidgetLayout(layersPanelControlBarLeftLayout, updateLayersPanelControlBarLeftLayout);
70-
layersPanelControlBarLeftLayout = layersPanelControlBarLeftLayout;
7171
});
7272
7373
editor.subscriptions.subscribeJsMessage(UpdateLayersPanelControlBarRightLayout, (updateLayersPanelControlBarRightLayout) => {
7474
patchWidgetLayout(layersPanelControlBarRightLayout, updateLayersPanelControlBarRightLayout);
75-
layersPanelControlBarRightLayout = layersPanelControlBarRightLayout;
7675
});
7776
7877
editor.subscriptions.subscribeJsMessage(UpdateLayersPanelBottomBarLayout, (updateLayersPanelBottomBarLayout) => {
7978
patchWidgetLayout(layersPanelBottomBarLayout, updateLayersPanelBottomBarLayout);
80-
layersPanelBottomBarLayout = layersPanelBottomBarLayout;
8179
});
8280
8381
editor.subscriptions.subscribeJsMessage(UpdateDocumentLayerStructureJs, (updateDocumentLayerStructure) => {
@@ -182,7 +180,7 @@
182180
183181
draggable = false;
184182
listing.editingName = true;
185-
layers = layers;
183+
// layers = layers;
186184
187185
await tick();
188186
@@ -197,7 +195,7 @@
197195
198196
draggable = true;
199197
listing.editingName = false;
200-
layers = layers;
198+
// layers = layers;
201199
202200
const name = (e.target instanceof HTMLInputElement && e.target.value) || "";
203201
editor.handle.setLayerName(listing.entry.id, name);
@@ -207,7 +205,7 @@
207205
async function onEditLayerNameDeselect(listing: LayerListingInfo) {
208206
draggable = true;
209207
listing.editingName = false;
210-
layers = layers;
208+
// layers = layers;
211209
212210
// Set it back to the original name if the user didn't enter a new name
213211
if (document.activeElement instanceof HTMLInputElement) document.activeElement.value = listing.entry.alias;
@@ -472,7 +470,7 @@
472470
});
473471
};
474472
recurse(updateDocumentLayerStructure);
475-
layers = layers;
473+
// layers = layers;
476474
}
477475
478476
function updateLayerInTree(targetId: bigint, targetLayer: LayerPanelEntry) {
@@ -481,12 +479,12 @@
481479
const layer = layers.find((layer: LayerListingInfo) => layer.entry.id === targetId);
482480
if (layer) {
483481
layer.entry = targetLayer;
484-
layers = layers;
482+
// layers = layers;
485483
}
486484
}
487485
</script>
488486

489-
<LayoutCol class="layers" on:dragleave={() => (dragInPanel = false)}>
487+
<LayoutCol class="layers" ondragleave={() => (dragInPanel = false)}>
490488
<LayoutRow class="control-bar" scrollableX={true}>
491489
<WidgetLayout layout={layersPanelControlBarLeftLayout} />
492490
<Separator />
@@ -498,10 +496,10 @@
498496
styles={{ cursor: layerToClipUponClick && layerToClipAltKeyPressed && layerToClipUponClick.entry.clippable ? "alias" : "auto" }}
499497
data-layer-panel
500498
bind:this={list}
501-
on:click={() => deselectAllLayers()}
502-
on:dragover={updateInsertLine}
503-
on:dragend={drop}
504-
on:drop={drop}
499+
onclick={() => deselectAllLayers()}
500+
ondragover={updateInsertLine}
501+
ondragend={drop}
502+
ondrop={drop}
505503
>
506504
{#each layers as listing, index}
507505
{@const selected = fakeHighlightOfNotYetSelectedLayerBeingDragged !== undefined ? fakeHighlightOfNotYetSelectedLayerBeingDragged === listing.entry.id : listing.entry.selected}
@@ -519,8 +517,8 @@
519517
data-index={index}
520518
tooltip={listing.entry.tooltip}
521519
{draggable}
522-
on:dragstart={(e) => draggable && dragStart(e, listing)}
523-
on:click={(e) => selectLayerWithModifiers(e, listing)}
520+
ondragstart={(e) => draggable && dragStart(e, listing)}
521+
onclick={(e) => selectLayerWithModifiers(e, listing)}
524522
>
525523
{#if listing.entry.childrenAllowed}
526524
<button
@@ -547,7 +545,7 @@
547545
{#if listing.entry.name === "Artboard"}
548546
<IconLabel icon="Artboard" class={"layer-type-icon"} />
549547
{/if}
550-
<LayoutRow class="layer-name" on:dblclick={() => onEditLayerName(listing)}>
548+
<LayoutRow class="layer-name" ondblclick={() => onEditLayerName(listing)}>
551549
<input
552550
data-text-input
553551
type="text"

frontend/src/components/panels/Properties.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
import { getContext, onMount } from "svelte";
33
44
import type { Editor } from "@graphite/editor";
5-
import { defaultWidgetLayout, patchWidgetLayout, UpdatePropertyPanelSectionsLayout } from "@graphite/messages";
5+
import { defaultWidgetLayout, patchWidgetLayout, UpdatePropertyPanelSectionsLayout } from "@graphite/messages.svelte";
6+
import type { WidgetLayout as WidgetLayoutState } from "@graphite/messages.svelte";
7+
68
79
import LayoutCol from "@graphite/components/layout/LayoutCol.svelte";
810
import WidgetLayout from "@graphite/components/widgets/WidgetLayout.svelte";
911
12+
1013
const editor = getContext<Editor>("editor");
1114
12-
let propertiesSectionsLayout = $state(defaultWidgetLayout());
15+
let propertiesSectionsLayout = $state<WidgetLayoutState>(defaultWidgetLayout());
1316
1417
onMount(() => {
1518
editor.subscriptions.subscribeJsMessage(UpdatePropertyPanelSectionsLayout, (updatePropertyPanelSectionsLayout) => {
1619
patchWidgetLayout(propertiesSectionsLayout, updatePropertyPanelSectionsLayout);
17-
propertiesSectionsLayout = propertiesSectionsLayout;
1820
});
1921
});
2022
</script>

0 commit comments

Comments
 (0)