zero-query 0.9.9 → 1.0.1
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 +34 -33
- package/cli/args.js +1 -1
- package/cli/commands/build.js +2 -2
- package/cli/commands/bundle.js +21 -18
- package/cli/commands/create.js +9 -2
- package/cli/commands/dev/devtools/index.js +1 -1
- package/cli/commands/dev/devtools/js/core.js +14 -14
- package/cli/commands/dev/devtools/js/elements.js +4 -4
- package/cli/commands/dev/devtools/js/stats.js +1 -1
- package/cli/commands/dev/devtools/styles.css +2 -2
- package/cli/commands/dev/index.js +2 -2
- package/cli/commands/dev/logger.js +1 -1
- package/cli/commands/dev/overlay.js +21 -14
- package/cli/commands/dev/server.js +5 -5
- package/cli/commands/dev/validator.js +7 -7
- package/cli/commands/dev/watcher.js +6 -6
- package/cli/help.js +3 -3
- package/cli/index.js +1 -1
- package/cli/scaffold/default/app/app.js +17 -18
- package/cli/scaffold/default/app/components/about.js +9 -9
- package/cli/scaffold/default/app/components/api-demo.js +6 -6
- package/cli/scaffold/default/app/components/contact-card.js +4 -4
- package/cli/scaffold/default/app/components/contacts/contacts.css +2 -2
- package/cli/scaffold/default/app/components/contacts/contacts.html +3 -3
- package/cli/scaffold/default/app/components/contacts/contacts.js +11 -11
- package/cli/scaffold/default/app/components/counter.js +8 -8
- package/cli/scaffold/default/app/components/home.js +13 -13
- package/cli/scaffold/default/app/components/not-found.js +1 -1
- package/cli/scaffold/default/app/components/playground/playground.css +1 -1
- package/cli/scaffold/default/app/components/playground/playground.html +11 -11
- package/cli/scaffold/default/app/components/playground/playground.js +11 -11
- package/cli/scaffold/default/app/components/todos.js +8 -8
- package/cli/scaffold/default/app/components/toolkit/toolkit.css +1 -1
- package/cli/scaffold/default/app/components/toolkit/toolkit.html +4 -4
- package/cli/scaffold/default/app/components/toolkit/toolkit.js +7 -7
- package/cli/scaffold/default/app/routes.js +1 -1
- package/cli/scaffold/default/app/store.js +1 -1
- package/cli/scaffold/default/global.css +2 -2
- package/cli/scaffold/default/index.html +2 -2
- package/cli/scaffold/minimal/app/app.js +6 -7
- package/cli/scaffold/minimal/app/components/about.js +5 -5
- package/cli/scaffold/minimal/app/components/counter.js +6 -6
- package/cli/scaffold/minimal/app/components/home.js +8 -8
- package/cli/scaffold/minimal/app/components/not-found.js +1 -1
- package/cli/scaffold/minimal/app/routes.js +1 -1
- package/cli/scaffold/minimal/app/store.js +1 -1
- package/cli/scaffold/minimal/global.css +2 -2
- package/cli/scaffold/minimal/index.html +1 -1
- package/cli/scaffold/ssr/app/app.js +1 -2
- package/cli/scaffold/ssr/app/components/about.js +5 -5
- package/cli/scaffold/ssr/app/components/home.js +2 -2
- package/cli/scaffold/ssr/app/components/not-found.js +2 -2
- package/cli/scaffold/ssr/app/routes.js +1 -1
- package/cli/scaffold/ssr/global.css +3 -4
- package/cli/scaffold/ssr/index.html +2 -2
- package/cli/scaffold/ssr/server/index.js +26 -25
- package/cli/utils.js +6 -6
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +508 -227
- package/dist/zquery.min.js +2 -2
- package/index.d.ts +16 -13
- package/index.js +7 -5
- package/package.json +3 -3
- package/src/component.js +64 -63
- package/src/core.js +15 -15
- package/src/diff.js +38 -38
- package/src/errors.js +17 -17
- package/src/expression.js +15 -17
- package/src/http.js +4 -4
- package/src/reactive.js +75 -9
- package/src/router.js +104 -24
- package/src/ssr.js +28 -28
- package/src/store.js +103 -21
- package/src/utils.js +64 -12
- package/tests/audit.test.js +143 -15
- package/tests/cli.test.js +20 -20
- package/tests/component.test.js +121 -121
- package/tests/core.test.js +56 -56
- package/tests/diff.test.js +42 -42
- package/tests/errors.test.js +5 -5
- package/tests/expression.test.js +58 -53
- package/tests/http.test.js +20 -20
- package/tests/reactive.test.js +185 -24
- package/tests/router.test.js +501 -74
- package/tests/ssr.test.js +15 -13
- package/tests/store.test.js +264 -23
- package/tests/test-minifier.js +153 -0
- package/tests/test-ssr.js +27 -0
- package/tests/utils.test.js +163 -26
- package/types/collection.d.ts +2 -2
- package/types/component.d.ts +5 -5
- package/types/errors.d.ts +3 -3
- package/types/http.d.ts +3 -3
- package/types/misc.d.ts +9 -9
- package/types/reactive.d.ts +25 -3
- package/types/router.d.ts +10 -6
- package/types/ssr.d.ts +2 -2
- package/types/store.d.ts +40 -5
- package/types/utils.d.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// server/index.js
|
|
1
|
+
// server/index.js - SSR HTTP server
|
|
2
2
|
//
|
|
3
3
|
// Renders routes to HTML with zQuery SSR and serves them over HTTP.
|
|
4
|
-
// Components are imported from app/components/
|
|
4
|
+
// Components are imported from app/components/ - the same definitions
|
|
5
5
|
// the client uses.
|
|
6
6
|
//
|
|
7
7
|
// Usage:
|
|
@@ -14,7 +14,7 @@ import { join, extname, resolve } from 'node:path';
|
|
|
14
14
|
import { fileURLToPath } from 'node:url';
|
|
15
15
|
import { createSSRApp } from 'zero-query/ssr';
|
|
16
16
|
|
|
17
|
-
// Shared component definitions
|
|
17
|
+
// Shared component definitions - same ones the client registers
|
|
18
18
|
import { homePage } from '../app/components/home.js';
|
|
19
19
|
import { aboutPage } from '../app/components/about.js';
|
|
20
20
|
import { notFound } from '../app/components/not-found.js';
|
|
@@ -40,32 +40,33 @@ function matchRoute(pathname) {
|
|
|
40
40
|
|
|
41
41
|
// --- Render a full HTML page ------------------------------------------------
|
|
42
42
|
|
|
43
|
+
// Read the index.html shell once at startup — it already has z-link nav,
|
|
44
|
+
// client scripts (zquery.min.js + app/app.js), and the <z-outlet> tag.
|
|
45
|
+
// On each request we just inject the SSR body into <z-outlet>.
|
|
46
|
+
let shellCache = null;
|
|
47
|
+
async function getShell() {
|
|
48
|
+
if (!shellCache) shellCache = await readFile(join(ROOT, 'index.html'), 'utf-8');
|
|
49
|
+
return shellCache;
|
|
50
|
+
}
|
|
51
|
+
|
|
43
52
|
async function render(pathname) {
|
|
44
53
|
const component = matchRoute(pathname);
|
|
45
54
|
const body = await app.renderToString(component);
|
|
55
|
+
const shell = await getShell();
|
|
56
|
+
|
|
57
|
+
// Inject SSR content into <z-outlet …> and add active class to nav
|
|
58
|
+
let html = shell.replace(/(<z-outlet[^>]*>)(<\/z-outlet>)?/, `$1${body}</z-outlet>`);
|
|
59
|
+
|
|
60
|
+
// Mark the active nav link for the current route
|
|
61
|
+
html = html.replace(
|
|
62
|
+
/(<a\s+z-link="([^"]*)"[^>]*class="nav-link)(">)/g,
|
|
63
|
+
(match, before, href, after) =>
|
|
64
|
+
href === pathname
|
|
65
|
+
? `${before} active${after}`
|
|
66
|
+
: `${before}${after}`
|
|
67
|
+
);
|
|
46
68
|
|
|
47
|
-
return
|
|
48
|
-
<html lang="en">
|
|
49
|
-
<head>
|
|
50
|
-
<meta charset="UTF-8">
|
|
51
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
52
|
-
<title>{{NAME}}</title>
|
|
53
|
-
<link rel="stylesheet" href="/global.css">
|
|
54
|
-
</head>
|
|
55
|
-
<body>
|
|
56
|
-
<nav class="navbar">
|
|
57
|
-
<span class="brand">⚡ {{NAME}}</span>
|
|
58
|
-
<div class="nav-links">
|
|
59
|
-
${routes.map(r =>
|
|
60
|
-
` <a href="${r.path}" class="nav-link${r.path === pathname ? ' active' : ''}">${
|
|
61
|
-
r.path === '/' ? 'Home' : r.path.slice(1)[0].toUpperCase() + r.path.slice(2)
|
|
62
|
-
}</a>`).join('\n')}
|
|
63
|
-
</div>
|
|
64
|
-
</nav>
|
|
65
|
-
<main id="app">${body}</main>
|
|
66
|
-
<footer class="footer"><small>Built with zQuery · SSR</small></footer>
|
|
67
|
-
</body>
|
|
68
|
-
</html>`;
|
|
69
|
+
return html;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
// --- Static files -----------------------------------------------------------
|
package/cli/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* cli/utils.js
|
|
2
|
+
* cli/utils.js - shared utility functions
|
|
3
3
|
*
|
|
4
4
|
* Context-aware comment stripping, quick minification, size formatting,
|
|
5
5
|
* and recursive directory copying. These are consumed by both the
|
|
@@ -12,7 +12,7 @@ const fs = require('fs');
|
|
|
12
12
|
const path = require('path');
|
|
13
13
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
|
-
// _copyTemplateLiteral
|
|
15
|
+
// _copyTemplateLiteral - copy a template literal verbatim, tracking ${…}
|
|
16
16
|
// nesting so that `//` inside template text isn't mistaken for a comment.
|
|
17
17
|
// ---------------------------------------------------------------------------
|
|
18
18
|
|
|
@@ -49,7 +49,7 @@ function _copyTemplateLiteral(code, start) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
|
-
// stripComments
|
|
52
|
+
// stripComments - context-aware, skips strings / templates / regex
|
|
53
53
|
// ---------------------------------------------------------------------------
|
|
54
54
|
|
|
55
55
|
function stripComments(code) {
|
|
@@ -127,7 +127,7 @@ function stripComments(code) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// ---------------------------------------------------------------------------
|
|
130
|
-
// minify
|
|
130
|
+
// minify - single-pass minification
|
|
131
131
|
// Strips comments, collapses whitespace to the minimum required,
|
|
132
132
|
// and preserves string / template-literal / regex content verbatim.
|
|
133
133
|
// ---------------------------------------------------------------------------
|
|
@@ -251,7 +251,7 @@ function _isRegexCtx(out) {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
// ---------------------------------------------------------------------------
|
|
254
|
-
// sizeKB
|
|
254
|
+
// sizeKB - human-readable file size
|
|
255
255
|
// ---------------------------------------------------------------------------
|
|
256
256
|
|
|
257
257
|
function sizeKB(buf) {
|
|
@@ -259,7 +259,7 @@ function sizeKB(buf) {
|
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
// ---------------------------------------------------------------------------
|
|
262
|
-
// copyDirSync
|
|
262
|
+
// copyDirSync - recursive directory copy
|
|
263
263
|
// ---------------------------------------------------------------------------
|
|
264
264
|
|
|
265
265
|
function copyDirSync(src, dest) {
|
package/dist/zquery.dist.zip
CHANGED
|
Binary file
|