zero-query 0.3.1 → 0.5.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/README.md +48 -19
- package/cli/args.js +33 -0
- package/cli/commands/build.js +58 -0
- package/cli/commands/bundle.js +687 -0
- package/cli/commands/create.js +67 -0
- package/cli/commands/dev.js +520 -0
- package/cli/help.js +104 -0
- package/cli/index.js +53 -0
- package/cli/scaffold/LICENSE +21 -0
- package/cli/scaffold/index.html +62 -0
- package/cli/scaffold/scripts/app.js +101 -0
- package/cli/scaffold/scripts/components/about.js +119 -0
- package/cli/scaffold/scripts/components/api-demo.js +103 -0
- package/cli/scaffold/scripts/components/contacts/contacts.css +253 -0
- package/cli/scaffold/scripts/components/contacts/contacts.html +139 -0
- package/cli/scaffold/scripts/components/contacts/contacts.js +137 -0
- package/cli/scaffold/scripts/components/counter.js +65 -0
- package/cli/scaffold/scripts/components/home.js +137 -0
- package/cli/scaffold/scripts/components/not-found.js +16 -0
- package/cli/scaffold/scripts/components/todos.js +130 -0
- package/cli/scaffold/scripts/routes.js +13 -0
- package/cli/scaffold/scripts/store.js +96 -0
- package/cli/scaffold/styles/styles.css +556 -0
- package/cli/utils.js +122 -0
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +448 -62
- package/dist/zquery.min.js +5 -5
- package/index.d.ts +213 -66
- package/index.js +14 -7
- package/package.json +8 -8
- package/src/component.js +408 -52
- package/src/core.js +26 -3
- package/src/router.js +2 -2
- package/cli.js +0 -1208
package/src/core.js
CHANGED
|
@@ -468,6 +468,16 @@ query.id = (id) => document.getElementById(id);
|
|
|
468
468
|
query.class = (name) => document.querySelector(`.${name}`);
|
|
469
469
|
query.classes = (name) => Array.from(document.getElementsByClassName(name));
|
|
470
470
|
query.tag = (name) => Array.from(document.getElementsByTagName(name));
|
|
471
|
+
Object.defineProperty(query, 'name', {
|
|
472
|
+
value: (name) => Array.from(document.getElementsByName(name)),
|
|
473
|
+
writable: true, configurable: true
|
|
474
|
+
});
|
|
475
|
+
query.attr = (attr, value) => Array.from(
|
|
476
|
+
document.querySelectorAll(value !== undefined ? `[${attr}="${value}"]` : `[${attr}]`)
|
|
477
|
+
);
|
|
478
|
+
query.data = (key, value) => Array.from(
|
|
479
|
+
document.querySelectorAll(value !== undefined ? `[data-${key}="${value}"]` : `[data-${key}]`)
|
|
480
|
+
);
|
|
471
481
|
query.children = (parentId) => {
|
|
472
482
|
const p = document.getElementById(parentId);
|
|
473
483
|
return p ? Array.from(p.children) : [];
|
|
@@ -496,13 +506,26 @@ query.ready = (fn) => {
|
|
|
496
506
|
else document.addEventListener('DOMContentLoaded', fn);
|
|
497
507
|
};
|
|
498
508
|
|
|
499
|
-
// Global event
|
|
500
|
-
|
|
509
|
+
// Global event listeners — supports direct and delegated forms
|
|
510
|
+
// $.on('keydown', handler) → direct listener on document
|
|
511
|
+
// $.on('click', '.btn', handler) → delegated via closest()
|
|
512
|
+
query.on = (event, selectorOrHandler, handler) => {
|
|
513
|
+
if (typeof selectorOrHandler === 'function') {
|
|
514
|
+
// 2-arg: direct document listener (keydown, resize, etc.)
|
|
515
|
+
document.addEventListener(event, selectorOrHandler);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
// 3-arg: delegated
|
|
501
519
|
document.addEventListener(event, (e) => {
|
|
502
|
-
const target = e.target.closest(
|
|
520
|
+
const target = e.target.closest(selectorOrHandler);
|
|
503
521
|
if (target) handler.call(target, e);
|
|
504
522
|
});
|
|
505
523
|
};
|
|
506
524
|
|
|
525
|
+
// Remove a direct global listener
|
|
526
|
+
query.off = (event, handler) => {
|
|
527
|
+
document.removeEventListener(event, handler);
|
|
528
|
+
};
|
|
529
|
+
|
|
507
530
|
// Extend collection prototype (like $.fn in jQuery)
|
|
508
531
|
query.fn = ZQueryCollection.prototype;
|
package/src/router.js
CHANGED
|
@@ -22,9 +22,9 @@ import { mount, destroy } from './component.js';
|
|
|
22
22
|
class Router {
|
|
23
23
|
constructor(config = {}) {
|
|
24
24
|
this._el = null;
|
|
25
|
-
//
|
|
25
|
+
// file:// protocol can't use pushState — always force hash mode
|
|
26
26
|
const isFile = typeof location !== 'undefined' && location.protocol === 'file:';
|
|
27
|
-
this._mode =
|
|
27
|
+
this._mode = isFile ? 'hash' : (config.mode || 'history');
|
|
28
28
|
|
|
29
29
|
// Base path for sub-path deployments
|
|
30
30
|
// Priority: explicit config.base → window.__ZQ_BASE → <base href> tag
|