2.1.7 • Published 2 months ago

@violentmonkey/dom v2.1.7

Weekly downloads
6
License
ISC
Repository
github
Last release
2 months ago

@violentmonkey/dom

NPM License jsDocs.io

Use JSX for HTML elements.

Based on @gera2ld/jsx-dom.

What is it?

This library is just a light wrapper around document.createElement. So we can easily create DOM elements using JSX with the help of this library instead of writing tedious imperative code.

When should we NOT use it?

You should NOT use it when you use a library that has its own implementation of JSX, such as React, Vue, Svelte, SolidJS, etc. The JSX syntaxes are incompatible and using them together will cause unexpected issues.

You don't need it if you initialize a userscript project with generator-userscript, which uses solid-js.

However, you can still use methods like VM.h directly without using JSX to make the code shorter.

Usage

First, include @violentmonkey/dom as a dependency:

// ...
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2
// ...

Then you can use VM.h (similar to React.createElement) and VM.m (for mounting as DOM elements) directly.

There is also a VM.hm for VM.h plus VM.m if you don't need SVG support and want to get rid of VM.m.

const vdom = VM.h('div', {}, 'hello');
const el = VM.m(vdom); // -> HTMLDivElement

// or
const el = VM.hm('div', {}, 'hello'); // -> HTMLDivElement

document.body.appendChild(el);

Or use with JSX and bundlers, for example:

// .babelrc.js
{
  plugins: [
    // JSX
    ['@babel/plugin-transform-react-jsx', {
      pragma: 'VM.h', // or 'VM.hm' if you don't need SVG support and want to get rid of 'VM.m'
      pragmaFrag: 'VM.Fragment',
    }],
  ],
}
// pragma: VM.h
document.body.appendChild(VM.m(<div>hello</div>));

// pragma: VM.hm
document.body.appendChild(<div>hello</div>);

API

See jsDocs.io.

2.1.7

2 months ago

2.1.6

2 months ago

2.1.5

9 months ago

2.1.4

1 year ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.1.3-0

2 years ago

2.1.3-1

2 years ago

2.0.2

3 years ago

2.0.0-3

3 years ago

2.0.2-0

3 years ago

2.0.0-2

3 years ago

2.0.0-1

3 years ago

2.0.0-0

3 years ago

2.1.0

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago