@openelement/create 0.42.0-alpha.3 → 0.42.0-alpha.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openelement/create",
3
- "version": "0.42.0-alpha.3",
3
+ "version": "0.42.0-alpha.4",
4
4
  "type": "module",
5
5
  "main": "./src/cli.js",
6
6
  "types": "./src/cli.d.ts",
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
- /** The published CLI version, embedded so packed npm installs are self-contained. */ export const CREATE_VERSION = '0.42.0-alpha.3';
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZpbGU6Ly8vaG9tZS9ydW5uZXIvd29yay9vcGVuZWxlbWVudC9vcGVuZWxlbWVudC9wYWNrYWdlcy9jcmVhdGUvc3JjL3ZlcnNpb24udHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqIFRoZSBwdWJsaXNoZWQgQ0xJIHZlcnNpb24sIGVtYmVkZGVkIHNvIHBhY2tlZCBucG0gaW5zdGFsbHMgYXJlIHNlbGYtY29udGFpbmVkLiAqL1xuZXhwb3J0IGNvbnN0IENSRUFURV9WRVJTSU9OID0gJzAuNDIuMC1hbHBoYS4zJztcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxtRkFBbUYsR0FDbkYsT0FBTyxNQUFNLGlCQUFpQixpQkFBaUIifQ==
1
+ /** The published CLI version, embedded so packed npm installs are self-contained. */ export const CREATE_VERSION = '0.42.0-alpha.4';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZpbGU6Ly8vaG9tZS9ydW5uZXIvd29yay9vcGVuZWxlbWVudC9vcGVuZWxlbWVudC9wYWNrYWdlcy9jcmVhdGUvc3JjL3ZlcnNpb24udHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqIFRoZSBwdWJsaXNoZWQgQ0xJIHZlcnNpb24sIGVtYmVkZGVkIHNvIHBhY2tlZCBucG0gaW5zdGFsbHMgYXJlIHNlbGYtY29udGFpbmVkLiAqL1xuZXhwb3J0IGNvbnN0IENSRUFURV9WRVJTSU9OID0gJzAuNDIuMC1hbHBoYS40JztcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxtRkFBbUYsR0FDbkYsT0FBTyxNQUFNLGlCQUFpQixpQkFBaUIifQ==
@@ -0,0 +1,57 @@
1
+ /** @jsxImportSource @openelement/element */
2
+ import {
3
+ definePage,
4
+ fail,
5
+ type OpenElementActionFailure,
6
+ redirect,
7
+ useActionData,
8
+ } from '@openelement/app';
9
+
10
+ export const tagName = 'contact-page';
11
+
12
+ interface ContactActionData {
13
+ error?: string;
14
+ email?: string;
15
+ }
16
+
17
+ /**
18
+ * A request-time route exercising the 0.42 WC Application Loop: plain HTML
19
+ * form works without JavaScript (422 echo / 303 PRG), data-open-enhance
20
+ * morphs the page when JS is present.
21
+ */
22
+ export function action(ctx: { formData: FormData }): OpenElementActionFailure<ContactActionData> {
23
+ const email = String(ctx.formData.get('email') ?? '').trim();
24
+ if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) {
25
+ return fail(422, { error: 'a valid email is required', email });
26
+ }
27
+ redirect(`/contact?subscribed=${encodeURIComponent(email)}`);
28
+ }
29
+
30
+ const ContactPage = definePage({
31
+ renderIntent: { mode: 'dynamic' },
32
+ head: { title: 'Contact — openElement' },
33
+ render({ request }) {
34
+ const actionData = useActionData() as ContactActionData | undefined;
35
+ const subscribed = request ? new URL(request.url).searchParams.get('subscribed') : undefined;
36
+ return (
37
+ <main>
38
+ <h1>Stay in the loop</h1>
39
+ <form method='post' data-open-enhance>
40
+ <input
41
+ id='email'
42
+ name='email'
43
+ type='text'
44
+ value={actionData?.email ?? ''}
45
+ placeholder='you@example.com'
46
+ />
47
+ <button type='submit'>Subscribe</button>
48
+ </form>
49
+ {actionData?.error ? <p id='error'>{actionData.error}</p> : null}
50
+ {subscribed ? <p id='thanks'>subscribed={subscribed}</p> : null}
51
+ </main>
52
+ );
53
+ },
54
+ });
55
+
56
+ customElements.define(tagName, ContactPage);
57
+ export default ContactPage;