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 +8 -3
- package/jsx-runtime.mjs +1 -0
- package/package.json +1 -1
- package/types/index.d.ts +1 -1
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
|
-
|
|
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
package/package.json
CHANGED
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:
|
|
16
|
+
export const defineComponent: (name: string, Component: ComponentType<any>, attachShadow?: boolean | { mode: "open" | "closed" }) => void;
|