T
TyphonJSgeoidesic

How do I get the elementRoot of a ChatMessage?

SvelteApplication provides elementRoot prop to components that implement it, which is very useful. I'm looking to get something similar for my Svelte chat message templates. I'm using this in index.js
Hooks.on('renderChatMessage, (message, html) => {
message._svelteComponent = new SurgeRoll(
{
target: html[0],
props: {
surgeMessage,
messageId: message._id
}
}
)
}
Hooks.on('renderChatMessage, (message, html) => {
message._svelteComponent = new SurgeRoll(
{
target: html[0],
props: {
surgeMessage,
messageId: message._id
}
}
)
}
SurgeRoll.svelte does this:
<script>
import * as ChatComponents from "~/view/chatmessage/rollchat";
export let surgeMessage;
</script>

<svelte:component this={ChatComponents[surgeMessage.chatTemplate]} {...$$props} />
<script>
import * as ChatComponents from "~/view/chatmessage/rollchat";
export let surgeMessage;
</script>

<svelte:component this={ChatComponents[surgeMessage.chatTemplate]} {...$$props} />
The svelte:component is the component in which I want to get hold of that root element. Specifically I want to be able to do something like:
elementRoot.style.setProperty("--sheet-color", owner.color);
elementRoot.style.setProperty("--sheet-color", owner.color);
... which I'm currently using successfully in my SvelteApplication ActorSheet component.
TM
TyphonJS (Michael)310d ago
elementRoot is a prop of the component ApplicationShell, so you are in full control with your own components for chat messages.
G
geoidesic310d ago
Ok I don't understand what ApplicationShell has to do with the above? (Nor where to find it)
TM
TyphonJS (Michael)310d ago
It doesn't and you are not using it in this case. If you are not using it there is no elementRoot to bind. I suggest though that you check out the applyStyles action from @typhonjs-fvtt/runtime/svelte/action This import will change in the coming release. Unfortunately I don't have time right now to have a lengthy discussion. I need to finish this release up absolutely by tomorrow.
G
geoidesic309d ago
Thanks I managed to get it working using style-props for the Chat Message: https://svelte.dev/docs/component-directives#style-props However, I've been looking at applyStyles within the context of Application Shell and haven't quite figured out how to get it to apply the styles. I tried:
stylesApp = `--sheet-color="${getActorOwner($documentStore).color}"`;
stylesApp = `--sheet-color="${getActorOwner($documentStore).color}"`;
and then
ApplicationShell(bind:elementRoot bind:stylesApp)
ApplicationShell(bind:elementRoot bind:stylesApp)
And I can see that the value is reaching ApplicationShell's props but it's not populating to the rendered style property for the app. Maybe it's the wrong type. Should be an object I guess. Yup! That did it 🙂
Want results from more Discord servers?
Add your server
More Posts
Getting started with the GUI and understanding element rootIt's been a while, but I've been working on my Knowledge Recalled module since V11 is out, and my frDrag & Drop broke in v11Ok so something that broke for me when moving to v11 is drag&drop from both the items tab of the sidTJSDocument and Token Issues```js const tokens = cardData.targets .map(t => [t, fromUuidSync(t)]) .filter(([_, tSyrinControl & Svelte...I gather there is a bit to discuss... 😄Ver .11Not sure if this is the place to ask, but updated to v .7.11 foundry 10. Lost all quest data. FoldePackage Release: Foundry Summons (3rd party)Greets @everyone. I do try to use pings sparingly, but want to show a spotlight on @vauxs new packagCreating an interim TJSDocument / document attribute bridgeHi @wasp... Just moving discussion here as it is a better forum post. > So I have made a system wiTJSGameSettings with not registered settings.I am not sure what is happening in here. I have created an attachement to the existing Settings pagStoring a collection of Items in an Item?Use cases would be: - containers could contain other Items - some items have prerequisites, which coRelease: Quest Log `0.7.12`Greets @FVTT ▹ Quest Log! The v11 compatibility release is now available from the Foundry package mTJSDialog how to use buttons and callback or return value?I'm planning to use TJSDialog to act as an intervening Application. So... player clicks a button thaRelease: `TRL 0.0.23` - "v11 hot patch"Greets @FVTT ▹ Developer! I just released a hot patch of TRL for v11 support. The only thing changv11 Debug embedded collection changesJust a post to track the v11 changes to embedded collections and what needs to be updated in an inteCopying existing FQL to a new worldHello! I am running a world with Forien's Quest Log set up in a world, and I updated Foundry from v8