mono-jsx-dom 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // index.ts
2
- import { atom, jsx, store } from "./jsx-runtime.mjs";
3
- function defineComponent(name, Component) {
2
+ import { atom, jsx, render, store } from "./jsx-runtime.mjs";
3
+ function defineComponent(name, Component, attachShadow) {
4
4
  customElements.define(
5
5
  name,
6
6
  class extends HTMLElement {
@@ -8,7 +8,12 @@ function defineComponent(name, Component) {
8
8
  connectedCallback() {
9
9
  this.#ac ??= new AbortController();
10
10
  const props = Object.fromEntries(this.getAttributeNames().map((name2) => [name2, this.getAttribute(name2)]));
11
- this.mount(jsx(Component, props), this.#ac.signal);
11
+ if (attachShadow) {
12
+ const shadowRoot = this.attachShadow(typeof attachShadow === "boolean" ? { mode: "open" } : attachShadow);
13
+ render(null, jsx(Component, props), shadowRoot, this.#ac.signal);
14
+ } else {
15
+ this.mount(jsx(Component, props), this.#ac.signal);
16
+ }
12
17
  }
13
18
  disconnectedCallback() {
14
19
  this.#ac?.abort();
package/jsx-runtime.mjs CHANGED
@@ -786,5 +786,6 @@ export {
786
786
  jsx,
787
787
  jsx as jsxDEV,
788
788
  jsx as jsxs,
789
+ render,
789
790
  store
790
791
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mono-jsx-dom",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A JSX runtime for browsers.",
5
5
  "keywords": [
6
6
  "jsx",
package/types/index.d.ts CHANGED
@@ -13,4 +13,4 @@ export const store: <T extends Record<string, unknown>>(initValue: T) => T;
13
13
  /**
14
14
  * Defines a custom element with the given name and component.
15
15
  */
16
- export const defineComponent: <P = {}>(name: string, Component: ComponentType<P>) => void;
16
+ export const defineComponent: (name: string, Component: ComponentType<any>, attachShadow?: boolean | { mode: "open" | "closed" }) => void;