Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/mouse-solid2-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@solid-primitives/mouse": major
---

Migrate to Solid.js v2.0 (beta.13)

## Breaking Changes

**Peer dependencies**: `solid-js@^2.0.0-beta.13` and `@solidjs/web@^2.0.0-beta.13` are now required.

### `@solid-primitives/mouse`

- `isServer` now imported from `@solidjs/web` (not `solid-js/web`)
- `onMount` replaced by `onSettled` for post-render initialization
- `sharedConfig.context` replaced by `sharedConfig.hydrating` for hydration detection
- `createEffect` migrated to split compute/apply form — reactive target re-attachment now uses explicit cleanup return from the apply phase
- Added `test/server.test.ts` with SSR safety coverage for `createMousePosition` and `createPositionToElement`
8 changes: 5 additions & 3 deletions packages/mouse/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solid-primitives/mouse",
"version": "2.1.6",
"version": "3.0.0",
"description": "A collection of Solid Primitives, that capture current mouse cursor position, and help to deal with common related usecases.",
"author": "Damian Tarnawski <gthetarnav@gmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -51,7 +51,8 @@
],
"devDependencies": {
"@solid-primitives/raf": "workspace:^",
"solid-js": "^1.9.7"
"@solidjs/web": "2.0.0-beta.13",
"solid-js": "2.0.0-beta.13"
},
"dependencies": {
"@solid-primitives/event-listener": "workspace:^",
Expand All @@ -60,7 +61,8 @@
"@solid-primitives/utils": "workspace:^"
},
"peerDependencies": {
"solid-js": "^1.6.12"
"@solidjs/web": "^2.0.0-beta.13",
"solid-js": "^2.0.0-beta.13"
},
"typesVersions": {}
}
2 changes: 1 addition & 1 deletion packages/mouse/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
PositionRelativeToElement,
UseTouchOptions,
} from "./types.js";
import { isServer } from "solid-js/web";
import { isServer } from "@solidjs/web";

const PASSIVE = { passive: true };

Expand Down
17 changes: 9 additions & 8 deletions packages/mouse/src/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createHydratableSingletonRoot } from "@solid-primitives/rootless";
import { createDerivedStaticStore, createStaticStore } from "@solid-primitives/static-store";
import { asAccessor, type MaybeAccessor, type Position } from "@solid-primitives/utils";
import { type Accessor, createEffect, createSignal, onMount, sharedConfig } from "solid-js";
import { isServer } from "solid-js/web";
import { type Accessor, createEffect, createSignal, onSettled, sharedConfig } from "solid-js";
import { isServer } from "@solidjs/web";
import {
DEFAULT_MOUSE_POSITION,
DEFAULT_RELATIVE_ELEMENT_POSITION,
Expand Down Expand Up @@ -64,13 +64,14 @@ export function createMousePosition(

const [state, setState] = createStaticStore(fallback);

const attachListeners = (el: SVGSVGElement | HTMLElement | Window | Document | undefined) => {
makeMousePositionListener(el, setState, options);
makeMouseInsideListener(el, setState.bind(void 0, "isInside"), options);
const attachListeners = (el: SVGSVGElement | HTMLElement | Window | Document | undefined): VoidFunction => {
const clear1 = makeMousePositionListener(el, setState, options);
const clear2 = makeMouseInsideListener(el, setState.bind(void 0, "isInside"), options);
return () => { clear1(); clear2(); };
};

if (typeof target !== "function") attachListeners(target);
else createEffect(() => attachListeners(target()));
else createEffect(() => target(), el => attachListeners(el));

return state;
}
Expand Down Expand Up @@ -127,11 +128,11 @@ export function createPositionToElement(
}

const isFn = typeof element === "function",
isHydrating = sharedConfig.context,
isHydrating = sharedConfig.hydrating,
getEl = asAccessor(element),
[shouldFallback, setShouldFallback] = createSignal(!!isHydrating, { equals: false });

if (isHydrating || isFn) onMount(() => setShouldFallback(false));
if (isHydrating || isFn) onSettled(() => { setShouldFallback(false); });

return createDerivedStaticStore(() => {
let el!: Element | undefined;
Expand Down
4 changes: 3 additions & 1 deletion packages/mouse/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStaticStore } from "@solid-primitives/static-store";
import { createRoot } from "solid-js";
import { createRoot, flush } from "solid-js";
import { describe, expect, it } from "vitest";

import { createMousePosition, createPositionToElement } from "../src/index.js";
Expand Down Expand Up @@ -50,6 +50,7 @@ describe("createMouseToElement", () => {
});

setPos({ x: -20, y: 30 });
flush();

expect(relative).toEqual({
x: -20,
Expand All @@ -62,6 +63,7 @@ describe("createMouseToElement", () => {
});

setPos({ x: 15 });
flush();

expect(relative).toEqual({
x: 15,
Expand Down
33 changes: 33 additions & 0 deletions packages/mouse/test/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import { createMousePosition, createPositionToElement } from "../src/index.js";

describe("createMousePosition", () => {
it("returns fallback on the server", () => {
const pos = createMousePosition();
expect(pos).toEqual({ x: 0, y: 0, sourceType: null, isInside: false });
});

it("respects initialValue on the server", () => {
const pos = createMousePosition(undefined, { initialValue: { x: 10, y: 20 } });
expect(pos).toEqual({ x: 10, y: 20, sourceType: null, isInside: false });
});
});

describe("createPositionToElement", () => {
it("returns fallback on the server", () => {
const pos = createPositionToElement(
() => undefined,
() => ({ x: 0, y: 0 }),
);
expect(pos).toEqual({ x: 0, y: 0, top: 0, left: 0, width: 0, height: 0, isInside: true });
});

it("respects initialValue on the server", () => {
const pos = createPositionToElement(
() => undefined,
() => ({ x: 0, y: 0 }),
{ initialValue: { x: 5, y: 10, top: 1, left: 2, width: 100, height: 200 } },
);
expect(pos).toEqual({ x: 5, y: 10, top: 1, left: 2, width: 100, height: 200, isInside: true });
});
});
7 changes: 5 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.