@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.
@@ -1,4 +1,4 @@
1
- /* Version: 0.9.6 - October 23, 2025 19:46:22 */
1
+ /* Version: 0.9.8 - October 26, 2025 19:05:34 */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -1816,6 +1816,7 @@
1816
1816
  $sceDelegate: "$sceDelegate",
1817
1817
  $state: "$state",
1818
1818
  $stateRegistry: "$stateRegistry",
1819
+ $sse: "$sse",
1819
1820
  $$sanitizeUri: "$$sanitizeUri",
1820
1821
  $$sanitizeUriProvider: "$$sanitizeUriProvider",
1821
1822
  $templateCache: "$templateCache",
@@ -4016,7 +4017,7 @@
4016
4017
  */
4017
4018
 
4018
4019
  /**
4019
- * @type {Record<string, import("../../interface.js").DirectiveFactory>}
4020
+ * @type {Record<string, ng.DirectiveFactory>}
4020
4021
  */
4021
4022
  const ngEventDirectives = {};
4022
4023
 
@@ -4029,7 +4030,7 @@
4029
4030
  "$exceptionHandler",
4030
4031
  /**
4031
4032
  * @param {import("../../core/parse/interface.ts").ParseService} $parse
4032
- * @param {import('../../services/exception/exception-handler.js').ErrorHandler} $exceptionHandler
4033
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
4033
4034
  * @returns
4034
4035
  */
4035
4036
  ($parse, $exceptionHandler) => {
@@ -4045,11 +4046,11 @@
4045
4046
 
4046
4047
  /**
4047
4048
  *
4048
- * @param {import("../../core/parse/interface.ts").ParseService} $parse
4049
- * @param {import('../../services/exception/exception-handler.js').ErrorHandler} $exceptionHandler
4049
+ * @param {ng.ParseService} $parse
4050
+ * @param {ng.ExceptionHandlerService} $exceptionHandler
4050
4051
  * @param {string} directiveName
4051
4052
  * @param {string} eventName
4052
- * @returns {import("../../interface.ts").Directive}
4053
+ * @returns {ng.Directive}
4053
4054
  */
4054
4055
  function createEventDirective(
4055
4056
  $parse,
@@ -13349,17 +13350,17 @@
13349
13350
  const maxlengthDirective = [
13350
13351
  $injectTokens.$parse,
13351
13352
  /**
13352
- * @param {import("../../core/parse/interface.ts").ParseService} $parse
13353
- * @returns {import("../../interface.ts").Directive}
13353
+ * @param {ng.ParseService} $parse
13354
+ * @returns {ng.Directive}
13354
13355
  */
13355
13356
  ($parse) => ({
13356
13357
  restrict: "A",
13357
13358
  require: "?ngModel",
13358
13359
  link:
13359
13360
  /**
13360
- * @param {import("../../core/scope/scope.js").Scope} scope
13361
- * @param {*} _elm
13362
- * @param {import("../../core/compile/attributes.js").Attributes} attr
13361
+ * @param {ng.Scope} scope
13362
+ * @param {Element} _elm
13363
+ * @param {ng.Attributes} attr
13363
13364
  * @param {import("../../interface.ts").NgModelController} ctrl
13364
13365
  * @returns
13365
13366
  */
@@ -18307,7 +18308,7 @@
18307
18308
  $injectTokens.$sce,
18308
18309
  /**
18309
18310
  *
18310
- * @param {import("../../core/di/internal-injector.js").InjectorService} $injector
18311
+ * @param {ng.InjectorService} $injector
18311
18312
  * @param {*} $sce
18312
18313
  * @returns
18313
18314
  */
@@ -35111,10 +35112,18 @@
35111
35112
  * @param {"get" | "delete" | "post" | "put"} method
35112
35113
  * @returns {ng.DirectiveFactory}
35113
35114
  */
35114
- function defineDirective(method) {
35115
- const attrName = "ng" + method.charAt(0).toUpperCase() + method.slice(1);
35115
+ function defineDirective(method, attrOverride) {
35116
+ const attrName =
35117
+ attrOverride || "ng" + method.charAt(0).toUpperCase() + method.slice(1);
35116
35118
  const directive = createHttpDirective(method, attrName);
35117
- directive["$inject"] = [$injectTokens.$http, $injectTokens.$compile, $injectTokens.$log, $injectTokens.$parse, $injectTokens.$state];
35119
+ directive["$inject"] = [
35120
+ $injectTokens.$http,
35121
+ $injectTokens.$compile,
35122
+ $injectTokens.$log,
35123
+ $injectTokens.$parse,
35124
+ $injectTokens.$state,
35125
+ $injectTokens.$sse,
35126
+ ];
35118
35127
  return directive;
35119
35128
  }
35120
35129
 
@@ -35130,6 +35139,9 @@
35130
35139
  /** @type {ng.DirectiveFactory} */
35131
35140
  const ngPutDirective = defineDirective("put");
35132
35141
 
35142
+ /** @type {ng.DirectiveFactory} */
35143
+ const ngSseDirective = defineDirective("get", "ngSse");
35144
+
35133
35145
  /**
35134
35146
  * @typedef {"click" | "change" | "submit"} EventType
35135
35147
  */
@@ -35247,9 +35259,10 @@
35247
35259
  * @param {ng.LogService} $log
35248
35260
  * @param {ng.ParseService} $parse
35249
35261
  * @param {ng.StateService} $state
35262
+ * @param {Function} $sse
35250
35263
  * @returns {ng.Directive}
35251
35264
  */
35252
- return function ($http, $compile, $log, $parse, $state) {
35265
+ return function ($http, $compile, $log, $parse, $state, $sse) {
35253
35266
  /**
35254
35267
  * Collects form data from the element or its associated form.
35255
35268
  *
@@ -35338,7 +35351,6 @@
35338
35351
  element.addEventListener(eventName, async (event) => {
35339
35352
  if (/** @type {HTMLButtonElement} */ (element).disabled) return;
35340
35353
  if (tag === "form") event.preventDefault();
35341
-
35342
35354
  const swap = attrs["swap"] || "innerHTML";
35343
35355
  const targetSelector = attrs["target"];
35344
35356
  const target = targetSelector
@@ -35392,7 +35404,6 @@
35392
35404
  $compile,
35393
35405
  );
35394
35406
  };
35395
-
35396
35407
  if (isDefined(attrs["delay"])) {
35397
35408
  await wait(parseInt(attrs["delay"]) | 0);
35398
35409
  }
@@ -35431,11 +35442,57 @@
35431
35442
  }
35432
35443
  $http[method](url, data, config).then(handler).catch(handler);
35433
35444
  } else {
35434
- $http[method](url).then(handler).catch(handler);
35445
+ // If SSE mode is enabled
35446
+ if (method === "get" && attrs["ngSse"]) {
35447
+ const sseUrl = url;
35448
+ const config = {
35449
+ withCredentials: attrs["withCredentials"] === "true",
35450
+ transformMessage: (data) => {
35451
+ try {
35452
+ return JSON.parse(data);
35453
+ } catch {
35454
+ return data;
35455
+ }
35456
+ },
35457
+ onOpen: () => {
35458
+ $log.info(`${attrName}: SSE connection opened to ${sseUrl}`);
35459
+ if (isDefined(attrs["loading"])) attrs.$set("loading", false);
35460
+ if (isDefined(attrs["loadingClass"]))
35461
+ attrs.$removeClass(attrs["loadingClass"]);
35462
+ },
35463
+ onMessage: (data) => {
35464
+ const res = { status: 200, data };
35465
+ handler(res);
35466
+ },
35467
+ onError: (err) => {
35468
+ $log.error(`${attrName}: SSE error`, err);
35469
+ const res = { status: 500, data: err };
35470
+ handler(res);
35471
+ },
35472
+ };
35473
+
35474
+ // Open the SSE connection using the injected service
35475
+ const source = $sse(sseUrl, config);
35476
+
35477
+ // Cleanup on scope destroy
35478
+ scope.$on("$destroy", () => {
35479
+ $log.info(`${attrName}: closing SSE connection`);
35480
+ source.close();
35481
+ });
35482
+ } else {
35483
+ $http[method](url).then(handler).catch(handler);
35484
+ }
35435
35485
  }
35436
35486
  });
35437
35487
 
35438
- scope.$on("$destroy", () => clearInterval(intervalId));
35488
+ if (intervalId) {
35489
+ scope.$on("$destroy", () => clearInterval(intervalId));
35490
+ }
35491
+
35492
+ // Eagerly execute for 'load' event
35493
+ if (eventName == "load") {
35494
+ element.dispatchEvent(new Event("load"));
35495
+ }
35439
35496
  },
35440
35497
  };
35441
35498
  };
@@ -35475,6 +35532,120 @@
35475
35532
  };
35476
35533
  }
35477
35534
 
35535
+ /**
35536
+ * @returns {ng.Directive}
35537
+ */
35538
+ function ngElDirective() {
35539
+ return {
35540
+ restrict: "A",
35541
+ link(scope, element, attrs) {
35542
+ const expr = attrs["ngEl"];
35543
+ const key = !expr ? element.id : expr;
35544
+
35545
+ scope.$target[key] = element;
35546
+ const parent = element.parentNode;
35547
+ if (!parent) return;
35548
+
35549
+ const observer = new MutationObserver((mutations) => {
35550
+ for (const mutation of mutations) {
35551
+ Array.from(mutation.removedNodes).forEach((removedNode) => {
35552
+ if (removedNode === element) {
35553
+ //
35554
+ delete scope.$target[key];
35555
+ observer.disconnect();
35556
+ }
35557
+ });
35558
+ }
35559
+ });
35560
+
35561
+ observer.observe(parent, { childList: true });
35562
+ },
35563
+ };
35564
+ }
35565
+
35566
+ /**
35567
+ * SSE Provider
35568
+ *
35569
+ * Usage:
35570
+ * const source = $sse('/events', {
35571
+ * onMessage: (data) => console.log(data),
35572
+ * onError: (err) => console.error(err),
35573
+ * withCredentials: true
35574
+ * });
35575
+ *
35576
+ * // later:
35577
+ * source.close();
35578
+ */
35579
+
35580
+ class SseProvider {
35581
+ constructor() {
35582
+ /**
35583
+ * Optional provider-level defaults
35584
+ * @type {ng.SseConfig}
35585
+ */
35586
+ this.defaults = {};
35587
+ }
35588
+
35589
+ /**
35590
+ * Returns the $sse service function
35591
+ * @returns {ng.SseService}
35592
+ */
35593
+ $get =
35594
+ () =>
35595
+ (url, config = {}) => {
35596
+ const finalUrl = this.#buildUrl(url, config.params);
35597
+ return this.#createEventSource(finalUrl, config);
35598
+ };
35599
+
35600
+ /**
35601
+ * Build URL with query parameters
35602
+ * @param {string} url - Base URL
35603
+ * @param {Record<string, any>=} params - Query parameters
35604
+ * @returns {string} URL with serialized query string
35605
+ */
35606
+ #buildUrl(url, params) {
35607
+ if (!params) return url;
35608
+ const query = Object.entries(params)
35609
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
35610
+ .join("&");
35611
+ return url + (url.includes("?") ? "&" : "?") + query;
35612
+ }
35613
+
35614
+ /**
35615
+ * Create and manage an EventSource
35616
+ * @param {string} url - URL for SSE connection
35617
+ * @param {ng.SseConfig} config - Configuration object
35618
+ * @returns {EventSource} The EventSource instance wrapped as SseService
35619
+ */
35620
+ #createEventSource(url, config) {
35621
+ const es = new EventSource(url, {
35622
+ withCredentials: !!config.withCredentials,
35623
+ });
35624
+
35625
+ if (config.onOpen) {
35626
+ es.addEventListener("open", (e) => config.onOpen(e));
35627
+ }
35628
+
35629
+ es.addEventListener("message", (e) => {
35630
+ let data = e.data;
35631
+ try {
35632
+ data = config.transformMessage
35633
+ ? config.transformMessage(data)
35634
+ : JSON.parse(data);
35635
+ } catch {
35636
+ // leave as raw string if not JSON
35637
+ }
35638
+ config.onMessage?.(data, e);
35639
+ });
35640
+
35641
+ if (config.onError) {
35642
+ es.addEventListener("error", (e) => config.onError(e));
35643
+ }
35644
+
35645
+ return es;
35646
+ }
35647
+ }
35648
+
35478
35649
  /**
35479
35650
  * Initializes core `ng` module.
35480
35651
  * @param {import('./angular.js').Angular} angular
@@ -35514,6 +35685,7 @@
35514
35685
  ngController: ngControllerDirective,
35515
35686
  ngDelete: ngDeleteDirective,
35516
35687
  ngDisabled: ngDisabledAriaDirective,
35688
+ ngEl: ngElDirective,
35517
35689
  ngForm: ngFormDirective,
35518
35690
  ngGet: ngGetDirective,
35519
35691
  ngHide: ngHideDirective,
@@ -35534,6 +35706,7 @@
35534
35706
  ngSetter: ngSetterDirective,
35535
35707
  ngShow: ngShowDirective,
35536
35708
  ngStyle: ngStyleDirective,
35709
+ ngSse: ngSseDirective,
35537
35710
  ngSwitch: ngSwitchDirective,
35538
35711
  ngSwitchWhen: ngSwitchWhenDirective,
35539
35712
  ngSwitchDefault: ngSwitchDefaultDirective,
@@ -35605,6 +35778,7 @@
35605
35778
  $router: Router,
35606
35779
  $sce: SceProvider,
35607
35780
  $sceDelegate: SceDelegateProvider,
35781
+ $sse: SseProvider,
35608
35782
  $templateCache: TemplateCacheProvider,
35609
35783
  $templateRequest: TemplateRequestProvider,
35610
35784
  $urlConfig: UrlConfigProvider,
@@ -35647,7 +35821,7 @@
35647
35821
  /**
35648
35822
  * @type {string} `version` from `package.json`
35649
35823
  */
35650
- this.version = "0.9.6"; //inserted via rollup plugin
35824
+ this.version = "0.9.8"; //inserted via rollup plugin
35651
35825
 
35652
35826
  /** @type {!Array<string|any>} */
35653
35827
  this.bootsrappedModules = [];