qcobjects 2.4.107-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.
- package/.hintrc +5 -0
- package/VERSION +1 -1
- package/build/ArrayCollection.js +136 -0
- package/build/BackendMicroservice.js +211 -0
- package/build/Base64.js +100 -0
- package/build/CONFIG.js +85 -0
- package/build/Cast.js +53 -0
- package/build/Class.js +284 -0
- package/build/ClassFactory.js +38 -0
- package/build/ComplexStorageCache.js +91 -0
- package/build/Component.js +1133 -0
- package/build/ComponentFactory.js +113 -0
- package/build/ConfigSettings.js +39 -0
- package/build/Controller.js +81 -0
- package/build/Crypt.js +87 -0
- package/build/DDO.js +81 -0
- package/build/DOMCreateElement.js +15 -0
- package/build/DataStringify.js +22 -0
- package/build/DefaultTemplateHandler.js +57 -0
- package/build/DocumentLayout.js +20 -0
- package/build/Effect.js +46 -0
- package/build/Export.js +11 -0
- package/build/Import.js +140 -0
- package/build/IncrementInstanceID.js +11 -0
- package/build/InheritClass.js +194 -0
- package/build/LegacyCopy.js +31 -0
- package/build/Logger.js +33 -0
- package/build/MainProcess.js +549 -0
- package/build/NamespaceRef.js +29 -0
- package/build/New.js +17 -0
- package/build/ObjectName.js +22 -0
- package/build/Package.js +67 -0
- package/build/PrimaryCollections.js +7 -0
- package/build/Processor.js +81 -0
- package/build/QCObjects.js +182 -4843
- package/build/Ready.js +49 -0
- package/build/RegisterClass.js +28 -0
- package/build/Service.js +112 -0
- package/build/SourceCSS.js +56 -0
- package/build/SourceJS.js +73 -0
- package/build/Tag.js +77 -0
- package/build/Timer.js +30 -0
- package/build/Toggle.js +59 -0
- package/build/TransitionEffect.js +65 -0
- package/build/VO.js +11 -0
- package/build/View.js +18 -0
- package/build/WidgetsFactory.js +537 -0
- package/build/assign.js +32 -0
- package/build/asyncLoad.js +43 -0
- package/build/basePath.js +32 -0
- package/build/captureFalseTouch.js +32 -0
- package/build/componentLoader.js +258 -0
- package/build/defaultProcessors.js +130 -0
- package/build/domain.js +4 -0
- package/build/findPackageNodePath.js +47 -0
- package/build/getType.js +38 -0
- package/build/globalSettings.js +115 -0
- package/build/index.d.ts +1045 -0
- package/build/index.js +24 -4
- package/build/index.mjs +1 -1
- package/build/introspection.js +86 -0
- package/build/isQCObjects.js +20 -0
- package/build/is_a.js +19 -0
- package/build/is_forbidden_name.js +15 -0
- package/build/is_raw_class.js +7 -0
- package/build/loadSDK.js +63 -0
- package/build/localStorage.js +19 -0
- package/build/make_global.js +24 -0
- package/build/mathFunctions.js +7 -0
- package/build/platform.js +28 -0
- package/build/range.js +17 -0
- package/build/routings.js +21 -0
- package/build/secretKey.js +5 -0
- package/build/serviceLoader.js +300 -0
- package/build/shortCode.js +14 -0
- package/build/subelements.js +8 -0
- package/build/super.js +20 -0
- package/build/tag_filter.js +4 -0
- package/build/top.js +23 -0
- package/build/uniqueID.js +5 -0
- package/build/waitUntil.js +31 -0
- package/build-esbuild.js +62 -0
- package/eslint.config.mjs +87 -0
- package/package.json +26 -23
- package/public/browser/index.js +6502 -0
- package/public/browser/index.js.map +7 -0
- package/public/cjs/index.cjs +6586 -0
- package/public/cjs/index.cjs.map +7 -0
- package/public/esm/index.mjs +6494 -0
- package/public/esm/index.mjs.map +7 -0
- package/spec/helpers/mock-sdk.helper.ts +5 -0
- package/spec/mocks/qcobjects-sdk.mock.ts +1 -0
- package/spec/support/jasmine.json +3 -3
- package/spec/testsClassFactorySpec.ts +40 -0
- package/spec/{testsConfigSpec.js → testsConfigSpec.ts} +2 -2
- package/spec/{testsGlobalFeaturesSpec.js → testsGlobalFeaturesSpec.ts} +10 -8
- package/spec/{testsSpec.js → testsSpec.ts} +11 -10
- package/spec/{testsTypeSpec.js → testsTypeSpec.ts} +5 -3
- package/src/ArrayCollection.ts +143 -0
- package/src/BackendMicroservice.ts +229 -0
- package/src/Base64.ts +92 -0
- package/src/CONFIG.ts +96 -0
- package/src/Cast.ts +46 -0
- package/src/Class.ts +303 -0
- package/src/ClassFactory.ts +34 -0
- package/src/ComplexStorageCache.ts +97 -0
- package/src/Component.ts +1222 -0
- package/src/ComponentFactory.ts +122 -0
- package/src/ConfigSettings.ts +62 -0
- package/src/Controller.ts +90 -0
- package/src/Crypt.ts +87 -0
- package/src/DDO.ts +93 -0
- package/src/DOMCreateElement.ts +12 -0
- package/src/DataStringify.ts +19 -0
- package/src/DefaultTemplateHandler.ts +55 -0
- package/src/DocumentLayout.ts +16 -0
- package/src/Effect.ts +56 -0
- package/src/Export.ts +8 -0
- package/src/Import.ts +135 -0
- package/src/IncrementInstanceID.ts +8 -0
- package/src/InheritClass.ts +210 -0
- package/src/LegacyCopy.ts +27 -0
- package/src/Logger.ts +32 -0
- package/src/MainProcess.ts +629 -0
- package/src/NamespaceRef.ts +26 -0
- package/src/New.ts +15 -0
- package/src/ObjectName.ts +16 -0
- package/src/Package.ts +67 -0
- package/src/PrimaryCollections.ts +7 -0
- package/src/Processor.ts +93 -0
- package/src/QCObjects.ts +100 -0
- package/src/Ready.ts +44 -0
- package/src/RegisterClass.ts +26 -0
- package/src/Service.ts +127 -0
- package/src/SourceCSS.ts +59 -0
- package/src/SourceJS.ts +76 -0
- package/src/Tag.ts +76 -0
- package/src/Timer.ts +42 -0
- package/src/Toggle.ts +65 -0
- package/src/TransitionEffect.ts +80 -0
- package/src/VO.ts +8 -0
- package/src/View.ts +17 -0
- package/src/WidgetsFactory.ts +543 -0
- package/src/assign.ts +33 -0
- package/src/asyncLoad.ts +42 -0
- package/src/basePath.ts +29 -0
- package/src/captureFalseTouch.ts +29 -0
- package/src/componentLoader.ts +252 -0
- package/src/defaultProcessors.ts +145 -0
- package/src/domain.ts +1 -0
- package/src/findPackageNodePath.ts +43 -0
- package/src/getType.ts +36 -0
- package/src/globalSettings.ts +118 -0
- package/src/index.mts +1 -1
- package/src/index.ts +1 -1
- package/src/introspection.ts +80 -0
- package/src/isQCObjects.ts +19 -0
- package/src/is_a.ts +16 -0
- package/src/is_forbidden_name.ts +12 -0
- package/src/is_raw_class.ts +3 -0
- package/src/loadSDK.ts +59 -0
- package/src/localStorage.ts +17 -0
- package/src/make_global.ts +19 -0
- package/src/mathFunctions.ts +3 -0
- package/src/platform.ts +30 -0
- package/src/range.ts +15 -0
- package/src/routings.ts +18 -0
- package/src/secretKey.ts +3 -0
- package/src/serviceLoader.ts +306 -0
- package/src/shortCode.ts +11 -0
- package/src/subelements.ts +4 -0
- package/src/super.ts +17 -0
- package/src/tag_filter.ts +1 -0
- package/src/top.ts +111 -0
- package/src/types/global/index.d.ts +597 -0
- package/src/uniqueID.ts +3 -0
- package/src/waitUntil.ts +26 -0
- package/tsconfig.d.json +35 -8
- package/tsconfig.jasmine.json +39 -0
- package/tsconfig.json +46 -12
- package/.eslintignore +0 -5
- package/.eslintrc.cjs +0 -21
- package/.eslintrc.json +0 -24
- package/browser/QCObjects.js +0 -2
- package/browser/QCObjects.js.map +0 -7
- package/browser/chunks/chunk-O2PFFZVJ.js +0 -713
- package/browser/chunks/chunk-O2PFFZVJ.js.map +0 -7
- package/browser/chunks/chunk-TBLBK5VV.js +0 -713
- package/browser/chunks/chunk-TBLBK5VV.js.map +0 -7
- package/browser/chunks/chunk-ZYLXOA35.js +0 -713
- package/browser/chunks/chunk-ZYLXOA35.js.map +0 -7
- package/browser/index.js +0 -2
- package/browser/index.js.map +0 -7
- package/spec/testsClassFactorySpec.js +0 -41
- package/src/QCObjects.js +0 -5247
- package/src/index.d.ts +0 -8
- package/types/index.d.ts +0 -472
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { IComponent, TCacheController } from "types";
|
|
2
|
+
import { asyncLoad } from "./asyncLoad";
|
|
3
|
+
import { ComplexStorageCache } from "./ComplexStorageCache";
|
|
4
|
+
import { _DataStringify } from "./DataStringify";
|
|
5
|
+
import { logger } from "./Logger";
|
|
6
|
+
import { _require_, is_phonegap, isBrowser } from "./platform";
|
|
7
|
+
import { _top } from "./top";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Loads a simple component from a template
|
|
11
|
+
*
|
|
12
|
+
* @author: Jean Machuca <correojean@gmail.com>
|
|
13
|
+
* @param component a Component object
|
|
14
|
+
*/
|
|
15
|
+
export const componentLoader = function (component: IComponent, _async: boolean):Promise<any> {
|
|
16
|
+
let __promise__: Promise<any>;
|
|
17
|
+
const _componentLoaderInBrowser = function (component: IComponent) {
|
|
18
|
+
__promise__ = new Promise(function (resolve, reject) {
|
|
19
|
+
const _promise = component.__promise__;
|
|
20
|
+
const container = (Object.hasOwn(component, "container") && typeof component.container !== "undefined" && component.container !== null) ? (component.container) : (component.body);
|
|
21
|
+
if (container !== null) {
|
|
22
|
+
const _feedComponent_ = function (component: { feedComponent: () => void; }) {
|
|
23
|
+
component.feedComponent();
|
|
24
|
+
const standardResponse = {
|
|
25
|
+
"request": xhr,
|
|
26
|
+
component
|
|
27
|
+
};
|
|
28
|
+
resolve.call(_promise, standardResponse);
|
|
29
|
+
};
|
|
30
|
+
logger.debug("LOADING COMPONENT DATA {{DATA}} FROM {{URL}}".replace("{{DATA}}", _DataStringify(component.data)).replace("{{URL}}", component.url));
|
|
31
|
+
|
|
32
|
+
const _componentLoaded = function () {
|
|
33
|
+
const successStatus = (is_file) ? (0) : (200);
|
|
34
|
+
if (xhr.status === successStatus) {
|
|
35
|
+
const response = xhr.responseText;
|
|
36
|
+
logger.debug("Data received {{DATA}}".replace("{{DATA}}", _DataStringify(response)));
|
|
37
|
+
logger.debug("CREATING COMPONENT {{NAME}}".replace("{{NAME}}", component.name));
|
|
38
|
+
component.template = response;
|
|
39
|
+
if (component.cached && (typeof cache !== "undefined")) {
|
|
40
|
+
cache.save(component.name, component.template);
|
|
41
|
+
}
|
|
42
|
+
_feedComponent_(component);
|
|
43
|
+
} else {
|
|
44
|
+
const standardResponse = {
|
|
45
|
+
"request": xhr,
|
|
46
|
+
component
|
|
47
|
+
};
|
|
48
|
+
reject.call(_promise, standardResponse);
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (typeof component.template === "string" && component.template !== "") {
|
|
53
|
+
// component already has a template it does not need to be reloaded
|
|
54
|
+
_feedComponent_(component);
|
|
55
|
+
} else {
|
|
56
|
+
var is_file = !!(component.url.startsWith("file:"));
|
|
57
|
+
var xhr = new XMLHttpRequest();
|
|
58
|
+
if (!is_file) {
|
|
59
|
+
try {
|
|
60
|
+
logger.debug("Calling the url of component in async mode.");
|
|
61
|
+
xhr.open(component.method, component.url, true);
|
|
62
|
+
} catch (e:any) {
|
|
63
|
+
logger.debug(`An error ocurred: ${e}.`);
|
|
64
|
+
logger.debug("Last try has failed... The component cannot be loaded.");
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
if ("fetch" in _top) {
|
|
68
|
+
logger.debug("I can use fetch...");
|
|
69
|
+
logger.debug("It is a file to be loaded, so I will try to use fetch");
|
|
70
|
+
fetch(component.url).then(response => {
|
|
71
|
+
logger.debug("I got a response from fetch, so I'll feed the component");
|
|
72
|
+
response.text().then(text => {
|
|
73
|
+
component.template = text;
|
|
74
|
+
_feedComponent_(component);
|
|
75
|
+
})
|
|
76
|
+
.catch((e:any) => {throw new Error (`An error ocurred: ${e}`);});
|
|
77
|
+
}).catch ((e:any) => {throw new Error (`An error ocurred: ${e}`);});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!is_phonegap && !is_file) {
|
|
81
|
+
xhr.setRequestHeader("Content-Type", "text/html");
|
|
82
|
+
}
|
|
83
|
+
if (!is_file) {
|
|
84
|
+
xhr.onload = _componentLoaded;
|
|
85
|
+
}
|
|
86
|
+
const _directLoad = function (is_file: boolean) {
|
|
87
|
+
is_file = !((typeof is_file === "undefined" || !is_file));
|
|
88
|
+
logger.debug("SENDING THE NORMAL REQUEST ");
|
|
89
|
+
if (is_file) {
|
|
90
|
+
if (!("fetch" in _top)) {
|
|
91
|
+
logger.debug("I have to try to load the file using xhr... ");
|
|
92
|
+
xhr.send(null);
|
|
93
|
+
if (xhr.status === XMLHttpRequest.DONE) {
|
|
94
|
+
_componentLoaded();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
logger.debug("Trying to send the data to the component... ");
|
|
99
|
+
xhr.send(_DataStringify(component.data));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (component.cached && (!is_file)) {
|
|
104
|
+
logger.debug("USING CACHE FOR COMPONENT: " + component.name);
|
|
105
|
+
var cache = new ComplexStorageCache({
|
|
106
|
+
index: component.cacheIndex,
|
|
107
|
+
load() {
|
|
108
|
+
_directLoad.call(this, is_file);
|
|
109
|
+
},
|
|
110
|
+
alternate(cacheController: TCacheController) {
|
|
111
|
+
if (component.method === "GET") {
|
|
112
|
+
component.template = cacheController.cache.getCached(component.cacheIndex);
|
|
113
|
+
_feedComponent_.call(this, component);
|
|
114
|
+
} else {
|
|
115
|
+
_directLoad.call(this, is_file);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
(_top as any).lastCache = cache;
|
|
121
|
+
} else {
|
|
122
|
+
logger.debug("NOT USING CACHE FOR COMPONENT: " + component.name);
|
|
123
|
+
_directLoad(is_file);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
logger.debug("CONTAINER DOESNT EXIST");
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
__promise__.then(function (standardResponse) {
|
|
132
|
+
return component.__done__().then(function () {
|
|
133
|
+
let _ret_;
|
|
134
|
+
if (typeof component.done === "function") {
|
|
135
|
+
_ret_ = component.done.call(component, standardResponse);
|
|
136
|
+
}
|
|
137
|
+
return Promise.resolve(_ret_);
|
|
138
|
+
});
|
|
139
|
+
}, function (standardResponse) {
|
|
140
|
+
if (typeof component.fail === "function") {
|
|
141
|
+
component.fail.call(component, standardResponse)
|
|
142
|
+
.catch ((e:any)=> {throw new Error (`${e}`);});
|
|
143
|
+
}
|
|
144
|
+
return Promise.reject(new Error ("An error ocurred"));
|
|
145
|
+
}).catch(function (e:any) {
|
|
146
|
+
logger.debug("Something wrong loading the component");
|
|
147
|
+
throw new Error (`An error ocurred: ${e}`);
|
|
148
|
+
});
|
|
149
|
+
return __promise__;
|
|
150
|
+
};
|
|
151
|
+
const _componentLoaderInNode = function (component: IComponent) {
|
|
152
|
+
__promise__ = new Promise(function (resolve, reject) {
|
|
153
|
+
const _promise = __promise__;
|
|
154
|
+
const _feedComponent_ = function (component: IComponent) {
|
|
155
|
+
component.feedComponent()
|
|
156
|
+
.catch ((e:any) => {
|
|
157
|
+
throw new Error (`An error ocurred trying to feed the component: ${component.name}. Error: ${e}`);
|
|
158
|
+
});
|
|
159
|
+
const standardResponse = {
|
|
160
|
+
"request": null,
|
|
161
|
+
component
|
|
162
|
+
};
|
|
163
|
+
resolve.call(_promise, standardResponse);
|
|
164
|
+
};
|
|
165
|
+
logger.debug("LOADING COMPONENT DATA {{DATA}} FROM {{URL}}".replace("{{DATA}}", _DataStringify(component.data)).replace("{{URL}}", component.url));
|
|
166
|
+
|
|
167
|
+
const _componentLoaded = function (err: any, responseText: { toString: () => any; }) {
|
|
168
|
+
if (!err) {
|
|
169
|
+
const response = responseText.toString();
|
|
170
|
+
logger.debug("Data received {{DATA}}".replace("{{DATA}}", _DataStringify(response)));
|
|
171
|
+
logger.debug("CREATING COMPONENT {{NAME}}".replace("{{NAME}}", component.name));
|
|
172
|
+
component.template = response;
|
|
173
|
+
if (component.cached && (typeof cache !== "undefined")) {
|
|
174
|
+
cache.save(component.name, component.template);
|
|
175
|
+
}
|
|
176
|
+
_feedComponent_(component);
|
|
177
|
+
} else {
|
|
178
|
+
const standardResponse = {
|
|
179
|
+
"request": null,
|
|
180
|
+
component
|
|
181
|
+
};
|
|
182
|
+
reject.call(_promise, standardResponse);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
if (typeof component.template === "string" && component.template !== "") {
|
|
186
|
+
// component already has a template it does not need to be reloaded
|
|
187
|
+
_feedComponent_(component);
|
|
188
|
+
} else {
|
|
189
|
+
logger.debug("Loading the component as a local file in server...");
|
|
190
|
+
const _directLoad = function () {
|
|
191
|
+
const fs = _require_("fs");
|
|
192
|
+
logger.debug("SENDING THE NORMAL REQUEST ");
|
|
193
|
+
(fs).readFile(component.url, _componentLoaded);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
if (component.cached) {
|
|
197
|
+
logger.debug("USING CACHE FOR COMPONENT: " + component.name);
|
|
198
|
+
var cache = new ComplexStorageCache({
|
|
199
|
+
index: component.cacheIndex,
|
|
200
|
+
load() {
|
|
201
|
+
_directLoad();
|
|
202
|
+
},
|
|
203
|
+
alternate(cacheController: TCacheController) {
|
|
204
|
+
if (component.method === "GET") {
|
|
205
|
+
component.template = cacheController.cache.getCached(component.cacheIndex);
|
|
206
|
+
_feedComponent_.call(this, component);
|
|
207
|
+
} else {
|
|
208
|
+
_directLoad.call(this);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
(_top as any).lastCache = cache;
|
|
214
|
+
} else {
|
|
215
|
+
logger.debug("NOT USING CACHE FOR COMPONENT: " + component.name);
|
|
216
|
+
_directLoad();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
__promise__.then(function (standardResponse) {
|
|
222
|
+
return component.__done__().then(function () {
|
|
223
|
+
let _ret_;
|
|
224
|
+
if (typeof component.done === "function") {
|
|
225
|
+
_ret_ = component.done.call(component, standardResponse);
|
|
226
|
+
}
|
|
227
|
+
return Promise.resolve(_ret_);
|
|
228
|
+
});
|
|
229
|
+
}, function (standardResponse) {
|
|
230
|
+
if (typeof component.fail === "function") {
|
|
231
|
+
component.fail.call(component, standardResponse)
|
|
232
|
+
.catch((e:any) => {throw new Error (`An error ocurred: ${e}`);});
|
|
233
|
+
}
|
|
234
|
+
return Promise.reject(new Error ("An error ocurred."));
|
|
235
|
+
}).catch(function (e) {
|
|
236
|
+
logger.debug(`Something wrong loading the component: ${e}`);
|
|
237
|
+
});
|
|
238
|
+
return __promise__;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
let _ret_;
|
|
242
|
+
if (isBrowser) {
|
|
243
|
+
if (typeof _async !== "undefined" && _async) {
|
|
244
|
+
_ret_ = asyncLoad(_componentLoaderInBrowser, [component, _async]);
|
|
245
|
+
} else {
|
|
246
|
+
_ret_ = _componentLoaderInBrowser(component);
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
_ret_ = _componentLoaderInNode(component);
|
|
250
|
+
}
|
|
251
|
+
return _ret_ as Promise<any>;
|
|
252
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { logger } from "./Logger";
|
|
2
|
+
import { GlobalProcessor as Processor } from "./Processor";
|
|
3
|
+
import { _top } from "./top";
|
|
4
|
+
import { range } from "./range";
|
|
5
|
+
import { IComponent } from "types";
|
|
6
|
+
|
|
7
|
+
// Set Processors
|
|
8
|
+
export const setDefaultProcessors = () => {
|
|
9
|
+
(function (_top) {
|
|
10
|
+
|
|
11
|
+
const mapper = (componentInstance:IComponent, componentName:string, valueName:string):string => {
|
|
12
|
+
/*
|
|
13
|
+
* Mapper processor
|
|
14
|
+
* @usage
|
|
15
|
+
* $mapper(<componentName>,<valueName>)
|
|
16
|
+
*
|
|
17
|
+
* Where componentName is the name of the component (same value as in attribute tag name) without quotes
|
|
18
|
+
* and valueName is the name of the variable that contains the value to map, it can be either a property of
|
|
19
|
+
* the component instance, the data object or a global value
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
if (typeof componentInstance === "undefined" || componentInstance === null) {
|
|
23
|
+
throw Error(`mapper.${componentName}.${valueName} does not have a component instance or it is null.`);
|
|
24
|
+
}
|
|
25
|
+
const globalValue = _top.global.get(valueName);
|
|
26
|
+
const componentValue = componentInstance.get(valueName);
|
|
27
|
+
const dataValue = componentInstance.data[valueName];
|
|
28
|
+
const list = (typeof dataValue !== "undefined") ? (dataValue) : ((typeof componentValue !== "undefined") ? (componentValue) : (globalValue));
|
|
29
|
+
let listItems = "";
|
|
30
|
+
if (typeof list !== "undefined" && typeof list.map !== "undefined") {
|
|
31
|
+
listItems = list.map(function (element:HTMLElement) {
|
|
32
|
+
const dataItems = [...Object.keys(element)].map(k => ` data-${k}="${(typeof (element as any)[k] !== "undefined" && (element as any)[k] !== null) ? ((element as any)[k].toString()) : ("")}"`).join("");
|
|
33
|
+
return `<quick-component name="${componentName}" ${dataItems} ></quick-component>`;
|
|
34
|
+
}).join("");
|
|
35
|
+
} else {
|
|
36
|
+
logger.debug(`${componentName}.${valueName} does not have a map property`);
|
|
37
|
+
}
|
|
38
|
+
return listItems;
|
|
39
|
+
};
|
|
40
|
+
Processor.setProcessor(mapper);
|
|
41
|
+
|
|
42
|
+
const layout = function (componentInstance:IComponent, layoutname:string, cssfile:string):string {
|
|
43
|
+
/*
|
|
44
|
+
* Layout processor
|
|
45
|
+
* @usage
|
|
46
|
+
* $layout(<layoutname>, <cssfile>)
|
|
47
|
+
* Where layoutname can be "portrait" or "landscape" without quotes
|
|
48
|
+
* cssfile is the uri for the css file to import
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
const layout_portrait = `
|
|
52
|
+
/* CSS Document for Mobile Imports */
|
|
53
|
+
@import url("${cssfile}") (orientation:portrait);
|
|
54
|
+
@import url("${cssfile}") (max-width:460px);
|
|
55
|
+
@import url("${cssfile}") (aspect-ratio: 9/16);
|
|
56
|
+
@import url("${cssfile}") (aspect-ratio: 10/16);
|
|
57
|
+
@import url("${cssfile}") (aspect-ratio: 5/8);
|
|
58
|
+
@import url("${cssfile}") (aspect-ratio: 3/4);
|
|
59
|
+
@import url("${cssfile}") (aspect-ratio: 2/3);
|
|
60
|
+
`;
|
|
61
|
+
const layout_landscape = `
|
|
62
|
+
@import url("${cssfile}") (orientation:landscape) and (min-width:460px);
|
|
63
|
+
@import url("${cssfile}") (aspect-ratio: 16/9) and (min-width:460px);
|
|
64
|
+
@import url("${cssfile}") (aspect-ratio: 16/10) and (min-width:460px);
|
|
65
|
+
@import url("${cssfile}") (aspect-ratio: 8/5) and (min-width:460px);
|
|
66
|
+
@import url("${cssfile}") (aspect-ratio: 4/3) and (min-width:460px);
|
|
67
|
+
@import url("${cssfile}") (aspect-ratio: 3/2) and (min-width:460px);
|
|
68
|
+
`;
|
|
69
|
+
const layout_code = {
|
|
70
|
+
"landscape": layout_landscape,
|
|
71
|
+
"portrait": layout_portrait
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return (Object.hasOwn(layout_code, layoutname)) ? ((layout_code as any)[layoutname] as string) : ("");
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
Processor.setProcessor(layout);
|
|
78
|
+
|
|
79
|
+
const component = (componentInstance:IComponent ,name:string, componentClass:string, ...args:string[]):string => {
|
|
80
|
+
/*
|
|
81
|
+
* component processor
|
|
82
|
+
* @usage
|
|
83
|
+
* $component(name=<name>, componentClass=<componentClass>, ...)
|
|
84
|
+
* Returns a component tag declaration like:
|
|
85
|
+
* <component name=<name> ...></component>
|
|
86
|
+
*/
|
|
87
|
+
const arg = [...args].map(function (a) {
|
|
88
|
+
return {
|
|
89
|
+
[a.split("=")[0]]: a.split("=")[1]
|
|
90
|
+
};
|
|
91
|
+
}).reduce(function (k1, k2) {
|
|
92
|
+
return Object.assign(k1, k2);
|
|
93
|
+
});
|
|
94
|
+
const attrs = [...Object.keys(arg)].map(function (a) {
|
|
95
|
+
return `${a}=${arg[a as any]}`;
|
|
96
|
+
}).join(" ");
|
|
97
|
+
return `<component name="${name}" componentClass="${componentClass}" ${attrs}></component>`;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Processor.setProcessor(component);
|
|
101
|
+
|
|
102
|
+
const quick_component = (componentInstance: IComponent,name:string, componentClass:string, ...args:string[]):string => {
|
|
103
|
+
/*
|
|
104
|
+
* component processor
|
|
105
|
+
* @usage
|
|
106
|
+
* $quick_component(name=<name>, componentClass=<componentClass>, ...)
|
|
107
|
+
* Returns a component tag declaration like:
|
|
108
|
+
* <quick-component name=<name> ...></quick-component>
|
|
109
|
+
*/
|
|
110
|
+
const arg = [...args].map(function (a) {
|
|
111
|
+
return {
|
|
112
|
+
[a.split("=")[0]]: a.split("=")[1]
|
|
113
|
+
};
|
|
114
|
+
}).reduce(function (k1, k2) {
|
|
115
|
+
return Object.assign(k1, k2);
|
|
116
|
+
});
|
|
117
|
+
const attrs = [...Object.keys(arg)].map(function (a) {
|
|
118
|
+
return `${a}=${arg[a as any]}`;
|
|
119
|
+
}).join(" ");
|
|
120
|
+
return `<quick-component name="${name}" componentClass="${componentClass}" ${attrs}></quick-component>`;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
Processor.setProcessor(quick_component);
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
const repeat = (componentInstance:IComponent, length:number, text:string):string => {
|
|
127
|
+
/*
|
|
128
|
+
* Repeat processor
|
|
129
|
+
* @usage
|
|
130
|
+
* $repeat(<length>, <text>)
|
|
131
|
+
* Where length is the number of occurrences of text
|
|
132
|
+
*/
|
|
133
|
+
return range(length).map(
|
|
134
|
+
function (index) {
|
|
135
|
+
return text.replace("{{index}}", index.toString());
|
|
136
|
+
}
|
|
137
|
+
).join("");
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
Processor.setProcessor(repeat);
|
|
141
|
+
|
|
142
|
+
})(_top);
|
|
143
|
+
|
|
144
|
+
};
|
|
145
|
+
|
package/src/domain.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const _domain_:string = (typeof location !== "undefined" && location.hostname !== "") ? (location.hostname) : ("localhost");
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CONFIG } from "./CONFIG";
|
|
2
|
+
import { Export } from "./Export";
|
|
3
|
+
import { logger } from "./Logger";
|
|
4
|
+
import { _require_, isBrowser } from "./platform";
|
|
5
|
+
|
|
6
|
+
export const findPackageNodePath = function (packagename:string):string|null {
|
|
7
|
+
let sdkPath = null;
|
|
8
|
+
if (!isBrowser) {
|
|
9
|
+
const fs = _require_("fs");
|
|
10
|
+
try {
|
|
11
|
+
let sdkPaths = [
|
|
12
|
+
`${CONFIG.get("projectPath")}${CONFIG.get("relativeImportPath")}`,
|
|
13
|
+
`${CONFIG.get("basePath")}${CONFIG.get("relativeImportPath")}`,
|
|
14
|
+
`${CONFIG.get("projectPath")}`,
|
|
15
|
+
`${CONFIG.get("basePath")}`,
|
|
16
|
+
`${CONFIG.get("relativeImportPath")}`,
|
|
17
|
+
`${process.cwd()}${CONFIG.get("relativeImportPath")}`,
|
|
18
|
+
`${process.cwd()}/node_modules/` + packagename,
|
|
19
|
+
`${process.cwd()}/node_modules`,
|
|
20
|
+
`${process.cwd()}`,
|
|
21
|
+
"node_modules",
|
|
22
|
+
"./",
|
|
23
|
+
""
|
|
24
|
+
].concat(module.paths);
|
|
25
|
+
sdkPaths = sdkPaths.filter(p => {
|
|
26
|
+
return (fs).existsSync(p + "/" + packagename);
|
|
27
|
+
});
|
|
28
|
+
if (sdkPaths.length > 0) {
|
|
29
|
+
sdkPath = sdkPaths[0];
|
|
30
|
+
logger.info(packagename + " is Installed.");
|
|
31
|
+
} else {
|
|
32
|
+
sdkPath = "";
|
|
33
|
+
logger.info(`${packagename} is not in a standard path.`);
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
// do nothing
|
|
37
|
+
console.log(e);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
return sdkPath;
|
|
42
|
+
};
|
|
43
|
+
Export(findPackageNodePath);
|
package/src/getType.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __is_raw_class__ } from "./is_raw_class";
|
|
2
|
+
import { ObjectName } from "./ObjectName";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determine the type of the Object for any QCObjects Object
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} object
|
|
8
|
+
*/
|
|
9
|
+
export const __getType__ = function __getType__(o_c:any):any {
|
|
10
|
+
let _ret_ = "";
|
|
11
|
+
switch (true) {
|
|
12
|
+
case __is_raw_class__(o_c) && !!o_c.name:
|
|
13
|
+
_ret_ = o_c.name;
|
|
14
|
+
break;
|
|
15
|
+
case typeof o_c === "object" &&
|
|
16
|
+
(!!o_c.constructor &&
|
|
17
|
+
!!o_c.constructor.name)
|
|
18
|
+
&& o_c.constructor.name !== "":
|
|
19
|
+
_ret_ = o_c.constructor.name;
|
|
20
|
+
break;
|
|
21
|
+
case (!!o_c && !!o_c.__classType) && o_c.__classType !== "":
|
|
22
|
+
_ret_ = o_c.__classType;
|
|
23
|
+
break;
|
|
24
|
+
case (!!o_c && !!o_c.__definition) && (!!o_c.__definition.__classType) && o_c.__definition.__classType !== "":
|
|
25
|
+
_ret_ = o_c.__definition.__classType;
|
|
26
|
+
break;
|
|
27
|
+
case typeof o_c === "function" && !!o_c.name:
|
|
28
|
+
_ret_ = o_c.name;
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
_ret_ = ObjectName(o_c);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
return _ret_;
|
|
35
|
+
};
|
|
36
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { IGlobalSettings } from "types";
|
|
2
|
+
import { CONFIG } from "./CONFIG";
|
|
3
|
+
import { InheritClass } from "./InheritClass";
|
|
4
|
+
import { logger } from "./Logger";
|
|
5
|
+
import { Package } from "./Package";
|
|
6
|
+
import { isBrowser } from "./platform";
|
|
7
|
+
import { serviceLoader } from "./serviceLoader";
|
|
8
|
+
import { _top, buildComponentsStack, configService, setConfigService } from "./top";
|
|
9
|
+
import { ConfigService } from "./Service";
|
|
10
|
+
|
|
11
|
+
export class GlobalSettings extends InheritClass implements IGlobalSettings{
|
|
12
|
+
static __start__() {
|
|
13
|
+
return GlobalSettings.instance.__start__();
|
|
14
|
+
}
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
|
|
17
|
+
_GLOBAL:any = {};
|
|
18
|
+
private static _instance:GlobalSettings;
|
|
19
|
+
static get instance ():GlobalSettings{
|
|
20
|
+
if (typeof GlobalSettings._instance === "undefined"){
|
|
21
|
+
GlobalSettings._instance = new GlobalSettings();
|
|
22
|
+
}
|
|
23
|
+
return GlobalSettings._instance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set(name: string, value: any) {
|
|
27
|
+
this._GLOBAL[name] = value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get(name: string, _default?: any):any {
|
|
31
|
+
let _value:any;
|
|
32
|
+
if (typeof this._GLOBAL[name] !== "undefined") {
|
|
33
|
+
_value = this._GLOBAL[name];
|
|
34
|
+
} else if (typeof _default !== "undefined") {
|
|
35
|
+
_value = _default;
|
|
36
|
+
}
|
|
37
|
+
return _value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
__start__():Promise<any> {
|
|
41
|
+
const __load__serviceWorker = function () {
|
|
42
|
+
let _promise: Promise<ServiceWorkerRegistration> | Promise<unknown>;
|
|
43
|
+
if (isBrowser) {
|
|
44
|
+
_promise = new Promise<ServiceWorkerRegistration>(function (resolve, reject) {
|
|
45
|
+
if (("serviceWorker" in navigator) &&
|
|
46
|
+
(typeof CONFIG.get("serviceWorkerURI") !== "undefined")) {
|
|
47
|
+
CONFIG.set("serviceWorkerScope", CONFIG.get("serviceWorkerScope") ? (CONFIG.get("serviceWorkerScope")) : ("/"));
|
|
48
|
+
navigator.serviceWorker.register(CONFIG.get("serviceWorkerURI"), {
|
|
49
|
+
scope: CONFIG.get("serviceWorkerScope")
|
|
50
|
+
})
|
|
51
|
+
.then(function (registration) {
|
|
52
|
+
logger.debug("Service Worker Registered");
|
|
53
|
+
resolve.call(_promise, registration);
|
|
54
|
+
}, function (registration) {
|
|
55
|
+
logger.debug("Error registering Service Worker");
|
|
56
|
+
reject.call(_promise, registration);
|
|
57
|
+
});
|
|
58
|
+
navigator.serviceWorker.ready.then(function (registration) {
|
|
59
|
+
logger.debug("Service Worker Ready");
|
|
60
|
+
resolve.call(_promise, registration);
|
|
61
|
+
}, function (registration) {
|
|
62
|
+
logger.debug("Error loading Service Worker");
|
|
63
|
+
reject.call(_promise, registration);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
_promise = Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
return _promise;
|
|
71
|
+
};
|
|
72
|
+
const _buildComponents = function () {
|
|
73
|
+
return new Promise<void>((resolve) => {
|
|
74
|
+
if (isBrowser) {
|
|
75
|
+
logger.debug("Starting to building components");
|
|
76
|
+
try {
|
|
77
|
+
buildComponentsStack();
|
|
78
|
+
} catch (e: any) {
|
|
79
|
+
throw Error(`Something went wrong trying to start components tree: ${e.message}`);
|
|
80
|
+
}
|
|
81
|
+
logger.debug("Initializing the service worker");
|
|
82
|
+
__load__serviceWorker.call(_top)
|
|
83
|
+
.catch(function (e) {
|
|
84
|
+
logger.debug(`error loading the service worker ${e}`);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
resolve();
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return new Promise<any> ((resolve) => {
|
|
92
|
+
logger.debug("Starting to load the config settings...");
|
|
93
|
+
if (CONFIG.get("useConfigService", false)) {
|
|
94
|
+
logger.debug("Loading settings using local configuration file...");
|
|
95
|
+
setConfigService(new ConfigService());
|
|
96
|
+
configService.configLoaded = _buildComponents;
|
|
97
|
+
serviceLoader(configService)
|
|
98
|
+
?.then((standardResponse:any)=> {
|
|
99
|
+
resolve(standardResponse);
|
|
100
|
+
})
|
|
101
|
+
?.catch ((e:any) => {throw new Error (`An error ocurred while trying to load ${configService.url}: ${e}`);});
|
|
102
|
+
} else {
|
|
103
|
+
logger.debug("Starting to load the components...");
|
|
104
|
+
_buildComponents.call(this)
|
|
105
|
+
.then(()=> {
|
|
106
|
+
resolve({});
|
|
107
|
+
})
|
|
108
|
+
.catch((e:any) => {throw new Error (`An error ocurred while trying to build the components stack. ${e}`);});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Package("com.qcobjects", [
|
|
117
|
+
GlobalSettings
|
|
118
|
+
]);
|
package/src/index.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import QCObjects from "./QCObjects.js";
|
|
1
|
+
import * as QCObjects from "./QCObjects.js";
|
|
2
2
|
export default QCObjects;
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import QCObjects from "./QCObjects";
|
|
1
|
+
import * as QCObjects from "./QCObjects";
|
|
2
2
|
export default QCObjects;
|