Skip to content

Commit dc65e2c

Browse files
authored
Merge pull request #11 from JosunLP/copilot/integrate-bquery-template
2 parents 81c1ffd + b5591ae commit dc65e2c

6 files changed

Lines changed: 426 additions & 6 deletions

File tree

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ A modern, production-ready template for building UserScripts using TypeScript an
3434
- 💾 **Storage Management:** Type-safe wrapper for GM_setValue/GM_getValue
3535
- 🛠️ **Build System:** Optimized Vite configuration with automatic header generation
3636
- 🎨 **DOM Utilities:** Helper functions for element manipulation and waiting
37+
-**Optional bQuery Upgrade Path:** Advanced example using `@bquery/bquery/core`, `reactive`, and `media`
3738
- 🔒 **Error Handling:** Comprehensive error boundary system
3839
-**Event System:** Type-safe event emitter for module communication
3940
- 📱 **Mobile Support:** Touch-optimized interface with mobile browser detection
@@ -75,7 +76,7 @@ src/
7576
├── types/ # TypeScript type definitions
7677
├── utils/ # Utility functions (Storage, DOM, Events)
7778
├── core/ # Core application logic
78-
├── modules/ # Feature modules
79+
├── modules/ # Feature modules, including the optional bQuery example
7980
└── index.ts # Main application entry point
8081

8182
tools/
@@ -104,6 +105,21 @@ The main configuration is in `header.config.json`. This file controls UserScript
104105
}
105106
```
106107

108+
### Optional bQuery Integration
109+
110+
The template now ships with a selective `@bquery/bquery` example instead of replacing the existing utility layer.
111+
112+
- The existing `DOMUtils`, `EventEmitter`, `Storage`, and mobile helpers remain the default foundation.
113+
- The advanced example in `src/modules/bquery-example.ts` demonstrates when bQuery adds value:
114+
- `@bquery/bquery/core` for DOM updates and delegated events
115+
- `@bquery/bquery/reactive` for signal-driven state
116+
- `@bquery/bquery/media` for responsive viewport state
117+
- Only subpath imports are used so the bundle stays as small as possible.
118+
- Because bQuery ships modern ESM, the advanced path now targets current UserScript-capable browsers and runtime versions (`node >=24`, `bun >=1.3.11`).
119+
- If you do not want the advanced path, remove the `bquery-example` module import from `src/index.ts` and uninstall `@bquery/bquery`.
120+
121+
This keeps the base template approachable while still providing a modern upgrade path for more interactive UserScripts.
122+
107123
### Build Commands
108124

109125
```bash
@@ -242,6 +258,22 @@ export class MyModule extends EventEmitter<ModuleEvents> {
242258
}
243259
```
244260

261+
### bQuery Advanced Example
262+
263+
The included advanced example module shows a selective integration strategy:
264+
265+
- keep GM storage in `Storage`
266+
- keep the existing template modules intact
267+
- add bQuery only where it improves ergonomics
268+
269+
It uses:
270+
271+
- reactive signals for counter and panel state
272+
- delegated event handling via bQuery core
273+
- viewport/media tracking via bQuery media helpers
274+
275+
That makes it a good starting point for overlays, dashboards, and richer in-page tools without forcing a full framework-style migration.
276+
245277
### Mobile Utilities
246278

247279
Mobile-specific functionality for touch-enabled devices:

bun.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
},
4545
"homepage": "https://github.com/JosunLP/UserScriptProjectTemplate#readme",
4646
"engines": {
47-
"bun": ">=1.3.0"
47+
"node": ">=24.0.0",
48+
"bun": ">=1.3.11"
4849
},
4950
"devDependencies": {
5051
"@types/node": "^24.12.2",
@@ -57,5 +58,8 @@
5758
"typescript": "^5.9.3",
5859
"vite": "^7.3.2",
5960
"vite-tsconfig-paths": "^4.3.2"
61+
},
62+
"dependencies": {
63+
"@bquery/bquery": "1.10.0"
6064
}
6165
}

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BQueryExampleModule } from '@/modules/bquery-example';
12
import { ExampleModule } from '@/modules/example';
23
import { DOMUtils } from '@/utils/dom';
34
import { EventEmitter } from '@/utils/events';
@@ -94,6 +95,10 @@ class App extends EventEmitter<AppEvents> {
9495
await exampleModule.initialize();
9596
this.registerModule('example', exampleModule);
9697

98+
const bQueryExampleModule = new BQueryExampleModule();
99+
await bQueryExampleModule.initialize();
100+
this.registerModule('bquery-example', bQueryExampleModule);
101+
97102
// Initialize mobile module if on mobile device
98103
const mobileInfo = MobileUtils.detect();
99104
if (mobileInfo.isMobile || mobileInfo.hasTouch) {
@@ -123,6 +128,16 @@ class App extends EventEmitter<AppEvents> {
123128
`📡 Module action received: ${action} at ${new Date(timestamp).toLocaleString()}`
124129
);
125130
});
131+
132+
bQueryExampleModule.on('actionPerformed', eventData => {
133+
const trigger = eventData.trigger;
134+
const count = eventData.count;
135+
const viewport = eventData.viewport;
136+
const mode = eventData.compact ? 'compact' : 'wide';
137+
console.log(
138+
`✨ bQuery module action: ${trigger} (count: ${count}, viewport: ${viewport}, mode: ${mode})`
139+
);
140+
});
126141
} catch (error) {
127142
console.error('❌ Failed to initialize modules:', error);
128143
}

0 commit comments

Comments
 (0)