create-qwik 0.0.36 → 0.0.39-dev20220722190315

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.
Files changed (46) hide show
  1. package/create-qwik +14 -14
  2. package/index.js +12 -8
  3. package/package.json +1 -1
  4. package/starters/apps/base/{.eslintrc.js → .eslintrc.cjs} +0 -0
  5. package/starters/apps/base/package.json +9 -8
  6. package/starters/apps/blank/package.json +5 -1
  7. package/starters/apps/library/package.json +9 -5
  8. package/starters/apps/library/vite.config.ts +2 -1
  9. package/starters/apps/qwik-city/package.json +6 -1
  10. package/starters/apps/qwik-city/src/components/breadcrumbs/breadcrumbs.css +25 -0
  11. package/starters/apps/qwik-city/src/components/breadcrumbs/breadcrumbs.tsx +77 -0
  12. package/starters/apps/qwik-city/src/components/footer/footer.css +1 -1
  13. package/starters/apps/qwik-city/src/components/footer/footer.tsx +3 -1
  14. package/starters/apps/qwik-city/src/components/header/header.css +10 -1
  15. package/starters/apps/qwik-city/src/components/header/header.tsx +24 -32
  16. package/starters/apps/qwik-city/src/components/menu/menu.css +10 -0
  17. package/starters/apps/qwik-city/src/components/menu/menu.tsx +4 -4
  18. package/starters/apps/qwik-city/src/global.css +21 -12
  19. package/starters/apps/qwik-city/src/routes/about-us.tsx +2 -4
  20. package/starters/apps/qwik-city/src/routes/api/[org]/[user].json/index.ts +12 -23
  21. package/starters/apps/qwik-city/src/routes/api/_layout-foo/index.tsx +16 -22
  22. package/starters/apps/qwik-city/src/routes/api/data.json.ts +6 -9
  23. package/starters/apps/qwik-city/src/routes/api/index@foo.tsx +7 -4
  24. package/starters/apps/qwik-city/src/routes/blog/[...slug].tsx +28 -5
  25. package/starters/apps/qwik-city/src/routes/blog/_layout/index.tsx +2 -2
  26. package/starters/apps/qwik-city/src/routes/dashboard/index.tsx +8 -0
  27. package/starters/apps/qwik-city/src/routes/docs/[category]/[id]/index.tsx +14 -6
  28. package/starters/apps/qwik-city/src/routes/docs/{_layout/docs.css → _layout!/index.css} +2 -1
  29. package/starters/apps/qwik-city/src/routes/docs/_layout!/index.tsx +31 -0
  30. package/starters/apps/qwik-city/src/routes/docs/_menu.md +4 -2
  31. package/starters/apps/qwik-city/src/routes/docs/getting-started.md +44 -0
  32. package/starters/apps/qwik-city/src/routes/docs/index.tsx +2 -4
  33. package/starters/apps/qwik-city/src/routes/docs/{introduction → overview}/index.md +2 -2
  34. package/starters/apps/qwik-city/src/routes/index.tsx +6 -1
  35. package/starters/apps/qwik-city/src/routes/products/[id].tsx +132 -0
  36. package/starters/features/react/package.json +2 -2
  37. package/starters/features/react/src/react/app.tsx +1 -1
  38. package/starters/servers/cloudflare-pages/functions/[[path]].ts +1 -1
  39. package/starters/servers/express/package.json +1 -1
  40. package/starters/servers/express/src/entry.express.tsx +2 -1
  41. package/starters/apps/qwik-city/src/routes/__auth/_layout.tsx +0 -17
  42. package/starters/apps/qwik-city/src/routes/__auth/sign-in.tsx +0 -25
  43. package/starters/apps/qwik-city/src/routes/__auth/sign-up.tsx +0 -29
  44. package/starters/apps/qwik-city/src/routes/api/on-sign-in.ts +0 -67
  45. package/starters/apps/qwik-city/src/routes/docs/_layout/index.tsx +0 -23
  46. package/starters/apps/qwik-city/src/routes/docs/getting-started.mdx +0 -32
@@ -0,0 +1,132 @@
1
+ import { Resource, component$, Host, useStore } from '@builder.io/qwik';
2
+ import { useEndpoint, useLocation, EndpointHandler, DocumentHead } from '@builder.io/qwik-city';
3
+ import os from 'os';
4
+
5
+ export default component$(() => {
6
+ const { params, pathname } = useLocation();
7
+ const store = useStore({ productFetchData: '' });
8
+
9
+ const resource = useEndpoint<EndpointData>();
10
+
11
+ return (
12
+ <Host>
13
+ <Resource
14
+ resource={resource}
15
+ onPending={() => <p>Loading</p>}
16
+ onResolved={(product) => {
17
+ if (product == null) {
18
+ return <h1>Product "{params.id}" not found</h1>;
19
+ }
20
+
21
+ return (
22
+ <>
23
+ <h1>Product: {product.productId}</h1>
24
+ <p>Price: {product.price}</p>
25
+ <p>{product.description}</p>
26
+ </>
27
+ );
28
+ }}
29
+ />
30
+
31
+ <p>(Artificial response delay of 250ms)</p>
32
+
33
+ <p>
34
+ <button
35
+ onClick$={async () => {
36
+ const rsp = await fetch(pathname, {
37
+ headers: { accept: 'application/json' },
38
+ });
39
+ store.productFetchData = JSON.stringify(await rsp.json(), null, 2);
40
+ }}
41
+ >
42
+ fetch("{pathname}") data
43
+ </button>
44
+ </p>
45
+
46
+ <pre>
47
+ <code>{store.productFetchData}</code>
48
+ </pre>
49
+
50
+ <hr />
51
+
52
+ <ul>
53
+ <li>
54
+ <a href="/products/jacket">Jacket</a>
55
+ </li>
56
+ <li>
57
+ <a href="/products/hat">Hat</a>
58
+ </li>
59
+ <li>
60
+ <a href="/products/shirt">T-Shirt (Redirect to /products/tshirt)</a>
61
+ </li>
62
+ <li>
63
+ <a href="/products/hoodie">Hoodie (404 Not Found)</a>
64
+ </li>
65
+ </ul>
66
+ </Host>
67
+ );
68
+ });
69
+
70
+ export const head: DocumentHead<ProductData | null> = ({ data }) => {
71
+ if (!data) {
72
+ return {
73
+ title: 'Product Not Found',
74
+ };
75
+ }
76
+
77
+ return {
78
+ title: `Product ${data.productId}, ${data.price}`,
79
+ };
80
+ };
81
+
82
+ export const onGet: EndpointHandler<EndpointData> = async ({ params, response }) => {
83
+ // Serverside Endpoint
84
+ // During SSR, this method is called directly on the server and returns the data object
85
+ // On the client, this same data can be requested with fetch() at the same URL, but also
86
+ // requires the "accept: application/json" request header.
87
+
88
+ // artificial slow response
89
+ await new Promise<void>((resolve) => setTimeout(resolve, 250));
90
+
91
+ if (params.id === 'shirt') {
92
+ // Redirect, which will skip any rendering and the server will immediately redirect
93
+ response.redirect('/products/tshirt');
94
+ return;
95
+ }
96
+
97
+ const productPrice = PRODUCT_DB[params.id];
98
+
99
+ if (!productPrice) {
100
+ // Product data not found
101
+ // but the data is still given to the renderer to decide what to do
102
+ response.status(404);
103
+ return null;
104
+ }
105
+
106
+ // Found the product data
107
+ // This same data is passed to the head() function
108
+ // and in the component$() it can be access with useEndpoint()
109
+ response.headers.set('Cache-Control', 'no-cache, no-store, no-fun');
110
+ return {
111
+ productId: params.id,
112
+ price: productPrice,
113
+ description: `Node ${process.versions.node} ${os.platform()} ${os.arch()} ${
114
+ os.cpus()[0].model
115
+ }`,
116
+ };
117
+ };
118
+
119
+ // Our pretty awesome database of prices
120
+ const PRODUCT_DB: Record<string, string> = {
121
+ hat: '$21.96',
122
+ jacket: '$48.96',
123
+ tshirt: '$18.96',
124
+ };
125
+
126
+ type EndpointData = ProductData | null;
127
+
128
+ interface ProductData {
129
+ productId: string;
130
+ price: string;
131
+ description: string;
132
+ }
@@ -1,11 +1,11 @@
1
1
  {
2
- "description": "Prettier code formatter.",
2
+ "description": "Use React components into your Qwik app",
3
3
  "scripts": {
4
4
  "fmt": "prettier --write .",
5
5
  "fmt.check": "prettier --check ."
6
6
  },
7
7
  "devDependencies": {
8
- "@builder.io/qwik-react": "0.0.4",
8
+ "@builder.io/qwik-react": "0.0.8",
9
9
  "@emotion/react": "11.9.3",
10
10
  "@emotion/server": "11.4.0",
11
11
  "@emotion/styled": "11.9.3",
@@ -11,4 +11,4 @@ export function ReactCmp() {
11
11
  );
12
12
  }
13
13
 
14
- export const ReactRoot = qwikify$(ReactCmp);
14
+ export const ReactRoot = /*#__PURE__*/ qwikify$(ReactCmp);
@@ -2,4 +2,4 @@
2
2
 
3
3
  // Cloudflare Pages Functions
4
4
  // https://developers.cloudflare.com/pages/platform/functions/
5
- export { onRequest } from '../server/entry.cloudflare.js';
5
+ export { onRequest } from '../server/entry.cloudflare';
@@ -2,7 +2,7 @@
2
2
  "description": "Express.js server.",
3
3
  "scripts": {
4
4
  "build.ssr": "vite build --ssr src/entry.express.tsx",
5
- "serve": "node server/entry.express.js"
5
+ "serve": "node server/entry.express"
6
6
  },
7
7
  "devDependencies": {
8
8
  "@types/express": "4.17.13",
@@ -1,4 +1,5 @@
1
1
  import express from 'express';
2
+ import { fileURLToPath } from 'url';
2
3
  import { join } from 'path';
3
4
  import cityPlan from '@qwik-city-plan';
4
5
  import { qwikCity } from '@builder.io/qwik-city/middleware/express';
@@ -9,7 +10,7 @@ const app = express();
9
10
  app.use(
10
11
  qwikCity(render, {
11
12
  ...cityPlan,
12
- staticDir: join(__dirname, '..', 'dist'),
13
+ staticDir: join(fileURLToPath(import.meta.url), '..', '..', 'dist'),
13
14
  })
14
15
  );
15
16
 
@@ -1,17 +0,0 @@
1
- import { component$, Host, Slot } from '@builder.io/qwik';
2
-
3
- export default component$(() => {
4
- return (
5
- <Host>
6
- <section>
7
- <Slot />
8
- </section>
9
- <aside>
10
- <p>Account Help</p>
11
- <ul>
12
- <li>Forgot password</li>
13
- </ul>
14
- </aside>
15
- </Host>
16
- );
17
- });
@@ -1,25 +0,0 @@
1
- import { component$, Host } from '@builder.io/qwik';
2
- import type { DocumentHead } from '@builder.io/qwik-city';
3
-
4
- export default component$(() => {
5
- return (
6
- <Host>
7
- <h1>Sign In</h1>
8
- <form action="/api/on-sign-in" method="post">
9
- <label>
10
- <span>Username</span>
11
- <input name="username" type="text" />
12
- </label>
13
- <label>
14
- <span>Password</span>
15
- <input name="password" type="password" />
16
- </label>
17
- <button>Log In</button>
18
- </form>
19
- </Host>
20
- );
21
- });
22
-
23
- export const head: DocumentHead = {
24
- title: 'Sign In',
25
- };
@@ -1,29 +0,0 @@
1
- import { component$, Host } from '@builder.io/qwik';
2
- import type { DocumentHead } from '@builder.io/qwik-city';
3
-
4
- export default component$(() => {
5
- return (
6
- <Host>
7
- <h1>Sign Up</h1>
8
- <form>
9
- <label>
10
- <span>Username</span>
11
- <input type="text" />
12
- </label>
13
- <label>
14
- <span>Password</span>
15
- <input type="password" />
16
- </label>
17
- <label>
18
- <span>Re-entry Password</span>
19
- <input type="password" />
20
- </label>
21
- <button>Create Account</button>
22
- </form>
23
- </Host>
24
- );
25
- });
26
-
27
- export const head: DocumentHead = {
28
- title: 'Sign Up',
29
- };
@@ -1,67 +0,0 @@
1
- import type { EndpointHandler } from '@builder.io/qwik-city';
2
-
3
- export type Cookie = Record<string, string>;
4
- export type AuthResult = 'New Login' | 'Already Logged In' | 'Invalid Credentials';
5
- export const STATUS: Record<AuthResult, { code: number; msg: string }> = {
6
- 'New Login': {
7
- code: 200,
8
- msg: 'You are now logged in!',
9
- },
10
- 'Already Logged In': {
11
- code: 200,
12
- msg: 'You are now logged in!',
13
- },
14
- 'Invalid Credentials': {
15
- code: 403,
16
- msg: 'Incorrect user name and password',
17
- },
18
- };
19
-
20
- export const post: EndpointHandler = async (ev: any) => {
21
- const cookie = parseCookie(ev.request.headers.get('cookie'));
22
- const formdata = await ev.request.formData();
23
- const result = handleAuth(formdata, cookie);
24
- const status = STATUS[result];
25
- return {
26
- status: status.code,
27
- headers:
28
- result == 'New Login'
29
- ? {
30
- 'Set-Cookie': `${AUTHTOKEN_NAME}=${generateToken()}; Secure; HttpOnly; Max-Age=${
31
- 60 * 5
32
- }`,
33
- }
34
- : {},
35
- };
36
- };
37
-
38
- const AUTHTOKEN_NAME = 'qwikcity-auth-token';
39
- export const handleAuth = (submission: FormData, cookie: Cookie): AuthResult => {
40
- const username = submission.get('username');
41
- const password = submission.get('password');
42
- const token = cookie[AUTHTOKEN_NAME];
43
- if (token !== undefined) {
44
- return 'Already Logged In';
45
- }
46
- if (username == 'admin' && password == 'password') {
47
- return 'New Login';
48
- }
49
- return 'Invalid Credentials';
50
- };
51
-
52
- export const generateToken = () => {
53
- return Math.round(Math.random() * 1000);
54
- };
55
-
56
- export const parseCookie = (raw: string | null): Cookie => {
57
- if (!raw) {
58
- return {};
59
- }
60
- return raw
61
- .split(';')
62
- .map((v) => v.split('='))
63
- .reduce((acc: Cookie, v) => {
64
- acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
65
- return acc;
66
- }, {});
67
- };
@@ -1,23 +0,0 @@
1
- import { component$, Host, Slot, useStyles$ } from '@builder.io/qwik';
2
- import type { DocumentHead } from '@builder.io/qwik-city';
3
- import { Menu } from '../../../components/menu/menu';
4
- import styles from './docs.css?inline';
5
-
6
- export default component$(() => {
7
- useStyles$(styles);
8
-
9
- return (
10
- <Host class="docs">
11
- <Menu />
12
- <section class="docs-content">
13
- <Slot />
14
- </section>
15
- </Host>
16
- );
17
- });
18
-
19
- export const head: DocumentHead = ({ head }) => {
20
- return {
21
- title: `Docs: ${head.title}`,
22
- };
23
- };
@@ -1,32 +0,0 @@
1
- ---
2
- title: Welcome
3
- ---
4
-
5
- import { Counter } from '~/components/counter/counter';
6
-
7
- # Welcome
8
-
9
- Welcome to the fabulous Qwik City. QwikCity is our official kit to build amazing sites:
10
-
11
- - 🐎 Powered by Qwik. Zero hydration and instant interactivity.
12
- - 🗃 File based routing (like Nextjs)
13
- - 🌏 Deploy easily to the edge: Netlify, Cloudflare, Vercel, Deno...
14
- - 📖 Author content directly in Markdown or MDX. MDX brings the best of markdown and JSX, allowing you to render Qwik components directly in markdown, like this one:
15
-
16
- <Counter />
17
-
18
- ## Next steps
19
-
20
- Open your editor and check out the following:
21
-
22
- **The `src/routes` folder**
23
-
24
- This is where the main content lives. Adding folders and / or files (`.md`, `.mdx`, or `.tsx`) will automatically create new URLs. For example, code saved at `routes/dashboard/settings/index.tsx` will be accessible via the URL path `/dashboard/settings`.
25
-
26
- **The `src/routes/_layout` files and folders**
27
-
28
- These bring form to your content. Since different pages may need to be rendered by different layouts, QwikCity provides the ability to scope layouts to specific routes, while still allowing for easy reuse across different content. For any page without its own layout defined, the `src/routes/_layout.tsx` is used by default.
29
-
30
- **The `src/components` folder**
31
-
32
- QwikCity is still a normal Qwik app. Any custom component, design systems, or functionality should live here. Notice the `header`, `footer` and `content-nav` components. They are used by the `default` layout!