@angular-wave/angular.ts 0.9.6 → 0.9.8

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.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @returns {ng.Directive}
3
+ */
4
+ export function ngElDirective(): ng.Directive;
@@ -1,21 +1,18 @@
1
1
  /**
2
2
  *
3
- * @param {import("../../core/parse/interface.ts").ParseService} $parse
4
- * @param {import('../../services/exception/exception-handler.js').ErrorHandler} $exceptionHandler
3
+ * @param {ng.ParseService} $parse
4
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
5
5
  * @param {string} directiveName
6
6
  * @param {string} eventName
7
- * @returns {import("../../interface.ts").Directive}
7
+ * @returns {ng.Directive}
8
8
  */
9
9
  export function createEventDirective(
10
- $parse: import("../../core/parse/interface.ts").ParseService,
11
- $exceptionHandler: import("../../services/exception/exception-handler.js").ErrorHandler,
10
+ $parse: ng.ParseService,
11
+ $exceptionHandler: ng.ExceptionHandlerService,
12
12
  directiveName: string,
13
13
  eventName: string,
14
- ): import("../../interface.ts").Directive;
14
+ ): ng.Directive;
15
15
  /**
16
- * @type {Record<string, import("../../interface.js").DirectiveFactory>}
16
+ * @type {Record<string, ng.DirectiveFactory>}
17
17
  */
18
- export const ngEventDirectives: Record<
19
- string,
20
- import("../../interface.js").DirectiveFactory
21
- >;
18
+ export const ngEventDirectives: Record<string, ng.DirectiveFactory>;
@@ -43,4 +43,6 @@ export const ngDeleteDirective: ng.DirectiveFactory;
43
43
  export const ngPostDirective: ng.DirectiveFactory;
44
44
  /** @type {ng.DirectiveFactory} */
45
45
  export const ngPutDirective: ng.DirectiveFactory;
46
+ /** @type {ng.DirectiveFactory} */
47
+ export const ngSseDirective: ng.DirectiveFactory;
46
48
  export type EventType = "click" | "change" | "submit";
@@ -104,9 +104,7 @@ export const patternDirective: (
104
104
  */
105
105
  export const maxlengthDirective: (
106
106
  | string
107
- | ((
108
- $parse: import("../../core/parse/interface.ts").ParseService,
109
- ) => import("../../interface.ts").Directive)
107
+ | (($parse: ng.ParseService) => ng.Directive)
110
108
  )[];
111
109
  /**
112
110
  *
@@ -30,6 +30,10 @@ import {
30
30
  import { StateProvider } from "./router/state/state-service.js";
31
31
  import { HttpService as THttpService } from "./services/http/interface.ts";
32
32
  import { LogService as TLogService } from "./services/log/interface.ts";
33
+ import {
34
+ SseService as TSseService,
35
+ SseConfig as TSseConfig,
36
+ } from "./services/sse/interface.ts";
33
37
  declare global {
34
38
  interface Function {
35
39
  $inject?: readonly string[] | undefined;
@@ -67,6 +71,8 @@ declare global {
67
71
  type RootElementService = Element;
68
72
  type RootScopeService = InstanceType<typeof Scope>;
69
73
  type StateService = InstanceType<typeof StateProvider>;
74
+ type SseService = TSseService;
75
+ type SseConfig = TSseConfig;
70
76
  type TemplateCacheService = InstanceType<typeof Map<string, string>>;
71
77
  type TemplateRequestService = TTemplateRequestService;
72
78
  type ErrorHandlingConfig = TErrorHandlingConfig;
@@ -106,7 +106,7 @@ export class HttpProvider {
106
106
  $get: (
107
107
  | string
108
108
  | ((
109
- $injector: import("../../core/di/internal-injector.js").InjectorService,
109
+ $injector: ng.InjectorService,
110
110
  $sce: any,
111
111
  ) => {
112
112
  (requestConfig: any): Promise<any>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Configuration object for SSE
3
+ */
4
+ export interface SseConfig {
5
+ withCredentials?: boolean;
6
+ headers?: Record<string, string>;
7
+ onOpen?: (event: Event) => void;
8
+ onMessage?: (data: any, event: MessageEvent) => void;
9
+ onError?: (err: Event) => void;
10
+ transformMessage?: (data: string) => any;
11
+ params?: Record<string, any>;
12
+ }
13
+ /**
14
+ * $sse service type
15
+ */
16
+ export type SseService = (url: string, config?: SseConfig) => EventSource;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * SSE Provider
3
+ *
4
+ * Usage:
5
+ * const source = $sse('/events', {
6
+ * onMessage: (data) => console.log(data),
7
+ * onError: (err) => console.error(err),
8
+ * withCredentials: true
9
+ * });
10
+ *
11
+ * // later:
12
+ * source.close();
13
+ */
14
+ export class SseProvider {
15
+ /**
16
+ * Optional provider-level defaults
17
+ * @type {ng.SseConfig}
18
+ */
19
+ defaults: ng.SseConfig;
20
+ /**
21
+ * Returns the $sse service function
22
+ * @returns {ng.SseService}
23
+ */
24
+ $get: () => ng.SseService;
25
+ #private;
26
+ }
@@ -1,4 +1,4 @@
1
- /* Version: 0.9.6 - October 23, 2025 19:46:24 */
1
+ /* Version: 0.9.8 - October 26, 2025 19:05:36 */
2
2
  const VALID_CLASS = "ng-valid";
3
3
  const INVALID_CLASS = "ng-invalid";
4
4
  const PRISTINE_CLASS = "ng-pristine";
@@ -1810,6 +1810,7 @@ const $injectTokens = Object.freeze({
1810
1810
  $sceDelegate: "$sceDelegate",
1811
1811
  $state: "$state",
1812
1812
  $stateRegistry: "$stateRegistry",
1813
+ $sse: "$sse",
1813
1814
  $$sanitizeUri: "$$sanitizeUri",
1814
1815
  $$sanitizeUriProvider: "$$sanitizeUriProvider",
1815
1816
  $templateCache: "$templateCache",
@@ -4010,7 +4011,7 @@ function SceProvider() {
4010
4011
  */
4011
4012
 
4012
4013
  /**
4013
- * @type {Record<string, import("../../interface.js").DirectiveFactory>}
4014
+ * @type {Record<string, ng.DirectiveFactory>}
4014
4015
  */
4015
4016
  const ngEventDirectives = {};
4016
4017
 
@@ -4023,7 +4024,7 @@ const ngEventDirectives = {};
4023
4024
  "$exceptionHandler",
4024
4025
  /**
4025
4026
  * @param {import("../../core/parse/interface.ts").ParseService} $parse
4026
- * @param {import('../../services/exception/exception-handler.js').ErrorHandler} $exceptionHandler
4027
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
4027
4028
  * @returns
4028
4029
  */
4029
4030
  ($parse, $exceptionHandler) => {
@@ -4039,11 +4040,11 @@ const ngEventDirectives = {};
4039
4040
 
4040
4041
  /**
4041
4042
  *
4042
- * @param {import("../../core/parse/interface.ts").ParseService} $parse
4043
- * @param {import('../../services/exception/exception-handler.js').ErrorHandler} $exceptionHandler
4043
+ * @param {ng.ParseService} $parse
4044
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
4044
4045
  * @param {string} directiveName
4045
4046
  * @param {string} eventName
4046
- * @returns {import("../../interface.ts").Directive}
4047
+ * @returns {ng.Directive}
4047
4048
  */
4048
4049
  function createEventDirective(
4049
4050
  $parse,
@@ -13343,17 +13344,17 @@ const patternDirective = [
13343
13344
  const maxlengthDirective = [
13344
13345
  $injectTokens.$parse,
13345
13346
  /**
13346
- * @param {import("../../core/parse/interface.ts").ParseService} $parse
13347
- * @returns {import("../../interface.ts").Directive}
13347
+ * @param {ng.ParseService} $parse
13348
+ * @returns {ng.Directive}
13348
13349
  */
13349
13350
  ($parse) => ({
13350
13351
  restrict: "A",
13351
13352
  require: "?ngModel",
13352
13353
  link:
13353
13354
  /**
13354
- * @param {import("../../core/scope/scope.js").Scope} scope
13355
- * @param {*} _elm
13356
- * @param {import("../../core/compile/attributes.js").Attributes} attr
13355
+ * @param {ng.Scope} scope
13356
+ * @param {Element} _elm
13357
+ * @param {ng.Attributes} attr
13357
13358
  * @param {import("../../interface.ts").NgModelController} ctrl
13358
13359
  * @returns
13359
13360
  */
@@ -18301,7 +18302,7 @@ function HttpProvider() {
18301
18302
  $injectTokens.$sce,
18302
18303
  /**
18303
18304
  *
18304
- * @param {import("../../core/di/internal-injector.js").InjectorService} $injector
18305
+ * @param {ng.InjectorService} $injector
18305
18306
  * @param {*} $sce
18306
18307
  * @returns
18307
18308
  */
@@ -35105,10 +35106,18 @@ function ngSetterDirective($parse, $log) {
35105
35106
  * @param {"get" | "delete" | "post" | "put"} method
35106
35107
  * @returns {ng.DirectiveFactory}
35107
35108
  */
35108
- function defineDirective(method) {
35109
- const attrName = "ng" + method.charAt(0).toUpperCase() + method.slice(1);
35109
+ function defineDirective(method, attrOverride) {
35110
+ const attrName =
35111
+ attrOverride || "ng" + method.charAt(0).toUpperCase() + method.slice(1);
35110
35112
  const directive = createHttpDirective(method, attrName);
35111
- directive["$inject"] = [$injectTokens.$http, $injectTokens.$compile, $injectTokens.$log, $injectTokens.$parse, $injectTokens.$state];
35113
+ directive["$inject"] = [
35114
+ $injectTokens.$http,
35115
+ $injectTokens.$compile,
35116
+ $injectTokens.$log,
35117
+ $injectTokens.$parse,
35118
+ $injectTokens.$state,
35119
+ $injectTokens.$sse,
35120
+ ];
35112
35121
  return directive;
35113
35122
  }
35114
35123
 
@@ -35124,6 +35133,9 @@ const ngPostDirective = defineDirective("post");
35124
35133
  /** @type {ng.DirectiveFactory} */
35125
35134
  const ngPutDirective = defineDirective("put");
35126
35135
 
35136
+ /** @type {ng.DirectiveFactory} */
35137
+ const ngSseDirective = defineDirective("get", "ngSse");
35138
+
35127
35139
  /**
35128
35140
  * @typedef {"click" | "change" | "submit"} EventType
35129
35141
  */
@@ -35241,9 +35253,10 @@ function createHttpDirective(method, attrName) {
35241
35253
  * @param {ng.LogService} $log
35242
35254
  * @param {ng.ParseService} $parse
35243
35255
  * @param {ng.StateService} $state
35256
+ * @param {Function} $sse
35244
35257
  * @returns {ng.Directive}
35245
35258
  */
35246
- return function ($http, $compile, $log, $parse, $state) {
35259
+ return function ($http, $compile, $log, $parse, $state, $sse) {
35247
35260
  /**
35248
35261
  * Collects form data from the element or its associated form.
35249
35262
  *
@@ -35332,7 +35345,6 @@ function createHttpDirective(method, attrName) {
35332
35345
  element.addEventListener(eventName, async (event) => {
35333
35346
  if (/** @type {HTMLButtonElement} */ (element).disabled) return;
35334
35347
  if (tag === "form") event.preventDefault();
35335
-
35336
35348
  const swap = attrs["swap"] || "innerHTML";
35337
35349
  const targetSelector = attrs["target"];
35338
35350
  const target = targetSelector
@@ -35386,7 +35398,6 @@ function createHttpDirective(method, attrName) {
35386
35398
  $compile,
35387
35399
  );
35388
35400
  };
35389
-
35390
35401
  if (isDefined(attrs["delay"])) {
35391
35402
  await wait(parseInt(attrs["delay"]) | 0);
35392
35403
  }
@@ -35425,11 +35436,57 @@ function createHttpDirective(method, attrName) {
35425
35436
  }
35426
35437
  $http[method](url, data, config).then(handler).catch(handler);
35427
35438
  } else {
35428
- $http[method](url).then(handler).catch(handler);
35439
+ // If SSE mode is enabled
35440
+ if (method === "get" && attrs["ngSse"]) {
35441
+ const sseUrl = url;
35442
+ const config = {
35443
+ withCredentials: attrs["withCredentials"] === "true",
35444
+ transformMessage: (data) => {
35445
+ try {
35446
+ return JSON.parse(data);
35447
+ } catch {
35448
+ return data;
35449
+ }
35450
+ },
35451
+ onOpen: () => {
35452
+ $log.info(`${attrName}: SSE connection opened to ${sseUrl}`);
35453
+ if (isDefined(attrs["loading"])) attrs.$set("loading", false);
35454
+ if (isDefined(attrs["loadingClass"]))
35455
+ attrs.$removeClass(attrs["loadingClass"]);
35456
+ },
35457
+ onMessage: (data) => {
35458
+ const res = { status: 200, data };
35459
+ handler(res);
35460
+ },
35461
+ onError: (err) => {
35462
+ $log.error(`${attrName}: SSE error`, err);
35463
+ const res = { status: 500, data: err };
35464
+ handler(res);
35465
+ },
35466
+ };
35467
+
35468
+ // Open the SSE connection using the injected service
35469
+ const source = $sse(sseUrl, config);
35470
+
35471
+ // Cleanup on scope destroy
35472
+ scope.$on("$destroy", () => {
35473
+ $log.info(`${attrName}: closing SSE connection`);
35474
+ source.close();
35475
+ });
35476
+ } else {
35477
+ $http[method](url).then(handler).catch(handler);
35478
+ }
35429
35479
  }
35430
35480
  });
35431
35481
 
35432
- scope.$on("$destroy", () => clearInterval(intervalId));
35482
+ if (intervalId) {
35483
+ scope.$on("$destroy", () => clearInterval(intervalId));
35484
+ }
35485
+
35486
+ // Eagerly execute for 'load' event
35487
+ if (eventName == "load") {
35488
+ element.dispatchEvent(new Event("load"));
35489
+ }
35433
35490
  },
35434
35491
  };
35435
35492
  };
@@ -35469,6 +35526,120 @@ function ngInjectDirective($log, $injector) {
35469
35526
  };
35470
35527
  }
35471
35528
 
35529
+ /**
35530
+ * @returns {ng.Directive}
35531
+ */
35532
+ function ngElDirective() {
35533
+ return {
35534
+ restrict: "A",
35535
+ link(scope, element, attrs) {
35536
+ const expr = attrs["ngEl"];
35537
+ const key = !expr ? element.id : expr;
35538
+
35539
+ scope.$target[key] = element;
35540
+ const parent = element.parentNode;
35541
+ if (!parent) return;
35542
+
35543
+ const observer = new MutationObserver((mutations) => {
35544
+ for (const mutation of mutations) {
35545
+ Array.from(mutation.removedNodes).forEach((removedNode) => {
35546
+ if (removedNode === element) {
35547
+ //
35548
+ delete scope.$target[key];
35549
+ observer.disconnect();
35550
+ }
35551
+ });
35552
+ }
35553
+ });
35554
+
35555
+ observer.observe(parent, { childList: true });
35556
+ },
35557
+ };
35558
+ }
35559
+
35560
+ /**
35561
+ * SSE Provider
35562
+ *
35563
+ * Usage:
35564
+ * const source = $sse('/events', {
35565
+ * onMessage: (data) => console.log(data),
35566
+ * onError: (err) => console.error(err),
35567
+ * withCredentials: true
35568
+ * });
35569
+ *
35570
+ * // later:
35571
+ * source.close();
35572
+ */
35573
+
35574
+ class SseProvider {
35575
+ constructor() {
35576
+ /**
35577
+ * Optional provider-level defaults
35578
+ * @type {ng.SseConfig}
35579
+ */
35580
+ this.defaults = {};
35581
+ }
35582
+
35583
+ /**
35584
+ * Returns the $sse service function
35585
+ * @returns {ng.SseService}
35586
+ */
35587
+ $get =
35588
+ () =>
35589
+ (url, config = {}) => {
35590
+ const finalUrl = this.#buildUrl(url, config.params);
35591
+ return this.#createEventSource(finalUrl, config);
35592
+ };
35593
+
35594
+ /**
35595
+ * Build URL with query parameters
35596
+ * @param {string} url - Base URL
35597
+ * @param {Record<string, any>=} params - Query parameters
35598
+ * @returns {string} URL with serialized query string
35599
+ */
35600
+ #buildUrl(url, params) {
35601
+ if (!params) return url;
35602
+ const query = Object.entries(params)
35603
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
35604
+ .join("&");
35605
+ return url + (url.includes("?") ? "&" : "?") + query;
35606
+ }
35607
+
35608
+ /**
35609
+ * Create and manage an EventSource
35610
+ * @param {string} url - URL for SSE connection
35611
+ * @param {ng.SseConfig} config - Configuration object
35612
+ * @returns {EventSource} The EventSource instance wrapped as SseService
35613
+ */
35614
+ #createEventSource(url, config) {
35615
+ const es = new EventSource(url, {
35616
+ withCredentials: !!config.withCredentials,
35617
+ });
35618
+
35619
+ if (config.onOpen) {
35620
+ es.addEventListener("open", (e) => config.onOpen(e));
35621
+ }
35622
+
35623
+ es.addEventListener("message", (e) => {
35624
+ let data = e.data;
35625
+ try {
35626
+ data = config.transformMessage
35627
+ ? config.transformMessage(data)
35628
+ : JSON.parse(data);
35629
+ } catch {
35630
+ // leave as raw string if not JSON
35631
+ }
35632
+ config.onMessage?.(data, e);
35633
+ });
35634
+
35635
+ if (config.onError) {
35636
+ es.addEventListener("error", (e) => config.onError(e));
35637
+ }
35638
+
35639
+ return es;
35640
+ }
35641
+ }
35642
+
35472
35643
  /**
35473
35644
  * Initializes core `ng` module.
35474
35645
  * @param {import('./angular.js').Angular} angular
@@ -35508,6 +35679,7 @@ function registerNgModule(angular) {
35508
35679
  ngController: ngControllerDirective,
35509
35680
  ngDelete: ngDeleteDirective,
35510
35681
  ngDisabled: ngDisabledAriaDirective,
35682
+ ngEl: ngElDirective,
35511
35683
  ngForm: ngFormDirective,
35512
35684
  ngGet: ngGetDirective,
35513
35685
  ngHide: ngHideDirective,
@@ -35528,6 +35700,7 @@ function registerNgModule(angular) {
35528
35700
  ngSetter: ngSetterDirective,
35529
35701
  ngShow: ngShowDirective,
35530
35702
  ngStyle: ngStyleDirective,
35703
+ ngSse: ngSseDirective,
35531
35704
  ngSwitch: ngSwitchDirective,
35532
35705
  ngSwitchWhen: ngSwitchWhenDirective,
35533
35706
  ngSwitchDefault: ngSwitchDefaultDirective,
@@ -35599,6 +35772,7 @@ function registerNgModule(angular) {
35599
35772
  $router: Router,
35600
35773
  $sce: SceProvider,
35601
35774
  $sceDelegate: SceDelegateProvider,
35775
+ $sse: SseProvider,
35602
35776
  $templateCache: TemplateCacheProvider,
35603
35777
  $templateRequest: TemplateRequestProvider,
35604
35778
  $urlConfig: UrlConfigProvider,
@@ -35641,7 +35815,7 @@ class Angular {
35641
35815
  /**
35642
35816
  * @type {string} `version` from `package.json`
35643
35817
  */
35644
- this.version = "0.9.6"; //inserted via rollup plugin
35818
+ this.version = "0.9.8"; //inserted via rollup plugin
35645
35819
 
35646
35820
  /** @type {!Array<string|any>} */
35647
35821
  this.bootsrappedModules = [];