PomiGen 如何將提示詞圖庫接入 React 圖片編輯器
How we carry a prompt gallery into a React image editor
PomiGen 為提示詞圖庫設計三種通往 React 圖片編輯器的入口,分別用於創作相似內容、編輯原圖及將圖片用作參考。圖庫連結透過 URL 傳遞提示詞 ID,另外兩種操作會加入模式及圖片索引;編輯原圖時指令欄留空,同一提示詞資料重新載入也不會覆寫已輸入的草稿。
Posted on Nov 24 Fully Autonomous
A gallery thumbnail is a surprisingly ambiguous starting point for an image editor. Someone looking at a studio photo of a coffee cup might want the lighting recipe for a different product. Someone else might want to remove a spoon from that exact photograph. Those clicks should open different editor states.
We ran into this while building the prompt gallery for PomiGen. Here is the small routing decision behind our three entry points.
| Gallery action | Initial text | Initial reference image |
|---|---|---|
| Make something similar | The example prompt | None |
| Edit this image | Empty, ready for an instruction | The selected image |
| Use as reference | The example prompt | The selected image |
Pass an identifier through the URL
The gallery link carries a prompt ID. The other two actions add a mode and an image index. The index matters when an example has several images: if a reader is looking at the third one, using the cover image would silently change their input.
The workbench fetches the example by ID. If an image index is missing or out of range, it falls back to the first image. An edit starts with a blank instruction because the caption that generated the original cup is rarely the instruction someone needs to remove the spoon.
Initialize the form once
Applying a fetched prompt to editable React state has a trap. If the query refreshes after someone has started typing, an effect can overwrite their changes. Our workbench records which prompt ID has already initialized the text field. A refresh of that same record leaves the draft alone. Image selection is handled separately because it also depends on the selected image index.
Three checks worth trying in your own editor:
- Open the second image in a gallery entry and choose Edit. Check that the second image arrives with an empty instruction.
- Open Make something similar, change a sentence, and trigger a query refresh. Check that your edit survives.
- Open Use as reference. Check both the input image and the text before generating anything.
You can test all three transitions without spending a generation credit. Inspecting the inputs catches a routing mistake that a plausible-looking generated image can easily hide.
Written with AI assistance using our project's implementation.
來源:DEV Community · dev.to