Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1,210 changes: 1 addition & 1,209 deletions build/main.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions templates/button.css → components/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ button {
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
body{
background-color: #b02fc7;
}
21 changes: 14 additions & 7 deletions components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/** @jsxImportSource preact */
import type { JSX } from "preact";
import type { ComponentChildren } from "preact";
import { count } from "#signals/counter";

function Button(
{ onClick, children = "Click Me !" }: {
onClick?: JSX.MouseEventHandler<HTMLButtonElement> | undefined;
children?: JSX.Element | string;
{ children = "Increment" }: {
children?: ComponentChildren;
},
) {
const handleClick = () => {
count.value++;
};

return (
<button type="button" onClick={onClick}>
<slot>{children}</slot>
</button>
<>
<link rel="stylesheet" href="/components/button.css" />
<button type="button" onClick={handleClick}>
{children}
</button>
</>
);
}

Expand Down
20 changes: 0 additions & 20 deletions components/button2.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion components/counter.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
element-counter2 {
div {
display: block;
font-family: system-ui, sans-serif;
border: 2px solid #ccc;
Expand All @@ -7,4 +7,5 @@ element-counter2 {
margin: 16px 0;
text-align: center;
background-color: #f9f9f9;
font-size: xx-large;
}
10 changes: 7 additions & 3 deletions components/counter.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/** @jsxImportSource preact */
import { count } from "#signals/counter";

function Counter() {
return (
<div>
{count}
</div>
<>
<link rel="stylesheet" href="/components/counter.css" />
<div>
{count}
</div>
</>
);
}

Expand Down
11 changes: 0 additions & 11 deletions components/counter2.tsx

This file was deleted.

52 changes: 52 additions & 0 deletions components/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/** @jsxImportSource preact */

import { Button } from "#components/button";
import { Counter } from "#components/counter";

function Document() {
return (
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>Elements</title>
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" />
<script type="module" src="/dom/main.js"></script>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/standard-web-components">Standard Web Components</a></li>
</ul>
</nav>
</header>
<main>
<h1>Preact Web Components Study</h1>

<form onSubmit={(event) => event.preventDefault()}>
<fieldset>
<legend>Counter Form</legend>
<p>
Current count: <element-counter hydrate>
<template shadowrootmode="open"><Counter>0</Counter></template>
</element-counter>
</p>
<element-button hydrate><template shadowrootmode="open"><Button>Increment</Button></template>Add</element-button>
</fieldset>
</form>
</main>
</body>
</html>
)
}

export { Document }
16 changes: 0 additions & 16 deletions components/dsd-button.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions components/dsd-counter.tsx

This file was deleted.

96 changes: 0 additions & 96 deletions components/home.tsx

This file was deleted.

20 changes: 7 additions & 13 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dev": "deno serve --allow-read --watch main.tsx",
"serve": "deno serve --allow-read main.tsx",
"build": "deno run -A functions/dnt.ts",
"bundle": "deno run -A --unstable-bundle functions/deno-bundle.ts",
"ssg": "deno run --allow-read --allow-write --allow-env --allow-net functions/ssg.ts"
},
"exports": {
Expand All @@ -13,22 +14,15 @@
"imports": {
"@deno/dnt": "jsr:@deno/dnt",
"@preact/signals": "npm:@preact/signals",
"#button": "./components/button.tsx",
"#components/button2": "./components/button2.tsx",
"#components/counter2": "./components/counter2.tsx",
"@std/fs": "jsr:@std/fs@^1.0.19",
"#components/button.css": "./components/button.css",
"#components/button": "./components/button.tsx",
"#components/counter.css": "./components/counter.css",
"#components/dsd-button": "./components/dsd-button.tsx",
"#components/dsd-counter": "./components/dsd-counter.tsx",
"#counter": "./components/counter.tsx",
"#elements/button-preact": "./elements/button-preact.tsx",
"#elements/button": "./elements/button.ts",
"#elements/counter-preact": "./elements/counter-preact.tsx",
"#elements/counter": "./elements/counter.ts",
"#home": "./components/home.tsx",
"#components/counter": "./components/counter.tsx",
"#document": "./components/document.tsx",
"#wrangler-config": "./functions/wrangler.ts",
"#signals/counter": "./signals/counter.ts",
"#template-button": "./templates/template-button.tsx",
"#template-counter": "./templates/template-counter.tsx",
"@std/http": "jsr:@std/http@^1.0.20",
"eszip": "https://deno.land/x/[email protected]/mod.ts",
"preact-render-to-string": "npm:preact-render-to-string",
"preact-custom-element": "npm:preact-custom-element",
Expand Down
19 changes: 5 additions & 14 deletions dom/main.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import register from 'preact-custom-element';
import { CounterPreact } from "#elements/counter-preact";
import { ButtonPreact } from "#elements/button-preact";
import { Button2 } from "#components/button2";
import { Counter2 } from "#components/counter2";
import { Counter } from "#elements/counter";
import { Button } from "#elements/button";

import { Button } from "#components/button";
import { Counter } from "#components/counter";

function main() {
customElements.define("dsd-counter-preact", CounterPreact);
customElements.define("dsd-button-preact", ButtonPreact);
register(Counter2, 'element-counter2', [], { shadow: true, mode: 'open', adoptedStyleSheets: [counterStyle] });
register(Button2, 'element-button2', [], { shadow: true, mode: 'open', adoptedStyleSheets: [] });
customElements.define("element-counter", Counter);
customElements.define("element-button", Button);
register(Counter, 'element-counter', [], { shadow: true, mode: 'open' });
register(Button, 'element-button', [], { shadow: true, mode: 'open' });
}

document.addEventListener("DOMContentLoaded", main)
document.addEventListener("DOMContentLoaded", main);
Loading