npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monaco-tailwindcss

v0.6.1

Published

Tailwindcss integration for Monaco editor

Downloads

1,079

Readme

Monaco Tailwindcss

ci workflow npm version prettier code style demo netlify Status

Tailwindcss integration for Monaco editor.

Table of Contents

Installation

npm install monaco-tailwindcss

Usage

Import monaco-tailwindcss and configure it before an editor instance is created.

import * as monaco from 'monaco-editor'
import { configureMonacoTailwindcss, tailwindcssData } from 'monaco-tailwindcss'

monaco.languages.css.cssDefaults.setOptions({
  data: {
    dataProviders: {
      tailwindcssData
    }
  }
})

configureMonacoTailwindcss(monaco)

monaco.editor.create(document.createElement('editor'), {
  language: 'html',
  value: `<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <div class="w-6 h-6 text-gray-600 bg-[#ff8888] hover:text-sky-600 ring-gray-900/5"></div>
  </body>
</html>
`
})

Also make sure to register the web worker. When using Webpack 5, this looks like the code below. Other bundlers may use a different syntax, but the idea is the same. Languages you don’t used can be omitted.

window.MonacoEnvironment = {
  getWorker(moduleId, label) {
    switch (label) {
      case 'editorWorkerService':
        return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url))
      case 'css':
      case 'less':
      case 'scss':
        return new Worker(new URL('monaco-editor/esm/vs/language/css/css.worker', import.meta.url))
      case 'handlebars':
      case 'html':
      case 'razor':
        return new Worker(
          new URL('monaco-editor/esm/vs/language/html/html.worker', import.meta.url)
        )
      case 'json':
        return new Worker(
          new URL('monaco-editor/esm/vs/language/json/json.worker', import.meta.url)
        )
      case 'javascript':
      case 'typescript':
        return new Worker(
          new URL('monaco-editor/esm/vs/language/typescript/ts.worker', import.meta.url)
        )
      case 'tailwindcss':
        return new Worker(new URL('monaco-tailwindcss/tailwindcss.worker', import.meta.url))
      default:
        throw new Error(`Unknown label ${label}`)
    }
  }
}

API

This package exposes two exports. One to setup the main logic, another to customize the Tailwind configuration in the worker.

monaco-tailwindcss

configureMonacoTailwindcss(monaco, options?)

Configure monaco-tailwindcss.

Arguments:

  • monaco: The monaco-editor module. (object)
  • options: An object with the following properties:
    • languageSelector: The language ID or IDs to which to apply monaco-unified. (string | string[], optional, default: ['css', 'javascript', 'html', 'mdx', 'typescript'])
    • tailwindConfig: The tailwind configuration to use. This may be either the Tailwind configuration object, or a string that gets processed in the worker. (object | string, optional)

Returns: A disposable with the following additional properties:

  • setTailwindConfig(tailwindConfig): Update the current Tailwind configuration.
  • generateStylesFromContent(css, content): Generate a CSS string based on the current Tailwind configuration.

tailwindcssData

This data can be used with the default Monaco CSS support to support tailwind directives. It will provider hover information from the Tailwindcss documentation, including a link.

monaco-tailwindcss/tailwindcss.worker

initialize(options)

Setup the Tailwindcss worker using a customized configuration.

Arguments:

  • options: An object with the following properties:
    • prepareTailwindConfig(tailwindConfig) A functions which accepts the Tailwind configuration passed from the main thread, and returns a valid Tailwind configuration.

Related projects

Showcase

  • Motif uses monaco-tailwindcss to provide Tailwindcss intellisense in their MDX based content editor.

License

MIT @ Remco Haszing