zero-query 1.1.1 → 1.2.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/LICENSE +21 -21
- package/README.md +2 -0
- package/cli/args.js +33 -33
- package/cli/commands/build-api.js +442 -442
- package/cli/commands/build.js +253 -247
- package/cli/commands/bundle.js +1226 -1224
- package/cli/commands/create.js +178 -121
- package/cli/commands/dev/devtools/index.js +56 -56
- package/cli/commands/dev/devtools/js/components.js +49 -49
- package/cli/commands/dev/devtools/js/core.js +423 -423
- package/cli/commands/dev/devtools/js/elements.js +421 -421
- package/cli/commands/dev/devtools/js/network.js +166 -166
- package/cli/commands/dev/devtools/js/performance.js +73 -73
- package/cli/commands/dev/devtools/js/router.js +105 -105
- package/cli/commands/dev/devtools/js/source.js +132 -132
- package/cli/commands/dev/devtools/js/stats.js +35 -35
- package/cli/commands/dev/devtools/js/tabs.js +79 -79
- package/cli/commands/dev/devtools/panel.html +95 -95
- package/cli/commands/dev/devtools/styles.css +244 -244
- package/cli/commands/dev/index.js +107 -107
- package/cli/commands/dev/logger.js +75 -75
- package/cli/commands/dev/overlay.js +858 -858
- package/cli/commands/dev/server.js +220 -220
- package/cli/commands/dev/validator.js +94 -94
- package/cli/commands/dev/watcher.js +172 -172
- package/cli/help.js +114 -112
- package/cli/index.js +52 -52
- package/cli/scaffold/default/LICENSE +21 -21
- package/cli/scaffold/default/app/app.js +207 -207
- package/cli/scaffold/default/app/components/about.js +201 -201
- package/cli/scaffold/default/app/components/api-demo.js +143 -143
- package/cli/scaffold/default/app/components/contact-card.js +231 -231
- package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
- package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
- package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
- package/cli/scaffold/default/app/components/counter.js +127 -127
- package/cli/scaffold/default/app/components/home.js +249 -249
- package/cli/scaffold/default/app/components/not-found.js +16 -16
- package/cli/scaffold/default/app/components/playground/playground.css +115 -115
- package/cli/scaffold/default/app/components/playground/playground.html +161 -161
- package/cli/scaffold/default/app/components/playground/playground.js +116 -116
- package/cli/scaffold/default/app/components/todos.js +225 -225
- package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
- package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
- package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
- package/cli/scaffold/default/app/routes.js +15 -15
- package/cli/scaffold/default/app/store.js +101 -101
- package/cli/scaffold/default/global.css +552 -552
- package/cli/scaffold/default/index.html +99 -99
- package/cli/scaffold/minimal/app/app.js +85 -85
- package/cli/scaffold/minimal/app/components/about.js +68 -68
- package/cli/scaffold/minimal/app/components/counter.js +122 -122
- package/cli/scaffold/minimal/app/components/home.js +68 -68
- package/cli/scaffold/minimal/app/components/not-found.js +16 -16
- package/cli/scaffold/minimal/app/routes.js +9 -9
- package/cli/scaffold/minimal/app/store.js +36 -36
- package/cli/scaffold/minimal/global.css +300 -300
- package/cli/scaffold/minimal/index.html +44 -44
- package/cli/scaffold/ssr/app/app.js +41 -41
- package/cli/scaffold/ssr/app/components/about.js +55 -55
- package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
- package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
- package/cli/scaffold/ssr/app/components/home.js +37 -37
- package/cli/scaffold/ssr/app/components/not-found.js +15 -15
- package/cli/scaffold/ssr/app/routes.js +8 -8
- package/cli/scaffold/ssr/global.css +228 -228
- package/cli/scaffold/ssr/index.html +37 -37
- package/cli/scaffold/ssr/package.json +8 -8
- package/cli/scaffold/ssr/server/data/posts.js +144 -144
- package/cli/scaffold/ssr/server/index.js +213 -213
- package/cli/scaffold/webrtc/app/app.js +11 -0
- package/cli/scaffold/webrtc/app/components/video-room.js +441 -0
- package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
- package/cli/scaffold/webrtc/global.css +250 -0
- package/cli/scaffold/webrtc/index.html +21 -0
- package/cli/scaffold/webrtc/package.json +16 -0
- package/cli/scaffold/webrtc/server/index.js +198 -0
- package/cli/utils.js +305 -287
- package/dist/API.md +661 -0
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +10454 -6614
- package/dist/zquery.min.js +8 -631
- package/index.d.ts +570 -371
- package/index.js +311 -240
- package/package.json +77 -70
- package/src/component.js +1758 -1691
- package/src/core.js +929 -921
- package/src/diff.js +497 -497
- package/src/errors.js +209 -209
- package/src/expression.js +929 -922
- package/src/http.js +242 -242
- package/src/package.json +1 -1
- package/src/reactive.js +271 -255
- package/src/router.js +878 -843
- package/src/ssr.js +421 -418
- package/src/store.js +325 -318
- package/src/utils.js +534 -515
- package/src/webrtc/e2ee.js +351 -0
- package/src/webrtc/errors.js +116 -0
- package/src/webrtc/ice.js +301 -0
- package/src/webrtc/index.js +131 -0
- package/src/webrtc/joinToken.js +119 -0
- package/src/webrtc/observe.js +172 -0
- package/src/webrtc/peer.js +351 -0
- package/src/webrtc/reactive.js +268 -0
- package/src/webrtc/room.js +625 -0
- package/src/webrtc/sdp.js +302 -0
- package/src/webrtc/sfu/index.js +43 -0
- package/src/webrtc/sfu/livekit.js +131 -0
- package/src/webrtc/sfu/mediasoup.js +150 -0
- package/src/webrtc/signaling.js +373 -0
- package/src/webrtc/turn.js +237 -0
- package/tests/_helpers/webrtcFakes.js +289 -0
- package/tests/audit.test.js +4158 -4158
- package/tests/bench/render.bench.js +77 -0
- package/tests/cli.test.js +1136 -1103
- package/tests/compare.test.js +497 -486
- package/tests/component.test.js +4076 -3938
- package/tests/core.test.js +1926 -1910
- package/tests/dev-server.test.js +489 -489
- package/tests/diff.test.js +1416 -1416
- package/tests/docs.test.js +1664 -1650
- package/tests/electron-features.test.js +864 -864
- package/tests/errors.test.js +619 -619
- package/tests/expression.test.js +1087 -1056
- package/tests/http.test.js +693 -648
- package/tests/reactive.test.js +844 -819
- package/tests/router.test.js +2423 -2327
- package/tests/ssr.test.js +916 -870
- package/tests/store.test.js +840 -830
- package/tests/test-minifier.js +153 -153
- package/tests/test-ssr.js +27 -27
- package/tests/utils.test.js +1411 -1377
- package/tests/webrtc/e2ee.test.js +283 -0
- package/tests/webrtc/ice.test.js +202 -0
- package/tests/webrtc/joinToken.test.js +89 -0
- package/tests/webrtc/observe.test.js +111 -0
- package/tests/webrtc/peer.test.js +373 -0
- package/tests/webrtc/reactive.test.js +235 -0
- package/tests/webrtc/room.test.js +406 -0
- package/tests/webrtc/sdp.test.js +151 -0
- package/tests/webrtc/sfu-livekit.test.js +119 -0
- package/tests/webrtc/sfu.test.js +160 -0
- package/tests/webrtc/signaling.test.js +251 -0
- package/tests/webrtc/turn.test.js +256 -0
- package/types/collection.d.ts +383 -383
- package/types/component.d.ts +186 -186
- package/types/errors.d.ts +135 -135
- package/types/http.d.ts +92 -92
- package/types/misc.d.ts +201 -201
- package/types/reactive.d.ts +98 -98
- package/types/router.d.ts +190 -190
- package/types/ssr.d.ts +102 -102
- package/types/store.d.ts +146 -146
- package/types/utils.d.ts +245 -245
- package/types/webrtc.d.ts +653 -0
package/cli/commands/create.js
CHANGED
|
@@ -1,121 +1,178 @@
|
|
|
1
|
-
// cli/commands/create.js - scaffold a new zQuery project
|
|
2
|
-
//
|
|
3
|
-
// Templates live in cli/scaffold/<variant>/ (default or minimal).
|
|
4
|
-
// Reads template files, replaces {{NAME}} with the project name,
|
|
5
|
-
// and writes them into the target directory.
|
|
6
|
-
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const { execSync, spawn } = require('child_process');
|
|
10
|
-
const { flag } = require('../args');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Recursively collect every file under `dir`, returning paths relative to `dir`.
|
|
14
|
-
*/
|
|
15
|
-
function walkDir(dir, prefix = '') {
|
|
16
|
-
const entries = [];
|
|
17
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
18
|
-
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
19
|
-
if (entry.isDirectory()) {
|
|
20
|
-
entries.push(...walkDir(path.join(dir, entry.name), rel));
|
|
21
|
-
} else {
|
|
22
|
-
entries.push(rel);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return entries;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function createProject(args) {
|
|
29
|
-
// First positional arg after "create" is the target dir (skip flags)
|
|
30
|
-
const dirArg = args.slice(1).find(a => !a.startsWith('-'));
|
|
31
|
-
const target = dirArg ? path.resolve(dirArg) : process.cwd();
|
|
32
|
-
const name = path.basename(target);
|
|
33
|
-
|
|
34
|
-
// Determine scaffold variant: --minimal / -m or --ssr / -s or default
|
|
35
|
-
const variant = flag('minimal', 'm')
|
|
36
|
-
: flag('ssr', 's')
|
|
37
|
-
:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
console.error(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
console.log(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
fs.
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
// cli/commands/create.js - scaffold a new zQuery project
|
|
2
|
+
//
|
|
3
|
+
// Templates live in cli/scaffold/<variant>/ (default or minimal).
|
|
4
|
+
// Reads template files, replaces {{NAME}} with the project name,
|
|
5
|
+
// and writes them into the target directory.
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { execSync, spawn } = require('child_process');
|
|
10
|
+
const { flag } = require('../args');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Recursively collect every file under `dir`, returning paths relative to `dir`.
|
|
14
|
+
*/
|
|
15
|
+
function walkDir(dir, prefix = '') {
|
|
16
|
+
const entries = [];
|
|
17
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
18
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
19
|
+
if (entry.isDirectory()) {
|
|
20
|
+
entries.push(...walkDir(path.join(dir, entry.name), rel));
|
|
21
|
+
} else {
|
|
22
|
+
entries.push(rel);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return entries;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createProject(args) {
|
|
29
|
+
// First positional arg after "create" is the target dir (skip flags)
|
|
30
|
+
const dirArg = args.slice(1).find(a => !a.startsWith('-'));
|
|
31
|
+
const target = dirArg ? path.resolve(dirArg) : process.cwd();
|
|
32
|
+
const name = path.basename(target);
|
|
33
|
+
|
|
34
|
+
// Determine scaffold variant: --minimal / -m or --ssr / -s or --webrtc-demo / -w or default
|
|
35
|
+
const variant = flag('minimal', 'm') ? 'minimal'
|
|
36
|
+
: flag('ssr', 's') ? 'ssr'
|
|
37
|
+
: flag('webrtc-demo', 'w') ? 'webrtc'
|
|
38
|
+
: 'default';
|
|
39
|
+
|
|
40
|
+
// Guard: refuse to overwrite existing files
|
|
41
|
+
const checkFiles = ['index.html', 'global.css', 'app', 'assets'];
|
|
42
|
+
if (variant === 'ssr' || variant === 'webrtc') checkFiles.push('server');
|
|
43
|
+
const conflicts = checkFiles.filter(f =>
|
|
44
|
+
fs.existsSync(path.join(target, f))
|
|
45
|
+
);
|
|
46
|
+
if (conflicts.length) {
|
|
47
|
+
console.error(`\n ✗ Directory already contains: ${conflicts.join(', ')}`);
|
|
48
|
+
console.error(` Aborting to avoid overwriting existing files.\n`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log(`\n zQuery - Create Project (${variant})\n`);
|
|
53
|
+
console.log(` Scaffolding into ${target}\n`);
|
|
54
|
+
|
|
55
|
+
// Resolve the scaffold template directory for the chosen variant
|
|
56
|
+
const scaffoldDir = path.resolve(__dirname, '..', 'scaffold', variant);
|
|
57
|
+
|
|
58
|
+
if (!fs.existsSync(scaffoldDir)) {
|
|
59
|
+
console.error(`\n ✗ Scaffold variant "${variant}" not found.\n`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Walk the scaffold directory and copy each file
|
|
64
|
+
const templateFiles = walkDir(scaffoldDir);
|
|
65
|
+
|
|
66
|
+
for (const rel of templateFiles) {
|
|
67
|
+
const src = path.join(scaffoldDir, rel);
|
|
68
|
+
let content = fs.readFileSync(src, 'utf-8');
|
|
69
|
+
|
|
70
|
+
// Replace the {{NAME}} placeholder with the actual project name
|
|
71
|
+
content = content.replace(/\{\{NAME\}\}/g, name);
|
|
72
|
+
|
|
73
|
+
const dest = path.join(target, rel);
|
|
74
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
75
|
+
fs.writeFileSync(dest, content, 'utf-8');
|
|
76
|
+
console.log(` ✓ ${rel}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const devCmd = `npx zquery dev${target !== process.cwd() ? ` ${dirArg}` : ''}`;
|
|
80
|
+
|
|
81
|
+
// Copy zquery.min.js from the package's pre-built dist into the project root
|
|
82
|
+
// so file:// previews and the dev/SSR servers all serve the same minified
|
|
83
|
+
// bundle that ships with the installed zero-query package. The dev server
|
|
84
|
+
// also intercepts requests for "zquery.min.js" and will fall back to the
|
|
85
|
+
// package copy if the file is missing, so this is a convenience for direct
|
|
86
|
+
// file access (Open in Browser, etc.).
|
|
87
|
+
{
|
|
88
|
+
const zqRoot = path.resolve(__dirname, '..', '..');
|
|
89
|
+
const zqMin = path.join(zqRoot, 'dist', 'zquery.min.js');
|
|
90
|
+
if (fs.existsSync(zqMin)) {
|
|
91
|
+
fs.copyFileSync(zqMin, path.join(target, 'zquery.min.js'));
|
|
92
|
+
console.log(` ✓ zquery.min.js`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (variant === 'ssr') {
|
|
97
|
+
console.log(`\n Installing dependencies...\n`);
|
|
98
|
+
// Install zero-query from the same package that provides this CLI
|
|
99
|
+
// (works both in local dev and when installed from npm)
|
|
100
|
+
const zqRoot = path.resolve(__dirname, '..', '..');
|
|
101
|
+
try {
|
|
102
|
+
execSync(`npm install "${zqRoot}"`, { cwd: target, stdio: 'inherit' });
|
|
103
|
+
} catch {
|
|
104
|
+
console.error(`\n ✗ npm install failed. Run it manually:\n\n cd ${dirArg || '.'}\n npm install\n node server/index.js\n`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Copy zquery.min.js into the project root so the SSR server can serve it
|
|
109
|
+
const zqMin = path.join(target, 'node_modules', 'zero-query', 'dist', 'zquery.min.js');
|
|
110
|
+
if (fs.existsSync(zqMin)) {
|
|
111
|
+
fs.copyFileSync(zqMin, path.join(target, 'zquery.min.js'));
|
|
112
|
+
console.log(` ✓ zquery.min.js`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.log(`\n Starting SSR server...\n`);
|
|
116
|
+
const child = spawn('node', ['server/index.js'], { cwd: target, stdio: 'inherit' });
|
|
117
|
+
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
const open = process.platform === 'win32' ? 'start'
|
|
120
|
+
: process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
121
|
+
try { execSync(`${open} http://localhost:3000`, { stdio: 'ignore' }); } catch {}
|
|
122
|
+
}, 500);
|
|
123
|
+
|
|
124
|
+
process.on('SIGINT', () => { child.kill(); process.exit(); });
|
|
125
|
+
process.on('SIGTERM', () => { child.kill(); process.exit(); });
|
|
126
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
127
|
+
return; // keep process alive for the server
|
|
128
|
+
} else if (variant === 'webrtc') {
|
|
129
|
+
console.log(`\n Installing dependencies...\n`);
|
|
130
|
+
// Install zero-query from the same package that provides this CLI so
|
|
131
|
+
// local-dev and published-npm both work. Dev deps (@zero-server/sdk +
|
|
132
|
+
// @zero-server/webrtc) are declared in the scaffold's package.json and
|
|
133
|
+
// get installed by the same `npm install`. The server has its own
|
|
134
|
+
// install-prompt as a safety net.
|
|
135
|
+
const zqRoot = path.resolve(__dirname, '..', '..');
|
|
136
|
+
try {
|
|
137
|
+
execSync(`npm install "${zqRoot}"`, { cwd: target, stdio: 'inherit' });
|
|
138
|
+
execSync(`npm install`, { cwd: target, stdio: 'inherit' });
|
|
139
|
+
} catch {
|
|
140
|
+
console.error(`\n ✗ npm install failed. Run it manually:\n\n cd ${dirArg || '.'}\n npm install\n node server/index.js\n`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Refresh zquery.min.js from the installed package (preferred over the
|
|
145
|
+
// pre-copied one above so post-install rebuilds win).
|
|
146
|
+
const zqMin = path.join(target, 'node_modules', 'zero-query', 'dist', 'zquery.min.js');
|
|
147
|
+
if (fs.existsSync(zqMin)) {
|
|
148
|
+
fs.copyFileSync(zqMin, path.join(target, 'zquery.min.js'));
|
|
149
|
+
console.log(` ✓ zquery.min.js`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
console.log(`
|
|
153
|
+
Done! The WebRTC demo needs the signaling server running. In one terminal:
|
|
154
|
+
|
|
155
|
+
cd ${dirArg || '.'}
|
|
156
|
+
node server/index.js
|
|
157
|
+
|
|
158
|
+
Then in another terminal serve the static client:
|
|
159
|
+
|
|
160
|
+
${devCmd}
|
|
161
|
+
|
|
162
|
+
Notes:
|
|
163
|
+
- Camera, microphone, and screen-share are OFF by default. Users opt-in
|
|
164
|
+
from inside the room.
|
|
165
|
+
- Set WEBRTC_JWT_SECRET to enforce signed join tokens.
|
|
166
|
+
- Set TURN_SECRET + TURN_URLS to issue time-limited TURN credentials.
|
|
167
|
+
`);
|
|
168
|
+
return;
|
|
169
|
+
} else {
|
|
170
|
+
console.log(`
|
|
171
|
+
Done! Next steps:
|
|
172
|
+
|
|
173
|
+
${devCmd}
|
|
174
|
+
`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
module.exports = createProject;
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cli/commands/dev/devtools/index.js - DevTools HTML assembler
|
|
3
|
-
*
|
|
4
|
-
* Reads CSS, HTML, and JS partials from this folder and concatenates them
|
|
5
|
-
* into a single self-contained HTML page served at /_devtools.
|
|
6
|
-
*
|
|
7
|
-
* Communication:
|
|
8
|
-
* - window.opener: direct DOM access (same-origin popup)
|
|
9
|
-
* - BroadcastChannel('__zq_devtools'): cross-tab fallback
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
const { readFileSync } = require('fs');
|
|
15
|
-
const { join } = require('path');
|
|
16
|
-
|
|
17
|
-
const dir = __dirname;
|
|
18
|
-
const read = (f) => readFileSync(join(dir, f), 'utf8');
|
|
19
|
-
|
|
20
|
-
const css = read('styles.css');
|
|
21
|
-
const html = read('panel.html');
|
|
22
|
-
|
|
23
|
-
const jsFiles = [
|
|
24
|
-
'js/core.js',
|
|
25
|
-
'js/tabs.js',
|
|
26
|
-
'js/source.js',
|
|
27
|
-
'js/elements.js',
|
|
28
|
-
'js/network.js',
|
|
29
|
-
'js/components.js',
|
|
30
|
-
'js/performance.js',
|
|
31
|
-
'js/router.js',
|
|
32
|
-
'js/stats.js'
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const js = jsFiles.map(read).join('\n\n');
|
|
36
|
-
|
|
37
|
-
module.exports = `<!DOCTYPE html>
|
|
38
|
-
<html lang="en">
|
|
39
|
-
<head>
|
|
40
|
-
<meta charset="UTF-8">
|
|
41
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
42
|
-
<title>zQuery DevTools</title>
|
|
43
|
-
<style>
|
|
44
|
-
${css}
|
|
45
|
-
</style>
|
|
46
|
-
</head>
|
|
47
|
-
<body>
|
|
48
|
-
${html}
|
|
49
|
-
<script>
|
|
50
|
-
(function() {
|
|
51
|
-
'use strict';
|
|
52
|
-
${js}
|
|
53
|
-
})();
|
|
54
|
-
</script>
|
|
55
|
-
</body>
|
|
56
|
-
</html>`;
|
|
1
|
+
/**
|
|
2
|
+
* cli/commands/dev/devtools/index.js - DevTools HTML assembler
|
|
3
|
+
*
|
|
4
|
+
* Reads CSS, HTML, and JS partials from this folder and concatenates them
|
|
5
|
+
* into a single self-contained HTML page served at /_devtools.
|
|
6
|
+
*
|
|
7
|
+
* Communication:
|
|
8
|
+
* - window.opener: direct DOM access (same-origin popup)
|
|
9
|
+
* - BroadcastChannel('__zq_devtools'): cross-tab fallback
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
const { readFileSync } = require('fs');
|
|
15
|
+
const { join } = require('path');
|
|
16
|
+
|
|
17
|
+
const dir = __dirname;
|
|
18
|
+
const read = (f) => readFileSync(join(dir, f), 'utf8');
|
|
19
|
+
|
|
20
|
+
const css = read('styles.css');
|
|
21
|
+
const html = read('panel.html');
|
|
22
|
+
|
|
23
|
+
const jsFiles = [
|
|
24
|
+
'js/core.js',
|
|
25
|
+
'js/tabs.js',
|
|
26
|
+
'js/source.js',
|
|
27
|
+
'js/elements.js',
|
|
28
|
+
'js/network.js',
|
|
29
|
+
'js/components.js',
|
|
30
|
+
'js/performance.js',
|
|
31
|
+
'js/router.js',
|
|
32
|
+
'js/stats.js'
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const js = jsFiles.map(read).join('\n\n');
|
|
36
|
+
|
|
37
|
+
module.exports = `<!DOCTYPE html>
|
|
38
|
+
<html lang="en">
|
|
39
|
+
<head>
|
|
40
|
+
<meta charset="UTF-8">
|
|
41
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
42
|
+
<title>zQuery DevTools</title>
|
|
43
|
+
<style>
|
|
44
|
+
${css}
|
|
45
|
+
</style>
|
|
46
|
+
</head>
|
|
47
|
+
<body>
|
|
48
|
+
${html}
|
|
49
|
+
<script>
|
|
50
|
+
(function() {
|
|
51
|
+
'use strict';
|
|
52
|
+
${js}
|
|
53
|
+
})();
|
|
54
|
+
</script>
|
|
55
|
+
</body>
|
|
56
|
+
</html>`;
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
// ===================================================================
|
|
2
|
-
// Components
|
|
3
|
-
// ===================================================================
|
|
4
|
-
function renderComponents() {
|
|
5
|
-
var list = document.getElementById('comp-list');
|
|
6
|
-
if (!targetWin || !targetWin.$) {
|
|
7
|
-
list.innerHTML = '<div class="empty-state">Waiting for zQuery to load...</div>';
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
var $ = targetWin.$;
|
|
11
|
-
var html = '';
|
|
12
|
-
|
|
13
|
-
// Iterate mounted components if components registry exists
|
|
14
|
-
if ($ && typeof $.components === 'function') {
|
|
15
|
-
var names = Object.keys($.components());
|
|
16
|
-
if (!names.length) {
|
|
17
|
-
list.innerHTML = '<div class="empty-state">No components registered</div>';
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
for (var n = 0; n < names.length; n++) {
|
|
21
|
-
var name = names[n];
|
|
22
|
-
// Find mounted instances (exclude scoped <style> tags that carry data-zq-component)
|
|
23
|
-
var hosts = targetDoc.querySelectorAll(name + ':not(style)');
|
|
24
|
-
html += '<div class="comp-card">';
|
|
25
|
-
html += '<div class="comp-name"><' + name + '></div>';
|
|
26
|
-
html += '<div class="comp-host">' + hosts.length + ' instance' + (hosts.length !== 1 ? 's' : '') + ' mounted</div>';
|
|
27
|
-
hosts.forEach(function(host) {
|
|
28
|
-
try {
|
|
29
|
-
var inst = $.getInstance(host);
|
|
30
|
-
if (inst && inst.state) {
|
|
31
|
-
html += '<div class="comp-state">';
|
|
32
|
-
var keys = Object.keys(inst.state);
|
|
33
|
-
for (var k = 0; k < keys.length; k++) {
|
|
34
|
-
var key = keys[k];
|
|
35
|
-
var val = inst.state[key];
|
|
36
|
-
var display = typeof val === 'object' ? JSON.stringify(val) : String(val);
|
|
37
|
-
if (display.length > 80) display = display.slice(0, 80) + '...';
|
|
38
|
-
html += '<div class="detail-row"><span class="comp-state-key">' + esc(key) + '</span><span class="comp-state-val">' + esc(display) + '</span></div>';
|
|
39
|
-
}
|
|
40
|
-
html += '</div>';
|
|
41
|
-
}
|
|
42
|
-
} catch(e) {}
|
|
43
|
-
});
|
|
44
|
-
html += '</div>';
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (!html) html = '<div class="empty-state">No components found</div>';
|
|
48
|
-
list.innerHTML = html;
|
|
49
|
-
}
|
|
1
|
+
// ===================================================================
|
|
2
|
+
// Components
|
|
3
|
+
// ===================================================================
|
|
4
|
+
function renderComponents() {
|
|
5
|
+
var list = document.getElementById('comp-list');
|
|
6
|
+
if (!targetWin || !targetWin.$) {
|
|
7
|
+
list.innerHTML = '<div class="empty-state">Waiting for zQuery to load...</div>';
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
var $ = targetWin.$;
|
|
11
|
+
var html = '';
|
|
12
|
+
|
|
13
|
+
// Iterate mounted components if components registry exists
|
|
14
|
+
if ($ && typeof $.components === 'function') {
|
|
15
|
+
var names = Object.keys($.components());
|
|
16
|
+
if (!names.length) {
|
|
17
|
+
list.innerHTML = '<div class="empty-state">No components registered</div>';
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (var n = 0; n < names.length; n++) {
|
|
21
|
+
var name = names[n];
|
|
22
|
+
// Find mounted instances (exclude scoped <style> tags that carry data-zq-component)
|
|
23
|
+
var hosts = targetDoc.querySelectorAll(name + ':not(style)');
|
|
24
|
+
html += '<div class="comp-card">';
|
|
25
|
+
html += '<div class="comp-name"><' + name + '></div>';
|
|
26
|
+
html += '<div class="comp-host">' + hosts.length + ' instance' + (hosts.length !== 1 ? 's' : '') + ' mounted</div>';
|
|
27
|
+
hosts.forEach(function(host) {
|
|
28
|
+
try {
|
|
29
|
+
var inst = $.getInstance(host);
|
|
30
|
+
if (inst && inst.state) {
|
|
31
|
+
html += '<div class="comp-state">';
|
|
32
|
+
var keys = Object.keys(inst.state);
|
|
33
|
+
for (var k = 0; k < keys.length; k++) {
|
|
34
|
+
var key = keys[k];
|
|
35
|
+
var val = inst.state[key];
|
|
36
|
+
var display = typeof val === 'object' ? JSON.stringify(val) : String(val);
|
|
37
|
+
if (display.length > 80) display = display.slice(0, 80) + '...';
|
|
38
|
+
html += '<div class="detail-row"><span class="comp-state-key">' + esc(key) + '</span><span class="comp-state-val">' + esc(display) + '</span></div>';
|
|
39
|
+
}
|
|
40
|
+
html += '</div>';
|
|
41
|
+
}
|
|
42
|
+
} catch(e) {}
|
|
43
|
+
});
|
|
44
|
+
html += '</div>';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!html) html = '<div class="empty-state">No components found</div>';
|
|
48
|
+
list.innerHTML = html;
|
|
49
|
+
}
|