w3c / webcomponents-cg

Web Components community group
https://w3c.github.io/webcomponents-cg/
189 stars 11 forks source link

Proposal Demo Day #80

Closed trusktr closed 5 months ago

trusktr commented 7 months ago

Reply here with a link and description of your concept to present on demo day. I'll update OP to list them:

JRJurman commented 7 months ago

I would love to talk briefly about Tram-Deco, a DCE implementation that leans on Declarative Shadow DOM, existing Web Component APIs, and has some affordances for external component definitions (nothing super close to HTML Modules, but would certainly benefited by it 😅).

trusktr commented 7 months ago

element-modules - Proof of concept of declarative custom elements that are importable from .html files or JS files, no build step or tooling needed, in an HTML-first format akin to component systems like Vue or Svelte with JS being optional. codepen.io/trusktr/pen/gOEWGXV

thescientist13 commented 7 months ago

On the topic of HTML Modules, I would like to demo supporting the (DX) use case for the separation of technologies / concerns (whichever side you land on!) that would now be unlocked by extending the module system all the way through to HTML. 💯

// hero.js
import sheet from './hero.css' with { type: "css" };
import template from "./hero.html" with { type: "html" };

export default class Hero extends HTMLElement {
  connectedCallback() {
    if(!this.shadowRoot) {
      this.attachShadow({ mode: 'open' });

      this.shadowRoot.appendChild(template.content.cloneNode(true));
      this.shadowRoot.adoptedStyleSheets = [sheet];
    }
  }
}

customElements.define('app-hero', HeroBanner)
<!-- hero.html -->
<div class="hero">
  <h2>This is a really nice website!/h2>
  <img src="/path/to/image.png">
</div>
/* hero.css */
:host {
  text-align: center;
  margin-bottom: 40px;
}

:host h2 {
  font-size: 3em;
}

I'm honestly less opinionated about what the actual return value is, aside from just making the use case / developer workflow possible, be it <template> or a document fragment.

I don't have a full demo yet but will be able to provide it next week (yay OSS vacation!) with SSR, depending on when we need to present by and if any other folks would be interested in this as well.


I've chosen to use a <template> partially because I could see this being augmented with DOM Parts and I think those were mentioned in the proposal, but as mentioned, I'm not super opinionated outside of just ensuring compatibility since i believe this would / could work really nicely together. 🤩

// this vision aims to support the separation of concerns / technologies use case for Web Components
import sheet from './hero.css' with { type: "css" };
import template from "./hero.html" with { type: "html" };

export default class Hero extends HTMLElement {
  connectedCallback() {
    if(!this.shadowRoot) {
      // with DOM Parts
      const heading = this.getAttribute('heading');
      const heading = this.getAttribute('image');

      template.heading.value = heading;
      template.image.value = image;

      this.attachShadow({ mode: 'open' });
      this.shadowRoot.appendChild(template.content.cloneNode(true));
      this.shadowRoot.adoptedStyleSheets = [sheet];
    }
  }
}

customElements.define('app-hero', Hero)
<div>
  <h2>{{heading}}</h2>
  <img src="{{image}}" />
</div>
trusktr commented 7 months ago

@thescientist13 is there a link to your concept, or a concise description I can paste in the OP?

trusktr commented 7 months ago

@sashafirsov what's the conciese description for yours that I can use for the list in the OP above?

trusktr commented 7 months ago

@EisenbergEffect what's the title and description for yours to put in the list in the OP above?

EisenbergEffect commented 7 months ago

Well, the document is just titled "HTML Modules and Declarative Custom Elements Proposal".

trusktr commented 7 months ago

@EisenbergEffect 👍 updated the list in the OP

sashafirsov commented 7 months ago

@trusktr ,

what's the conciese description for yours that I can use for the list in the OP above?

I guess "pure declarative DCE POC" would fit the bill.

sashafirsov commented 7 months ago

Not sure, should those be listed among implementations, as custom-element is more functional.

Pure declarative DCE:

dy commented 7 months ago

I've done some research / work on possible approaches to DCE as well https://github.com/dy/define-element/blob/main/README.md

Some solutions are tentative, others are more-less tested out / proven.

jaredcwhite commented 6 months ago

I have a library that supports DCE, and also supports defining components in HTML Modules, but not DCE directly inside an HTML Module so I want to try to add that and then I'll throw my hat in the ring. I'll try to get that done later in the week…if not I'll let you know I might not make it in time.

jaredcwhite commented 6 months ago

Still lots to document, but you can take a look now at Heartml, and in particular the sections on Module files and DCEs (scroll down a bit).

Obviously Heartml encompasses a lot of concepts beyond what we'd been looking at for immediate specs inspiration, but the various pieces you could imagine getting closer to the "metal" over time (aka template syntax could get closer to Parts, it could use native Signals instead of the Preact library, property/attribute reflection, etc.)

FYI, a lot of this stuff is already in production on a few sites I run. Pretty fun stuff!

justinfagnani commented 6 months ago

I would like to demo Stampino Element: https://github.com/justinfagnani/stampino-element

intervalia commented 6 months ago

At some point I would love to demo my transpiler: https://www.npmjs.com/package/@evolvedweb/wc https://www.evowc.com/docs/intro

jogibear9988 commented 6 months ago

I've also added a simple DCE to my BasicWebcomponent (https://github.com/node-projects/base-custom-webcomponent) wich I'd like to show. I can also show my Designer: https://node-projects.github.io/web-component-designer-demo/index.html wich also supports usage of DCE (and all other webcomponents) I could also show webUi wich is a UI designer for iobroker (a homeautomation system), in this I've included the concept of desinging components in the ui, and reuse them as webcomponents in other views (http://129.159.205.3:8082/webui/index.html)

iammoonman commented 6 months ago

Small syntax idea I'd be happy to talk about for doing reasonably familiar declarative logic in the template: https://gist.github.com/iammoonman/986ffd0fcfda884dfcf00508635882e6

Westbrook commented 6 months ago

@dy and @jaredcwhite please share you availability for the next Demo Day so we can include your work: https://www.when2meet.com/?24156364-pOaZk

JRJurman commented 6 months ago

We're going to need 3 demo days at this point 😆

jogibear9988 commented 6 months ago

Workin sample of DCE version of my web component library:

[Sample](https://node-projects.github.io/web-component-designer-demo/index.html?html=%3Cnode-projects-dce%20name=%22simple-dce-demo%22%20properties=%27{%22list%22:%22Array%22,%20%22list2%22:%22Array%22,%20%22ctx%22:{%22type%22:%22String%22,%22reflect%22:true}}%27%20enable-bindings%20%3E%20%3Ctemplate%3E%20%3Cstyle%3Eh1%20{color:%20red}%3C/style%3E%20%3Ch1%3EHello%20World%3C/h1%3E%20%3Cdiv%20style=%22border:%20solid%203px%20black%22%3ECtx:%20[[this.ctx]]%3C/div%3E%20%3Ctemplate%20repeat:myitem=%22[[this.list]]%22%3E%20%3Cbutton%3E[[myitem.toUpperCase()]]%20-%20%3Cb%3E[[myitem.toLowerCase()]]%3C/b%3E%20-%20[[index]]%3C/button%3E%20%3Cul%3E%20%3Ctemplate%20repeat:myitem2=%22[[this.list2]]%22%20repeat-index=%22inneridx%22%3E%20%3Cbutton%20@click=%22[[this.ctx%20=%20myitem2]]%22%20%3E[[myitem.toUpperCase()]]%20-%20%3Cb%3E[[myitem2.toLowerCase()]]%3C/b%3E%20-%20[[inneridx%20*%20100]]%3C/button%3E%20%3C/template%3E%20%3C/ul%3E%20%3C/template%3E%20%3C/template%3E%20%3C/node-projects-dce%3E%20%3Csimple-dce-demo%20list=%27[%22aa%22,%22bb%22,%22cc%22]%27%20list2=%27[%22hello%22,%20%22you%22]%27%20ctx=%22TestCtx%22%20style=%22position:absolute;left:184px;top:-53px;%22%3E%3C/simple-dce-demo%3E)

you could edit the declaritive custom element, and the changed template is adopted on all instance of the element already created. Don't know if this is something that should be possible/used at runtime, but for designtime I think it's usefull.

Supports Bindings (to Atrributes, Properties, Styles, two-way), Events (with direct included js code).

One downside atm is, a changed value refreshes all the bindings, this is smth. I've to find a good solution for.

Westbrook commented 5 months ago

Great sessions all. Be sure to continue the conversation in the various discussions opened around this.

dy commented 4 months ago

@Westbrook is there particular reason define-element was omitted?

Westbrook commented 4 months ago

If I omitted something in some way, it was by no mean intentional. Feel free to create any issues, discussion, or whatnot that I may have missed trying to cover the large amount of really amazing work by you and the rest of the participants.

dy commented 2 months ago

https://github.com/kgscialdone/facet https://github.com/vimeshjs/vimesh-ui