#Web Component Support
1 messages · Page 1 of 1 (latest)
Question from @flat pond: #dev-support message
Why would you need to have entirely custom tags instead of using stuff like span/div with a class assigned?
@flat pond The way web components work is that you register a custom tag with the browser.
https://developer.mozilla.org/en-US/docs/Web/API/Window/customElements
Here is how I was doing it in the ready hook. I'm using Svelte to make a web component, but you could use any library / Lit, etc. or even just a plain ESM / JS file.
import MyChatMessage from './view/webcomponent/MyChatMessage.svelte';
Hooks.once('ready', () =>
{
customElements.define('my-chat-message', MyChatMessage);
});
Then use <my-chat-message/> in a content area.
There have been other requests for web component support, so this isn’t a new suggestion, and it’s one we might well entertain when it comes around to supporting multiple application rendering backends when we develop App V2
Cool.. Right on.. It definitely is easy enough to manage creating / loading web components from any module / system, etc.
Glad to hear that a proposal / method to make it happen may come to Foundry in the future.
It definitely is something that can be used by any application rendering library be it handlebars or otherwise since it is "library neutral" so to speak.
It can be used now, just not in user content areas that go through HTML sanitation.
Replying to @wintry finch :
#dev-support message
Moving discussion back to the thread.
Interestingly enough... Just did a little test / mostly CSS. Perhaps the x- tag creates a div, but an "unknown tag" can still be styled and the internal content shows up styled; IE the some text part. Didn't know that.. Granted the example is from a Svelte component, but would apply to raw CSS / HTML too.
A WC does support "slots" and such for internal content to WC tags.
A non-container tag like <wc-stat-block docId="DOCUMENT_ID"/> would just be ignored / no content displayed if the WC was not registered.
I just found it interesting that you can style an unknown tag and the styles take with content in between closing / opening tags.
@wintry finch the info / page you found appears to be very old / circa 2011 prior to the web component spec / introduction it seems.
The Web Component spec initally appeared in 2012 w/ mainstream browser adoption between 2018 - 2020. And for most mobile browsers very recently this year in February.
I saw that date afterwards. I don't think it changes the analysis significantly though.
Ah, but it is an analysis of an unaccepted / unofficial specification / IE the WHATWG "Component Model", so probably of limited use / not accurate to actual WC world of today.
I don't think "non-container" HTMLUnkownElements are possible:
I gather the non-container unknown tags are just ignored. I just thought it was curious w/ the test above that an unknown tag can have CSS attached and still style content in between the unknown tag.
I used a "non-standard" grid and row elements here and it works exactly like <div class="grid"></div>
Yeah. Styled it too
Well certainly interesting! Though I'm not sure if it is interpreted by the browser as <div class="grid"></div> and who knows if it would work in other browsers besides Chrome which is the only one I tested.
It also works on Firefox at least. That code is from a Wordle clone I'm working on for my friends at school and as a way to learn Svelte: https://arcanist.me/wordle-clone/
https://github.com/arcanistzed/wordle-clone
Yeah.. Just tested Firefox myself. 😛
Anyway. I don't think that it should be an issue for core to be concerned about supporting all things considered.
Yeah... a little yak shaving in the discussion here. ;P Good to know though.
For core it's a decision of do we let WC through in user content areas; hopefully this falls in the "low hanging fruit" category and can be considered.
Looks like someone was following along with this conversation: https://gitlab.com/foundrynet/foundryvtt/-/issues/6877
I love the start of it chat messages get satanized 😈 I also think that being able to use web components everywhere could help with structure of the web gui.