@omnia/velcron 8.0.96-vnext → 8.0.97-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 +1 -1
- package/actions/Date.d.ts +3 -0
- package/actions/Date.js +31 -0
- package/actions/IActionHandler.d.ts +1 -0
- package/actions/Timer.d.ts +4 -0
- package/actions/Timer.js +80 -0
- package/actions/index.d.ts +2 -0
- package/actions/index.js +2 -0
- package/models/VelcronDefinitions.d.ts +5 -4
- package/package.json +1 -1
- package/parser/VelcronActions.d.ts +1 -1
- package/parser/VelcronActions.js +3 -0
- package/parser/VelcronData.js +4 -1
- package/parser/VelcronRenderers.js +1 -0
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
|
|
6
|
+
action: (action, value) => {
|
|
7
7
|
//value = VelcronData.dataBind(action, value)
|
|
8
8
|
//alert(value + nisse ? nisse : 'nullsiu');
|
|
9
9
|
alert(`${value}`);
|
package/actions/Date.js
ADDED
|
@@ -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
|
+
};
|
package/actions/Timer.js
ADDED
|
@@ -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
|
+
}
|
package/actions/index.d.ts
CHANGED
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
|
@@ -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;
|
package/parser/VelcronActions.js
CHANGED
|
@@ -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
|
package/parser/VelcronData.js
CHANGED
|
@@ -285,7 +285,10 @@ class VelcronData {
|
|
|
285
285
|
}
|
|
286
286
|
else {
|
|
287
287
|
//try get value from render context
|
|
288
|
-
|
|
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());
|