@lowdefy/engine 4.0.0-alpha.5 → 4.0.0-alpha.8
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 +70 -68
- package/dist/Blocks.js +41 -61
- package/dist/Events.js +12 -15
- package/dist/Requests.js +14 -16
- package/dist/State.js +7 -7
- package/dist/actions/createCallMethod.js +29 -0
- package/dist/actions/{Request.js → createDisplayMessage.js} +5 -8
- package/dist/actions/createGetActions.js +27 -0
- package/dist/actions/{Logout.js → createGetBlockId.js} +5 -3
- package/dist/actions/createGetEvent.js +27 -0
- package/dist/actions/createGetGlobal.js +27 -0
- package/dist/actions/createGetInput.js +27 -0
- package/dist/actions/{Login.js → createGetPageId.js} +5 -3
- package/dist/actions/createGetRequestDetails.js +27 -0
- package/dist/actions/{Wait.js → createGetState.js} +12 -8
- package/dist/actions/createGetUrlQuery.js +27 -0
- package/dist/actions/createGetUser.js +27 -0
- package/dist/actions/createLink.js +20 -0
- package/dist/actions/createLogin.js +20 -0
- package/dist/actions/createLogout.js +20 -0
- package/dist/actions/{Message.js → createRequest.js} +10 -9
- package/dist/actions/{Reset.js → createReset.js} +7 -5
- package/dist/actions/{ResetValidation.js → createResetValidation.js} +5 -3
- package/dist/actions/{SetGlobal.js → createSetGlobal.js} +10 -8
- package/dist/actions/{SetState.js → createSetState.js} +9 -7
- package/dist/actions/{Validate.js → createValidate.js} +9 -7
- package/dist/actions/getActionMethods.js +61 -0
- package/dist/actions/getFromObject.js +42 -0
- package/dist/createLink.js +45 -22
- package/dist/getContext.js +6 -10
- package/package.json +9 -8
- package/dist/actions/CallMethod.js +0 -28
- package/dist/actions/JsAction.js +0 -55
- package/dist/actions/Link.js +0 -27
- package/dist/actions/ScrollTo.js +0 -26
- package/dist/actions/Throw.js +0 -40
- package/dist/actions/index.js +0 -46
package/dist/Actions.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
-
import
|
|
16
|
+
import getActionMethods from './actions/getActionMethods.js';
|
|
17
17
|
let Actions = class Actions {
|
|
18
18
|
async callAsyncAction({ action , arrayIndices , block , event , index , responses }) {
|
|
19
19
|
try {
|
|
@@ -31,31 +31,31 @@ let Actions = class Actions {
|
|
|
31
31
|
console.error(error);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
async callActionLoop({ actions
|
|
35
|
-
for (const [index, action] of
|
|
34
|
+
async callActionLoop({ actions , arrayIndices , block , event , responses }) {
|
|
35
|
+
for (const [index, action] of actions.entries()){
|
|
36
36
|
try {
|
|
37
37
|
if (action.async === true) {
|
|
38
38
|
this.callAsyncAction({
|
|
39
39
|
action,
|
|
40
|
-
arrayIndices
|
|
41
|
-
block
|
|
42
|
-
event
|
|
40
|
+
arrayIndices,
|
|
41
|
+
block,
|
|
42
|
+
event,
|
|
43
43
|
index,
|
|
44
|
-
responses
|
|
44
|
+
responses
|
|
45
45
|
});
|
|
46
46
|
} else {
|
|
47
47
|
const response = await this.callAction({
|
|
48
48
|
action,
|
|
49
|
-
arrayIndices
|
|
50
|
-
block
|
|
51
|
-
event
|
|
49
|
+
arrayIndices,
|
|
50
|
+
block,
|
|
51
|
+
event,
|
|
52
52
|
index,
|
|
53
|
-
responses
|
|
53
|
+
responses
|
|
54
54
|
});
|
|
55
|
-
|
|
55
|
+
responses[action.id] = response;
|
|
56
56
|
}
|
|
57
57
|
} catch (error) {
|
|
58
|
-
|
|
58
|
+
responses[action.id] = error;
|
|
59
59
|
throw {
|
|
60
60
|
error,
|
|
61
61
|
action
|
|
@@ -63,16 +63,15 @@ let Actions = class Actions {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
async callActions({ actions
|
|
66
|
+
async callActions({ actions , arrayIndices , block , catchActions , event , eventName }) {
|
|
67
67
|
const startTimestamp = new Date();
|
|
68
|
-
const responses = {
|
|
69
|
-
};
|
|
68
|
+
const responses = {};
|
|
70
69
|
try {
|
|
71
70
|
await this.callActionLoop({
|
|
72
|
-
actions
|
|
73
|
-
arrayIndices
|
|
74
|
-
block
|
|
75
|
-
event
|
|
71
|
+
actions,
|
|
72
|
+
arrayIndices,
|
|
73
|
+
block,
|
|
74
|
+
event,
|
|
76
75
|
responses
|
|
77
76
|
});
|
|
78
77
|
} catch (error) {
|
|
@@ -80,20 +79,20 @@ let Actions = class Actions {
|
|
|
80
79
|
try {
|
|
81
80
|
await this.callActionLoop({
|
|
82
81
|
actions: catchActions,
|
|
83
|
-
arrayIndices
|
|
84
|
-
block
|
|
85
|
-
event
|
|
82
|
+
arrayIndices,
|
|
83
|
+
block,
|
|
84
|
+
event,
|
|
86
85
|
responses
|
|
87
86
|
});
|
|
88
87
|
} catch (errorCatch) {
|
|
89
88
|
console.error(errorCatch);
|
|
90
89
|
return {
|
|
91
|
-
blockId:
|
|
90
|
+
blockId: block.blockId,
|
|
92
91
|
bounced: false,
|
|
93
92
|
endTimestamp: new Date(),
|
|
94
93
|
error,
|
|
95
94
|
errorCatch,
|
|
96
|
-
event
|
|
95
|
+
event,
|
|
97
96
|
eventName,
|
|
98
97
|
responses,
|
|
99
98
|
startTimestamp,
|
|
@@ -101,11 +100,11 @@ let Actions = class Actions {
|
|
|
101
100
|
};
|
|
102
101
|
}
|
|
103
102
|
return {
|
|
104
|
-
blockId:
|
|
103
|
+
blockId: block.blockId,
|
|
105
104
|
bounced: false,
|
|
106
105
|
endTimestamp: new Date(),
|
|
107
106
|
error,
|
|
108
|
-
event
|
|
107
|
+
event,
|
|
109
108
|
eventName,
|
|
110
109
|
responses,
|
|
111
110
|
startTimestamp,
|
|
@@ -113,47 +112,46 @@ let Actions = class Actions {
|
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
114
|
return {
|
|
116
|
-
blockId:
|
|
115
|
+
blockId: block.blockId,
|
|
117
116
|
bounced: false,
|
|
118
117
|
endTimestamp: new Date(),
|
|
119
|
-
event
|
|
118
|
+
event,
|
|
120
119
|
eventName,
|
|
121
120
|
responses,
|
|
122
121
|
startTimestamp,
|
|
123
122
|
success: true
|
|
124
123
|
};
|
|
125
124
|
}
|
|
126
|
-
async callAction({ action
|
|
127
|
-
if (!actions[
|
|
125
|
+
async callAction({ action , arrayIndices , block , event , index , responses }) {
|
|
126
|
+
if (!this.actions[action.type]) {
|
|
128
127
|
throw {
|
|
129
|
-
error: new Error(`Invalid action type "${
|
|
130
|
-
type:
|
|
131
|
-
index
|
|
128
|
+
error: new Error(`Invalid action type "${action.type}" at "${block.blockId}".`),
|
|
129
|
+
type: action.type,
|
|
130
|
+
index
|
|
132
131
|
};
|
|
133
132
|
}
|
|
134
133
|
const { output: parsedAction , errors: parserErrors } = this.context._internal.parser.parse({
|
|
135
|
-
actions:
|
|
136
|
-
event
|
|
137
|
-
arrayIndices
|
|
138
|
-
input:
|
|
139
|
-
location:
|
|
134
|
+
actions: responses,
|
|
135
|
+
event,
|
|
136
|
+
arrayIndices,
|
|
137
|
+
input: action,
|
|
138
|
+
location: block.blockId
|
|
140
139
|
});
|
|
141
140
|
if (parserErrors.length > 0) {
|
|
142
141
|
throw {
|
|
143
142
|
error: parserErrors[0],
|
|
144
|
-
type:
|
|
145
|
-
index
|
|
143
|
+
type: action.type,
|
|
144
|
+
index
|
|
146
145
|
};
|
|
147
146
|
}
|
|
148
147
|
if (parsedAction.skip === true) {
|
|
149
148
|
return {
|
|
150
|
-
type:
|
|
149
|
+
type: action.type,
|
|
151
150
|
skipped: true,
|
|
152
|
-
index
|
|
151
|
+
index
|
|
153
152
|
};
|
|
154
153
|
}
|
|
155
|
-
const messages = parsedAction.messages || {
|
|
156
|
-
};
|
|
154
|
+
const messages = parsedAction.messages || {};
|
|
157
155
|
let response;
|
|
158
156
|
const closeLoading = this.displayMessage({
|
|
159
157
|
defaultMessage: 'Loading',
|
|
@@ -162,32 +160,37 @@ let Actions = class Actions {
|
|
|
162
160
|
status: 'loading'
|
|
163
161
|
});
|
|
164
162
|
try {
|
|
165
|
-
response = await actions[
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
response = await this.actions[action.type]({
|
|
164
|
+
methods: getActionMethods({
|
|
165
|
+
actions: responses,
|
|
166
|
+
arrayIndices,
|
|
167
|
+
blockId: block.blockId,
|
|
168
|
+
context: this.context,
|
|
169
|
+
event
|
|
170
|
+
}),
|
|
171
|
+
document: this.context._internal.lowdefy._internal.document,
|
|
172
|
+
params: parsedAction.params,
|
|
173
|
+
window: this.context._internal.lowdefy._internal.window
|
|
171
174
|
});
|
|
172
175
|
} catch (error) {
|
|
173
|
-
|
|
176
|
+
responses[action.id] = {
|
|
174
177
|
error,
|
|
175
|
-
index
|
|
176
|
-
type:
|
|
178
|
+
index,
|
|
179
|
+
type: action.type
|
|
177
180
|
};
|
|
178
181
|
const { output: parsedMessages , errors: parserErrors } = this.context._internal.parser.parse({
|
|
179
|
-
actions:
|
|
180
|
-
event
|
|
181
|
-
arrayIndices
|
|
182
|
-
input:
|
|
183
|
-
location:
|
|
182
|
+
actions: responses,
|
|
183
|
+
event,
|
|
184
|
+
arrayIndices,
|
|
185
|
+
input: action.messages,
|
|
186
|
+
location: block.blockId
|
|
184
187
|
});
|
|
185
188
|
if (parserErrors.length > 0) {
|
|
186
189
|
// this condition is very unlikely since parser errors usually occur in the first parse.
|
|
187
190
|
throw {
|
|
188
191
|
error: parserErrors[0],
|
|
189
|
-
type:
|
|
190
|
-
index
|
|
192
|
+
type: action.type,
|
|
193
|
+
index
|
|
191
194
|
};
|
|
192
195
|
}
|
|
193
196
|
closeLoading();
|
|
@@ -195,14 +198,13 @@ let Actions = class Actions {
|
|
|
195
198
|
defaultMessage: error.message,
|
|
196
199
|
duration: 6,
|
|
197
200
|
hideExplicitly: true,
|
|
198
|
-
message: (parsedMessages || {
|
|
199
|
-
}).error,
|
|
201
|
+
message: (parsedMessages || {}).error,
|
|
200
202
|
status: 'error'
|
|
201
203
|
});
|
|
202
204
|
throw {
|
|
203
|
-
type:
|
|
205
|
+
type: action.type,
|
|
204
206
|
error,
|
|
205
|
-
index
|
|
207
|
+
index
|
|
206
208
|
};
|
|
207
209
|
}
|
|
208
210
|
closeLoading();
|
|
@@ -212,9 +214,9 @@ let Actions = class Actions {
|
|
|
212
214
|
status: 'success'
|
|
213
215
|
});
|
|
214
216
|
return {
|
|
215
|
-
type:
|
|
217
|
+
type: action.type,
|
|
216
218
|
response,
|
|
217
|
-
index
|
|
219
|
+
index
|
|
218
220
|
};
|
|
219
221
|
}
|
|
220
222
|
displayMessage({ defaultMessage , duration , hideExplicitly , message , status }) {
|
|
@@ -235,7 +237,7 @@ let Actions = class Actions {
|
|
|
235
237
|
this.callActionLoop = this.callActionLoop.bind(this);
|
|
236
238
|
this.callActions = this.callActions.bind(this);
|
|
237
239
|
this.displayMessage = this.displayMessage.bind(this);
|
|
238
|
-
this.actions = actions;
|
|
240
|
+
this.actions = context._internal.lowdefy._internal.actions;
|
|
239
241
|
}
|
|
240
242
|
};
|
|
241
243
|
export default Actions;
|
package/dist/Blocks.js
CHANGED
|
@@ -37,32 +37,20 @@ let Blocks = class Blocks {
|
|
|
37
37
|
block.visible = type.isNone(block.visible) ? true : block.visible;
|
|
38
38
|
block.required = type.isNone(block.required) ? false : block.required;
|
|
39
39
|
block.validate = type.isArray(block.validate) ? block.validate : [];
|
|
40
|
-
block.properties = type.isNone(block.properties) ? {
|
|
41
|
-
} : block.
|
|
42
|
-
block.
|
|
43
|
-
} : block.
|
|
44
|
-
block.
|
|
45
|
-
|
|
46
|
-
block.
|
|
47
|
-
|
|
48
|
-
block.
|
|
49
|
-
};
|
|
50
|
-
block.
|
|
51
|
-
};
|
|
52
|
-
block.propertiesEval = {
|
|
53
|
-
};
|
|
54
|
-
block.requiredEval = {
|
|
55
|
-
};
|
|
56
|
-
block.styleEval = {
|
|
57
|
-
};
|
|
58
|
-
block.validationEval = {
|
|
59
|
-
};
|
|
60
|
-
block.visibleEval = {
|
|
61
|
-
};
|
|
40
|
+
block.properties = type.isNone(block.properties) ? {} : block.properties;
|
|
41
|
+
block.style = type.isNone(block.style) ? {} : block.style;
|
|
42
|
+
block.layout = type.isNone(block.layout) ? {} : block.layout;
|
|
43
|
+
block.events = type.isNone(block.events) ? {} : block.events;
|
|
44
|
+
block.areasLayoutEval = {};
|
|
45
|
+
block.layoutEval = {};
|
|
46
|
+
block.propertiesEval = {};
|
|
47
|
+
block.requiredEval = {};
|
|
48
|
+
block.styleEval = {};
|
|
49
|
+
block.validationEval = {};
|
|
50
|
+
block.visibleEval = {};
|
|
62
51
|
block.meta = this.context._internal.lowdefy._internal.blockComponents[block.type].meta;
|
|
63
52
|
if (!type.isNone(block.areas)) {
|
|
64
|
-
block.areasLayout = {
|
|
65
|
-
};
|
|
53
|
+
block.areasLayout = {};
|
|
66
54
|
Object.keys(block.areas).forEach((key)=>{
|
|
67
55
|
// eslint-disable-next-line no-unused-vars
|
|
68
56
|
const { blocks , ...areaLayout } = block.areas[key];
|
|
@@ -71,12 +59,10 @@ let Blocks = class Blocks {
|
|
|
71
59
|
};
|
|
72
60
|
});
|
|
73
61
|
} else {
|
|
74
|
-
block.areasLayout = {
|
|
75
|
-
};
|
|
62
|
+
block.areasLayout = {};
|
|
76
63
|
}
|
|
77
64
|
block.requestKeys = getFieldValues('_request', block.style, block.properties, block.validate, block.visible, block.required);
|
|
78
|
-
block.methods = {
|
|
79
|
-
};
|
|
65
|
+
block.methods = {};
|
|
80
66
|
block.registerMethod = (methodName, method)=>{
|
|
81
67
|
block.methods[methodName] = method;
|
|
82
68
|
};
|
|
@@ -96,8 +82,7 @@ let Blocks = class Blocks {
|
|
|
96
82
|
0
|
|
97
83
|
]),
|
|
98
84
|
block,
|
|
99
|
-
initState: {
|
|
100
|
-
}
|
|
85
|
+
initState: {}
|
|
101
86
|
}));
|
|
102
87
|
this.context._internal.State.set(block.field, undefined);
|
|
103
88
|
// set block and subBlock values undefined, so as not to pass values to new blocks
|
|
@@ -111,8 +96,7 @@ let Blocks = class Blocks {
|
|
|
111
96
|
this.subBlocks[block.id].length
|
|
112
97
|
]),
|
|
113
98
|
block,
|
|
114
|
-
initState: {
|
|
115
|
-
}
|
|
99
|
+
initState: {}
|
|
116
100
|
}));
|
|
117
101
|
block.update = true;
|
|
118
102
|
this.context._internal.update();
|
|
@@ -238,26 +222,26 @@ let Blocks = class Blocks {
|
|
|
238
222
|
}
|
|
239
223
|
});
|
|
240
224
|
}
|
|
241
|
-
newBlocks({ arrayIndices , block
|
|
225
|
+
newBlocks({ arrayIndices , block , initState }) {
|
|
242
226
|
const SubBlocks = new Blocks({
|
|
243
227
|
arrayIndices,
|
|
244
|
-
areas:
|
|
228
|
+
areas: block.areas,
|
|
245
229
|
context: this.context
|
|
246
230
|
});
|
|
247
|
-
SubBlocks.init(
|
|
231
|
+
SubBlocks.init(initState);
|
|
248
232
|
return SubBlocks;
|
|
249
233
|
}
|
|
250
234
|
// used for update comparison
|
|
251
|
-
static blockEvalToString(
|
|
235
|
+
static blockEvalToString(block) {
|
|
252
236
|
return serializer.serializeToString({
|
|
253
|
-
areasLayoutEval:
|
|
254
|
-
layoutEval:
|
|
255
|
-
propertiesEval:
|
|
256
|
-
requiredEval:
|
|
257
|
-
styleEval:
|
|
258
|
-
validationEval:
|
|
259
|
-
value:
|
|
260
|
-
visibleEval:
|
|
237
|
+
areasLayoutEval: block.areasLayoutEval,
|
|
238
|
+
layoutEval: block.layoutEval,
|
|
239
|
+
propertiesEval: block.propertiesEval,
|
|
240
|
+
requiredEval: block.requiredEval,
|
|
241
|
+
styleEval: block.styleEval,
|
|
242
|
+
validationEval: block.validationEval,
|
|
243
|
+
value: block.value,
|
|
244
|
+
visibleEval: block.visibleEval
|
|
261
245
|
});
|
|
262
246
|
}
|
|
263
247
|
recEval(visibleParent) {
|
|
@@ -490,27 +474,27 @@ let Blocks = class Blocks {
|
|
|
490
474
|
});
|
|
491
475
|
});
|
|
492
476
|
}
|
|
493
|
-
validate(
|
|
477
|
+
validate(match) {
|
|
494
478
|
this.updateStateFromRoot(); // update to recalculate validationEval to raise block errors
|
|
495
|
-
const validationErrors = this.getValidateRec(
|
|
479
|
+
const validationErrors = this.getValidateRec(match, []); // get all relevant raised block errors and set showValidation
|
|
496
480
|
this.setBlocksCache(); // update cache to render
|
|
497
481
|
return validationErrors;
|
|
498
482
|
}
|
|
499
|
-
resetValidationRec(
|
|
483
|
+
resetValidationRec(match) {
|
|
500
484
|
this.loopBlocks((block)=>{
|
|
501
|
-
if (
|
|
485
|
+
if (match(block.blockId)) {
|
|
502
486
|
block.showValidation = false;
|
|
503
487
|
block.update = true;
|
|
504
488
|
}
|
|
505
489
|
});
|
|
506
490
|
Object.keys(this.subBlocks).forEach((subKey)=>{
|
|
507
491
|
this.subBlocks[subKey].forEach((subBlock)=>{
|
|
508
|
-
subBlock.resetValidationRec(
|
|
492
|
+
subBlock.resetValidationRec(match);
|
|
509
493
|
});
|
|
510
494
|
});
|
|
511
495
|
}
|
|
512
|
-
resetValidation(
|
|
513
|
-
this.resetValidationRec(
|
|
496
|
+
resetValidation(match) {
|
|
497
|
+
this.resetValidationRec(match);
|
|
514
498
|
this.setBlocksCache();
|
|
515
499
|
}
|
|
516
500
|
update() {
|
|
@@ -531,10 +515,8 @@ let Blocks = class Blocks {
|
|
|
531
515
|
layout: block.layoutEval.output,
|
|
532
516
|
style: block.styleEval.output,
|
|
533
517
|
validation: {
|
|
534
|
-
...block.validationEval.output || {
|
|
535
|
-
}
|
|
536
|
-
status: block.showValidation ? (block.validationEval.output || {
|
|
537
|
-
}).status : null
|
|
518
|
+
...block.validationEval.output || {},
|
|
519
|
+
status: block.showValidation ? (block.validationEval.output || {}).status : null
|
|
538
520
|
},
|
|
539
521
|
value: type.isNone(block.value) ? null : block.value,
|
|
540
522
|
visible: block.visibleEval.output
|
|
@@ -563,16 +545,14 @@ let Blocks = class Blocks {
|
|
|
563
545
|
});
|
|
564
546
|
});
|
|
565
547
|
}
|
|
566
|
-
constructor({ arrayIndices
|
|
548
|
+
constructor({ arrayIndices , areas , context }){
|
|
567
549
|
this.id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
|
|
568
550
|
this.areas = serializer.copy(areas || []);
|
|
569
|
-
this.arrayIndices = type.isArray(
|
|
551
|
+
this.arrayIndices = type.isArray(arrayIndices) ? arrayIndices : [];
|
|
570
552
|
this.context = context;
|
|
571
|
-
this.map = {
|
|
572
|
-
};
|
|
553
|
+
this.map = {};
|
|
573
554
|
this.recCount = 0;
|
|
574
|
-
this.subBlocks = {
|
|
575
|
-
};
|
|
555
|
+
this.subBlocks = {};
|
|
576
556
|
this.getValidateRec = this.getValidateRec.bind(this);
|
|
577
557
|
this.init = this.init.bind(this);
|
|
578
558
|
this.newBlocks = this.newBlocks.bind(this);
|
package/dist/Events.js
CHANGED
|
@@ -28,17 +28,16 @@ let Events = class Events {
|
|
|
28
28
|
this.events[eventName] = this.initEvent(this.block.events[eventName]);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
registerEvent({ name , actions
|
|
32
|
-
this.events[name] = this.initEvent(
|
|
31
|
+
registerEvent({ name , actions }) {
|
|
32
|
+
this.events[name] = this.initEvent(actions);
|
|
33
33
|
}
|
|
34
|
-
async triggerEvent({ name
|
|
35
|
-
const eventDescription = this.events[
|
|
34
|
+
async triggerEvent({ name , event }) {
|
|
35
|
+
const eventDescription = this.events[name];
|
|
36
36
|
let result = {
|
|
37
37
|
blockId: this.block.blockId,
|
|
38
38
|
event,
|
|
39
|
-
eventName:
|
|
40
|
-
responses: {
|
|
41
|
-
},
|
|
39
|
+
eventName: name,
|
|
40
|
+
responses: {},
|
|
42
41
|
endTimestamp: new Date(),
|
|
43
42
|
startTimestamp: new Date(),
|
|
44
43
|
success: true,
|
|
@@ -58,7 +57,7 @@ let Events = class Events {
|
|
|
58
57
|
block: this.block,
|
|
59
58
|
catchActions: eventDescription.catchActions,
|
|
60
59
|
event,
|
|
61
|
-
eventName:
|
|
60
|
+
eventName: name
|
|
62
61
|
});
|
|
63
62
|
eventDescription.history.unshift(res);
|
|
64
63
|
this.context.eventLog.unshift(res);
|
|
@@ -73,7 +72,7 @@ let Events = class Events {
|
|
|
73
72
|
}
|
|
74
73
|
const delay = !type.isNone(eventDescription.debounce.ms) ? eventDescription.debounce.ms : this.defaultDebounceMs;
|
|
75
74
|
// leading edge: bounce
|
|
76
|
-
if (this.timeouts[
|
|
75
|
+
if (this.timeouts[name] && eventDescription.debounce.immediate === true) {
|
|
77
76
|
result.bounced = true;
|
|
78
77
|
eventDescription.history.unshift(result);
|
|
79
78
|
this.context.eventLog.unshift(result);
|
|
@@ -81,8 +80,8 @@ let Events = class Events {
|
|
|
81
80
|
}
|
|
82
81
|
// leading edge: trigger
|
|
83
82
|
if (eventDescription.debounce.immediate === true) {
|
|
84
|
-
this.timeouts[
|
|
85
|
-
this.timeouts[
|
|
83
|
+
this.timeouts[name] = setTimeout(()=>{
|
|
84
|
+
this.timeouts[name] = null;
|
|
86
85
|
}, delay);
|
|
87
86
|
return actionHandle();
|
|
88
87
|
}
|
|
@@ -107,10 +106,8 @@ let Events = class Events {
|
|
|
107
106
|
}
|
|
108
107
|
constructor({ arrayIndices , block , context }){
|
|
109
108
|
this.defaultDebounceMs = 300;
|
|
110
|
-
this.events = {
|
|
111
|
-
};
|
|
112
|
-
this.timeouts = {
|
|
113
|
-
};
|
|
109
|
+
this.events = {};
|
|
110
|
+
this.timeouts = {};
|
|
114
111
|
this.arrayIndices = arrayIndices;
|
|
115
112
|
this.block = block;
|
|
116
113
|
this.context = context;
|
package/dist/Requests.js
CHANGED
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { get, serializer, type } from '@lowdefy/helpers';
|
|
16
16
|
let Requests = class Requests {
|
|
17
|
-
callRequests({ actions , arrayIndices , event , params } = {
|
|
18
|
-
|
|
19
|
-
if (params.all === true) {
|
|
17
|
+
callRequests({ actions , arrayIndices , event , params } = {}) {
|
|
18
|
+
if (type.isObject(params) && params.all === true) {
|
|
20
19
|
return Promise.all(Object.keys(this.requestConfig).map((requestId)=>this.callRequest({
|
|
21
20
|
requestId,
|
|
22
21
|
event,
|
|
@@ -37,7 +36,7 @@ let Requests = class Requests {
|
|
|
37
36
|
})
|
|
38
37
|
));
|
|
39
38
|
}
|
|
40
|
-
callRequest({ actions
|
|
39
|
+
callRequest({ actions , arrayIndices , event , requestId }) {
|
|
41
40
|
const request = this.requestConfig[requestId];
|
|
42
41
|
if (!request) {
|
|
43
42
|
const error = new Error(`Configuration Error: Request ${requestId} not defined on page.`);
|
|
@@ -58,9 +57,9 @@ let Requests = class Requests {
|
|
|
58
57
|
};
|
|
59
58
|
}
|
|
60
59
|
const { output: payload , errors: parserErrors } = this.context._internal.parser.parse({
|
|
61
|
-
actions
|
|
62
|
-
event
|
|
63
|
-
arrayIndices
|
|
60
|
+
actions,
|
|
61
|
+
event,
|
|
62
|
+
arrayIndices,
|
|
64
63
|
input: request.payload,
|
|
65
64
|
location: requestId
|
|
66
65
|
});
|
|
@@ -73,8 +72,8 @@ let Requests = class Requests {
|
|
|
73
72
|
payload
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
|
-
async fetch({ requestId
|
|
77
|
-
this.context.requests[
|
|
75
|
+
async fetch({ requestId , payload }) {
|
|
76
|
+
this.context.requests[requestId].loading = true;
|
|
78
77
|
if (this.context._internal.RootBlocks) {
|
|
79
78
|
this.context._internal.RootBlocks.setBlocksLoadingCache();
|
|
80
79
|
}
|
|
@@ -82,18 +81,18 @@ let Requests = class Requests {
|
|
|
82
81
|
const response = await this.context._internal.lowdefy._internal.callRequest({
|
|
83
82
|
pageId: this.context.pageId,
|
|
84
83
|
payload: serializer.serialize(payload),
|
|
85
|
-
requestId
|
|
84
|
+
requestId
|
|
86
85
|
});
|
|
87
86
|
const deserializedResponse = serializer.deserialize(get(response, 'response', {
|
|
88
87
|
default: null
|
|
89
88
|
}));
|
|
90
|
-
this.context.requests[
|
|
91
|
-
this.context.requests[
|
|
89
|
+
this.context.requests[requestId].response = deserializedResponse;
|
|
90
|
+
this.context.requests[requestId].loading = false;
|
|
92
91
|
this.context._internal.update();
|
|
93
92
|
return deserializedResponse;
|
|
94
93
|
} catch (error) {
|
|
95
|
-
this.context.requests[
|
|
96
|
-
this.context.requests[
|
|
94
|
+
this.context.requests[requestId].error.unshift(error);
|
|
95
|
+
this.context.requests[requestId].loading = false;
|
|
97
96
|
this.context._internal.update();
|
|
98
97
|
throw error;
|
|
99
98
|
}
|
|
@@ -103,8 +102,7 @@ let Requests = class Requests {
|
|
|
103
102
|
this.callRequests = this.callRequests.bind(this);
|
|
104
103
|
this.callRequest = this.callRequest.bind(this);
|
|
105
104
|
this.fetch = this.fetch.bind(this);
|
|
106
|
-
this.requestConfig = {
|
|
107
|
-
};
|
|
105
|
+
this.requestConfig = {};
|
|
108
106
|
(this.context._internal.rootBlock.requests || []).forEach((request)=>{
|
|
109
107
|
this.requestConfig[request.requestId] = request;
|
|
110
108
|
});
|
package/dist/State.js
CHANGED
|
@@ -32,10 +32,10 @@ let State = class State {
|
|
|
32
32
|
set(field, value) {
|
|
33
33
|
set(this.context.state, field, value);
|
|
34
34
|
}
|
|
35
|
-
del(
|
|
36
|
-
unset(this.context.state,
|
|
35
|
+
del(field) {
|
|
36
|
+
unset(this.context.state, field);
|
|
37
37
|
// remove all empty objects from state as an effect of deleted values
|
|
38
|
-
const fields =
|
|
38
|
+
const fields = field.split('.');
|
|
39
39
|
if (fields.length > 1) {
|
|
40
40
|
const parent = fields.slice(0, fields.length - 1).join('.');
|
|
41
41
|
const parentValue = get(this.context.state, parent);
|
|
@@ -44,15 +44,15 @@ let State = class State {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
swapItems(
|
|
48
|
-
const arr = get(this.context.state,
|
|
47
|
+
swapItems(field, from, to) {
|
|
48
|
+
const arr = get(this.context.state, field);
|
|
49
49
|
if (!type.isArray(arr) || from < 0 || to < 0 || from >= arr.length || to >= arr.length) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
swap(arr, from, to);
|
|
53
53
|
}
|
|
54
|
-
removeItem(
|
|
55
|
-
const arr = get(this.context.state,
|
|
54
|
+
removeItem(field, index) {
|
|
55
|
+
const arr = get(this.context.state, field);
|
|
56
56
|
if (!type.isArray(arr) || index < 0 || index >= arr.length) {
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { applyArrayIndices, type } from '@lowdefy/helpers';
|
|
16
|
+
function createCallMethod({ arrayIndices , context }) {
|
|
17
|
+
return function callMethod(params) {
|
|
18
|
+
const { blockId , method , args =[] } = params;
|
|
19
|
+
const blockMethod = context._internal.RootBlocks.map[applyArrayIndices(arrayIndices, blockId)].methods[method];
|
|
20
|
+
if (!type.isArray(args)) {
|
|
21
|
+
throw new Error(`Failed to call method "${method}" on block "${blockId}": "args" should be an array. Received "${JSON.stringify(params)}".`);
|
|
22
|
+
}
|
|
23
|
+
if (!type.isFunction(blockMethod)) {
|
|
24
|
+
throw new Error(`Failed to call method "${method}" on block "${blockId}". Check if "${method}" is a valid block method for block "${blockId}". Received "${JSON.stringify(params)}".`);
|
|
25
|
+
}
|
|
26
|
+
return blockMethod(...args);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export default createCallMethod;
|