@lowdefy/engine 4.4.0 → 4.5.1
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/LICENSE +183 -183
- package/dist/Areas.js +166 -0
- package/dist/Block.js +439 -0
- package/dist/Requests.js +1 -0
- package/dist/actions/createCallAPI.js +24 -0
- package/dist/actions/createCallMethod.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 +2 -0
- package/dist/callAPIHandler.js +63 -0
- package/dist/getContext.js +6 -6
- package/dist/index.js +4 -4
- package/package.json +7 -7
- package/dist/Blocks.js +0 -581
package/dist/Block.js
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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
|
+
*/ function _define_property(obj, key, value) {
|
|
16
|
+
if (key in obj) {
|
|
17
|
+
Object.defineProperty(obj, key, {
|
|
18
|
+
value: value,
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
obj[key] = value;
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
import { applyArrayIndices, get, serializer, swap, type } from '@lowdefy/helpers';
|
|
29
|
+
import Events from './Events.js';
|
|
30
|
+
import Areas from './Areas.js';
|
|
31
|
+
let Block = class Block {
|
|
32
|
+
constructor({ context, arrayIndices }, { id, blockId, events, layout, loading, properties, required, skeleton, style, validate, visible, type: blockType, areas }){
|
|
33
|
+
_define_property(this, "_initInput", ()=>{
|
|
34
|
+
this.setValue = (value)=>{
|
|
35
|
+
this.value = type.enforceType(this.meta.valueType, value);
|
|
36
|
+
this.context._internal.State.set(this.blockId, this.value);
|
|
37
|
+
this.update = true;
|
|
38
|
+
this.context._internal.update();
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
_define_property(this, "_initList", ()=>{
|
|
42
|
+
// TODO: to initialize new object in array, the new value should be passed by method to unshiftItem and pushItem
|
|
43
|
+
this.unshiftItem = ()=>{
|
|
44
|
+
this.loopSubAreas((areasClass, i)=>{
|
|
45
|
+
areasClass.recUpdateArrayIndices(this.arrayIndices.concat([
|
|
46
|
+
i
|
|
47
|
+
]), this.arrayIndices.concat([
|
|
48
|
+
i + 1
|
|
49
|
+
]));
|
|
50
|
+
});
|
|
51
|
+
this.subAreas.unshift(this.newAreas({
|
|
52
|
+
arrayIndices: this.arrayIndices.concat([
|
|
53
|
+
0
|
|
54
|
+
]),
|
|
55
|
+
initState: {}
|
|
56
|
+
}));
|
|
57
|
+
this.context._internal.State.set(this.blockId, undefined);
|
|
58
|
+
// set area block and sub areas values undefined, so as not to pass values to new blocks
|
|
59
|
+
this.subAreas[0].recSetUndefined();
|
|
60
|
+
this.update = true;
|
|
61
|
+
this.context._internal.update();
|
|
62
|
+
};
|
|
63
|
+
this.pushItem = ()=>{
|
|
64
|
+
this.subAreas.push(this.newAreas({
|
|
65
|
+
arrayIndices: this.arrayIndices.concat([
|
|
66
|
+
this.subAreas.length
|
|
67
|
+
]),
|
|
68
|
+
initState: {}
|
|
69
|
+
}));
|
|
70
|
+
this.update = true;
|
|
71
|
+
this.context._internal.update();
|
|
72
|
+
};
|
|
73
|
+
this.removeItem = (index)=>{
|
|
74
|
+
this.context._internal.State.removeItem(this.blockId, index);
|
|
75
|
+
const lastArea = this.subAreas[this.subAreas.length - 1];
|
|
76
|
+
lastArea.recRemoveBlocksFromMap();
|
|
77
|
+
const largerAreas = this.subAreas.slice(index + 1);
|
|
78
|
+
largerAreas.forEach((areasClass, i)=>{
|
|
79
|
+
areasClass.recUpdateArrayIndices(this.arrayIndices.concat([
|
|
80
|
+
index + i + 1
|
|
81
|
+
]), this.arrayIndices.concat([
|
|
82
|
+
index + i
|
|
83
|
+
]));
|
|
84
|
+
});
|
|
85
|
+
this.subAreas.splice(index, 1);
|
|
86
|
+
this.update = true;
|
|
87
|
+
this.context._internal.update();
|
|
88
|
+
};
|
|
89
|
+
this.moveItemUp = (index)=>{
|
|
90
|
+
if (index === 0) return;
|
|
91
|
+
this.context._internal.State.swapItems(this.blockId, index - 1, index);
|
|
92
|
+
this.subAreas[index - 1].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
93
|
+
index - 1
|
|
94
|
+
]), this.arrayIndices.concat([
|
|
95
|
+
index
|
|
96
|
+
]));
|
|
97
|
+
this.subAreas[index].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
98
|
+
index
|
|
99
|
+
]), this.arrayIndices.concat([
|
|
100
|
+
index - 1
|
|
101
|
+
]));
|
|
102
|
+
swap(this.subAreas, index - 1, index);
|
|
103
|
+
this.update = true;
|
|
104
|
+
this.context._internal.update();
|
|
105
|
+
};
|
|
106
|
+
this.moveItemDown = (index)=>{
|
|
107
|
+
if (index === this.subAreas.length - 1) return;
|
|
108
|
+
this.context._internal.State.swapItems(this.blockId, index, index + 1);
|
|
109
|
+
this.subAreas[index + 1].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
110
|
+
index + 1
|
|
111
|
+
]), this.arrayIndices.concat([
|
|
112
|
+
index
|
|
113
|
+
]));
|
|
114
|
+
this.subAreas[index].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
115
|
+
index
|
|
116
|
+
]), this.arrayIndices.concat([
|
|
117
|
+
index + 1
|
|
118
|
+
]));
|
|
119
|
+
swap(this.subAreas, index, index + 1);
|
|
120
|
+
this.update = true;
|
|
121
|
+
this.context._internal.update();
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
_define_property(this, "loopSubAreas", (fn)=>{
|
|
125
|
+
if (this.subAreas) {
|
|
126
|
+
this.subAreas.forEach(fn);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
_define_property(this, "isDisplay", ()=>{
|
|
130
|
+
return this.meta?.category === 'display';
|
|
131
|
+
});
|
|
132
|
+
_define_property(this, "isList", ()=>{
|
|
133
|
+
return this.meta?.category === 'list';
|
|
134
|
+
});
|
|
135
|
+
_define_property(this, "isInput", ()=>{
|
|
136
|
+
return this.meta?.category === 'input' || this.meta?.category === 'input-container';
|
|
137
|
+
});
|
|
138
|
+
_define_property(this, "isContainer", ()=>{
|
|
139
|
+
return this.meta?.category === 'container' || this.meta?.category === 'input-container';
|
|
140
|
+
});
|
|
141
|
+
_define_property(this, "registerMethod", (methodName, method)=>{
|
|
142
|
+
this.methods[methodName] = method;
|
|
143
|
+
});
|
|
144
|
+
_define_property(this, "newAreas", ({ arrayIndices, initState })=>{
|
|
145
|
+
const areasClass = new Areas({
|
|
146
|
+
arrayIndices,
|
|
147
|
+
areas: this.areas,
|
|
148
|
+
context: this.context
|
|
149
|
+
});
|
|
150
|
+
areasClass.init(initState);
|
|
151
|
+
return areasClass;
|
|
152
|
+
});
|
|
153
|
+
_define_property(this, "reset", (parentSubAreas, initWithState)=>{
|
|
154
|
+
this.update = true;
|
|
155
|
+
this.showValidation = false;
|
|
156
|
+
if (this.isInput() || this.isList()) {
|
|
157
|
+
let blockValue = get(initWithState, this.blockId);
|
|
158
|
+
if (type.isUndefined(blockValue)) {
|
|
159
|
+
blockValue = type.isUndefined(this.meta.initValue) ? type.enforceType(this.meta.valueType, null) : this.meta.initValue;
|
|
160
|
+
this.context._internal.State.set(this.blockId, blockValue);
|
|
161
|
+
}
|
|
162
|
+
if (this.isList()) {
|
|
163
|
+
if (!type.isArray(this.subAreas)) {
|
|
164
|
+
this.subAreas = [];
|
|
165
|
+
parentSubAreas[this.id] = this.subAreas;
|
|
166
|
+
}
|
|
167
|
+
if (type.isArray(blockValue)) {
|
|
168
|
+
blockValue.forEach((item, i)=>{
|
|
169
|
+
if (!this.subAreas[i]) {
|
|
170
|
+
this.subAreas.push(this.newAreas({
|
|
171
|
+
arrayIndices: this.arrayIndices.concat([
|
|
172
|
+
i
|
|
173
|
+
]),
|
|
174
|
+
initState: initWithState
|
|
175
|
+
}));
|
|
176
|
+
} else {
|
|
177
|
+
this.subAreas[i].reset(initWithState);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
this.subAreas.splice(blockValue.length);
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
this.value = blockValue;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (this.isContainer()) {
|
|
187
|
+
if (!type.isArray(this.subAreas)) {
|
|
188
|
+
this.subAreas = [];
|
|
189
|
+
parentSubAreas[this.id] = this.subAreas;
|
|
190
|
+
}
|
|
191
|
+
if (!this.subAreas[0]) {
|
|
192
|
+
this.subAreas.push(this.newAreas({
|
|
193
|
+
arrayIndices: this.arrayIndices,
|
|
194
|
+
initState: initWithState
|
|
195
|
+
}));
|
|
196
|
+
} else {
|
|
197
|
+
this.subAreas[0].reset(initWithState);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
_define_property(this, "evaluate", (visibleParent, repeat)=>{
|
|
202
|
+
if (this.isInput()) {
|
|
203
|
+
const stateValue = get(this.context.state, this.blockId);
|
|
204
|
+
this.value = type.isUndefined(stateValue) ? this.value : stateValue;
|
|
205
|
+
}
|
|
206
|
+
const beforeVisible = this.visibleEval ? this.visibleEval.output : true;
|
|
207
|
+
if (visibleParent === false) {
|
|
208
|
+
this.visibleEval.output = false;
|
|
209
|
+
} else {
|
|
210
|
+
this.visibleEval = this.parse(this.visible);
|
|
211
|
+
}
|
|
212
|
+
if (beforeVisible !== this.visibleEval.output) {
|
|
213
|
+
repeat.value = true;
|
|
214
|
+
}
|
|
215
|
+
if (this.visibleEval.output !== false) {
|
|
216
|
+
this.propertiesEval = this.parse(this.properties);
|
|
217
|
+
this.requiredEval = this.parse(this.required);
|
|
218
|
+
this.validateEval();
|
|
219
|
+
this.styleEval = this.parse(this.style);
|
|
220
|
+
this.layoutEval = this.parse(this.layout);
|
|
221
|
+
this.loadingEval = this.parse(this.loading);
|
|
222
|
+
this.skeletonEval = this.parse(this.skeleton);
|
|
223
|
+
this.areasLayoutEval = this.parse(this.areasLayout);
|
|
224
|
+
}
|
|
225
|
+
if (this.isContainer() || this.isList()) {
|
|
226
|
+
this.loopSubAreas((areasClass)=>{
|
|
227
|
+
repeat.value = areasClass.recEval(this.visibleEval.output) || repeat.value;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const after = this.evalToString();
|
|
231
|
+
if (this.before !== after) {
|
|
232
|
+
this.update = true;
|
|
233
|
+
this.before = after;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
_define_property(this, "parse", (input)=>{
|
|
237
|
+
return this.context._internal.parser.parse({
|
|
238
|
+
input,
|
|
239
|
+
location: this.blockId,
|
|
240
|
+
arrayIndices: this.arrayIndices
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
_define_property(this, "validateEval", ()=>{
|
|
244
|
+
const requiredValidation = {
|
|
245
|
+
pass: {
|
|
246
|
+
_not: {
|
|
247
|
+
_type: 'none'
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
status: 'error',
|
|
251
|
+
message: type.isString(this.requiredEval.output) ? this.requiredEval.output : 'This field is required'
|
|
252
|
+
};
|
|
253
|
+
const validation = this.requiredEval.output === false ? this.validate : [
|
|
254
|
+
...this.validate,
|
|
255
|
+
requiredValidation
|
|
256
|
+
];
|
|
257
|
+
this.validationEval = {
|
|
258
|
+
output: {
|
|
259
|
+
status: null,
|
|
260
|
+
errors: [],
|
|
261
|
+
warnings: []
|
|
262
|
+
},
|
|
263
|
+
errors: []
|
|
264
|
+
};
|
|
265
|
+
let validationError = false;
|
|
266
|
+
let validationWarning = false;
|
|
267
|
+
validation.forEach((test)=>{
|
|
268
|
+
const parsed = this.parse(test);
|
|
269
|
+
// for parser errors
|
|
270
|
+
if (parsed.errors.length > 0) {
|
|
271
|
+
this.validationEval.output.errors.push(parsed.output.message);
|
|
272
|
+
this.validationEval.errors.push(parsed.errors);
|
|
273
|
+
validationError = true;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
// failed validation
|
|
277
|
+
if (!parsed.output.pass) {
|
|
278
|
+
// no status indication on validation tests defaults to error
|
|
279
|
+
if (!test.status || test.status === 'error') {
|
|
280
|
+
this.validationEval.output.errors.push(parsed.output.message);
|
|
281
|
+
validationError = true;
|
|
282
|
+
}
|
|
283
|
+
if (test.status === 'warning') {
|
|
284
|
+
this.validationEval.output.warnings.push(parsed.output.message);
|
|
285
|
+
validationWarning = true;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
if (validation.length > 0) {
|
|
290
|
+
this.validationEval.output.status = 'success';
|
|
291
|
+
}
|
|
292
|
+
if (validationWarning) {
|
|
293
|
+
this.validationEval.output.status = 'warning';
|
|
294
|
+
}
|
|
295
|
+
if (validationError && this.showValidation) {
|
|
296
|
+
this.validationEval.output.status = 'error';
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
_define_property(this, "evalToString", ()=>{
|
|
300
|
+
return serializer.serializeToString({
|
|
301
|
+
areasLayoutEval: this.areasLayoutEval,
|
|
302
|
+
layoutEval: this.layoutEval,
|
|
303
|
+
loadingEval: this.loadingEval,
|
|
304
|
+
propertiesEval: this.propertiesEval,
|
|
305
|
+
requiredEval: this.requiredEval,
|
|
306
|
+
skeletonEval: this.skeletonEval,
|
|
307
|
+
styleEval: this.styleEval,
|
|
308
|
+
validationEval: this.validationEval,
|
|
309
|
+
value: this.value,
|
|
310
|
+
visibleEval: this.visibleEval
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
_define_property(this, "updateState", (toSet)=>{
|
|
314
|
+
if (!this.isVisible()) return;
|
|
315
|
+
if (this.isContainer() || this.isList()) {
|
|
316
|
+
if (this.subAreas && this.subAreas.length > 0) {
|
|
317
|
+
this.loopSubAreas((subAreasClass)=>subAreasClass.updateState());
|
|
318
|
+
return; // Don't add to set
|
|
319
|
+
} else {
|
|
320
|
+
this.context._internal.State.set(this.blockId, type.enforceType(this.meta.valueType, null));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (this.isInput()) {
|
|
324
|
+
this.context._internal.State.set(this.blockId, this.value);
|
|
325
|
+
}
|
|
326
|
+
toSet.add(this.blockId);
|
|
327
|
+
});
|
|
328
|
+
_define_property(this, "isVisible", ()=>{
|
|
329
|
+
return this.visibleEval.output !== false;
|
|
330
|
+
});
|
|
331
|
+
_define_property(this, "updateArrayIndices", ()=>{
|
|
332
|
+
this.blockId = applyArrayIndices(this.arrayIndices, this.blockIdPattern);
|
|
333
|
+
this.context._internal.RootAreas.map[this.blockId] = this;
|
|
334
|
+
});
|
|
335
|
+
_define_property(this, "getValidate", (match)=>{
|
|
336
|
+
if (!match(this.blockId)) return null;
|
|
337
|
+
this.showValidation = true;
|
|
338
|
+
this.update = true;
|
|
339
|
+
if (this.visibleEval.output !== false && this.validationEval.output && this.validationEval.output.errors.length > 0) {
|
|
340
|
+
this.validationEval.output.status = 'error';
|
|
341
|
+
return {
|
|
342
|
+
blockId: this.blockId,
|
|
343
|
+
validation: this.validationEval.output
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
});
|
|
348
|
+
_define_property(this, "deleteFromMap", ()=>{
|
|
349
|
+
delete this.context._internal.RootAreas.map[this.blockId];
|
|
350
|
+
});
|
|
351
|
+
_define_property(this, "resetValidation", (match)=>{
|
|
352
|
+
if (!match(this.blockId)) return;
|
|
353
|
+
this.showValidation = false;
|
|
354
|
+
this.update = true;
|
|
355
|
+
});
|
|
356
|
+
_define_property(this, "render", ()=>{
|
|
357
|
+
if (!this.update) return;
|
|
358
|
+
this.update = false;
|
|
359
|
+
this.eval = {
|
|
360
|
+
areas: this.areasLayoutEval.output,
|
|
361
|
+
events: type.isNone(this.Events.events) ? null : this.Events.events,
|
|
362
|
+
properties: this.propertiesEval.output,
|
|
363
|
+
loading: this.loadingEval.output,
|
|
364
|
+
skeleton: this.skeletonEval.output,
|
|
365
|
+
required: this.requiredEval.output,
|
|
366
|
+
layout: this.layoutEval.output,
|
|
367
|
+
style: this.styleEval.output,
|
|
368
|
+
validation: {
|
|
369
|
+
...this.validationEval.output || {},
|
|
370
|
+
status: this.showValidation || this.validationEval.output?.status === 'warning' ? this.validationEval.output?.status : null
|
|
371
|
+
},
|
|
372
|
+
value: type.isNone(this.value) ? null : this.value,
|
|
373
|
+
visible: this.visibleEval.output
|
|
374
|
+
};
|
|
375
|
+
this.context._internal.lowdefy._internal.updateBlock(this.id);
|
|
376
|
+
});
|
|
377
|
+
this.context = context;
|
|
378
|
+
this.arrayIndices = arrayIndices;
|
|
379
|
+
this.idPattern = id;
|
|
380
|
+
this.blockIdPattern = blockId;
|
|
381
|
+
this.id = applyArrayIndices(this.arrayIndices, this.idPattern);
|
|
382
|
+
this.blockId = applyArrayIndices(this.arrayIndices, this.blockIdPattern);
|
|
383
|
+
this.events = type.isNone(events) ? {} : events;
|
|
384
|
+
this.layout = type.isNone(layout) ? {} : layout;
|
|
385
|
+
this.loading = type.isNone(loading) ? false : loading;
|
|
386
|
+
this.properties = type.isNone(properties) ? {} : properties;
|
|
387
|
+
this.required = type.isNone(required) ? false : required;
|
|
388
|
+
this.skeleton = type.isNone(skeleton) ? null : skeleton;
|
|
389
|
+
this.style = type.isNone(style) ? {} : style;
|
|
390
|
+
this.validate = type.isNone(validate) ? [] : validate;
|
|
391
|
+
this.visible = type.isNone(visible) ? true : visible;
|
|
392
|
+
this.type = blockType;
|
|
393
|
+
this.areas = areas;
|
|
394
|
+
this.areasLayoutEval = {};
|
|
395
|
+
this.layoutEval = {};
|
|
396
|
+
this.loadingEval = {};
|
|
397
|
+
this.propertiesEval = {};
|
|
398
|
+
this.requiredEval = {};
|
|
399
|
+
this.skeletonEval = {};
|
|
400
|
+
this.styleEval = {};
|
|
401
|
+
this.validationEval = {};
|
|
402
|
+
this.visibleEval = {};
|
|
403
|
+
try {
|
|
404
|
+
this.meta = this.context._internal.lowdefy._internal.blockComponents[this.type].meta;
|
|
405
|
+
} catch (error) {
|
|
406
|
+
throw new Error(`Block type ${this.type} not found at ${this.blockId}. Check your plugins to make sure the block is installed. For more info, see https://docs.lowdefy.com/plugins.`);
|
|
407
|
+
}
|
|
408
|
+
if (!this.isContainer() && !this.isDisplay() && !this.isInput() && !this.isList()) {
|
|
409
|
+
throw new Error(`Block type ${this.type}.meta.category must be either "container", "display", "input", "list", or "input-container".`);
|
|
410
|
+
}
|
|
411
|
+
if (!type.isNone(areas)) {
|
|
412
|
+
this.areasLayout = {};
|
|
413
|
+
Object.keys(areas).forEach((key)=>{
|
|
414
|
+
// eslint-disable-next-line no-unused-vars
|
|
415
|
+
const { blocks, ...areaLayout } = areas[key];
|
|
416
|
+
this.areasLayout[key] = {
|
|
417
|
+
...areaLayout
|
|
418
|
+
};
|
|
419
|
+
});
|
|
420
|
+
} else {
|
|
421
|
+
this.areasLayout = {};
|
|
422
|
+
}
|
|
423
|
+
this.methods = {};
|
|
424
|
+
if (this.isList()) {
|
|
425
|
+
this._initList();
|
|
426
|
+
}
|
|
427
|
+
if (this.isInput()) {
|
|
428
|
+
this._initInput();
|
|
429
|
+
}
|
|
430
|
+
this.Events = new Events({
|
|
431
|
+
arrayIndices: this.arrayIndices,
|
|
432
|
+
block: this,
|
|
433
|
+
context: this.context
|
|
434
|
+
});
|
|
435
|
+
this.triggerEvent = this.Events.triggerEvent;
|
|
436
|
+
this.registerEvent = this.Events.registerEvent;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
export default Block;
|
package/dist/Requests.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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 callAPIHandler from '../callAPIHandler.js';
|
|
16
|
+
function createCallAPI({ blockId, context }) {
|
|
17
|
+
return function callAPI(params) {
|
|
18
|
+
return callAPIHandler(context, {
|
|
19
|
+
blockId,
|
|
20
|
+
params
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export default createCallAPI;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
function createCallMethod({ arrayIndices, context }) {
|
|
17
17
|
return function callMethod(params) {
|
|
18
18
|
const { blockId, method, args = [] } = params;
|
|
19
|
-
const blockMethod = context._internal.
|
|
19
|
+
const blockMethod = context._internal.RootAreas.map[applyArrayIndices(arrayIndices, blockId)].methods[method];
|
|
20
20
|
if (!type.isArray(args)) {
|
|
21
21
|
throw new Error(`Failed to call method "${method}" on block "${blockId}": "args" should be an array. Received "${JSON.stringify(params)}".`);
|
|
22
22
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
function createReset({ context }) {
|
|
17
17
|
return function reset() {
|
|
18
18
|
context._internal.State.resetState();
|
|
19
|
-
context._internal.
|
|
19
|
+
context._internal.RootAreas.reset(serializer.deserializeFromString(context._internal.State.frozenState));
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
export default createReset;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/ import getBlockMatcher from '../getBlockMatcher.js';
|
|
16
16
|
function createResetValidation({ context }) {
|
|
17
17
|
return function resetValidation(params) {
|
|
18
|
-
context._internal.
|
|
18
|
+
context._internal.RootAreas.resetValidation(getBlockMatcher(params));
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
export default createResetValidation;
|
|
@@ -18,7 +18,7 @@ const createSetGlobal = ({ arrayIndices, context })=>{
|
|
|
18
18
|
Object.keys(params).forEach((key)=>{
|
|
19
19
|
set(context._internal.lowdefy.lowdefyGlobal, applyArrayIndices(arrayIndices, key), params[key]);
|
|
20
20
|
});
|
|
21
|
-
context._internal.
|
|
21
|
+
context._internal.RootAreas.reset();
|
|
22
22
|
context._internal.update();
|
|
23
23
|
};
|
|
24
24
|
};
|
|
@@ -18,7 +18,7 @@ function createSetState({ arrayIndices, context }) {
|
|
|
18
18
|
Object.keys(params).forEach((key)=>{
|
|
19
19
|
context._internal.State.set(applyArrayIndices(arrayIndices, key), params[key]);
|
|
20
20
|
});
|
|
21
|
-
context._internal.
|
|
21
|
+
context._internal.RootAreas.reset();
|
|
22
22
|
context._internal.update();
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/ import getBlockMatcher from '../getBlockMatcher.js';
|
|
16
16
|
function createValidate({ context }) {
|
|
17
17
|
return function validate(params) {
|
|
18
|
-
const validationErrors = context._internal.
|
|
18
|
+
const validationErrors = context._internal.RootAreas.validate(getBlockMatcher(params));
|
|
19
19
|
if (validationErrors.length > 0) {
|
|
20
20
|
const error = new Error(`Your input has ${validationErrors.length} validation error${validationErrors.length !== 1 ? 's' : ''}.`);
|
|
21
21
|
throw error;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createCallMethod from './createCallMethod.js';
|
|
16
|
+
import createCallAPI from './createCallAPI.js';
|
|
16
17
|
import createGetActions from './createGetActions.js';
|
|
17
18
|
import createGetBlockId from './createGetBlockId.js';
|
|
18
19
|
import createGetEvent from './createGetEvent.js';
|
|
@@ -36,6 +37,7 @@ import createUpdateSession from './createUpdateSession.js';
|
|
|
36
37
|
import createValidate from './createValidate.js';
|
|
37
38
|
function getActionMethods(props) {
|
|
38
39
|
return {
|
|
40
|
+
callAPI: createCallAPI(props),
|
|
39
41
|
callMethod: createCallMethod(props),
|
|
40
42
|
displayMessage: createDisplayMessage(props),
|
|
41
43
|
getActions: createGetActions(props),
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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
|
+
async function callAPIHandler(context, { blockId, params }) {
|
|
17
|
+
if (!context._internal.lowdefy.apiResponses[params.endpointId]) {
|
|
18
|
+
context._internal.lowdefy.apiResponses[params.endpointId] = [];
|
|
19
|
+
}
|
|
20
|
+
const api = {
|
|
21
|
+
...params,
|
|
22
|
+
blockId,
|
|
23
|
+
loading: true,
|
|
24
|
+
success: null,
|
|
25
|
+
pageId: context.pageId,
|
|
26
|
+
startTimestamp: new Date(),
|
|
27
|
+
endTimestamp: null
|
|
28
|
+
};
|
|
29
|
+
context._internal.lowdefy.apiResponses[api.endpointId].unshift(api);
|
|
30
|
+
let apiResponse;
|
|
31
|
+
try {
|
|
32
|
+
apiResponse = await context._internal.lowdefy._internal.callAPI({
|
|
33
|
+
blockId: api.blockId,
|
|
34
|
+
pageId: context.pageId,
|
|
35
|
+
payload: serializer.serialize(api.payload),
|
|
36
|
+
endpointId: api.endpointId
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
api.error = error;
|
|
40
|
+
api.loading = false;
|
|
41
|
+
api.response = null;
|
|
42
|
+
api.status = 'error';
|
|
43
|
+
api.success = false;
|
|
44
|
+
api.endTimestamp = new Date();
|
|
45
|
+
api.responseTime = api.endTimestamp - api.startTimestamp;
|
|
46
|
+
context._internal.update();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
const { error, response, status, success } = apiResponse;
|
|
50
|
+
api.error = serializer.deserialize(error);
|
|
51
|
+
api.loading = false;
|
|
52
|
+
api.response = serializer.deserialize(response);
|
|
53
|
+
api.status = status;
|
|
54
|
+
api.success = success;
|
|
55
|
+
api.endTimestamp = new Date();
|
|
56
|
+
api.responseTime = api.endTimestamp - api.startTimestamp;
|
|
57
|
+
context._internal.update();
|
|
58
|
+
if (!success) {
|
|
59
|
+
throw serializer.deserialize(error);
|
|
60
|
+
}
|
|
61
|
+
return api;
|
|
62
|
+
}
|
|
63
|
+
export default callAPIHandler;
|
package/dist/getContext.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { WebParser } from '@lowdefy/operators';
|
|
16
16
|
import Actions from './Actions.js';
|
|
17
|
-
import
|
|
17
|
+
import Areas from './Areas.js';
|
|
18
18
|
import Requests from './Requests.js';
|
|
19
19
|
import State from './State.js';
|
|
20
20
|
const blockData = ({ areas, blockId, blocks, events, field, id, layout, pageId, properties, requests, required, style, type, validate, visible })=>({
|
|
@@ -72,7 +72,7 @@ function getContext({ config, jsMap = {}, lowdefy, resetContext = {
|
|
|
72
72
|
_internal.State = new State(ctx);
|
|
73
73
|
_internal.Actions = new Actions(ctx);
|
|
74
74
|
_internal.Requests = new Requests(ctx);
|
|
75
|
-
_internal.
|
|
75
|
+
_internal.RootAreas = new Areas({
|
|
76
76
|
areas: {
|
|
77
77
|
root: {
|
|
78
78
|
blocks: [
|
|
@@ -82,14 +82,14 @@ function getContext({ config, jsMap = {}, lowdefy, resetContext = {
|
|
|
82
82
|
},
|
|
83
83
|
context: ctx
|
|
84
84
|
});
|
|
85
|
-
_internal.
|
|
85
|
+
_internal.RootAreas.init();
|
|
86
86
|
_internal.update = ()=>{
|
|
87
|
-
_internal.
|
|
87
|
+
_internal.RootAreas.update();
|
|
88
88
|
};
|
|
89
89
|
_internal.runOnInit = async (progress)=>{
|
|
90
90
|
progress();
|
|
91
91
|
if (!_internal.onInitDone) {
|
|
92
|
-
await _internal.
|
|
92
|
+
await _internal.RootAreas.areas.root.blocks[0].triggerEvent({
|
|
93
93
|
name: 'onInit',
|
|
94
94
|
progress
|
|
95
95
|
});
|
|
@@ -100,7 +100,7 @@ function getContext({ config, jsMap = {}, lowdefy, resetContext = {
|
|
|
100
100
|
};
|
|
101
101
|
_internal.runOnInitAsync = async (progress)=>{
|
|
102
102
|
if (_internal.onInitDone && !_internal.onInitAsyncDone) {
|
|
103
|
-
await _internal.
|
|
103
|
+
await _internal.RootAreas.areas.root.blocks[0].triggerEvent({
|
|
104
104
|
name: 'onInitAsync',
|
|
105
105
|
progress
|
|
106
106
|
});
|
package/dist/index.js
CHANGED
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import Actions from './Actions.js';
|
|
16
|
-
import
|
|
17
|
-
import Blocks from './Blocks.js';
|
|
16
|
+
import Areas from './Areas.js';
|
|
18
17
|
import createLink from './createLink.js';
|
|
18
|
+
import Events from './Events.js';
|
|
19
|
+
import getContext from './getContext.js';
|
|
19
20
|
import Requests from './Requests.js';
|
|
20
21
|
import State from './State.js';
|
|
21
|
-
|
|
22
|
-
export { Actions, Events, Blocks, createLink, Requests, State };
|
|
22
|
+
export { Actions, Areas, createLink, Events, Requests, State };
|
|
23
23
|
export default getContext;
|