elements-kit 0.0.14 → 0.0.15
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.
|
@@ -216,13 +216,8 @@ function setEvent(el, key, handler) {
|
|
|
216
216
|
return () => el.removeEventListener(event, handler);
|
|
217
217
|
}
|
|
218
218
|
//#endregion
|
|
219
|
-
//#region src/jsx-runtime/ref.ts
|
|
220
|
-
const $ref = Symbol("ref");
|
|
221
|
-
//#endregion
|
|
222
219
|
//#region src/jsx-runtime/element.ts
|
|
223
|
-
function createElement(type,
|
|
224
|
-
const ref = rawProps[$ref];
|
|
225
|
-
const props = Object.fromEntries(Object.entries(rawProps));
|
|
220
|
+
function createElement(type, { ref, ...props } = {}) {
|
|
226
221
|
if (typeof type === "function" && !type.prototype?.render) return createFunctionElement(type, props, ref);
|
|
227
222
|
return createNodeElement(type, props, ref);
|
|
228
223
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as disposeElement } from "./element-
|
|
1
|
+
import { n as disposeElement } from "./element-ChF24-2z.mjs";
|
|
2
2
|
import { _ as signal, g as onCleanup, u as effect, v as trigger, y as untracked } from "./signals-BHmWX6ox.mjs";
|
|
3
3
|
//#region src/jsx-runtime/for.ts
|
|
4
4
|
/**
|
|
@@ -15,10 +15,12 @@ type Child = PrimitiveNodeType | AnyFn | Child[];
|
|
|
15
15
|
type AnyFn = (...args: any[]) => any;
|
|
16
16
|
//#endregion
|
|
17
17
|
//#region src/jsx-runtime/element.d.ts
|
|
18
|
-
declare function createElement(type: string | Element | DocumentFragment | ComponentClass | ComponentFn,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
declare function createElement(type: string | Element | DocumentFragment | ComponentClass | ComponentFn, {
|
|
19
|
+
ref,
|
|
20
|
+
...props
|
|
21
|
+
}?: Record<string | symbol, unknown> & {
|
|
22
|
+
ref?: (el: Element) => void;
|
|
23
|
+
}): Element | DocumentFragment | null;
|
|
22
24
|
//#endregion
|
|
23
25
|
//#region src/jsx-runtime/fragment.d.ts
|
|
24
26
|
/**
|
|
@@ -59,7 +61,7 @@ type SlotProps<K extends string> = { [P in K as `slot:${P}`]?: Child };
|
|
|
59
61
|
type Attrs<K extends keyof JSX.IntrinsicElements> = JSX.IntrinsicElements[K];
|
|
60
62
|
/** Extra props injected into every intrinsic element beyond dom-expressions defaults. */
|
|
61
63
|
type OurProps = {
|
|
62
|
-
|
|
64
|
+
ref?: (el: Element) => void;
|
|
63
65
|
[slot: `slot:${string}`]: Child;
|
|
64
66
|
[cls: `class:${string}`]: FunctionMaybe<boolean>;
|
|
65
67
|
[sty: `style:${string}`]: FunctionMaybe<string | null>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { d as effectScope } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
|
+
import { async } from "./async.mjs";
|
|
3
4
|
import { createInterval } from "./interval.mjs";
|
|
4
5
|
//#region src/utilities/interval.test.ts
|
|
5
6
|
afterEach(() => {
|
|
@@ -92,6 +93,21 @@ describe("createInterval", () => {
|
|
|
92
93
|
vi.advanceTimersByTime(500);
|
|
93
94
|
globalExpect(cb).toHaveBeenCalledTimes(0);
|
|
94
95
|
});
|
|
96
|
+
it("composes with async() — reruns on each tick", async () => {
|
|
97
|
+
vi.useFakeTimers();
|
|
98
|
+
const asyncOp = async;
|
|
99
|
+
let runCount = 0;
|
|
100
|
+
const timer = createInterval(100);
|
|
101
|
+
const op = asyncOp(() => {
|
|
102
|
+
timer.timestamp();
|
|
103
|
+
runCount++;
|
|
104
|
+
return Promise.resolve(runCount);
|
|
105
|
+
}).start();
|
|
106
|
+
await vi.advanceTimersByTimeAsync(350);
|
|
107
|
+
globalExpect(runCount).toBeGreaterThan(1);
|
|
108
|
+
timer[Symbol.dispose]();
|
|
109
|
+
op.stop();
|
|
110
|
+
});
|
|
95
111
|
});
|
|
96
112
|
//#endregion
|
|
97
113
|
export {};
|
|
@@ -59,6 +59,61 @@ describe("createTimeout", () => {
|
|
|
59
59
|
vi.advanceTimersByTime(300);
|
|
60
60
|
globalExpect(cb).toHaveBeenCalledOnce();
|
|
61
61
|
});
|
|
62
|
+
it("immediate=false does not start automatically", () => {
|
|
63
|
+
vi.useFakeTimers();
|
|
64
|
+
const cb = vi.fn();
|
|
65
|
+
let t;
|
|
66
|
+
effectScope(() => {
|
|
67
|
+
t = createTimeout(cb, 200, false);
|
|
68
|
+
});
|
|
69
|
+
globalExpect(t.pending()).toBe(false);
|
|
70
|
+
vi.advanceTimersByTime(300);
|
|
71
|
+
globalExpect(cb).not.toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
it("start() fires after delay when called manually", () => {
|
|
74
|
+
vi.useFakeTimers();
|
|
75
|
+
const cb = vi.fn();
|
|
76
|
+
let t;
|
|
77
|
+
effectScope(() => {
|
|
78
|
+
t = createTimeout(cb, 200, false);
|
|
79
|
+
});
|
|
80
|
+
t.start();
|
|
81
|
+
globalExpect(t.pending()).toBe(true);
|
|
82
|
+
vi.advanceTimersByTime(200);
|
|
83
|
+
globalExpect(cb).toHaveBeenCalledOnce();
|
|
84
|
+
globalExpect(t.pending()).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
it("Symbol.dispose cancels the timeout", () => {
|
|
87
|
+
vi.useFakeTimers();
|
|
88
|
+
const cb = vi.fn();
|
|
89
|
+
let t;
|
|
90
|
+
effectScope(() => {
|
|
91
|
+
t = createTimeout(cb, 500);
|
|
92
|
+
});
|
|
93
|
+
t[Symbol.dispose]();
|
|
94
|
+
vi.advanceTimersByTime(1e3);
|
|
95
|
+
globalExpect(cb).not.toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
it("stops when scope is disposed", () => {
|
|
98
|
+
vi.useFakeTimers();
|
|
99
|
+
const cb = vi.fn();
|
|
100
|
+
effectScope(() => {
|
|
101
|
+
createTimeout(cb, 200);
|
|
102
|
+
})();
|
|
103
|
+
vi.advanceTimersByTime(500);
|
|
104
|
+
globalExpect(cb).not.toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
it("dynamic delay function is called at start", () => {
|
|
107
|
+
vi.useFakeTimers();
|
|
108
|
+
const cb = vi.fn();
|
|
109
|
+
const getDelay = vi.fn().mockReturnValue(300);
|
|
110
|
+
effectScope(() => {
|
|
111
|
+
createTimeout(cb, getDelay);
|
|
112
|
+
});
|
|
113
|
+
vi.advanceTimersByTime(300);
|
|
114
|
+
globalExpect(cb).toHaveBeenCalledOnce();
|
|
115
|
+
globalExpect(getDelay).toHaveBeenCalledOnce();
|
|
116
|
+
});
|
|
62
117
|
});
|
|
63
118
|
//#endregion
|
|
64
119
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elements-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.15",
|
|
5
5
|
"description": "A lightweight reactive UI library that transforms native HTMLElements into reactive components with signals. Ideal for framework-agnostic applications and web components.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webcomponents",
|