@omnia/velcron 8.0.96-vnext → 8.0.98-vnext

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/actions/Alert.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.alerter = void 0;
4
4
  exports.alerter = {
5
5
  name: "@alert",
6
- action: (action, value, nisse) => {
6
+ action: (action, value) => {
7
7
  //value = VelcronData.dataBind(action, value)
8
8
  //alert(value + nisse ? nisse : 'nullsiu');
9
9
  alert(`${value}`);
@@ -0,0 +1,3 @@
1
+ import { IActionHandler } from "./IActionHandler";
2
+ export declare const dateFormat: IActionHandler;
3
+ export declare const dateCountDown: IActionHandler;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dateCountDown = exports.dateFormat = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
+ const duration_1 = tslib_1.__importDefault(require("dayjs/plugin/duration"));
7
+ dayjs_1.default.extend(duration_1.default);
8
+ exports.dateFormat = {
9
+ name: "@date.format",
10
+ action: (action, value) => {
11
+ return Promise.resolve((0, dayjs_1.default)().format(value));
12
+ }
13
+ };
14
+ exports.dateCountDown = {
15
+ name: "@date.diff",
16
+ action: (action, date, past = false) => {
17
+ const now = (0, dayjs_1.default)();
18
+ const futureDateTime = (0, dayjs_1.default)(date);
19
+ const duration = past ? dayjs_1.default.duration(now.diff(futureDateTime)) : dayjs_1.default.duration(futureDateTime.diff(now));
20
+ const expired = past ? false : duration.asMilliseconds() <= 0;
21
+ return Promise.resolve({
22
+ years: duration.years(),
23
+ months: duration.months(),
24
+ days: duration.days(),
25
+ hours: duration.hours(),
26
+ minutes: duration.minutes(),
27
+ seconds: duration.seconds(),
28
+ expired,
29
+ });
30
+ }
31
+ };
@@ -2,4 +2,5 @@ import { VelcronActionWithAutoAwait } from "../models";
2
2
  export interface IActionHandler {
3
3
  name: string;
4
4
  action: (action: VelcronActionWithAutoAwait, ...parameters: any) => Promise<unknown>;
5
+ dispose?: (action: VelcronActionWithAutoAwait) => () => void;
5
6
  }
@@ -0,0 +1,4 @@
1
+ import { IActionHandler } from "./IActionHandler";
2
+ export declare const timerCreate: IActionHandler;
3
+ export declare const timerStart: IActionHandler;
4
+ export declare const timerStop: IActionHandler;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.timerStop = exports.timerStart = exports.timerCreate = void 0;
4
+ const parser_1 = require("../parser");
5
+ const timerCreateName = "@timer.create";
6
+ exports.timerCreate = {
7
+ name: "@timer.create",
8
+ action: (action, interval, autostart = true, immediate = false) => {
9
+ if (!action.path) {
10
+ parser_1.VelcronLogger.logActionError(`${timerCreateName} requires assignment to a state variable. Example: $state.timer1 = ${timerCreateName}(1000)`);
11
+ }
12
+ if (interval < 1000) {
13
+ parser_1.VelcronLogger.logActionError(`${timerCreateName} The timer interval must be at least 1000 milliseconds`);
14
+ }
15
+ const path = getPath(action.path);
16
+ if (action.rootContext[path] === typeof TimerInstance) {
17
+ //TODO: What do we do if the instance is already created?
18
+ console.dir("Timer already created");
19
+ }
20
+ else {
21
+ //TODO: action.rootContext[path] validate it to be Array<string>
22
+ action.rootContext[path] = new TimerInstance(action.rootContext[path], action, interval, autostart, immediate);
23
+ }
24
+ return Promise.resolve(null);
25
+ },
26
+ dispose: (action) => {
27
+ return () => {
28
+ const path = getPath(action.path);
29
+ action.rootContext[path].stop();
30
+ action.rootContext[path] = undefined;
31
+ };
32
+ }
33
+ };
34
+ const timerStartName = "@timer.start";
35
+ exports.timerStart = {
36
+ name: timerStartName,
37
+ action: (action, timer) => {
38
+ if ((timer instanceof TimerInstance) === false) {
39
+ parser_1.VelcronLogger.logActionError(`Error in ${timerStartName} the timer does not exists. Did you use ${timerCreateName} to create the timer?`);
40
+ }
41
+ timer.start();
42
+ return Promise.resolve(null);
43
+ }
44
+ };
45
+ const timerStopName = "@timer.stop";
46
+ exports.timerStop = {
47
+ name: timerStopName,
48
+ action: (action, timer) => {
49
+ if ((timer instanceof TimerInstance) === false) {
50
+ parser_1.VelcronLogger.logActionError(`Error in ${timerStopName} the timer does not exists. Did you use ${timerCreateName} to create the timer?`);
51
+ }
52
+ timer.stop();
53
+ return Promise.resolve(null);
54
+ }
55
+ };
56
+ function getPath(path) {
57
+ return path.substring(0, path.indexOf("=")).trim();
58
+ }
59
+ class TimerInstance {
60
+ constructor(actions, renderCtx, interval, autostart, immediate) {
61
+ this.actions = actions;
62
+ this.renderCtx = renderCtx;
63
+ this.interval = interval;
64
+ this.autostart = autostart;
65
+ this.immediate = immediate;
66
+ if (autostart) {
67
+ this.start();
68
+ }
69
+ }
70
+ stop() {
71
+ clearInterval(this.intervalId);
72
+ }
73
+ start() {
74
+ //Run the action immediately
75
+ this.immediate && parser_1.VelcronActions.parseAndExecuteActions(this.actions, this.renderCtx);
76
+ this.intervalId = setInterval(() => {
77
+ parser_1.VelcronActions.parseAndExecuteActions(this.actions, this.renderCtx);
78
+ }, this.interval);
79
+ }
80
+ }
@@ -9,3 +9,5 @@ export * from "./Log";
9
9
  export * from "./MsGraph";
10
10
  export * from "./MsSharePoint";
11
11
  export * from "./Emit";
12
+ export * from "./Timer";
13
+ export * from "./Date";
package/actions/index.js CHANGED
@@ -12,3 +12,5 @@ tslib_1.__exportStar(require("./Log"), exports);
12
12
  tslib_1.__exportStar(require("./MsGraph"), exports);
13
13
  tslib_1.__exportStar(require("./MsSharePoint"), exports);
14
14
  tslib_1.__exportStar(require("./Emit"), exports);
15
+ tslib_1.__exportStar(require("./Timer"), exports);
16
+ tslib_1.__exportStar(require("./Date"), exports);
@@ -44,19 +44,20 @@ export interface VelcronRenderContext {
44
44
  colors?: ReturnType<typeof useVelcronColorSchemaStore>;
45
45
  blueprints?: ReturnType<typeof useVelcronBlueprintStore>;
46
46
  actions?: {
47
- [name: string]: [];
47
+ [name: string]: Array<string>;
48
48
  };
49
49
  components?: Array<VelcronCustomComponentDefinition>;
50
50
  properties?: {
51
51
  [name: string]: VelcronPrimitiveType | VelcroncomponentArrayType;
52
52
  };
53
53
  computed?: {
54
- [name: string]: [];
54
+ [name: string]: Array<string>;
55
55
  };
56
56
  parent?: VelcronRenderContext;
57
57
  hooks?: VelcronRenderContextHooks;
58
58
  eventHandlers?: VelcronRenderContextEventHandlers;
59
59
  editMode?: boolean;
60
+ disposers: Array<() => void>;
60
61
  }
61
62
  export interface VelcronRenderContextEventHandlers {
62
63
  receiving?: {
@@ -172,13 +173,13 @@ export interface VelcronAppDefinition<TState extends DynamicState = DynamicState
172
173
  body?: Array<VelcronDefinition>;
173
174
  events?: VelcronOnLoadEvent & VelcronOnEditModeEvent;
174
175
  actions?: {
175
- [name: string]: [];
176
+ [name: string]: Array<string>;
176
177
  };
177
178
  components?: Array<VelcronCustomComponentDefinition>;
178
179
  propEditors?: Array<VelcronPropertyEditor>;
179
180
  state?: TState;
180
181
  computed?: {
181
- [name: string]: [];
182
+ [name: string]: Array<string>;
182
183
  };
183
184
  }
184
185
  export interface VelcronComponentDefinition extends VelcronDefinition {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnia/velcron",
3
3
  "license": "MIT",
4
- "version": "8.0.96-vnext",
4
+ "version": "8.0.98-vnext",
5
5
  "description": "Provide Omnia Velcron Stuffs.",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -7,7 +7,7 @@ export declare class VelcronActions {
7
7
  static registerAction(name: string, handler: IActionHandler): void;
8
8
  static parseAndExecuteActions(templates: Array<string>, renderContext: VelcronRenderContext, customActionContext?: VelcronCustomActionExecutionContext): void;
9
9
  static parseFunction(target: {
10
- [name: string]: [];
10
+ [name: string]: Array<string>;
11
11
  }, template: string, renderContext: VelcronRenderContext, params: Array<VelcronActionParameterValue>, foundCb: (name: string, params: {}) => void): void;
12
12
  static getActionFromTemplate(partialTemplate: string, eventId: string, renderContext: VelcronRenderContext, customActionContext?: VelcronCustomActionExecutionContext): VelcronAction;
13
13
  static valueIsAction(value: string): boolean;
@@ -271,6 +271,9 @@ class VelcronActions {
271
271
  if (VelcronActions._actionHandlers[actionName]) {
272
272
  //Built in handler
273
273
  promise = VelcronActions._actionHandlers[actionName].action(awAction, ...paramValues);
274
+ if (VelcronActions._actionHandlers[actionName].dispose) {
275
+ awAction.disposers.push(VelcronActions._actionHandlers[actionName].dispose(awAction));
276
+ }
274
277
  }
275
278
  else {
276
279
  //Custom handler
@@ -285,7 +285,10 @@ class VelcronData {
285
285
  }
286
286
  else {
287
287
  //try get value from render context
288
- value = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, value);
288
+ const localVal = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, value);
289
+ if (localVal !== undefined && localVal !== null) {
290
+ value = localVal;
291
+ }
289
292
  }
290
293
  }
291
294
  }
@@ -75,6 +75,7 @@ class VelcronRenderers {
75
75
  colors: currentRenderCtx.colors,
76
76
  editMode: currentRenderCtx.editMode,
77
77
  blueprints: currentRenderCtx.blueprints,
78
+ disposers: currentRenderCtx.disposers
78
79
  };
79
80
  if (VelcronRenderers.definitionContainsCustomColorSchema(definition)) {
80
81
  const colorSchemaStore = (0, __1.useVelcronColorSchemaStore)(definition.key.toString());