@openelement/create 0.43.3 → 0.44.0-beta.2
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/README.md +2 -2
- package/package.json +1 -1
- package/src/cli.js +40 -28
- package/src/template-builder.js +61 -12
- package/src/version.js +2 -2
- package/templates/README.tmpl +19 -11
- package/templates/app/components/page-404.tsx +22 -0
- package/templates/app/components/page-blog-index.tsx +35 -0
- package/templates/app/components/page-blog-welcome.tsx +54 -0
- package/templates/app/components/page-contact.tsx +46 -0
- package/templates/app/components/page-freshness.tsx +22 -0
- package/templates/app/components/page-home.tsx +55 -0
- package/templates/app/components/page-styles.ts +64 -0
- package/templates/app/islands/app-shell.tsx +58 -0
- package/templates/app/islands/my-counter.tsx +25 -26
- package/templates/app/islands/only-ticker.tsx +21 -27
- package/templates/app/routes/404.tsx +4 -38
- package/templates/app/routes/blog/index.tsx +5 -71
- package/templates/app/routes/blog/welcome.tsx +7 -0
- package/templates/app/routes/contact.tsx +17 -79
- package/templates/app/routes/freshness.tsx +9 -39
- package/templates/app/routes/index.tsx +4 -99
- package/templates/deno.json.tmpl +1 -1
- package/templates/vite.config.ts +69 -18
- package/templates/app/components/app-shell.tsx +0 -61
- package/templates/app/routes/blog/[slug].tsx +0 -79
- package/templates/content/blog/welcome.md +0 -14
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style sheets for the starter's compiled islands (v0.44).
|
|
3
|
+
*
|
|
4
|
+
* Compiled modules may not carry runtime top-level statements, so the sheets
|
|
5
|
+
* live in this plain module and the compiled classes reference them through
|
|
6
|
+
* `static styles` (adoptedStyleSheets on shadow roots — see the zag-combobox
|
|
7
|
+
* fixture pattern in packages/adapter-vite). Page elements use light roots;
|
|
8
|
+
* their rules live in the global baseline in vite.config.ts (scoped under
|
|
9
|
+
* each page's host tag) because the compiled serializer never inlines styles
|
|
10
|
+
* into SSR output and page classes are not registered client-side.
|
|
11
|
+
*/
|
|
12
|
+
import { StyleSheet, type StyleSheetLike } from '@openelement/element';
|
|
13
|
+
|
|
14
|
+
function sheet(css: string): StyleSheetLike {
|
|
15
|
+
const instance = new StyleSheet();
|
|
16
|
+
instance.replaceSync(css);
|
|
17
|
+
return instance;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const shellStyles = [
|
|
21
|
+
sheet(`
|
|
22
|
+
:host { display: block; min-height: 100vh; }
|
|
23
|
+
header { border-bottom: 1px solid var(--line); }
|
|
24
|
+
.bar { max-width: 740px; margin: 0 auto; padding: 1.15rem 1.25rem; display: flex; justify-content: space-between; align-items: baseline; }
|
|
25
|
+
.brand { font-family: var(--font-serif); font-weight: 700; font-size: 1.2rem; letter-spacing: -0.01em; color: var(--ink); }
|
|
26
|
+
.brand:hover { text-decoration: none; color: var(--brand); }
|
|
27
|
+
nav { display: flex; gap: 1.5rem; }
|
|
28
|
+
nav a { color: var(--ink-2); font-size: 0.95rem; font-weight: 500; }
|
|
29
|
+
nav a:hover { color: var(--brand); text-decoration: none; }
|
|
30
|
+
main { max-width: 740px; margin: 0 auto; padding: 3rem 1.25rem 4rem; }
|
|
31
|
+
footer { border-top: 1px solid var(--line); color: var(--ink-2); font-size: 0.85rem; }
|
|
32
|
+
.foot { max-width: 740px; margin: 0 auto; padding: 1.25rem; display: flex; justify-content: space-between; gap: 1rem; }
|
|
33
|
+
a { color: var(--brand); text-decoration: none; }
|
|
34
|
+
a:hover { text-decoration: underline; }
|
|
35
|
+
`),
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export const counterStyles = [
|
|
39
|
+
sheet(`
|
|
40
|
+
:host { display: inline-block; }
|
|
41
|
+
.counter-row { display: inline-flex; gap: 0.75rem; align-items: center; }
|
|
42
|
+
button {
|
|
43
|
+
width: 2rem; height: 2rem; border: 1px solid var(--line); border-radius: 6px;
|
|
44
|
+
background: #fff; color: var(--ink); font-size: 1rem; line-height: 1; cursor: pointer;
|
|
45
|
+
transition: border-color 0.15s ease, color 0.15s ease;
|
|
46
|
+
}
|
|
47
|
+
button:hover { border-color: var(--brand); color: var(--brand); }
|
|
48
|
+
span { min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
|
|
49
|
+
`),
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
export const tickerStyles = [
|
|
53
|
+
sheet(`
|
|
54
|
+
:host { display: inline-block; }
|
|
55
|
+
.ticker-row { display: inline-flex; gap: 0.75rem; align-items: center; }
|
|
56
|
+
button {
|
|
57
|
+
height: 2rem; padding: 0 0.9rem; border: 1px solid var(--line); border-radius: 6px;
|
|
58
|
+
background: #fff; color: var(--ink); font-size: 0.9rem; cursor: pointer;
|
|
59
|
+
transition: border-color 0.15s ease, color 0.15s ease;
|
|
60
|
+
}
|
|
61
|
+
button:hover { border-color: var(--brand); color: var(--brand); }
|
|
62
|
+
span { min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
|
|
63
|
+
`),
|
|
64
|
+
];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* app-shell — compiled layout island (v0.44, ADR-0143).
|
|
3
|
+
*
|
|
4
|
+
* The server entry renders this class around every page
|
|
5
|
+
* (appShell: { tagName, import, props } in vite.config.ts) and injects the
|
|
6
|
+
* page host before the closing tag; the static <slot> projects it. The shell
|
|
7
|
+
* is also a 'load' island: the compiled style scope applies `static styles`
|
|
8
|
+
* when the element activates client-side (the serializer never inlines
|
|
9
|
+
* styles into DSD), so the shell chrome is styled as soon as it hydrates.
|
|
10
|
+
*
|
|
11
|
+
* The compiler grammar v1 has no data-driven per-item attribute slots, so the
|
|
12
|
+
* header nav is static authoring here — edit the links below directly
|
|
13
|
+
* (the vite.config content.nav headerNav indirection of 0.43 is gone).
|
|
14
|
+
*/
|
|
15
|
+
import { defineIslandConfig } from '@openelement/app';
|
|
16
|
+
import { element, OpenElement, property } from '@openelement/element';
|
|
17
|
+
import { shellStyles } from '../components/page-styles.ts';
|
|
18
|
+
|
|
19
|
+
export const openElement = defineIslandConfig({ hydrate: 'load', ssr: true, dsd: true });
|
|
20
|
+
|
|
21
|
+
@element('app-shell', { root: 'shadow-open' })
|
|
22
|
+
export default class AppShell extends OpenElement {
|
|
23
|
+
static override styles = shellStyles;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Filled from appShell.props in vite.config.ts at render time.
|
|
27
|
+
* Attribute-backed (site-name) so the SSR'd value survives the client claim:
|
|
28
|
+
* attribute: false properties reset to their compiled default on claim and
|
|
29
|
+
* the drift check would fail closed.
|
|
30
|
+
*/
|
|
31
|
+
@property({ reflect: false })
|
|
32
|
+
siteName = 'openElement';
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
return (
|
|
36
|
+
<div class='shell-body'>
|
|
37
|
+
<header data-open-layout='app-shell'>
|
|
38
|
+
<div class='bar'>
|
|
39
|
+
<a class='brand' href='/'>{this.siteName}</a>
|
|
40
|
+
<nav>
|
|
41
|
+
<a href='/'>Home</a>
|
|
42
|
+
<a href='/blog'>Blog</a>
|
|
43
|
+
</nav>
|
|
44
|
+
</div>
|
|
45
|
+
</header>
|
|
46
|
+
<main>
|
|
47
|
+
<slot></slot>
|
|
48
|
+
</main>
|
|
49
|
+
<footer>
|
|
50
|
+
<div class='foot'>
|
|
51
|
+
<span>Generated by @openelement/create.</span>
|
|
52
|
+
<a href='https://github.com/open-element/openelement'>GitHub</a>
|
|
53
|
+
</div>
|
|
54
|
+
</footer>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* my-counter — minimal counter island (v0.44 compiled, ADR-0143).
|
|
3
|
+
*
|
|
4
|
+
* Hydrates on idle; the buttons increment/decrement through the compiled
|
|
5
|
+
* event Parts and the count renders through the compiled text Part. The
|
|
6
|
+
* shadow root keeps the island a DSD citizen.
|
|
7
|
+
*/
|
|
2
8
|
import { defineIslandConfig } from '@openelement/app';
|
|
3
|
-
import {
|
|
9
|
+
import { element, OpenElement, property } from '@openelement/element';
|
|
10
|
+
import { counterStyles } from '../components/page-styles.ts';
|
|
4
11
|
|
|
5
|
-
export const tagName = 'my-counter';
|
|
6
12
|
export const openElement = defineIslandConfig({ hydrate: 'idle', ssr: true, dsd: true });
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
sheet.replaceSync(`
|
|
10
|
-
:host { display: inline-flex; gap: 0.75rem; align-items: center; }
|
|
11
|
-
button {
|
|
12
|
-
width: 2rem; height: 2rem; border: 1px solid var(--line); border-radius: 6px;
|
|
13
|
-
background: #fff; color: var(--ink); font-size: 1rem; line-height: 1; cursor: pointer;
|
|
14
|
-
transition: border-color 0.15s ease, color 0.15s ease;
|
|
15
|
-
}
|
|
16
|
-
button:hover { border-color: var(--brand); color: var(--brand); }
|
|
17
|
-
span { min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
|
|
18
|
-
`);
|
|
19
|
-
|
|
14
|
+
@element('my-counter', { root: 'shadow-open' })
|
|
20
15
|
export default class MyCounter extends OpenElement {
|
|
21
|
-
static override styles =
|
|
16
|
+
static override styles = counterStyles;
|
|
22
17
|
|
|
23
|
-
|
|
18
|
+
@property({ reflect: false, attribute: false })
|
|
19
|
+
count = 0;
|
|
20
|
+
|
|
21
|
+
decrement(): void {
|
|
22
|
+
this.count--;
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.registerSignal('count', this.#count);
|
|
25
|
+
increment(): void {
|
|
26
|
+
this.count++;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
render() {
|
|
31
30
|
return (
|
|
32
|
-
|
|
33
|
-
<button type='button' onClick={
|
|
34
|
-
<span>{this
|
|
35
|
-
<button type='button' onClick={
|
|
36
|
-
|
|
31
|
+
<div class='counter-row'>
|
|
32
|
+
<button type='button' onClick={this.decrement}>-</button>
|
|
33
|
+
<span id='count'>{this.count}</span>
|
|
34
|
+
<button type='button' onClick={this.increment}>+</button>
|
|
35
|
+
</div>
|
|
37
36
|
);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
@@ -1,40 +1,34 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* only-ticker — client-only island (v0.44 compiled, ADR-0143).
|
|
3
|
+
*
|
|
4
|
+
* hydrate: 'only' with ssr: false renders nothing on the server; the client
|
|
5
|
+
* entry creates the DOM fresh from the compiled Part Program and binds the
|
|
6
|
+
* tick event Part. Each hydrated island gets its own compiled property state,
|
|
7
|
+
* so multiple tickers on one page never share state.
|
|
8
|
+
*/
|
|
2
9
|
import { defineIslandConfig } from '@openelement/app';
|
|
3
|
-
import {
|
|
10
|
+
import { element, OpenElement, property } from '@openelement/element';
|
|
11
|
+
import { tickerStyles } from '../components/page-styles.ts';
|
|
4
12
|
|
|
5
|
-
export const tagName = 'only-ticker';
|
|
6
13
|
export const openElement = defineIslandConfig({ hydrate: 'only', ssr: false, dsd: false });
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
sheet.replaceSync(`
|
|
10
|
-
:host { display: inline-flex; gap: 0.75rem; align-items: center; }
|
|
11
|
-
button {
|
|
12
|
-
height: 2rem; padding: 0 0.9rem; border: 1px solid var(--line); border-radius: 6px;
|
|
13
|
-
background: #fff; color: var(--ink); font-size: 0.9rem; cursor: pointer;
|
|
14
|
-
transition: border-color 0.15s ease, color 0.15s ease;
|
|
15
|
-
}
|
|
16
|
-
button:hover { border-color: var(--brand); color: var(--brand); }
|
|
17
|
-
span { min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
|
|
18
|
-
`);
|
|
19
|
-
|
|
15
|
+
@element('only-ticker', { root: 'shadow-open' })
|
|
20
16
|
export default class OnlyTicker extends OpenElement {
|
|
21
|
-
static override styles =
|
|
17
|
+
static override styles = tickerStyles;
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
#tick = signal(0);
|
|
19
|
+
@property({ reflect: false, attribute: false })
|
|
20
|
+
tick = 0;
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.registerSignal('tick', this.#tick);
|
|
22
|
+
bump(): void {
|
|
23
|
+
this.tick++;
|
|
30
24
|
}
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
render() {
|
|
33
27
|
return (
|
|
34
|
-
|
|
35
|
-
<span>{this
|
|
36
|
-
<button type='button' onClick={
|
|
37
|
-
|
|
28
|
+
<div class='ticker-row'>
|
|
29
|
+
<span id='tick'>{this.tick}</span>
|
|
30
|
+
<button type='button' onClick={this.bump}>tick</button>
|
|
31
|
+
</div>
|
|
38
32
|
);
|
|
39
33
|
}
|
|
40
34
|
}
|
|
@@ -1,45 +1,11 @@
|
|
|
1
|
-
/** @jsxImportSource @openelement/element */
|
|
2
|
-
import { defineElement, definePage } from '@openelement/app';
|
|
3
|
-
import { StyleSheet } from '@openelement/element';
|
|
4
|
-
|
|
5
|
-
// Names the content element below. definePage routes always register under
|
|
6
|
-
// the route-path tag; this export never drives page registration (#960).
|
|
7
|
-
export const tagName = 'not-found-page';
|
|
8
|
-
|
|
9
|
-
const styles = new StyleSheet();
|
|
10
|
-
styles.replaceSync(`
|
|
11
|
-
:host { display: block; }
|
|
12
|
-
h1 { font-family: var(--font-serif); font-size: 2.4rem; letter-spacing: -0.015em; margin: 0.75rem 0 0.5rem; font-weight: 700; }
|
|
13
|
-
p { color: var(--ink-2); line-height: 1.6; }
|
|
14
|
-
a { color: var(--brand); font-weight: 600; text-decoration: none; }
|
|
15
|
-
a:hover { text-decoration: underline; }
|
|
16
|
-
`);
|
|
17
|
-
|
|
18
|
-
defineElement(tagName, {
|
|
19
|
-
styles,
|
|
20
|
-
render() {
|
|
21
|
-
return (
|
|
22
|
-
<>
|
|
23
|
-
<h1>404</h1>
|
|
24
|
-
<p>The page you are looking for does not exist.</p>
|
|
25
|
-
<p>
|
|
26
|
-
<a href='/'>Back to the homepage</a>
|
|
27
|
-
</p>
|
|
28
|
-
</>
|
|
29
|
-
);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
1
|
/**
|
|
34
2
|
* Styled 404 (#923): the request-time server renders this page with a 404
|
|
35
3
|
* status for unmatched paths; SSG builds also emit it as static 404.html.
|
|
36
4
|
*/
|
|
37
|
-
|
|
5
|
+
import { definePage } from '@openelement/app';
|
|
6
|
+
import NotFoundPage from '../components/page-404.tsx';
|
|
7
|
+
|
|
8
|
+
export default definePage(NotFoundPage, {
|
|
38
9
|
renderIntent: { mode: 'dynamic' },
|
|
39
10
|
head: { title: '404 — openElement' },
|
|
40
|
-
render() {
|
|
41
|
-
return <not-found-page />;
|
|
42
|
-
},
|
|
43
11
|
});
|
|
44
|
-
|
|
45
|
-
export default NotFoundPage;
|
|
@@ -1,76 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { posts } from '@openelement/generated/blog-data';
|
|
1
|
+
/** Static blog index (default renderIntent mode 'static'). */
|
|
2
|
+
import { definePage } from '@openelement/app';
|
|
3
|
+
import BlogIndexPage from '../../components/page-blog-index.tsx';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
// the route-path tag; this export never drives page registration (#960).
|
|
8
|
-
export const tagName = 'blog-index-page';
|
|
9
|
-
|
|
10
|
-
const styles = new StyleSheet();
|
|
11
|
-
styles.replaceSync(`
|
|
12
|
-
:host { display: block; }
|
|
13
|
-
.eyebrow { color: var(--brand); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; }
|
|
14
|
-
h1 { font-family: var(--font-serif); letter-spacing: -0.015em; margin: 0.5rem 0; }
|
|
15
|
-
.sub { color: var(--ink-2); font-size: 0.925rem; margin: 0 0 1.5rem; }
|
|
16
|
-
.sub code { font-size: 0.85em; }
|
|
17
|
-
.posts { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
|
|
18
|
-
.post { display: block; padding: 1.15rem 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
|
|
19
|
-
a.post:hover { text-decoration: none; }
|
|
20
|
-
a.post:hover .title { color: var(--brand); }
|
|
21
|
-
.post .title { display: block; font-family: var(--font-serif); font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); transition: color 0.15s ease; }
|
|
22
|
-
.post .meta { display: block; margin-top: 0.3rem; font-size: 0.85rem; color: var(--ink-2); }
|
|
23
|
-
.post .excerpt { display: block; margin-top: 0.45rem; color: var(--ink-2); line-height: 1.6; }
|
|
24
|
-
a { color: var(--brand); text-decoration: none; }
|
|
25
|
-
`);
|
|
26
|
-
|
|
27
|
-
// Newest first: sort by frontmatter date descending.
|
|
28
|
-
const sortedPosts = [...posts].sort((a, b) => b.frontmatter.date.localeCompare(a.frontmatter.date));
|
|
29
|
-
|
|
30
|
-
defineElement(tagName, {
|
|
31
|
-
styles,
|
|
32
|
-
render() {
|
|
33
|
-
return (
|
|
34
|
-
<>
|
|
35
|
-
<span class='eyebrow'>Index</span>
|
|
36
|
-
<h1>Blog</h1>
|
|
37
|
-
<p class='sub'>
|
|
38
|
-
Every post is a markdown file in <code>content/blog/</code>, pre-rendered at build time.
|
|
39
|
-
</p>
|
|
40
|
-
<ul class='posts'>
|
|
41
|
-
{sortedPosts.map((post) => (
|
|
42
|
-
<li key={post.slug}>
|
|
43
|
-
<a class='post' href={'/blog/' + post.slug}>
|
|
44
|
-
<span class='title'>{post.frontmatter.title}</span>
|
|
45
|
-
<span class='meta'>
|
|
46
|
-
<time>{post.frontmatter.date.slice(0, 10)}</time>
|
|
47
|
-
{(post.frontmatter.tags ?? []).length
|
|
48
|
-
? ' · ' + (post.frontmatter.tags ?? []).join(', ')
|
|
49
|
-
: ''}
|
|
50
|
-
</span>
|
|
51
|
-
{post.frontmatter.excerpt
|
|
52
|
-
? <span class='excerpt'>{post.frontmatter.excerpt}</span>
|
|
53
|
-
: null}
|
|
54
|
-
</a>
|
|
55
|
-
</li>
|
|
56
|
-
))}
|
|
57
|
-
</ul>
|
|
58
|
-
</>
|
|
59
|
-
);
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export default definePage({
|
|
64
|
-
route: { path: '/blog' },
|
|
5
|
+
export default definePage(BlogIndexPage, {
|
|
65
6
|
head: {
|
|
66
7
|
title: 'Blog — My openElement App',
|
|
67
|
-
description: 'Posts from
|
|
68
|
-
},
|
|
69
|
-
renderIntent: {
|
|
70
|
-
mode: 'static',
|
|
71
|
-
revalidate: false,
|
|
72
|
-
},
|
|
73
|
-
render() {
|
|
74
|
-
return <blog-index-page />;
|
|
8
|
+
description: 'Posts from app/routes/blog',
|
|
75
9
|
},
|
|
76
10
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Static blog post page (default renderIntent mode 'static'). */
|
|
2
|
+
import { definePage } from '@openelement/app';
|
|
3
|
+
import BlogWelcomePage from '../../components/page-blog-welcome.tsx';
|
|
4
|
+
|
|
5
|
+
export default definePage(BlogWelcomePage, {
|
|
6
|
+
head: { title: 'Welcome — My openElement App' },
|
|
7
|
+
});
|
|
@@ -1,73 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { StyleSheet } from '@openelement/element';
|
|
1
|
+
/**
|
|
2
|
+
* /contact — a request-time route exercising the WC Application Loop: the
|
|
3
|
+
* plain HTML form works without JavaScript (422 echo / 303 PRG), and
|
|
4
|
+
* data-open-enhance morphs the page when JS is present. The props projector
|
|
5
|
+
* is the single deterministic seam mapping request scope onto the compiled
|
|
6
|
+
* page properties.
|
|
7
|
+
*/
|
|
8
|
+
import { definePage, fail, type OpenElementActionFailure, redirect } from '@openelement/app';
|
|
9
|
+
import ContactPage from '../components/page-contact.tsx';
|
|
11
10
|
|
|
12
11
|
interface ContactActionData {
|
|
13
12
|
error?: string;
|
|
14
13
|
email?: string;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
const styles = new StyleSheet();
|
|
18
|
-
styles.replaceSync(`
|
|
19
|
-
:host { display: block; }
|
|
20
|
-
h1 { font-family: var(--font-serif); font-size: 2.4rem; letter-spacing: -0.015em; margin: 0.75rem 0 0.5rem; font-weight: 700; }
|
|
21
|
-
.sub { color: var(--ink-2); line-height: 1.6; max-width: 52ch; margin: 0 0 1.75rem; }
|
|
22
|
-
form { display: flex; gap: 0.6rem; flex-wrap: wrap; }
|
|
23
|
-
input {
|
|
24
|
-
font: inherit; min-width: 16rem; padding: 0.55rem 0.8rem; color: var(--ink);
|
|
25
|
-
border: 1px solid var(--line); border-radius: 6px; background: #fff;
|
|
26
|
-
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
27
|
-
}
|
|
28
|
-
input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px #8262db2e; }
|
|
29
|
-
button {
|
|
30
|
-
font: inherit; font-weight: 600; padding: 0.55rem 1.1rem; cursor: pointer;
|
|
31
|
-
border: 1px solid var(--brand); border-radius: 6px; background: var(--brand); color: #fff;
|
|
32
|
-
transition: opacity 0.15s ease;
|
|
33
|
-
}
|
|
34
|
-
button:hover { opacity: 0.88; }
|
|
35
|
-
#error { color: #c92a2a; margin: 1rem 0 0; }
|
|
36
|
-
#thanks { color: var(--brand); font-weight: 600; margin: 1rem 0 0; }
|
|
37
|
-
`);
|
|
38
|
-
|
|
39
|
-
defineElement('contact-form-view', {
|
|
40
|
-
styles,
|
|
41
|
-
render(props: { email?: string; error?: string; subscribed?: string }) {
|
|
42
|
-
return (
|
|
43
|
-
<>
|
|
44
|
-
<h1>Stay in the loop</h1>
|
|
45
|
-
<p class='sub'>
|
|
46
|
-
A request-time route: the plain form works without JavaScript, and morphs in place with
|
|
47
|
-
it.
|
|
48
|
-
</p>
|
|
49
|
-
<form method='post' data-open-enhance>
|
|
50
|
-
<input
|
|
51
|
-
id='email'
|
|
52
|
-
name='email'
|
|
53
|
-
type='text'
|
|
54
|
-
value={props.email ?? ''}
|
|
55
|
-
placeholder='you@example.com'
|
|
56
|
-
/>
|
|
57
|
-
<button type='submit'>Subscribe</button>
|
|
58
|
-
</form>
|
|
59
|
-
{props.error ? <p id='error'>{props.error}</p> : null}
|
|
60
|
-
{props.subscribed ? <p id='thanks'>subscribed={props.subscribed}</p> : null}
|
|
61
|
-
</>
|
|
62
|
-
);
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* A request-time route exercising the 0.42 WC Application Loop: plain HTML
|
|
68
|
-
* form works without JavaScript (422 echo / 303 PRG), data-open-enhance
|
|
69
|
-
* morphs the page when JS is present.
|
|
70
|
-
*/
|
|
71
16
|
export function action(ctx: { formData: FormData }): OpenElementActionFailure<ContactActionData> {
|
|
72
17
|
const email = String(ctx.formData.get('email') ?? '').trim();
|
|
73
18
|
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) {
|
|
@@ -76,23 +21,16 @@ export function action(ctx: { formData: FormData }): OpenElementActionFailure<Co
|
|
|
76
21
|
throw redirect(`/contact?subscribed=${encodeURIComponent(email)}`);
|
|
77
22
|
}
|
|
78
23
|
|
|
79
|
-
|
|
24
|
+
export default definePage(ContactPage, {
|
|
80
25
|
renderIntent: { mode: 'dynamic' },
|
|
81
26
|
head: { title: 'Contact — openElement' },
|
|
82
|
-
|
|
83
|
-
const actionData = useActionData() as ContactActionData | undefined;
|
|
27
|
+
props({ request, actionData }) {
|
|
84
28
|
const subscribed = request ? new URL(request.url).searchParams.get('subscribed') : undefined;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
);
|
|
29
|
+
const result = actionData as ContactActionData | undefined;
|
|
30
|
+
return {
|
|
31
|
+
email: result?.email ?? '',
|
|
32
|
+
errorText: result?.error ?? '',
|
|
33
|
+
subscribedText: subscribed ? `subscribed=${subscribed}` : '',
|
|
34
|
+
};
|
|
92
35
|
},
|
|
93
36
|
});
|
|
94
|
-
|
|
95
|
-
// The generated server registers route default exports itself
|
|
96
|
-
// (entry-renderer.ts) — route modules never call customElements.define,
|
|
97
|
-
// which also keeps the packed-consumer typecheck clean.
|
|
98
|
-
export default ContactPage;
|
|
@@ -1,47 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* /freshness — static prerender proof route. The page is prerendered once at
|
|
3
|
+
* build time like any other static route; v0.44 ships no route-level cache
|
|
4
|
+
* revalidation semantics (ISR was removed, see issue #1217).
|
|
5
|
+
*/
|
|
6
|
+
import { definePage } from '@openelement/app';
|
|
7
|
+
import FreshnessPage from '../components/page-freshness.tsx';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
// the route-path tag; this export never drives page registration (#960).
|
|
7
|
-
export const tagName = 'freshness-view';
|
|
8
|
-
|
|
9
|
-
const styles = new StyleSheet();
|
|
10
|
-
styles.replaceSync(`
|
|
11
|
-
:host { display: block; max-width: 800px; margin: 2rem auto; padding: 0 1rem; }
|
|
12
|
-
p { color: var(--text-secondary, #666); }
|
|
13
|
-
`);
|
|
14
|
-
|
|
15
|
-
defineElement(tagName, {
|
|
16
|
-
styles,
|
|
17
|
-
render() {
|
|
18
|
-
return (
|
|
19
|
-
<>
|
|
20
|
-
<h1>Freshness proof</h1>
|
|
21
|
-
<p>
|
|
22
|
-
This page records ISR/cache intent with a 300 second revalidate window. In 0.42 the
|
|
23
|
-
revalidate value is a forward-compatible record only — no cache is wired to it yet
|
|
24
|
-
(targeted for 0.44), so this page renders statically at build time like any other static
|
|
25
|
-
route.
|
|
26
|
-
</p>
|
|
27
|
-
</>
|
|
28
|
-
);
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export default definePage({
|
|
33
|
-
route: { path: '/freshness' },
|
|
9
|
+
export default definePage(FreshnessPage, {
|
|
34
10
|
head: {
|
|
35
11
|
title: 'Freshness proof',
|
|
36
|
-
description: 'Generated openElement
|
|
12
|
+
description: 'Generated openElement static prerender route',
|
|
37
13
|
},
|
|
38
14
|
renderIntent: {
|
|
39
15
|
mode: 'static',
|
|
40
|
-
// Forward-compatible record only — not wired to any cache in 0.42
|
|
41
|
-
// (0.44 target); the page is prerendered once at build time.
|
|
42
|
-
revalidate: 300,
|
|
43
|
-
},
|
|
44
|
-
render() {
|
|
45
|
-
return <freshness-view />;
|
|
46
16
|
},
|
|
47
17
|
});
|