@lowdefy/engine 4.0.0-alpha.8 → 4.0.0-alpha.9
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/dist/Actions.js +13 -6
- package/dist/Blocks.js +29 -27
- package/dist/Events.js +4 -3
- package/dist/Requests.js +1 -4
- package/dist/State.js +1 -1
- package/dist/actions/createCallMethod.js +1 -1
- package/dist/actions/createDisplayMessage.js +1 -1
- package/dist/actions/createGetActions.js +1 -1
- package/dist/actions/createGetBlockId.js +1 -1
- package/dist/actions/createGetEvent.js +1 -1
- package/dist/actions/createGetGlobal.js +1 -1
- package/dist/actions/createGetInput.js +1 -1
- package/dist/actions/createGetPageId.js +1 -1
- package/dist/actions/createGetRequestDetails.js +1 -1
- package/dist/actions/createGetState.js +1 -1
- package/dist/actions/createGetUrlQuery.js +1 -1
- package/dist/actions/createGetUser.js +1 -1
- package/dist/actions/createLink.js +1 -1
- package/dist/actions/createLogin.js +1 -1
- package/dist/actions/createLogout.js +1 -1
- package/dist/actions/createRequest.js +1 -1
- package/dist/actions/createReset.js +1 -1
- package/dist/actions/createResetValidation.js +1 -1
- package/dist/actions/createSetGlobal.js +1 -1
- package/dist/actions/createSetState.js +1 -1
- package/dist/actions/createValidate.js +1 -1
- package/dist/actions/getActionMethods.js +1 -1
- package/dist/actions/getFromObject.js +1 -1
- package/dist/createLink.js +1 -1
- package/dist/getBlockMatcher.js +1 -1
- package/dist/getContext.js +30 -12
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/getFieldValues.js +0 -35
package/dist/Actions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -31,7 +31,7 @@ let Actions = class Actions {
|
|
|
31
31
|
console.error(error);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
async callActionLoop({ actions , arrayIndices , block , event , responses }) {
|
|
34
|
+
async callActionLoop({ actions , arrayIndices , block , event , progress , responses }) {
|
|
35
35
|
for (const [index, action] of actions.entries()){
|
|
36
36
|
try {
|
|
37
37
|
if (action.async === true) {
|
|
@@ -41,6 +41,7 @@ let Actions = class Actions {
|
|
|
41
41
|
block,
|
|
42
42
|
event,
|
|
43
43
|
index,
|
|
44
|
+
progress,
|
|
44
45
|
responses
|
|
45
46
|
});
|
|
46
47
|
} else {
|
|
@@ -50,6 +51,7 @@ let Actions = class Actions {
|
|
|
50
51
|
block,
|
|
51
52
|
event,
|
|
52
53
|
index,
|
|
54
|
+
progress,
|
|
53
55
|
responses
|
|
54
56
|
});
|
|
55
57
|
responses[action.id] = response;
|
|
@@ -63,7 +65,7 @@ let Actions = class Actions {
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
async callActions({ actions , arrayIndices , block , catchActions , event , eventName }) {
|
|
68
|
+
async callActions({ actions , arrayIndices , block , catchActions , event , eventName , progress }) {
|
|
67
69
|
const startTimestamp = new Date();
|
|
68
70
|
const responses = {};
|
|
69
71
|
try {
|
|
@@ -72,7 +74,8 @@ let Actions = class Actions {
|
|
|
72
74
|
arrayIndices,
|
|
73
75
|
block,
|
|
74
76
|
event,
|
|
75
|
-
responses
|
|
77
|
+
responses,
|
|
78
|
+
progress
|
|
76
79
|
});
|
|
77
80
|
} catch (error) {
|
|
78
81
|
console.error(error);
|
|
@@ -82,7 +85,8 @@ let Actions = class Actions {
|
|
|
82
85
|
arrayIndices,
|
|
83
86
|
block,
|
|
84
87
|
event,
|
|
85
|
-
responses
|
|
88
|
+
responses,
|
|
89
|
+
progress
|
|
86
90
|
});
|
|
87
91
|
} catch (errorCatch) {
|
|
88
92
|
console.error(errorCatch);
|
|
@@ -122,7 +126,7 @@ let Actions = class Actions {
|
|
|
122
126
|
success: true
|
|
123
127
|
};
|
|
124
128
|
}
|
|
125
|
-
async callAction({ action , arrayIndices , block , event , index , responses }) {
|
|
129
|
+
async callAction({ action , arrayIndices , block , event , index , progress , responses }) {
|
|
126
130
|
if (!this.actions[action.type]) {
|
|
127
131
|
throw {
|
|
128
132
|
error: new Error(`Invalid action type "${action.type}" at "${block.blockId}".`),
|
|
@@ -172,6 +176,9 @@ let Actions = class Actions {
|
|
|
172
176
|
params: parsedAction.params,
|
|
173
177
|
window: this.context._internal.lowdefy._internal.window
|
|
174
178
|
});
|
|
179
|
+
if (progress) {
|
|
180
|
+
progress();
|
|
181
|
+
}
|
|
175
182
|
} catch (error) {
|
|
176
183
|
responses[action.id] = {
|
|
177
184
|
error,
|
package/dist/Blocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { applyArrayIndices, get, serializer, swap, type } from '@lowdefy/helpers';
|
|
16
16
|
import Events from './Events.js';
|
|
17
|
-
import getFieldValues from './getFieldValues.js';
|
|
18
17
|
let Blocks = class Blocks {
|
|
19
18
|
loopBlocks(fn) {
|
|
20
19
|
if (type.isObject(this.areas)) {
|
|
@@ -34,21 +33,29 @@ let Blocks = class Blocks {
|
|
|
34
33
|
block.blockId = applyArrayIndices(this.arrayIndices, block.blockIdPattern);
|
|
35
34
|
block.field = !type.isNone(block.fieldPattern) ? applyArrayIndices(this.arrayIndices, block.fieldPattern) : block.blockId;
|
|
36
35
|
this.context._internal.RootBlocks.map[block.id] = block;
|
|
37
|
-
block.
|
|
38
|
-
block.
|
|
39
|
-
block.
|
|
36
|
+
block.events = type.isNone(block.events) ? {} : block.events;
|
|
37
|
+
block.layout = type.isNone(block.layout) ? {} : block.layout;
|
|
38
|
+
block.loading = type.isNone(block.loading) ? false : block.loading;
|
|
40
39
|
block.properties = type.isNone(block.properties) ? {} : block.properties;
|
|
40
|
+
block.required = type.isNone(block.required) ? false : block.required;
|
|
41
|
+
block.skeleton = type.isNone(block.skeleton) ? null : block.skeleton;
|
|
41
42
|
block.style = type.isNone(block.style) ? {} : block.style;
|
|
42
|
-
block.
|
|
43
|
-
block.
|
|
43
|
+
block.validate = type.isNone(block.validate) ? [] : block.validate;
|
|
44
|
+
block.visible = type.isNone(block.visible) ? true : block.visible;
|
|
44
45
|
block.areasLayoutEval = {};
|
|
45
46
|
block.layoutEval = {};
|
|
47
|
+
block.loadingEval = {};
|
|
46
48
|
block.propertiesEval = {};
|
|
47
49
|
block.requiredEval = {};
|
|
50
|
+
block.skeletonEval = {};
|
|
48
51
|
block.styleEval = {};
|
|
49
52
|
block.validationEval = {};
|
|
50
53
|
block.visibleEval = {};
|
|
51
|
-
|
|
54
|
+
try {
|
|
55
|
+
block.meta = this.context._internal.lowdefy._internal.blockComponents[block.type].meta;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw new Error(`Block type ${block.type} not found at ${block.blockId}. Check your plugins to make sure the block is installed. For more info, see https://docs.lowdefy.com/plugins.`);
|
|
58
|
+
}
|
|
52
59
|
if (!type.isNone(block.areas)) {
|
|
53
60
|
block.areasLayout = {};
|
|
54
61
|
Object.keys(block.areas).forEach((key)=>{
|
|
@@ -61,7 +68,6 @@ let Blocks = class Blocks {
|
|
|
61
68
|
} else {
|
|
62
69
|
block.areasLayout = {};
|
|
63
70
|
}
|
|
64
|
-
block.requestKeys = getFieldValues('_request', block.style, block.properties, block.validate, block.visible, block.required);
|
|
65
71
|
block.methods = {};
|
|
66
72
|
block.registerMethod = (methodName, method)=>{
|
|
67
73
|
block.methods[methodName] = method;
|
|
@@ -236,8 +242,10 @@ let Blocks = class Blocks {
|
|
|
236
242
|
return serializer.serializeToString({
|
|
237
243
|
areasLayoutEval: block.areasLayoutEval,
|
|
238
244
|
layoutEval: block.layoutEval,
|
|
245
|
+
loadingEval: block.loadingEval,
|
|
239
246
|
propertiesEval: block.propertiesEval,
|
|
240
247
|
requiredEval: block.requiredEval,
|
|
248
|
+
skeletonEval: block.skeletonEval,
|
|
241
249
|
styleEval: block.styleEval,
|
|
242
250
|
validationEval: block.validationEval,
|
|
243
251
|
value: block.value,
|
|
@@ -346,6 +354,16 @@ let Blocks = class Blocks {
|
|
|
346
354
|
location: block.blockId,
|
|
347
355
|
arrayIndices: this.arrayIndices
|
|
348
356
|
});
|
|
357
|
+
block.loadingEval = this.context._internal.parser.parse({
|
|
358
|
+
input: block.loading,
|
|
359
|
+
location: block.blockId,
|
|
360
|
+
arrayIndices: this.arrayIndices
|
|
361
|
+
});
|
|
362
|
+
block.skeletonEval = this.context._internal.parser.parse({
|
|
363
|
+
input: block.skeleton,
|
|
364
|
+
location: block.blockId,
|
|
365
|
+
arrayIndices: this.arrayIndices
|
|
366
|
+
});
|
|
349
367
|
block.areasLayoutEval = this.context._internal.parser.parse({
|
|
350
368
|
input: block.areasLayout,
|
|
351
369
|
location: block.blockId,
|
|
@@ -505,12 +523,12 @@ let Blocks = class Blocks {
|
|
|
505
523
|
this.loopBlocks((block)=>{
|
|
506
524
|
if (block.update) {
|
|
507
525
|
block.update = false;
|
|
508
|
-
block.loading = block.requestKeys.reduce((acc, key)=>acc || (this.context.requests[key] ? this.context.requests[key].loading : true)
|
|
509
|
-
, false);
|
|
510
526
|
block.eval = {
|
|
511
527
|
areas: block.areasLayoutEval.output,
|
|
512
528
|
events: type.isNone(block.Events.events) ? null : block.Events.events,
|
|
513
529
|
properties: block.propertiesEval.output,
|
|
530
|
+
loading: block.loadingEval.output,
|
|
531
|
+
skeleton: block.skeletonEval.output,
|
|
514
532
|
required: block.requiredEval.output,
|
|
515
533
|
layout: block.layoutEval.output,
|
|
516
534
|
style: block.styleEval.output,
|
|
@@ -530,21 +548,6 @@ let Blocks = class Blocks {
|
|
|
530
548
|
});
|
|
531
549
|
});
|
|
532
550
|
}
|
|
533
|
-
setBlocksLoadingCache() {
|
|
534
|
-
this.loopBlocks((block)=>{
|
|
535
|
-
block.loading_prev = block.loading;
|
|
536
|
-
block.loading = block.requestKeys.reduce((acc, key)=>acc || (this.context.requests[key] ? this.context.requests[key].loading : true)
|
|
537
|
-
, false);
|
|
538
|
-
if (block.loading_prev !== block.loading) {
|
|
539
|
-
this.context._internal.lowdefy._internal.updateBlock(block.id);
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
Object.keys(this.subBlocks).forEach((subKey)=>{
|
|
543
|
-
this.subBlocks[subKey].forEach((subBlock)=>{
|
|
544
|
-
subBlock.setBlocksLoadingCache();
|
|
545
|
-
});
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
551
|
constructor({ arrayIndices , areas , context }){
|
|
549
552
|
this.id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
|
|
550
553
|
this.areas = serializer.copy(areas || []);
|
|
@@ -565,7 +568,6 @@ let Blocks = class Blocks {
|
|
|
565
568
|
this.resetValidation = this.resetValidation.bind(this);
|
|
566
569
|
this.resetValidationRec = this.resetValidationRec.bind(this);
|
|
567
570
|
this.setBlocksCache = this.setBlocksCache.bind(this);
|
|
568
|
-
this.setBlocksLoadingCache = this.setBlocksLoadingCache.bind(this);
|
|
569
571
|
this.update = this.update.bind(this);
|
|
570
572
|
this.updateState = this.updateState.bind(this);
|
|
571
573
|
this.updateStateFromRoot = this.updateStateFromRoot.bind(this);
|
package/dist/Events.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -31,7 +31,7 @@ let Events = class Events {
|
|
|
31
31
|
registerEvent({ name , actions }) {
|
|
32
32
|
this.events[name] = this.initEvent(actions);
|
|
33
33
|
}
|
|
34
|
-
async triggerEvent({ name , event }) {
|
|
34
|
+
async triggerEvent({ name , event , progress }) {
|
|
35
35
|
const eventDescription = this.events[name];
|
|
36
36
|
let result = {
|
|
37
37
|
blockId: this.block.blockId,
|
|
@@ -57,7 +57,8 @@ let Events = class Events {
|
|
|
57
57
|
block: this.block,
|
|
58
58
|
catchActions: eventDescription.catchActions,
|
|
59
59
|
event,
|
|
60
|
-
eventName: name
|
|
60
|
+
eventName: name,
|
|
61
|
+
progress
|
|
61
62
|
});
|
|
62
63
|
eventDescription.history.unshift(res);
|
|
63
64
|
this.context.eventLog.unshift(res);
|
package/dist/Requests.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -74,9 +74,6 @@ let Requests = class Requests {
|
|
|
74
74
|
}
|
|
75
75
|
async fetch({ requestId , payload }) {
|
|
76
76
|
this.context.requests[requestId].loading = true;
|
|
77
|
-
if (this.context._internal.RootBlocks) {
|
|
78
|
-
this.context._internal.RootBlocks.setBlocksLoadingCache();
|
|
79
|
-
}
|
|
80
77
|
try {
|
|
81
78
|
const response = await this.context._internal.lowdefy._internal.callRequest({
|
|
82
79
|
pageId: this.context.pageId,
|
package/dist/State.js
CHANGED
package/dist/createLink.js
CHANGED
package/dist/getBlockMatcher.js
CHANGED
package/dist/getContext.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -35,15 +35,20 @@ const blockData = ({ areas , blockId , blocks , events , field , id , layout , p
|
|
|
35
35
|
visible
|
|
36
36
|
})
|
|
37
37
|
;
|
|
38
|
-
|
|
38
|
+
function getContext({ config , lowdefy , resetContext ={
|
|
39
|
+
reset: false,
|
|
40
|
+
setReset: ()=>undefined
|
|
41
|
+
} , }) {
|
|
39
42
|
if (!config) {
|
|
40
43
|
throw new Error('A page must be provided to get context.');
|
|
41
44
|
}
|
|
42
45
|
const { id } = config;
|
|
43
|
-
if (lowdefy.contexts[id] && !
|
|
46
|
+
if (lowdefy.contexts[id] && !resetContext.reset) {
|
|
47
|
+
// memoize context if already created, eg between page transitions, unless the reset flag is raised
|
|
44
48
|
lowdefy.contexts[id]._internal.update();
|
|
45
49
|
return lowdefy.contexts[id];
|
|
46
50
|
}
|
|
51
|
+
resetContext.setReset(false); // lower context reset flag.
|
|
47
52
|
if (!lowdefy.inputs[id]) {
|
|
48
53
|
lowdefy.inputs[id] = {};
|
|
49
54
|
}
|
|
@@ -64,7 +69,6 @@ async function getContext({ config , lowdefy , development =false }) {
|
|
|
64
69
|
context: ctx,
|
|
65
70
|
operators: lowdefy._internal.operators
|
|
66
71
|
});
|
|
67
|
-
await _internal.parser.init();
|
|
68
72
|
_internal.State = new State(ctx);
|
|
69
73
|
_internal.Actions = new Actions(ctx);
|
|
70
74
|
_internal.Requests = new Requests(ctx);
|
|
@@ -82,14 +86,28 @@ async function getContext({ config , lowdefy , development =false }) {
|
|
|
82
86
|
_internal.update = ()=>{
|
|
83
87
|
_internal.RootBlocks.update();
|
|
84
88
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
_internal.runOnInit = async (progress)=>{
|
|
90
|
+
progress();
|
|
91
|
+
if (!_internal.onInitDone) {
|
|
92
|
+
await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
|
93
|
+
name: 'onInit',
|
|
94
|
+
progress
|
|
95
|
+
});
|
|
96
|
+
_internal.update();
|
|
97
|
+
_internal.State.freezeState();
|
|
98
|
+
_internal.onInitDone = true;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
_internal.runOnInitAsync = async (progress)=>{
|
|
102
|
+
if (_internal.onInitDone && !_internal.onInitAsyncDone) {
|
|
103
|
+
await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
|
104
|
+
name: 'onInitAsync',
|
|
105
|
+
progress
|
|
106
|
+
});
|
|
107
|
+
_internal.onInitAsyncDone = true;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
ctx._internal.update();
|
|
93
111
|
lowdefy.contexts[id] = ctx;
|
|
94
112
|
return ctx;
|
|
95
113
|
}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/engine",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.9",
|
|
4
4
|
"licence": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"test": "jest --coverage"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
42
|
-
"@lowdefy/operators": "4.0.0-alpha.
|
|
41
|
+
"@lowdefy/helpers": "4.0.0-alpha.9",
|
|
42
|
+
"@lowdefy/operators": "4.0.0-alpha.9"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@lowdefy/operators-js": "4.0.0-alpha.
|
|
45
|
+
"@lowdefy/operators-js": "4.0.0-alpha.9",
|
|
46
46
|
"@swc/cli": "0.1.55",
|
|
47
47
|
"@swc/core": "1.2.135",
|
|
48
48
|
"@swc/jest": "0.2.17",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "98b544eca231bdcfca6c3a8601a891835d5ce571"
|
|
55
55
|
}
|
package/dist/getFieldValues.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/ import { serializer } from '@lowdefy/helpers';
|
|
16
|
-
function getFieldValues(operatorName, ...args) {
|
|
17
|
-
const result = new Set();
|
|
18
|
-
function reviver(key, value) {
|
|
19
|
-
if (key === operatorName) {
|
|
20
|
-
result.add(value);
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
[
|
|
25
|
-
...args
|
|
26
|
-
].forEach((element)=>{
|
|
27
|
-
serializer.deserializeFromString(serializer.serializeToString(element), {
|
|
28
|
-
reviver
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
return [
|
|
32
|
-
...result
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
export default getFieldValues;
|