Skip to content
GitHub

Editor support

Custom element data for VS Code and typed tag names.

On every build start, and whenever a *.ce.* file changes, the plugin runs web-component-analyzer over js, templates and components. The result gives you tag and attribute completion in Twig and HTML files.

VS Code

Point VS Code to the generated file:

.vscode/settings.json
{
  "html.customData": [
    "web/themes/custom/mytheme/.uebertool/vscode.html-custom-data.json"
  ]
}

Documenting elements

Write a JSDoc comment with an @element tag. For Vue files, put it in a <docs> block:

<docs lang="ts">
/**
 * A Vue single file component as custom element.
 *
 * @element demo-hello-vue
 *
 * @attr {string} name - Who to greet.
 *
 * @slot - Appended after the greeting.
 */
</docs>

Generated for this theme

.uebertool/vscode.html-custom-data.json
{
  "version": 1,
  "tags": [
    {
      "name": "demo-translated-cart",
      "description": "Translatable strings in a lazily loaded custom element.\n\nAttributes:\n\n  * `count` {number} - Number of items in the cart.",
      "attributes": [
        {
          "name": "count",
          "description": "`count` {number} - Number of items in the cart.\n\n"
        }
      ]
    },
    {
      "name": "demo-mouse-tracker",
      "description": "Uses auto-imported APIs only: `ref`/`computed` (vue preset),\n`useMouse` (@vueuse/core preset) and `formatMs` (./js/utils).\n\n",
      "attributes": []
    },
    {
      "name": "demo-tailwind-card",
      "description": "Tailwind utilities inside the shadow DOM of a Vue custom element.\n\nSlots:\n\n  * ` ` {} - Card body.\n\nAttributes:\n\n  * `heading` {string} - Card heading.",
      "attributes": [
        {
          "name": "heading",
          "description": "`heading` {string} - Card heading.\n\n"
        }
      ]
    },
    {
      "name": "demo-hello-lit",
      "description": "A Lit element.\n\nSlots:\n\n  * ` ` {} - Appended after the greeting.\n\nAttributes:\n\n  * `name` {string} - Who to greet.\n\nProperties:\n\n  * `properties` {`{ name: { type: any; }; }`} - \n\n  * `styles` - \n\n  * `name` {string} - Who to greet.",
      "attributes": [
        {
          "name": "name",
          "description": "`name` {string} - Who to greet.\n\nProperty: name\n\nDefault: Somebody"
        }
      ]
    },
    {
      "name": "demo-hello-tsx",
      "description": "A custom element that renders JSX with Preact.\n\nAttributes:\n\n  * `name` {string} - Who to greet.",
      "attributes": [
        {
          "name": "name",
          "description": "`name` {string} - Who to greet.\n\n"
        }
      ]
    },
    {
      "name": "demo-hello-vanilla",
      "description": "A vanilla custom element.\n\nAttributes:\n\n  * `name` {string} - Who to greet.",
      "attributes": [
        {
          "name": "name",
          "description": "`name` {string} - Who to greet.\n\n"
        }
      ]
    },
    {
      "name": "demo-hello-vue",
      "description": "A Vue single file component as custom element.\n\nSlots:\n\n  * ` ` {} - Appended after the greeting.\n\nAttributes:\n\n  * `name` {string} - Who to greet.",
      "attributes": [
        {
          "name": "name",
          "description": "`name` {string} - Who to greet.\n\n"
        }
      ]
    }
  ],
  "globalAttributes": [],
  "valueSets": []
}

Vue custom elements are also added to HTMLElementTagNameMap, so document.querySelector('demo-hello-vue') is typed:

.uebertool/custom-elements.d.ts
export {}

declare global {
interface HTMLElementTagNameMap {
  "demo-hello-vue": HTMLElement
  "demo-mouse-tracker": HTMLElement
  "demo-tailwind-card": HTMLElement
  }
}