"in app" editing app #2135
Replies: 2 comments 4 replies
-
Nice exploration & really good ideas! It seems like returning "magic" strings from the message-render function is the most viable approach. Unfortunately, we are likely going to run into reactivity challenges when trying to toggle between magic-strings and regular text message rendering. Might it be possible to use invisible characters (zero width space & co) to encode the message ID in a text node? This would side-step any flickering issues caused by the magic-string replacement. Edit: Just checked, and we can put Zero-width spaces into messages without |
Beta Was this translation helpful? Give feedback.
-
I suggest not shipping such functionality in Paraglide but launching a dedicated app.
|
Beta Was this translation helpful? Give feedback.
-
the idea to have "in app editing" or at least a simple way to get from the rendered view of a message to the place where it can be edited (similar to clicking on a component with svelte dev tools) came up multiple times. this discussion will keep track of current limitations and possibilities.
mini-hackathon outcome:
i investigated 3 possible ways to connect the dom nodes for attaching the edit ui to the source of messages.
a) using build-metadata: would work only for specific build tools (vite/esbuild), is limited to showing connections by file eg. component "a" uses message "b" and "c" but not where exactly the message is rendered. this seeems too limiting to investigate further unless all other options fail for some reason.
b) using runtime magic to get information about the rendering context of a message: this seems not possible for pure functions with modern js/ strict mode. when using svelte stores instead of functions, it would be possible to get a connection of each component to which messages are used there. the same limitations as option "a" apply.
c) in the end all messages are rendered to text nodes, therefore the only left option to really associate specific nodes with metadata is by annotating the rendered text with message id and possibly source file information in the text output. in the final poc the format
<magicstring>__<messageId>__<magicstring>
was used as it allows simple parsing and debugging.the poc used a mutation observer to look for added dom nodes, scan for the magicstring, remove it from the rendered output and move the metadata annotation to a data attribute of the parent node, so that the ui can attach to this. this worked well but proved to be limiting on the dev experience when not using this feature, as the impact on normal development would be too great (performance impact, flashes of magicstring if it is not removed fast enough etc.), the only viable solution for a next iteration would be to use a hotkey or a toggle switch to enable this behaviour selectively instead of always while in dev mode, similar to svelte dev tools. this would reqire paraglide to not use a devtool flag on startup time but be able to add runtime context to the message render functions that was previously compiled with the message id in scope. This would allwo it to add the magicstring and metadata just in a specific message function execution.
another limitation is the use of html tags in messages and the connected use of "{@html" in svelte, to support these constructs, the text annotation is not required/possible but has to be done directly in the message render function, which also requires to add some wrapper divs or spans to be able to attach the ui to the right entities and not just parts of the html messages.
steps for a viable solution based on current learnings would be:
code snippets from poc:
mutation observer
edit ui:
Beta Was this translation helpful? Give feedback.
All reactions