@omnia/velcron 7.0.36-preview

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 (112) hide show
  1. package/README.md +6 -0
  2. package/actions/ActionResults.d.ts +4 -0
  3. package/actions/ActionResults.js +14 -0
  4. package/actions/Alert.d.ts +2 -0
  5. package/actions/Alert.js +12 -0
  6. package/actions/Array.d.ts +3 -0
  7. package/actions/Array.js +22 -0
  8. package/actions/Debounce.d.ts +2 -0
  9. package/actions/Debounce.js +43 -0
  10. package/actions/Delay.d.ts +2 -0
  11. package/actions/Delay.js +14 -0
  12. package/actions/Emit.d.ts +2 -0
  13. package/actions/Emit.js +25 -0
  14. package/actions/Http.d.ts +2 -0
  15. package/actions/Http.js +15 -0
  16. package/actions/IActionHandler.d.ts +5 -0
  17. package/actions/IActionHandler.js +2 -0
  18. package/actions/Log.d.ts +2 -0
  19. package/actions/Log.js +10 -0
  20. package/actions/MsGraph.d.ts +2 -0
  21. package/actions/MsGraph.js +16 -0
  22. package/actions/MsSharePoint.d.ts +2 -0
  23. package/actions/MsSharePoint.js +17 -0
  24. package/actions/index.d.ts +11 -0
  25. package/actions/index.js +14 -0
  26. package/index.d.ts +6 -0
  27. package/index.js +9 -0
  28. package/internal-do-not-import-from-here/shared/models/Bring.d.ts +23 -0
  29. package/internal-do-not-import-from-here/shared/models/Bring.js +2 -0
  30. package/internal-do-not-import-from-here/shared/models/Broadcasting.d.ts +25 -0
  31. package/internal-do-not-import-from-here/shared/models/Broadcasting.js +12 -0
  32. package/internal-do-not-import-from-here/shared/models/Future.d.ts +44 -0
  33. package/internal-do-not-import-from-here/shared/models/Future.js +122 -0
  34. package/internal-do-not-import-from-here/shared/models/Guid.d.ts +17 -0
  35. package/internal-do-not-import-from-here/shared/models/Guid.js +51 -0
  36. package/internal-do-not-import-from-here/shared/models/OmniaSharedBootstrapData.d.ts +25 -0
  37. package/internal-do-not-import-from-here/shared/models/OmniaSharedBootstrapData.js +2 -0
  38. package/internal-do-not-import-from-here/shared/models/Realtime.d.ts +40 -0
  39. package/internal-do-not-import-from-here/shared/models/Realtime.js +40 -0
  40. package/internal-do-not-import-from-here/shared/models/SharedConstants.d.ts +5 -0
  41. package/internal-do-not-import-from-here/shared/models/SharedConstants.js +9 -0
  42. package/internal-do-not-import-from-here/shared/models/StringExtensions.d.ts +6 -0
  43. package/internal-do-not-import-from-here/shared/models/StringExtensions.js +3 -0
  44. package/internal-do-not-import-from-here/shared/models/Tenant.d.ts +4 -0
  45. package/internal-do-not-import-from-here/shared/models/Tenant.js +2 -0
  46. package/internal-do-not-import-from-here/shared/models/Tokens.d.ts +13 -0
  47. package/internal-do-not-import-from-here/shared/models/Tokens.js +2 -0
  48. package/internal-do-not-import-from-here/shared/models/Topic.d.ts +10 -0
  49. package/internal-do-not-import-from-here/shared/models/Topic.js +2 -0
  50. package/internal-do-not-import-from-here/shared/models/WorkerProxyFuncs.d.ts +8 -0
  51. package/internal-do-not-import-from-here/shared/models/WorkerProxyFuncs.js +14 -0
  52. package/internal-do-not-import-from-here/shared/models/Workers.d.ts +29 -0
  53. package/internal-do-not-import-from-here/shared/models/Workers.js +8 -0
  54. package/internal-do-not-import-from-here/shared/models/index.d.ts +14 -0
  55. package/internal-do-not-import-from-here/shared/models/index.js +18 -0
  56. package/internal-do-not-import-from-here/shared/models/theming/BlueprintDefinition.d.ts +27 -0
  57. package/internal-do-not-import-from-here/shared/models/theming/BlueprintDefinition.js +2 -0
  58. package/internal-do-not-import-from-here/shared/models/theming/OmniaThemes.d.ts +5 -0
  59. package/internal-do-not-import-from-here/shared/models/theming/OmniaThemes.js +18 -0
  60. package/internal-do-not-import-from-here/shared/models/theming/ThemeDefinitionV2.d.ts +61 -0
  61. package/internal-do-not-import-from-here/shared/models/theming/ThemeDefinitionV2.js +24 -0
  62. package/internal-do-not-import-from-here/shared/models/theming/ThemeMethods.d.ts +11 -0
  63. package/internal-do-not-import-from-here/shared/models/theming/ThemeMethods.js +143 -0
  64. package/internal-do-not-import-from-here/shared/models/theming/TypographyDefinition.d.ts +29 -0
  65. package/internal-do-not-import-from-here/shared/models/theming/TypographyDefinition.js +11 -0
  66. package/internal-do-not-import-from-here/shared/models/theming/index.d.ts +4 -0
  67. package/internal-do-not-import-from-here/shared/models/theming/index.js +7 -0
  68. package/models/Enums.d.ts +53 -0
  69. package/models/Enums.js +65 -0
  70. package/models/VelcronDefinitions.d.ts +268 -0
  71. package/models/VelcronDefinitions.js +8 -0
  72. package/models/VelcronDescriptors.d.ts +35 -0
  73. package/models/VelcronDescriptors.js +2 -0
  74. package/models/VelcronEvents.d.ts +16 -0
  75. package/models/VelcronEvents.js +2 -0
  76. package/models/VelcronTypes.d.ts +10 -0
  77. package/models/VelcronTypes.js +2 -0
  78. package/models/VelcronUnitProvider.d.ts +5 -0
  79. package/models/VelcronUnitProvider.js +2 -0
  80. package/models/ViewModelAndContext.d.ts +4 -0
  81. package/models/ViewModelAndContext.js +2 -0
  82. package/models/index.d.ts +7 -0
  83. package/models/index.js +10 -0
  84. package/package.json +27 -0
  85. package/parser/TextValue.d.ts +4 -0
  86. package/parser/TextValue.js +9 -0
  87. package/parser/VelcronActions.d.ts +36 -0
  88. package/parser/VelcronActions.js +443 -0
  89. package/parser/VelcronConstants.d.ts +29 -0
  90. package/parser/VelcronConstants.js +32 -0
  91. package/parser/VelcronData.d.ts +39 -0
  92. package/parser/VelcronData.js +638 -0
  93. package/parser/VelcronLogger.d.ts +6 -0
  94. package/parser/VelcronLogger.js +18 -0
  95. package/parser/VelcronRenderers.d.ts +41 -0
  96. package/parser/VelcronRenderers.js +126 -0
  97. package/parser/VelcronStyles.d.ts +12 -0
  98. package/parser/VelcronStyles.js +159 -0
  99. package/parser/index.d.ts +7 -0
  100. package/parser/index.js +10 -0
  101. package/stores/ReactivitySystem.d.ts +5 -0
  102. package/stores/ReactivitySystem.js +12 -0
  103. package/stores/VelcronStore.d.ts +12 -0
  104. package/stores/VelcronStore.js +23 -0
  105. package/stores/VelcronTheming.d.ts +19 -0
  106. package/stores/VelcronTheming.js +49 -0
  107. package/stores/index.d.ts +3 -0
  108. package/stores/index.js +6 -0
  109. package/utilities/ColorUtility.d.ts +1 -0
  110. package/utilities/ColorUtility.js +45 -0
  111. package/utilities/index.d.ts +1 -0
  112. package/utilities/index.js +4 -0
@@ -0,0 +1,638 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VelcronData = void 0;
4
+ const models_1 = require("../models");
5
+ const VelcronConstants_1 = require("./VelcronConstants");
6
+ const VelcronLogger_1 = require("./VelcronLogger");
7
+ const TextValue_1 = require("./TextValue");
8
+ class VelcronData {
9
+ static dataBind(renderContext, text) {
10
+ if (!VelcronData.isString(text)) {
11
+ return text;
12
+ }
13
+ const tokens = this.getTokens(text);
14
+ tokens.forEach((name) => {
15
+ let data = this.getOrSetObjectByPathUsingRenderContext(renderContext, name);
16
+ const token = VelcronConstants_1.VelcronConstants.properties.tokenStart + name + VelcronConstants_1.VelcronConstants.properties.tokenEnd;
17
+ if (data instanceof TextValue_1.TextValue) {
18
+ data = data.value;
19
+ }
20
+ text = text.replace(token, data);
21
+ });
22
+ return text;
23
+ }
24
+ static addCtxToVariableNames(template, skipIfNameStartsWith, skipIfNameMatches, overridePrefixWhenNameMatches) {
25
+ const re = new RegExp(/[^0-9a-z-.'$]/, "gi");
26
+ const results = [];
27
+ let match;
28
+ let lastIndex;
29
+ while (lastIndex = re.lastIndex, match = re.exec(template)) {
30
+ const text = template.substring(lastIndex, match.index);
31
+ if (text.length > 0 && text.startsWith("'") === false && text.endsWith("'") === false) {
32
+ results.push({ text: text, index: lastIndex });
33
+ }
34
+ }
35
+ results.push({ text: template.substring(lastIndex), index: lastIndex });
36
+ let appendedLenght = 0;
37
+ results.forEach((variableMatch) => {
38
+ //variable name cant start as a number
39
+ //'' is not allowed as variable name we used it in regex so if a value is set
40
+ //containing same name as a variable it will not be replaced
41
+ if (isNaN(variableMatch.text.substring(0, 1)) && (!variableMatch.text.startsWith("'")) && variableMatch.text.length > 0) {
42
+ if (skipIfNameStartsWith && variableMatch.text.startsWith(skipIfNameStartsWith) || skipIfNameMatches && skipIfNameMatches.filter(p => p === variableMatch.text).length > 0) { }
43
+ else {
44
+ let subName = variableMatch.text;
45
+ if (subName.startsWith(VelcronConstants_1.VelcronConstants.state.stateRootToken)) {
46
+ subName = subName.substring(VelcronConstants_1.VelcronConstants.state.stateRootToken.length + 1);
47
+ }
48
+ let prefix = variableMatch.text.startsWith(VelcronConstants_1.VelcronConstants.state.stateRootToken) ? "rootCtx " : "currentCtx";
49
+ if (overridePrefixWhenNameMatches && overridePrefixWhenNameMatches[variableMatch.text]) {
50
+ prefix = overridePrefixWhenNameMatches[variableMatch.text];
51
+ }
52
+ else if (overridePrefixWhenNameMatches && variableMatch.text.indexOf(".") > -1) {
53
+ //TODO: If this gets issues we need make overridePrefixWhenNameMatches to contain settings object
54
+ const toMatch = variableMatch.text.substring(0, variableMatch.text.indexOf("."));
55
+ if (overridePrefixWhenNameMatches[toMatch]) {
56
+ prefix = overridePrefixWhenNameMatches[toMatch];
57
+ subName = variableMatch.text.substring(toMatch.length + 1);
58
+ }
59
+ }
60
+ const newName = `${prefix.trim()}.${subName}`;
61
+ template = template.substring(0, (variableMatch.index + appendedLenght)) + newName + template.substring((variableMatch.index + appendedLenght) + variableMatch.text.length);
62
+ appendedLenght = +prefix.length + 1;
63
+ }
64
+ }
65
+ });
66
+ return template;
67
+ }
68
+ static evauluateJs(template, renderContext, overrideNamesMatching = null) {
69
+ const obj = [];
70
+ const names = [];
71
+ let propertiesToEval = {};
72
+ if (renderContext.properties) {
73
+ //Custom component properties evaluation
74
+ propertiesToEval = {};
75
+ Object.keys(renderContext.properties).forEach((key) => {
76
+ propertiesToEval[key] = "properties";
77
+ });
78
+ names.push("properties");
79
+ obj.push(renderContext.properties);
80
+ }
81
+ else if (overrideNamesMatching) {
82
+ propertiesToEval = overrideNamesMatching;
83
+ }
84
+ const reservedWords = [
85
+ "null",
86
+ "return"
87
+ ];
88
+ template = VelcronData.addCtxToVariableNames(template, undefined, reservedWords, propertiesToEval);
89
+ names.push("rootCtx");
90
+ names.push("currentCtx");
91
+ obj.push(renderContext.rootContext);
92
+ obj.push(renderContext.currentContext);
93
+ //TODO we shouls try catch and return info
94
+ const evalResult = Function(...names, "\"use strict\";return " + template)(...obj);
95
+ return evalResult;
96
+ }
97
+ static deleteVariables(id) {
98
+ if (VelcronData.variables[id]) {
99
+ delete VelcronData.variables[id];
100
+ }
101
+ }
102
+ static getVariable(name, renderContext) {
103
+ const variables = VelcronData.variables;
104
+ const result = { is: false, value: undefined };
105
+ if (renderContext.id &&
106
+ variables.hasOwnProperty(renderContext.id) &&
107
+ variables[renderContext.id].hasOwnProperty(name)) {
108
+ result.value = variables[renderContext.id][name];
109
+ result.is = true;
110
+ }
111
+ return result;
112
+ }
113
+ static setVariables(eventId, varsToSet) {
114
+ const variables = VelcronData.variables;
115
+ if (!variables[eventId]) {
116
+ variables[eventId] = {};
117
+ }
118
+ Object.keys(varsToSet).forEach((key) => {
119
+ variables[eventId][key] = varsToSet[key];
120
+ });
121
+ }
122
+ static evaluateSet(path, value, renderContext) {
123
+ const obj = [];
124
+ const names = [];
125
+ let assignOperator = models_1.AssignOperators.equals;
126
+ path = path.trim();
127
+ const variables = VelcronData.variables;
128
+ let isReturnValueSet = false;
129
+ let runEvaluation = true;
130
+ let runAssignment = true;
131
+ let directVariableAssignment = false;
132
+ let variableReassignmentFromPath = false;
133
+ let variableReassignmentFromValue = false;
134
+ let variableReassignmentFromValueIsFromVariable = false;
135
+ let pathSubLength = 0;
136
+ if (!path) {
137
+ return;
138
+ }
139
+ if (path === VelcronConstants_1.VelcronConstants.events.returnValueVariableName) {
140
+ isReturnValueSet = true;
141
+ path = value;
142
+ }
143
+ //Increment or decrement assignment
144
+ if (path.endsWith(models_1.AssignOperators.plusPlus) || path.endsWith(models_1.AssignOperators.minusMinus)) {
145
+ //increment or decrement after wont work since we dont operate on the real object
146
+ VelcronLogger_1.VelcronLogger.logActionError(`Only prefix increment/decrement operator is supported: ${path}`);
147
+ return;
148
+ }
149
+ else if (path.endsWith(models_1.AssignOperators.equalsPlus)) {
150
+ assignOperator = models_1.AssignOperators.equalsPlus;
151
+ path = path.substring(0, path.length - models_1.AssignOperators.equalsPlus.length);
152
+ }
153
+ else if (path.endsWith(models_1.AssignOperators.plusEquals)) {
154
+ assignOperator = models_1.AssignOperators.plusEquals;
155
+ path = path.substring(0, path.length - models_1.AssignOperators.plusEquals.length);
156
+ }
157
+ else if (path.endsWith(models_1.AssignOperators.equalsQuestion)) {
158
+ assignOperator = models_1.AssignOperators.equalsQuestion;
159
+ path = path.substring(0, path.length - models_1.AssignOperators.equalsQuestion.length);
160
+ runAssignment = false;
161
+ }
162
+ else if (path.startsWith(models_1.AssignOperators.plusPlus) || path.startsWith(models_1.AssignOperators.minusMinus)) {
163
+ assignOperator = path.substring(0, 2);
164
+ path = path.substring(2);
165
+ }
166
+ else if (path.endsWith(models_1.AssignOperators.equals)) {
167
+ assignOperator = models_1.AssignOperators.equals;
168
+ path = path.substring(0, path.length - models_1.AssignOperators.equals.length);
169
+ }
170
+ else if (path.endsWith(models_1.AssignOperators.equalsExclamation)) {
171
+ assignOperator = models_1.AssignOperators.equalsExclamation;
172
+ path = path.substring(0, path.length - models_1.AssignOperators.equalsExclamation.length);
173
+ }
174
+ path = path.trim();
175
+ //Support both var and let for local variables at the moment
176
+ if (path.startsWith("var ") || path.startsWith("let ")) {
177
+ pathSubLength = 4;
178
+ directVariableAssignment = true;
179
+ }
180
+ else if (renderContext.id &&
181
+ variables.hasOwnProperty(renderContext.id) &&
182
+ VelcronData.getOrSetObjectByPath(variables[renderContext.id], path) != undefined) {
183
+ variableReassignmentFromPath = true;
184
+ //value = VelcronData.getOrSetObjectByPath(variables[renderContext.id], value);
185
+ }
186
+ else if (renderContext.id &&
187
+ VelcronData.isString(value) &&
188
+ variables.hasOwnProperty(renderContext.id) &&
189
+ VelcronData.getOrSetObjectByPath(variables[renderContext.id], value) != undefined) {
190
+ variableReassignmentFromValue = true;
191
+ if (variables[renderContext.id] && variables[renderContext.id][path] != undefined) {
192
+ variableReassignmentFromValueIsFromVariable = true;
193
+ }
194
+ }
195
+ if (directVariableAssignment || variableReassignmentFromPath || variableReassignmentFromValue || isReturnValueSet) {
196
+ //Set result to temp variable
197
+ if (renderContext.id && !variables[renderContext.id]) {
198
+ variables[renderContext.id] = {};
199
+ }
200
+ if (VelcronData.isString(value) || value instanceof TextValue_1.TextValue) {
201
+ if (value instanceof TextValue_1.TextValue) {
202
+ //If the text value is returned from an action
203
+ //let text = 'Hello world' => return text
204
+ //Then we create TextValue class so we know that it is a string
205
+ //Action1 prints text from functions > Action2 returns text > Action 3 returns text
206
+ //The support is in the DataBind to bind the text value from the TextValue class
207
+ }
208
+ else {
209
+ let strValue = value.trim();
210
+ //Direct string assignment remove the ' ' in the string
211
+ if (strValue.startsWith("'") && strValue.endsWith(("'"))) {
212
+ strValue = strValue.substring(1, strValue.length - 1);
213
+ value = new TextValue_1.TextValue(VelcronData.dataBind(renderContext, strValue));
214
+ }
215
+ else if (renderContext.id && variableReassignmentFromValue) {
216
+ //Get the variable from value = parameter value
217
+ //@show(show): @data.loading = show
218
+ //value = variables[renderContext.id][value];
219
+ value = VelcronData.getOrSetObjectByPath(variables[renderContext.id], value);
220
+ }
221
+ else if (renderContext.id && variables[renderContext.id][path.substring(pathSubLength)]) {
222
+ //Try to get from previously assigned variable
223
+ value = variables[renderContext.id][path.substring(pathSubLength)];
224
+ }
225
+ else {
226
+ //Try get value from rootContext or currentContext
227
+ value = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, value);
228
+ }
229
+ }
230
+ }
231
+ if (renderContext?.parent?.id && isReturnValueSet) {
232
+ const toSet = {};
233
+ toSet[VelcronConstants_1.VelcronConstants.events.returnValueVariableName] = value;
234
+ VelcronData.setVariables(renderContext.parent.id, toSet);
235
+ //variables[renderContext.parent.id][VelcronConstants.events.returnValueVariableName] = value;
236
+ }
237
+ else if (renderContext.id && !variableReassignmentFromValue) {
238
+ variables[renderContext.id][path.substring(pathSubLength)] = value;
239
+ }
240
+ runEvaluation = false;
241
+ runAssignment = false;
242
+ if (variableReassignmentFromValue && !variableReassignmentFromValueIsFromVariable) {
243
+ //runAssignment = true;
244
+ runEvaluation = true;
245
+ }
246
+ }
247
+ const existingVal = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, path);
248
+ if (assignOperator === models_1.AssignOperators.equals || assignOperator === models_1.AssignOperators.equalsExclamation) {
249
+ //debugger;
250
+ if (typeof existingVal === "boolean" && typeof value !== "boolean") {
251
+ if (assignOperator === models_1.AssignOperators.equalsExclamation) {
252
+ value = !existingVal;
253
+ }
254
+ const isBool = VelcronData.tryParseBoolean(value);
255
+ if (isBool.is) {
256
+ value = isBool.value;
257
+ }
258
+ else {
259
+ VelcronLogger_1.VelcronLogger.logDataError(`Error setting boolean value for property with path ${path} the source datatype is not a boolean`);
260
+ }
261
+ }
262
+ else if (typeof existingVal === "number" && typeof value !== "number") {
263
+ if (isNaN(value)) {
264
+ VelcronLogger_1.VelcronLogger.logDataError(`The view model property ${path} is a number but the value tried to be set is a string. Its not allowed to change type of source property`);
265
+ }
266
+ value = parseInt(value);
267
+ }
268
+ }
269
+ if (runAssignment) {
270
+ if (VelcronData.isString(value) && value.startsWith("'") && value.endsWith("'")) {
271
+ // Value is string assignment
272
+ // "$state.title = 'Hello'"
273
+ value = value.substring(1, value.length - 1);
274
+ }
275
+ else if (assignOperator && VelcronData.isString(value)) {
276
+ //Value is assignment from renderContext
277
+ // "$state.title = title" or "$state.title = $state.anotherTitle"
278
+ if (value === "this") {
279
+ // $state.currentItem = this (this means currentContext)
280
+ value = renderContext.currentContext;
281
+ }
282
+ else {
283
+ if (value === "null") {
284
+ //$state.currentItem = null;
285
+ value = null;
286
+ }
287
+ else {
288
+ //try get value from render context
289
+ value = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, value);
290
+ }
291
+ }
292
+ }
293
+ }
294
+ if (runEvaluation) {
295
+ if (path.indexOf(VelcronConstants_1.VelcronConstants.state.stateRootToken) > -1) {
296
+ path = path.replace(VelcronConstants_1.VelcronConstants.state.stateRootToken, "rootCtx");
297
+ }
298
+ else {
299
+ path = path.replace(path, `currentCtx.${path}`);
300
+ }
301
+ if (renderContext.id &&
302
+ variables.hasOwnProperty(renderContext.id) &&
303
+ VelcronData.getOrSetObjectByPath(variables[renderContext.id], value) != undefined) {
304
+ value = VelcronData.getOrSetObjectByPath(variables[renderContext.id], value);
305
+ }
306
+ let template = path;
307
+ if (assignOperator === models_1.AssignOperators.plusPlus || assignOperator === models_1.AssignOperators.minusMinus) {
308
+ //++var or --var
309
+ template = assignOperator + path;
310
+ }
311
+ else if (assignOperator === models_1.AssignOperators.equalsPlus || assignOperator === models_1.AssignOperators.plusEquals) {
312
+ if (Array.isArray(existingVal)) {
313
+ names.push("value");
314
+ obj.push(value);
315
+ const method = assignOperator === models_1.AssignOperators.equalsPlus ? "push" : "unshift";
316
+ if (Array.isArray(value)) {
317
+ template = `value.forEach((v)=>{ ${path}.${method}(v) })`;
318
+ }
319
+ else {
320
+ template = `${path}.${method}(value)`;
321
+ }
322
+ }
323
+ }
324
+ else if (assignOperator === models_1.AssignOperators.equalsQuestion) {
325
+ if (Array.isArray(existingVal)) {
326
+ //fix this
327
+ value = VelcronData.addCtxToVariableNames(value, ".");
328
+ const pattern = /(?:^|\W)\.(\w+)(?!\w)/;
329
+ const re = new RegExp(pattern, "g");
330
+ let match;
331
+ while ((match = re.exec(value)) != null) {
332
+ if (match.index) {
333
+ value = value.substring(0, (match.index)) + ` $$$obj${match[0].trim()}` + value.substring(match.index + match[0].length);
334
+ }
335
+ }
336
+ template = `${template} = ${template}.filter($$$obj => ${value});`;
337
+ }
338
+ }
339
+ else {
340
+ //var = val
341
+ names.push("value");
342
+ obj.push(value);
343
+ template = `${path}=value`;
344
+ }
345
+ names.push("rootCtx");
346
+ names.push("currentCtx");
347
+ obj.push(renderContext.rootContext);
348
+ obj.push(renderContext.currentContext);
349
+ //TODO we shouls try catch and return info
350
+ try {
351
+ const evalResult = Function(...names, "\"use strict\";" + template)(...obj);
352
+ }
353
+ catch (error) {
354
+ VelcronLogger_1.VelcronLogger.logDataError(`Error in VelcronData: ${error}`);
355
+ }
356
+ }
357
+ }
358
+ static evaluateArray(template, renderContext) {
359
+ let result = null;
360
+ const evalResult = VelcronData.evauluateJs(template, renderContext);
361
+ if (Array.isArray(evalResult)) {
362
+ result = evalResult;
363
+ }
364
+ else {
365
+ VelcronLogger_1.VelcronLogger.logDataError(`Cant evaluate ${template} to a Array`);
366
+ }
367
+ return result;
368
+ }
369
+ static evaluateBoolean(template, renderContext) {
370
+ if (VelcronData.isUndefined(template)) {
371
+ return false;
372
+ }
373
+ if (VelcronData.isBoolean(template)) {
374
+ return template;
375
+ }
376
+ const evalResult = VelcronData.evauluateJs(template, renderContext);
377
+ if (evalResult === null || VelcronData.isUndefined(evalResult)) {
378
+ return false;
379
+ }
380
+ const parseRes = this.tryParseBoolean(evalResult);
381
+ let result = null;
382
+ if (parseRes.is) {
383
+ result = parseRes.value;
384
+ }
385
+ else {
386
+ VelcronLogger_1.VelcronLogger.logDataError(`Cant evaluate ${template} to a boolean`);
387
+ }
388
+ return result;
389
+ }
390
+ static tryParseBoolean(bool) {
391
+ const result = {
392
+ is: false,
393
+ value: null
394
+ };
395
+ if (typeof bool === "boolean") {
396
+ result.value = bool;
397
+ result.is = true;
398
+ }
399
+ else if (typeof bool === "string") {
400
+ switch (bool.toLowerCase().trim()) {
401
+ case "true":
402
+ result.value = true;
403
+ result.is = true;
404
+ break;
405
+ case "false":
406
+ case null:
407
+ result.value = false;
408
+ result.is = true;
409
+ break;
410
+ }
411
+ }
412
+ return result;
413
+ }
414
+ static isString(text) {
415
+ return typeof text === "string" || text instanceof String;
416
+ }
417
+ static isBoolean(value) {
418
+ return typeof value === "boolean" ? true : false;
419
+ }
420
+ static isNumber(value) {
421
+ return !isNaN(value);
422
+ }
423
+ static isUndefined(value) {
424
+ return typeof value === "undefined";
425
+ }
426
+ static isArray(obj) {
427
+ return Array.isArray(obj);
428
+ }
429
+ static isObject(value) {
430
+ return typeof value === "object" &&
431
+ !Array.isArray(value) &&
432
+ value !== null;
433
+ }
434
+ static extendObject(obj) {
435
+ //Give objects some powerups
436
+ if (VelcronData.isUndefined(obj)) {
437
+ return obj;
438
+ }
439
+ if (VelcronData.isArray(obj)) {
440
+ //obj.take(5) => returns 5 items
441
+ obj.take = (amount) => {
442
+ return obj = obj.slice(0, amount);
443
+ };
444
+ }
445
+ return obj;
446
+ }
447
+ static getOrSetObjectByPath(object, path, value = undefined) {
448
+ if (typeof path !== "string") {
449
+ return null;
450
+ }
451
+ if (path === "") {
452
+ //If we pass $state = root we just return object
453
+ return object;
454
+ }
455
+ path = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties
456
+ path = path.replace(/^\./, ""); // strip a leading dot
457
+ const a = path.split(".");
458
+ const lastParent = null;
459
+ for (let i = 0, n = a.length; i < n; ++i) {
460
+ const k = a[i];
461
+ if (object.hasOwnProperty(k)) {
462
+ //
463
+ if (typeof value !== "undefined" && (i + 1) == a.length) {
464
+ if (Array.isArray(object[k]) && typeof value === "string" || value instanceof String) {
465
+ //Support resetting Arrays
466
+ if (value.trim() === "[]") {
467
+ value = [];
468
+ }
469
+ }
470
+ else if (typeof object[k] === "boolean") {
471
+ const isBool = VelcronData.tryParseBoolean(value);
472
+ if (isBool.is) {
473
+ value = isBool.value;
474
+ }
475
+ else {
476
+ VelcronLogger_1.VelcronLogger.logDataError(`Error setting boolean value for property with name ${k} the source datatype is not a boolean`);
477
+ }
478
+ }
479
+ object[k] = VelcronData.extendObject(value);
480
+ }
481
+ object = VelcronData.extendObject(object[k]);
482
+ }
483
+ else {
484
+ //If the property does not exist we create it to make it reactive
485
+ //Todo this only works if the parent object exists already
486
+ //we should throw warning/exception
487
+ // if (value) {
488
+ // Vue.set(object, k, value);
489
+ // }
490
+ return null;
491
+ }
492
+ }
493
+ return object;
494
+ }
495
+ static getOrSetObjectByPathUsingRenderContext(renderContext, path, value = undefined) {
496
+ let result;
497
+ if (VelcronData.isUndefined(path)) {
498
+ return result;
499
+ }
500
+ const variables = VelcronData.variables;
501
+ if (renderContext.id &&
502
+ variables.hasOwnProperty(renderContext.id) &&
503
+ variables[renderContext.id].hasOwnProperty(value)) {
504
+ result = variables[renderContext.id][value];
505
+ }
506
+ else if (renderContext.id &&
507
+ variables.hasOwnProperty(renderContext.id) &&
508
+ variables[renderContext.id].hasOwnProperty(path)) {
509
+ result = variables[renderContext.id][path];
510
+ }
511
+ else {
512
+ let pathIsPropertyValue = false;
513
+ if (renderContext.properties?.hasOwnProperty(path)) {
514
+ pathIsPropertyValue = true;
515
+ const propObj = renderContext.properties[path];
516
+ if (VelcronData.isString(propObj)) {
517
+ const propString = propObj;
518
+ path = VelcronData.dataBind(renderContext, propString);
519
+ }
520
+ result = propObj;
521
+ }
522
+ if (!result || VelcronData.isString(result)) {
523
+ const tokens = VelcronData.getTokens(path);
524
+ if (tokens.length > 0) {
525
+ path = tokens[0];
526
+ }
527
+ let object = null;
528
+ if (path.startsWith(`${VelcronConstants_1.VelcronConstants.state.stateRootToken}.`) || path === VelcronConstants_1.VelcronConstants.state.stateRootToken) {
529
+ //Fetch from the data object
530
+ object = renderContext.rootContext;
531
+ path = path.substring(6);
532
+ }
533
+ else {
534
+ //Fetch from current ctx
535
+ object = renderContext.currentContext;
536
+ }
537
+ if (VelcronData.isObject(object)) {
538
+ result = VelcronData.getOrSetObjectByPath(object, path, value);
539
+ }
540
+ else {
541
+ //For example if you bind to Array of ["string"] the currentContext is only a string so we just return the object without mapping path
542
+ result = object;
543
+ }
544
+ if (typeof result === "undefined" && pathIsPropertyValue) {
545
+ result = path;
546
+ }
547
+ }
548
+ }
549
+ return result;
550
+ }
551
+ static getTokens(template) {
552
+ const tokens = [];
553
+ if (template) {
554
+ template.replace(/(\${).+?(?=\})/g, (tokenWithVar, token) => {
555
+ tokens.push(tokenWithVar.substring(2));
556
+ return token;
557
+ });
558
+ }
559
+ return tokens;
560
+ }
561
+ static ensureEventId(event) {
562
+ return event.startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart) ?
563
+ event :
564
+ VelcronConstants_1.VelcronConstants.events.idTokenStart + VelcronData.generateId() + VelcronConstants_1.VelcronConstants.events.idTokenEnd + " " + event;
565
+ }
566
+ static ensureKeys(ui, generateNewKeys = false) {
567
+ if (!ui.key || generateNewKeys) {
568
+ ui.key = VelcronData.generateId();
569
+ }
570
+ if (ui.events) {
571
+ Object.keys(ui.events).forEach((key) => {
572
+ const evArr = ui.events ? ui.events[key] : [];
573
+ //Only the first item in the events array need id
574
+ if (evArr.length > 0 && !evArr[0].startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart)) {
575
+ evArr[0] = VelcronData.ensureEventId(evArr[0]);
576
+ }
577
+ });
578
+ }
579
+ Object.keys(ui).forEach((key) => {
580
+ if (Array.isArray(ui[key])) {
581
+ ui[key].forEach((item) => {
582
+ if (!item.key || generateNewKeys) {
583
+ item.key = VelcronData.generateId();
584
+ }
585
+ VelcronData.ensureKeys(item, generateNewKeys);
586
+ });
587
+ }
588
+ });
589
+ }
590
+ static removeKeys(ui) {
591
+ if (ui.key) {
592
+ delete ui.key;
593
+ }
594
+ if (ui.events) {
595
+ Object.keys(ui.events).forEach((key) => {
596
+ const evArr = ui.events ? ui.events[key] : [];
597
+ if (evArr.length > 0 && evArr[0].startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart)) {
598
+ evArr[0] = evArr[0].substring(VelcronConstants_1.VelcronConstants.events.idTokenStart.length + VelcronData.generateId().length + VelcronConstants_1.VelcronConstants.events.idTokenEnd.length).trim();
599
+ }
600
+ });
601
+ }
602
+ if (ui.actions) {
603
+ const appDef = ui;
604
+ if (appDef.actions) {
605
+ Object.keys(appDef.actions).forEach((key) => {
606
+ const actionArr = appDef.actions ? appDef.actions[key] : [];
607
+ if (actionArr.length > 0 && actionArr[0].startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart)) {
608
+ actionArr[0] = actionArr[0].substring(VelcronConstants_1.VelcronConstants.events.idTokenStart.length + VelcronData.generateId().length + VelcronConstants_1.VelcronConstants.events.idTokenEnd.length).trim();
609
+ }
610
+ });
611
+ }
612
+ }
613
+ Object.keys(ui).forEach((key) => {
614
+ if (Array.isArray(ui[key])) {
615
+ ui[key].forEach((item) => {
616
+ if (item.key) {
617
+ delete item.key;
618
+ }
619
+ VelcronData.removeKeys(item);
620
+ });
621
+ }
622
+ });
623
+ }
624
+ static generateId() {
625
+ const firstPart = (Math.random() * 46656) | 0;
626
+ const secondPart = (Math.random() * 46656) | 0;
627
+ return (("000" + firstPart.toString(36)).slice(-3) + ("000" + secondPart.toString(36)).slice(-3)).toString();
628
+ }
629
+ static createDeferredPromise() {
630
+ let resolve, reject;
631
+ const promise = new Promise((res, rej) => {
632
+ [resolve, reject] = [res, rej];
633
+ });
634
+ return { promise, reject, resolve };
635
+ }
636
+ }
637
+ exports.VelcronData = VelcronData;
638
+ VelcronData.variables = {};
@@ -0,0 +1,6 @@
1
+ export declare class VelcronLogger {
2
+ static logDataError(log: string): void;
3
+ static logActionError(log: string): void;
4
+ static logError(log: string): void;
5
+ static logCustomComponentError(log: string): void;
6
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VelcronLogger = void 0;
4
+ class VelcronLogger {
5
+ static logDataError(log) {
6
+ console.error(log);
7
+ }
8
+ static logActionError(log) {
9
+ console.error(log);
10
+ }
11
+ static logError(log) {
12
+ console.error(log);
13
+ }
14
+ static logCustomComponentError(log) {
15
+ console.error(log);
16
+ }
17
+ }
18
+ exports.VelcronLogger = VelcronLogger;