@pixel-point/toolcraft 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +98 -0
- package/README.md +41 -0
- package/bin/create-toolcraft-app.mjs +8 -0
- package/bin/toolcraft.mjs +8 -0
- package/package.json +24 -0
- package/scripts/prepare-pack.mjs +29 -0
- package/src/cli.mjs +392 -0
- package/src/cli.test.mjs +284 -0
- package/src/copy-recursive.mjs +86 -0
- package/src/generate.mjs +212 -0
- package/src/generate.test.mjs +322 -0
- package/src/import-map.mjs +14 -0
- package/src/package-json.mjs +80 -0
- package/src/package-json.test.mjs +67 -0
- package/src/rewrite-imports.mjs +85 -0
- package/src/rewrite-imports.test.mjs +58 -0
- package/templates/runtime/contracts/component-contracts.test.ts +1165 -0
- package/templates/runtime/contracts/component-contracts.ts +1340 -0
- package/templates/runtime/contracts/decision-contracts.test.ts +206 -0
- package/templates/runtime/contracts/decision-contracts.ts +283 -0
- package/templates/runtime/contracts/index.test.ts +14 -0
- package/templates/runtime/contracts/index.ts +3 -0
- package/templates/runtime/contracts/types.ts +56 -0
- package/templates/runtime/export/export.test.ts +203 -0
- package/templates/runtime/export/export.ts +132 -0
- package/templates/runtime/export/index.ts +1 -0
- package/templates/runtime/index.ts +14 -0
- package/templates/runtime/react/canvas-shell.test.tsx +424 -0
- package/templates/runtime/react/canvas-shell.tsx +408 -0
- package/templates/runtime/react/control-renderers.ts +31 -0
- package/templates/runtime/react/controls-panel.test.tsx +3736 -0
- package/templates/runtime/react/controls-panel.tsx +2327 -0
- package/templates/runtime/react/curve-geometry.test.ts +70 -0
- package/templates/runtime/react/index.ts +15 -0
- package/templates/runtime/react/layer-tree.ts +96 -0
- package/templates/runtime/react/layers-panel.test.tsx +487 -0
- package/templates/runtime/react/layers-panel.tsx +1348 -0
- package/templates/runtime/react/media-file.ts +82 -0
- package/templates/runtime/react/panel-host-config.ts +80 -0
- package/templates/runtime/react/panel-host-geometry.test.ts +66 -0
- package/templates/runtime/react/panel-host-geometry.ts +109 -0
- package/templates/runtime/react/panel-host-types.ts +74 -0
- package/templates/runtime/react/panel-host.test.tsx +102 -0
- package/templates/runtime/react/panel-host.tsx +353 -0
- package/templates/runtime/react/runtime-public-api.test.tsx +132 -0
- package/templates/runtime/react/settings-transfer.test.ts +150 -0
- package/templates/runtime/react/settings-transfer.ts +279 -0
- package/templates/runtime/react/storage-key-migration.ts +48 -0
- package/templates/runtime/react/theme-runtime.tsx +177 -0
- package/templates/runtime/react/timeline-panel.test.tsx +668 -0
- package/templates/runtime/react/timeline-panel.tsx +2953 -0
- package/templates/runtime/react/toolbar-panel.test.tsx +212 -0
- package/templates/runtime/react/toolbar-panel.tsx +205 -0
- package/templates/runtime/react/toolcraft-app.integration.test.tsx +350 -0
- package/templates/runtime/react/toolcraft-app.test.tsx +339 -0
- package/templates/runtime/react/toolcraft-app.tsx +81 -0
- package/templates/runtime/react/toolcraft-root.test.tsx +347 -0
- package/templates/runtime/react/toolcraft-root.tsx +203 -0
- package/templates/runtime/react/use-toolcraft.ts +41 -0
- package/templates/runtime/schema/define-toolcraft.test.ts +1524 -0
- package/templates/runtime/schema/define-toolcraft.ts +1442 -0
- package/templates/runtime/schema/keyframe-capability.test.ts +90 -0
- package/templates/runtime/schema/keyframe-capability.ts +51 -0
- package/templates/runtime/schema/runtime-targets.ts +40 -0
- package/templates/runtime/schema/types.ts +370 -0
- package/templates/runtime/state/canvas-zoom.ts +8 -0
- package/templates/runtime/state/create-template-state.test.ts +242 -0
- package/templates/runtime/state/create-template-state.ts +95 -0
- package/templates/runtime/state/keyframe-evaluation.test.ts +141 -0
- package/templates/runtime/state/keyframe-evaluation.ts +203 -0
- package/templates/runtime/state/persistence.test.ts +217 -0
- package/templates/runtime/state/persistence.ts +511 -0
- package/templates/runtime/state/reducer.test.ts +937 -0
- package/templates/runtime/state/reducer.ts +1212 -0
- package/templates/runtime/state/timeline-readiness.ts +43 -0
- package/templates/runtime/state/types.ts +242 -0
- package/templates/runtime/styles.css +125 -0
- package/templates/runtime/testing/performance.test.ts +1058 -0
- package/templates/runtime/testing/performance.ts +1078 -0
- package/templates/starter/AGENTS.md +186 -0
- package/templates/starter/LICENSE.md +98 -0
- package/templates/starter/NOTICE.md +8 -0
- package/templates/starter/docs/toolcraft/README.md +41 -0
- package/templates/starter/docs/toolcraft/acceptance-testing.md +205 -0
- package/templates/starter/docs/toolcraft/agent-worklog.md +81 -0
- package/templates/starter/docs/toolcraft/assembly-workflow.md +206 -0
- package/templates/starter/docs/toolcraft/component-rules.md +299 -0
- package/templates/starter/docs/toolcraft/custom-controls.md +71 -0
- package/templates/starter/docs/toolcraft/decision-contract.md +71 -0
- package/templates/starter/docs/toolcraft/performance.md +112 -0
- package/templates/starter/docs/toolcraft/renderer-technique.md +48 -0
- package/templates/starter/docs/toolcraft/schema-reference.md +265 -0
- package/templates/starter/docs/toolcraft/workflow.md +87 -0
- package/templates/starter/e2e/app-browser-acceptance.spec.ts +785 -0
- package/templates/starter/e2e/app-controls.spec.ts +41 -0
- package/templates/starter/e2e/app-performance.spec.ts +326 -0
- package/templates/starter/e2e/canvas-handle-helpers.ts +244 -0
- package/templates/starter/e2e/performance-helpers.ts +612 -0
- package/templates/starter/e2e/product-observable-helpers.ts +170 -0
- package/templates/starter/index.html +12 -0
- package/templates/starter/package.json +52 -0
- package/templates/starter/playwright.config.ts +43 -0
- package/templates/starter/scripts/check-ai-skills.mjs +95 -0
- package/templates/starter/scripts/check-toolcraft-docs.mjs +159 -0
- package/templates/starter/scripts/check-toolcraft-integrity.mjs +232 -0
- package/templates/starter/scripts/run-vite-on-free-port.mjs +48 -0
- package/templates/starter/scripts/toolcraft-port.mjs +54 -0
- package/templates/starter/scripts/toolcraft-port.test.mjs +73 -0
- package/templates/starter/src/app/starter-acceptance.test.ts +5959 -0
- package/templates/starter/src/app/starter-acceptance.ts +2646 -0
- package/templates/starter/src/app/starter-performance.test.ts +1390 -0
- package/templates/starter/src/app/starter-performance.ts +12 -0
- package/templates/starter/src/app/starter-schema.test.ts +70 -0
- package/templates/starter/src/app/starter-schema.ts +15 -0
- package/templates/starter/src/main.tsx +18 -0
- package/templates/starter/src/router.tsx +16 -0
- package/templates/starter/src/routes/index.tsx +7 -0
- package/templates/starter/src/routes/root.tsx +19 -0
- package/templates/starter/src/styles.css +120 -0
- package/templates/starter/tsconfig.json +11 -0
- package/templates/starter/vite.config.ts +13 -0
- package/templates/ui/components/composites/accordion.tsx +73 -0
- package/templates/ui/components/composites/alert-dialog.tsx +190 -0
- package/templates/ui/components/composites/alert.tsx +74 -0
- package/templates/ui/components/composites/aspect-ratio.tsx +22 -0
- package/templates/ui/components/composites/avatar.tsx +98 -0
- package/templates/ui/components/composites/badge.tsx +69 -0
- package/templates/ui/components/composites/breadcrumb.tsx +106 -0
- package/templates/ui/components/composites/card.tsx +91 -0
- package/templates/ui/components/composites/combobox.tsx +486 -0
- package/templates/ui/components/composites/command.tsx +296 -0
- package/templates/ui/components/composites/context-menu.tsx +247 -0
- package/templates/ui/components/composites/dialog.tsx +282 -0
- package/templates/ui/components/composites/dropdown-menu.tsx +299 -0
- package/templates/ui/components/composites/empty.tsx +110 -0
- package/templates/ui/components/composites/hover-card.tsx +44 -0
- package/templates/ui/components/composites/index.ts +30 -0
- package/templates/ui/components/composites/menubar.tsx +214 -0
- package/templates/ui/components/composites/navigation-menu.tsx +167 -0
- package/templates/ui/components/composites/pagination.tsx +131 -0
- package/templates/ui/components/composites/progress.tsx +72 -0
- package/templates/ui/components/composites/radio-group.tsx +84 -0
- package/templates/ui/components/composites/resizable.tsx +42 -0
- package/templates/ui/components/composites/sheet.tsx +153 -0
- package/templates/ui/components/composites/sidebar-structural.tsx +310 -0
- package/templates/ui/components/composites/sidebar.tsx +431 -0
- package/templates/ui/components/composites/sonner.tsx +35 -0
- package/templates/ui/components/composites/spinner.tsx +43 -0
- package/templates/ui/components/composites/table.tsx +108 -0
- package/templates/ui/components/composites/tabs.tsx +83 -0
- package/templates/ui/components/control-layout/index.tsx +437 -0
- package/templates/ui/components/controls/actions/actions-control.tsx +139 -0
- package/templates/ui/components/controls/actions/index.ts +9 -0
- package/templates/ui/components/controls/anchor-grid/anchor-grid-control.tsx +107 -0
- package/templates/ui/components/controls/anchor-grid/index.ts +4 -0
- package/templates/ui/components/controls/boolean/boolean-controls.tsx +79 -0
- package/templates/ui/components/controls/boolean/index.ts +4 -0
- package/templates/ui/components/controls/channel-mixer/channel-mixer-control.tsx +95 -0
- package/templates/ui/components/controls/channel-mixer/index.ts +4 -0
- package/templates/ui/components/controls/channel-tabs/channel-tabs.tsx +42 -0
- package/templates/ui/components/controls/channel-tabs/index.ts +6 -0
- package/templates/ui/components/controls/code-textarea/code-textarea-control.tsx +90 -0
- package/templates/ui/components/controls/code-textarea/index.ts +4 -0
- package/templates/ui/components/controls/color/color-control.tsx +571 -0
- package/templates/ui/components/controls/color/color-picker-popover.tsx +104 -0
- package/templates/ui/components/controls/color/index.ts +41 -0
- package/templates/ui/components/controls/color/palette-control-data.ts +436 -0
- package/templates/ui/components/controls/color/palette-control.tsx +535 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-channel-utils.ts +162 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-interactions.ts +190 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-logic.ts +485 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-parts.tsx +710 -0
- package/templates/ui/components/controls/color/style-guide-color-picker.tsx +503 -0
- package/templates/ui/components/controls/control-types.ts +43 -0
- package/templates/ui/components/controls/curves/curve-geometry.ts +355 -0
- package/templates/ui/components/controls/curves/curve-graph.tsx +390 -0
- package/templates/ui/components/controls/curves/curves-control.tsx +445 -0
- package/templates/ui/components/controls/curves/index.ts +6 -0
- package/templates/ui/components/controls/file-drop/file-drop-control.tsx +191 -0
- package/templates/ui/components/controls/file-drop/index.ts +5 -0
- package/templates/ui/components/controls/font-picker/font-catalog.json +15360 -0
- package/templates/ui/components/controls/font-picker/font-catalog.ts +116 -0
- package/templates/ui/components/controls/font-picker/font-picker-control.tsx +1202 -0
- package/templates/ui/components/controls/font-picker/font-preview-loader.ts +336 -0
- package/templates/ui/components/controls/font-picker/index.ts +24 -0
- package/templates/ui/components/controls/font-picker/use-hover-intent.ts +46 -0
- package/templates/ui/components/controls/gradient/gradient-control-utils.ts +190 -0
- package/templates/ui/components/controls/gradient/gradient-control.tsx +612 -0
- package/templates/ui/components/controls/gradient/gradient-stop-list.tsx +400 -0
- package/templates/ui/components/controls/gradient/gradient-toolbar.tsx +152 -0
- package/templates/ui/components/controls/gradient/index.ts +4 -0
- package/templates/ui/components/controls/image-picker/image-picker-control.tsx +139 -0
- package/templates/ui/components/controls/image-picker/index.ts +7 -0
- package/templates/ui/components/controls/index.ts +192 -0
- package/templates/ui/components/controls/range-input/index.ts +4 -0
- package/templates/ui/components/controls/range-input/range-input-control.tsx +173 -0
- package/templates/ui/components/controls/range-slider/index.ts +4 -0
- package/templates/ui/components/controls/range-slider/range-slider-control.tsx +122 -0
- package/templates/ui/components/controls/range-slider/range-slider-value.ts +61 -0
- package/templates/ui/components/controls/segmented/index.ts +8 -0
- package/templates/ui/components/controls/segmented/segmented-control.tsx +94 -0
- package/templates/ui/components/controls/select/index.ts +4 -0
- package/templates/ui/components/controls/select/select-control.tsx +223 -0
- package/templates/ui/components/controls/slider/index.ts +4 -0
- package/templates/ui/components/controls/slider/slider-control.tsx +150 -0
- package/templates/ui/components/controls/slider/slider-value.ts +56 -0
- package/templates/ui/components/controls/text-input/index.ts +4 -0
- package/templates/ui/components/controls/text-input/text-input-control.tsx +158 -0
- package/templates/ui/components/controls/use-measured-element-width.ts +42 -0
- package/templates/ui/components/controls/vector/index.ts +8 -0
- package/templates/ui/components/controls/vector/vector-control.tsx +401 -0
- package/templates/ui/components/panel/index.ts +19 -0
- package/templates/ui/components/panel/panel-actions.tsx +165 -0
- package/templates/ui/components/panel/panel-header.tsx +61 -0
- package/templates/ui/components/panel/panel-icon-button.tsx +96 -0
- package/templates/ui/components/panel/panel-section.tsx +168 -0
- package/templates/ui/components/panel/panel-surface.tsx +206 -0
- package/templates/ui/components/panel/panel.tsx +210 -0
- package/templates/ui/components/primitives/animated-loader.tsx +61 -0
- package/templates/ui/components/primitives/button-group.tsx +134 -0
- package/templates/ui/components/primitives/button.tsx +429 -0
- package/templates/ui/components/primitives/checkbox.tsx +62 -0
- package/templates/ui/components/primitives/editable-slider-value-label.tsx +337 -0
- package/templates/ui/components/primitives/field.tsx +225 -0
- package/templates/ui/components/primitives/index.ts +82 -0
- package/templates/ui/components/primitives/input-group.tsx +298 -0
- package/templates/ui/components/primitives/input.tsx +61 -0
- package/templates/ui/components/primitives/internal/button-loading.tsx +178 -0
- package/templates/ui/components/primitives/label.tsx +16 -0
- package/templates/ui/components/primitives/popover.tsx +126 -0
- package/templates/ui/components/primitives/portal-layer-context.tsx +33 -0
- package/templates/ui/components/primitives/primitive-arrow-icon.tsx +38 -0
- package/templates/ui/components/primitives/scroll-fade-logic.ts +441 -0
- package/templates/ui/components/primitives/scroll-fade-render.tsx +75 -0
- package/templates/ui/components/primitives/scroll-fade-types.ts +41 -0
- package/templates/ui/components/primitives/scroll-fade.tsx +72 -0
- package/templates/ui/components/primitives/select.tsx +408 -0
- package/templates/ui/components/primitives/selection-state.ts +31 -0
- package/templates/ui/components/primitives/separator.tsx +21 -0
- package/templates/ui/components/primitives/slider/index.ts +4 -0
- package/templates/ui/components/primitives/slider/slider-interaction.tsx +96 -0
- package/templates/ui/components/primitives/slider/slider-parts.tsx +303 -0
- package/templates/ui/components/primitives/slider/slider-reset.ts +152 -0
- package/templates/ui/components/primitives/slider/slider-value.ts +114 -0
- package/templates/ui/components/primitives/slider/slider.tsx +511 -0
- package/templates/ui/components/primitives/switch.tsx +35 -0
- package/templates/ui/components/primitives/textarea.tsx +49 -0
- package/templates/ui/components/primitives/toggle-group.tsx +114 -0
- package/templates/ui/components/primitives/toggle.tsx +46 -0
- package/templates/ui/components/primitives/tooltip.tsx +100 -0
- package/templates/ui/hooks/use-mobile.ts +21 -0
- package/templates/ui/index.ts +31 -0
- package/templates/ui/lib/control-outline.ts +3 -0
- package/templates/ui/lib/input-control-style.ts +131 -0
- package/templates/ui/lib/style-guide-color-utils.ts +111 -0
- package/templates/ui/lib/utils.ts +6 -0
- package/templates/ui/styles.css +291 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cleanup,
|
|
3
|
+
fireEvent,
|
|
4
|
+
render,
|
|
5
|
+
screen,
|
|
6
|
+
waitFor,
|
|
7
|
+
} from "@testing-library/react";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
10
|
+
|
|
11
|
+
import { defineToolcraft } from "../schema/define-toolcraft";
|
|
12
|
+
import { ToolcraftApp } from "./toolcraft-app";
|
|
13
|
+
import { ToolcraftRoot } from "./toolcraft-root";
|
|
14
|
+
import { LayersPanel } from "./layers-panel";
|
|
15
|
+
import { TimelinePanel } from "./timeline-panel";
|
|
16
|
+
import { ToolbarPanel } from "./toolbar-panel";
|
|
17
|
+
|
|
18
|
+
declare module "vitest" {
|
|
19
|
+
interface Assertion<T = any> {
|
|
20
|
+
toBeDisabled(): void;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
expect.extend({
|
|
25
|
+
toBeDisabled(received: HTMLElement) {
|
|
26
|
+
const pass =
|
|
27
|
+
received.matches(":disabled") ||
|
|
28
|
+
received.getAttribute("aria-disabled") === "true";
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
message: () => `expected element ${pass ? "not " : ""}to be disabled`,
|
|
32
|
+
pass,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
beforeAll(() => {
|
|
38
|
+
Object.defineProperty(window, "matchMedia", {
|
|
39
|
+
value: (query: string) => ({
|
|
40
|
+
addEventListener: () => undefined,
|
|
41
|
+
addListener: () => undefined,
|
|
42
|
+
dispatchEvent: () => false,
|
|
43
|
+
matches: query === "(prefers-reduced-motion: reduce)",
|
|
44
|
+
media: query,
|
|
45
|
+
onchange: null,
|
|
46
|
+
removeEventListener: () => undefined,
|
|
47
|
+
removeListener: () => undefined,
|
|
48
|
+
}),
|
|
49
|
+
writable: true,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
cleanup();
|
|
55
|
+
document.documentElement.classList.remove("dark");
|
|
56
|
+
document.documentElement.style.colorScheme = "";
|
|
57
|
+
window.localStorage.clear();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function createAssembledSchema() {
|
|
61
|
+
return defineToolcraft({
|
|
62
|
+
canvas: {
|
|
63
|
+
enabled: true,
|
|
64
|
+
size: { height: 180, unit: "px", width: 320 },
|
|
65
|
+
sizing: { mode: "editable-output" },
|
|
66
|
+
upload: true,
|
|
67
|
+
},
|
|
68
|
+
panels: {
|
|
69
|
+
controls: {
|
|
70
|
+
sections: [
|
|
71
|
+
{
|
|
72
|
+
controls: {
|
|
73
|
+
prompt: {
|
|
74
|
+
defaultValue: "Initial prompt",
|
|
75
|
+
label: "Prompt",
|
|
76
|
+
target: "generation.prompt",
|
|
77
|
+
type: "text",
|
|
78
|
+
},
|
|
79
|
+
opacity: {
|
|
80
|
+
defaultValue: 75,
|
|
81
|
+
label: "Opacity",
|
|
82
|
+
max: 100,
|
|
83
|
+
min: 0,
|
|
84
|
+
target: "selectedLayer.opacity",
|
|
85
|
+
type: "slider",
|
|
86
|
+
unit: "%",
|
|
87
|
+
},
|
|
88
|
+
enabled: {
|
|
89
|
+
defaultValue: true,
|
|
90
|
+
label: "Enabled",
|
|
91
|
+
target: "generation.enabled",
|
|
92
|
+
type: "switch",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
title: "Basic",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
actionGroup: "secondary",
|
|
99
|
+
controls: {
|
|
100
|
+
footer: {
|
|
101
|
+
actions: [
|
|
102
|
+
{
|
|
103
|
+
command: "controls.reset",
|
|
104
|
+
label: "Reset",
|
|
105
|
+
value: "reset",
|
|
106
|
+
variant: "outline",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
command: "controls.apply",
|
|
110
|
+
label: "Apply",
|
|
111
|
+
value: "apply",
|
|
112
|
+
variant: "default",
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
target: "panel.actions",
|
|
116
|
+
type: "panelActions",
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
layout: "standalone",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
title: "Master Controls",
|
|
123
|
+
},
|
|
124
|
+
layers: true,
|
|
125
|
+
timeline: true,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function renderAssembledEditor() {
|
|
131
|
+
return render(
|
|
132
|
+
<ToolcraftApp
|
|
133
|
+
schema={createAssembledSchema()}
|
|
134
|
+
style={{ height: 720, width: 960 }}
|
|
135
|
+
/>,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
describe("assembled Toolcraft template runtime", () => {
|
|
140
|
+
it("imports media into shared runtime state and lets toolbar history undo and redo it", async () => {
|
|
141
|
+
const { container } = renderAssembledEditor();
|
|
142
|
+
|
|
143
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
144
|
+
const file = new File(["image"], "material.png", { type: "image/png" });
|
|
145
|
+
|
|
146
|
+
fireEvent.drop(canvas, {
|
|
147
|
+
clientX: 0,
|
|
148
|
+
clientY: 0,
|
|
149
|
+
dataTransfer: {
|
|
150
|
+
files: [file],
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await waitFor(() => {
|
|
155
|
+
expect(
|
|
156
|
+
screen.getByRole("button", { name: "Select material.png" }),
|
|
157
|
+
).toBeTruthy();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
expect(
|
|
161
|
+
container.querySelector<HTMLElement>(
|
|
162
|
+
"[data-toolcraft-editable-canvas]",
|
|
163
|
+
)?.style.width,
|
|
164
|
+
).toBe("320px");
|
|
165
|
+
expect(
|
|
166
|
+
(screen.getByRole("button", { name: "Undo" }) as HTMLButtonElement)
|
|
167
|
+
.disabled,
|
|
168
|
+
).toBe(false);
|
|
169
|
+
|
|
170
|
+
fireEvent.click(screen.getByRole("button", { name: "Undo" }));
|
|
171
|
+
|
|
172
|
+
expect(
|
|
173
|
+
screen.queryByRole("button", { name: "Select material.png" }),
|
|
174
|
+
).toBeNull();
|
|
175
|
+
expect(
|
|
176
|
+
(screen.getByRole("button", { name: "Redo" }) as HTMLButtonElement)
|
|
177
|
+
.disabled,
|
|
178
|
+
).toBe(false);
|
|
179
|
+
|
|
180
|
+
fireEvent.click(screen.getByRole("button", { name: "Redo" }));
|
|
181
|
+
|
|
182
|
+
expect(
|
|
183
|
+
screen.getByRole("button", { name: "Select material.png" }),
|
|
184
|
+
).toBeTruthy();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("renders optional layers and timeline panels only when enabled by schema", () => {
|
|
188
|
+
renderAssembledEditor();
|
|
189
|
+
|
|
190
|
+
expect(screen.getByText("Layers")).toBeTruthy();
|
|
191
|
+
fireEvent.click(
|
|
192
|
+
screen.getByRole("button", { name: "Expand timeline panel" }),
|
|
193
|
+
);
|
|
194
|
+
expect(screen.getByText("Duration:")).toBeTruthy();
|
|
195
|
+
expect(
|
|
196
|
+
screen.getByText("Add your first keyframe from the properties panel."),
|
|
197
|
+
).toBeTruthy();
|
|
198
|
+
|
|
199
|
+
cleanup();
|
|
200
|
+
|
|
201
|
+
render(
|
|
202
|
+
<ToolcraftRoot
|
|
203
|
+
schema={defineToolcraft({
|
|
204
|
+
canvas: { enabled: true },
|
|
205
|
+
panels: {},
|
|
206
|
+
})}
|
|
207
|
+
>
|
|
208
|
+
<LayersPanel framed={false} />
|
|
209
|
+
<TimelinePanel framed={false} />
|
|
210
|
+
</ToolcraftRoot>,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
expect(screen.queryByText("Layers")).toBeNull();
|
|
214
|
+
expect(screen.queryByText("Duration:")).toBeNull();
|
|
215
|
+
expect(screen.queryByText("Dur:")).toBeNull();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("uses schema-disabled toolbar features in assembled apps", () => {
|
|
219
|
+
render(
|
|
220
|
+
<ToolcraftRoot
|
|
221
|
+
schema={defineToolcraft({
|
|
222
|
+
canvas: { enabled: true },
|
|
223
|
+
panels: {},
|
|
224
|
+
toolbar: {
|
|
225
|
+
history: false,
|
|
226
|
+
radar: false,
|
|
227
|
+
theme: false,
|
|
228
|
+
zoom: false,
|
|
229
|
+
},
|
|
230
|
+
})}
|
|
231
|
+
>
|
|
232
|
+
<ToolbarPanel framed={false} />
|
|
233
|
+
</ToolcraftRoot>,
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
expect(screen.queryByRole("button", { name: "Undo" })).toBeNull();
|
|
237
|
+
expect(screen.queryByRole("button", { name: "Redo" })).toBeNull();
|
|
238
|
+
expect(screen.queryByRole("button", { name: "Center canvas" })).toBeNull();
|
|
239
|
+
expect(screen.queryByRole("button", { name: "Zoom in" })).toBeNull();
|
|
240
|
+
expect(screen.queryByRole("button", { name: "Light theme" })).toBeNull();
|
|
241
|
+
expect(screen.queryByText("70%")).toBeNull();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("keeps schema-only apps wired through the full shared runtime base", async () => {
|
|
245
|
+
const { container } = renderAssembledEditor();
|
|
246
|
+
|
|
247
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
248
|
+
const world = container.querySelector<HTMLElement>(
|
|
249
|
+
"[data-toolcraft-canvas-world]",
|
|
250
|
+
);
|
|
251
|
+
const grid = container.querySelector("[data-toolcraft-canvas-grid]");
|
|
252
|
+
const themeScope = container.querySelector<HTMLElement>(
|
|
253
|
+
"[data-toolcraft-theme-scope]",
|
|
254
|
+
);
|
|
255
|
+
const toolbar = container.querySelector<HTMLElement>(
|
|
256
|
+
"[data-toolcraft-inspect-toolbar]",
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
expect(canvas).toBeTruthy();
|
|
260
|
+
expect(world).toBeTruthy();
|
|
261
|
+
expect(grid).toBeNull();
|
|
262
|
+
expect(
|
|
263
|
+
container.querySelector<HTMLElement>(
|
|
264
|
+
"[data-toolcraft-editable-canvas]",
|
|
265
|
+
)?.style.width,
|
|
266
|
+
).toBe("320px");
|
|
267
|
+
expect(screen.getByText("Master Controls")).toBeTruthy();
|
|
268
|
+
expect(screen.getByText("Layers")).toBeTruthy();
|
|
269
|
+
expect(screen.getByText("Dur:")).toBeTruthy();
|
|
270
|
+
expect(screen.queryByText("Duration:")).toBeNull();
|
|
271
|
+
expect(toolbar?.textContent).toContain("70%");
|
|
272
|
+
expect(screen.getByRole("button", { name: "Undo" })).toBeDisabled();
|
|
273
|
+
expect(screen.getByRole("button", { name: "Redo" })).toBeDisabled();
|
|
274
|
+
expect(themeScope?.dataset.toolcraftTheme).toBe("dark");
|
|
275
|
+
|
|
276
|
+
const canvasWidthInput = screen.getByDisplayValue("320");
|
|
277
|
+
|
|
278
|
+
fireEvent.change(canvasWidthInput, {
|
|
279
|
+
target: { value: "384" },
|
|
280
|
+
});
|
|
281
|
+
expect(
|
|
282
|
+
container.querySelector<HTMLElement>(
|
|
283
|
+
"[data-toolcraft-editable-canvas]",
|
|
284
|
+
)?.style.width,
|
|
285
|
+
).toBe("320px");
|
|
286
|
+
|
|
287
|
+
fireEvent.blur(canvasWidthInput);
|
|
288
|
+
expect(
|
|
289
|
+
container.querySelector<HTMLElement>(
|
|
290
|
+
"[data-toolcraft-editable-canvas]",
|
|
291
|
+
)?.style.width,
|
|
292
|
+
).toBe("384px");
|
|
293
|
+
|
|
294
|
+
fireEvent.change(screen.getByDisplayValue("Initial prompt"), {
|
|
295
|
+
target: { value: "Updated prompt" },
|
|
296
|
+
});
|
|
297
|
+
expect(screen.getByDisplayValue("Updated prompt")).toBeTruthy();
|
|
298
|
+
|
|
299
|
+
fireEvent.click(screen.getByRole("button", { name: "Reset" }));
|
|
300
|
+
expect(screen.getByDisplayValue("Initial prompt")).toBeTruthy();
|
|
301
|
+
expect(
|
|
302
|
+
container.querySelector<HTMLElement>(
|
|
303
|
+
"[data-toolcraft-editable-canvas]",
|
|
304
|
+
)?.style.width,
|
|
305
|
+
).toBe("320px");
|
|
306
|
+
|
|
307
|
+
fireEvent.click(screen.getByRole("button", { name: "Zoom in" }));
|
|
308
|
+
expect(screen.getByText("80%")).toBeTruthy();
|
|
309
|
+
|
|
310
|
+
const wheelEvent = new WheelEvent("wheel", {
|
|
311
|
+
bubbles: true,
|
|
312
|
+
cancelable: true,
|
|
313
|
+
deltaX: 20,
|
|
314
|
+
deltaY: -10,
|
|
315
|
+
});
|
|
316
|
+
expect(canvas.dispatchEvent(wheelEvent)).toBe(false);
|
|
317
|
+
await waitFor(() => {
|
|
318
|
+
expect(world?.style.transform).toContain("translate(-20px, 10px)");
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
fireEvent.click(screen.getByRole("button", { name: "Center canvas" }));
|
|
322
|
+
expect(world?.style.transform).toContain("translate(0px, 0px)");
|
|
323
|
+
|
|
324
|
+
fireEvent.click(screen.getByRole("button", { name: "Light theme" }));
|
|
325
|
+
expect(themeScope?.dataset.toolcraftTheme).toBe("light");
|
|
326
|
+
expect(document.documentElement.classList.contains("dark")).toBe(false);
|
|
327
|
+
|
|
328
|
+
const file = new File(["image"], "ready.png", { type: "image/png" });
|
|
329
|
+
fireEvent.drop(canvas, {
|
|
330
|
+
clientX: 0,
|
|
331
|
+
clientY: 0,
|
|
332
|
+
dataTransfer: { files: [file] },
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
await waitFor(() => {
|
|
336
|
+
expect(
|
|
337
|
+
screen.getByRole("button", { name: "Select ready.png" }),
|
|
338
|
+
).toBeTruthy();
|
|
339
|
+
});
|
|
340
|
+
expect(screen.getByRole("button", { name: "Undo" })).not.toBeDisabled();
|
|
341
|
+
|
|
342
|
+
fireEvent.click(
|
|
343
|
+
screen.getByRole("button", { name: "Expand timeline panel" }),
|
|
344
|
+
);
|
|
345
|
+
expect(screen.getByText("Duration:")).toBeTruthy();
|
|
346
|
+
expect(
|
|
347
|
+
screen.getByRole("button", { name: "Add Opacity keyframe" }),
|
|
348
|
+
).toBeTruthy();
|
|
349
|
+
});
|
|
350
|
+
});
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cleanup,
|
|
3
|
+
fireEvent,
|
|
4
|
+
render,
|
|
5
|
+
screen,
|
|
6
|
+
waitFor,
|
|
7
|
+
} from "@testing-library/react";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
10
|
+
|
|
11
|
+
import { defineToolcraft } from "../schema/define-toolcraft";
|
|
12
|
+
import type { ToolcraftCustomControlRendererProps } from "./control-renderers";
|
|
13
|
+
import { ToolcraftApp } from "./toolcraft-app";
|
|
14
|
+
import { useToolcraft } from "./use-toolcraft";
|
|
15
|
+
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
Object.defineProperty(window, "matchMedia", {
|
|
18
|
+
value: (query: string) => ({
|
|
19
|
+
addEventListener: () => undefined,
|
|
20
|
+
addListener: () => undefined,
|
|
21
|
+
dispatchEvent: () => false,
|
|
22
|
+
matches: query === "(prefers-reduced-motion: reduce)",
|
|
23
|
+
media: query,
|
|
24
|
+
onchange: null,
|
|
25
|
+
removeEventListener: () => undefined,
|
|
26
|
+
removeListener: () => undefined,
|
|
27
|
+
}),
|
|
28
|
+
writable: true,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
cleanup();
|
|
34
|
+
document.documentElement.classList.remove("dark");
|
|
35
|
+
document.documentElement.style.colorScheme = "";
|
|
36
|
+
window.localStorage.clear();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function createSchema() {
|
|
40
|
+
return defineToolcraft({
|
|
41
|
+
canvas: {
|
|
42
|
+
enabled: true,
|
|
43
|
+
size: { height: 180, unit: "px", width: 320 },
|
|
44
|
+
upload: true,
|
|
45
|
+
},
|
|
46
|
+
panels: {
|
|
47
|
+
controls: {
|
|
48
|
+
sections: [
|
|
49
|
+
{
|
|
50
|
+
controls: {
|
|
51
|
+
prompt: {
|
|
52
|
+
defaultValue: "Initial prompt",
|
|
53
|
+
label: "Prompt",
|
|
54
|
+
target: "generation.prompt",
|
|
55
|
+
type: "text",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
title: "Basic",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
title: "Controls",
|
|
62
|
+
},
|
|
63
|
+
layers: true,
|
|
64
|
+
timeline: true,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createCustomControlSchema() {
|
|
70
|
+
return defineToolcraft({
|
|
71
|
+
canvas: {
|
|
72
|
+
enabled: true,
|
|
73
|
+
size: { height: 180, unit: "px", width: 320 },
|
|
74
|
+
},
|
|
75
|
+
panels: {
|
|
76
|
+
controls: {
|
|
77
|
+
sections: [
|
|
78
|
+
{
|
|
79
|
+
controls: {
|
|
80
|
+
power: {
|
|
81
|
+
defaultValue: 10,
|
|
82
|
+
label: "Power",
|
|
83
|
+
target: "generation.power",
|
|
84
|
+
type: "customPower",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
title: "Custom",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
title: "Controls",
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function CanvasSlotProbe(): React.JSX.Element {
|
|
97
|
+
const { state } = useToolcraft();
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<span data-testid="canvas-slot-probe">
|
|
101
|
+
{state.canvas.size.width}:{state.mediaAssets.length}
|
|
102
|
+
</span>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function CustomValueProbe(): React.JSX.Element {
|
|
107
|
+
const { state } = useToolcraft();
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<span data-testid="custom-value-probe">
|
|
111
|
+
{String(state.values["generation.power"])}
|
|
112
|
+
</span>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe("ToolcraftApp", () => {
|
|
117
|
+
it("renders enabled runtime surfaces from the app schema", () => {
|
|
118
|
+
const { container } = render(<ToolcraftApp schema={createSchema()} />);
|
|
119
|
+
|
|
120
|
+
expect(
|
|
121
|
+
screen.getByRole("application", { name: "Canvas viewport" }),
|
|
122
|
+
).toBeTruthy();
|
|
123
|
+
expect(screen.getByText("Controls")).toBeTruthy();
|
|
124
|
+
expect(screen.getByText("Layers")).toBeTruthy();
|
|
125
|
+
expect(screen.getByText("Dur:")).toBeTruthy();
|
|
126
|
+
expect(screen.queryByText("Duration:")).toBeNull();
|
|
127
|
+
expect(screen.getByRole("button", { name: "Undo" })).toBeTruthy();
|
|
128
|
+
expect(screen.getByRole("button", { name: "Redo" })).toBeTruthy();
|
|
129
|
+
expect(screen.getByRole("button", { name: "Center canvas" })).toBeTruthy();
|
|
130
|
+
expect(screen.getByRole("button", { name: "Light theme" })).toBeTruthy();
|
|
131
|
+
expect(
|
|
132
|
+
container.querySelector('[data-slot="toolcraft-runtime-app"]'),
|
|
133
|
+
).toBeTruthy();
|
|
134
|
+
expect(
|
|
135
|
+
container.querySelector<HTMLElement>('[data-slot="toolcraft-runtime-app"]')
|
|
136
|
+
?.style.minWidth,
|
|
137
|
+
).toBe("1024px");
|
|
138
|
+
expect(
|
|
139
|
+
container.querySelector('[data-panel-type="controls"]'),
|
|
140
|
+
).toBeTruthy();
|
|
141
|
+
expect(container.querySelector('[data-panel-type="layers"]')).toBeTruthy();
|
|
142
|
+
expect(
|
|
143
|
+
container.querySelector('[data-panel-type="timeline"]'),
|
|
144
|
+
).toBeTruthy();
|
|
145
|
+
expect(container.querySelector('[data-panel-type="toolbar"]')).toBeTruthy();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("does not render disabled optional panels or toolbar features", () => {
|
|
149
|
+
const schema = defineToolcraft({
|
|
150
|
+
canvas: { enabled: true },
|
|
151
|
+
panels: {},
|
|
152
|
+
toolbar: {
|
|
153
|
+
history: false,
|
|
154
|
+
radar: false,
|
|
155
|
+
theme: false,
|
|
156
|
+
zoom: false,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
const { container } = render(<ToolcraftApp schema={schema} />);
|
|
160
|
+
|
|
161
|
+
expect(
|
|
162
|
+
screen.getByRole("application", { name: "Canvas viewport" }),
|
|
163
|
+
).toBeTruthy();
|
|
164
|
+
expect(screen.queryByText("Controls")).toBeNull();
|
|
165
|
+
expect(screen.queryByText("Layers")).toBeNull();
|
|
166
|
+
expect(screen.queryByText("Duration:")).toBeNull();
|
|
167
|
+
expect(screen.queryByText("Dur:")).toBeNull();
|
|
168
|
+
expect(screen.queryByRole("button", { name: "Undo" })).toBeNull();
|
|
169
|
+
expect(screen.queryByRole("button", { name: "Center canvas" })).toBeNull();
|
|
170
|
+
expect(container.querySelector('[data-panel-type="toolbar"]')).toBeNull();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("renders app-specific canvas content inside the shared runtime canvas slot", () => {
|
|
174
|
+
const { container } = render(
|
|
175
|
+
<ToolcraftApp
|
|
176
|
+
canvasContent={<CanvasSlotProbe />}
|
|
177
|
+
renderDefaultCanvasMedia={false}
|
|
178
|
+
schema={createSchema()}
|
|
179
|
+
/>,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const editableCanvas = container.querySelector<HTMLElement>(
|
|
183
|
+
"[data-toolcraft-editable-canvas]",
|
|
184
|
+
);
|
|
185
|
+
const canvasSlot = container.querySelector<HTMLElement>(
|
|
186
|
+
"[data-toolcraft-canvas-slot]",
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
expect(editableCanvas).toBeTruthy();
|
|
190
|
+
expect(canvasSlot?.parentElement).toBe(editableCanvas);
|
|
191
|
+
expect(screen.getByTestId("canvas-slot-probe").textContent).toBe("320:0");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("lets app-specific canvas renderers replace default media rendering while keeping upload state", async () => {
|
|
195
|
+
render(
|
|
196
|
+
<ToolcraftApp
|
|
197
|
+
canvasContent={<CanvasSlotProbe />}
|
|
198
|
+
renderDefaultCanvasMedia={false}
|
|
199
|
+
schema={createSchema()}
|
|
200
|
+
/>,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
204
|
+
const file = new File(["image"], "shader-input.png", {
|
|
205
|
+
type: "image/png",
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
fireEvent.drop(canvas, {
|
|
209
|
+
clientX: 0,
|
|
210
|
+
clientY: 0,
|
|
211
|
+
dataTransfer: {
|
|
212
|
+
files: [file],
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
await waitFor(() => {
|
|
217
|
+
expect(screen.getByTestId("canvas-slot-probe").textContent).toBe("320:1");
|
|
218
|
+
});
|
|
219
|
+
expect(
|
|
220
|
+
screen.queryByRole("button", { name: "Select shader-input.png" }),
|
|
221
|
+
).toBeNull();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("preserves reset, upload, and toolbar history without manual shell wiring", async () => {
|
|
225
|
+
render(<ToolcraftApp schema={createSchema()} />);
|
|
226
|
+
|
|
227
|
+
fireEvent.change(screen.getByDisplayValue("Initial prompt"), {
|
|
228
|
+
target: { value: "Updated prompt" },
|
|
229
|
+
});
|
|
230
|
+
expect(screen.getByDisplayValue("Updated prompt")).toBeTruthy();
|
|
231
|
+
|
|
232
|
+
fireEvent.click(screen.getByRole("button", { name: "Reset controls" }));
|
|
233
|
+
expect(screen.getByDisplayValue("Initial prompt")).toBeTruthy();
|
|
234
|
+
|
|
235
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
236
|
+
const file = new File(["image"], "material.png", { type: "image/png" });
|
|
237
|
+
|
|
238
|
+
fireEvent.drop(canvas, {
|
|
239
|
+
clientX: 0,
|
|
240
|
+
clientY: 0,
|
|
241
|
+
dataTransfer: {
|
|
242
|
+
files: [file],
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
await waitFor(() => {
|
|
247
|
+
expect(
|
|
248
|
+
screen.getByRole("button", { name: "Select material.png" }),
|
|
249
|
+
).toBeTruthy();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
fireEvent.click(screen.getByRole("button", { name: "Undo" }));
|
|
253
|
+
|
|
254
|
+
expect(
|
|
255
|
+
screen.queryByRole("button", { name: "Select material.png" }),
|
|
256
|
+
).toBeNull();
|
|
257
|
+
expect(
|
|
258
|
+
(screen.getByRole("button", { name: "Redo" }) as HTMLButtonElement)
|
|
259
|
+
.disabled,
|
|
260
|
+
).toBe(false);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("routes app-specific sticky footer actions from the assembled app shell", () => {
|
|
264
|
+
const handledActions: string[] = [];
|
|
265
|
+
const schema = defineToolcraft({
|
|
266
|
+
canvas: { enabled: true },
|
|
267
|
+
panels: {
|
|
268
|
+
controls: {
|
|
269
|
+
sections: [
|
|
270
|
+
{
|
|
271
|
+
controls: {
|
|
272
|
+
footer: {
|
|
273
|
+
actions: [
|
|
274
|
+
{
|
|
275
|
+
icon: "export",
|
|
276
|
+
label: "Export image",
|
|
277
|
+
value: "export",
|
|
278
|
+
variant: "default",
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
target: "panel.actions",
|
|
282
|
+
type: "panelActions",
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
title: "Export",
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
title: "Controls",
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
render(
|
|
294
|
+
<ToolcraftApp
|
|
295
|
+
onPanelAction={({ action }) => {
|
|
296
|
+
handledActions.push(action.value);
|
|
297
|
+
}}
|
|
298
|
+
schema={schema}
|
|
299
|
+
/>,
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
fireEvent.click(screen.getByRole("button", { name: "Export image" }));
|
|
303
|
+
|
|
304
|
+
expect(handledActions).toEqual(["export"]);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("renders registered custom controls through the shared runtime setter", async () => {
|
|
308
|
+
function CustomPowerControl({
|
|
309
|
+
name,
|
|
310
|
+
setValue,
|
|
311
|
+
value,
|
|
312
|
+
}: ToolcraftCustomControlRendererProps): React.JSX.Element {
|
|
313
|
+
return (
|
|
314
|
+
<button type="button" onClick={() => setValue(42)}>
|
|
315
|
+
{name}: {String(value)}
|
|
316
|
+
</button>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
render(
|
|
321
|
+
<ToolcraftApp
|
|
322
|
+
canvasContent={<CustomValueProbe />}
|
|
323
|
+
controlRenderers={{
|
|
324
|
+
customPower: CustomPowerControl,
|
|
325
|
+
}}
|
|
326
|
+
schema={createCustomControlSchema()}
|
|
327
|
+
/>,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
expect(screen.getByRole("button", { name: "Power: 10" })).toBeTruthy();
|
|
331
|
+
expect(screen.getByTestId("custom-value-probe").textContent).toBe("10");
|
|
332
|
+
|
|
333
|
+
fireEvent.click(screen.getByRole("button", { name: "Power: 10" }));
|
|
334
|
+
|
|
335
|
+
await waitFor(() => {
|
|
336
|
+
expect(screen.getByTestId("custom-value-probe").textContent).toBe("42");
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|