@praxisjs/composables 1.1.8 → 1.2.1
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/CHANGELOG.md +14 -0
- package/dist/__tests__/browser.test.js +17 -0
- package/dist/__tests__/browser.test.js.map +1 -1
- package/dist/__tests__/dom.test.js +47 -0
- package/dist/__tests__/dom.test.js.map +1 -1
- package/dist/__tests__/upload.test.d.ts +2 -0
- package/dist/__tests__/upload.test.d.ts.map +1 -0
- package/dist/__tests__/upload.test.js +531 -0
- package/dist/__tests__/upload.test.js.map +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +5 -3
- package/dist/browser.js.map +1 -1
- package/dist/dom.d.ts.map +1 -1
- package/dist/dom.js +13 -7
- package/dist/dom.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/upload.d.ts +148 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +356 -0
- package/dist/upload.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/browser.test.ts +19 -0
- package/src/__tests__/dom.test.ts +52 -0
- package/src/__tests__/upload.test.ts +639 -0
- package/src/browser.ts +5 -3
- package/src/dom.ts +15 -9
- package/src/index.ts +15 -0
- package/src/upload.ts +450 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@praxisjs/composables",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"typescript": "^6.0.3"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@praxisjs/core": "2.
|
|
17
|
+
"@praxisjs/core": "2.2.0",
|
|
18
18
|
"@praxisjs/shared": "0.3.1"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
3
3
|
|
|
4
|
+
import { effect } from "@praxisjs/core/internal";
|
|
5
|
+
|
|
4
6
|
import { MediaQuery, ColorScheme, Mouse, KeyCombo, Idle } from "../browser";
|
|
5
7
|
|
|
6
8
|
function mockMatchMedia(matches: boolean, onAdd?: (_: string, fn: (e: MediaQueryListEvent) => void) => void) {
|
|
@@ -393,3 +395,20 @@ describe("Idle (additional)", () => {
|
|
|
393
395
|
vi.useRealTimers();
|
|
394
396
|
});
|
|
395
397
|
});
|
|
398
|
+
|
|
399
|
+
describe("Mouse paired updates", () => {
|
|
400
|
+
it("re-runs dependents once per mousemove", () => {
|
|
401
|
+
const mouse = new Mouse();
|
|
402
|
+
const { x, y } = mouse.setup() as { x: () => number; y: () => number };
|
|
403
|
+
let runs = 0;
|
|
404
|
+
effect(() => {
|
|
405
|
+
void x();
|
|
406
|
+
void y();
|
|
407
|
+
runs++;
|
|
408
|
+
});
|
|
409
|
+
runs = 0;
|
|
410
|
+
window.dispatchEvent(new MouseEvent("mousemove", { clientX: 5, clientY: 6 }));
|
|
411
|
+
expect(runs).toBe(1);
|
|
412
|
+
mouse.onUnmount();
|
|
413
|
+
});
|
|
414
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
3
3
|
|
|
4
|
+
import { effect } from "@praxisjs/core/internal";
|
|
5
|
+
|
|
4
6
|
import { WindowSize, ScrollPosition, ElementSize, Intersection, Focus } from "../dom";
|
|
5
7
|
|
|
6
8
|
// ── WindowSize ────────────────────────────────────────────────────────────────
|
|
@@ -513,3 +515,53 @@ describe("ScrollPosition (_staticTarget fallback)", () => {
|
|
|
513
515
|
sp.onUnmount();
|
|
514
516
|
});
|
|
515
517
|
});
|
|
518
|
+
|
|
519
|
+
describe("paired updates re-run dependents once per event", () => {
|
|
520
|
+
function countRuns(read: () => void) {
|
|
521
|
+
let runs = 0;
|
|
522
|
+
effect(() => {
|
|
523
|
+
read();
|
|
524
|
+
runs++;
|
|
525
|
+
});
|
|
526
|
+
runs = 0;
|
|
527
|
+
return () => runs;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
it("WindowSize", () => {
|
|
531
|
+
const ws = new WindowSize();
|
|
532
|
+
const { width, height } = ws.setup() as { width: () => number; height: () => number };
|
|
533
|
+
const runs = countRuns(() => { void width(); void height(); });
|
|
534
|
+
Object.defineProperty(window, "innerWidth", { value: 111, configurable: true });
|
|
535
|
+
Object.defineProperty(window, "innerHeight", { value: 222, configurable: true });
|
|
536
|
+
window.dispatchEvent(new Event("resize"));
|
|
537
|
+
expect(runs()).toBe(1);
|
|
538
|
+
ws.onUnmount();
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("ScrollPosition", () => {
|
|
542
|
+
const sp = new ScrollPosition(window);
|
|
543
|
+
const { x, y } = sp.setup() as { x: () => number; y: () => number };
|
|
544
|
+
sp.onMount();
|
|
545
|
+
const runs = countRuns(() => { void x(); void y(); });
|
|
546
|
+
Object.defineProperty(window, "scrollX", { value: 7, configurable: true });
|
|
547
|
+
Object.defineProperty(window, "scrollY", { value: 9, configurable: true });
|
|
548
|
+
window.dispatchEvent(new Event("scroll"));
|
|
549
|
+
expect(runs()).toBe(1);
|
|
550
|
+
sp.onUnmount();
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
it("ElementSize", () => {
|
|
554
|
+
let callback!: ResizeObserverCallback;
|
|
555
|
+
vi.stubGlobal("ResizeObserver", class {
|
|
556
|
+
constructor(cb: ResizeObserverCallback) { callback = cb; }
|
|
557
|
+
observe = vi.fn();
|
|
558
|
+
disconnect = vi.fn();
|
|
559
|
+
});
|
|
560
|
+
const es = new ElementSize({ current: document.createElement("div") });
|
|
561
|
+
const { width, height } = es.setup() as { width: () => number; height: () => number };
|
|
562
|
+
const runs = countRuns(() => { void width(); void height(); });
|
|
563
|
+
callback([{ contentRect: { width: 10, height: 20 } } as ResizeObserverEntry], {} as ResizeObserver);
|
|
564
|
+
expect(runs()).toBe(1);
|
|
565
|
+
vi.unstubAllGlobals();
|
|
566
|
+
});
|
|
567
|
+
});
|