chore: restructure repository into packages/ folder (#3197)

We're having a growing number of packages in this repository. This PR
moves them into a `packages/` directory like it's commonly done in other
projects.
This commit is contained in:
Marvin Hagemeister
2025-08-06 15:52:45 +02:00
committed by GitHub
parent 27e407a1e3
commit 815b1940e3
184 changed files with 94 additions and 82 deletions
@@ -0,0 +1,34 @@
import { useComputed, useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
export function ComputedSignal(props: { id?: string }) {
const status = useSignal("it doesn't work");
const c = useComputed(() => 1);
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div id={props.id} class={active.value ? "ready" : ""}>
<button
type="button"
class="trigger"
onClick={() => {
try {
// This should throw
// deno-lint-ignore no-explicit-any
(c as any).value = 10;
status.value = "it doesn't work";
} catch {
status.value = "it works";
}
}}
>
trigger
</button>
<p class="output">{status}</p>
</div>
);
}
@@ -0,0 +1,34 @@
import { type Signal, useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
export interface CounterProps {
id?: string;
count: Signal<number>;
}
export function Counter(props: CounterProps) {
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div id={props.id} class={active.value ? "ready" : ""}>
<button
type="button"
class="decrement"
onClick={() => props.count.value -= 1}
>
-1
</button>
<p class="output">{props.count}</p>
<button
type="button"
class="increment"
onClick={() => props.count.value += 1}
>
+1
</button>
</div>
);
}
@@ -0,0 +1,31 @@
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
import type { ComponentChildren } from "preact";
export function CounterWithSlots(
props: { children?: ComponentChildren; jsx?: ComponentChildren },
) {
const sig = useSignal(0);
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<div class="counter-with-children">
<p class="output">{sig}</p>
<button type="button" onClick={() => sig.value = sig.peek() + 1}>
update
</button>
</div>
<div class="children">
{props.children}
</div>
<div class="jsx">
{props.jsx}
</div>
</div>
);
}
@@ -0,0 +1,17 @@
import { useEffect } from "preact/hooks";
import { useSignal } from "@preact/signals";
export function EscapeIsland(props: { str: string }) {
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<p>it works</p>
<div>{props.str}</div>
</div>
);
}
@@ -0,0 +1,25 @@
import type { VNode } from "preact";
import { FragmentIsland } from "./FragmentIsland.tsx";
import { useEffect } from "preact/hooks";
import { useSignal } from "@preact/signals";
function Foo(props: { children: () => VNode }) {
return props.children();
}
export function FnIsland() {
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<Foo>
{() => <FragmentIsland />}
</Foo>
</div>
);
}
@@ -0,0 +1,9 @@
// deno-lint-ignore-file jsx-curly-braces
export function FragmentIsland() {
return (
<>
<p>it{" "}</p>
<p>works</p>
</>
);
}
@@ -0,0 +1,23 @@
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
export interface FreshAttrs {
id?: string;
}
export function FreshAttrs(props: FreshAttrs) {
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div id={props.id} class={active.value ? "ready" : ""}>
<h1>Fresh attrs</h1>
<div class="f-client-nav-true" f-client-nav>f-client-nav=true</div>
<div class="f-client-nav-false" f-client-nav={false}>
f-client-nav=false
</div>
</div>
);
}
@@ -0,0 +1,19 @@
import { useSignal } from "@preact/signals";
import { Counter } from "./Counter.tsx";
export function IslandInIsland() {
const sig = useSignal(0);
return (
<div>
<button
type="button"
class="trigger"
onClick={() => sig.value = sig.peek() + 1}
>
trigger
</button>
<Counter count={sig} />
</div>
);
}
@@ -0,0 +1,5 @@
import data from "./data.json" with { type: "json" };
export function JsonIsland() {
return <pre>{JSON.stringify(data)}</pre>;
}
@@ -0,0 +1,22 @@
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
import type { ComponentChildren } from "preact";
export interface JsxIslandProps {
children?: ComponentChildren;
}
export function JsxChildrenIsland(props: JsxIslandProps) {
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<div class="children">{props.children}</div>
{active.value ? <div class="after">{props.children}</div> : null}
</div>
);
}
@@ -0,0 +1,32 @@
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
import type { ComponentChildren } from "preact";
export interface JsxConditionalProps {
jsx?: ComponentChildren;
children?: ComponentChildren;
}
export function JsxConditional(props: JsxConditionalProps) {
const active = useSignal(false);
const sig = useSignal(0);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<p class="cond-output">{sig}</p>
<button
type="button"
class="cond-update"
onClick={() => sig.value = sig.peek() + 1}
>
update
</button>
<div class="jsx">{active.value ? props.jsx : null}</div>
<div class="children">{active.value ? props.children : null}</div>
</div>
);
}
@@ -0,0 +1,32 @@
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
import { type ComponentChildren, isValidElement } from "preact";
export interface JsxIslandProps {
jsx?: ComponentChildren;
children?: ComponentChildren;
}
export function JsxIsland(props: JsxIslandProps) {
const active = useSignal(false);
const sig = useSignal(0);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<p class="output">{sig}</p>
<button
type="button"
class="update"
onClick={() => sig.value = sig.peek() + 1}
>
update
</button>
<div class="jsx">{props.jsx}</div>
<div class="children">{props.children}</div>
<pre>{JSON.stringify({jsx: isValidElement(props.jsx), children: isValidElement(props.children)})}</pre>
</div>
);
}
@@ -0,0 +1,17 @@
import type { ComponentChildren } from "preact";
import { Counter } from "./Counter.tsx";
import { useSignal } from "@preact/signals";
export interface MultipleProps {
id?: string;
children?: ComponentChildren;
}
export function Multiple1(props: MultipleProps) {
const sig = useSignal(0);
return <Counter id={props.id} count={sig} />;
}
export function Multiple2(props: MultipleProps) {
const sig = useSignal(0);
return <Counter id={props.id} count={sig} />;
}
@@ -0,0 +1,21 @@
import { useEffect } from "preact/hooks";
import { useSignal } from "@preact/signals";
import { IS_BROWSER } from "fresh/runtime";
export function NodeProcess() {
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
// @ts-ignore bundling
// deno-lint-ignore no-process-global
const value = IS_BROWSER ? process.env.NODE_ENV : "no";
return (
<div class={active.value ? "ready" : ""}>
value: {value}
</div>
);
}
@@ -0,0 +1,10 @@
import { useEffect } from "preact/hooks";
export function NullIsland() {
useEffect(() => {
const div = document.createElement("div");
div.className = "ready";
document.body.appendChild(div);
}, []);
return null;
}
@@ -0,0 +1,7 @@
export function OptOutPartialLink(props: { href: string; partial: string }) {
return (
<div f-client-nav={false}>
<a class="update" href={props.href} f-partial={props.partial}>link</a>
</div>
);
}
@@ -0,0 +1,9 @@
import { Partial } from "fresh/runtime";
export function PartialInIsland() {
return (
<Partial name="invalid">
<p class="invalid">invalid</p>
</Partial>
);
}
@@ -0,0 +1,9 @@
import type { ComponentChildren } from "preact";
export function PassThrough(props: { children?: ComponentChildren }) {
return (
<div class="passthrough">
{props.children}
</div>
);
}
@@ -0,0 +1,27 @@
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
export interface SelfCounterProps {
id?: string;
}
export function SelfCounter(props: SelfCounterProps) {
const count = useSignal(0);
const active = useSignal(false);
useEffect(() => {
active.value = true;
}, []);
return (
<div id={props.id} class={active.value ? "ready self-counter" : ""}>
<button type="button" class="decrement" onClick={() => count.value -= 1}>
-1
</button>
<p class="output">{count}</p>
<button type="button" class="increment" onClick={() => count.value += 1}>
+1
</button>
</div>
);
}
@@ -0,0 +1,3 @@
{
"foo": 123
}