qcobjects 2.4.105-ts → 2.4.108-ts

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.
Files changed (197) hide show
  1. package/.hintrc +5 -0
  2. package/VERSION +1 -1
  3. package/build/ArrayCollection.js +136 -0
  4. package/build/BackendMicroservice.js +211 -0
  5. package/build/Base64.js +100 -0
  6. package/build/CONFIG.js +85 -0
  7. package/build/Cast.js +53 -0
  8. package/build/Class.js +284 -0
  9. package/build/ClassFactory.js +38 -0
  10. package/build/ComplexStorageCache.js +91 -0
  11. package/build/Component.js +1133 -0
  12. package/build/ComponentFactory.js +113 -0
  13. package/build/ConfigSettings.js +39 -0
  14. package/build/Controller.js +81 -0
  15. package/build/Crypt.js +87 -0
  16. package/build/DDO.js +81 -0
  17. package/build/DOMCreateElement.js +15 -0
  18. package/build/DataStringify.js +22 -0
  19. package/build/DefaultTemplateHandler.js +57 -0
  20. package/build/DocumentLayout.js +20 -0
  21. package/build/Effect.js +46 -0
  22. package/build/Export.js +11 -0
  23. package/build/Import.js +140 -0
  24. package/build/IncrementInstanceID.js +11 -0
  25. package/build/InheritClass.js +194 -0
  26. package/build/LegacyCopy.js +31 -0
  27. package/build/Logger.js +33 -0
  28. package/build/MainProcess.js +549 -0
  29. package/build/NamespaceRef.js +29 -0
  30. package/build/New.js +17 -0
  31. package/build/ObjectName.js +22 -0
  32. package/build/Package.js +67 -0
  33. package/build/PrimaryCollections.js +7 -0
  34. package/build/Processor.js +81 -0
  35. package/build/QCObjects.js +182 -4843
  36. package/build/Ready.js +49 -0
  37. package/build/RegisterClass.js +28 -0
  38. package/build/Service.js +112 -0
  39. package/build/SourceCSS.js +56 -0
  40. package/build/SourceJS.js +73 -0
  41. package/build/Tag.js +77 -0
  42. package/build/Timer.js +30 -0
  43. package/build/Toggle.js +59 -0
  44. package/build/TransitionEffect.js +65 -0
  45. package/build/VO.js +11 -0
  46. package/build/View.js +18 -0
  47. package/build/WidgetsFactory.js +537 -0
  48. package/build/assign.js +32 -0
  49. package/build/asyncLoad.js +43 -0
  50. package/build/basePath.js +32 -0
  51. package/build/captureFalseTouch.js +32 -0
  52. package/build/componentLoader.js +258 -0
  53. package/build/defaultProcessors.js +130 -0
  54. package/build/domain.js +4 -0
  55. package/build/findPackageNodePath.js +47 -0
  56. package/build/getType.js +38 -0
  57. package/build/globalSettings.js +115 -0
  58. package/build/index.d.ts +1045 -0
  59. package/build/index.js +24 -4
  60. package/build/index.mjs +1 -1
  61. package/build/introspection.js +86 -0
  62. package/build/isQCObjects.js +20 -0
  63. package/build/is_a.js +19 -0
  64. package/build/is_forbidden_name.js +15 -0
  65. package/build/is_raw_class.js +7 -0
  66. package/build/loadSDK.js +63 -0
  67. package/build/localStorage.js +19 -0
  68. package/build/make_global.js +24 -0
  69. package/build/mathFunctions.js +7 -0
  70. package/build/platform.js +28 -0
  71. package/build/range.js +17 -0
  72. package/build/routings.js +21 -0
  73. package/build/secretKey.js +5 -0
  74. package/build/serviceLoader.js +300 -0
  75. package/build/shortCode.js +14 -0
  76. package/build/subelements.js +8 -0
  77. package/build/super.js +20 -0
  78. package/build/tag_filter.js +4 -0
  79. package/build/top.js +23 -0
  80. package/build/uniqueID.js +5 -0
  81. package/build/waitUntil.js +31 -0
  82. package/build-esbuild.js +62 -0
  83. package/eslint.config.mjs +87 -0
  84. package/package.json +25 -22
  85. package/public/browser/index.js +6502 -0
  86. package/public/browser/index.js.map +7 -0
  87. package/public/cjs/index.cjs +6586 -0
  88. package/public/cjs/index.cjs.map +7 -0
  89. package/public/esm/index.mjs +6494 -0
  90. package/public/esm/index.mjs.map +7 -0
  91. package/spec/helpers/mock-sdk.helper.ts +5 -0
  92. package/spec/mocks/qcobjects-sdk.mock.ts +1 -0
  93. package/spec/support/jasmine.json +3 -3
  94. package/spec/testsClassFactorySpec.ts +40 -0
  95. package/spec/{testsConfigSpec.js → testsConfigSpec.ts} +2 -2
  96. package/spec/{testsGlobalFeaturesSpec.js → testsGlobalFeaturesSpec.ts} +10 -8
  97. package/spec/{testsSpec.js → testsSpec.ts} +11 -10
  98. package/spec/{testsTypeSpec.js → testsTypeSpec.ts} +5 -3
  99. package/src/ArrayCollection.ts +143 -0
  100. package/src/BackendMicroservice.ts +229 -0
  101. package/src/Base64.ts +92 -0
  102. package/src/CONFIG.ts +96 -0
  103. package/src/Cast.ts +46 -0
  104. package/src/Class.ts +303 -0
  105. package/src/ClassFactory.ts +34 -0
  106. package/src/ComplexStorageCache.ts +97 -0
  107. package/src/Component.ts +1222 -0
  108. package/src/ComponentFactory.ts +122 -0
  109. package/src/ConfigSettings.ts +62 -0
  110. package/src/Controller.ts +90 -0
  111. package/src/Crypt.ts +87 -0
  112. package/src/DDO.ts +93 -0
  113. package/src/DOMCreateElement.ts +12 -0
  114. package/src/DataStringify.ts +19 -0
  115. package/src/DefaultTemplateHandler.ts +55 -0
  116. package/src/DocumentLayout.ts +16 -0
  117. package/src/Effect.ts +56 -0
  118. package/src/Export.ts +8 -0
  119. package/src/Import.ts +135 -0
  120. package/src/IncrementInstanceID.ts +8 -0
  121. package/src/InheritClass.ts +210 -0
  122. package/src/LegacyCopy.ts +27 -0
  123. package/src/Logger.ts +32 -0
  124. package/src/MainProcess.ts +629 -0
  125. package/src/NamespaceRef.ts +26 -0
  126. package/src/New.ts +15 -0
  127. package/src/ObjectName.ts +16 -0
  128. package/src/Package.ts +67 -0
  129. package/src/PrimaryCollections.ts +7 -0
  130. package/src/Processor.ts +93 -0
  131. package/src/QCObjects.ts +100 -0
  132. package/src/Ready.ts +44 -0
  133. package/src/RegisterClass.ts +26 -0
  134. package/src/Service.ts +127 -0
  135. package/src/SourceCSS.ts +59 -0
  136. package/src/SourceJS.ts +76 -0
  137. package/src/Tag.ts +76 -0
  138. package/src/Timer.ts +42 -0
  139. package/src/Toggle.ts +65 -0
  140. package/src/TransitionEffect.ts +80 -0
  141. package/src/VO.ts +8 -0
  142. package/src/View.ts +17 -0
  143. package/src/WidgetsFactory.ts +543 -0
  144. package/src/assign.ts +33 -0
  145. package/src/asyncLoad.ts +42 -0
  146. package/src/basePath.ts +29 -0
  147. package/src/captureFalseTouch.ts +29 -0
  148. package/src/componentLoader.ts +252 -0
  149. package/src/defaultProcessors.ts +145 -0
  150. package/src/domain.ts +1 -0
  151. package/src/findPackageNodePath.ts +43 -0
  152. package/src/getType.ts +36 -0
  153. package/src/globalSettings.ts +118 -0
  154. package/src/index.mts +1 -1
  155. package/src/index.ts +1 -1
  156. package/src/introspection.ts +80 -0
  157. package/src/isQCObjects.ts +19 -0
  158. package/src/is_a.ts +16 -0
  159. package/src/is_forbidden_name.ts +12 -0
  160. package/src/is_raw_class.ts +3 -0
  161. package/src/loadSDK.ts +59 -0
  162. package/src/localStorage.ts +17 -0
  163. package/src/make_global.ts +19 -0
  164. package/src/mathFunctions.ts +3 -0
  165. package/src/platform.ts +30 -0
  166. package/src/range.ts +15 -0
  167. package/src/routings.ts +18 -0
  168. package/src/secretKey.ts +3 -0
  169. package/src/serviceLoader.ts +306 -0
  170. package/src/shortCode.ts +11 -0
  171. package/src/subelements.ts +4 -0
  172. package/src/super.ts +17 -0
  173. package/src/tag_filter.ts +1 -0
  174. package/src/top.ts +111 -0
  175. package/src/types/global/index.d.ts +597 -0
  176. package/src/uniqueID.ts +3 -0
  177. package/src/waitUntil.ts +26 -0
  178. package/tsconfig.d.json +35 -8
  179. package/tsconfig.jasmine.json +39 -0
  180. package/tsconfig.json +46 -12
  181. package/.eslintignore +0 -5
  182. package/.eslintrc.cjs +0 -21
  183. package/.eslintrc.json +0 -24
  184. package/browser/QCObjects.js +0 -2
  185. package/browser/QCObjects.js.map +0 -7
  186. package/browser/chunks/chunk-O2PFFZVJ.js +0 -713
  187. package/browser/chunks/chunk-O2PFFZVJ.js.map +0 -7
  188. package/browser/chunks/chunk-TBLBK5VV.js +0 -713
  189. package/browser/chunks/chunk-TBLBK5VV.js.map +0 -7
  190. package/browser/chunks/chunk-ZYLXOA35.js +0 -713
  191. package/browser/chunks/chunk-ZYLXOA35.js.map +0 -7
  192. package/browser/index.js +0 -2
  193. package/browser/index.js.map +0 -7
  194. package/spec/testsClassFactorySpec.js +0 -41
  195. package/src/QCObjects.js +0 -5247
  196. package/src/index.d.ts +0 -8
  197. package/types/index.d.ts +0 -472
@@ -0,0 +1,1222 @@
1
+ import { Base64 } from "./Base64";
2
+ import { _basePath_ } from "./basePath";
3
+ import { _Cast } from "./Cast";
4
+ import { ClassFactory } from "./ClassFactory";
5
+ import { _buildComponentsFromElements_, ComponentURI } from "./ComponentFactory";
6
+ import { _DataStringify } from "./DataStringify";
7
+ import { _domain_ } from "./domain";
8
+ import { _DOMCreateElement } from "./DOMCreateElement";
9
+ import { __getType__ } from "./getType";
10
+ import { InheritClass } from "./InheritClass";
11
+ import { _methods_, _protected_code_ } from "./introspection";
12
+ import { is_a } from "./is_a";
13
+ import { isQCObjects_Object } from "./isQCObjects";
14
+ import { logger } from "./Logger";
15
+ import { New } from "./New";
16
+ import { Package } from "./Package";
17
+ import { isBrowser } from "./platform";
18
+ import { Processor } from "./Processor";
19
+ import { __routing_params__, __valid_routing_way__, __valid_routings__ } from "./routings";
20
+ import { _top, componentsStack } from "./top";
21
+ import { CONFIG } from "./CONFIG";
22
+ import { serviceLoader } from "./serviceLoader";
23
+ import { _tag_filter_ } from "./tag_filter";
24
+ import { componentLoader } from "./componentLoader";
25
+ import { IComponent, IController, IEffect, IProcessor, IQCObjectsElement, IQCObjectsShadowedElement, IView, TBody, TComponentDoneResponse, TComponentParams, TComponentRouting, TComponentRoutings } from "types";
26
+
27
+ export class Component extends InheritClass implements IComponent {
28
+ static shadowed: boolean | undefined = false;
29
+ static cached: any = true;
30
+ [key: string]: any;
31
+ name!: string;
32
+ templateURI!: string;
33
+ url!:string;
34
+ tplsource!: string;
35
+ tplextension!: string;
36
+ template!: string;
37
+ validRoutingWays: string[] = ["pathname", "hash", "search"];
38
+ basePath = _basePath_;
39
+ domain = _domain_;
40
+ templateHandler = "DefaultTemplateHandler";
41
+ processorHandler?: IProcessor;
42
+ routingWay: string | null = null;
43
+ routingNodes: (IQCObjectsElement | HTMLElement)[] = [];
44
+ routings: TComponentRoutings = [];
45
+ routingPath = "";
46
+ routingPaths: string[] = [];
47
+ _componentHelpers: any[] = [];
48
+ subcomponents: any[] = [];
49
+ splashScreenComponent?: IComponent = undefined;
50
+ controller?: IController = undefined;
51
+ routingController?: IController = undefined;
52
+
53
+ view?: IView = undefined;
54
+ effect?: IEffect = undefined;
55
+ effectClass!: string;
56
+ method = "GET";
57
+ cached?: boolean = true;
58
+ __promise__?: Promise<any> | null = null;
59
+ data!: any;
60
+ __namespace?: string = undefined;
61
+ protected _parsedAssignmentText!: string;
62
+ protected __shadowRoot: any;
63
+ protected _serviceClassName: string | null = null;
64
+ enableServiceClass?: boolean | undefined = true;
65
+ serviceInstance: any;
66
+ serviceData: any;
67
+ shadowed?: boolean = false;
68
+ container: any;
69
+ innerHTML: any;
70
+ reload: any;
71
+ static subcomponents: any;
72
+ assignRoutingParams?: boolean = true;
73
+ responseTo?: string | undefined;
74
+ static responseTo?: string | undefined;
75
+
76
+ constructor({
77
+ __parent__,
78
+ templateURI = "",
79
+ template,
80
+ tplsource = "default",
81
+ tplextension,
82
+ url = "",
83
+ name = "",
84
+ method = "GET",
85
+ data = {},
86
+ reload = false,
87
+ shadowed = false,
88
+ cached = true,
89
+ enableServiceClass,
90
+ assignRoutingParams = true,
91
+ _body = _DOMCreateElement("div"),
92
+ __promise__ = null,
93
+ __shadowRoot,
94
+ body,
95
+ shadowRoot,
96
+ splashScreenComponent,
97
+ controller,
98
+ view
99
+ }: TComponentParams) {
100
+ if (arguments.length < 1) {
101
+ throw Error("No arguments in component. You must at least give one argument.");
102
+ }
103
+ super({
104
+ __parent__,
105
+ templateURI,
106
+ template,
107
+ tplsource,
108
+ tplextension,
109
+ url,
110
+ name,
111
+ method,
112
+ data,
113
+ reload,
114
+ shadowed,
115
+ cached,
116
+ enableServiceClass,
117
+ assignRoutingParams,
118
+ _body,
119
+ __promise__,
120
+ __shadowRoot,
121
+ body,
122
+ shadowRoot,
123
+ splashScreenComponent,
124
+ controller,
125
+ view
126
+ });
127
+ const self = this;
128
+
129
+ if (typeof self.name === "undefined") {
130
+ logger.warn("A name is not defined for " + __getType__(self));
131
+ }
132
+
133
+ self.routingWay = CONFIG.get("routingWay");
134
+
135
+ self.processorHandler = new Processor({
136
+ component: self
137
+ });
138
+
139
+ /* assign body data attributes to data */
140
+ self.data = (typeof self.data === "undefined" || self.data === null) ? ({}) : (self.data);
141
+ self.data = Object.assign(self.data, self.dataAttributes);
142
+
143
+ self.createServiceInstance()
144
+ .then(() => {
145
+ if (typeof self.__new__ === "function") {
146
+ self.__new__(self);
147
+ }
148
+
149
+ self._generateRoutingPaths(self.body)
150
+ .then(function () {
151
+ self._reroute_()
152
+ .then(function () {
153
+ return self.rebuild()
154
+ .then(function () {
155
+ logger.info(`Component._new_ The component ${self.name} was built successfully!`);
156
+ }).catch(function (standardResponse) {
157
+ logger.warn(`Component._new_ Something went wrong building the component ${self.name}`);
158
+ console.error(standardResponse);
159
+ });
160
+ }).catch((e: any) => {
161
+ throw Error(`Unexpected error ${e}`);
162
+ });
163
+ }).catch((e: any) => {
164
+ throw Error(`Unexpected error ${e}`);
165
+ });
166
+
167
+ }).catch((e: any) => {
168
+ throw Error(`Unexpected error. ${e}`);
169
+ });
170
+
171
+ }
172
+
173
+ set cacheIndex(value) {
174
+ // readonly
175
+ logger.debug("[cacheIndex] This property is readonly");
176
+ }
177
+
178
+ get cacheIndex() {
179
+ const self = this;
180
+ const __routing_path__ = _DataStringify(self.routingPath);
181
+ return Base64.encode(self.name + __routing_path__);
182
+ }
183
+
184
+ set parsedAssignmentText(value: string) {
185
+ // readonly
186
+ logger.debug("[parsedAssignmentText] This property is readonly");
187
+ }
188
+
189
+ get parsedAssignmentText(): string {
190
+ const self = this;
191
+ self._parsedAssignmentText = self.parseTemplate(self.template);
192
+ if (typeof self._parsedAssignmentText === "undefined") {
193
+ throw Error(`[Component][${this.name}][parsedAssignmentText] Could not generate content!`);
194
+ }
195
+ return self._parsedAssignmentText;
196
+ }
197
+
198
+
199
+ set shadowRoot(value: IQCObjectsShadowedElement) {
200
+ const self = this;
201
+ if (typeof self.__shadowRoot === "undefined") {
202
+ self.__shadowRoot = value;
203
+ } else {
204
+ logger.debug("[shadowRoot] This property can only be assigned once!");
205
+ }
206
+ }
207
+
208
+ get shadowRoot(): IQCObjectsShadowedElement {
209
+ const self = this;
210
+ return self.__shadowRoot as IQCObjectsShadowedElement;
211
+ }
212
+
213
+
214
+ set routingSelected(value: TComponentRouting[]) {
215
+ logger.debug("[routingSelected] This is a read-only property of the component");
216
+ }
217
+
218
+ get routingSelected(): TComponentRouting[] {
219
+ const self = this;
220
+ return __valid_routings__(self.routings, self.routingPath);
221
+ }
222
+
223
+ set routingParams(value) {
224
+ logger.debug("[routingParams] This is a read-only property of the component");
225
+ }
226
+
227
+ get routingParams(): object {
228
+ const component = this;
229
+ return [{}].concat(component.routingSelected.map(function (routing: any) {
230
+ return __routing_params__(routing, component.routingPath);
231
+ })).reduce(function (accumulator, colData) {
232
+ return Object.assign(accumulator, colData);
233
+ });
234
+ }
235
+
236
+
237
+ set serviceClassName(_serviceClassName: string) {
238
+ this._serviceClassName = _serviceClassName;
239
+ }
240
+
241
+ get serviceClassName(): string | null {
242
+ let _serviceClassName: string | null = "";
243
+ if (isBrowser) {
244
+ _serviceClassName = ((this.body as HTMLElement).getAttribute("serviceClass") !== null) ? ((this.body as HTMLElement).getAttribute("serviceClass")) : (
245
+ this._serviceClassName
246
+ );
247
+ } else {
248
+ _serviceClassName = this._serviceClassName;
249
+ }
250
+ return _serviceClassName;
251
+ }
252
+
253
+ protected get responseToData ():boolean {
254
+ let _response_to_data_:boolean = false;
255
+ if (isBrowser) {
256
+ const responseToAttr = (this.body as HTMLElement).getAttribute("response-to");
257
+ _response_to_data_ = responseToAttr === "data" || this.responseTo === "data";
258
+ } else {
259
+ _response_to_data_ = this.responseTo === "data";
260
+ }
261
+ return _response_to_data_;
262
+ }
263
+
264
+ protected get responseToTemplate ():boolean {
265
+ let _response_to_template_:boolean = false;
266
+ if (isBrowser) {
267
+ const responseToAttr = (this.body as HTMLElement).getAttribute("response-to");
268
+ _response_to_template_ = responseToAttr === "template" || this.responseTo === "template";
269
+ } else {
270
+ _response_to_template_ = this.responseTo === "template";
271
+ }
272
+ return _response_to_template_;
273
+ }
274
+
275
+ createServiceInstance(): Promise<JSON | string | null> {
276
+ const component = this;
277
+ let data = this.data;
278
+ let __serviceClass: any;
279
+ const __classDefinition = component.getClass().__definition;
280
+ const _serviceClassName = component.serviceClassName;
281
+
282
+ return new Promise(function (resolve, reject) {
283
+ /* __enable_service_class__ = true by default */
284
+ const __enable_service_class__ = component.enableServiceClass;
285
+ let _response_to_data_ = component.responseToData;
286
+ let _response_to_template_ = component.responseToTemplate;
287
+
288
+ if (__enable_service_class__ && _serviceClassName !== null) {
289
+ __serviceClass = ClassFactory(_serviceClassName);
290
+ }
291
+ if (!_response_to_data_ && __classDefinition && Object.hasOwn(__classDefinition, "responseTo")) {
292
+ _response_to_data_ = (__classDefinition.responseTo === "data");
293
+ } else if (!_response_to_data_ && Object.hasOwn(ClassFactory("Component"), "responseTo")) {
294
+ _response_to_data_ = ((ClassFactory("Component") as Component).responseTo === "data");
295
+ }
296
+ if (!_response_to_template_ && __classDefinition && Object.hasOwn(__classDefinition, "responseTo")) {
297
+ _response_to_template_ = (__classDefinition.responseTo === "template");
298
+ } else if (!_response_to_template_ && Object.hasOwn(ClassFactory("Component"), "responseTo")) {
299
+ _response_to_template_ = ((ClassFactory("Component") as Component).responseTo === "template");
300
+ }
301
+
302
+ if (typeof __serviceClass !== "undefined" &&
303
+ (typeof __enable_service_class__ !== "undefined" &&
304
+ __enable_service_class__ === true) &&
305
+ (_response_to_data_ || _response_to_template_)
306
+ ) {
307
+ logger.info("Loading service " + _serviceClassName);
308
+ const serviceInstance = New(__serviceClass, {
309
+ data
310
+ });
311
+ (serviceLoader(serviceInstance) as Promise<any>)?.then(function ({
312
+ service
313
+ }: { request: any, service: any }) {
314
+ let serviceResponse;
315
+ if (typeof service.JSONresponse !== "undefined" && service.JSONresponse !== null) {
316
+ serviceResponse = service.JSONresponse;
317
+ } else {
318
+ serviceResponse = service.template;
319
+ }
320
+ if (_response_to_data_) {
321
+ if (typeof data === "object" && typeof serviceResponse === "object") {
322
+ data = Object.assign(data, serviceResponse);
323
+ } else {
324
+ data = serviceResponse;
325
+ }
326
+ component.data = data;
327
+ }
328
+ component.serviceInstance = serviceInstance;
329
+ component.serviceData = data;
330
+
331
+ if (_response_to_template_) {
332
+ component.template = serviceResponse;
333
+ }
334
+ resolve(serviceResponse);
335
+ }, function (rejectedResponse: Error) {
336
+ logger.debug(`Service loading rejected for ${_serviceClassName} in ${component.name}`);
337
+ reject(rejectedResponse);
338
+ }).catch(function (e: any) {
339
+ logger.debug("Something went wroing while trying to load the service " + _serviceClassName);
340
+ throw Error(`Error loading ${_serviceClassName} for ${component.name}. Detail: ${e}`);
341
+ });
342
+ } else {
343
+ resolve(null);
344
+ }
345
+ });
346
+ }
347
+
348
+ _bindroute_() {
349
+ const _component_ = this;
350
+ if (!(_component_ as any)._bindroute_.loaded) {
351
+ if (isBrowser) {
352
+
353
+ (_component_.hostElements("a") as unknown as HTMLAnchorElement[]).map(function (a: HTMLAnchorElement) {
354
+ (a as any).oldclick = a.onclick;
355
+ a.onclick = function (e) {
356
+ let _ret_ = true;
357
+ if (!_top.global.get("routingPaths")) {
358
+ _top.global.set("routingPaths", []);
359
+ }
360
+ const routingWay = CONFIG.get("routingWay");
361
+ const routingPath = (e.target as any)[routingWay];
362
+ if (_top.global.get("routingPaths").includes(routingPath) &&
363
+ (e.target as any)[routingWay] !== (location as any)[routingWay] &&
364
+ (e.target as HTMLAnchorElement).href !== document.location.href
365
+ ) {
366
+ logger.debug("A ROUTING WAS FOUND: " + routingPath);
367
+ window.history.pushState({
368
+ href: (e.target as HTMLAnchorElement).href
369
+ }, (e?.target as HTMLAnchorElement)?.href, (e.target as HTMLAnchorElement).href);
370
+ Component.route().catch((e) => { throw Error(`Unexpected error: ${e}`); });
371
+ _ret_ = false;
372
+ } else {
373
+ logger.debug("NO ROUTING FOUND FOR: " + routingPath);
374
+ }
375
+ if (typeof (e.target as any).oldclick !== "undefined" && typeof (e.target as any).oldclick === "function") {
376
+ (e.target as any).oldclick.call(e.target, e);
377
+ }
378
+ return _ret_;
379
+ };
380
+ return null;
381
+ });
382
+
383
+ } else {
384
+ // not yet implemented.
385
+ }
386
+ (_component_ as any)._bindroute_.loaded = true;
387
+ } else {
388
+ logger.debug(`Routes already bound to popstate events for ${_component_.name}`);
389
+ }
390
+
391
+ }
392
+
393
+ done(standardResponse?: TComponentDoneResponse): Promise<TComponentDoneResponse> {
394
+ const _ret_ = new Promise<TComponentDoneResponse>((resolve) => {
395
+ if (typeof standardResponse !== "undefined") {
396
+ const { request, component } = standardResponse;
397
+ resolve({ request, component });
398
+ } else {
399
+ resolve({ request: undefined, component: undefined });
400
+ }
401
+ });
402
+ return _ret_;
403
+ }
404
+
405
+ createControllerInstance(): Promise<{ component: IComponent, controller: IController }> {
406
+ let _Controller: any;
407
+ if (isBrowser) {
408
+ if (typeof this.body === "undefined") {
409
+ throw new Error("The component has no body");
410
+ }
411
+ var controllerName = (this.body as HTMLElement).getAttribute("controllerClass");
412
+ if (!controllerName) {
413
+ controllerName = "Controller";
414
+ }
415
+ _Controller = ClassFactory(controllerName);
416
+ if (typeof _Controller !== "undefined") {
417
+ this.controller = New(_Controller, {
418
+ component: this
419
+ });
420
+ }
421
+
422
+ }
423
+
424
+ return new Promise((resolve, reject) => {
425
+ if (isBrowser) {
426
+ if (typeof _Controller !== "undefined" && typeof this.controller !== "undefined") {
427
+ if (typeof (this.controller).done === "function") {
428
+ try {
429
+ this.controller.done.call(this.controller);
430
+ } catch (e: any) {
431
+ throw Error(e);
432
+ }
433
+ } else {
434
+ logger.debug(`${controllerName} does not have a done() method.`);
435
+ reject(new Error(`${controllerName} does not have a done() method.`));
436
+ }
437
+ if (typeof this.controller.createRoutingController === "function") {
438
+ this.controller.createRoutingController.call(this.controller);
439
+ } else {
440
+ logger.debug(`${controllerName} does not have a createRoutingController() method.`);
441
+ }
442
+ }
443
+ }
444
+ resolve({ component: this, controller: this.controller as IController });
445
+ });
446
+ }
447
+
448
+ createEffectInstance(): Promise<{ component: Component, effect: IEffect }> {
449
+ const _component_ = this;
450
+ return new Promise(function (resolve) {
451
+ if (isBrowser) {
452
+ const effectClassName = (_component_.body as HTMLElement)?.getAttribute("effectClass");
453
+ let applyEffectTo = (_component_.body as HTMLElement)?.getAttribute("apply-effect-to");
454
+ applyEffectTo = (applyEffectTo !== null) ? (applyEffectTo) : ("load");
455
+ if (effectClassName !== null && applyEffectTo === "observe") {
456
+ _component_.applyObserveTransitionEffect(effectClassName);
457
+ } else if (effectClassName !== null && applyEffectTo === "load") {
458
+ _component_.applyTransitionEffect(effectClassName);
459
+ }
460
+ }
461
+ resolve({ component: _component_, effect: _component_.effect as IEffect });
462
+ });
463
+ }
464
+
465
+ createViewInstance(): Promise<{ component: Component, view: IView }> {
466
+ const _component_ = this;
467
+ return new Promise(function (resolve) {
468
+ const viewName = (isBrowser) ? ((_component_.body as HTMLElement).getAttribute("viewClass")) : (null);
469
+ if (viewName !== null) {
470
+ const _View = ClassFactory(viewName);
471
+ if (typeof _View !== "undefined") {
472
+ _component_.view = New(_View, {
473
+ component: _component_
474
+ }); // Initializes the main view for the component
475
+ if (Object.hasOwn(_component_.view as object, "done") && typeof _component_.view?.done === "function") {
476
+ _component_.view?.done.call(_component_.view);
477
+ }
478
+ }
479
+
480
+ }
481
+ resolve({ component: _component_, view: _component_.view as IView });
482
+
483
+ });
484
+ }
485
+
486
+ __done__(): Promise<unknown> {
487
+ const _component_ = this;
488
+ const componentDone = function () {
489
+ if (typeof _component_ === "undefined") {
490
+ throw new Error("componentDone() has lost its context");
491
+ }
492
+ if (typeof _component_.body === "undefined") {
493
+ throw new Error("The component has no body");
494
+ }
495
+
496
+ (async () => {
497
+ await _component_.createViewInstance();
498
+ await _component_.createControllerInstance();
499
+ await _component_.createEffectInstance();
500
+ })()
501
+ .catch ((e:any) => {
502
+ throw new Error (`Unknown error ${e}.`);
503
+ });
504
+
505
+ logger.debug(`Trying to run component helpers for ${_component_.name}...`);
506
+ try {
507
+ _component_.runComponentHelpers();
508
+ logger.debug(`Component helpers for ${_component_.name} executed.`);
509
+ } catch (e: any) {
510
+ logger.debug(`Component helpers for ${_component_.name} could not be executed.`);
511
+ throw Error(e);
512
+ }
513
+
514
+ _component_.subcomponents = _component_.__buildSubComponents__();
515
+
516
+ _component_._bindroute_();
517
+ if (isBrowser) {
518
+ (_component_.body as HTMLElement).setAttribute("loaded", "true");
519
+ }
520
+ };
521
+
522
+ return new Promise(function (resolve, reject) {
523
+ try {
524
+ resolve(componentDone.call(_component_));
525
+ } catch (e:any) {
526
+ reject(new Error (e));
527
+ }
528
+ });
529
+
530
+ }
531
+
532
+ hostElements(tagFilter: string): (IQCObjectsElement | HTMLElement | IQCObjectsShadowedElement)[] {
533
+ const _component_ = this;
534
+ let elementList: (IQCObjectsElement | HTMLElement | IQCObjectsShadowedElement)[] = [];
535
+ if (isBrowser) {
536
+ elementList = (_component_.shadowed && (typeof _component_.shadowRoot !== "undefined")) ? (
537
+ _component_.shadowRoot.subelements(tagFilter) as IQCObjectsShadowedElement[]
538
+ ) : (
539
+ (_component_.body as IQCObjectsElement).subelements(tagFilter)
540
+ );
541
+
542
+ }
543
+ return elementList;
544
+ }
545
+
546
+ get subtags(): (HTMLElement | IQCObjectsElement | IQCObjectsShadowedElement)[] {
547
+ const _component_ = this;
548
+ const tagFilter = _tag_filter_;
549
+ return _component_.hostElements(tagFilter);
550
+ }
551
+
552
+ get bodyAttributes() {
553
+ const _component_ = this;
554
+ const c = _component_.body;
555
+ return (isBrowser) ? ([...(c as HTMLElement).getAttributeNames()].map(a => { return { [a]: (c as HTMLElement).getAttribute(a) }; }).reduce((accumulator, colData) => { return Object.assign(accumulator, colData); })) : ({});
556
+ }
557
+
558
+ get dataAttributes() {
559
+ const _component_ = this;
560
+ const c = _component_.body;
561
+ return (isBrowser) ? ([{}].concat([...(c as HTMLElement).getAttributeNames()].filter(n => n.startsWith("data-")).map(a => { return { [a.split("-")[1]]: (c as HTMLElement).getAttribute(a) }; })).reduce((accumulator, colData) => { return Object.assign(accumulator, colData); })) : ({});
562
+ }
563
+
564
+ __buildSubComponents__(rebuildObjects = false):any {
565
+ const _component_: Component = this as Component;
566
+ let elementList = _component_.subtags;
567
+ if (!rebuildObjects) {
568
+ elementList = (elementList as HTMLElement[]).filter((t: HTMLElement) => t.getAttribute("loaded") !== "true") as unknown[] as IQCObjectsElement[];
569
+ }
570
+ if ((typeof _component_ !== "undefined") || (_component_ as Component).subcomponents.length < 1) {
571
+ _component_.subcomponents = _buildComponentsFromElements_(elementList as HTMLElement[], _component_);
572
+ }
573
+ return _component_.subcomponents;
574
+ }
575
+
576
+ fail(standardResponse: { error: any; component: Component; }): Promise<{ error: any; component: Component; }> {
577
+ const _ret_ = new Promise<{ error: any; component: Component; }>((resolve, reject) => {
578
+ if (typeof standardResponse !== "undefined") {
579
+ const { error, component } = standardResponse;
580
+ resolve({ error, component });
581
+ } else {
582
+ reject( new Error (" Unknown error."));
583
+ }
584
+ });
585
+ return _ret_;
586
+ }
587
+
588
+ set(key: string, value: any) {
589
+ this[key] = value;
590
+ }
591
+
592
+ get(key: string, _defaultValue?: string):any {
593
+ return this[key] || _defaultValue;
594
+ }
595
+
596
+ feedComponent(): Promise<any> {
597
+ const _component_ = this;
598
+ logger.debug(`[Component][${this.name}][feedComponent] start feeding component...`);
599
+ const _feedComponent_InBrowser = function (_component_: Component):any {
600
+ if (typeof _component_.container === "undefined" && typeof _component_.body === "undefined") {
601
+ logger.warn("COMPONENT {{NAME}} has an undefined container and body".replace("{{NAME}}", _component_.name));
602
+ return;
603
+ }
604
+ const container = (typeof _component_.container === "undefined" || _component_.container === null) ? (_component_.body) : (_component_.container);
605
+ const parsedAssignmentText = _component_.parsedAssignmentText;
606
+ _component_.innerHTML = parsedAssignmentText;
607
+ if (_component_.shadowed) {
608
+ logger.debug("COMPONENT {{NAME}} is shadowed".replace("{{NAME}}", _component_.name));
609
+ logger.debug("Preparing slots for Shadowed COMPONENT {{NAME}}".replace("{{NAME}}", _component_.name));
610
+ const tmp_shadowContainer = _DOMCreateElement("div");
611
+ container.subelements("[slot]").map(
612
+ (c: { parentElement: any; }):any => {
613
+ if (c.parentElement === container) {
614
+ tmp_shadowContainer.appendChild(c as any);
615
+ }
616
+ return c;
617
+ });
618
+ logger.debug("Creating shadowedContainer for COMPONENT {{NAME}}".replace("{{NAME}}", _component_.name));
619
+ const shadowContainer = _DOMCreateElement("div");
620
+ shadowContainer.classList.add("shadowHost");
621
+ try {
622
+ _component_.shadowRoot = shadowContainer.attachShadow({
623
+ mode: "open"
624
+ }) as IQCObjectsShadowedElement;
625
+ } catch (e:any) {
626
+ logger.debug(`An error ocurred: ${e}.`);
627
+ try {
628
+ logger.debug("Shadowed COMPONENT {{NAME}} is repeated".replace("{{NAME}}", _component_.name));
629
+ _component_.shadowRoot = shadowContainer.shadowRoot as IQCObjectsShadowedElement;
630
+ } catch (e:any) {
631
+ logger.debug(`An error ocurred: ${e}.`);
632
+ logger.warn("Shadowed COMPONENT {{NAME}} is not allowed on this browser".replace("{{NAME}}", _component_.name));
633
+ }
634
+ }
635
+ if (typeof _component_.shadowRoot !== "undefined" && _component_.shadowRoot !== null) {
636
+ if (_component_.reload) {
637
+ logger.debug("FORCED RELOADING OF CONTAINER FOR Shadowed COMPONENT {{NAME}}".replace("{{NAME}}", _component_.name));
638
+ if (shadowContainer !== null && shadowContainer.shadowRoot !== null) {
639
+ shadowContainer.shadowRoot.innerHTML = _component_.innerHTML;
640
+ }
641
+ } else {
642
+ tmp_shadowContainer.innerHTML = _component_.parseTemplate(tmp_shadowContainer.innerHTML);
643
+ logger.debug("ADDING Shadowed COMPONENT {{NAME}} ".replace("{{NAME}}", _component_.name));
644
+ if (shadowContainer !== null && shadowContainer.shadowRoot !== null) {
645
+ shadowContainer.shadowRoot.innerHTML += _component_.innerHTML;
646
+ }
647
+ }
648
+ logger.debug("ADDING Slots to Shadowed COMPONENT {{NAME}} ".replace("{{NAME}}", _component_.name));
649
+ shadowContainer.innerHTML += tmp_shadowContainer.innerHTML;
650
+ logger.debug("APPENDING Shadowed COMPONENT {{NAME}} to Container ".replace("{{NAME}}", _component_.name));
651
+ const qs = container.querySelector(".shadowHost");
652
+ if (!(typeof qs !== "undefined" && qs !== null)) {
653
+ container.appendChild(shadowContainer);
654
+ } else {
655
+ logger.debug("Shadowed Container for COMPONENT {{NAME}} is already present in the tree ".replace("{{NAME}}", _component_.name));
656
+ if (_component_.shadowRoot !== null && shadowContainer.shadowRoot !== null) {
657
+ _component_.shadowRoot.innerHTML = shadowContainer.shadowRoot.innerHTML;
658
+ }
659
+ }
660
+ } else {
661
+ logger.warn("Shadowed COMPONENT {{NAME}} is bad configured".replace("{{NAME}}", _component_.name));
662
+ }
663
+ } else {
664
+ if (_component_.reload) {
665
+ logger.debug("FORCED RELOADING OF CONTAINER FOR COMPONENT {{NAME}}".replace("{{NAME}}", _component_.name));
666
+ container.innerHTML = _component_.innerHTML;
667
+ } else if (container && _component_) {
668
+ logger.debug("ADDING COMPONENT {{NAME}} ".replace("{{NAME}}", _component_.name));
669
+ container.innerHTML += _component_.innerHTML;
670
+ } else {
671
+ logger.warn("COMPONENT {{NAME}} is not added to the DOM".replace("{{NAME}}", _component_.name));
672
+ }
673
+ }
674
+
675
+ };
676
+
677
+ const _feedComponent_InNode = function (_component_: Component):any {
678
+ const parsedAssignmentText = _component_.parsedAssignmentText;
679
+ _component_.innerHTML = parsedAssignmentText;
680
+ };
681
+
682
+ let _ret_;
683
+ if (!is_a(_component_, "Component")) {
684
+ logger.warn("Trying to feed a non component object");
685
+ return Promise.reject(new Error (`Trying to feed a non component object ${typeof _component_}`));
686
+ }
687
+ return new Promise <any> ((resolve, reject) => {
688
+ if (isBrowser) {
689
+ try {
690
+ _ret_ = _feedComponent_InBrowser(_component_);
691
+ resolve(_ret_);
692
+ } catch (e:any) {
693
+ reject (new Error(e));
694
+ }
695
+ } else {
696
+ try {
697
+ _ret_ = _feedComponent_InNode(_component_);
698
+ resolve(_ret_);
699
+ } catch (e:any){
700
+ reject (new Error (e));
701
+ }
702
+
703
+ }
704
+
705
+ });
706
+ }
707
+
708
+ rebuild(): Promise<{ request?: XMLHttpRequest, component: Component }> {
709
+ const _component = this as Component;
710
+ var _promise = new Promise<{ request?: XMLHttpRequest, component: Component }>(function (resolve, reject) {
711
+ if (typeof _component === "undefined" || _component === null) {
712
+ reject(new Error ("Component is undefined"));
713
+ }
714
+ if (isQCObjects_Object(_component) && is_a(_component, "Component")) {
715
+ switch (true) {
716
+ case (_component.get("tplsource") === "none"):
717
+ logger.debug("Component " + _component.name + " has specified template-source=none, so no template load was done");
718
+ var standardResponse = {
719
+ request: undefined,
720
+ component: _component
721
+ };
722
+ _component.__done__().then(function () {
723
+ if (typeof _component.done === "function") {
724
+ _component.done.call(_component, standardResponse)
725
+ .catch((e:any)=> {
726
+ logger.debug(`It was an error while calling done() in ${_component.name}: ${e}`);
727
+ });
728
+ }
729
+ resolve.call(_promise, standardResponse);
730
+ }, function () {
731
+ reject.call(_promise, standardResponse);
732
+ });
733
+ break;
734
+ case (_component.get("tplsource") === "inline"):
735
+ logger.debug("Component " + _component.name + " has specified template-source=inline, so it is assumed that template is already declared");
736
+ (async (_component) => {
737
+ await _component.feedComponent.bind(_component)();
738
+ })(_component)
739
+ .catch((e:any)=> {
740
+ logger.debug(`It was not possible to feed the component ${_component.name}: ${e}`);
741
+ });
742
+ var standardResponse = {
743
+ request: undefined,
744
+ component: _component
745
+ };
746
+ _component.__done__().then(async () => {
747
+ if (typeof _component.done === "function") {
748
+ await _component.done(standardResponse);
749
+ }
750
+ resolve.call(_promise, standardResponse);
751
+ }, function () {
752
+ reject.call(_promise, standardResponse);
753
+ });
754
+ break;
755
+ case (_component.get("tplsource") === "default" &&
756
+ _component.get("templateURI") !== ""):
757
+ _component.set("url", _component.get("basePath") + _component.get("templateURI"));
758
+ (componentLoader(_component, false))?.then(
759
+ function (standardResponse: any) {
760
+ resolve.call(_promise, standardResponse);
761
+ },
762
+ function (standardResponse: any) {
763
+ reject.call(_promise, standardResponse);
764
+ });
765
+ break;
766
+ case (_component.get("tplsource") === "external" &&
767
+ _component.get("templateURI") !== ""):
768
+ _component.set("url", _component.get("templateURI"));
769
+ (componentLoader(_component, false)).then(
770
+ function (standardResponse: any) {
771
+ resolve.call(_promise, standardResponse);
772
+ },
773
+ function (standardResponse: any) {
774
+ reject.call(_promise, standardResponse);
775
+ });
776
+ break;
777
+ case _component.get("tplsource") === "default" && _component.get("templateURI", "") === "":
778
+ logger.debug(`Component ${_component.name} template-source is ${_component.get("tplsource")} and no templateURI is present`);
779
+ reject.call(_promise, `Component ${_component.name} template-source is ${_component.get("tplsource")} and no templateURI is present`);
780
+ break;
781
+ default:
782
+ logger.debug("Component " + _component.name + " will not be rebuilt because no templateURI is present");
783
+ reject.call(_promise, {
784
+ request: null,
785
+ component: _component
786
+ });
787
+ break;
788
+ }
789
+
790
+ }
791
+ });
792
+ return _promise;
793
+ }
794
+
795
+ Cast(oClass: any):any {
796
+ /* Cast method for components has been deprecated. Don't use this method, it is available only for compatibility purposes */
797
+ const o = _methods_(oClass).map((m):any => (m as Function).name.replace(/bound /g, "")).map(m => {
798
+ return {
799
+ [m]: oClass[m].bind(this)
800
+ };
801
+ }).reduce((c, p) => Object.assign(c, p), {});
802
+ return _Cast(this, o);
803
+ }
804
+
805
+ route () {
806
+ return (this.constructor as typeof Component).route();
807
+ }
808
+
809
+ static route() {
810
+ const componentClass = this; /* is can be class or object */
811
+ let _route_promise_;
812
+ const isValidInstance = !!((isQCObjects_Object(componentClass) && is_a(componentClass, "Component")));
813
+ const __route__ = function (componentList: any[]) {
814
+ const _componentNames_: any[] = [];
815
+ const _promises_ = componentList.filter(function (rc: any) {
816
+ return typeof rc !== "undefined";
817
+ }).map(function (rc: Component): Promise<void> {
818
+ if (typeof rc.name !== "undefined") {
819
+ _componentNames_.push(rc.name);
820
+ } else {
821
+ throw new Error(__getType__(rc) + " does not have a name");
822
+ }
823
+ return new Promise(function (resolve, reject) {
824
+ if (typeof rc !== "undefined" && !!rc._reroute_) {
825
+ rc._reroute_()
826
+ .then(function () {
827
+ rc.reload = true;
828
+ rc.rebuild()
829
+ .then(()=> {
830
+ resolve();
831
+ })
832
+ .catch((e:any) => {
833
+ logger.debug(`Error ${e}`);
834
+ });
835
+ return;
836
+ })
837
+ .then(function () {
838
+ if (Object.hasOwn(rc, "subcomponents") &&
839
+ typeof rc.subcomponents !== "undefined" &&
840
+ rc.subcomponents.length > 0
841
+ ) {
842
+ logger.debug("LOOKING FOR ROUTINGS IN SUBCOMPONENTS FOR: " + rc.name);
843
+ return __route__.call(rc, rc.subcomponents);
844
+ } else {
845
+ logger.debug("No subcomponents to look for routings in: " + rc.name);
846
+ if (rc.subtags.length > 0) {
847
+ rc.subcomponents = rc.__buildSubComponents__(true);
848
+ }
849
+ resolve();
850
+ }
851
+ }).catch ((e:any) => {
852
+ logger.debug(`Error: ${e}`);
853
+ });
854
+ } else if (typeof rc !== "undefined") {
855
+ reject(new Error ("Component " + rc.name + " is not an instance of Component"));
856
+ }
857
+ return;
858
+ });
859
+ });
860
+ return Promise.all(_promises_)
861
+ .then(function () {
862
+ logger.debug("ROUTING COMPLETED FOR " + _componentNames_.join(", "));
863
+ }).catch(function (err) {
864
+ logger.warn("ROUTING FAILED FOR " + _componentNames_.join(", ") + ": " + err);
865
+ });
866
+ };
867
+ if (isValidInstance || !!componentsStack) {
868
+ if (isValidInstance) {
869
+ logger.debug("loading routings for instance " + componentClass.name);
870
+ }
871
+ _route_promise_ = __route__.call(componentClass, (isValidInstance) ? (componentClass.subcomponents) : (componentsStack));
872
+ } else {
873
+ logger.debug("An undetermined result expected if load routings. So will not be loaded this time.");
874
+ throw Error("There is no valid instance and no components stack available to apply rountings");
875
+ }
876
+ return _route_promise_;
877
+ }
878
+
879
+ fullscreen() {
880
+ if (isBrowser) {
881
+ const elem:HTMLElement = this.body as HTMLElement;
882
+ if (elem.requestFullscreen) {
883
+ elem.requestFullscreen()
884
+ .catch ((e:any) => {
885
+ throw new Error (`An error ocurred when requesting fullscreen: ${e}`);
886
+ });
887
+ } else if ((elem as any).mozRequestFullScreen) {
888
+ /* Firefox */
889
+ (elem as any).mozRequestFullScreen();
890
+ } else if ((elem as any).webkitRequestFullscreen) {
891
+ /* Chrome, Safari & Opera */
892
+ (elem as any).webkitRequestFullscreen();
893
+ } else if ((elem as any).msRequestFullscreen) {
894
+ /* IE/Edge */
895
+ (elem as any).msRequestFullscreen();
896
+ }
897
+ } else {
898
+ // not yet implemented.
899
+ }
900
+ }
901
+
902
+ closefullscreen() {
903
+ if (isBrowser) {
904
+ if (document.exitFullscreen) {
905
+ document.exitFullscreen()
906
+ .catch((e:any) => {throw new Error (`An error ocurred when trying to exit fullscrenn ${e}.`);});
907
+ } else if ((document as any).mozCancelFullScreen) {
908
+ (document as any).mozCancelFullScreen();
909
+ } else if ((document as any).webkitExitFullscreen) {
910
+ (document as any).webkitExitFullscreen();
911
+ } else if ((document as any).msExitFullscreen) {
912
+ (document as any).msExitFullscreen();
913
+ }
914
+ } else {
915
+ // noy yet implemented.
916
+ }
917
+ }
918
+
919
+ _generateRoutingPaths(componentBody: TBody) {
920
+ const component = this;
921
+ return new Promise<void>(function (resolve) {
922
+ if (isBrowser) {
923
+ if (__valid_routing_way__(component.validRoutingWays, component.routingWay || "")) {
924
+ if (typeof componentBody !== "undefined") {
925
+ component.innerHTML = (componentBody as HTMLElement)?.innerHTML;
926
+ component.routingNodes = (componentBody as IQCObjectsElement)?.subelements("routing");
927
+ component.routings = [];
928
+ component.routingNodes.map( (routingNode):any => {
929
+ const attributeNames = (routingNode as HTMLElement).getAttributeNames();
930
+ const routing = {} as TComponentRouting;
931
+ attributeNames.map( (attributeName: any, a: string | number):any => {
932
+ (routing as any)[attributeNames[a as any]] = (routingNode as HTMLElement).getAttribute(attributeNames[a as any]);
933
+ return attributeName;
934
+ });
935
+ component.routings.push(routing as never);
936
+ if (!component.routingPaths) {
937
+ component.routingPaths = [];
938
+ }
939
+ if (!component.routingPaths.includes(routing.path as never)) {
940
+ component.routingPaths.push(routing.path as never);
941
+ }
942
+ if (!_top.global.get("routingPaths")) {
943
+ _top.global.set("routingPaths", []);
944
+ }
945
+ if (!_top.global.get("routingPaths").includes(routing.path)) {
946
+ _top.global.get("routingPaths").push(routing.path);
947
+ }
948
+ return routingNode;
949
+ });
950
+ }
951
+ }
952
+ } else {
953
+ // not yet implemented.
954
+ }
955
+ resolve();
956
+
957
+ });
958
+ }
959
+
960
+ parseTemplate(template: any):string {
961
+ const _self = this;
962
+ let _parsedAssignmentText:string;
963
+ const value = template;
964
+ if (Object.hasOwn(_self, "templateHandler")) {
965
+ const templateHandlerName = _self.templateHandler;
966
+ logger.debug(`[Component][${this.name}][parseTemplate] Attempting to use ${templateHandlerName} ...`);
967
+ const templateHandlerClass = ClassFactory(templateHandlerName);
968
+ const templateInstance = New(templateHandlerClass, {
969
+ component: _self,
970
+ template: value
971
+ });
972
+ templateInstance.component = _self;
973
+ let selfData = _self.data;
974
+ if (Object.hasOwn(_self, "assignRoutingParams") && _self.assignRoutingParams) {
975
+ try {
976
+ selfData = Object.assign(selfData, _self.routingParams);
977
+ } catch (e:any) {
978
+ logger.debug(`An error ocurred: ${e}.`);
979
+ logger.debug("[parseTemplate] it was not possible to assign the routing params to the template");
980
+ }
981
+ }
982
+ _parsedAssignmentText = templateInstance.assign(selfData);
983
+ } else {
984
+ logger.debug(`[Component][${this.name}][parseTemplate] No value for templateHandler. Using raw content...`);
985
+ _parsedAssignmentText = value;
986
+ }
987
+ return _parsedAssignmentText;
988
+ }
989
+
990
+ _reroute_(): Promise<Component> {
991
+ /* This method set the selected routing and makes the switch to the templateURI */
992
+ const rc = this;
993
+ return new Promise(function (resolve) {
994
+ if (isBrowser) {
995
+ if (__valid_routing_way__(rc.validRoutingWays, rc.routingWay || "")) {
996
+ rc.routingPath = (location as any)[rc.routingWay as string];
997
+ rc.routingSelected.map( (routing: TComponentRouting, ):TComponentRouting => {
998
+ const componentURI = ComponentURI({
999
+ "COMPONENTS_BASE_PATH": CONFIG.get("componentsBasePath"),
1000
+ "COMPONENT_NAME": routing.name.toString(),
1001
+ "TPLEXTENSION": (Object.hasOwn(routing, "tplextension")) ? (routing.tplextension || "") : (rc.tplextension),
1002
+ "TPL_SOURCE": "default" /* here is always default in order to get the right uri */
1003
+ });
1004
+ rc.templateURI = componentURI;
1005
+ return routing;
1006
+ });
1007
+ if (rc.routingSelected.length > 0) {
1008
+ rc.template = "";
1009
+ if (typeof rc.body !== "undefined" && rc.body !== null){
1010
+ (rc.body as HTMLElement).innerHTML = "";
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+ resolve(rc);
1016
+
1017
+ });
1018
+ }
1019
+
1020
+ lazyLoadImages() {
1021
+ if (isBrowser) {
1022
+ const component = this;
1023
+ const _componentRoot = component.componentRoot as IQCObjectsShadowedElement;
1024
+ if (typeof _componentRoot !== "undefined" && _componentRoot !== null){
1025
+ const _imgLazyLoaded = [..._componentRoot.subelements("img[lazy-src]")];
1026
+ const _lazyLoadImages = function (image: Element | HTMLElement) {
1027
+ image.setAttribute("src", image.getAttribute("lazy-src")?.toString() as string);
1028
+ (image as HTMLImageElement).onload = () => {
1029
+ image.removeAttribute("lazy-src");
1030
+ };
1031
+ };
1032
+ if ("IntersectionObserver" in window) {
1033
+ const observer = new IntersectionObserver((items, observer) => {
1034
+ items.forEach((item) => {
1035
+ if (item.isIntersecting) {
1036
+ _lazyLoadImages(item.target);
1037
+ observer.unobserve(item.target);
1038
+ }
1039
+ });
1040
+ });
1041
+ _imgLazyLoaded.map(function (img) {
1042
+ return observer.observe(img as unknown as HTMLImageElement);
1043
+ });
1044
+ } else {
1045
+ (_imgLazyLoaded as (HTMLElement | Element)[]).map(_lazyLoadImages);
1046
+ }
1047
+ }
1048
+ } else {
1049
+ // not yet implemented
1050
+ }
1051
+ return null;
1052
+ }
1053
+
1054
+ applyTransitionEffect(effectClassName: string) {
1055
+ const _Effect = ClassFactory(effectClassName);
1056
+ if (typeof _Effect === "undefined") {
1057
+ throw Error(`${effectClassName} not found.`);
1058
+ }
1059
+ if (typeof _Effect !== "undefined" && is_a(_Effect, "TransitionEffect")) {
1060
+ this.effect = New(_Effect, {
1061
+ component: this
1062
+ });
1063
+ (this.effect as any)?.apply((this.effect as any)?.defaultParams);
1064
+ } else {
1065
+ logger.debug(`${effectClassName} is ${__getType__(_Effect)} but is not a TransitionEffect`);
1066
+ }
1067
+ }
1068
+
1069
+ applyObserveTransitionEffect(effectClassName: any) {
1070
+ if (isBrowser) {
1071
+ const component = this;
1072
+ const _componentRoot = component.componentRoot;
1073
+ const _applyEffect_ = function () {
1074
+ component.applyTransitionEffect(effectClassName);
1075
+ };
1076
+ if ("IntersectionObserver" in window) {
1077
+ const observer = new IntersectionObserver((items, observer) => {
1078
+ items.forEach((item) => {
1079
+ if (item.isIntersecting) {
1080
+ _applyEffect_();
1081
+ observer.unobserve(item.target);
1082
+ }
1083
+ });
1084
+ });
1085
+ observer.observe(_componentRoot as Element);
1086
+ } else {
1087
+ _applyEffect_();
1088
+ }
1089
+ } else {
1090
+ // not yet implemented
1091
+ }
1092
+
1093
+ }
1094
+
1095
+ get componentRoot ():TBody {
1096
+ return (this.shadowed) ? (this.shadowRoot) : (this.body);
1097
+ }
1098
+
1099
+ scrollIntoHash() {
1100
+ if (isBrowser) {
1101
+ const component = this;
1102
+ if (document.location.hash !== "") {
1103
+ const _componentRoot = component.componentRoot;
1104
+ ((_componentRoot as IQCObjectsShadowedElement)?.subelements(document.location.hash) as unknown as Element[]).map(
1105
+ (element: Element):any => {
1106
+ if (typeof element.scrollIntoView === "function") {
1107
+ element.scrollIntoView(
1108
+ CONFIG.get("scrollIntoHash", {
1109
+ behavior: "auto",
1110
+ block: "top",
1111
+ inline: "top"
1112
+ })
1113
+ );
1114
+ }
1115
+ return element;
1116
+ }
1117
+ );
1118
+ }
1119
+ } else {
1120
+ // not yet implemented
1121
+ }
1122
+ }
1123
+
1124
+ i18n_translate() {
1125
+ if (isBrowser) {
1126
+ if (CONFIG.get("use_i18n")) {
1127
+ const component = this;
1128
+ const _componentRoot = component.componentRoot as IQCObjectsShadowedElement;
1129
+ const lang1 = CONFIG.get("lang", "en");
1130
+ const lang2 = navigator.language.slice(0, 2);
1131
+ const i18n = _top.global.get("i18n");
1132
+ if ((lang1 !== lang2) && (typeof i18n === "object" && Object.hasOwn(i18n, "messages"))) {
1133
+ const callback_i18n = () => {
1134
+ return new Promise<void>(function (resolve) {
1135
+ const messages = i18n.messages.filter(function (message: any) {
1136
+ return Object.hasOwn(message, lang1) && Object.hasOwn(message, lang2);
1137
+ });
1138
+ (_componentRoot?.subelements("ul,li,h1,h2,h3,a,b,p,input,textarea,summary,details,option,component") as HTMLElement[])
1139
+ .map( (element: HTMLElement):HTMLElement => {
1140
+ messages.map(function (message: { [x: string]: any; }) {
1141
+ let _innerHTML = element.innerHTML;
1142
+ _innerHTML = _innerHTML?.replace(new RegExp(`${message[lang1]}`, "g"), message[lang2]);
1143
+ element.innerHTML = _innerHTML;
1144
+ return null;
1145
+ });
1146
+ return element;
1147
+ });
1148
+ resolve();
1149
+ });
1150
+ };
1151
+ callback_i18n.call(component).then(function () {
1152
+ logger.debug("i18n loaded for component: " + component.name);
1153
+ }).catch((e:any) => {throw new Error (`An error ocurred when parsing i18n: ${e}.`);});
1154
+
1155
+ }
1156
+ }
1157
+ } else {
1158
+ // not yet implemented
1159
+ }
1160
+ }
1161
+
1162
+ addComponentHelper(componentHelper: any) {
1163
+ const component = this;
1164
+ component._componentHelpers.push(componentHelper as never);
1165
+ }
1166
+
1167
+ runComponentHelpers() {
1168
+ if (isBrowser) {
1169
+ const component = this;
1170
+ let __component_helpers__ = [];
1171
+ /*
1172
+ * BEGIN use i18n translation
1173
+ */
1174
+ __component_helpers__.push(component.i18n_translate.bind(component));
1175
+ /*
1176
+ * END use i18n translation
1177
+ */
1178
+
1179
+ /*
1180
+ * BEGIN component scrollIntoHash
1181
+ */
1182
+ __component_helpers__.push(component.scrollIntoHash.bind(component));
1183
+ /*
1184
+ * END component scrollIntoHash
1185
+ */
1186
+
1187
+ /*
1188
+ * BEGIN component images lazy-load
1189
+ */
1190
+
1191
+ __component_helpers__.push(component.lazyLoadImages.bind(component));
1192
+
1193
+ /*
1194
+ * END component images lazy-load
1195
+ */
1196
+
1197
+ __component_helpers__ = __component_helpers__.concat(component._componentHelpers);
1198
+
1199
+ __component_helpers__.map(
1200
+ (_component_helper_):any => {
1201
+ logger.debug(`Executing ${_component_helper_.name} as component helper for ${component.name}...`);
1202
+ _component_helper_();
1203
+ return _component_helper_;
1204
+ }
1205
+ );
1206
+
1207
+ } else {
1208
+ // not yet implemented
1209
+ }
1210
+
1211
+ }
1212
+
1213
+ }
1214
+
1215
+ Package("com.qcobjects", [
1216
+ Component
1217
+ ]);
1218
+
1219
+ (_methods_)(ClassFactory("Component")).map( (__c__):any => {
1220
+ (_protected_code_)(__c__);
1221
+ return __c__;
1222
+ });