@omnia/velcron 8.0.141-dev → 8.0.142-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,3 @@
1
1
  import { IActionHandler } from "./IActionHandler";
2
2
  export declare const objClone: IActionHandler;
3
+ export declare const objAssign: IActionHandler;
package/actions/Clone.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.objClone = void 0;
3
+ exports.objAssign = exports.objClone = void 0;
4
4
  const stores_1 = require("../stores");
5
5
  exports.objClone = {
6
6
  name: "@clone",
@@ -8,3 +8,10 @@ exports.objClone = {
8
8
  action.promise.resolve(stores_1.ReactivitySystem.makeReactive(JSON.parse(JSON.stringify(objToClone))));
9
9
  }
10
10
  };
11
+ exports.objAssign = {
12
+ name: "@assign",
13
+ action: (action, source, value) => {
14
+ //debugger;
15
+ action.promise.resolve(null);
16
+ }
17
+ };
@@ -1,5 +1,5 @@
1
1
  import { GuidValue } from "../Guid";
2
- import { BoxDimensions, ComponentBlueprints, SpacingBlueprints, TypographyBlueprints } from "./Blueprints";
2
+ import { BoxDimensions, ButtonBlueprint, ComponentBlueprints, SpacingBlueprints, TypographyBlueprints } from "./Blueprints";
3
3
  export type ThemeContextType = "default" | "admin" | "preview" | "color-context" | "designer";
4
4
  export interface ColorTypeResult<resultType> {
5
5
  base: resultType;
@@ -78,6 +78,22 @@ export interface ITemplateRegistration<TTemplateType = any> {
78
78
  hidden?: boolean;
79
79
  custom?: boolean;
80
80
  }
81
+ export type RegistrationType = "button" | "chrome";
82
+ export interface ITemplateRegistration2<TTemplateType = any, TType = RegistrationType> {
83
+ type: RegistrationType;
84
+ id: GuidValue;
85
+ template: TTemplateType;
86
+ hidden?: boolean;
87
+ custom?: boolean;
88
+ }
89
+ export interface ITemplateRegistration<TTemplateType = any> {
90
+ id: GuidValue;
91
+ template: TTemplateType;
92
+ hidden?: boolean;
93
+ custom?: boolean;
94
+ }
95
+ export interface ButtonBlueprintRegistration extends ITemplateRegistration2<ButtonBlueprint, "button"> {
96
+ }
81
97
  export type ColorSchemaType = keyof typeof ColorSchemaTypes;
82
98
  export declare enum ColorSchemaTypes {
83
99
  primary = "primary",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnia/velcron",
3
3
  "license": "MIT",
4
- "version": "8.0.141-dev",
4
+ "version": "8.0.142-dev",
5
5
  "description": "Provide Omnia Velcron Stuffs.",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -12,7 +12,10 @@ export declare class VelcronActions {
12
12
  static registerAction(handler: IActionHandler): void;
13
13
  static unregisterAction(name: string): void;
14
14
  static actionArrayToString(templates: Array<string>): string;
15
- static parseAndExecuteActions(templates: Array<string>, renderContext: VelcronRenderContext, customActionContext?: VelcronCustomActionExecutionContext): Future<unknown>;
15
+ static parseAndExecuteActions(templates: Array<string>, renderContext: VelcronRenderContext, options?: {
16
+ customActionContext?: VelcronCustomActionExecutionContext;
17
+ variables?: object;
18
+ }): Future<unknown>;
16
19
  static parseFunction(target: {
17
20
  [name: string]: Array<string>;
18
21
  }, template: string, renderContext: VelcronRenderContext, params: Array<VelcronActionParameterValue>, foundCb: (name: string, params: {}) => void): void;
@@ -42,7 +42,7 @@ class VelcronActions {
42
42
  }
43
43
  //TODO this might need to be added back together with other code in the file code marked "Sub Action Resolver"
44
44
  //private static actionPromises: { [id: string]: Array<Future<void>> } = {};
45
- static parseAndExecuteActions(templates, renderContext, customActionContext) {
45
+ static parseAndExecuteActions(templates, renderContext, options) {
46
46
  if (!templates) {
47
47
  VelcronLogger_1.VelcronLogger.logActionError("The event template is empty");
48
48
  return;
@@ -52,11 +52,15 @@ class VelcronActions {
52
52
  const evIdEnd = template.indexOf(VelcronConstants_1.VelcronConstants.events.idTokenEnd);
53
53
  const evId = template.substring(VelcronConstants_1.VelcronConstants.events.idTokenStart.length, evIdEnd);
54
54
  template = template.substring(evIdEnd + 1);
55
+ if (options?.variables) {
56
+ //Support settings event specific variables example in onPersistState/onRestoreState
57
+ VelcronData_1.VelcronData.setVariables(evId, options?.variables);
58
+ }
55
59
  //TODO this might need to be added back together with other code in the file code marked "Sub Action Resolver"
56
60
  //let requiredPromises = 1;
57
61
  for (const partialTemplate of template.split("=>")) {
58
62
  if (partialTemplate) {
59
- const res = VelcronActions.getActionFromTemplate(partialTemplate, evId, renderContext, customActionContext);
63
+ const res = VelcronActions.getActionFromTemplate(partialTemplate, evId, renderContext, options?.customActionContext);
60
64
  if (res) {
61
65
  actions.push(res);
62
66
  //TODO this might need to be added back together with other code in the file code marked "Sub Action Resolver"
@@ -70,10 +74,10 @@ class VelcronActions {
70
74
  }
71
75
  }
72
76
  if (actions.length > 0) {
73
- if (customActionContext) {
74
- customActionContext.customAction = renderContext;
75
- if (customActionContext.variables) {
76
- VelcronData_1.VelcronData.setVariables(evId, customActionContext.variables);
77
+ if (options?.customActionContext) {
78
+ options.customActionContext.customAction = renderContext;
79
+ if (options.customActionContext.variables) {
80
+ VelcronData_1.VelcronData.setVariables(evId, options.customActionContext.variables);
77
81
  }
78
82
  }
79
83
  else {
@@ -86,11 +90,13 @@ class VelcronActions {
86
90
  // console.dir("All promises resolved loveliiiii");
87
91
  // });
88
92
  }
89
- VelcronActions.executeActions(actions, 0, customActionContext);
90
- //Clean up temp variables after execution
91
- VelcronData_1.VelcronData.deleteVariables(evId);
93
+ VelcronActions.executeActions(actions, 0, options?.customActionContext);
92
94
  //The returned promise will resolved when all sub async actions are resolved
93
- return shared_1.Future.all(actions.filter(p => p.promise).map(a => a.promise));
95
+ //return Future.all((actions as Array<VelcronActionWithAutoAwait>).filter(p => p.promise).map(a => a.promise)) as Future<unknown>;
96
+ return shared_1.Future.all(actions.filter(p => p.promise).map(a => a.promise)).then(() => {
97
+ //Clean up temp variables after execution
98
+ VelcronData_1.VelcronData.deleteVariables(evId);
99
+ });
94
100
  //TODO this might need to be added back together with other code in the file code marked "Sub Action Resolver"
95
101
  // return Future.all((actions as Array<VelcronActionWithAutoAwait>).filter(p => p.promise).map(a => a.promise)).then(() => {
96
102
  // const firstUnresolved = VelcronActions.actionPromises[customActionContext ? customActionContext.parentAction.id : evId].find(p => p && !p.resolved);
@@ -337,7 +343,7 @@ class VelcronActions {
337
343
  variables: params,
338
344
  returnValue: shared_1.Future.new()
339
345
  };
340
- VelcronActions.parseAndExecuteActions(acArr, awAction, customActionContext);
346
+ VelcronActions.parseAndExecuteActions(acArr, awAction, { customActionContext });
341
347
  awAction.promise = customActionContext.returnValue;
342
348
  hasCustomActionValue = true;
343
349
  });
@@ -28,6 +28,7 @@ export declare const VelcronConstants: {
28
28
  idTokenStart: string;
29
29
  idTokenEnd: string;
30
30
  returnValueVariableName: string;
31
+ persistStateVariableName: string;
31
32
  };
32
33
  state: {
33
34
  stateRootToken: string;
@@ -30,7 +30,8 @@ exports.VelcronConstants = {
30
30
  events: {
31
31
  idTokenStart: "$ev{",
32
32
  idTokenEnd: "}",
33
- returnValueVariableName: "$returnValue"
33
+ returnValueVariableName: "$returnValue",
34
+ persistStateVariableName: "$persistedState"
34
35
  },
35
36
  state: {
36
37
  stateRootToken: "$state"
@@ -25,6 +25,7 @@ export declare class VelcronData {
25
25
  static isArray(obj: any): obj is ExtendArray;
26
26
  static isObject(value: any): boolean;
27
27
  static extendObject(obj: any): any;
28
+ static propertyPathExists(obj: object, path: string): boolean;
28
29
  static getOrSetObjectByPath<T>(object: Object, path: string, value?: any): T | null;
29
30
  static getOrSet<T>(renderContext: VelcronRenderContext, path: string, value?: any): T;
30
31
  static getTokens(template: any, removeBrackets: boolean): string[];
@@ -112,12 +112,9 @@ class VelcronData {
112
112
  return result;
113
113
  }
114
114
  static setVariables(eventId, varsToSet) {
115
- const variables = VelcronData.variables;
116
- if (!variables[eventId]) {
117
- variables[eventId] = {};
118
- }
115
+ VelcronData.variables[eventId] ??= {};
119
116
  Object.keys(varsToSet).forEach((key) => {
120
- variables[eventId][key] = varsToSet[key];
117
+ VelcronData.variables[eventId][key] = varsToSet[key];
121
118
  });
122
119
  }
123
120
  static evaluateSet(path, value, renderContext) {
@@ -180,16 +177,16 @@ class VelcronData {
180
177
  }
181
178
  else if (renderContext.id &&
182
179
  variables.hasOwnProperty(renderContext.id) &&
183
- VelcronData.getOrSetObjectByPath(variables[renderContext.id], path) != undefined) {
180
+ VelcronData.propertyPathExists(variables[renderContext.id], path)) {
184
181
  variableReassignmentFromPath = true;
185
182
  //value = VelcronData.getOrSetObjectByPath(variables[renderContext.id], value);
186
183
  }
187
184
  else if (renderContext.id &&
188
185
  VelcronData.isString(value) &&
189
186
  variables.hasOwnProperty(renderContext.id) &&
190
- VelcronData.getOrSetObjectByPath(variables[renderContext.id], value) != undefined) {
187
+ VelcronData.propertyPathExists(variables[renderContext.id], value)) {
191
188
  variableReassignmentFromValue = true;
192
- if (variables[renderContext.id] && variables[renderContext.id][path] != undefined) {
189
+ if (VelcronData.propertyPathExists(variables[renderContext.id], path)) {
193
190
  variableReassignmentFromValueIsFromVariable = true;
194
191
  }
195
192
  }
@@ -236,7 +233,8 @@ class VelcronData {
236
233
  //variables[renderContext.parent.id][VelcronConstants.events.returnValueVariableName] = value;
237
234
  }
238
235
  else if (renderContext.id && !variableReassignmentFromValue) {
239
- variables[renderContext.id][path.substring(pathSubLength)] = value;
236
+ VelcronData.getOrSetObjectByPath(variables[renderContext.id], path.substring(pathSubLength), value);
237
+ //variables[renderContext.id][path.substring(pathSubLength)] = value;
240
238
  }
241
239
  runEvaluation = false;
242
240
  runAssignment = false;
@@ -448,6 +446,19 @@ class VelcronData {
448
446
  }
449
447
  return obj;
450
448
  }
449
+ static propertyPathExists(obj, path) {
450
+ const keys = path.split(".");
451
+ let current = obj;
452
+ for (const key of keys) {
453
+ if (current[key] !== undefined) {
454
+ current = current[key];
455
+ }
456
+ else {
457
+ return false;
458
+ }
459
+ }
460
+ return true;
461
+ }
451
462
  static getOrSetObjectByPath(object, path, value = undefined) {
452
463
  if (typeof path !== "string") {
453
464
  return null;