zero-query 1.0.9 → 1.2.0
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 +443 -0
- package/cli/commands/build.js +254 -216
- package/cli/commands/bundle.js +1228 -1183
- package/cli/commands/create.js +137 -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 -167
- 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 +295 -0
- package/cli/scaffold/webrtc/app/lib/room.js +252 -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/utils.js +305 -287
- package/dist/API.md +7264 -0
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +10313 -6252
- package/dist/zquery.min.js +8 -601
- package/index.d.ts +570 -365
- package/index.js +311 -232
- package/package.json +76 -69
- package/src/component.js +1709 -1454
- package/src/core.js +921 -921
- package/src/diff.js +497 -497
- package/src/errors.js +209 -209
- package/src/expression.js +922 -922
- package/src/http.js +242 -242
- package/src/package.json +1 -1
- package/src/reactive.js +255 -254
- package/src/router.js +843 -773
- package/src/ssr.js +418 -418
- package/src/store.js +318 -272
- package/src/utils.js +515 -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/cli.test.js +1136 -1023
- package/tests/compare.test.js +497 -0
- package/tests/component.test.js +3969 -3938
- package/tests/core.test.js +1910 -1910
- package/tests/dev-server.test.js +489 -0
- package/tests/diff.test.js +1416 -1416
- package/tests/docs.test.js +1664 -0
- package/tests/electron-features.test.js +864 -0
- package/tests/errors.test.js +619 -619
- package/tests/expression.test.js +1056 -1056
- package/tests/http.test.js +648 -648
- package/tests/reactive.test.js +819 -819
- package/tests/router.test.js +2327 -2327
- package/tests/ssr.test.js +870 -870
- package/tests/store.test.js +830 -830
- package/tests/test-minifier.js +153 -153
- package/tests/test-ssr.js +27 -27
- package/tests/utils.test.js +1377 -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 -145
- package/types/utils.d.ts +245 -245
- package/types/webrtc.d.ts +653 -0
package/cli/index.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* zQuery CLI - entry point
|
|
5
|
-
*
|
|
6
|
-
* Dispatches to the appropriate command module under cli/commands/.
|
|
7
|
-
* Run `zquery --help` for full usage information.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const { join } = require('path');
|
|
11
|
-
const { watch } = require('fs');
|
|
12
|
-
|
|
13
|
-
const { args, flag } = require('./args');
|
|
14
|
-
const buildLibrary = require('./commands/build');
|
|
15
|
-
const bundleApp = require('./commands/bundle');
|
|
16
|
-
const devServer = require('./commands/dev');
|
|
17
|
-
const createProject = require('./commands/create');
|
|
18
|
-
const showHelp = require('./help');
|
|
19
|
-
|
|
20
|
-
const command = args[0];
|
|
21
|
-
|
|
22
|
-
if (!command || command === '--help' || command === '-h' || command === 'help') {
|
|
23
|
-
showHelp();
|
|
24
|
-
} else if (command === 'create') {
|
|
25
|
-
createProject(args);
|
|
26
|
-
} else if (command === 'build') {
|
|
27
|
-
console.log('\n zQuery Library Build\n');
|
|
28
|
-
buildLibrary();
|
|
29
|
-
|
|
30
|
-
if (flag('watch', 'w')) {
|
|
31
|
-
console.log(' Watching src/ for changes...\n');
|
|
32
|
-
const srcDir = join(process.cwd(), 'src');
|
|
33
|
-
let debounce;
|
|
34
|
-
|
|
35
|
-
function rebuild() {
|
|
36
|
-
clearTimeout(debounce);
|
|
37
|
-
debounce = setTimeout(() => {
|
|
38
|
-
console.log(' Rebuilding...\n');
|
|
39
|
-
try { buildLibrary(); } catch (e) { console.error(e.message); }
|
|
40
|
-
}, 200);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
watch(srcDir, { recursive: true }, rebuild);
|
|
44
|
-
watch(join(process.cwd(), 'index.js'), rebuild);
|
|
45
|
-
}
|
|
46
|
-
} else if (command === 'bundle') {
|
|
47
|
-
bundleApp();
|
|
48
|
-
} else if (command === 'dev') {
|
|
49
|
-
devServer();
|
|
50
|
-
} else {
|
|
51
|
-
console.error(`\n Unknown command: ${command}\n Run "zquery --help" for usage.\n`);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* zQuery CLI - entry point
|
|
5
|
+
*
|
|
6
|
+
* Dispatches to the appropriate command module under cli/commands/.
|
|
7
|
+
* Run `zquery --help` for full usage information.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { join } = require('path');
|
|
11
|
+
const { watch } = require('fs');
|
|
12
|
+
|
|
13
|
+
const { args, flag } = require('./args');
|
|
14
|
+
const buildLibrary = require('./commands/build');
|
|
15
|
+
const bundleApp = require('./commands/bundle');
|
|
16
|
+
const devServer = require('./commands/dev');
|
|
17
|
+
const createProject = require('./commands/create');
|
|
18
|
+
const showHelp = require('./help');
|
|
19
|
+
|
|
20
|
+
const command = args[0];
|
|
21
|
+
|
|
22
|
+
if (!command || command === '--help' || command === '-h' || command === 'help') {
|
|
23
|
+
showHelp();
|
|
24
|
+
} else if (command === 'create') {
|
|
25
|
+
createProject(args);
|
|
26
|
+
} else if (command === 'build') {
|
|
27
|
+
console.log('\n zQuery Library Build\n');
|
|
28
|
+
buildLibrary();
|
|
29
|
+
|
|
30
|
+
if (flag('watch', 'w')) {
|
|
31
|
+
console.log(' Watching src/ for changes...\n');
|
|
32
|
+
const srcDir = join(process.cwd(), 'src');
|
|
33
|
+
let debounce;
|
|
34
|
+
|
|
35
|
+
function rebuild() {
|
|
36
|
+
clearTimeout(debounce);
|
|
37
|
+
debounce = setTimeout(() => {
|
|
38
|
+
console.log(' Rebuilding...\n');
|
|
39
|
+
try { buildLibrary(); } catch (e) { console.error(e.message); }
|
|
40
|
+
}, 200);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
watch(srcDir, { recursive: true }, rebuild);
|
|
44
|
+
watch(join(process.cwd(), 'index.js'), rebuild);
|
|
45
|
+
}
|
|
46
|
+
} else if (command === 'bundle') {
|
|
47
|
+
bundleApp();
|
|
48
|
+
} else if (command === 'dev') {
|
|
49
|
+
devServer();
|
|
50
|
+
} else {
|
|
51
|
+
console.error(`\n Unknown command: ${command}\n Run "zquery --help" for usage.\n`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Tony Wiedman "molex"
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tony Wiedman "molex"
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
// app.js - Application entry point
|
|
2
|
-
//
|
|
3
|
-
// Bootstraps the app: imports components, sets up routing,
|
|
4
|
-
// wires the responsive sidebar, and connects the store.
|
|
5
|
-
//
|
|
6
|
-
// Key APIs used:
|
|
7
|
-
// $.router - SPA navigation (history mode)
|
|
8
|
-
// $.ready - run after DOM is loaded
|
|
9
|
-
// $.bus - event bus (toast notifications, contact card)
|
|
10
|
-
// $.on - global delegated event listeners
|
|
11
|
-
// $.storage - localStorage wrapper
|
|
12
|
-
// $.create - create DOM elements
|
|
13
|
-
|
|
14
|
-
import './store.js';
|
|
15
|
-
import './components/home.js';
|
|
16
|
-
import './components/counter.js';
|
|
17
|
-
import './components/todos.js';
|
|
18
|
-
import './components/api-demo.js';
|
|
19
|
-
import './components/playground/playground.js';
|
|
20
|
-
import './components/toolkit/toolkit.js';
|
|
21
|
-
import './components/about.js';
|
|
22
|
-
import './components/contact-card.js';
|
|
23
|
-
import './components/contacts/contacts.js';
|
|
24
|
-
import './components/not-found.js';
|
|
25
|
-
import { routes } from './routes.js';
|
|
26
|
-
|
|
27
|
-
// ---------------------------------------------------------------------------
|
|
28
|
-
// Router - SPA navigation with history mode
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
const router = $.router({
|
|
31
|
-
routes,
|
|
32
|
-
fallback: 'not-found',
|
|
33
|
-
mode: 'history'
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Post-navigation hook - track page views on every navigation
|
|
37
|
-
router.afterEach((to) => {
|
|
38
|
-
const store = $.getStore('main');
|
|
39
|
-
if (store) store.dispatch('incrementVisits');
|
|
40
|
-
console.log('📊 Navigated to:', to.path);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Highlight the active nav link on every route change
|
|
44
|
-
router.onChange((to) => {
|
|
45
|
-
// Close mobile menu on navigate
|
|
46
|
-
closeMobileMenu();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// Responsive sidebar toggle
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
const $sidebar = $('#sidebar');
|
|
53
|
-
const $overlay = $('#overlay');
|
|
54
|
-
const $toggle = $('#menu-toggle');
|
|
55
|
-
|
|
56
|
-
function toggleMobileMenu(open) {
|
|
57
|
-
$sidebar.toggleClass('open', open);
|
|
58
|
-
$overlay.toggleClass('visible', open);
|
|
59
|
-
$toggle.toggleClass('active', open);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function closeMobileMenu() { toggleMobileMenu(false); }
|
|
63
|
-
|
|
64
|
-
// $.on - global delegated event listeners
|
|
65
|
-
$.on('click', '#menu-toggle', () => toggleMobileMenu(!$sidebar.hasClass('open')));
|
|
66
|
-
$.on('click', '#overlay', closeMobileMenu);
|
|
67
|
-
|
|
68
|
-
// Close sidebar on Escape key - using $.on direct (no selector needed)
|
|
69
|
-
$.on('keydown', (e) => {
|
|
70
|
-
if (e.key === 'Escape') closeMobileMenu();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// ---------------------------------------------------------------------------
|
|
74
|
-
// Sidebar stats panel - collapsible, live-updating from $.store
|
|
75
|
-
// Starts expanded by default. Open/closed state saved via $.storage.
|
|
76
|
-
// ---------------------------------------------------------------------------
|
|
77
|
-
$.on('click', '#stats-toggle', () => {
|
|
78
|
-
const $body = $('#stats-body');
|
|
79
|
-
const $arrow = $('#stats-arrow');
|
|
80
|
-
if (!$body.length) return;
|
|
81
|
-
const open = $body.css('display') !== 'none';
|
|
82
|
-
open ? $body.hide() : $body.show();
|
|
83
|
-
$arrow.toggleClass('open', !open);
|
|
84
|
-
$.storage.set('statsOpen', !open);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
function updateSidebarStats() {
|
|
88
|
-
const store = $.getStore('main');
|
|
89
|
-
if (!store) return;
|
|
90
|
-
$('#ss-visits').text(store.state.visits);
|
|
91
|
-
$('#ss-todos').text(store.getters.todoCount);
|
|
92
|
-
$('#ss-pending').text(store.getters.pendingCount);
|
|
93
|
-
$('#ss-done').text(store.getters.doneCount);
|
|
94
|
-
$('#ss-contacts').text(store.getters.contactCount);
|
|
95
|
-
$('#ss-favorites').text(store.getters.favoriteCount);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
// Sidebar contacts - live status indicators from $.store
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
function updateSidebarContacts() {
|
|
102
|
-
const store = $.getStore('main');
|
|
103
|
-
if (!store) return;
|
|
104
|
-
const $list = $('#sc-list');
|
|
105
|
-
if (!$list.length) return;
|
|
106
|
-
|
|
107
|
-
const sorted = [...store.state.contacts].sort((a, b) => {
|
|
108
|
-
const order = { online: 0, away: 1, offline: 2 };
|
|
109
|
-
return (order[a.status] ?? 3) - (order[b.status] ?? 3);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const html = sorted.map(c => {
|
|
113
|
-
const hue = (c.name.charCodeAt(0) * 7) % 360;
|
|
114
|
-
const initial = $.escapeHtml(c.name.charAt(0).toUpperCase());
|
|
115
|
-
const name = $.escapeHtml(c.name);
|
|
116
|
-
return `<div class="sc-item" data-contact-id="${c.id}">
|
|
117
|
-
<span class="sc-avatar" style="background:hsl(${hue},55%,42%)">${initial}</span>
|
|
118
|
-
<span class="sc-dot sc-dot-${c.status}"></span>
|
|
119
|
-
<span class="sc-name">${name}</span>
|
|
120
|
-
</div>`;
|
|
121
|
-
}).join('');
|
|
122
|
-
|
|
123
|
-
$list.html(html);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// ---------------------------------------------------------------------------
|
|
127
|
-
// Toast notification system via $.bus (event bus)
|
|
128
|
-
// ---------------------------------------------------------------------------
|
|
129
|
-
// Any component can emit: $.bus.emit('toast', { message, type })
|
|
130
|
-
// Types: 'success', 'error', 'info'
|
|
131
|
-
$.bus.on('toast', ({ message, type = 'info' }) => {
|
|
132
|
-
const toast = $.create('div')
|
|
133
|
-
.addClass('toast', `toast-${type}`)
|
|
134
|
-
.text(message)
|
|
135
|
-
.appendTo('#toasts');
|
|
136
|
-
// Auto-remove after 3 seconds
|
|
137
|
-
setTimeout(() => {
|
|
138
|
-
toast.addClass('toast-exit');
|
|
139
|
-
setTimeout(() => toast.remove(), 300);
|
|
140
|
-
}, 3000);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// ---------------------------------------------------------------------------
|
|
144
|
-
// On DOM ready - final setup
|
|
145
|
-
// ---------------------------------------------------------------------------
|
|
146
|
-
$.ready(() => {
|
|
147
|
-
// Display version in the sidebar footer
|
|
148
|
-
$('#nav-version').text('v' + $.version);
|
|
149
|
-
|
|
150
|
-
// Theme: restore saved preference or auto-detect from system
|
|
151
|
-
const saved = $.storage.get('theme'); // 'dark' | 'light' | 'system' | null
|
|
152
|
-
const preference = saved || 'system';
|
|
153
|
-
applyTheme(preference);
|
|
154
|
-
|
|
155
|
-
// Listen for OS color-scheme changes (only applies when preference is 'system')
|
|
156
|
-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
|
157
|
-
const current = $.storage.get('theme') || 'system';
|
|
158
|
-
if (current === 'system') applyTheme('system');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Highlight the active link on initial load is handled by z-active-route
|
|
162
|
-
|
|
163
|
-
console.log('⚡ {{NAME}} - powered by zQuery v' + $.version);
|
|
164
|
-
|
|
165
|
-
// Stats panel: restore open/closed from $.storage (defaults to open)
|
|
166
|
-
const statsOpen = $.storage.get('statsOpen');
|
|
167
|
-
if (statsOpen === false) {
|
|
168
|
-
$('#stats-body').hide();
|
|
169
|
-
$('#stats-arrow').removeClass('open');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Sidebar contact click - open the global contact card overlay
|
|
173
|
-
$('#sc-list').on('click', '.sc-item', (e) => {
|
|
174
|
-
const item = e.target.closest('.sc-item');
|
|
175
|
-
if (!item) return;
|
|
176
|
-
const id = Number(item.dataset.contactId);
|
|
177
|
-
if (id) $.bus.emit('openContact', id);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
// Initial sidebar stats + contacts + live subscription
|
|
181
|
-
updateSidebarStats();
|
|
182
|
-
updateSidebarContacts();
|
|
183
|
-
const store = $.getStore('main');
|
|
184
|
-
if (store) {
|
|
185
|
-
store.subscribe(updateSidebarStats);
|
|
186
|
-
store.subscribe(updateSidebarContacts);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Mount any components outside the router outlet (e.g. <contact-card>)
|
|
190
|
-
$.mountAll();
|
|
191
|
-
|
|
192
|
-
console.log('⚡ {{NAME}} - powered by zQuery v' + $.version);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// ---------------------------------------------------------------------------
|
|
196
|
-
// Theme helper - resolves 'system' to actual dark/light and applies it
|
|
197
|
-
// ---------------------------------------------------------------------------
|
|
198
|
-
function applyTheme(preference) {
|
|
199
|
-
let resolved = preference;
|
|
200
|
-
if (preference === 'system') {
|
|
201
|
-
resolved = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
202
|
-
}
|
|
203
|
-
$('html').attr('data-theme', resolved);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Expose globally so components can call it
|
|
207
|
-
window.__applyTheme = applyTheme;
|
|
1
|
+
// app.js - Application entry point
|
|
2
|
+
//
|
|
3
|
+
// Bootstraps the app: imports components, sets up routing,
|
|
4
|
+
// wires the responsive sidebar, and connects the store.
|
|
5
|
+
//
|
|
6
|
+
// Key APIs used:
|
|
7
|
+
// $.router - SPA navigation (history mode)
|
|
8
|
+
// $.ready - run after DOM is loaded
|
|
9
|
+
// $.bus - event bus (toast notifications, contact card)
|
|
10
|
+
// $.on - global delegated event listeners
|
|
11
|
+
// $.storage - localStorage wrapper
|
|
12
|
+
// $.create - create DOM elements
|
|
13
|
+
|
|
14
|
+
import './store.js';
|
|
15
|
+
import './components/home.js';
|
|
16
|
+
import './components/counter.js';
|
|
17
|
+
import './components/todos.js';
|
|
18
|
+
import './components/api-demo.js';
|
|
19
|
+
import './components/playground/playground.js';
|
|
20
|
+
import './components/toolkit/toolkit.js';
|
|
21
|
+
import './components/about.js';
|
|
22
|
+
import './components/contact-card.js';
|
|
23
|
+
import './components/contacts/contacts.js';
|
|
24
|
+
import './components/not-found.js';
|
|
25
|
+
import { routes } from './routes.js';
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Router - SPA navigation with history mode
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
const router = $.router({
|
|
31
|
+
routes,
|
|
32
|
+
fallback: 'not-found',
|
|
33
|
+
mode: 'history'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Post-navigation hook - track page views on every navigation
|
|
37
|
+
router.afterEach((to) => {
|
|
38
|
+
const store = $.getStore('main');
|
|
39
|
+
if (store) store.dispatch('incrementVisits');
|
|
40
|
+
console.log('📊 Navigated to:', to.path);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Highlight the active nav link on every route change
|
|
44
|
+
router.onChange((to) => {
|
|
45
|
+
// Close mobile menu on navigate
|
|
46
|
+
closeMobileMenu();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Responsive sidebar toggle
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
const $sidebar = $('#sidebar');
|
|
53
|
+
const $overlay = $('#overlay');
|
|
54
|
+
const $toggle = $('#menu-toggle');
|
|
55
|
+
|
|
56
|
+
function toggleMobileMenu(open) {
|
|
57
|
+
$sidebar.toggleClass('open', open);
|
|
58
|
+
$overlay.toggleClass('visible', open);
|
|
59
|
+
$toggle.toggleClass('active', open);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function closeMobileMenu() { toggleMobileMenu(false); }
|
|
63
|
+
|
|
64
|
+
// $.on - global delegated event listeners
|
|
65
|
+
$.on('click', '#menu-toggle', () => toggleMobileMenu(!$sidebar.hasClass('open')));
|
|
66
|
+
$.on('click', '#overlay', closeMobileMenu);
|
|
67
|
+
|
|
68
|
+
// Close sidebar on Escape key - using $.on direct (no selector needed)
|
|
69
|
+
$.on('keydown', (e) => {
|
|
70
|
+
if (e.key === 'Escape') closeMobileMenu();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Sidebar stats panel - collapsible, live-updating from $.store
|
|
75
|
+
// Starts expanded by default. Open/closed state saved via $.storage.
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
$.on('click', '#stats-toggle', () => {
|
|
78
|
+
const $body = $('#stats-body');
|
|
79
|
+
const $arrow = $('#stats-arrow');
|
|
80
|
+
if (!$body.length) return;
|
|
81
|
+
const open = $body.css('display') !== 'none';
|
|
82
|
+
open ? $body.hide() : $body.show();
|
|
83
|
+
$arrow.toggleClass('open', !open);
|
|
84
|
+
$.storage.set('statsOpen', !open);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
function updateSidebarStats() {
|
|
88
|
+
const store = $.getStore('main');
|
|
89
|
+
if (!store) return;
|
|
90
|
+
$('#ss-visits').text(store.state.visits);
|
|
91
|
+
$('#ss-todos').text(store.getters.todoCount);
|
|
92
|
+
$('#ss-pending').text(store.getters.pendingCount);
|
|
93
|
+
$('#ss-done').text(store.getters.doneCount);
|
|
94
|
+
$('#ss-contacts').text(store.getters.contactCount);
|
|
95
|
+
$('#ss-favorites').text(store.getters.favoriteCount);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// Sidebar contacts - live status indicators from $.store
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
function updateSidebarContacts() {
|
|
102
|
+
const store = $.getStore('main');
|
|
103
|
+
if (!store) return;
|
|
104
|
+
const $list = $('#sc-list');
|
|
105
|
+
if (!$list.length) return;
|
|
106
|
+
|
|
107
|
+
const sorted = [...store.state.contacts].sort((a, b) => {
|
|
108
|
+
const order = { online: 0, away: 1, offline: 2 };
|
|
109
|
+
return (order[a.status] ?? 3) - (order[b.status] ?? 3);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const html = sorted.map(c => {
|
|
113
|
+
const hue = (c.name.charCodeAt(0) * 7) % 360;
|
|
114
|
+
const initial = $.escapeHtml(c.name.charAt(0).toUpperCase());
|
|
115
|
+
const name = $.escapeHtml(c.name);
|
|
116
|
+
return `<div class="sc-item" data-contact-id="${c.id}">
|
|
117
|
+
<span class="sc-avatar" style="background:hsl(${hue},55%,42%)">${initial}</span>
|
|
118
|
+
<span class="sc-dot sc-dot-${c.status}"></span>
|
|
119
|
+
<span class="sc-name">${name}</span>
|
|
120
|
+
</div>`;
|
|
121
|
+
}).join('');
|
|
122
|
+
|
|
123
|
+
$list.html(html);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Toast notification system via $.bus (event bus)
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Any component can emit: $.bus.emit('toast', { message, type })
|
|
130
|
+
// Types: 'success', 'error', 'info'
|
|
131
|
+
$.bus.on('toast', ({ message, type = 'info' }) => {
|
|
132
|
+
const toast = $.create('div')
|
|
133
|
+
.addClass('toast', `toast-${type}`)
|
|
134
|
+
.text(message)
|
|
135
|
+
.appendTo('#toasts');
|
|
136
|
+
// Auto-remove after 3 seconds
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
toast.addClass('toast-exit');
|
|
139
|
+
setTimeout(() => toast.remove(), 300);
|
|
140
|
+
}, 3000);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// On DOM ready - final setup
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
$.ready(() => {
|
|
147
|
+
// Display version in the sidebar footer
|
|
148
|
+
$('#nav-version').text('v' + $.version);
|
|
149
|
+
|
|
150
|
+
// Theme: restore saved preference or auto-detect from system
|
|
151
|
+
const saved = $.storage.get('theme'); // 'dark' | 'light' | 'system' | null
|
|
152
|
+
const preference = saved || 'system';
|
|
153
|
+
applyTheme(preference);
|
|
154
|
+
|
|
155
|
+
// Listen for OS color-scheme changes (only applies when preference is 'system')
|
|
156
|
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
|
157
|
+
const current = $.storage.get('theme') || 'system';
|
|
158
|
+
if (current === 'system') applyTheme('system');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Highlight the active link on initial load is handled by z-active-route
|
|
162
|
+
|
|
163
|
+
console.log('⚡ {{NAME}} - powered by zQuery v' + $.version);
|
|
164
|
+
|
|
165
|
+
// Stats panel: restore open/closed from $.storage (defaults to open)
|
|
166
|
+
const statsOpen = $.storage.get('statsOpen');
|
|
167
|
+
if (statsOpen === false) {
|
|
168
|
+
$('#stats-body').hide();
|
|
169
|
+
$('#stats-arrow').removeClass('open');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Sidebar contact click - open the global contact card overlay
|
|
173
|
+
$('#sc-list').on('click', '.sc-item', (e) => {
|
|
174
|
+
const item = e.target.closest('.sc-item');
|
|
175
|
+
if (!item) return;
|
|
176
|
+
const id = Number(item.dataset.contactId);
|
|
177
|
+
if (id) $.bus.emit('openContact', id);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Initial sidebar stats + contacts + live subscription
|
|
181
|
+
updateSidebarStats();
|
|
182
|
+
updateSidebarContacts();
|
|
183
|
+
const store = $.getStore('main');
|
|
184
|
+
if (store) {
|
|
185
|
+
store.subscribe(updateSidebarStats);
|
|
186
|
+
store.subscribe(updateSidebarContacts);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Mount any components outside the router outlet (e.g. <contact-card>)
|
|
190
|
+
$.mountAll();
|
|
191
|
+
|
|
192
|
+
console.log('⚡ {{NAME}} - powered by zQuery v' + $.version);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
// Theme helper - resolves 'system' to actual dark/light and applies it
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
function applyTheme(preference) {
|
|
199
|
+
let resolved = preference;
|
|
200
|
+
if (preference === 'system') {
|
|
201
|
+
resolved = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
202
|
+
}
|
|
203
|
+
$('html').attr('data-theme', resolved);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Expose globally so components can call it
|
|
207
|
+
window.__applyTheme = applyTheme;
|