snice 3.6.0 → 3.8.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/README.md +2 -2
- package/bin/snice.js +4 -5
- package/bin/templates/CLAUDE.md +25 -3
- package/bin/templates/pwa/README.md +188 -0
- package/bin/templates/pwa/global.d.ts +10 -0
- package/bin/templates/pwa/index.html +16 -0
- package/bin/templates/pwa/package.json +32 -0
- package/bin/templates/pwa/public/icons/.gitkeep +6 -0
- package/bin/templates/pwa/src/daemons/notifications.ts +148 -0
- package/bin/templates/pwa/src/fetcher.ts +15 -0
- package/bin/templates/pwa/src/guards/auth.ts +12 -0
- package/bin/templates/pwa/src/main.ts +42 -0
- package/bin/templates/pwa/src/middleware/auth.ts +16 -0
- package/bin/templates/pwa/src/middleware/error.ts +36 -0
- package/bin/templates/pwa/src/middleware/retry.ts +31 -0
- package/bin/templates/pwa/src/pages/dashboard.ts +143 -0
- package/bin/templates/pwa/src/pages/login.ts +161 -0
- package/bin/templates/pwa/src/pages/notifications.ts +156 -0
- package/bin/templates/pwa/src/pages/profile.ts +164 -0
- package/bin/templates/pwa/src/router.ts +20 -0
- package/bin/templates/pwa/src/services/auth.ts +48 -0
- package/bin/templates/pwa/src/services/jwt.ts +35 -0
- package/bin/templates/pwa/src/services/storage.ts +24 -0
- package/bin/templates/pwa/src/styles/global.css +55 -0
- package/bin/templates/pwa/src/types/auth.ts +21 -0
- package/bin/templates/pwa/src/types/notifications.ts +9 -0
- package/bin/templates/pwa/tests/helpers/test-utils.ts +84 -0
- package/bin/templates/pwa/tests/middleware/auth.test.ts +67 -0
- package/bin/templates/pwa/tests/middleware/error.test.ts +105 -0
- package/bin/templates/pwa/tests/middleware/retry.test.ts +103 -0
- package/bin/templates/pwa/tests/services/auth.test.ts +89 -0
- package/bin/templates/pwa/tests/services/jwt.test.ts +76 -0
- package/bin/templates/pwa/tests/services/storage.test.ts +69 -0
- package/bin/templates/{social → pwa}/tsconfig.json +11 -10
- package/bin/templates/pwa/vite.config.ts +94 -0
- package/bin/templates/{social/vite.config.ts → pwa/vitest.config.ts} +12 -17
- package/dist/components/music-player/snice-music-player.d.ts +72 -0
- package/dist/components/music-player/snice-music-player.js +730 -0
- package/dist/components/music-player/snice-music-player.js.map +1 -0
- package/dist/components/music-player/snice-music-player.types.d.ts +43 -0
- package/dist/components/timer/snice-timer.d.ts +27 -0
- package/dist/components/timer/snice-timer.js +197 -0
- package/dist/components/timer/snice-timer.js.map +1 -0
- package/dist/components/timer/snice-timer.types.d.ts +10 -0
- package/dist/fetcher.d.ts +65 -0
- package/dist/index.cjs +92 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +92 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +92 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/symbols.cjs +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/transitions.cjs +1 -1
- package/dist/transitions.esm.js +1 -1
- package/dist/types/context.d.ts +7 -1
- package/dist/types/router-options.d.ts +6 -0
- package/docs/ai/api.md +33 -1
- package/docs/ai/components/music-player.md +134 -0
- package/docs/ai/components/timer.md +43 -0
- package/docs/ai/patterns.md +48 -1
- package/docs/components/music-player.md +314 -0
- package/docs/components/timer.md +143 -0
- package/docs/fetcher.md +447 -0
- package/docs/routing.md +11 -8
- package/package.json +2 -1
- package/bin/templates/social/README.md +0 -42
- package/bin/templates/social/global.d.ts +0 -14
- package/bin/templates/social/index.html +0 -13
- package/bin/templates/social/package.json +0 -21
- package/bin/templates/social/src/main.ts +0 -33
- package/bin/templates/social/src/pages/feed-page.ts +0 -111
- package/bin/templates/social/src/pages/messages-page.ts +0 -102
- package/bin/templates/social/src/pages/not-found-page.ts +0 -46
- package/bin/templates/social/src/pages/profile-page.ts +0 -99
- package/bin/templates/social/src/pages/settings-page.ts +0 -119
- package/bin/templates/social/src/router.ts +0 -9
- package/bin/templates/social/src/styles/global.css +0 -156
- /package/bin/templates/{social → pwa}/public/vite.svg +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -18,4 +18,6 @@ export { trackRenders } from './render-debug';
|
|
|
18
18
|
export { debounce, throttle, once, memoize, clearDebounceTimers, clearThrottleTimers, clearMemoizeCache, resetOnce } from './method-decorators';
|
|
19
19
|
export { context } from './context';
|
|
20
20
|
export type { ContextOptions } from './context';
|
|
21
|
+
export { ContextAwareFetcher } from './fetcher';
|
|
22
|
+
export type { Fetcher, RequestMiddleware, ResponseMiddleware } from './fetcher';
|
|
21
23
|
export * from './types';
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* snice v3.
|
|
2
|
+
* snice v3.7.0
|
|
3
3
|
* Imperative TypeScript framework for building vanilla web components with decorators, differential rendering, routing, and controllers. No virtual DOM, no build complexity.
|
|
4
4
|
* (c) 2024
|
|
5
5
|
* Released under the MIT License.
|
|
@@ -2364,7 +2364,7 @@ let contextIdCounter = 0;
|
|
|
2364
2364
|
* Represents the bundled router state that can notify registered elements of changes
|
|
2365
2365
|
*/
|
|
2366
2366
|
class Context {
|
|
2367
|
-
constructor(context = {}, placards = [], currentRoute = '', routeParams = {}) {
|
|
2367
|
+
constructor(context = {}, placards = [], currentRoute = '', routeParams = {}, fetcher) {
|
|
2368
2368
|
this[_a] = new WeakMap();
|
|
2369
2369
|
this[_b] = new Set();
|
|
2370
2370
|
this[_c] = false;
|
|
@@ -2375,6 +2375,16 @@ class Context {
|
|
|
2375
2375
|
route: currentRoute,
|
|
2376
2376
|
params: routeParams
|
|
2377
2377
|
};
|
|
2378
|
+
// Initialize fetch with middleware support or fallback to native fetch
|
|
2379
|
+
if (fetcher && typeof fetcher.create === 'function') {
|
|
2380
|
+
this.fetch = fetcher.create(this);
|
|
2381
|
+
}
|
|
2382
|
+
else if (typeof fetch === 'function') {
|
|
2383
|
+
this.fetch = fetch.bind(this);
|
|
2384
|
+
}
|
|
2385
|
+
else {
|
|
2386
|
+
throw new Error('No fetch implementation available');
|
|
2387
|
+
}
|
|
2378
2388
|
}
|
|
2379
2389
|
/**
|
|
2380
2390
|
* Register an element to receive context updates
|
|
@@ -4469,7 +4479,7 @@ function Router(options) {
|
|
|
4469
4479
|
let currentLayoutTimestamp = null; // Track current layout timestamp
|
|
4470
4480
|
const context = options.context || {}; // Store context for guards
|
|
4471
4481
|
// Create Context instance for managing router state
|
|
4472
|
-
const navigationContext = new Context(context, [], '', {});
|
|
4482
|
+
const navigationContext = new Context(context, [], '', {}, options.fetcher);
|
|
4473
4483
|
function getCurrentLayoutElement(target) {
|
|
4474
4484
|
const noCurrentLayout = !currentLayoutName || !currentLayoutTimestamp;
|
|
4475
4485
|
if (noCurrentLayout) {
|
|
@@ -5398,5 +5408,83 @@ function resetOnce(instance, methodName) {
|
|
|
5398
5408
|
}
|
|
5399
5409
|
}
|
|
5400
5410
|
|
|
5401
|
-
|
|
5411
|
+
/**
|
|
5412
|
+
* Context-aware fetch implementation with middleware support
|
|
5413
|
+
*
|
|
5414
|
+
* @example
|
|
5415
|
+
* ```typescript
|
|
5416
|
+
* const fetcher = new ContextAwareFetcher();
|
|
5417
|
+
*
|
|
5418
|
+
* fetcher.use('request', function(request, next) {
|
|
5419
|
+
* const token = this.application.user?.token;
|
|
5420
|
+
* if (token) {
|
|
5421
|
+
* request.headers.set('Authorization', `Bearer ${token}`);
|
|
5422
|
+
* }
|
|
5423
|
+
* return next();
|
|
5424
|
+
* });
|
|
5425
|
+
*
|
|
5426
|
+
* fetcher.use('response', async function(response, next) {
|
|
5427
|
+
* if (!response.ok) {
|
|
5428
|
+
* throw new Error(`HTTP ${response.status}`);
|
|
5429
|
+
* }
|
|
5430
|
+
* return next();
|
|
5431
|
+
* });
|
|
5432
|
+
*
|
|
5433
|
+
* const router = Router({
|
|
5434
|
+
* target: '#app',
|
|
5435
|
+
* context: { user: null },
|
|
5436
|
+
* fetcher
|
|
5437
|
+
* });
|
|
5438
|
+
* ```
|
|
5439
|
+
*/
|
|
5440
|
+
class ContextAwareFetcher {
|
|
5441
|
+
constructor() {
|
|
5442
|
+
this.requestMiddlewares = [];
|
|
5443
|
+
this.responseMiddlewares = [];
|
|
5444
|
+
}
|
|
5445
|
+
use(type, middleware) {
|
|
5446
|
+
if (type === 'request') {
|
|
5447
|
+
this.requestMiddlewares.push(middleware);
|
|
5448
|
+
}
|
|
5449
|
+
else {
|
|
5450
|
+
this.responseMiddlewares.push(middleware);
|
|
5451
|
+
}
|
|
5452
|
+
}
|
|
5453
|
+
/**
|
|
5454
|
+
* Create a fetch function bound to the given Context instance
|
|
5455
|
+
* @param ctx - The Context instance to bind to
|
|
5456
|
+
* @returns A fetch function with middleware applied
|
|
5457
|
+
*/
|
|
5458
|
+
create(ctx) {
|
|
5459
|
+
const requestMiddlewares = this.requestMiddlewares;
|
|
5460
|
+
const responseMiddlewares = this.responseMiddlewares;
|
|
5461
|
+
const fetchFn = async function (input, init) {
|
|
5462
|
+
const request = new Request(input, init);
|
|
5463
|
+
// Request middleware chain
|
|
5464
|
+
let reqIndex = 0;
|
|
5465
|
+
const nextRequest = async () => {
|
|
5466
|
+
if (reqIndex < requestMiddlewares.length) {
|
|
5467
|
+
const middleware = requestMiddlewares[reqIndex++];
|
|
5468
|
+
return middleware.call(this, request, nextRequest);
|
|
5469
|
+
}
|
|
5470
|
+
// Execute actual fetch
|
|
5471
|
+
const response = await fetch(request);
|
|
5472
|
+
// Response middleware chain
|
|
5473
|
+
let resIndex = 0;
|
|
5474
|
+
const nextResponse = async () => {
|
|
5475
|
+
if (resIndex < responseMiddlewares.length) {
|
|
5476
|
+
const middleware = responseMiddlewares[resIndex++];
|
|
5477
|
+
return middleware.call(this, response, nextResponse);
|
|
5478
|
+
}
|
|
5479
|
+
return response;
|
|
5480
|
+
};
|
|
5481
|
+
return nextResponse();
|
|
5482
|
+
};
|
|
5483
|
+
return nextRequest();
|
|
5484
|
+
};
|
|
5485
|
+
return fetchFn.bind(ctx);
|
|
5486
|
+
}
|
|
5487
|
+
}
|
|
5488
|
+
|
|
5489
|
+
export { Context, ContextAwareFetcher, IS_CONTROLLER_INSTANCE, Router, SimpleArray, adopted, applyElementFunctionality, clearDebounceTimers, clearMemoizeCache, clearThrottleTimers, context$1 as context, context as contextProperty, controller, css, debounce, dispatch, dispose, element, getSymbol, html, layout, memoize, moved, nothing, observe, on, once, property, query, queryAll, ready, render, request, resetOnce, respond, setDisableElementReadyWarnings, styles, throttle, trackRenders, unsafeHTML, useNativeElementControllers, waitForAllCustomElements, waitForElementDefined, waitForElementReady, watch };
|
|
5402
5490
|
//# sourceMappingURL=index.esm.js.map
|